|
INET Framework for OMNeT++/OMNEST
|
A simple flooding protocol.
More...
#include <Flooding.h>
|
| | Flooding () |
| |
| virtual int | numInitStages () const override |
| | Initialization of omnetpp.ini parameters. More...
|
| |
| virtual void | initialize (int) override |
| | Reads all parameters from the ini file. More...
|
| |
| 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 () |
| |
A simple flooding protocol.
This implementation uses plain flooding, i.e. it "remembers" (stores) already broadcasted messages in a list and does not rebroadcast them again, if it gets another copy of that message.
The maximum number of entires for that list can be defined in the .ini file (bcMaxEntries) as well as the time after which an entry is deleted (bcDelTime).
If you prefere a memory-less version you can comment out the
#define PLAINFLOODING
- Author
- Daniel Willkomm
ported to Mixim 2.0 by Theodoros Kapourniotis
◆ cBroadcastList
◆ Flooding()
| inet::Flooding::Flooding |
( |
| ) |
|
|
inline |
◆ decapsulate()
| void inet::Flooding::decapsulate |
( |
Packet * |
packet | ) |
|
|
protected |
Decapsulates the packet from the received Network packet.
261 auto floodHeader = packet->popAtFront<FloodingHeader>();
262 auto payloadLength = floodHeader->getPayloadLengthField();
263 if (packet->getDataLength() < payloadLength) {
264 throw cRuntimeError(
"Data error: illegal payload length");
266 if (packet->getDataLength() > payloadLength)
267 packet->setBackOffset(packet->getFrontOffset() + payloadLength);
268 auto payloadProtocol = floodHeader->getProtocol();
269 packet->addTagIfAbsent<NetworkProtocolInd>()->setProtocol(&
getProtocol());
270 packet->addTagIfAbsent<NetworkProtocolInd>()->setNetworkProtocolHeader(floodHeader);
273 auto addressInd = packet->addTagIfAbsent<
L3AddressInd>();
274 addressInd->setSrcAddress(floodHeader->getSourceAddress());
275 addressInd->setDestAddress(floodHeader->getDestinationAddress());
276 packet->addTagIfAbsent<HopLimitInd>()->setHopLimit(floodHeader->getTtl());
Referenced by handleLowerPacket().
◆ encapsulate()
| void inet::Flooding::encapsulate |
( |
Packet * |
packet | ) |
|
|
protected |
Encapsulates the received ApplPkt into a NetwPkt and set all needed header fields.
287 EV <<
"in encaps...\n";
289 auto cInfo = appPkt->removeControlInfo();
290 auto pkt = makeShared<FloodingHeader>();
293 auto& hopLimitReq = appPkt->removeTagIfPresent<
HopLimitReq>();
294 int ttl = (hopLimitReq !=
nullptr) ? hopLimitReq->getHopLimit() : -1;
302 const auto& addressReq = appPkt->findTag<L3AddressReq>();
303 if (addressReq ==
nullptr) {
304 EV <<
"warning: Application layer did not specifiy a destination L3 address\n"
305 <<
"\tusing broadcast address instead\n";
306 netwAddr = netwAddr.getAddressType()->getBroadcastAddress();
310 netwAddr = addressReq->getDestAddress();
311 EV <<
"CInfo removed, netw addr=" << netwAddr << endl;
316 pkt->setDestAddr(netwAddr);
317 EV <<
" netw " <<
myNetwAddr <<
" sending packet" << endl;
319 EV <<
"sendDown: nHop=L3BROADCAST -> message has to be broadcasted"
320 <<
" -> set destMac=L2BROADCAST" << endl;
322 pkt->setPayloadLengthField(appPkt->getDataLength());
327 appPkt->insertAtFront(pkt);
328 EV <<
" pkt encapsulated\n";
Referenced by handleUpperPacket().
◆ finish()
| void inet::Flooding::finish |
( |
| ) |
|
|
overridevirtual |
87 recordScalar(
"meanNbHops", 0);
◆ getProtocol()
| const Protocol& inet::Flooding::getProtocol |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ handleCrashOperation()
|
|
inlineoverrideprotectedvirtual |
◆ handleLowerPacket()
| void inet::Flooding::handleLowerPacket |
( |
Packet * |
packet | ) |
|
|
overrideprotectedvirtual |
Handle messages from lower layer.
Messages from the mac layer will be forwarded to the application only if the are broadcast or destined for this node.
If the arrived message is a broadcast message it is also reflooded only if the tll field is bigger than one. Before the message is handed back to the mac layer the ttl field is reduced by one to account for this hop.
In the case of plain flooding the message will only be processed if there is no corresponding entry in the bcMsgs list (notBroadcasted). Otherwise the message will be deleted.
Reimplemented from inet::LayeredProtocolBase.
148 auto floodHeader = packet->peekAtFront<FloodingHeader>();
153 if (
interfaceTable->isLocalAddress(floodHeader->getDestinationAddress())) {
154 EV <<
" data msg for me! send to Upper" << endl;
161 else if (floodHeader->getDestinationAddress().isBroadcast()) {
163 if (floodHeader->getTtl() > 1) {
164 EV <<
" data msg BROADCAST! ttl = " << floodHeader->getTtl()
165 <<
" > 1 -> rebroadcast msg & send to upper\n";
166 auto dMsg = packet->dup();
167 auto newFloodHeader = dMsg->removeAtFront<FloodingHeader>();
168 newFloodHeader->setTtl(newFloodHeader->getTtl() - 1);
169 dMsg->insertAtFront(newFloodHeader);
175 EV <<
" max hops reached (ttl = " << floodHeader->getTtl() <<
") -> only send to upper\n";
186 if (floodHeader->getTtl() > 1) {
187 EV <<
" data msg not for me! ttl = " << floodHeader->getTtl()
188 <<
" > 1 -> forward\n";
190 auto packetCopy =
new Packet();
191 packetCopy->insertAtBack(packet->peekDataAt(
b(0), packet->getDataLength()));
192 auto floodHeaderCopy = staticPtrCast<FloodingHeader>(floodHeader->dupShared());
193 floodHeaderCopy->setTtl(floodHeader->getTtl() - 1);
194 packetCopy->insertAtFront(floodHeaderCopy);
196 cObject *
const pCtrlInfo = packetCopy->removeControlInfo();
197 if (pCtrlInfo !=
nullptr)
206 EV <<
" max hops reached (ttl = " << floodHeader->getTtl() <<
") -> delete msg\n";
212 EV <<
" data msg already BROADCASTed! delete msg\n";
◆ handleStartOperation()
|
|
inlineoverrideprotectedvirtual |
◆ handleStopOperation()
|
|
inlineoverrideprotectedvirtual |
◆ handleUpperPacket()
| void inet::Flooding::handleUpperPacket |
( |
Packet * |
packet | ) |
|
|
overrideprotectedvirtual |
Handle messages from upper layer.
All messages have to get a sequence number and the ttl filed has to be specified.
Afterwards the messages can be handed to the mac layer. The mac address is set to -1 (broadcast address) because the message is flooded (i.e. has to be send to all neighbors)
In the case of plain flooding the message sequence number and source address has also be stored in the bcMsgs list, so that this message will not be rebroadcasted, if a copy will be flooded back from the neigbouring nodes.
If the maximum number of entries is reached the first (oldest) entry is deleted.
Reimplemented from inet::LayeredProtocolBase.
108 auto floodHeader = packet->peekAtFront<FloodingHeader>();
114 if (it->delTime < simTime())
121 EV <<
"bcMsgs is full, delete oldest entry" << endl;
125 bcMsgs.push_back(Bcast(floodHeader->getSeqNum(), floodHeader->getSourceAddress(), simTime() +
bcDelTime));
◆ initialize()
| void inet::Flooding::initialize |
( |
int |
stage | ) |
|
|
overridevirtual |
Reads all parameters from the ini file.
If a parameter is not specified in the ini file a default value will be set.
Reimplemented from inet::NetworkProtocolBase.
71 throw cRuntimeError(
"No non-loopback interface found!");
◆ notBroadcasted()
Checks whether a message was already broadcasted.
The bcMsgs list is searched for the arrived message.
If the message is in the list, it was already broadcasted and the function returns false.
Concurrently all outdated (older than bcDelTime) are deleted. If the list is full and a new message has to be entered, the oldest entry is deleted.
233 if (it->delTime < simTime()) {
237 else if ((it->srcAddr == msg->getSourceAddress()) && (it->seqNum == msg->getSeqNum())) {
248 EV <<
"bcMsgs is full, delete oldest entry\n";
252 bcMsgs.push_back(Bcast(msg->getSeqNum(), msg->getSourceAddress(), simTime() +
bcDelTime));
Referenced by handleLowerPacket().
◆ numInitStages()
| virtual int inet::Flooding::numInitStages |
( |
| ) |
const |
|
inlineoverridevirtual |
Initialization of omnetpp.ini parameters.
◆ setDownControlInfo()
| void inet::Flooding::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. |
336 pMsg->addTagIfAbsent<MacAddressReq>()->setDestAddress(pDestAddr);
338 pMsg->addTagIfAbsent<DispatchProtocolInd>()->setProtocol(&
getProtocol());
Referenced by encapsulate(), and handleLowerPacket().
◆ bcDelTime
| simtime_t inet::Flooding::bcDelTime |
|
protected |
◆ bcMaxEntries
| unsigned int inet::Flooding::bcMaxEntries = 0 |
|
protected |
◆ bcMsgs
◆ defaultTtl
| int inet::Flooding::defaultTtl = 0 |
|
protected |
◆ headerLength
| int inet::Flooding::headerLength = 0 |
|
protected |
◆ myNetwAddr
◆ nbDataPacketsForwarded
| long inet::Flooding::nbDataPacketsForwarded = 0 |
|
protected |
◆ nbDataPacketsReceived
| long inet::Flooding::nbDataPacketsReceived = 0 |
|
protected |
◆ nbDataPacketsSent
| long inet::Flooding::nbDataPacketsSent = 0 |
|
protected |
◆ nbHops
| long inet::Flooding::nbHops = 0 |
|
protected |
◆ plainFlooding
| bool inet::Flooding::plainFlooding = false |
|
protected |
◆ seqNum
| unsigned long inet::Flooding::seqNum = 0 |
|
protected |
The documentation for this class was generated from the following files:
simtime_t bcDelTime
Time after which an entry for an already broadcasted msg can be deleted.
Definition: Flooding.h:98
int headerLength
Length of the header.
Definition: Flooding.h:62
long nbDataPacketsReceived
Definition: Flooding.h:100
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
INET_API InitStage INITSTAGE_NETWORK_LAYER
Initialization of network layer protocols.
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd L3AddressInd
Definition: IUdp-gates.txt:20
unsigned long seqNum
Network layer sequence number.
Definition: Flooding.h:56
void encapsulate(Packet *packet)
Encapsulates the received ApplPkt into a NetwPkt and set all needed header fields.
Definition: Flooding.cc:283
L3Address myNetwAddr
cached variable of my networ address
Definition: Flooding.h:59
void decapsulate(Packet *packet)
Decapsulates the packet from the received Network packet.
Definition: Flooding.cc:259
long nbDataPacketsSent
Definition: Flooding.h:101
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
INET_API InitStage INITSTAGE_NETWORK_INTERFACE_CONFIGURATION
Initialization of network interfaces includes:
virtual void sendUp(cMessage *message)
Definition: NetworkProtocolBase.cc:51
removed HopLimitReq
Definition: IUdp-gates.txt:11
int defaultTtl
Default time-to-live (ttl) used for this module.
Definition: Flooding.h:65
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:
unsigned int bcMaxEntries
Max number of entries in the list of already broadcasted messages.
Definition: Flooding.h:92
value< int64_t, units::b > b
Definition: Units.h:1241
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
bool plainFlooding
Defines whether to use plain flooding or not.
Definition: Flooding.h:68
long nbDataPacketsForwarded
Definition: Flooding.h:102
cBroadcastList bcMsgs
List of already broadcasted messages.
Definition: Flooding.h:86
long nbHops
Definition: Flooding.h:103
const Protocol & getProtocol() const override
Definition: Flooding.h:115
bool notBroadcasted(const FloodingHeader *)
Checks whether a message was already broadcasted.
Definition: Flooding.cc:226
virtual void setDownControlInfo(Packet *const pMsg, const MacAddress &pDestAddr)
Attaches a "control info" (NetwToMac) structure (object) to the message pMsg.
Definition: Flooding.cc:334
static const MacAddress BROADCAST_ADDRESS
The broadcast MAC address, ff:ff:ff:ff:ff:ff.
Definition: MacAddress.h:34
virtual void initialize(int stage) override
Definition: NetworkProtocolBase.cc:28
static const Protocol flooding
Definition: Protocol.h:126
virtual void sendDown(cMessage *message, int interfaceId=-1)
Definition: NetworkProtocolBase.cc:91