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

DSDV protocol implementation. More...

#include <Dsdv.h>

Inheritance diagram for inet::Dsdv:
inet::RoutingProtocolBase inet::OperationalBase inet::OperationalMixin< cSimpleModule > inet::ILifecycle

Classes

struct  ForwardEntry
 

Public Member Functions

 Dsdv ()
 
 ~Dsdv ()
 
- Public Member Functions inherited from inet::RoutingProtocolBase
 RoutingProtocolBase ()
 
- Public Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual ~OperationalMixin ()
 }@ More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessageWhenUp (cMessage *msg) override
 
void handleSelfMessage (cMessage *msg)
 
virtual void handleStartOperation (LifecycleOperation *operation) override
 
virtual void handleStopOperation (LifecycleOperation *operation) override
 
virtual void handleCrashOperation (LifecycleOperation *operation) override
 
void start ()
 
void stop ()
 
- Protected Member Functions inherited from inet::RoutingProtocolBase
virtual bool isInitializeStage (int stage) const override
 
virtual bool isModuleStartStage (int stage) const override
 
virtual bool isModuleStopStage (int stage) const override
 
- 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 ()
 

Protected Attributes

simtime_t helloInterval
 
ModuleRefByPar< IInterfaceTableift
 
ModuleRefByPar< IIpv4RoutingTablert
 
- Protected Attributes inherited from inet::OperationalMixin< cSimpleModule >
State operationalState
 
simtime_t lastChange
 
Operation activeOperation
 
cMessage * activeOperationTimeout
 
cMessage * activeOperationExtraTimer
 

Private Attributes

bool isForwardHello = false
 
cMessage * event = nullptr
 
cPar * broadcastDelay = nullptr
 
std::list< ForwardEntry * > * forwardList = nullptr
 
NetworkInterfaceinterface80211ptr = nullptr
 
int interfaceId = -1
 
unsigned int sequencenumber = 0
 
simtime_t routeLifetime
 
cModule * host = nullptr
 

Additional Inherited Members

- Protected Types inherited from inet::OperationalMixin< cSimpleModule >
enum  State
 

Detailed Description

DSDV protocol implementation.

Constructor & Destructor Documentation

◆ Dsdv()

inet::Dsdv::Dsdv ( )
36 {
37 }

◆ ~Dsdv()

inet::Dsdv::~Dsdv ( )
40 {
41  stop();
42  // Dispose of dynamically allocated the objects
43  delete event;
44  delete forwardList;
45 // delete Hello;
46 }

Member Function Documentation

◆ handleCrashOperation()

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

◆ handleMessageWhenUp()

void inet::Dsdv::handleMessageWhenUp ( cMessage *  msg)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

202 {
203  if (msg->isSelfMessage()) {
204  handleSelfMessage(msg);
205  }
206  else if (check_and_cast<Packet *>(msg)->getTag<PacketProtocolTag>()->getProtocol() == &Protocol::manet) {
207  auto packet = new Packet("Hello");
208 
209  // When DSDV module receives DsdvHello from other host
210  // it adds/replaces the information in routing table for the one contained in the message
211  // but only if it's useful/up-to-date. If not the DSDV module ignores the message.
212  auto addressReq = packet->addTag<L3AddressReq>();
213  addressReq->setDestAddress(Ipv4Address(255, 255, 255, 255)); // let's try the limited broadcast 255.255.255.255 but multicast goes from 224.0.0.0 to 239.255.255.255
214  addressReq->setSrcAddress(interface80211ptr->getProtocolData<Ipv4InterfaceData>()->getIPAddress());
215  packet->addTag<InterfaceReq>()->setInterfaceId(interface80211ptr->getInterfaceId());
216  packet->addTag<PacketProtocolTag>()->setProtocol(&Protocol::manet);
217  packet->addTag<DispatchProtocolReq>()->setProtocol(&Protocol::ipv4);
218  ForwardEntry *fhp = nullptr;
219  auto recHello = !isForwardHello ? staticPtrCast<DsdvHello>(check_and_cast<Packet *>(msg)->peekData<DsdvHello>()->dupShared()) : nullptr;
220  if (isForwardHello) {
221  fhp = new ForwardEntry();
222  fhp->hello = check_and_cast<Packet *>(msg->dup());
223  }
224 
225  if (msg->arrivedOn("ipIn")) {
226  ASSERT((!isForwardHello && recHello) || (isForwardHello && fhp->hello));
227  bubble("Received hello message");
228  Ipv4Address source = interface80211ptr->getProtocolData<Ipv4InterfaceData>()->getIPAddress();
229 
230  // reads DSDV hello message fields
231  Ipv4Address src;
232  unsigned int msgsequencenumber;
233  int numHops;
234  Ipv4Address next;
235  if (!isForwardHello) {
236  src = recHello->getSrcAddress();
237  msgsequencenumber = recHello->getSequencenumber();
238  next = recHello->getNextAddress();
239  numHops = recHello->getHopdistance();
240 
241  if (src == source) {
242  EV_INFO << "Hello msg dropped. This message returned to the original creator.\n";
243  delete packet;
244  delete fhp;
245  delete msg;
246  return;
247  }
248  }
249  else {
250  auto fhpHello = fhp->hello->peekData<DsdvHello>();
251  src = fhpHello->getSrcAddress();
252  msgsequencenumber = fhpHello->getSequencenumber();
253  next = fhpHello->getNextAddress();
254  numHops = fhpHello->getHopdistance();
255 
256  if (src == source) {
257  EV_INFO << "Hello msg dropped. This message returned to the original creator.\n";
258  delete packet;
259  delete fhp;
260  delete msg;
261  return;
262  }
263  }
264 
265  Ipv4Route *_entrada_routing = rt->findBestMatchingRoute(src);
266  DsdvIpv4Route *entrada_routing = dynamic_cast<DsdvIpv4Route *>(_entrada_routing);
267 
268  // Tests if the DSDV hello message that arrived is useful
269  if (_entrada_routing == nullptr
270  || (_entrada_routing != nullptr && _entrada_routing->getNetmask() != Ipv4Address::ALLONES_ADDRESS)
271  || (entrada_routing != nullptr && (msgsequencenumber > (entrada_routing->getSequencenumber()) || (msgsequencenumber == (entrada_routing->getSequencenumber()) && numHops < (entrada_routing->getMetric())))))
272  {
273 
274  // remove old entry
275  if (entrada_routing != nullptr)
276  rt->deleteRoute(entrada_routing);
277 
278  // adds new information to routing table according to information in hello message
279  {
280  Ipv4Address netmask = Ipv4Address::ALLONES_ADDRESS; // Ipv4Address(par("netmask").stringValue());
281  DsdvIpv4Route *e = new DsdvIpv4Route();
282  e->setDestination(src);
283  e->setNetmask(netmask);
284  e->setGateway(next);
285  e->setInterface(interface80211ptr);
286  e->setSourceType(IRoute::MANET);
287  e->setMetric(numHops);
288  e->setSequencenumber(msgsequencenumber);
289  e->setExpiryTime(simTime() + routeLifetime);
290  rt->addRoute(e);
291  }
292  if (!isForwardHello) {
293  recHello->setNextAddress(source);
294  numHops++;
295  recHello->setHopdistance(numHops);
296  double waitTime = intuniform(1, 50);
297  waitTime = waitTime / 100;
298  EV_DETAIL << "waitime for forward before was " << waitTime << " And host is " << source << "\n";
299 // waitTime= SIMTIME_DBL (simTime())+waitTime;
300  EV_DETAIL << "waitime for forward is " << waitTime << " And host is " << source << "\n"; // FIXME unchanged waitTime showed twice!!!
301  packet->insertAtBack(recHello);
302  sendDelayed(packet, waitTime, "ipOut");
303  packet = nullptr;
304  }
305  else {
306  auto forwardHello = staticPtrCast<DsdvHello>(fhp->hello->peekData<DsdvHello>()->dupShared());
307  // forward useful message to other nodes
308  forwardHello->setNextAddress(source);
309  numHops++;
310  forwardHello->setHopdistance(numHops);
311 // send(HelloForward, "ipOut");
312 // HelloForward=nullptr;
313  double waitTime = intuniform(1, 50);
314  waitTime = waitTime / 100;
315  EV_DETAIL << "waitime for forward before was " << waitTime << " And host is " << source << "\n";
316  EV_DETAIL << "waitime for forward is " << waitTime << " And host is " << source << "\n";
317  fhp->event = new cMessage("event2");
318  scheduleAfter(waitTime, fhp->event);
319  forwardList->push_back(fhp);
320  fhp = nullptr;
321  }
322  }
323  delete packet;
324  delete fhp;
325  delete msg;
326  }
327  else
328  throw cRuntimeError("Message arrived on unknown gate %s", msg->getArrivalGate()->getName());
329  }
330  else
331  throw cRuntimeError("Message not supported %s", msg->getName());
332 }

◆ handleSelfMessage()

void inet::Dsdv::handleSelfMessage ( cMessage *  msg)
protected

size of Hello message in bits

129 {
130  // When DSDV module receives selfmessage (scheduled event)
131  // it means that it's time for Hello message broadcast event
132  // i.e. Brodcast Hello messages to other nodes when selfmessage=event
133  // But if selmessage!=event it means that it is time to forward useful Hello message to othert nodes
134  if (msg == event) {
135  auto hello = makeShared<DsdvHello>();
136 
137  rt->purge();
138 
139  // count non-loopback interfaces
140 // int numIntf = 0;
141 // NetworkInterface *ie = nullptr;
142  //for (int k=0; k<ift->getNumInterfaces(); k++)
143 // if (!ift->getInterface(k)->isLoopback())
144 // {ie = ift->getInterface(k); numIntf++; }
145 
146  // Filling the DsdvHello fields
147 // Ipv4Address source = (ie->ipv4()->getIPAddress());
148  Ipv4Address source = (interface80211ptr->getProtocolData<Ipv4InterfaceData>()->getIPAddress());
149  hello->setChunkLength(b(128));
150  hello->setSrcAddress(source);
151  sequencenumber += 2;
152  hello->setSequencenumber(sequencenumber);
153  hello->setNextAddress(source);
154  hello->setHopdistance(1);
155 
156  /*http://www.cs.ucsb.edu/~ebelding/txt/bc.txt
157  The IPv4 address for "limited broadcast" is 255.255.255.255, and is not supposed to be forwarded.
158  Since the nodes in an ad hoc network are asked to forward the flooded packets, the limited broadcast
159  address is a poor choice. The other available choice, the "directed broadcast" address, would presume a
160  choice of routing prefix for the ad hoc network and thus is not a reasonable choice.
161  (...)
162  Limited Broadcast - Sent to all NICs on the some network segment as the source NIC. It is represented with
163  the 255.255.255.255 TCP/IP address. This broadcast is not forwarded by routers so will only appear on one
164  network segment.
165  Direct broadcast - Sent to all hosts on a network. Routers may be configured to forward directed broadcasts
166  on large networks. For network 192.168.0.0, the broadcast is 192.168.255.255.
167  */
168  // new control info for DsdvHello
169  auto packet = new Packet("Hello", hello);
170  auto addressReq = packet->addTag<L3AddressReq>();
171  addressReq->setDestAddress(Ipv4Address(255, 255, 255, 255)); // let's try the limited broadcast 255.255.255.255 but multicast goes from 224.0.0.0 to 239.255.255.255
172  addressReq->setSrcAddress(source); // let's try the limited broadcast
173  packet->addTag<InterfaceReq>()->setInterfaceId(interface80211ptr->getInterfaceId());
174  packet->addTag<PacketProtocolTag>()->setProtocol(&Protocol::manet);
175  packet->addTag<DispatchProtocolReq>()->setProtocol(&Protocol::ipv4);
176 
177  // broadcast to other nodes the hello message
178  send(packet, "ipOut");
179  packet = nullptr;
180  hello = nullptr;
181 
182  // schedule new brodcast hello message event
183  scheduleAfter(helloInterval + broadcastDelay->doubleValue(), event);
184  bubble("Sending new hello message");
185  }
186  else {
187  for (auto it = forwardList->begin(); it != forwardList->end(); it++) {
188  if ((*it)->event == msg) {
189  EV << "Vou mandar forward do " << (*it)->hello->peekData<DsdvHello>()->getSrcAddress() << endl; // todo
190  send((*it)->hello, "ipOut");
191  (*it)->hello = nullptr;
192  delete *it;
193  forwardList->erase(it);
194  break;
195  }
196  }
197  delete msg;
198  }
199 }

Referenced by handleMessageWhenUp().

◆ handleStartOperation()

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

◆ handleStopOperation()

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

◆ initialize()

void inet::Dsdv::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::OperationalMixin< cSimpleModule >.

49 {
51 
52  // reads from omnetpp.ini
53  if (stage == INITSTAGE_LOCAL) {
54  sequencenumber = 0;
55  host = getContainingNode(this);
56  ift.reference(this, "interfaceTableModule", true);
57  rt.reference(this, "routingTableModule", true);
58 
59  routeLifetime = par("routeLifetime").doubleValue();
60  helloInterval = par("helloInterval");
61  forwardList = new std::list<ForwardEntry *>();
62  event = new cMessage("event");
63  }
64  else if (stage == INITSTAGE_ROUTING_PROTOCOLS) {
65  registerProtocol(Protocol::manet, gate("ipOut"), gate("ipIn"));
66  }
67 }

◆ numInitStages()

virtual int inet::Dsdv::numInitStages ( ) const
inlineoverrideprotectedvirtual
73 { return NUM_INIT_STAGES; }

◆ start()

void inet::Dsdv::start ( )
protected
70 {
71  /* Search the 80211 interface */
72  int num_80211 = 0;
73  NetworkInterface *ie;
74  NetworkInterface *i_face;
75  const char *name;
76  broadcastDelay = &par("broadcastDelay");
77  for (int i = 0; i < ift->getNumInterfaces(); i++) {
78  ie = ift->getInterface(i);
79  name = ie->getInterfaceName();
80  if (strstr(name, "wlan") != nullptr) {
81  i_face = ie;
82  num_80211++;
83  interfaceId = i;
84  }
85  }
86 
87  // One enabled network interface (in total)
88  if (num_80211 == 1)
89  interface80211ptr = i_face;
90  else
91  throw cRuntimeError("DSDV has found %i 80211 interfaces", num_80211);
92  if (par("manetPurgeRoutingTables").boolValue()) {
93  Ipv4Route *entry;
94  // clean the route table wlan interface entry
95  for (int i = rt->getNumRoutes() - 1; i >= 0; i--) {
96  entry = rt->getRoute(i);
97  const NetworkInterface *ie = entry->getInterface();
98  if (strstr(ie->getInterfaceName(), "wlan") != nullptr)
99  rt->deleteRoute(entry);
100  }
101  }
102  CHK(interface80211ptr->getProtocolDataForUpdate<Ipv4InterfaceData>())->joinMulticastGroup(Ipv4Address::LL_MANET_ROUTERS);
103 
104  // schedules a random periodic event: the hello message broadcast from DSDV module
105 
106  // reads from omnetpp.ini
107 // HelloForward = new DsdvHello("HelloForward");
108  // schedules a random periodic event: the hello message broadcast from DSDV module
109  scheduleAfter(uniform(0.0, par("maxVariance").doubleValue()), event);
110 }

◆ stop()

void inet::Dsdv::stop ( )
protected
113 {
114  cancelEvent(event);
115  while (!forwardList->empty()) {
116  ForwardEntry *fh = forwardList->front();
117  if (fh->event)
118  cancelAndDelete(fh->event);
119  if (fh->hello)
120  cancelAndDelete(fh->hello);
121  fh->event = nullptr;
122  fh->hello = nullptr;
123  forwardList->pop_front();
124  delete fh;
125  }
126 }

Referenced by ~Dsdv().

Member Data Documentation

◆ broadcastDelay

cPar* inet::Dsdv::broadcastDelay = nullptr
private

Referenced by handleSelfMessage(), and start().

◆ event

cMessage* inet::Dsdv::event = nullptr
private

Referenced by handleSelfMessage(), start(), stop(), and ~Dsdv().

◆ forwardList

std::list<ForwardEntry *>* inet::Dsdv::forwardList = nullptr
private

◆ helloInterval

simtime_t inet::Dsdv::helloInterval
protected

Referenced by handleSelfMessage(), and initialize().

◆ host

cModule* inet::Dsdv::host = nullptr
private

Referenced by initialize().

◆ ift

ModuleRefByPar<IInterfaceTable> inet::Dsdv::ift
protected

Referenced by initialize(), and start().

◆ interface80211ptr

NetworkInterface* inet::Dsdv::interface80211ptr = nullptr
private

◆ interfaceId

int inet::Dsdv::interfaceId = -1
private

Referenced by start().

◆ isForwardHello

bool inet::Dsdv::isForwardHello = false
private

Referenced by handleMessageWhenUp().

◆ routeLifetime

simtime_t inet::Dsdv::routeLifetime
private

Referenced by handleMessageWhenUp(), and initialize().

◆ rt

◆ sequencenumber

unsigned int inet::Dsdv::sequencenumber = 0
private

Referenced by handleSelfMessage(), and initialize().


The documentation for this class was generated from the following files:
CHK
#define CHK(x)
Definition: INETDefs.h:87
inet::Dsdv::handleSelfMessage
void handleSelfMessage(cMessage *msg)
Definition: Dsdv.cc:128
inet::Dsdv::stop
void stop()
Definition: Dsdv.cc:112
inet::Protocol::ipv4
static const Protocol ipv4
Definition: Protocol.h:93
inet::IRoute::MANET
@ MANET
managed by manet, search exact address
Definition: IRoute.h:38
inet::Dsdv::routeLifetime
simtime_t routeLifetime
Definition: Dsdv.h:60
inet::getContainingNode
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
inet::Dsdv::rt
ModuleRefByPar< IIpv4RoutingTable > rt
Definition: Dsdv.h:66
inet::OperationalMixin< cSimpleModule >::initialize
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
inet::Dsdv::interfaceId
int interfaceId
Definition: Dsdv.h:58
InterfaceReq
removed InterfaceReq
Definition: IUdp-gates.txt:11
inet::units::constants::e
const value< double, units::C > e(1.602176487e-19)
DispatchProtocolReq
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
inet::NetworkInterface::getProtocolData
const InterfaceProtocolData * getProtocolData(int index) const
Returns the protocol data at the given index.
Definition: NetworkInterface.h:287
inet::Dsdv::host
cModule * host
Definition: Dsdv.h:61
inet::Dsdv::helloInterval
simtime_t helloInterval
Definition: Dsdv.h:64
PacketProtocolTag
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
inet::Ipv4Address::ALLONES_ADDRESS
static const Ipv4Address ALLONES_ADDRESS
255.255.255.255
Definition: Ipv4Address.h:94
inet::Protocol::manet
static const Protocol manet
Definition: Protocol.h:99
inet::Dsdv::broadcastDelay
cPar * broadcastDelay
Definition: Dsdv.h:55
inet::NetworkInterface::getInterfaceId
int getInterfaceId() const
Definition: NetworkInterface.h:232
inet::Dsdv::isForwardHello
bool isForwardHello
Definition: Dsdv.h:53
inet::Dsdv::forwardList
std::list< ForwardEntry * > * forwardList
Definition: Dsdv.h:56
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::Dsdv::start
void start()
Definition: Dsdv.cc:69
inet::NetworkInterface::getProtocolDataForUpdate
T * getProtocolDataForUpdate()
Returns the protocol data for the provided type or throws an exception if no such protocol data is fo...
Definition: NetworkInterface.h:320
inet::Dsdv::event
cMessage * event
Definition: Dsdv.h:54
inet::Dsdv::sequencenumber
unsigned int sequencenumber
Definition: Dsdv.h:59
inet::Dsdv::interface80211ptr
NetworkInterface * interface80211ptr
Definition: Dsdv.h:57
inet::registerProtocol
void registerProtocol(const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive)
Registers a protocol primitive (PDU processing) at the given gate.
Definition: IProtocolRegistrationListener.cc:83
inet::INITSTAGE_ROUTING_PROTOCOLS
INET_API InitStage INITSTAGE_ROUTING_PROTOCOLS
Initialization of routing protocols.
inet::Dsdv::ift
ModuleRefByPar< IInterfaceTable > ift
Definition: Dsdv.h:65
inet::Ipv4Address::LL_MANET_ROUTERS
static const Ipv4Address LL_MANET_ROUTERS
224.0.0.109 Manet all designated routers
Definition: Ipv4Address.h:102