A Discrete-Event Network Simulator
API
dsdv-routing-protocol.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Hemanth Narra, Yufei Cheng
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Hemanth Narra <hemanth@ittc.ku.com>
19  * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
20  *
21  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
22  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
23  * Information and Telecommunication Technology Center (ITTC)
24  * and Department of Electrical Engineering and Computer Science
25  * The University of Kansas Lawrence, KS USA.
26  *
27  * Work supported in part by NSF FIND (Future Internet Design) Program
28  * under grant CNS-0626918 (Postmodern Internet Architecture),
29  * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
30  * US Department of Defense (DoD), and ITTC at The University of Kansas.
31  */
32 
33 #include "dsdv-routing-protocol.h"
34 #include "ns3/log.h"
35 #include "ns3/inet-socket-address.h"
36 #include "ns3/trace-source-accessor.h"
37 #include "ns3/udp-socket-factory.h"
38 #include "ns3/wifi-net-device.h"
39 #include "ns3/boolean.h"
40 #include "ns3/double.h"
41 #include "ns3/uinteger.h"
42 
43 namespace ns3 {
44 
45 NS_LOG_COMPONENT_DEFINE ("DsdvRoutingProtocol");
46 
47 namespace dsdv {
48 
49 NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol);
50 
52 const uint32_t RoutingProtocol::DSDV_PORT = 269;
53 
55 struct DeferredRouteOutputTag : public Tag
56 {
58  int32_t oif;
59 
60  DeferredRouteOutputTag (int32_t o = -1)
61  : Tag (),
62  oif (o)
63  {
64  }
65 
66  static TypeId
68  {
69  static TypeId tid = TypeId ("ns3::dsdv::DeferredRouteOutputTag")
70  .SetParent<Tag> ()
71  .SetGroupName ("Dsdv")
72  .AddConstructor<DeferredRouteOutputTag> ()
73  ;
74  return tid;
75  }
76 
77  TypeId
79  {
80  return GetTypeId ();
81  }
82 
83  uint32_t
85  {
86  return sizeof(int32_t);
87  }
88 
89  void
90  Serialize (TagBuffer i) const
91  {
92  i.WriteU32 (oif);
93  }
94 
95  void
97  {
98  oif = i.ReadU32 ();
99  }
100 
101  void
102  Print (std::ostream &os) const
103  {
104  os << "DeferredRouteOutputTag: output interface = " << oif;
105  }
106 };
107 
108 TypeId
110 {
111  static TypeId tid = TypeId ("ns3::dsdv::RoutingProtocol")
113  .SetGroupName ("Dsdv")
114  .AddConstructor<RoutingProtocol> ()
115  .AddAttribute ("PeriodicUpdateInterval","Periodic interval between exchange of full routing tables among nodes. ",
116  TimeValue (Seconds (15)),
118  MakeTimeChecker ())
119  .AddAttribute ("SettlingTime", "Minimum time an update is to be stored in adv table before sending out"
120  "in case of change in metric (in seconds)",
121  TimeValue (Seconds (5)),
123  MakeTimeChecker ())
124  .AddAttribute ("MaxQueueLen", "Maximum number of packets that we allow a routing protocol to buffer.",
125  UintegerValue (500 /*assuming maximum nodes in simulation is 100*/),
127  MakeUintegerChecker<uint32_t> ())
128  .AddAttribute ("MaxQueuedPacketsPerDst", "Maximum number of packets that we allow per destination to buffer.",
129  UintegerValue (5),
131  MakeUintegerChecker<uint32_t> ())
132  .AddAttribute ("MaxQueueTime","Maximum time packets can be queued (in seconds)",
133  TimeValue (Seconds (30)),
135  MakeTimeChecker ())
136  .AddAttribute ("EnableBuffering","Enables buffering of data packets if no route to destination is available",
137  BooleanValue (true),
141  .AddAttribute ("EnableWST","Enables Weighted Settling Time for the updates before advertising",
142  BooleanValue (true),
146  .AddAttribute ("Holdtimes","Times the forwarding Interval to purge the route.",
147  UintegerValue (3),
149  MakeUintegerChecker<uint32_t> ())
150  .AddAttribute ("WeightedFactor","WeightedFactor for the settling time if Weighted Settling Time is enabled",
151  DoubleValue (0.875),
153  MakeDoubleChecker<double> ())
154  .AddAttribute ("EnableRouteAggregation","Enables Weighted Settling Time for the updates before advertising",
155  BooleanValue (false),
159  .AddAttribute ("RouteAggregationTime","Time to aggregate updates before sending them out (in seconds)",
160  TimeValue (Seconds (1)),
162  MakeTimeChecker ());
163  return tid;
164 }
165 
166 void
168 {
169  EnableBuffering = f;
170 }
171 bool
173 {
174  return EnableBuffering;
175 }
176 void
178 {
179  EnableWST = f;
180 }
181 bool
183 {
184  return EnableWST;
185 }
186 void
188 {
190 }
191 bool
193 {
194  return EnableRouteAggregation;
195 }
196 
197 int64_t
199 {
200  NS_LOG_FUNCTION (this << stream);
202  return 1;
203 }
204 
206  : m_routingTable (),
207  m_advRoutingTable (),
208  m_queue (),
209  m_periodicUpdateTimer (Timer::CANCEL_ON_DESTROY)
210 {
211  m_uniformRandomVariable = CreateObject<UniformRandomVariable> ();
212 }
213 
215 {
216 }
217 
218 void
220 {
221  m_ipv4 = 0;
222  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::iterator iter = m_socketAddresses.begin (); iter
223  != m_socketAddresses.end (); iter++)
224  {
225  iter->first->Close ();
226  }
227  m_socketAddresses.clear ();
229 }
230 
231 void
233 {
234  *stream->GetStream () << "Node: " << m_ipv4->GetObject<Node> ()->GetId ()
235  << ", Time: " << Now().As (Time::S)
236  << ", Local time: " << GetObject<Node> ()->GetLocalTime ().As (Time::S)
237  << ", DSDV Routing table" << std::endl;
238 
239  m_routingTable.Print (stream);
240  *stream->GetStream () << std::endl;
241 }
242 
243 void
245 {
250  m_advRoutingTable.Setholddowntime (Time (Holdtimes * m_periodicUpdateInterval));
255 }
256 
259  const Ipv4Header &header,
260  Ptr<NetDevice> oif,
261  Socket::SocketErrno &sockerr)
262 {
263  NS_LOG_FUNCTION (this << header << (oif ? oif->GetIfIndex () : 0));
264 
265  if (!p)
266  {
267  return LoopbackRoute (header,oif);
268  }
269  if (m_socketAddresses.empty ())
270  {
271  sockerr = Socket::ERROR_NOROUTETOHOST;
272  NS_LOG_LOGIC ("No dsdv interfaces");
273  Ptr<Ipv4Route> route;
274  return route;
275  }
276  std::map<Ipv4Address, RoutingTableEntry> removedAddresses;
277  sockerr = Socket::ERROR_NOTERROR;
278  Ptr<Ipv4Route> route;
279  Ipv4Address dst = header.GetDestination ();
280  NS_LOG_DEBUG ("Packet Size: " << p->GetSize ()
281  << ", Packet id: " << p->GetUid () << ", Destination address in Packet: " << dst);
283  m_routingTable.Purge (removedAddresses);
284  for (std::map<Ipv4Address, RoutingTableEntry>::iterator rmItr = removedAddresses.begin ();
285  rmItr != removedAddresses.end (); ++rmItr)
286  {
287  rmItr->second.SetEntriesChanged (true);
288  rmItr->second.SetSeqNo (rmItr->second.GetSeqNo () + 1);
289  m_advRoutingTable.AddRoute (rmItr->second);
290  }
291  if (!removedAddresses.empty ())
292  {
294  }
295  if (m_routingTable.LookupRoute (dst,rt))
296  {
297  if (EnableBuffering)
298  {
300  }
301  if (rt.GetHop () == 1)
302  {
303  route = rt.GetRoute ();
304  NS_ASSERT (route != 0);
305  NS_LOG_DEBUG ("A route exists from " << route->GetSource ()
306  << " to neighboring destination "
307  << route->GetDestination ());
308  if (oif != 0 && route->GetOutputDevice () != oif)
309  {
310  NS_LOG_DEBUG ("Output device doesn't match. Dropped.");
311  sockerr = Socket::ERROR_NOROUTETOHOST;
312  return Ptr<Ipv4Route> ();
313  }
314  return route;
315  }
316  else
317  {
318  RoutingTableEntry newrt;
319  if (m_routingTable.LookupRoute (rt.GetNextHop (),newrt))
320  {
321  route = newrt.GetRoute ();
322  NS_ASSERT (route != 0);
323  NS_LOG_DEBUG ("A route exists from " << route->GetSource ()
324  << " to destination " << dst << " via "
325  << rt.GetNextHop ());
326  if (oif != 0 && route->GetOutputDevice () != oif)
327  {
328  NS_LOG_DEBUG ("Output device doesn't match. Dropped.");
329  sockerr = Socket::ERROR_NOROUTETOHOST;
330  return Ptr<Ipv4Route> ();
331  }
332  return route;
333  }
334  }
335  }
336 
337  if (EnableBuffering)
338  {
339  uint32_t iif = (oif ? m_ipv4->GetInterfaceForDevice (oif) : -1);
340  DeferredRouteOutputTag tag (iif);
341  if (!p->PeekPacketTag (tag))
342  {
343  p->AddPacketTag (tag);
344  }
345  }
346  return LoopbackRoute (header,oif);
347 }
348 
349 void
351  const Ipv4Header & header,
352  UnicastForwardCallback ucb,
353  ErrorCallback ecb)
354 {
355  NS_LOG_FUNCTION (this << p << header);
356  NS_ASSERT (p != 0 && p != Ptr<Packet> ());
357  QueueEntry newEntry (p,header,ucb,ecb);
358  bool result = m_queue.Enqueue (newEntry);
359  if (result)
360  {
361  NS_LOG_DEBUG ("Added packet " << p->GetUid () << " to queue.");
362  }
363 }
364 
365 bool
367  const Ipv4Header &header,
369  UnicastForwardCallback ucb,
372  ErrorCallback ecb)
373 {
374  NS_LOG_FUNCTION (m_mainAddress << " received packet " << p->GetUid ()
375  << " from " << header.GetSource ()
376  << " on interface " << idev->GetAddress ()
377  << " to destination " << header.GetDestination ());
378  if (m_socketAddresses.empty ())
379  {
380  NS_LOG_DEBUG ("No dsdv interfaces");
381  return false;
382  }
383  NS_ASSERT (m_ipv4 != 0);
384  // Check if input device supports IP
385  NS_ASSERT (m_ipv4->GetInterfaceForDevice (idev) >= 0);
386  int32_t iif = m_ipv4->GetInterfaceForDevice (idev);
387 
388  Ipv4Address dst = header.GetDestination ();
389  Ipv4Address origin = header.GetSource ();
390 
391  // DSDV is not a multicast routing protocol
392  if (dst.IsMulticast ())
393  {
394  return false;
395  }
396 
397  // Deferred route request
398  if (EnableBuffering == true && idev == m_lo)
399  {
401  if (p->PeekPacketTag (tag))
402  {
403  DeferredRouteOutput (p,header,ucb,ecb);
404  return true;
405  }
406  }
407  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j =
408  m_socketAddresses.begin (); j != m_socketAddresses.end (); ++j)
409  {
410  Ipv4InterfaceAddress iface = j->second;
411  if (origin == iface.GetLocal ())
412  {
413  return true;
414  }
415  }
416  // LOCAL DELIVARY TO DSDV INTERFACES
417  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
418  != m_socketAddresses.end (); ++j)
419  {
420  Ipv4InterfaceAddress iface = j->second;
421  if (m_ipv4->GetInterfaceForAddress (iface.GetLocal ()) == iif)
422  {
423  if (dst == iface.GetBroadcast () || dst.IsBroadcast ())
424  {
425  Ptr<Packet> packet = p->Copy ();
426  if (lcb.IsNull () == false)
427  {
428  NS_LOG_LOGIC ("Broadcast local delivery to " << iface.GetLocal ());
429  lcb (p, header, iif);
430  // Fall through to additional processing
431  }
432  else
433  {
434  NS_LOG_ERROR ("Unable to deliver packet locally due to null callback " << p->GetUid () << " from " << origin);
435  ecb (p, header, Socket::ERROR_NOROUTETOHOST);
436  }
437  if (header.GetTtl () > 1)
438  {
439  NS_LOG_LOGIC ("Forward broadcast. TTL " << (uint16_t) header.GetTtl ());
440  RoutingTableEntry toBroadcast;
441  if (m_routingTable.LookupRoute (dst,toBroadcast,true))
442  {
443  Ptr<Ipv4Route> route = toBroadcast.GetRoute ();
444  ucb (route,packet,header);
445  }
446  else
447  {
448  NS_LOG_DEBUG ("No route to forward. Drop packet " << p->GetUid ());
449  }
450  }
451  return true;
452  }
453  }
454  }
455 
456  if (m_ipv4->IsDestinationAddress (dst, iif))
457  {
458  if (lcb.IsNull () == false)
459  {
460  NS_LOG_LOGIC ("Unicast local delivery to " << dst);
461  lcb (p, header, iif);
462  }
463  else
464  {
465  NS_LOG_ERROR ("Unable to deliver packet locally due to null callback " << p->GetUid () << " from " << origin);
466  ecb (p, header, Socket::ERROR_NOROUTETOHOST);
467  }
468  return true;
469  }
470  RoutingTableEntry toDst;
471  if (m_routingTable.LookupRoute (dst,toDst))
472  {
474  if (m_routingTable.LookupRoute (toDst.GetNextHop (),ne))
475  {
476  Ptr<Ipv4Route> route = ne.GetRoute ();
477  NS_LOG_LOGIC (m_mainAddress << " is forwarding packet " << p->GetUid ()
478  << " to " << dst
479  << " from " << header.GetSource ()
480  << " via nexthop neighbor " << toDst.GetNextHop ());
481  ucb (route,p,header);
482  return true;
483  }
484  }
485  NS_LOG_LOGIC ("Drop packet " << p->GetUid ()
486  << " as there is no route to forward it.");
487  return false;
488 }
489 
492 {
493  NS_ASSERT (m_lo != 0);
494  Ptr<Ipv4Route> rt = Create<Ipv4Route> ();
495  rt->SetDestination (hdr.GetDestination ());
496  // rt->SetSource (hdr.GetSource ());
497  //
498  // Source address selection here is tricky. The loopback route is
499  // returned when DSDV does not have a route; this causes the packet
500  // to be looped back and handled (cached) in RouteInput() method
501  // while a route is found. However, connection-oriented protocols
502  // like TCP need to create an endpoint four-tuple (src, src port,
503  // dst, dst port) and create a pseudo-header for checksumming. So,
504  // DSDV needs to guess correctly what the eventual source address
505  // will be.
506  //
507  // For single interface, single address nodes, this is not a problem.
508  // When there are possibly multiple outgoing interfaces, the policy
509  // implemented here is to pick the first available DSDV interface.
510  // If RouteOutput() caller specified an outgoing interface, that
511  // further constrains the selection of source address
512  //
513  std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin ();
514  if (oif)
515  {
516  // Iterate to find an address on the oif device
517  for (j = m_socketAddresses.begin (); j != m_socketAddresses.end (); ++j)
518  {
519  Ipv4Address addr = j->second.GetLocal ();
520  int32_t interface = m_ipv4->GetInterfaceForAddress (addr);
521  if (oif == m_ipv4->GetNetDevice (static_cast<uint32_t> (interface)))
522  {
523  rt->SetSource (addr);
524  break;
525  }
526  }
527  }
528  else
529  {
530  rt->SetSource (j->second.GetLocal ());
531  }
532  NS_ASSERT_MSG (rt->GetSource () != Ipv4Address (), "Valid DSDV source address not found");
533  rt->SetGateway (Ipv4Address ("127.0.0.1"));
534  rt->SetOutputDevice (m_lo);
535  return rt;
536 }
537 
538 void
540 {
541  Address sourceAddress;
542  Ptr<Packet> advpacket = Create<Packet> ();
543  Ptr<Packet> packet = socket->RecvFrom (sourceAddress);
544  InetSocketAddress inetSourceAddr = InetSocketAddress::ConvertFrom (sourceAddress);
545  Ipv4Address sender = inetSourceAddr.GetIpv4 ();
546  Ipv4Address receiver = m_socketAddresses[socket].GetLocal ();
547  Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (receiver));
548  uint32_t packetSize = packet->GetSize ();
549  NS_LOG_FUNCTION (m_mainAddress << " received dsdv packet of size: " << packetSize
550  << " and packet id: " << packet->GetUid ());
551  uint32_t count = 0;
552  for (; packetSize > 0; packetSize = packetSize - 12)
553  {
554  count = 0;
555  DsdvHeader dsdvHeader, tempDsdvHeader;
556  packet->RemoveHeader (dsdvHeader);
557  NS_LOG_DEBUG ("Processing new update for " << dsdvHeader.GetDst ());
558  /*Verifying if the packets sent by me were returned back to me. If yes, discarding them!*/
559  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
560  != m_socketAddresses.end (); ++j)
561  {
562  Ipv4InterfaceAddress interface = j->second;
563  if (dsdvHeader.GetDst () == interface.GetLocal ())
564  {
565  if (dsdvHeader.GetDstSeqno () % 2 == 1)
566  {
567  NS_LOG_DEBUG ("Sent Dsdv update back to the same Destination, "
568  "with infinite metric. Time left to send fwd update: "
570  count++;
571  }
572  else
573  {
574  NS_LOG_DEBUG ("Received update for my address. Discarding this.");
575  count++;
576  }
577  }
578  }
579  if (count > 0)
580  {
581  continue;
582  }
583  NS_LOG_DEBUG ("Received a DSDV packet from "
584  << sender << " to " << receiver << ". Details are: Destination: " << dsdvHeader.GetDst () << ", Seq No: "
585  << dsdvHeader.GetDstSeqno () << ", HopCount: " << dsdvHeader.GetHopCount ());
586  RoutingTableEntry fwdTableEntry, advTableEntry;
587  EventId event;
588  bool permanentTableVerifier = m_routingTable.LookupRoute (dsdvHeader.GetDst (),fwdTableEntry);
589  if (permanentTableVerifier == false)
590  {
591  if (dsdvHeader.GetDstSeqno () % 2 != 1)
592  {
593  NS_LOG_DEBUG ("Received New Route!");
594  RoutingTableEntry newEntry (
595  /*device=*/ dev, /*dst=*/
596  dsdvHeader.GetDst (), /*seqno=*/
597  dsdvHeader.GetDstSeqno (),
598  /*iface=*/ m_ipv4->GetAddress (m_ipv4->GetInterfaceForAddress (receiver), 0),
599  /*hops=*/ dsdvHeader.GetHopCount (), /*next hop=*/
600  sender, /*lifetime=*/
601  Simulator::Now (), /*settlingTime*/
602  m_settlingTime, /*entries changed*/
603  true);
604  newEntry.SetFlag (VALID);
605  m_routingTable.AddRoute (newEntry);
606  NS_LOG_DEBUG ("New Route added to both tables");
607  m_advRoutingTable.AddRoute (newEntry);
608  }
609  else
610  {
611  // received update not present in main routing table and also with infinite metric
612  NS_LOG_DEBUG ("Discarding this update as this route is not present in "
613  "main routing table and received with infinite metric");
614  }
615  }
616  else
617  {
618  if (!m_advRoutingTable.LookupRoute (dsdvHeader.GetDst (),advTableEntry))
619  {
621  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
623  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
624  {
625  NS_LOG_DEBUG ("ADV table routes are:" << i->second.GetDestination ());
626  }
627  // present in fwd table and not in advtable
628  m_advRoutingTable.AddRoute (fwdTableEntry);
629  m_advRoutingTable.LookupRoute (dsdvHeader.GetDst (),advTableEntry);
630  }
631  if (dsdvHeader.GetDstSeqno () % 2 != 1)
632  {
633  if (dsdvHeader.GetDstSeqno () > advTableEntry.GetSeqNo ())
634  {
635  // Received update with better seq number. Clear any old events that are running
636  if (m_advRoutingTable.ForceDeleteIpv4Event (dsdvHeader.GetDst ()))
637  {
638  NS_LOG_DEBUG ("Canceling the timer to update route with better seq number");
639  }
640  // if its a changed metric *nomatter* where the update came from, wait for WST
641  if (dsdvHeader.GetHopCount () != advTableEntry.GetHop ())
642  {
643  advTableEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
644  advTableEntry.SetLifeTime (Simulator::Now ());
645  advTableEntry.SetFlag (VALID);
646  advTableEntry.SetEntriesChanged (true);
647  advTableEntry.SetNextHop (sender);
648  advTableEntry.SetHop (dsdvHeader.GetHopCount ());
649  NS_LOG_DEBUG ("Received update with better sequence number and changed metric.Waiting for WST");
650  Time tempSettlingtime = GetSettlingTime (dsdvHeader.GetDst ());
651  advTableEntry.SetSettlingTime (tempSettlingtime);
652  NS_LOG_DEBUG ("Added Settling Time:" << tempSettlingtime.GetSeconds ()
653  << "s as there is no event running for this route");
654  event = Simulator::Schedule (tempSettlingtime,&RoutingProtocol::SendTriggeredUpdate,this);
655  m_advRoutingTable.AddIpv4Event (dsdvHeader.GetDst (),event);
656  NS_LOG_DEBUG ("EventCreated EventUID: " << event.GetUid ());
657  // if received changed metric, use it but adv it only after wst
658  m_routingTable.Update (advTableEntry);
659  m_advRoutingTable.Update (advTableEntry);
660  }
661  else
662  {
663  // Received update with better seq number and same metric.
664  advTableEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
665  advTableEntry.SetLifeTime (Simulator::Now ());
666  advTableEntry.SetFlag (VALID);
667  advTableEntry.SetEntriesChanged (true);
668  advTableEntry.SetNextHop (sender);
669  advTableEntry.SetHop (dsdvHeader.GetHopCount ());
670  m_advRoutingTable.Update (advTableEntry);
671  NS_LOG_DEBUG ("Route with better sequence number and same metric received. Advertised without WST");
672  }
673  }
674  else if (dsdvHeader.GetDstSeqno () == advTableEntry.GetSeqNo ())
675  {
676  if (dsdvHeader.GetHopCount () < advTableEntry.GetHop ())
677  {
678  /*Received update with same seq number and better hop count.
679  * As the metric is changed, we will have to wait for WST before sending out this update.
680  */
681  NS_LOG_DEBUG ("Canceling any existing timer to update route with same sequence number "
682  "and better hop count");
684  advTableEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
685  advTableEntry.SetLifeTime (Simulator::Now ());
686  advTableEntry.SetFlag (VALID);
687  advTableEntry.SetEntriesChanged (true);
688  advTableEntry.SetNextHop (sender);
689  advTableEntry.SetHop (dsdvHeader.GetHopCount ());
690  Time tempSettlingtime = GetSettlingTime (dsdvHeader.GetDst ());
691  advTableEntry.SetSettlingTime (tempSettlingtime);
692  NS_LOG_DEBUG ("Added Settling Time," << tempSettlingtime.GetSeconds ()
693  << " as there is no current event running for this route");
694  event = Simulator::Schedule (tempSettlingtime,&RoutingProtocol::SendTriggeredUpdate,this);
695  m_advRoutingTable.AddIpv4Event (dsdvHeader.GetDst (),event);
696  NS_LOG_DEBUG ("EventCreated EventUID: " << event.GetUid ());
697  // if received changed metric, use it but adv it only after wst
698  m_routingTable.Update (advTableEntry);
699  m_advRoutingTable.Update (advTableEntry);
700  }
701  else
702  {
703  /*Received update with same seq number but with same or greater hop count.
704  * Discard that update.
705  */
706  if (!m_advRoutingTable.AnyRunningEvent (dsdvHeader.GetDst ()))
707  {
708  /*update the timer only if nexthop address matches thus discarding
709  * updates to that destination from other nodes.
710  */
711  if (advTableEntry.GetNextHop () == sender)
712  {
713  advTableEntry.SetLifeTime (Simulator::Now ());
714  m_routingTable.Update (advTableEntry);
715  }
717  dsdvHeader.GetDst ());
718  }
719  NS_LOG_DEBUG ("Received update with same seq number and "
720  "same/worst metric for, " << dsdvHeader.GetDst () << ". Discarding the update.");
721  }
722  }
723  else
724  {
725  // Received update with an old sequence number. Discard the update
726  if (!m_advRoutingTable.AnyRunningEvent (dsdvHeader.GetDst ()))
727  {
728  m_advRoutingTable.DeleteRoute (dsdvHeader.GetDst ());
729  }
730  NS_LOG_DEBUG (dsdvHeader.GetDst () << " : Received update with old seq number. Discarding the update.");
731  }
732  }
733  else
734  {
735  NS_LOG_DEBUG ("Route with infinite metric received for "
736  << dsdvHeader.GetDst () << " from " << sender);
737  // Delete route only if update was received from my nexthop neighbor
738  if (sender == advTableEntry.GetNextHop ())
739  {
740  NS_LOG_DEBUG ("Triggering an update for this unreachable route:");
741  std::map<Ipv4Address, RoutingTableEntry> dstsWithNextHopSrc;
742  m_routingTable.GetListOfDestinationWithNextHop (dsdvHeader.GetDst (),dstsWithNextHopSrc);
743  m_routingTable.DeleteRoute (dsdvHeader.GetDst ());
744  advTableEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
745  advTableEntry.SetEntriesChanged (true);
746  m_advRoutingTable.Update (advTableEntry);
747  for (std::map<Ipv4Address, RoutingTableEntry>::iterator i = dstsWithNextHopSrc.begin (); i
748  != dstsWithNextHopSrc.end (); ++i)
749  {
750  i->second.SetSeqNo (i->second.GetSeqNo () + 1);
751  i->second.SetEntriesChanged (true);
752  m_advRoutingTable.AddRoute (i->second);
753  m_routingTable.DeleteRoute (i->second.GetDestination ());
754  }
755  }
756  else
757  {
758  if (!m_advRoutingTable.AnyRunningEvent (dsdvHeader.GetDst ()))
759  {
760  m_advRoutingTable.DeleteRoute (dsdvHeader.GetDst ());
761  }
762  NS_LOG_DEBUG (dsdvHeader.GetDst () <<
763  " : Discard this link break update as it was received from a different neighbor "
764  "and I can reach the destination");
765  }
766  }
767  }
768  }
769  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
771  if (EnableRouteAggregation && allRoutes.size () > 0)
772  {
774  }
775  else
776  {
778  }
779 }
780 
781 
782 void
784 {
785  NS_LOG_FUNCTION (m_mainAddress << " is sending a triggered update");
786  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
788  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
789  != m_socketAddresses.end (); ++j)
790  {
791  DsdvHeader dsdvHeader;
792  Ptr<Socket> socket = j->first;
793  Ipv4InterfaceAddress iface = j->second;
794  Ptr<Packet> packet = Create<Packet> ();
795  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
796  {
797  NS_LOG_LOGIC ("Destination: " << i->second.GetDestination ()
798  << " SeqNo:" << i->second.GetSeqNo () << " HopCount:"
799  << i->second.GetHop () + 1);
800  RoutingTableEntry temp = i->second;
801  if ((i->second.GetEntriesChanged () == true) && (!m_advRoutingTable.AnyRunningEvent (temp.GetDestination ())))
802  {
803  dsdvHeader.SetDst (i->second.GetDestination ());
804  dsdvHeader.SetDstSeqno (i->second.GetSeqNo ());
805  dsdvHeader.SetHopCount (i->second.GetHop () + 1);
806  temp.SetFlag (VALID);
807  temp.SetEntriesChanged (false);
808  m_advRoutingTable.DeleteIpv4Event (temp.GetDestination ());
809  if (!(temp.GetSeqNo () % 2))
810  {
811  m_routingTable.Update (temp);
812  }
813  packet->AddHeader (dsdvHeader);
814  m_advRoutingTable.DeleteRoute (temp.GetDestination ());
815  NS_LOG_DEBUG ("Deleted this route from the advertised table");
816  }
817  else
818  {
819  EventId event = m_advRoutingTable.GetEventId (temp.GetDestination ());
820  NS_ASSERT (event.GetUid () != 0);
821  NS_LOG_DEBUG ("EventID " << event.GetUid () << " associated with "
822  << temp.GetDestination () << " has not expired, waiting in adv table");
823  }
824  }
825  if (packet->GetSize () >= 12)
826  {
827  RoutingTableEntry temp2;
828  m_routingTable.LookupRoute (m_ipv4->GetAddress (1, 0).GetBroadcast (), temp2);
829  dsdvHeader.SetDst (m_ipv4->GetAddress (1, 0).GetLocal ());
830  dsdvHeader.SetDstSeqno (temp2.GetSeqNo ());
831  dsdvHeader.SetHopCount (temp2.GetHop () + 1);
832  NS_LOG_DEBUG ("Adding my update as well to the packet");
833  packet->AddHeader (dsdvHeader);
834  // Send to all-hosts broadcast if on /32 addr, subnet-directed otherwise
835  Ipv4Address destination;
836  if (iface.GetMask () == Ipv4Mask::GetOnes ())
837  {
838  destination = Ipv4Address ("255.255.255.255");
839  }
840  else
841  {
842  destination = iface.GetBroadcast ();
843  }
844  socket->SendTo (packet, 0, InetSocketAddress (destination, DSDV_PORT));
845  NS_LOG_FUNCTION ("Sent Triggered Update from "
846  << dsdvHeader.GetDst ()
847  << " with packet id : " << packet->GetUid () << " and packet Size: " << packet->GetSize ());
848  }
849  else
850  {
851  NS_LOG_FUNCTION ("Update not sent as there are no updates to be triggered");
852  }
853  }
854 }
855 
856 void
858 {
859  std::map<Ipv4Address, RoutingTableEntry> removedAddresses, allRoutes;
860  m_routingTable.Purge (removedAddresses);
863  if (allRoutes.empty ())
864  {
865  return;
866  }
867  NS_LOG_FUNCTION (m_mainAddress << " is sending out its periodic update");
868  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
869  != m_socketAddresses.end (); ++j)
870  {
871  Ptr<Socket> socket = j->first;
872  Ipv4InterfaceAddress iface = j->second;
873  Ptr<Packet> packet = Create<Packet> ();
874  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
875  {
876  DsdvHeader dsdvHeader;
877  if (i->second.GetHop () == 0)
878  {
879  RoutingTableEntry ownEntry;
880  dsdvHeader.SetDst (m_ipv4->GetAddress (1,0).GetLocal ());
881  dsdvHeader.SetDstSeqno (i->second.GetSeqNo () + 2);
882  dsdvHeader.SetHopCount (i->second.GetHop () + 1);
883  m_routingTable.LookupRoute (m_ipv4->GetAddress (1,0).GetBroadcast (),ownEntry);
884  ownEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
885  m_routingTable.Update (ownEntry);
886  packet->AddHeader (dsdvHeader);
887  }
888  else
889  {
890  dsdvHeader.SetDst (i->second.GetDestination ());
891  dsdvHeader.SetDstSeqno ((i->second.GetSeqNo ()));
892  dsdvHeader.SetHopCount (i->second.GetHop () + 1);
893  packet->AddHeader (dsdvHeader);
894  }
895  NS_LOG_DEBUG ("Forwarding the update for " << i->first);
896  NS_LOG_DEBUG ("Forwarding details are, Destination: " << dsdvHeader.GetDst ()
897  << ", SeqNo:" << dsdvHeader.GetDstSeqno ()
898  << ", HopCount:" << dsdvHeader.GetHopCount ()
899  << ", LifeTime: " << i->second.GetLifeTime ().GetSeconds ());
900  }
901  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator rmItr = removedAddresses.begin (); rmItr
902  != removedAddresses.end (); ++rmItr)
903  {
904  DsdvHeader removedHeader;
905  removedHeader.SetDst (rmItr->second.GetDestination ());
906  removedHeader.SetDstSeqno (rmItr->second.GetSeqNo () + 1);
907  removedHeader.SetHopCount (rmItr->second.GetHop () + 1);
908  packet->AddHeader (removedHeader);
909  NS_LOG_DEBUG ("Update for removed record is: Destination: " << removedHeader.GetDst ()
910  << " SeqNo:" << removedHeader.GetDstSeqno ()
911  << " HopCount:" << removedHeader.GetHopCount ());
912  }
913  socket->Send (packet);
914  // Send to all-hosts broadcast if on /32 addr, subnet-directed otherwise
915  Ipv4Address destination;
916  if (iface.GetMask () == Ipv4Mask::GetOnes ())
917  {
918  destination = Ipv4Address ("255.255.255.255");
919  }
920  else
921  {
922  destination = iface.GetBroadcast ();
923  }
924  socket->SendTo (packet, 0, InetSocketAddress (destination, DSDV_PORT));
925  NS_LOG_FUNCTION ("PeriodicUpdate Packet UID is : " << packet->GetUid ());
926  }
928 }
929 
930 void
932 {
933  NS_ASSERT (ipv4 != 0);
934  NS_ASSERT (m_ipv4 == 0);
935  m_ipv4 = ipv4;
936  // Create lo route. It is asserted that the only one interface up for now is loopback
937  NS_ASSERT (m_ipv4->GetNInterfaces () == 1 && m_ipv4->GetAddress (0, 0).GetLocal () == Ipv4Address ("127.0.0.1"));
938  m_lo = m_ipv4->GetNetDevice (0);
939  NS_ASSERT (m_lo != 0);
940  // Remember lo route
941  RoutingTableEntry rt (
942  /*device=*/ m_lo, /*dst=*/
943  Ipv4Address::GetLoopback (), /*seqno=*/
944  0,
945  /*iface=*/ Ipv4InterfaceAddress (Ipv4Address::GetLoopback (),Ipv4Mask ("255.0.0.0")),
946  /*hops=*/ 0, /*next hop=*/
948  /*lifetime=*/ Simulator::GetMaximumSimulationTime ());
949  rt.SetFlag (INVALID);
950  rt.SetEntriesChanged (false);
953 }
954 
955 void
957 {
958  NS_LOG_FUNCTION (this << m_ipv4->GetAddress (i, 0).GetLocal ()
959  << " interface is up");
960  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
961  Ipv4InterfaceAddress iface = l3->GetAddress (i,0);
962  if (iface.GetLocal () == Ipv4Address ("127.0.0.1"))
963  {
964  return;
965  }
966  // Create a socket to listen only on this interface
967  Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (),UdpSocketFactory::GetTypeId ());
968  NS_ASSERT (socket != 0);
971  socket->BindToNetDevice (l3->GetNetDevice (i));
972  socket->SetAllowBroadcast (true);
973  socket->SetAttribute ("IpTtl",UintegerValue (1));
974  m_socketAddresses.insert (std::make_pair (socket,iface));
975  // Add local broadcast record to the routing table
976  Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (iface.GetLocal ()));
977  RoutingTableEntry rt (/*device=*/ dev, /*dst=*/ iface.GetBroadcast (), /*seqno=*/ 0,/*iface=*/ iface,/*hops=*/ 0,
978  /*next hop=*/ iface.GetBroadcast (), /*lifetime=*/ Simulator::GetMaximumSimulationTime ());
980  if (m_mainAddress == Ipv4Address ())
981  {
982  m_mainAddress = iface.GetLocal ();
983  }
985 }
986 
987 void
989 {
990  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
991  Ptr<NetDevice> dev = l3->GetNetDevice (i);
992  Ptr<Socket> socket = FindSocketWithInterfaceAddress (m_ipv4->GetAddress (i,0));
993  NS_ASSERT (socket);
994  socket->Close ();
995  m_socketAddresses.erase (socket);
996  if (m_socketAddresses.empty ())
997  {
998  NS_LOG_LOGIC ("No dsdv interfaces");
1000  return;
1001  }
1004 }
1005 
1006 void
1009 {
1010  NS_LOG_FUNCTION (this << " interface " << i << " address " << address);
1011  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
1012  if (!l3->IsUp (i))
1013  {
1014  return;
1015  }
1016  Ipv4InterfaceAddress iface = l3->GetAddress (i,0);
1018  if (!socket)
1019  {
1020  if (iface.GetLocal () == Ipv4Address ("127.0.0.1"))
1021  {
1022  return;
1023  }
1024  Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (),UdpSocketFactory::GetTypeId ());
1025  NS_ASSERT (socket != 0);
1027  // Bind to any IP address so that broadcasts can be received
1029  socket->BindToNetDevice (l3->GetNetDevice (i));
1030  socket->SetAllowBroadcast (true);
1031  m_socketAddresses.insert (std::make_pair (socket,iface));
1032  Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (iface.GetLocal ()));
1033  RoutingTableEntry rt (/*device=*/ dev, /*dst=*/ iface.GetBroadcast (),/*seqno=*/ 0, /*iface=*/ iface,/*hops=*/ 0,
1034  /*next hop=*/ iface.GetBroadcast (), /*lifetime=*/ Simulator::GetMaximumSimulationTime ());
1035  m_routingTable.AddRoute (rt);
1036  }
1037 }
1038 
1039 void
1042 {
1043  Ptr<Socket> socket = FindSocketWithInterfaceAddress (address);
1044  if (socket)
1045  {
1046  m_socketAddresses.erase (socket);
1047  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
1048  if (l3->GetNAddresses (i))
1049  {
1050  Ipv4InterfaceAddress iface = l3->GetAddress (i,0);
1051  // Create a socket to listen only on this interface
1052  Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (),UdpSocketFactory::GetTypeId ());
1053  NS_ASSERT (socket != 0);
1055  // Bind to any IP address so that broadcasts can be received
1057  socket->SetAllowBroadcast (true);
1058  m_socketAddresses.insert (std::make_pair (socket,iface));
1059  }
1060  }
1061 }
1062 
1065 {
1066  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
1067  != m_socketAddresses.end (); ++j)
1068  {
1069  Ptr<Socket> socket = j->first;
1070  Ipv4InterfaceAddress iface = j->second;
1071  if (iface == addr)
1072  {
1073  return socket;
1074  }
1075  }
1076  Ptr<Socket> socket;
1077  return socket;
1078 }
1079 
1080 void
1082  Ptr<const Packet> packet,
1083  const Ipv4Header & header)
1084 {
1085  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
1086  NS_ASSERT (l3 != 0);
1087  Ptr<Packet> p = packet->Copy ();
1088  l3->Send (p,route->GetSource (),header.GetDestination (),header.GetProtocol (),route);
1089 }
1090 
1091 void
1093  const Ipv4Header & header,
1094  Socket::SocketErrno err)
1095 {
1096  NS_LOG_DEBUG (m_mainAddress << " drop packet " << packet->GetUid () << " to "
1097  << header.GetDestination () << " from queue. Error " << err);
1098 }
1099 
1100 void
1102 {
1103  NS_LOG_FUNCTION (this);
1104  Ptr<Ipv4Route> route;
1105  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
1106  m_routingTable.GetListOfAllRoutes (allRoutes);
1107  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
1108  {
1109  RoutingTableEntry rt;
1110  rt = i->second;
1111  if (m_queue.Find (rt.GetDestination ()))
1112  {
1113  if (rt.GetHop () == 1)
1114  {
1115  route = rt.GetRoute ();
1116  NS_LOG_LOGIC ("A route exists from " << route->GetSource ()
1117  << " to neighboring destination "
1118  << route->GetDestination ());
1119  NS_ASSERT (route != 0);
1120  }
1121  else
1122  {
1123  RoutingTableEntry newrt;
1124  m_routingTable.LookupRoute (rt.GetNextHop (),newrt);
1125  route = newrt.GetRoute ();
1126  NS_LOG_LOGIC ("A route exists from " << route->GetSource ()
1127  << " to destination " << route->GetDestination () << " via "
1128  << rt.GetNextHop ());
1129  NS_ASSERT (route != 0);
1130  }
1131  SendPacketFromQueue (rt.GetDestination (),route);
1132  }
1133  }
1134 }
1135 
1136 void
1138  Ptr<Ipv4Route> route)
1139 {
1140  NS_LOG_DEBUG (m_mainAddress << " is sending a queued packet to destination " << dst);
1141  QueueEntry queueEntry;
1142  if (m_queue.Dequeue (dst,queueEntry))
1143  {
1145  Ptr<Packet> p = ConstCast<Packet> (queueEntry.GetPacket ());
1146  if (p->RemovePacketTag (tag))
1147  {
1148  if (tag.oif != -1 && tag.oif != m_ipv4->GetInterfaceForDevice (route->GetOutputDevice ()))
1149  {
1150  NS_LOG_DEBUG ("Output device doesn't match. Dropped.");
1151  return;
1152  }
1153  }
1155  Ipv4Header header = queueEntry.GetIpv4Header ();
1156  header.SetSource (route->GetSource ());
1157  header.SetTtl (header.GetTtl () + 1); // compensate extra TTL decrement by fake loopback routing
1158  ucb (route,p,header);
1159  if (m_queue.GetSize () != 0 && m_queue.Find (dst))
1160  {
1162  &RoutingProtocol::SendPacketFromQueue,this,dst,route);
1163  }
1164  }
1165 }
1166 
1167 Time
1169 {
1170  NS_LOG_FUNCTION ("Calculating the settling time for " << address);
1171  RoutingTableEntry mainrt;
1172  Time weightedTime;
1173  m_routingTable.LookupRoute (address,mainrt);
1174  if (EnableWST)
1175  {
1176  if (mainrt.GetSettlingTime () == Seconds (0))
1177  {
1178  return Seconds (0);
1179  }
1180  else
1181  {
1182  NS_LOG_DEBUG ("Route SettlingTime: " << mainrt.GetSettlingTime ().GetSeconds ()
1183  << " and LifeTime:" << mainrt.GetLifeTime ().GetSeconds ());
1184  weightedTime = Time (m_weightedFactor * mainrt.GetSettlingTime ().GetSeconds () + (1.0 - m_weightedFactor)
1185  * mainrt.GetLifeTime ().GetSeconds ());
1186  NS_LOG_DEBUG ("Calculated weightedTime:" << weightedTime.GetSeconds ());
1187  return weightedTime;
1188  }
1189  }
1190  return mainrt.GetSettlingTime ();
1191 }
1192 
1193 void
1195 {
1196  NS_LOG_FUNCTION ("Merging advertised table changes with main table before sending out periodic update");
1197  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
1199  if (allRoutes.size () > 0)
1200  {
1201  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
1202  {
1203  RoutingTableEntry advEntry = i->second;
1204  if ((advEntry.GetEntriesChanged () == true) && (!m_advRoutingTable.AnyRunningEvent (advEntry.GetDestination ())))
1205  {
1206  if (!(advEntry.GetSeqNo () % 2))
1207  {
1208  advEntry.SetFlag (VALID);
1209  advEntry.SetEntriesChanged (false);
1210  m_routingTable.Update (advEntry);
1211  NS_LOG_DEBUG ("Merged update for " << advEntry.GetDestination () << " with main routing Table");
1212  }
1214  }
1215  else
1216  {
1217  NS_LOG_DEBUG ("Event currently running. Cannot Merge Routing Tables");
1218  }
1219  }
1220  }
1221 }
1222 }
1223 }
void SetSource(Ipv4Address source)
Definition: ipv4-header.cc:285
void Start()
Start protocol operation.
static TypeId GetTypeId(void)
Get the type ID.
static const uint32_t DSDV_PORT
UDP Port for DSDV control traffic.
static Ipv4Mask GetOnes(void)
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Routing table entry.
Definition: dsdv-rtable.h:56
an Inet address class
Ipv4Address GetIpv4(void) const
static Ipv4Address GetAny(void)
void SetEntriesChanged(bool entriesChanged)
Definition: dsdv-rtable.h:161
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
std::map< Ptr< Socket >, Ipv4InterfaceAddress > m_socketAddresses
Raw socket per each IP interface, map socket -> iface address (IP + mask)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
AttributeValue implementation for Boolean.
Definition: boolean.h:34
Ipv4Mask GetMask(void) const
Get the network mask.
Callback template class.
Definition: callback.h:1164
Ipv4Address GetNextHop() const
Definition: dsdv-rtable.h:86
bool EnableRouteAggregation
This is a flag to enable route aggregation.
A simple Timer class.
Definition: timer.h:73
Time m_periodicUpdateInterval
PeriodicUpdateInterval specifies the periodic time interval between which the a node broadcasts its e...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
bool EnableBuffering
Flag that is used to enable or disable buffering.
bool AnyRunningEvent(Ipv4Address address)
Force delete an update waiting for settling time to complete as a better update to same destination w...
Definition: dsdv-rtable.cc:272
void SetDst(Ipv4Address destination)
Definition: dsdv-packet.h:71
Ipv4Header GetIpv4Header() const
Ipv4Address GetLocal(void) const
Get the local address.
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
ErrorCallback m_ecb
Error callback for own packets.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:234
uint32_t GetHopCount() const
Definition: dsdv-packet.h:86
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: boolean.h:81
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:824
uint64_t GetUid(void) const
Returns the packet's Uid.
Definition: packet.cc:368
EventId GetEventId(Ipv4Address address)
Get the EcentId associated with that address.
Definition: dsdv-rtable.cc:338
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1258
bool EnableWST
Flag that is used to enable or disable Weighted Settling Time.
TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
uint8_t GetProtocol(void) const
Definition: ipv4-header.cc:272
void SetFlag(RouteFlags flag)
Definition: dsdv-rtable.h:151
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void SetDstSeqno(uint32_t sequenceNumber)
Definition: dsdv-packet.h:91
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:903
uint32_t GetSeqNo() const
Definition: dsdv-rtable.h:116
void SetMaxPacketsPerDst(uint32_t len)
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:786
second
Definition: nstime.h:114
virtual void DoDispose()
Destructor implementation.
bool IsMulticast(void) const
virtual void NotifyInterfaceDown(uint32_t interface)
void GetListOfAllRoutes(std::map< Ipv4Address, RoutingTableEntry > &allRoutes)
Lookup list of all addresses in the routing table.
Definition: dsdv-rtable.cc:170
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
double m_weightedFactor
This is the wighted factor to determine the weighted settling time.
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:719
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:339
TAG_BUFFER_INLINE uint32_t ReadU32(void)
Definition: tag-buffer.h:215
uint32_t GetDstSeqno() const
Definition: dsdv-packet.h:96
void SendPacketFromQueue(Ipv4Address dst, Ptr< Ipv4Route > route)
Send packet from queue.
int32_t oif
Positive if output device is fixed in RouteOutput.
bool Update(RoutingTableEntry &rt)
Updating the routing Table with routing table entry rt.
Definition: dsdv-rtable.cc:136
DSDV routing protocol.
Ptr< Ipv4Route > GetRoute() const
Definition: dsdv-rtable.h:71
a polymophic address class
Definition: address.h:90
void SendPeriodicUpdate()
Broadcasts the entire routing table for every PeriodicUpdateInterval.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
void SetSource(Ipv4Address src)
Definition: ipv4-route.cc:49
Ipv4Address GetDst() const
Definition: dsdv-packet.h:76
Ptr< NetDevice > GetOutputDevice(void) const
Definition: ipv4-route.cc:84
Packet header for IPv4.
Definition: ipv4-header.h:31
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
bool ForceDeleteIpv4Event(Ipv4Address address)
Force delete an update waiting for settling time to complete as a better update to same destination w...
Definition: dsdv-rtable.cc:296
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:846
virtual uint32_t GetInteger(void)=0
Get the next random value as an integer drawn from the distribution.
Ptr< Socket > FindSocketWithInterfaceAddress(Ipv4InterfaceAddress iface) const
Find socket with local interface address iface.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1216
AttributeValue implementation for Time.
Definition: nstime.h:957
void Schedule(void)
Schedule a new event using the currently-configured delay, function, and arguments.
Definition: timer.cc:158
DSDV Queue Entry.
void SetGateway(Ipv4Address gw)
Definition: ipv4-route.cc:63
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
void SetFunction(FN fn)
Definition: timer.h:309
Hold an unsigned integer type.
Definition: uinteger.h:44
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
Definition: tag-buffer.h:186
void SetSeqNo(uint32_t sequenceNumber)
Definition: dsdv-rtable.h:111
void Purge(std::map< Ipv4Address, RoutingTableEntry > &removedAddresses)
Delete all outdated entries if Lifetime is expired.
Definition: dsdv-rtable.cc:208
bool IsBroadcast(void) const
uint32_t m_maxQueueLen
The maximum number of packets that we allow a routing protocol to buffer.
Ptr< Ipv4Route > LoopbackRoute(const Ipv4Header &header, Ptr< NetDevice > oif) const
Create loopback route for given header.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1480
uint32_t GetUid(void) const
Definition: event-id.cc:89
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
Definition: socket.cc:128
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition: socket.cc:71
Ipv4Address GetSource(void) const
Definition: ipv4-route.cc:56
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
Time GetSettlingTime() const
Definition: dsdv-rtable.h:146
void SetMaxQueueLen(uint32_t len)
UnicastForwardCallback m_scb
Unicast callback for own packets.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
double f(double x, void *params)
Definition: 80211b.c:60
tag a set of bytes in a packet
Definition: tag.h:36
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
Implement the Ipv4 layer.
Time GetSettlingTime(Ipv4Address dst)
Get settlingTime for a destination.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
void DeferredRouteOutput(Ptr< const Packet > p, const Ipv4Header &header, UnicastForwardCallback ucb, ErrorCallback ecb)
Queue packet untill we find a route.
void LookForQueuedPackets(void)
Look for any queued packets to send them out.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time m_routeAggregationTime
Parameter that holds the route aggregation time interval.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
bool Dequeue(Ipv4Address dst, QueueEntry &entry)
Return first found (the earliest) entry for given destination.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
PacketQueue m_queue
A "drop front on full" queue used by the routing layer to buffer packets to which it does not have a ...
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
Definition: dsdv-rtable.cc:148
UnicastForwardCallback GetUnicastForwardCallback() const
Time m_maxQueueTime
The maximum period of time that a routing protocol is allowed to buffer a packet for.
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
Definition: dsdv-rtable.cc:128
void RecvDsdv(Ptr< Socket > socket)
Receive and process dsdv control packet.
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
Definition: simulator.h:1379
Ipv4Address m_mainAddress
Nodes IP address.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:958
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:223
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Equivalent in Linux to dst_entry.dev.
Definition: ipv4-route.cc:77
static Ipv4Address GetLoopback(void)
void SendTriggeredUpdate()
Sends trigger update from a node.
uint32_t m_maxQueuedPacketsPerDst
The maximum number of packets that we allow per destination to buffer.
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition: socket.cc:330
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: double.h:42
void GetListOfDestinationWithNextHop(Ipv4Address nxtHp, std::map< Ipv4Address, RoutingTableEntry > &dstList)
Lookup list of addresses for which nxtHp is the next Hop address.
Definition: dsdv-rtable.cc:183
bool DeleteIpv4Event(Ipv4Address address)
Clear up the entry from the map after the event is completed.
Definition: dsdv-rtable.cc:311
Ipv4Address GetDestination(void) const
Definition: ipv4-route.cc:42
uint32_t GetHop() const
Definition: dsdv-rtable.h:126
void Send(Ptr< Ipv4Route >, Ptr< const Packet >, const Ipv4Header &)
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
read and write tag data
Definition: tag-buffer.h:51
Ipv4Address GetBroadcast(void) const
Get the broadcast address.
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:388
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: dsdv-rtable.cc:111
a class to store IPv4 address information on an interface
An identifier for simulation events.
Definition: event-id.h:53
Ptr< NetDevice > m_lo
Loopback device used to defer route requests until a route is found.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:831
A network Node.
Definition: node.h:56
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
bool GetEntriesChanged() const
Definition: dsdv-rtable.h:166
void SetTtl(uint8_t ttl)
Definition: ipv4-header.cc:259
Ptr< const Packet > GetPacket() const
void SetHopCount(uint32_t hopCount)
Definition: dsdv-packet.h:81
Tag used by DSDV implementation.
DSDV Update Packet Format.
Definition: dsdv-packet.h:58
Abstract base class for IPv4 routing protocols.
Ipv4Address GetDestination() const
Definition: dsdv-rtable.h:66
void Clear()
Delete all entries from routing table.
Definition: dsdv-rtable.h:273
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
Ptr< Ipv4 > m_ipv4
IP protocol.
void Setholddowntime(Time t)
Definition: dsdv-rtable.h:330
RoutingTable m_advRoutingTable
Advertised Routing table for the node.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:911
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:330
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:220
virtual void NotifyInterfaceUp(uint32_t interface)
uint8_t GetTtl(void) const
Definition: ipv4-header.cc:265
static const uint32_t packetSize
void Print(std::ostream &os) const
bool AddIpv4Event(Ipv4Address address, EventId id)
Add an event for a destination address so that the update to for that destination is sent after the e...
Definition: dsdv-rtable.cc:264
void Print(Ptr< OutputStreamWrapper > stream) const
Print routing table.
Definition: dsdv-rtable.cc:252
tuple address
Definition: first.py:37
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: dsdv-rtable.cc:72
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
Timer m_periodicUpdateTimer
Timer to trigger periodic updates from a node.
uint32_t GetSize()
Number of entries.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
virtual int Close(void)=0
Close a socket.
RoutingTable m_routingTable
Main Routing table for the node.
void Drop(Ptr< const Packet >, const Ipv4Header &, Socket::SocketErrno)
Notify that packet is dropped for some reason.
Time GetDelayLeft(void) const
Definition: timer.cc:87
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:191
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:58
Time m_settlingTime
SettlingTime specifies the time for which a node waits before propagating an update.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:826
Time GetLifeTime() const
Definition: dsdv-rtable.h:136
static Time GetMaximumSimulationTime(void)
Get the maximum representable simulation time.
Definition: simulator.cc:336
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
virtual Address GetAddress(void) const =0
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:257
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
void SetDestination(Ipv4Address dest)
Definition: ipv4-route.cc:35
Callback< void, Ptr< Ipv4Route >, Ptr< const Packet >, const Ipv4Header & > UnicastForwardCallback
Callback for unicast packets to be forwarded.
uint32_t Holdtimes
Holdtimes is the multiplicative factor of PeriodicUpdateInterval for which the node waits since the l...
bool Enqueue(QueueEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...