INET Framework for OMNeT++/OMNEST
inet::ProbabilisticBroadcast Class Reference

This class offers a data dissemination service using probabilistic broadcast. More...

#include <ProbabilisticBroadcast.h>

Inheritance diagram for inet::ProbabilisticBroadcast:
inet::NetworkProtocolBase inet::INetworkProtocol inet::LayeredProtocolBase inet::DefaultProtocolRegistrationListener inet::OperationalBase inet::IProtocolRegistrationListener inet::OperationalMixin< cSimpleModule > inet::ILifecycle inet::AdaptiveProbabilisticBroadcast

Classes

struct  tMsgDesc
 Store messages in a structure so that we can keep some information needed by the protocol. More...
 

Public Member Functions

 ProbabilisticBroadcast ()
 
virtual int numInitStages () const override
 Initialization of the module and some variables. More...
 
virtual void initialize (int) override
 
virtual void finish () override
 
const ProtocolgetProtocol () const override
 
- Public Member Functions inherited from inet::NetworkProtocolBase
virtual void handleRegisterService (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterProtocol (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) override
 
- Public Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual ~OperationalMixin ()
 }@ More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 
- Public Member Functions inherited from inet::DefaultProtocolRegistrationListener
virtual void handleRegisterServiceGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterProtocolGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterAnyService (cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterAnyProtocol (cGate *gate, ServicePrimitive servicePrimitive) override
 
- Public Member Functions inherited from inet::INetworkProtocol
virtual ~INetworkProtocol ()
 

Protected Types

enum  messagesTypes { UNKNOWN = 0, BROADCAST_TIMER, NEIGHBOR_TIMER, BETA_TIMER }
 
typedef struct inet::ProbabilisticBroadcast::tMsgDesc tMsgDesc
 Store messages in a structure so that we can keep some information needed by the protocol. More...
 
typedef std::set< unsigned int > MsgIdSet
 
typedef std::multimap< simtime_t, tMsgDesc * > TimeMsgMap
 
- Protected Types inherited from inet::OperationalMixin< cSimpleModule >
enum  State
 

Protected Member Functions

virtual void handleUpperPacket (Packet *packet) override
 Handle messages from upper layer. More...
 
virtual void handleLowerPacket (Packet *packet) override
 Handle messages from lower layer. More...
 
virtual void handleSelfMessage (cMessage *msg) override
 Handle self messages. More...
 
virtual bool messageKnown (unsigned int msgId)
 Checks whether a message is known (= kept in memory) or not. More...
 
virtual bool debugMessageKnown (unsigned int msgId)
 Checks whether a message is known (= kept in memory) or not. More...
 
virtual void insertMessage (simtime_t_cref bcastDelay, tMsgDesc *msgDesc)
 Insert a message in both known ID list and message queue. More...
 
virtual tMsgDescpopFirstMessageUpdateQueue (void)
 Returns the descriptor of the first message in the queue, then remove its pointer from the queue and its id from the known IDs list. More...
 
virtual void encapsulate (Packet *packet)
 Returns a network layer packet which encapsulates the upper layer packet passed to the function. More...
 
virtual void decapsulate (Packet *packet)
 extracts and returns the application layer packet which is encapsulated in the network layer packet given in argument, delete network layer packet. More...
 
virtual void insertNewMessage (Packet *packet, bool iAmInitialSender=false)
 Insert a new message in both known ID list and message queue. More...
 
virtual void setDownControlInfo (Packet *const pMsg, const MacAddress &pDestAddr)
 Attaches a "control info" (NetwToMac) structure (object) to the message pMsg. More...
 
virtual void handleStartOperation (LifecycleOperation *operation) override
 
virtual void handleStopOperation (LifecycleOperation *operation) override
 
virtual void handleCrashOperation (LifecycleOperation *operation) override
 
- Protected Member Functions inherited from inet::NetworkProtocolBase
 NetworkProtocolBase ()
 
virtual ~NetworkProtocolBase ()
 
virtual void sendUp (cMessage *message)
 
virtual void sendDown (cMessage *message, int interfaceId=-1)
 
virtual bool isUpperMessage (cMessage *message) const override
 
virtual bool isLowerMessage (cMessage *message) const override
 
virtual bool isInitializeStage (int stage) const override
 
virtual bool isModuleStartStage (int stage) const override
 
virtual bool isModuleStopStage (int stage) const override
 
virtual void handleUpperCommand (cMessage *msg) override
 
- Protected Member Functions inherited from inet::LayeredProtocolBase
virtual void handleMessageWhenUp (cMessage *message) override
 
virtual void handleUpperMessage (cMessage *message)
 
virtual void handleLowerMessage (cMessage *message)
 
virtual void handleLowerCommand (cMessage *message)
 
- Protected Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual int numInitStages () const override
 
virtual void refreshDisplay () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual bool handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual State getInitialOperationalState () const
 Returns initial operational state: OPERATING or NOT_OPERATING. More...
 
virtual void handleActiveOperationTimeout (cMessage *message)
 
virtual bool isUp () const
 utility functions More...
 
virtual bool isDown () const
 
virtual void setOperationalState (State newState)
 
virtual void scheduleOperationTimeout (simtime_t timeout)
 
virtual void setupActiveOperation (LifecycleOperation *operation, IDoneCallback *doneCallback, State)
 
virtual void delayActiveOperationFinish (simtime_t timeout)
 
virtual void startActiveOperationExtraTime (simtime_t delay=SIMTIME_ZERO)
 
virtual void startActiveOperationExtraTimeOrFinish (simtime_t extraTime)
 
virtual void finishActiveOperation ()
 

Static Protected Member Functions

static long getNextID ()
 

Protected Attributes

simtime_t broadcastPeriod
 Period (in sim time) between two broadcast attempts. More...
 
double beta = 0.0
 Probability of each broadcast attempt. More...
 
simtime_t timeToLive
 
int maxNbBcast = 0
 Maximal number of broadcast attempts for each packet. More...
 
simtime_t maxFirstBcastBackoff
 Maximal back-off before first broadcast attempt [seconds]. More...
 
simtime_t timeInQueueAfterDeath
 How long the message should be kept in queue after its died. More...
 
int headerLength = 0
 Length of the NetwPkt header Read from omnetpp.ini. More...
 
cMessage * broadcastTimer = nullptr
 
MsgIdSet knownMsgIds
 
TimeMsgMap msgQueue
 
MsgIdSet debugMsgIdSet
 
long nbDataPacketsReceived = 0
 
long nbDataPacketsSent = 0
 
long nbHops = 0
 
int debugNbMessageKnown = 0
 
long nbDataPacketsForwarded = 0
 
cOutVector oneHopLatencies
 
L3Address myNetwAddr
 
- Protected Attributes inherited from inet::NetworkProtocolBase
ModuleRefByPar< IInterfaceTableinterfaceTable
 
std::set< const Protocol * > upperProtocols
 
std::map< int, SocketDescriptor * > socketIdToSocketDescriptor
 
- Protected Attributes inherited from inet::OperationalMixin< cSimpleModule >
State operationalState
 
simtime_t lastChange
 
Operation activeOperation
 
cMessage * activeOperationTimeout
 
cMessage * activeOperationExtraTimer
 

Static Protected Attributes

static long id_counter = 0
 

Private Member Functions

 ProbabilisticBroadcast (const ProbabilisticBroadcast &)
 Copy constructor is not allowed. More...
 
ProbabilisticBroadcastoperator= (const ProbabilisticBroadcast &)
 Assignment operator is not allowed. More...
 

Detailed Description

This class offers a data dissemination service using probabilistic broadcast.

Each packet which arrives from upper layer or from the network is (re-)transmitted n times with n = floor(TTL/bcperiod) with probability beta.

Author
Damien Piguet

Member Typedef Documentation

◆ MsgIdSet

typedef std::set<unsigned int> inet::ProbabilisticBroadcast::MsgIdSet
protected

◆ TimeMsgMap

typedef std::multimap<simtime_t, tMsgDesc *> inet::ProbabilisticBroadcast::TimeMsgMap
protected

◆ tMsgDesc

Store messages in a structure so that we can keep some information needed by the protocol.

Member Enumeration Documentation

◆ messagesTypes

Enumerator
UNKNOWN 
BROADCAST_TIMER 
NEIGHBOR_TIMER 
BETA_TIMER 
54  {
55  UNKNOWN = 0,
58  BETA_TIMER,
59  };

Constructor & Destructor Documentation

◆ ProbabilisticBroadcast() [1/2]

inet::ProbabilisticBroadcast::ProbabilisticBroadcast ( const ProbabilisticBroadcast )
private

Copy constructor is not allowed.

◆ ProbabilisticBroadcast() [2/2]

inet::ProbabilisticBroadcast::ProbabilisticBroadcast ( )
inline
42 {}

Member Function Documentation

◆ debugMessageKnown()

bool inet::ProbabilisticBroadcast::debugMessageKnown ( unsigned int  msgId)
protectedvirtual

Checks whether a message is known (= kept in memory) or not.

235 {
236  return contains(debugMsgIdSet, msgId);
237 }

Referenced by handleLowerPacket().

◆ decapsulate()

void inet::ProbabilisticBroadcast::decapsulate ( Packet packet)
protectedvirtual

extracts and returns the application layer packet which is encapsulated in the network layer packet given in argument, delete network layer packet.

344 {
345  auto networkHeader = packet->popAtFront<ProbabilisticBroadcastHeader>();
346  auto payloadLength = networkHeader->getPayloadLengthField();
347  if (packet->getDataLength() < payloadLength) {
348  throw cRuntimeError("Data error: illegal payload length"); // FIXME packet drop
349  }
350  if (packet->getDataLength() > payloadLength)
351  packet->setBackOffset(packet->getFrontOffset() + payloadLength);
352  auto payloadProtocol = networkHeader->getProtocol();
353  packet->addTagIfAbsent<NetworkProtocolInd>()->setProtocol(&getProtocol());
354  packet->addTagIfAbsent<NetworkProtocolInd>()->setNetworkProtocolHeader(networkHeader);
355  packet->addTagIfAbsent<DispatchProtocolReq>()->setProtocol(payloadProtocol);
356  packet->addTagIfAbsent<PacketProtocolTag>()->setProtocol(payloadProtocol);
357  packet->addTagIfAbsent<L3AddressInd>()->setSrcAddress(networkHeader->getSrcAddr());
358 }

Referenced by handleLowerPacket().

◆ encapsulate()

void inet::ProbabilisticBroadcast::encapsulate ( Packet packet)
protectedvirtual

Returns a network layer packet which encapsulates the upper layer packet passed to the function.

284 {
285  auto pkt = makeShared<ProbabilisticBroadcastHeader>(); // TODO msg->getName());
286  cObject *controlInfo = packet->removeControlInfo();
287  L3Address broadcastAddress = myNetwAddr.getAddressType()->getBroadcastAddress();
288 
289  pkt->setChunkLength(B(headerLength));
290  pkt->setSrcAddr(myNetwAddr);
291  pkt->setDestAddr(broadcastAddress);
292  pkt->setInitialSrcAddr(myNetwAddr);
293  pkt->setFinalDestAddr(broadcastAddress);
294  pkt->setAppTtl(timeToLive);
295  pkt->setId(getNextID());
296  pkt->setProtocol(packet->getTag<PacketProtocolTag>()->getProtocol());
297  pkt->setPayloadLengthField(packet->getDataLength());
298  // clean-up
299  delete controlInfo;
300 
301  // encapsulate the application packet
302  packet->insertAtFront(pkt);
303 
305 }

Referenced by handleUpperPacket().

◆ finish()

void inet::ProbabilisticBroadcast::finish ( )
overridevirtual
207 {
208  EV << "PBr: " << simTime() << " n" << myNetwAddr << " finish()" << endl;
209  cancelAndDelete(broadcastTimer);
210  // if some messages are still in the queue, delete them.
211  while (!msgQueue.empty()) {
212  auto pos = msgQueue.begin();
213  tMsgDesc *msgDesc = pos->second;
214  msgQueue.erase(pos);
215  delete msgDesc->pkt;
216  delete msgDesc;
217  }
218  recordScalar("nbDataPacketsReceived", nbDataPacketsReceived);
219  recordScalar("debugNbMessageKnown", debugNbMessageKnown);
220  recordScalar("nbDataPacketsForwarded", nbDataPacketsForwarded);
221  if (nbDataPacketsReceived > 0) {
222  recordScalar("meanNbHops", (double)nbHops / (double)nbDataPacketsReceived);
223  }
224  else {
225  recordScalar("meanNbHops", 0);
226  }
227 }

◆ getNextID()

static long inet::ProbabilisticBroadcast::getNextID ( )
inlinestaticprotected
167  {
168  long nextID = id_counter;
169  id_counter++;
170  return nextID;
171  }

Referenced by encapsulate().

◆ getProtocol()

const Protocol& inet::ProbabilisticBroadcast::getProtocol ( ) const
inlineoverridevirtual

Implements inet::NetworkProtocolBase.

51 { return Protocol::probabilistic; }

Referenced by decapsulate().

◆ handleCrashOperation()

virtual void inet::ProbabilisticBroadcast::handleCrashOperation ( LifecycleOperation operation)
inlineoverrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

145 {} // TODO implementation

◆ handleLowerPacket()

void inet::ProbabilisticBroadcast::handleLowerPacket ( Packet packet)
overrideprotectedvirtual

Handle messages from lower layer.

Reimplemented from inet::LayeredProtocolBase.

Reimplemented in inet::AdaptiveProbabilisticBroadcast.

72 {
73  MacAddress macSrcAddr;
74  auto macHeader = dynamicPtrCast<ProbabilisticBroadcastHeader>(packet->popAtFront<ProbabilisticBroadcastHeader>()->dupShared());
75  packet->trim();
76  auto macAddressInd = packet->getTag<MacAddressInd>();
77  macHeader->setNbHops(macHeader->getNbHops() + 1);
78  macSrcAddr = macAddressInd->getSrcAddress();
79  delete packet->removeControlInfo();
81  nbHops = nbHops + macHeader->getNbHops();
82  oneHopLatencies.record(SIMTIME_DBL(simTime() - packet->getTimestamp()));
83  // oneHopLatency gives us an estimate of how long the message spent in the MAC queue of
84  // its sender (compared to that, transmission delay is negligible). Use this value
85  // to update the TTL of the message. Dump it if it is dead.
86 // m->setAppTtl(m->getAppTtl().dbl() - oneHopLatency);
87  if (/*(m->getAppTtl() <= 0) || */ (messageKnown(macHeader->getId()))) {
88  // we got this message already, ignore it.
89  EV << "PBr: " << simTime() << " n" << myNetwAddr << " handleLowerMsg(): Dead or Known message ID=" << macHeader->getId() << " from node "
90  << macSrcAddr << " TTL = " << macHeader->getAppTtl() << endl;
91  delete packet;
92  }
93  else {
94  if (debugMessageKnown(macHeader->getId())) {
96  EV << "PBr: " << simTime() << " n" << myNetwAddr << " ERROR Message should be known TTL= " << macHeader->getAppTtl() << endl;
97  }
98  EV << "PBr: " << simTime() << " n" << myNetwAddr << " handleLowerMsg(): Unknown message ID=" << macHeader->getId() << " from node "
99  << macSrcAddr << endl;
100  // Unknown message. Insert message in queue with random backoff broadcast delay.
101  // Because we got the message from lower layer, we need to create and add a new
102  // control info with the MAC destination address = broadcast address.
104  // before inserting message, update source address (for this hop, not the initial source)
105  macHeader->setSrcAddr(myNetwAddr);
106  packet->insertAtFront(macHeader);
107  insertNewMessage(packet);
108 
109  // until a subscription mechanism is implemented, duplicate and pass all received packets
110  // to the application layer who will be able to compute statistics.
111  // TODO implement an application subscription mechanism.
112  if (true) {
113  auto mCopy = packet->dup();
114  decapsulate(mCopy);
115  sendUp(mCopy);
116  }
117  }
118 }

Referenced by inet::AdaptiveProbabilisticBroadcast::handleLowerPacket().

◆ handleSelfMessage()

void inet::ProbabilisticBroadcast::handleSelfMessage ( cMessage *  msg)
overrideprotectedvirtual

Handle self messages.

Reimplemented from inet::LayeredProtocolBase.

Reimplemented in inet::AdaptiveProbabilisticBroadcast.

121 {
122  if (msg == broadcastTimer) {
123  tMsgDesc *msgDesc;
124  // called method pops the first message from the message queue and
125  // schedules the message timer for the next one. The message is embedded
126  // into a container of type tMsgDesc.
127  msgDesc = popFirstMessageUpdateQueue();
128  auto packet = msgDesc->pkt;
129  auto macHeader = packet->peekAtFront<ProbabilisticBroadcastHeader>();
130  // if the packet is alive, duplicate it and insert the copy in the queue,
131  // then perform a broadcast attempt.
132  EV << "PBr: " << simTime() << " n" << myNetwAddr << " handleSelfMsg(): Message ID= " << macHeader->getId() << " TTL= " << macHeader->getAppTtl() << endl;
133  if (macHeader->getAppTtl() > 0) {
134  // check if we are allowed to re-transmit the message on more time.
135  if (msgDesc->nbBcast < maxNbBcast) {
136  bool sendForSure = msgDesc->initialSend;
137 
138  // duplicate packet and insert the copy in the queue.
139  // two possibilities: the packet will be alive at next
140  // broadcast period => insert it with delay = broadcastPeriod.
141  // Or the packet will be dead at next broadcast period (TTL <= broadcastPeriod)
142  // => insert it with delay = TTL. So when the copy will be popped out of the
143  // queue, it will be considered as dead and discarded.
144  auto packetCopy = packet->dup();
145  auto macHeaderCopy = packetCopy->peekAtFront<ProbabilisticBroadcastHeader>();
146  // control info is not duplicated with the message, so we have to re-create one here.
148  // it the copy that is re-inserted into the queue so update the container accordingly
149  msgDesc->pkt = packetCopy;
150  // increment nbBcast field of the descriptor because at this point, it is sure that
151  // the message will go through one more broadcast attempt.
152  msgDesc->nbBcast++;
153  // for sure next broadcast attempt will not be the initial one.
154  msgDesc->initialSend = false;
155  // if msg TTL > broadcast period, the message will be broadcasted one more
156  // time, insert it with delay = broadcast period. Otherwise, the message
157  // will be dead at next broadcast attempt. Keep it in the list with
158  // delay = TTL + timeInQueueAfterDeath. insertMessage() will update its
159  // TTL to -timeInQueueAfterDeath, a negative value. That way, the message
160  // is known to the system, de-synchronization between copies of the same message
161  // is therefore handled and when the message will be popped out, its TTL will
162  // be smaller than zero, thus the message will be discarded, not broadcasted.
163  if (macHeaderCopy->getAppTtl() > broadcastPeriod)
164  insertMessage(broadcastPeriod, msgDesc);
165  else
166  insertMessage(macHeaderCopy->getAppTtl() + timeInQueueAfterDeath, msgDesc);
167  // broadcast the message with probability beta
168  if (sendForSure) {
169  EV << "PBr: " << simTime() << " n" << myNetwAddr << " Send packet down for sure." << endl;
170  packet->setTimestamp();
171  sendDown(packet);
173  }
174  else {
175  if (bernoulli(beta)) {
176  EV << "PBr: " << simTime() << " n" << myNetwAddr << " Bernoulli test result: TRUE. Send packet down." << endl;
177  packet->setTimestamp();
178  sendDown(packet);
180  }
181  else {
182  EV << "PBr: " << simTime() << " n" << myNetwAddr << " Bernoulli test result: FALSE" << endl;
183  delete packet;
184  }
185  }
186  }
187  else {
188  // we can't re-transmit the message because maxNbBcast is reached.
189  // re-insert-it in the queue with delay = TTL so that its ID is still
190  // known by the system.
191  EV << "PBr: " << simTime() << " n" << myNetwAddr << " maxNbBcast reached." << endl;
192  insertMessage(macHeader->getAppTtl() + timeInQueueAfterDeath, msgDesc);
193  }
194  }
195  else {
196  EV << "PBr: " << simTime() << " n" << myNetwAddr << " Message TTL zero, discard." << endl;
197  delete msgDesc;
198  delete packet;
199  }
200  }
201  else {
202  EV << "PBr: " << simTime() << " n" << myNetwAddr << " Received unexpected self message" << endl;
203  }
204 }

Referenced by inet::AdaptiveProbabilisticBroadcast::handleSelfMessage().

◆ handleStartOperation()

virtual void inet::ProbabilisticBroadcast::handleStartOperation ( LifecycleOperation operation)
inlineoverrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

143 {} // TODO implementation

◆ handleStopOperation()

virtual void inet::ProbabilisticBroadcast::handleStopOperation ( LifecycleOperation operation)
inlineoverrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

144 {} // TODO implementation

◆ handleUpperPacket()

void inet::ProbabilisticBroadcast::handleUpperPacket ( Packet packet)
overrideprotectedvirtual

Handle messages from upper layer.

Reimplemented from inet::LayeredProtocolBase.

61 {
62  // encapsulate message in a network layer packet.
63  encapsulate(packet);
64  auto macHeader = packet->peekAtFront<ProbabilisticBroadcastHeader>();
66  EV << "PBr: " << simTime() << " n" << myNetwAddr << " handleUpperMsg(): Pkt ID = " << macHeader->getId() << " TTL = " << macHeader->getAppTtl() << endl;
67  // submit packet for first insertion in queue.
68  insertNewMessage(packet, true);
69 }

◆ initialize()

void inet::ProbabilisticBroadcast::initialize ( int  stage)
overridevirtual

Reimplemented from inet::NetworkProtocolBase.

Reimplemented in inet::AdaptiveProbabilisticBroadcast.

30 {
32  if (stage == INITSTAGE_LOCAL) {
33  broadcastPeriod = par("bcperiod");
34  beta = par("beta");
35  maxNbBcast = par("maxNbBcast");
36  headerLength = par("headerLength");
37  timeInQueueAfterDeath = par("timeInQueueAfterDeath");
38  timeToLive = par("timeToLive");
39  broadcastTimer = new cMessage("broadcastTimer");
40  maxFirstBcastBackoff = par("maxFirstBcastBackoff");
41  oneHopLatencies.setName("oneHopLatencies");
46  nbHops = 0;
47  }
49  for (int i = 0; i < interfaceTable->getNumInterfaces(); i++)
50  interfaceTable->getInterface(i)->setHasModulePathAddress(true);
51  }
52  else if (stage == INITSTAGE_NETWORK_LAYER) {
53  if (auto ie = interfaceTable->findFirstNonLoopbackInterface())
54  myNetwAddr = ie->getNetworkAddress();
55  else
56  throw cRuntimeError("No non-loopback interface found!");
57  }
58 }

Referenced by inet::AdaptiveProbabilisticBroadcast::initialize().

◆ insertMessage()

void inet::ProbabilisticBroadcast::insertMessage ( simtime_t_cref  bcastDelay,
tMsgDesc msgDesc 
)
protectedvirtual

Insert a message in both known ID list and message queue.

If the message comes in front of the queue (i.e. it will be the next one to be broadcasted, the broadcastTimer is reset accordingly.

Parameters
bcastDelayrelative (to now) simulator time of next broadcast attempt.
msgdescriptor of the message to insert in the queue.
240 {
241  simtime_t bcastTime = simTime() + bcastDelay;
242 
243  EV << "PBr: " << simTime() << " n" << myNetwAddr << " insertMessage() bcastDelay = " << bcastDelay << " Msg ID = " << msgDesc->pkt->getId() << endl;
244  // update TTL field of the message to the value it will have when taken out of the list
245  msgDesc->pkt->trim();
246  auto macHeader = msgDesc->pkt->removeAtFront<ProbabilisticBroadcastHeader>();
247  macHeader->setAppTtl(macHeader->getAppTtl() - bcastDelay);
248  msgDesc->pkt->insertAtFront(macHeader);
249  // insert message ID in ID list.
250  knownMsgIds.insert(macHeader->getId());
251  // insert key value pair <broadcast time, pointer to message> in message queue.
252  auto pos = msgQueue.insert(make_pair(bcastTime, msgDesc));
253  // if the message has been inserted in the front of the list, it means that it
254  // will be the next message to be broadcasted, therefore we have to re-schedule
255  // the broadcast timer to the message's broadcast instant.
256  if (pos == msgQueue.begin()) {
257  EV << "PBr: " << simTime() << " n" << myNetwAddr << " message inserted in the front, reschedule it." << endl;
258  rescheduleAt(bcastTime, broadcastTimer);
259  }
260 }

Referenced by handleSelfMessage(), and insertNewMessage().

◆ insertNewMessage()

void inet::ProbabilisticBroadcast::insertNewMessage ( Packet packet,
bool  iAmInitialSender = false 
)
protectedvirtual

Insert a new message in both known ID list and message queue.

The message comes either from upper layer or from lower layer. In both cases, it will be inserted in the queue with a broadcast attempt delay taken uniformly between 0 and min(broadcast period, TTL) in order to implement a random backoff for the first broadcast of a message.

Parameters
msgDescdescriptor of the message to insert in the queue.
iAmInitialSendermessage comes from upper layer, I am its creator and initial sender.
308 {
309  auto macHeader = packet->peekAtFront<ProbabilisticBroadcastHeader>();
310  simtime_t ttl = macHeader->getAppTtl();
311 
312  if (ttl > 0) {
313  simtime_t bcastDelay;
314  tMsgDesc *msgDesc;
315 
316  // insert packet in queue with delay in [0, min(TTL, broadcast period)].
317  // since the insertion schedules the message for its first broadcast attempt,
318  // we use a uniform random back-off taken between now and the broadcast delay
319  // to avoid having all nodes in the neighborhood forward the packet at the same
320  // time. Backoffs used at MAC layer are thought to be too short.
322  bcastDelay = broadcastPeriod;
323  else
324  bcastDelay = maxFirstBcastBackoff;
325  if (bcastDelay > ttl)
326  bcastDelay = ttl;
327  EV << "PBr: " << simTime() << " n" << myNetwAddr << " insertNewMessage(): insert packet " << macHeader->getId() << " with delay "
328  << bcastDelay << endl;
329  // create container for message and initialize container's values.
330  msgDesc = new tMsgDesc;
331  msgDesc->pkt = packet;
332  msgDesc->nbBcast = 0; // so far, pkt has been forwarded zero times.
333  msgDesc->initialSend = iAmInitialSender;
334  debugMsgIdSet.insert(macHeader->getId());
335  insertMessage(uniform(0, bcastDelay), msgDesc);
336  }
337  else {
338  EV << "PBr: " << simTime() << " n" << myNetwAddr << " insertNewMessage(): got new packet with TTL = 0." << endl;
339  delete packet;
340  }
341 }

Referenced by handleLowerPacket(), and handleUpperPacket().

◆ messageKnown()

bool inet::ProbabilisticBroadcast::messageKnown ( unsigned int  msgId)
protectedvirtual

Checks whether a message is known (= kept in memory) or not.

230 {
231  return contains(knownMsgIds, msgId);
232 }

Referenced by handleLowerPacket().

◆ numInitStages()

virtual int inet::ProbabilisticBroadcast::numInitStages ( ) const
inlineoverridevirtual

Initialization of the module and some variables.

45 { return NUM_INIT_STAGES; }

◆ operator=()

ProbabilisticBroadcast& inet::ProbabilisticBroadcast::operator= ( const ProbabilisticBroadcast )
private

Assignment operator is not allowed.

◆ popFirstMessageUpdateQueue()

ProbabilisticBroadcast::tMsgDesc * inet::ProbabilisticBroadcast::popFirstMessageUpdateQueue ( void  )
protectedvirtual

Returns the descriptor of the first message in the queue, then remove its pointer from the queue and its id from the known IDs list.

Then re-schedule the broadcastTimer to the broadcast instant of the new first element in the list.

263 {
264  tMsgDesc *msgDesc;
265 
266  // get first message.
267  ASSERT(!msgQueue.empty());
268  auto pos = msgQueue.begin();
269  msgDesc = pos->second;
270  // remove first message from message queue and from ID list
271  msgQueue.erase(pos);
272  knownMsgIds.erase(msgDesc->pkt->getId());
273  EV << "PBr: " << simTime() << " n" << myNetwAddr << " pop(): just popped msg " << msgDesc->pkt->getId() << endl;
274  if (!msgQueue.empty()) {
275  // schedule broadcast of new first message
276  EV << "PBr: " << simTime() << " n" << myNetwAddr << " pop(): schedule next message." << endl;
277  pos = msgQueue.begin();
278  scheduleAt(pos->first, broadcastTimer);
279  }
280  return msgDesc;
281 }

Referenced by handleSelfMessage().

◆ setDownControlInfo()

void inet::ProbabilisticBroadcast::setDownControlInfo ( Packet *const  pMsg,
const MacAddress pDestAddr 
)
protectedvirtual

Attaches a "control info" (NetwToMac) structure (object) to the message pMsg.

Attaches a "control info" structure (object) to the down message pMsg.

This is most useful when passing packets between protocol layers of a protocol stack, the control info will contain the destination MAC address.

The "control info" object will be deleted when the message is deleted. Only one "control info" structure can be attached (the second setL3ToL2ControlInfo() call throws an error).

Parameters
pMsgThe message where the "control info" shall be attached.
pDestAddrThe MAC address of the message receiver.
364 {
365  pMsg->addTagIfAbsent<MacAddressReq>()->setDestAddress(pDestAddr);
366  pMsg->addTagIfAbsent<PacketProtocolTag>()->setProtocol(&Protocol::probabilistic);
367  pMsg->addTagIfAbsent<DispatchProtocolInd>()->setProtocol(&Protocol::probabilistic);
368 }

Referenced by encapsulate(), handleLowerPacket(), and handleSelfMessage().

Member Data Documentation

◆ beta

double inet::ProbabilisticBroadcast::beta = 0.0
protected

Probability of each broadcast attempt.

Read from omnetpp.ini

Referenced by handleSelfMessage(), inet::AdaptiveProbabilisticBroadcast::initialize(), initialize(), and inet::AdaptiveProbabilisticBroadcast::updateBeta().

◆ broadcastPeriod

simtime_t inet::ProbabilisticBroadcast::broadcastPeriod
protected

Period (in sim time) between two broadcast attempts.

Read from omnetpp.ini

Referenced by handleSelfMessage(), initialize(), and insertNewMessage().

◆ broadcastTimer

cMessage* inet::ProbabilisticBroadcast::broadcastTimer = nullptr
protected

◆ debugMsgIdSet

MsgIdSet inet::ProbabilisticBroadcast::debugMsgIdSet
protected

◆ debugNbMessageKnown

int inet::ProbabilisticBroadcast::debugNbMessageKnown = 0
protected

◆ headerLength

int inet::ProbabilisticBroadcast::headerLength = 0
protected

Length of the NetwPkt header Read from omnetpp.ini.

Referenced by encapsulate(), and initialize().

◆ id_counter

long inet::ProbabilisticBroadcast::id_counter = 0
staticprotected

◆ knownMsgIds

MsgIdSet inet::ProbabilisticBroadcast::knownMsgIds
protected

◆ maxFirstBcastBackoff

simtime_t inet::ProbabilisticBroadcast::maxFirstBcastBackoff
protected

Maximal back-off before first broadcast attempt [seconds].

Read from omnetpp.ini

Referenced by initialize(), and insertNewMessage().

◆ maxNbBcast

int inet::ProbabilisticBroadcast::maxNbBcast = 0
protected

Maximal number of broadcast attempts for each packet.

Read from omnetpp.ini

Referenced by handleSelfMessage(), and initialize().

◆ msgQueue

TimeMsgMap inet::ProbabilisticBroadcast::msgQueue
protected

◆ myNetwAddr

◆ nbDataPacketsForwarded

long inet::ProbabilisticBroadcast::nbDataPacketsForwarded = 0
protected

◆ nbDataPacketsReceived

long inet::ProbabilisticBroadcast::nbDataPacketsReceived = 0
protected

◆ nbDataPacketsSent

long inet::ProbabilisticBroadcast::nbDataPacketsSent = 0
protected

Referenced by handleUpperPacket(), and initialize().

◆ nbHops

long inet::ProbabilisticBroadcast::nbHops = 0
protected

◆ oneHopLatencies

cOutVector inet::ProbabilisticBroadcast::oneHopLatencies
protected

Referenced by handleLowerPacket(), and initialize().

◆ timeInQueueAfterDeath

simtime_t inet::ProbabilisticBroadcast::timeInQueueAfterDeath
protected

How long the message should be kept in queue after its died.

That way the message is known if the node receives one of its copy that isn't dead because of TTL de-synchronization due to MAC backoff, propagation delay and clock drift. Read from omnetpp.ini

Referenced by handleSelfMessage(), and initialize().

◆ timeToLive

simtime_t inet::ProbabilisticBroadcast::timeToLive
protected

Referenced by encapsulate(), and initialize().


The documentation for this class was generated from the following files:
inet::ProbabilisticBroadcast::nbDataPacketsReceived
long nbDataPacketsReceived
Definition: ProbabilisticBroadcast.h:212
inet::ProbabilisticBroadcast::NEIGHBOR_TIMER
@ NEIGHBOR_TIMER
Definition: ProbabilisticBroadcast.h:57
inet::ProbabilisticBroadcast::messageKnown
virtual bool messageKnown(unsigned int msgId)
Checks whether a message is known (= kept in memory) or not.
Definition: ProbabilisticBroadcast.cc:229
inet::ProbabilisticBroadcast::BETA_TIMER
@ BETA_TIMER
Definition: ProbabilisticBroadcast.h:58
inet::ProbabilisticBroadcast::id_counter
static long id_counter
Definition: ProbabilisticBroadcast.h:164
inet::ProbabilisticBroadcast::debugMsgIdSet
MsgIdSet debugMsgIdSet
Definition: ProbabilisticBroadcast.h:209
DispatchProtocolReq
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
inet::ProbabilisticBroadcast::debugNbMessageKnown
int debugNbMessageKnown
Definition: ProbabilisticBroadcast.h:215
inet::INITSTAGE_NETWORK_LAYER
INET_API InitStage INITSTAGE_NETWORK_LAYER
Initialization of network layer protocols.
L3AddressInd
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd L3AddressInd
Definition: IUdp-gates.txt:20
inet::ProbabilisticBroadcast::timeToLive
simtime_t timeToLive
Definition: ProbabilisticBroadcast.h:162
inet::IL3AddressType::getBroadcastAddress
virtual L3Address getBroadcastAddress() const =0
inet::ProbabilisticBroadcast::insertNewMessage
virtual void insertNewMessage(Packet *packet, bool iAmInitialSender=false)
Insert a new message in both known ID list and message queue.
Definition: ProbabilisticBroadcast.cc:307
inet::ProbabilisticBroadcast::maxFirstBcastBackoff
simtime_t maxFirstBcastBackoff
Maximal back-off before first broadcast attempt [seconds].
Definition: ProbabilisticBroadcast.h:183
inet::ProbabilisticBroadcast::getProtocol
const Protocol & getProtocol() const override
Definition: ProbabilisticBroadcast.h:51
inet::ProbabilisticBroadcast::debugMessageKnown
virtual bool debugMessageKnown(unsigned int msgId)
Checks whether a message is known (= kept in memory) or not.
Definition: ProbabilisticBroadcast.cc:234
inet::ProbabilisticBroadcast::myNetwAddr
L3Address myNetwAddr
Definition: ProbabilisticBroadcast.h:221
PacketProtocolTag
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
inet::ProbabilisticBroadcast::UNKNOWN
@ UNKNOWN
Definition: ProbabilisticBroadcast.h:55
inet::ProbabilisticBroadcast::broadcastPeriod
simtime_t broadcastPeriod
Period (in sim time) between two broadcast attempts.
Definition: ProbabilisticBroadcast.h:151
inet::INITSTAGE_NETWORK_INTERFACE_CONFIGURATION
INET_API InitStage INITSTAGE_NETWORK_INTERFACE_CONFIGURATION
Initialization of network interfaces includes:
inet::ProbabilisticBroadcast::tMsgDesc::pkt
Packet * pkt
Definition: ProbabilisticBroadcast.h:65
inet::ProbabilisticBroadcast::nbDataPacketsForwarded
long nbDataPacketsForwarded
Definition: ProbabilisticBroadcast.h:216
inet::ProbabilisticBroadcast::beta
double beta
Probability of each broadcast attempt.
Definition: ProbabilisticBroadcast.h:157
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::NetworkProtocolBase::sendUp
virtual void sendUp(cMessage *message)
Definition: NetworkProtocolBase.cc:51
inet::contains
bool contains(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:65
inet::ProbabilisticBroadcast::knownMsgIds
MsgIdSet knownMsgIds
Definition: ProbabilisticBroadcast.h:207
inet::NetworkProtocolBase::interfaceTable
ModuleRefByPar< IInterfaceTable > interfaceTable
Definition: NetworkProtocolBase.h:35
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::ProbabilisticBroadcast::headerLength
int headerLength
Length of the NetwPkt header Read from omnetpp.ini.
Definition: ProbabilisticBroadcast.h:198
inet::ProbabilisticBroadcast::nbHops
long nbHops
Definition: ProbabilisticBroadcast.h:214
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::ProbabilisticBroadcast::nbDataPacketsSent
long nbDataPacketsSent
Definition: ProbabilisticBroadcast.h:213
inet::ProbabilisticBroadcast::insertMessage
virtual void insertMessage(simtime_t_cref bcastDelay, tMsgDesc *msgDesc)
Insert a message in both known ID list and message queue.
Definition: ProbabilisticBroadcast.cc:239
inet::ProbabilisticBroadcast::broadcastTimer
cMessage * broadcastTimer
Definition: ProbabilisticBroadcast.h:201
inet::ProbabilisticBroadcast::encapsulate
virtual void encapsulate(Packet *packet)
Returns a network layer packet which encapsulates the upper layer packet passed to the function.
Definition: ProbabilisticBroadcast.cc:283
inet::ProbabilisticBroadcast::maxNbBcast
int maxNbBcast
Maximal number of broadcast attempts for each packet.
Definition: ProbabilisticBroadcast.h:177
inet::ProbabilisticBroadcast::oneHopLatencies
cOutVector oneHopLatencies
Definition: ProbabilisticBroadcast.h:219
inet::ProbabilisticBroadcast::timeInQueueAfterDeath
simtime_t timeInQueueAfterDeath
How long the message should be kept in queue after its died.
Definition: ProbabilisticBroadcast.h:192
inet::MacAddress::BROADCAST_ADDRESS
static const MacAddress BROADCAST_ADDRESS
The broadcast MAC address, ff:ff:ff:ff:ff:ff.
Definition: MacAddress.h:34
inet::Protocol::probabilistic
static const Protocol probabilistic
Definition: Protocol.h:129
inet::L3Address::getAddressType
IL3AddressType * getAddressType() const
Definition: L3Address.cc:59
inet::NetworkProtocolBase::initialize
virtual void initialize(int stage) override
Definition: NetworkProtocolBase.cc:28
inet::ProbabilisticBroadcast::tMsgDesc
struct inet::ProbabilisticBroadcast::tMsgDesc tMsgDesc
Store messages in a structure so that we can keep some information needed by the protocol.
inet::ProbabilisticBroadcast::msgQueue
TimeMsgMap msgQueue
Definition: ProbabilisticBroadcast.h:208
inet::ProbabilisticBroadcast::decapsulate
virtual void decapsulate(Packet *packet)
extracts and returns the application layer packet which is encapsulated in the network layer packet g...
Definition: ProbabilisticBroadcast.cc:343
inet::ProbabilisticBroadcast::popFirstMessageUpdateQueue
virtual tMsgDesc * popFirstMessageUpdateQueue(void)
Returns the descriptor of the first message in the queue, then remove its pointer from the queue and ...
Definition: ProbabilisticBroadcast.cc:262
inet::NetworkProtocolBase::sendDown
virtual void sendDown(cMessage *message, int interfaceId=-1)
Definition: NetworkProtocolBase.cc:91
inet::ProbabilisticBroadcast::getNextID
static long getNextID()
Definition: ProbabilisticBroadcast.h:166
inet::ProbabilisticBroadcast::BROADCAST_TIMER
@ BROADCAST_TIMER
Definition: ProbabilisticBroadcast.h:56
inet::ProbabilisticBroadcast::setDownControlInfo
virtual void setDownControlInfo(Packet *const pMsg, const MacAddress &pDestAddr)
Attaches a "control info" (NetwToMac) structure (object) to the message pMsg.
Definition: ProbabilisticBroadcast.cc:363