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. More...
#include <ProbabilisticBroadcast.h>
Inherits BaseNetwLayer.
Inherited by AdaptiveProbabilisticBroadcast.
Classes | |
struct | tMsgDesc |
Store messages in a structure so that we can keep some information needed by the protocol. More... | |
Public Member Functions | |
virtual void | initialize (int) |
Initialization of the module and some variables. | |
virtual void | finish () |
Called when the simulation has finished. | |
Protected Types | |
enum | messagesTypes { UNKNOWN = 0, BROADCAST_TIMER, NEIGHBOR_TIMER, BETA_TIMER, DATA } |
typedef struct ProbabilisticBroadcast::tMsgDesc | tMsgDesc |
Store messages in a structure so that we can keep some information needed by the protocol. | |
typedef set< unsigned int > | MsgIdSet |
typedef multimap< simtime_t, tMsgDesc * > | TimeMsgMap |
Protected Member Functions | |
virtual void | handleUpperMsg (cMessage *msg) |
Handle messages from upper layer. | |
virtual void | handleLowerMsg (cMessage *msg) |
Handle messages from lower layer. | |
virtual void | handleSelfMsg (cMessage *msg) |
Handle self messages. | |
virtual void | handleLowerControl (cMessage *msg) |
Handle control messages from lower layer. | |
virtual bool | messageKnown (unsigned int msgId) |
Checks whether a message is known (= kept in memory) or not. | |
virtual bool | debugMessageKnown (unsigned int msgId) |
Checks whether a message is known (= kept in memory) or not. | |
virtual void | insertMessage (simtime_t bcastDelay, tMsgDesc *msgDesc) |
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. | |
virtual tMsgDesc * | popFirstMessageUpdateQueue (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. Then re-schedule the broadcastTimer to the broadcast instant of the new first element in the list. | |
virtual ProbabilisticBroadcastPkt * | encapsMsg (cMessage *msg) |
Returns a network layer packet which encapsulates the upper layer packet passed to the function. | |
virtual cMessage * | decapsMsg (ProbabilisticBroadcastPkt *msg) |
extracts and returns the application layer packet which is encapsulated in the network layer packet given in argument. | |
virtual void | insertNewMessage (ProbabilisticBroadcastPkt *pkt, bool iAmInitialSender=false) |
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. | |
Static Protected Member Functions | |
static long | getNextID () |
Protected Attributes | |
simtime_t | broadcastPeriod |
Period (in sim time) between two broadcast attempts. Read from omnetpp.ini. | |
double | beta |
Probability of each broadcast attempt. Read from omnetpp.ini. | |
simtime_t | timeToLive |
int | maxNbBcast |
Maximal number of broadcast attempts for each packet. Read from omnetpp.ini. | |
int | maxFirstBcastBackoff |
Maximal back-off before first broadcast attempt [seconds]. Read from omnetpp.ini. | |
simtime_t | timeInQueueAfterDeath |
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. | |
int | headerLength |
Length of the NetwPkt header Read from omnetpp.ini. | |
bool | trace |
bool | stats |
bool | debug |
Debug switch for all other modules. | |
cMessage * | broadcastTimer |
MsgIdSet | knownMsgIds |
TimeMsgMap | msgQueue |
MsgIdSet | debugMsgIdSet |
int | convertedMacBroadcastAddr |
long | nbDataPacketsReceived |
long | nbDataPacketsSent |
long | nbHops |
int | debugNbMessageKnown |
long | nbDataPacketsForwarded |
cOutVector | oneHopLatencies |
Static Protected Attributes | |
static long | id_counter = 0 |
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.
Definition at line 36 of file ProbabilisticBroadcast.h.
void ProbabilisticBroadcast::insertMessage | ( | simtime_t | bcastDelay, | |
tMsgDesc * | msgDesc | |||
) | [protected, virtual] |
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.
bcastDelay | relative (to now) simulator time of next broadcast attempt. | |
msg | descriptor of the message to insert in the queue. |
Definition at line 238 of file ProbabilisticBroadcast.cc.
References BaseNetwLayer::myNetwAddr.
Referenced by handleSelfMsg(), and insertNewMessage().
{ TimeMsgMap::iterator pos; simtime_t bcastTime = simTime() + bcastDelay; EV << "PBr: " << simTime() << " n" << myNetwAddr << " insertMessage() bcastDelay = " << bcastDelay << " Msg ID = " << msgDesc->pkt->getId() << endl; // update TTL field of the message to the value it will have when taken out of the list msgDesc->pkt->setAppTtl(msgDesc->pkt->getAppTtl() - bcastDelay); // insert message ID in ID list. knownMsgIds.insert(msgDesc->pkt->getId()); // insert key value pair <broadcast time, pointer to message> in message queue. pos = msgQueue.insert(make_pair(bcastTime, msgDesc)); // if the message has been inserted in the front of the list, it means that it // will be the next message to be broadcasted, therefore we have to re-schedule // the broadcast timer to the message's broadcast instant. if (pos == msgQueue.begin()) { EV << "PBr: " << simTime() << " n" << myNetwAddr << " message inserted in the front, reschedule it." << endl; cancelEvent(broadcastTimer); scheduleAt(bcastTime, broadcastTimer); } }
void ProbabilisticBroadcast::insertNewMessage | ( | ProbabilisticBroadcastPkt * | pkt, | |
bool | iAmInitialSender = false | |||
) | [protected, virtual] |
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.
msgDesc | descriptor of the message to insert in the queue. | |
iAmInitialSender | message comes from upper layer, I am its creator and initial sender. |
Definition at line 309 of file ProbabilisticBroadcast.cc.
References broadcastPeriod, insertMessage(), maxFirstBcastBackoff, and BaseNetwLayer::myNetwAddr.
Referenced by handleLowerMsg(), and handleUpperMsg().
{ simtime_t ttl = pkt->getAppTtl(); if (ttl > 0) { simtime_t bcastDelay; tMsgDesc* msgDesc; // insert packet in queue with delay in [0, min(TTL, broadcast period)]. // since the insertion schedules the message for its first broadcast attempt, // we use a uniform random back-off taken between now and the broadcast delay // to avoid having all nodes in the neighborhood forward the packet at the same // time. Backoffs used at MAC layer are thought to be too short. if (broadcastPeriod < maxFirstBcastBackoff) bcastDelay = broadcastPeriod; else bcastDelay = maxFirstBcastBackoff; if (bcastDelay > ttl) bcastDelay = ttl; EV << "PBr: " << simTime() << " n" << myNetwAddr << " insertNewMessage(): insert packet " << pkt->getId() << " with delay " << bcastDelay << endl; // create container for message and initialize container's values. msgDesc = new tMsgDesc; msgDesc->pkt = pkt; msgDesc->nbBcast = 0; // so far, pkt has been forwarded zero times. msgDesc->initialSend = iAmInitialSender; debugMsgIdSet.insert(pkt->getId()); insertMessage(uniform(0, bcastDelay), msgDesc); } else { EV << "PBr: " << simTime() << " n" << myNetwAddr << " insertNewMessage(): got new packet with TTL = 0." << endl; delete pkt; } }