|
INET Framework for OMNeT++/OMNEST
|
This class offers a data dissemination service using probabilistic broadcast.
More...
#include <ProbabilisticBroadcast.h>
|
| struct | tMsgDesc |
| | Store messages in a structure so that we can keep some information needed by the protocol. More...
|
| |
|
| | ProbabilisticBroadcast () |
| |
| virtual int | numInitStages () const override |
| | Initialization of the module and some variables. More...
|
| |
| virtual void | initialize (int) override |
| |
| virtual void | finish () override |
| |
| const Protocol & | getProtocol () const override |
| |
| virtual void | handleRegisterService (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) override |
| |
| virtual void | handleRegisterProtocol (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) override |
| |
| virtual | ~OperationalMixin () |
| | }@ More...
|
| |
| virtual | ~ILifecycle () |
| |
| 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 |
| |
| virtual | ~INetworkProtocol () |
| |
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
◆ MsgIdSet
◆ TimeMsgMap
◆ tMsgDesc
Store messages in a structure so that we can keep some information needed by the protocol.
◆ messagesTypes
| Enumerator |
|---|
| UNKNOWN | |
| BROADCAST_TIMER | |
| NEIGHBOR_TIMER | |
| BETA_TIMER | |
◆ ProbabilisticBroadcast() [1/2]
Copy constructor is not allowed.
◆ ProbabilisticBroadcast() [2/2]
| inet::ProbabilisticBroadcast::ProbabilisticBroadcast |
( |
| ) |
|
|
inline |
◆ debugMessageKnown()
| bool inet::ProbabilisticBroadcast::debugMessageKnown |
( |
unsigned int |
msgId | ) |
|
|
protectedvirtual |
Checks whether a message is known (= kept in memory) or not.
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.
345 auto networkHeader = packet->popAtFront<ProbabilisticBroadcastHeader>();
346 auto payloadLength = networkHeader->getPayloadLengthField();
347 if (packet->getDataLength() < payloadLength) {
348 throw cRuntimeError(
"Data error: illegal payload length");
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);
357 packet->addTagIfAbsent<
L3AddressInd>()->setSrcAddress(networkHeader->getSrcAddr());
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.
285 auto pkt = makeShared<ProbabilisticBroadcastHeader>();
286 cObject *controlInfo = packet->removeControlInfo();
291 pkt->setDestAddr(broadcastAddress);
293 pkt->setFinalDestAddr(broadcastAddress);
297 pkt->setPayloadLengthField(packet->getDataLength());
302 packet->insertAtFront(pkt);
Referenced by handleUpperPacket().
◆ finish()
| void inet::ProbabilisticBroadcast::finish |
( |
| ) |
|
|
overridevirtual |
208 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" finish()" << endl;
225 recordScalar(
"meanNbHops", 0);
◆ getNextID()
| static long inet::ProbabilisticBroadcast::getNextID |
( |
| ) |
|
|
inlinestaticprotected |
◆ getProtocol()
| const Protocol& inet::ProbabilisticBroadcast::getProtocol |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ handleCrashOperation()
| virtual void inet::ProbabilisticBroadcast::handleCrashOperation |
( |
LifecycleOperation * |
operation | ) |
|
|
inlineoverrideprotectedvirtual |
◆ handleLowerPacket()
| void inet::ProbabilisticBroadcast::handleLowerPacket |
( |
Packet * |
packet | ) |
|
|
overrideprotectedvirtual |
Handle messages from lower layer.
Reimplemented from inet::LayeredProtocolBase.
Reimplemented in inet::AdaptiveProbabilisticBroadcast.
73 MacAddress macSrcAddr;
74 auto macHeader = dynamicPtrCast<ProbabilisticBroadcastHeader>(packet->popAtFront<ProbabilisticBroadcastHeader>()->dupShared());
76 auto macAddressInd = packet->getTag<MacAddressInd>();
77 macHeader->setNbHops(macHeader->getNbHops() + 1);
78 macSrcAddr = macAddressInd->getSrcAddress();
79 delete packet->removeControlInfo();
82 oneHopLatencies.record(SIMTIME_DBL(simTime() - packet->getTimestamp()));
89 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" handleLowerMsg(): Dead or Known message ID=" << macHeader->getId() <<
" from node "
90 << macSrcAddr <<
" TTL = " << macHeader->getAppTtl() << endl;
96 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" ERROR Message should be known TTL= " << macHeader->getAppTtl() << endl;
98 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" handleLowerMsg(): Unknown message ID=" << macHeader->getId() <<
" from node "
99 << macSrcAddr << endl;
106 packet->insertAtFront(macHeader);
113 auto mCopy = packet->dup();
Referenced by inet::AdaptiveProbabilisticBroadcast::handleLowerPacket().
◆ handleSelfMessage()
| void inet::ProbabilisticBroadcast::handleSelfMessage |
( |
cMessage * |
msg | ) |
|
|
overrideprotectedvirtual |
Handle self messages.
Reimplemented from inet::LayeredProtocolBase.
Reimplemented in inet::AdaptiveProbabilisticBroadcast.
128 auto packet = msgDesc->pkt;
129 auto macHeader = packet->peekAtFront<ProbabilisticBroadcastHeader>();
132 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" handleSelfMsg(): Message ID= " << macHeader->getId() <<
" TTL= " << macHeader->getAppTtl() << endl;
133 if (macHeader->getAppTtl() > 0) {
136 bool sendForSure = msgDesc->initialSend;
144 auto packetCopy = packet->dup();
145 auto macHeaderCopy = packetCopy->peekAtFront<ProbabilisticBroadcastHeader>();
149 msgDesc->pkt = packetCopy;
154 msgDesc->initialSend =
false;
169 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" Send packet down for sure." << endl;
170 packet->setTimestamp();
175 if (bernoulli(
beta)) {
176 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" Bernoulli test result: TRUE. Send packet down." << endl;
177 packet->setTimestamp();
182 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" Bernoulli test result: FALSE" << endl;
191 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" maxNbBcast reached." << endl;
196 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" Message TTL zero, discard." << endl;
202 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" Received unexpected self message" << endl;
Referenced by inet::AdaptiveProbabilisticBroadcast::handleSelfMessage().
◆ handleStartOperation()
| virtual void inet::ProbabilisticBroadcast::handleStartOperation |
( |
LifecycleOperation * |
operation | ) |
|
|
inlineoverrideprotectedvirtual |
◆ handleStopOperation()
| virtual void inet::ProbabilisticBroadcast::handleStopOperation |
( |
LifecycleOperation * |
operation | ) |
|
|
inlineoverrideprotectedvirtual |
◆ handleUpperPacket()
| void inet::ProbabilisticBroadcast::handleUpperPacket |
( |
Packet * |
packet | ) |
|
|
overrideprotectedvirtual |
Handle messages from upper layer.
Reimplemented from inet::LayeredProtocolBase.
64 auto macHeader = packet->peekAtFront<ProbabilisticBroadcastHeader>();
66 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" handleUpperMsg(): Pkt ID = " << macHeader->getId() <<
" TTL = " << macHeader->getAppTtl() << endl;
◆ initialize()
| void inet::ProbabilisticBroadcast::initialize |
( |
int |
stage | ) |
|
|
overridevirtual |
◆ 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
-
| bcastDelay | relative (to now) simulator time of next broadcast attempt. |
| msg | descriptor of the message to insert in the queue. |
241 simtime_t bcastTime = simTime() + bcastDelay;
243 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" insertMessage() bcastDelay = " << bcastDelay <<
" Msg ID = " << msgDesc->pkt->getId() << endl;
245 msgDesc->pkt->trim();
246 auto macHeader = msgDesc->pkt->removeAtFront<ProbabilisticBroadcastHeader>();
247 macHeader->setAppTtl(macHeader->getAppTtl() - bcastDelay);
248 msgDesc->pkt->insertAtFront(macHeader);
252 auto pos =
msgQueue.insert(make_pair(bcastTime, msgDesc));
257 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" message inserted in the front, reschedule it." << endl;
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
-
| msgDesc | descriptor of the message to insert in the queue. |
| iAmInitialSender | message comes from upper layer, I am its creator and initial sender. |
309 auto macHeader = packet->peekAtFront<ProbabilisticBroadcastHeader>();
310 simtime_t ttl = macHeader->getAppTtl();
313 simtime_t bcastDelay;
325 if (bcastDelay > ttl)
327 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" insertNewMessage(): insert packet " << macHeader->getId() <<
" with delay "
328 << bcastDelay << endl;
331 msgDesc->
pkt = packet;
332 msgDesc->nbBcast = 0;
333 msgDesc->initialSend = iAmInitialSender;
338 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" insertNewMessage(): got new packet with TTL = 0." << endl;
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.
Referenced by handleLowerPacket().
◆ numInitStages()
| virtual int inet::ProbabilisticBroadcast::numInitStages |
( |
| ) |
const |
|
inlineoverridevirtual |
Initialization of the module and some variables.
◆ operator=()
Assignment operator is not allowed.
◆ popFirstMessageUpdateQueue()
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.
269 msgDesc = pos->second;
273 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" pop(): just popped msg " << msgDesc->pkt->getId() << endl;
276 EV <<
"PBr: " << simTime() <<
" n" <<
myNetwAddr <<
" pop(): schedule next message." << endl;
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
-
| pMsg | The message where the "control info" shall be attached. |
| pDestAddr | The MAC address of the message receiver. |
365 pMsg->addTagIfAbsent<MacAddressReq>()->setDestAddress(pDestAddr);
Referenced by encapsulate(), handleLowerPacket(), and handleSelfMessage().
◆ beta
| double inet::ProbabilisticBroadcast::beta = 0.0 |
|
protected |
◆ broadcastPeriod
| simtime_t inet::ProbabilisticBroadcast::broadcastPeriod |
|
protected |
◆ 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 |
◆ id_counter
| long inet::ProbabilisticBroadcast::id_counter = 0 |
|
staticprotected |
◆ knownMsgIds
| MsgIdSet inet::ProbabilisticBroadcast::knownMsgIds |
|
protected |
◆ maxFirstBcastBackoff
| simtime_t inet::ProbabilisticBroadcast::maxFirstBcastBackoff |
|
protected |
◆ maxNbBcast
| int inet::ProbabilisticBroadcast::maxNbBcast = 0 |
|
protected |
◆ msgQueue
◆ myNetwAddr
| L3Address inet::ProbabilisticBroadcast::myNetwAddr |
|
protected |
◆ nbDataPacketsForwarded
| long inet::ProbabilisticBroadcast::nbDataPacketsForwarded = 0 |
|
protected |
◆ nbDataPacketsReceived
| long inet::ProbabilisticBroadcast::nbDataPacketsReceived = 0 |
|
protected |
◆ nbDataPacketsSent
| long inet::ProbabilisticBroadcast::nbDataPacketsSent = 0 |
|
protected |
◆ nbHops
| long inet::ProbabilisticBroadcast::nbHops = 0 |
|
protected |
◆ oneHopLatencies
| cOutVector inet::ProbabilisticBroadcast::oneHopLatencies |
|
protected |
◆ 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 |
The documentation for this class was generated from the following files:
long nbDataPacketsReceived
Definition: ProbabilisticBroadcast.h:212
@ NEIGHBOR_TIMER
Definition: ProbabilisticBroadcast.h:57
virtual bool messageKnown(unsigned int msgId)
Checks whether a message is known (= kept in memory) or not.
Definition: ProbabilisticBroadcast.cc:229
@ BETA_TIMER
Definition: ProbabilisticBroadcast.h:58
static long id_counter
Definition: ProbabilisticBroadcast.h:164
MsgIdSet debugMsgIdSet
Definition: ProbabilisticBroadcast.h:209
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
int debugNbMessageKnown
Definition: ProbabilisticBroadcast.h:215
INET_API InitStage INITSTAGE_NETWORK_LAYER
Initialization of network layer protocols.
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd L3AddressInd
Definition: IUdp-gates.txt:20
simtime_t timeToLive
Definition: ProbabilisticBroadcast.h:162
virtual L3Address getBroadcastAddress() const =0
virtual void insertNewMessage(Packet *packet, bool iAmInitialSender=false)
Insert a new message in both known ID list and message queue.
Definition: ProbabilisticBroadcast.cc:307
simtime_t maxFirstBcastBackoff
Maximal back-off before first broadcast attempt [seconds].
Definition: ProbabilisticBroadcast.h:183
const Protocol & getProtocol() const override
Definition: ProbabilisticBroadcast.h:51
virtual bool debugMessageKnown(unsigned int msgId)
Checks whether a message is known (= kept in memory) or not.
Definition: ProbabilisticBroadcast.cc:234
L3Address myNetwAddr
Definition: ProbabilisticBroadcast.h:221
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
@ UNKNOWN
Definition: ProbabilisticBroadcast.h:55
simtime_t broadcastPeriod
Period (in sim time) between two broadcast attempts.
Definition: ProbabilisticBroadcast.h:151
INET_API InitStage INITSTAGE_NETWORK_INTERFACE_CONFIGURATION
Initialization of network interfaces includes:
Packet * pkt
Definition: ProbabilisticBroadcast.h:65
long nbDataPacketsForwarded
Definition: ProbabilisticBroadcast.h:216
double beta
Probability of each broadcast attempt.
Definition: ProbabilisticBroadcast.h:157
intscale< b, 1, 8 > B
Definition: Units.h:1168
virtual void sendUp(cMessage *message)
Definition: NetworkProtocolBase.cc:51
bool contains(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:65
MsgIdSet knownMsgIds
Definition: ProbabilisticBroadcast.h:207
ModuleRefByPar< IInterfaceTable > interfaceTable
Definition: NetworkProtocolBase.h:35
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
int headerLength
Length of the NetwPkt header Read from omnetpp.ini.
Definition: ProbabilisticBroadcast.h:198
long nbHops
Definition: ProbabilisticBroadcast.h:214
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
long nbDataPacketsSent
Definition: ProbabilisticBroadcast.h:213
virtual void insertMessage(simtime_t_cref bcastDelay, tMsgDesc *msgDesc)
Insert a message in both known ID list and message queue.
Definition: ProbabilisticBroadcast.cc:239
cMessage * broadcastTimer
Definition: ProbabilisticBroadcast.h:201
virtual void encapsulate(Packet *packet)
Returns a network layer packet which encapsulates the upper layer packet passed to the function.
Definition: ProbabilisticBroadcast.cc:283
int maxNbBcast
Maximal number of broadcast attempts for each packet.
Definition: ProbabilisticBroadcast.h:177
cOutVector oneHopLatencies
Definition: ProbabilisticBroadcast.h:219
simtime_t timeInQueueAfterDeath
How long the message should be kept in queue after its died.
Definition: ProbabilisticBroadcast.h:192
static const MacAddress BROADCAST_ADDRESS
The broadcast MAC address, ff:ff:ff:ff:ff:ff.
Definition: MacAddress.h:34
static const Protocol probabilistic
Definition: Protocol.h:129
IL3AddressType * getAddressType() const
Definition: L3Address.cc:59
virtual void initialize(int stage) override
Definition: NetworkProtocolBase.cc:28
struct inet::ProbabilisticBroadcast::tMsgDesc tMsgDesc
Store messages in a structure so that we can keep some information needed by the protocol.
TimeMsgMap msgQueue
Definition: ProbabilisticBroadcast.h:208
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
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
virtual void sendDown(cMessage *message, int interfaceId=-1)
Definition: NetworkProtocolBase.cc:91
static long getNextID()
Definition: ProbabilisticBroadcast.h:166
@ BROADCAST_TIMER
Definition: ProbabilisticBroadcast.h:56
virtual void setDownControlInfo(Packet *const pMsg, const MacAddress &pDestAddr)
Attaches a "control info" (NetwToMac) structure (object) to the message pMsg.
Definition: ProbabilisticBroadcast.cc:363