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::OperationalBase 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
 
- Public Member Functions inherited from inet::OperationalBase
 OperationalBase ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 
- 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 Member Functions

virtual void handleUpperPacket (cPacket *msg) override
 Handle messages from upper layer. More...
 
virtual void handleLowerPacket (cPacket *msg) 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 cPacket * encapsMsg (cPacket *msg)
 Returns a network layer packet which encapsulates the upper layer packet passed to the function. More...
 
virtual cPacket * decapsMsg (ProbabilisticBroadcastDatagram *msg)
 extracts and returns the application layer packet which is encapsulated in the network layer packet given in argument. More...
 
virtual void insertNewMessage (ProbabilisticBroadcastDatagram *pkt, bool iAmInitialSender=false)
 Insert a new message in both known ID list and message queue. More...
 
virtual cObject * setDownControlInfo (cMessage *const pMsg, const MACAddress &pDestAddr)
 Attaches a "control info" (NetwToMac) structure (object) to the message pMsg. More...
 
- Protected Member Functions inherited from inet::NetworkProtocolBase
 NetworkProtocolBase ()
 
virtual void handleUpperCommand (cMessage *message) override
 
virtual void sendUp (cMessage *message, int transportProtocol)
 
virtual void sendDown (cMessage *message, int interfaceId=-1)
 
virtual bool isUpperMessage (cMessage *message) override
 
virtual bool isLowerMessage (cMessage *message) override
 
virtual bool isInitializeStage (int stage) override
 
virtual bool isNodeStartStage (int stage) override
 
virtual bool isNodeShutdownStage (int stage) override
 
- Protected Member Functions inherited from inet::LayeredProtocolBase
virtual void handleMessageWhenUp (cMessage *message) override
 
virtual void handleLowerCommand (cMessage *message)
 
- Protected Member Functions inherited from inet::OperationalBase
virtual void handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual bool handleNodeStart (IDoneCallback *doneCallback)
 
virtual bool handleNodeShutdown (IDoneCallback *doneCallback)
 
virtual void handleNodeCrash ()
 
virtual void setOperational (bool isOperational)
 

Static Protected Member Functions

static long getNextID ()
 

Protected Attributes

simtime_t broadcastPeriod
 Period (in sim time) between two broadcast attempts. More...
 
double beta
 Probability of each broadcast attempt. More...
 
simtime_t timeToLive
 
int maxNbBcast
 Maximal number of broadcast attempts for each packet. More...
 
int 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
 Length of the NetwPkt header Read from omnetpp.ini. More...
 
cMessage * broadcastTimer
 
MsgIdSet knownMsgIds
 
TimeMsgMap msgQueue
 
MsgIdSet debugMsgIdSet
 
long nbDataPacketsReceived
 
long nbDataPacketsSent
 
long nbHops
 
int debugNbMessageKnown
 
long nbDataPacketsForwarded
 
cOutVector oneHopLatencies
 
L3Address myNetwAddr
 
- Protected Attributes inherited from inet::NetworkProtocolBase
ProtocolMapping protocolMapping
 
IInterfaceTableinterfaceTable
 
- Protected Attributes inherited from inet::OperationalBase
bool isOperational
 
simtime_t lastChange
 

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...
 

Additional Inherited Members

- Static Public Attributes inherited from inet::LayeredProtocolBase
static simsignal_t packetSentToUpperSignal = registerSignal("packetSentToUpper")
 
static simsignal_t packetReceivedFromUpperSignal = registerSignal("packetReceivedFromUpper")
 
static simsignal_t packetFromUpperDroppedSignal = registerSignal("packetFromUpperDropped")
 
static simsignal_t packetSentToLowerSignal = registerSignal("packetSentToLower")
 
static simsignal_t packetReceivedFromLowerSignal = registerSignal("packetReceivedFromLower")
 
static simsignal_t packetFromLowerDroppedSignal = registerSignal("packetFromLowerDropped")
 

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

typedef std::set<unsigned int> inet::ProbabilisticBroadcast::MsgIdSet
protected
typedef std::multimap<simtime_t, tMsgDesc *> inet::ProbabilisticBroadcast::TimeMsgMap
protected

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

Member Enumeration Documentation

Enumerator
UNKNOWN 
BROADCAST_TIMER 
NEIGHBOR_TIMER 
BETA_TIMER 
69  {
70  UNKNOWN = 0,
73  BETA_TIMER,
74  };
Definition: ProbabilisticBroadcast.h:70
Definition: ProbabilisticBroadcast.h:72
Definition: ProbabilisticBroadcast.h:73
Definition: ProbabilisticBroadcast.h:71

Constructor & Destructor Documentation

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

Copy constructor is not allowed.

inet::ProbabilisticBroadcast::ProbabilisticBroadcast ( )
inline
42  , broadcastPeriod()
43  , beta(0)
44  , timeToLive()
45  , maxNbBcast(0)
48  , headerLength(0)
49  , broadcastTimer(nullptr)
50  , knownMsgIds()
51  , msgQueue()
52  , debugMsgIdSet()
55  , nbHops(0)
58  , oneHopLatencies()
59  {}
NetworkProtocolBase()
Definition: NetworkProtocolBase.cc:23
int headerLength
Length of the NetwPkt header Read from omnetpp.ini.
Definition: ProbabilisticBroadcast.h:209
MsgIdSet knownMsgIds
Definition: ProbabilisticBroadcast.h:218
int debugNbMessageKnown
Definition: ProbabilisticBroadcast.h:226
MsgIdSet debugMsgIdSet
Definition: ProbabilisticBroadcast.h:220
long nbDataPacketsForwarded
Definition: ProbabilisticBroadcast.h:227
simtime_t broadcastPeriod
Period (in sim time) between two broadcast attempts.
Definition: ProbabilisticBroadcast.h:162
double beta
Probability of each broadcast attempt.
Definition: ProbabilisticBroadcast.h:168
simtime_t timeToLive
Definition: ProbabilisticBroadcast.h:173
int maxNbBcast
Maximal number of broadcast attempts for each packet.
Definition: ProbabilisticBroadcast.h:188
long nbDataPacketsSent
Definition: ProbabilisticBroadcast.h:224
long nbHops
Definition: ProbabilisticBroadcast.h:225
cOutVector oneHopLatencies
Definition: ProbabilisticBroadcast.h:230
int maxFirstBcastBackoff
Maximal back-off before first broadcast attempt [seconds].
Definition: ProbabilisticBroadcast.h:194
TimeMsgMap msgQueue
Definition: ProbabilisticBroadcast.h:219
cMessage * broadcastTimer
Definition: ProbabilisticBroadcast.h:212
simtime_t timeInQueueAfterDeath
How long the message should be kept in queue after its died.
Definition: ProbabilisticBroadcast.h:203
long nbDataPacketsReceived
Definition: ProbabilisticBroadcast.h:223

Member Function Documentation

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

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

Referenced by handleLowerPacket().

225 {
226  auto pos = debugMsgIdSet.find(msgId);
227  return pos != debugMsgIdSet.end();
228 }
MsgIdSet debugMsgIdSet
Definition: ProbabilisticBroadcast.h:220
cPacket * inet::ProbabilisticBroadcast::decapsMsg ( ProbabilisticBroadcastDatagram msg)
protectedvirtual

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

Referenced by handleLowerPacket().

335 {
336  cPacket *m = msg->decapsulate();
337  SimpleNetworkProtocolControlInfo *const controlInfo = new SimpleNetworkProtocolControlInfo();
338  controlInfo->setSourceAddress(msg->getSrcAddr());
339  controlInfo->setProtocol(msg->getTransportProtocol());
340  m->setControlInfo(controlInfo);
341  delete msg;
342  return m;
343 }
value< double, units::m > m
Definition: Units.h:1047
cPacket * inet::ProbabilisticBroadcast::encapsMsg ( cPacket *  msg)
protectedvirtual

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

Referenced by handleUpperPacket().

273 {
274  ProbabilisticBroadcastDatagram *pkt = new ProbabilisticBroadcastDatagram(msg->getName());
275  cObject *controlInfo = msg->removeControlInfo();
276  INetworkProtocolControlInfo *networkControlInfo = check_and_cast<INetworkProtocolControlInfo *>(controlInfo);
277  L3Address broadcastAddress = myNetwAddr.getAddressType()->getBroadcastAddress();
278 
279  ASSERT(networkControlInfo);
280  pkt->setByteLength(headerLength);
281  pkt->setSrcAddr(myNetwAddr);
282  pkt->setDestAddr(broadcastAddress);
283  pkt->setInitialSrcAddr(myNetwAddr);
284  pkt->setFinalDestAddr(broadcastAddress);
285  pkt->setAppTtl(timeToLive);
286  pkt->setId(getNextID());
287  pkt->setTransportProtocol(networkControlInfo->getTransportProtocol());
288 
290  //encapsulate the application packet
291  pkt->encapsulate(msg);
292 
293  // clean-up
294  delete controlInfo;
295 
296  return pkt;
297 }
int headerLength
Length of the NetwPkt header Read from omnetpp.ini.
Definition: ProbabilisticBroadcast.h:209
IL3AddressType * getAddressType() const
Definition: L3Address.cc:60
simtime_t timeToLive
Definition: ProbabilisticBroadcast.h:173
static long getNextID()
Definition: ProbabilisticBroadcast.h:177
virtual cObject * setDownControlInfo(cMessage *const pMsg, const MACAddress &pDestAddr)
Attaches a "control info" (NetwToMac) structure (object) to the message pMsg.
Definition: ProbabilisticBroadcast.cc:348
virtual L3Address getBroadcastAddress() const =0
L3Address myNetwAddr
Definition: ProbabilisticBroadcast.h:232
static const MACAddress BROADCAST_ADDRESS
The broadcast MAC address, ff:ff:ff:ff:ff:ff.
Definition: MACAddress.h:60
void inet::ProbabilisticBroadcast::finish ( )
overridevirtual
196 {
197  EV << "PBr: " << simTime() << " n" << myNetwAddr << " finish()" << endl;
198  cancelAndDelete(broadcastTimer);
199  // if some messages are still in the queue, delete them.
200  while (!msgQueue.empty()) {
201  auto pos = msgQueue.begin();
202  tMsgDesc *msgDesc = pos->second;
203  msgQueue.erase(pos);
204  delete msgDesc->pkt;
205  delete msgDesc;
206  }
207  recordScalar("nbDataPacketsReceived", nbDataPacketsReceived);
208  recordScalar("debugNbMessageKnown", debugNbMessageKnown);
209  recordScalar("nbDataPacketsForwarded", nbDataPacketsForwarded);
210  if (nbDataPacketsReceived > 0) {
211  recordScalar("meanNbHops", (double)nbHops / (double)nbDataPacketsReceived);
212  }
213  else {
214  recordScalar("meanNbHops", 0);
215  }
216 }
int debugNbMessageKnown
Definition: ProbabilisticBroadcast.h:226
long nbDataPacketsForwarded
Definition: ProbabilisticBroadcast.h:227
long nbHops
Definition: ProbabilisticBroadcast.h:225
L3Address myNetwAddr
Definition: ProbabilisticBroadcast.h:232
TimeMsgMap msgQueue
Definition: ProbabilisticBroadcast.h:219
cMessage * broadcastTimer
Definition: ProbabilisticBroadcast.h:212
struct inet::ProbabilisticBroadcast::tMsgDesc tMsgDesc
Store messages in a structure so that we can keep some information needed by the protocol.
long nbDataPacketsReceived
Definition: ProbabilisticBroadcast.h:223
static long inet::ProbabilisticBroadcast::getNextID ( )
inlinestaticprotected

Referenced by encapsMsg().

178  {
179  long nextID = id_counter;
180  id_counter++;
181  return nextID;
182  }
static long id_counter
Definition: ProbabilisticBroadcast.h:175
void inet::ProbabilisticBroadcast::handleLowerPacket ( cPacket *  msg)
overrideprotectedvirtual

Handle messages from lower layer.

Implements inet::LayeredProtocolBase.

Reimplemented in inet::AdaptiveProbabilisticBroadcast.

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

62 {
63  MACAddress macSrcAddr;
64  ProbabilisticBroadcastDatagram *m = check_and_cast<ProbabilisticBroadcastDatagram *>(msg);
65  IMACProtocolControlInfo *cInfo = check_and_cast<IMACProtocolControlInfo *>(m->removeControlInfo());
66  m->setNbHops(m->getNbHops() + 1);
67  macSrcAddr = cInfo->getSourceAddress();
68  delete cInfo;
70  nbHops = nbHops + m->getNbHops();
71  oneHopLatencies.record(SIMTIME_DBL(simTime() - m->getTimestamp()));
72  // oneHopLatency gives us an estimate of how long the message spent in the MAC queue of
73  // its sender (compared to that, transmission delay is negligible). Use this value
74  // to update the TTL of the message. Dump it if it is dead.
75  //m->setAppTtl(m->getAppTtl().dbl() - oneHopLatency);
76  if ( /*(m->getAppTtl() <= 0) || */ (messageKnown(m->getId()))) {
77  // we got this message already, ignore it.
78  EV << "PBr: " << simTime() << " n" << myNetwAddr << " handleLowerMsg(): Dead or Known message ID=" << m->getId() << " from node "
79  << macSrcAddr << " TTL = " << m->getAppTtl() << endl;
80  delete m;
81  }
82  else {
83  if (debugMessageKnown(m->getId())) {
85  EV << "PBr: " << simTime() << " n" << myNetwAddr << " ERROR Message should be known TTL= " << m->getAppTtl() << endl;
86  }
87  EV << "PBr: " << simTime() << " n" << myNetwAddr << " handleLowerMsg(): Unknown message ID=" << m->getId() << " from node "
88  << macSrcAddr << endl;
89  // Unknown message. Insert message in queue with random backoff broadcast delay.
90  // Because we got the message from lower layer, we need to create and add a new
91  // control info with the MAC destination address = broadcast address.
93  // before inserting message, update source address (for this hop, not the initial source)
94  m->setSrcAddr(myNetwAddr);
96 
97  // until a subscription mechanism is implemented, duplicate and pass all received packets
98  // to the application layer who will be able to compute statistics.
99  // TODO: implement an application subscription mechanism.
100  if (true) {
101  int protocol = m->getTransportProtocol();
102  ProbabilisticBroadcastDatagram *mCopy = check_and_cast<ProbabilisticBroadcastDatagram *>(m->dup());
103  sendUp(decapsMsg(mCopy), protocol);
104  }
105  }
106 }
int debugNbMessageKnown
Definition: ProbabilisticBroadcast.h:226
uint8_t protocol
Definition: TCP_NSC.cc:88
virtual bool messageKnown(unsigned int msgId)
Checks whether a message is known (= kept in memory) or not.
Definition: ProbabilisticBroadcast.cc:218
virtual void sendUp(cMessage *message, int transportProtocol)
Definition: NetworkProtocolBase.cc:46
long nbHops
Definition: ProbabilisticBroadcast.h:225
virtual cPacket * decapsMsg(ProbabilisticBroadcastDatagram *msg)
extracts and returns the application layer packet which is encapsulated in the network layer packet g...
Definition: ProbabilisticBroadcast.cc:334
cOutVector oneHopLatencies
Definition: ProbabilisticBroadcast.h:230
virtual cObject * setDownControlInfo(cMessage *const pMsg, const MACAddress &pDestAddr)
Attaches a "control info" (NetwToMac) structure (object) to the message pMsg.
Definition: ProbabilisticBroadcast.cc:348
L3Address myNetwAddr
Definition: ProbabilisticBroadcast.h:232
virtual void insertNewMessage(ProbabilisticBroadcastDatagram *pkt, bool iAmInitialSender=false)
Insert a new message in both known ID list and message queue.
Definition: ProbabilisticBroadcast.cc:299
virtual bool debugMessageKnown(unsigned int msgId)
Checks whether a message is known (= kept in memory) or not.
Definition: ProbabilisticBroadcast.cc:224
long nbDataPacketsReceived
Definition: ProbabilisticBroadcast.h:223
value< double, units::m > m
Definition: Units.h:1047
static const MACAddress BROADCAST_ADDRESS
The broadcast MAC address, ff:ff:ff:ff:ff:ff.
Definition: MACAddress.h:60
void inet::ProbabilisticBroadcast::handleSelfMessage ( cMessage *  msg)
overrideprotectedvirtual

Handle self messages.

Reimplemented from inet::LayeredProtocolBase.

Reimplemented in inet::AdaptiveProbabilisticBroadcast.

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

109 {
110  if (msg == broadcastTimer) {
111  tMsgDesc *msgDesc;
112  ProbabilisticBroadcastDatagram *pkt;
113 
114  // called method pops the first message from the message queue and
115  // schedules the message timer for the next one. The message is embedded
116  // into a container of type tMsgDesc.
117  msgDesc = popFirstMessageUpdateQueue();
118  pkt = msgDesc->pkt;
119  // if the packet is alive, duplicate it and insert the copy in the queue,
120  // then perform a broadcast attempt.
121  EV << "PBr: " << simTime() << " n" << myNetwAddr << " handleSelfMsg(): Message ID= " << pkt->getId() << " TTL= " << pkt->getAppTtl() << endl;
122  if (pkt->getAppTtl() > 0) {
123  // check if we are allowed to re-transmit the message on more time.
124  if (msgDesc->nbBcast < maxNbBcast) {
125  ProbabilisticBroadcastDatagram *pktCopy;
126  bool sendForSure = msgDesc->initialSend;
127 
128  // duplicate packet and insert the copy in the queue.
129  // two possibilities: the packet will be alive at next
130  // broadcast period => insert it with delay = broadcastPeriod.
131  // Or the packet will be dead at next broadcast period (TTL <= broadcastPeriod)
132  // => insert it with delay = TTL. So when the copy will be popped out of the
133  // queue, it will be considered as dead and discarded.
134  pktCopy = pkt->dup();
135  // control info is not duplicated with the message, so we have to re-create one here.
137  // it the copy that is re-inserted into the queue so update the container accordingly
138  msgDesc->pkt = pktCopy;
139  // increment nbBcast field of the descriptor because at this point, it is sure that
140  // the message will go through one more broadcast attempt.
141  msgDesc->nbBcast++;
142  // for sure next broadcast attempt will not be the initial one.
143  msgDesc->initialSend = false;
144  // if msg TTL > broadcast period, the message will be broadcasted one more
145  // time, insert it with delay = broadcast period. Otherwise, the message
146  // will be dead at next broadcast attempt. Keep it in the list with
147  // delay = TTL + timeInQueueAfterDeath. insertMessage() will update its
148  // TTL to -timeInQueueAfterDeath, a negative value. That way, the message
149  // is known to the system, de-synchronization between copies of the same message
150  // is therefore handled and when the message will be popped out, its TTL will
151  // be smaller than zero, thus the message will be discarded, not broadcasted.
152  if (pktCopy->getAppTtl() > broadcastPeriod)
153  insertMessage(broadcastPeriod, msgDesc);
154  else
155  insertMessage(pktCopy->getAppTtl() + timeInQueueAfterDeath, msgDesc);
156  // broadcast the message with probability beta
157  if (sendForSure) {
158  EV << "PBr: " << simTime() << " n" << myNetwAddr << " Send packet down for sure." << endl;
159  pkt->setTimestamp();
160  sendDown(pkt);
162  }
163  else {
164  if (bernoulli(beta)) {
165  EV << "PBr: " << simTime() << " n" << myNetwAddr << " Bernoulli test result: TRUE. Send packet down." << endl;
166  pkt->setTimestamp();
167  sendDown(pkt);
169  }
170  else {
171  EV << "PBr: " << simTime() << " n" << myNetwAddr << " Bernoulli test result: FALSE" << endl;
172  delete pkt;
173  }
174  }
175  }
176  else {
177  // we can't re-transmit the message because maxNbBcast is reached.
178  // re-insert-it in the queue with delay = TTL so that its ID is still
179  // known by the system.
180  EV << "PBr: " << simTime() << " n" << myNetwAddr << " maxNbBcast reached." << endl;
181  insertMessage(pkt->getAppTtl() + timeInQueueAfterDeath, msgDesc);
182  }
183  }
184  else {
185  EV << "PBr: " << simTime() << " n" << myNetwAddr << " Message TTL zero, discard." << endl;
186  delete msgDesc;
187  delete pkt;
188  }
189  }
190  else {
191  EV << "PBr: " << simTime() << " n" << myNetwAddr << " Received unexpected self message" << endl;
192  }
193 }
long nbDataPacketsForwarded
Definition: ProbabilisticBroadcast.h:227
simtime_t broadcastPeriod
Period (in sim time) between two broadcast attempts.
Definition: ProbabilisticBroadcast.h:162
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:251
double beta
Probability of each broadcast attempt.
Definition: ProbabilisticBroadcast.h:168
int maxNbBcast
Maximal number of broadcast attempts for each packet.
Definition: ProbabilisticBroadcast.h:188
virtual void insertMessage(simtime_t_cref bcastDelay, tMsgDesc *msgDesc)
Insert a message in both known ID list and message queue.
Definition: ProbabilisticBroadcast.cc:230
virtual cObject * setDownControlInfo(cMessage *const pMsg, const MACAddress &pDestAddr)
Attaches a "control info" (NetwToMac) structure (object) to the message pMsg.
Definition: ProbabilisticBroadcast.cc:348
L3Address myNetwAddr
Definition: ProbabilisticBroadcast.h:232
cMessage * broadcastTimer
Definition: ProbabilisticBroadcast.h:212
struct inet::ProbabilisticBroadcast::tMsgDesc tMsgDesc
Store messages in a structure so that we can keep some information needed by the protocol.
simtime_t timeInQueueAfterDeath
How long the message should be kept in queue after its died.
Definition: ProbabilisticBroadcast.h:203
virtual void sendDown(cMessage *message, int interfaceId=-1)
Definition: NetworkProtocolBase.cc:53
static const MACAddress BROADCAST_ADDRESS
The broadcast MAC address, ff:ff:ff:ff:ff:ff.
Definition: MACAddress.h:60
void inet::ProbabilisticBroadcast::handleUpperPacket ( cPacket *  msg)
overrideprotectedvirtual

Handle messages from upper layer.

Implements inet::LayeredProtocolBase.

50 {
51  ProbabilisticBroadcastDatagram *pkt;
52 
53  // encapsulate message in a network layer packet.
54  pkt = check_and_cast<ProbabilisticBroadcastDatagram *>(encapsMsg(check_and_cast<cPacket *>(msg)));
56  EV << "PBr: " << simTime() << " n" << myNetwAddr << " handleUpperMsg(): Pkt ID = " << pkt->getId() << " TTL = " << pkt->getAppTtl() << endl;
57  // submit packet for first insertion in queue.
58  insertNewMessage(pkt, true);
59 }
virtual cPacket * encapsMsg(cPacket *msg)
Returns a network layer packet which encapsulates the upper layer packet passed to the function...
Definition: ProbabilisticBroadcast.cc:272
long nbDataPacketsSent
Definition: ProbabilisticBroadcast.h:224
L3Address myNetwAddr
Definition: ProbabilisticBroadcast.h:232
virtual void insertNewMessage(ProbabilisticBroadcastDatagram *pkt, bool iAmInitialSender=false)
Insert a new message in both known ID list and message queue.
Definition: ProbabilisticBroadcast.cc:299
void inet::ProbabilisticBroadcast::initialize ( int  stage)
overridevirtual

Reimplemented from inet::NetworkProtocolBase.

Reimplemented in inet::AdaptiveProbabilisticBroadcast.

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

26 {
28  if (stage == INITSTAGE_LOCAL) {
29  broadcastPeriod = par("bcperiod");
30  beta = par("beta");
31  maxNbBcast = par("maxNbBcast");
32  headerLength = par("headerLength");
33  timeInQueueAfterDeath = par("timeInQueueAfterDeath");
34  timeToLive = par("timeToLive");
35  broadcastTimer = new cMessage("broadcastTimer");
36  maxFirstBcastBackoff = par("maxFirstBcastBackoff");
37  oneHopLatencies.setName("oneHopLatencies");
42  nbHops = 0;
43  }
44  else if (stage == INITSTAGE_NETWORK_LAYER_3) {
46  }
47 }
virtual void initialize(int stage) override
Definition: NetworkProtocolBase.cc:28
int headerLength
Length of the NetwPkt header Read from omnetpp.ini.
Definition: ProbabilisticBroadcast.h:209
int debugNbMessageKnown
Definition: ProbabilisticBroadcast.h:226
Initialization of network-layer protocols, stage 3.
Definition: InitStages.h:84
long nbDataPacketsForwarded
Definition: ProbabilisticBroadcast.h:227
simtime_t broadcastPeriod
Period (in sim time) between two broadcast attempts.
Definition: ProbabilisticBroadcast.h:162
Local initializations.
Definition: InitStages.h:35
IInterfaceTable * interfaceTable
Definition: NetworkProtocolBase.h:32
double beta
Probability of each broadcast attempt.
Definition: ProbabilisticBroadcast.h:168
simtime_t timeToLive
Definition: ProbabilisticBroadcast.h:173
int maxNbBcast
Maximal number of broadcast attempts for each packet.
Definition: ProbabilisticBroadcast.h:188
long nbDataPacketsSent
Definition: ProbabilisticBroadcast.h:224
long nbHops
Definition: ProbabilisticBroadcast.h:225
cOutVector oneHopLatencies
Definition: ProbabilisticBroadcast.h:230
const L3Address getNetworkAddress() const
Definition: InterfaceEntry.cc:239
L3Address myNetwAddr
Definition: ProbabilisticBroadcast.h:232
int maxFirstBcastBackoff
Maximal back-off before first broadcast attempt [seconds].
Definition: ProbabilisticBroadcast.h:194
virtual InterfaceEntry * getInterface(int pos) const =0
Returns the InterfaceEntry specified by an index 0..numInterfaces-1.
cMessage * broadcastTimer
Definition: ProbabilisticBroadcast.h:212
simtime_t timeInQueueAfterDeath
How long the message should be kept in queue after its died.
Definition: ProbabilisticBroadcast.h:203
long nbDataPacketsReceived
Definition: ProbabilisticBroadcast.h:223
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.

Referenced by handleSelfMessage(), and insertNewMessage().

231 {
232  simtime_t bcastTime = simTime() + bcastDelay;
233 
234  EV << "PBr: " << simTime() << " n" << myNetwAddr << " insertMessage() bcastDelay = " << bcastDelay << " Msg ID = " << msgDesc->pkt->getId() << endl;
235  // update TTL field of the message to the value it will have when taken out of the list
236  msgDesc->pkt->setAppTtl(msgDesc->pkt->getAppTtl() - bcastDelay);
237  // insert message ID in ID list.
238  knownMsgIds.insert(msgDesc->pkt->getId());
239  // insert key value pair <broadcast time, pointer to message> in message queue.
240  auto pos = msgQueue.insert(make_pair(bcastTime, msgDesc));
241  // if the message has been inserted in the front of the list, it means that it
242  // will be the next message to be broadcasted, therefore we have to re-schedule
243  // the broadcast timer to the message's broadcast instant.
244  if (pos == msgQueue.begin()) {
245  EV << "PBr: " << simTime() << " n" << myNetwAddr << " message inserted in the front, reschedule it." << endl;
246  cancelEvent(broadcastTimer);
247  scheduleAt(bcastTime, broadcastTimer);
248  }
249 }
MsgIdSet knownMsgIds
Definition: ProbabilisticBroadcast.h:218
L3Address myNetwAddr
Definition: ProbabilisticBroadcast.h:232
TimeMsgMap msgQueue
Definition: ProbabilisticBroadcast.h:219
cMessage * broadcastTimer
Definition: ProbabilisticBroadcast.h:212
void inet::ProbabilisticBroadcast::insertNewMessage ( ProbabilisticBroadcastDatagram pkt,
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.

Referenced by handleLowerPacket(), and handleUpperPacket().

300 {
301  simtime_t ttl = pkt->getAppTtl();
302 
303  if (ttl > 0) {
304  simtime_t bcastDelay;
305  tMsgDesc *msgDesc;
306 
307  // insert packet in queue with delay in [0, min(TTL, broadcast period)].
308  // since the insertion schedules the message for its first broadcast attempt,
309  // we use a uniform random back-off taken between now and the broadcast delay
310  // to avoid having all nodes in the neighborhood forward the packet at the same
311  // time. Backoffs used at MAC layer are thought to be too short.
313  bcastDelay = broadcastPeriod;
314  else
315  bcastDelay = maxFirstBcastBackoff;
316  if (bcastDelay > ttl)
317  bcastDelay = ttl;
318  EV << "PBr: " << simTime() << " n" << myNetwAddr << " insertNewMessage(): insert packet " << pkt->getId() << " with delay "
319  << bcastDelay << endl;
320  // create container for message and initialize container's values.
321  msgDesc = new tMsgDesc;
322  msgDesc->pkt = pkt;
323  msgDesc->nbBcast = 0; // so far, pkt has been forwarded zero times.
324  msgDesc->initialSend = iAmInitialSender;
325  debugMsgIdSet.insert(pkt->getId());
326  insertMessage(uniform(0, bcastDelay), msgDesc);
327  }
328  else {
329  EV << "PBr: " << simTime() << " n" << myNetwAddr << " insertNewMessage(): got new packet with TTL = 0." << endl;
330  delete pkt;
331  }
332 }
MsgIdSet debugMsgIdSet
Definition: ProbabilisticBroadcast.h:220
ProbabilisticBroadcastDatagram * pkt
Definition: ProbabilisticBroadcast.h:81
simtime_t broadcastPeriod
Period (in sim time) between two broadcast attempts.
Definition: ProbabilisticBroadcast.h:162
virtual void insertMessage(simtime_t_cref bcastDelay, tMsgDesc *msgDesc)
Insert a message in both known ID list and message queue.
Definition: ProbabilisticBroadcast.cc:230
L3Address myNetwAddr
Definition: ProbabilisticBroadcast.h:232
int maxFirstBcastBackoff
Maximal back-off before first broadcast attempt [seconds].
Definition: ProbabilisticBroadcast.h:194
struct inet::ProbabilisticBroadcast::tMsgDesc tMsgDesc
Store messages in a structure so that we can keep some information needed by the protocol.
uint8_t ttl
Definition: TCP_NSC.cc:87
bool inet::ProbabilisticBroadcast::messageKnown ( unsigned int  msgId)
protectedvirtual

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

Referenced by handleLowerPacket().

219 {
220  auto pos = knownMsgIds.find(msgId);
221  return pos != knownMsgIds.end();
222 }
MsgIdSet knownMsgIds
Definition: ProbabilisticBroadcast.h:218
virtual int inet::ProbabilisticBroadcast::numInitStages ( ) const
inlineoverridevirtual

Initialization of the module and some variables.

Reimplemented from inet::OperationalBase.

62 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
ProbabilisticBroadcast& inet::ProbabilisticBroadcast::operator= ( const ProbabilisticBroadcast )
private

Assignment operator is not allowed.

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.

Referenced by handleSelfMessage().

252 {
253  tMsgDesc *msgDesc;
254 
255  // get first message.
256  ASSERT(!msgQueue.empty());
257  auto pos = msgQueue.begin();
258  msgDesc = pos->second;
259  // remove first message from message queue and from ID list
260  msgQueue.erase(pos);
261  knownMsgIds.erase(msgDesc->pkt->getId());
262  EV << "PBr: " << simTime() << " n" << myNetwAddr << " pop(): just popped msg " << msgDesc->pkt->getId() << endl;
263  if (!msgQueue.empty()) {
264  // schedule broadcast of new first message
265  EV << "PBr: " << simTime() << " n" << myNetwAddr << " pop(): schedule next message." << endl;
266  pos = msgQueue.begin();
267  scheduleAt(pos->first, broadcastTimer);
268  }
269  return msgDesc;
270 }
MsgIdSet knownMsgIds
Definition: ProbabilisticBroadcast.h:218
L3Address myNetwAddr
Definition: ProbabilisticBroadcast.h:232
TimeMsgMap msgQueue
Definition: ProbabilisticBroadcast.h:219
cMessage * broadcastTimer
Definition: ProbabilisticBroadcast.h:212
struct inet::ProbabilisticBroadcast::tMsgDesc tMsgDesc
Store messages in a structure so that we can keep some information needed by the protocol.
cObject * inet::ProbabilisticBroadcast::setDownControlInfo ( cMessage *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.

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

349 {
350  SimpleLinkLayerControlInfo *const cCtrlInfo = new SimpleLinkLayerControlInfo();
351  cCtrlInfo->setDest(pDestAddr);
352  pMsg->setControlInfo(cCtrlInfo);
353  return cCtrlInfo;
354 }

Member Data Documentation

double inet::ProbabilisticBroadcast::beta
protected

Probability of each broadcast attempt.

Read from omnetpp.ini

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

simtime_t inet::ProbabilisticBroadcast::broadcastPeriod
protected

Period (in sim time) between two broadcast attempts.

Read from omnetpp.ini

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

cMessage* inet::ProbabilisticBroadcast::broadcastTimer
protected
MsgIdSet inet::ProbabilisticBroadcast::debugMsgIdSet
protected
int inet::ProbabilisticBroadcast::debugNbMessageKnown
protected
int inet::ProbabilisticBroadcast::headerLength
protected

Length of the NetwPkt header Read from omnetpp.ini.

Referenced by encapsMsg(), and initialize().

long inet::ProbabilisticBroadcast::id_counter = 0
staticprotected
MsgIdSet inet::ProbabilisticBroadcast::knownMsgIds
protected
int inet::ProbabilisticBroadcast::maxFirstBcastBackoff
protected

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

Read from omnetpp.ini

Referenced by initialize(), and insertNewMessage().

int inet::ProbabilisticBroadcast::maxNbBcast
protected

Maximal number of broadcast attempts for each packet.

Read from omnetpp.ini

Referenced by handleSelfMessage(), and initialize().

TimeMsgMap inet::ProbabilisticBroadcast::msgQueue
protected
long inet::ProbabilisticBroadcast::nbDataPacketsForwarded
protected
long inet::ProbabilisticBroadcast::nbDataPacketsReceived
protected
long inet::ProbabilisticBroadcast::nbDataPacketsSent
protected

Referenced by handleUpperPacket(), and initialize().

long inet::ProbabilisticBroadcast::nbHops
protected
cOutVector inet::ProbabilisticBroadcast::oneHopLatencies
protected

Referenced by handleLowerPacket(), and initialize().

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().

simtime_t inet::ProbabilisticBroadcast::timeToLive
protected

Referenced by encapsMsg(), and initialize().


The documentation for this class was generated from the following files: