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 #define NS_LOG_APPEND_CONTEXT \
34  if (GetObject<Node> ()) { std::clog << "[node " << GetObject<Node> ()->GetId () << "] "; }
35 
36 #include "dsdv-routing-protocol.h"
37 #include "ns3/log.h"
38 #include "ns3/inet-socket-address.h"
39 #include "ns3/trace-source-accessor.h"
40 #include "ns3/udp-socket-factory.h"
41 #include "ns3/wifi-net-device.h"
42 #include "ns3/boolean.h"
43 #include "ns3/double.h"
44 #include "ns3/uinteger.h"
45 #include "ns3/qkd-manager.h"
46 
47 namespace ns3 {
48 
49 NS_LOG_COMPONENT_DEFINE ("DsdvRoutingProtocol");
50 
51 namespace dsdv {
52 
53 NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol);
54 
56 const uint32_t RoutingProtocol::DSDV_PORT = 69;
57 
59 struct DeferredRouteOutputTag : public Tag
60 {
62  int32_t oif;
63 
69  DeferredRouteOutputTag (int32_t o = -1)
70  : Tag (),
71  oif (o)
72  {
73  }
74 
79  static TypeId
81  {
82  static TypeId tid = TypeId ("ns3::dsdv::DeferredRouteOutputTag")
83  .SetParent<Tag> ()
84  .SetGroupName ("Dsdv")
85  .AddConstructor<DeferredRouteOutputTag> ()
86  ;
87  return tid;
88  }
89 
90  TypeId
92  {
93  return GetTypeId ();
94  }
95 
96  uint32_t
98  {
99  return sizeof(int32_t);
100  }
101 
102  void
104  {
105  i.WriteU32 (oif);
106  }
107 
108  void
110  {
111  oif = i.ReadU32 ();
112  }
113 
114  void
115  Print (std::ostream &os) const
116  {
117  os << "DeferredRouteOutputTag: output interface = " << oif;
118  }
119 };
120 
121 TypeId
123 {
124  static TypeId tid = TypeId ("ns3::dsdv::RoutingProtocol")
126  .SetGroupName ("Dsdv")
127  .AddConstructor<RoutingProtocol> ()
128  .AddAttribute ("PeriodicUpdateInterval","Periodic interval between exchange of full routing tables among nodes. ",
129  TimeValue (Seconds (15)),
131  MakeTimeChecker ())
132  .AddAttribute ("SettlingTime", "Minimum time an update is to be stored in adv table before sending out"
133  "in case of change in metric (in seconds)",
134  TimeValue (Seconds (5)),
136  MakeTimeChecker ())
137  .AddAttribute ("MaxQueueLen", "Maximum number of packets that we allow a routing protocol to buffer.",
138  UintegerValue (500 /*assuming maximum nodes in simulation is 100*/),
140  MakeUintegerChecker<uint32_t> ())
141  .AddAttribute ("MaxQueuedPacketsPerDst", "Maximum number of packets that we allow per destination to buffer.",
142  UintegerValue (5),
144  MakeUintegerChecker<uint32_t> ())
145  .AddAttribute ("MaxQueueTime","Maximum time packets can be queued (in seconds)",
146  TimeValue (Seconds (30)),
148  MakeTimeChecker ())
149  .AddAttribute ("EnableBuffering","Enables buffering of data packets if no route to destination is available",
150  BooleanValue (false),
154  .AddAttribute ("EnableWST","Enables Weighted Settling Time for the updates before advertising",
155  BooleanValue (true),
159  .AddAttribute ("Holdtimes","Times the forwarding Interval to purge the route.",
160  UintegerValue (3),
162  MakeUintegerChecker<uint32_t> ())
163  .AddAttribute ("WeightedFactor","WeightedFactor for the settling time if Weighted Settling Time is enabled",
164  DoubleValue (0.875),
166  MakeDoubleChecker<double> ())
167  .AddAttribute ("EnableRouteAggregation","Enables Weighted Settling Time for the updates before advertising",
168  BooleanValue (false),
172  .AddAttribute ("RouteAggregationTime","Time to aggregate updates before sending them out (in seconds)",
173  TimeValue (Seconds (1)),
175  MakeTimeChecker ());
176  return tid;
177 }
178 
179 void
181 {
182  EnableBuffering = f;
183 }
184 bool
186 {
187  return EnableBuffering;
188 }
189 void
191 {
192  EnableWST = f;
193 }
194 bool
196 {
197  return EnableWST;
198 }
199 void
201 {
202  EnableRouteAggregation = f;
203 }
204 bool
206 {
207  return EnableRouteAggregation;
208 }
209 
210 int64_t
212 {
213  NS_LOG_FUNCTION (this << stream);
214  m_uniformRandomVariable->SetStream (stream);
215  return 1;
216 }
217 
219  : m_routingTable (),
220  m_advRoutingTable (),
221  m_queue (),
222  m_periodicUpdateTimer (Timer::CANCEL_ON_DESTROY)
223 {
224  m_uniformRandomVariable = CreateObject<UniformRandomVariable> ();
225 }
226 
228 {
229 }
230 
231 void
233 {
234  m_ipv4 = 0;
235  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::iterator iter = m_socketAddresses.begin (); iter
236  != m_socketAddresses.end (); iter++)
237  {
238  iter->first->Close ();
239  }
240  m_socketAddresses.clear ();
242 }
243 
244 void
246 {
247  *stream->GetStream () << "Node: " << m_ipv4->GetObject<Node> ()->GetId ()
248  << ", Time: " << Now ().As (unit)
249  << ", Local time: " << GetObject<Node> ()->GetLocalTime ().As (unit)
250  << ", DSDV Routing table" << std::endl;
251 
252  m_routingTable.Print (stream);
253  *stream->GetStream () << std::endl;
254 }
255 
256 
257 void
258 RoutingProtocol::PrintRoutingTable (Ptr<OutputStreamWrapper> streamWrapper, std::string additionalData) const
259 {
260 
261  NS_LOG_FUNCTION (this << Simulator::Now ().GetNanoSeconds() << additionalData);
262 
263  std::ostream *stream = streamWrapper->GetStream ();
264  *stream << "Node: " << m_ipv4->GetObject<Node> ()->GetId () << "\t"
265  << " Time: " << Simulator::Now ().GetSeconds () << "\t"
266  << "s " << "\t" << additionalData << std::endl;
267 
268  m_routingTable.Print (streamWrapper);
269 }
270 
271 
272 void
274 {
279  m_advRoutingTable.Setholddowntime (Time (Holdtimes * m_periodicUpdateInterval));
284 }
285 
288  const Ipv4Header &header,
289  Ptr<NetDevice> oif,
290  Socket::SocketErrno &sockerr)
291 {
292  NS_LOG_FUNCTION (this << header << (oif ? oif->GetIfIndex () : 0));
293 
294  if (!p)
295  {
296  return LoopbackRoute (header,oif);
297  }
298  if (m_socketAddresses.empty ())
299  {
300  sockerr = Socket::ERROR_NOROUTETOHOST;
301  NS_LOG_LOGIC ("No dsdv interfaces");
302  Ptr<Ipv4Route> route;
303  return route;
304  }
305  std::map<Ipv4Address, RoutingTableEntry> removedAddresses;
306  sockerr = Socket::ERROR_NOTERROR;
307  Ptr<Ipv4Route> route;
308  Ipv4Address dst = header.GetDestination ();
309  NS_LOG_DEBUG ("Packet Size: " << p->GetSize ()
310  << ", Packet id: " << p->GetUid () << ", Destination address in Packet: " << dst);
312  m_routingTable.Purge (removedAddresses);
313  for (std::map<Ipv4Address, RoutingTableEntry>::iterator rmItr = removedAddresses.begin ();
314  rmItr != removedAddresses.end (); ++rmItr)
315  {
316  rmItr->second.SetEntriesChanged (true);
317  rmItr->second.SetSeqNo (rmItr->second.GetSeqNo () + 1);
318  m_advRoutingTable.AddRoute (rmItr->second);
319  }
320  if (!removedAddresses.empty ())
321  {
323  }
324  if (m_routingTable.LookupRoute (dst,rt))
325  {
326  if (EnableBuffering)
327  {
329  }
330  if (rt.GetHop () == 1)
331  {
332  route = rt.GetRoute ();
333  NS_ASSERT (route != 0);
334  NS_LOG_DEBUG ("A route exists from " << route->GetSource ()
335  << " to neighboring destination "
336  << route->GetDestination ());
337  if (oif != 0 && route->GetOutputDevice () != oif)
338  {
339  NS_LOG_DEBUG ("Output device doesn't match. Dropped.");
340  sockerr = Socket::ERROR_NOROUTETOHOST;
341  return Ptr<Ipv4Route> ();
342  }
343  return route;
344  }
345  else
346  {
347  RoutingTableEntry newrt;
348  if (m_routingTable.LookupRoute (rt.GetNextHop (),newrt))
349  {
350  route = newrt.GetRoute ();
351  NS_ASSERT (route != 0);
352  NS_LOG_DEBUG ("A route exists from " << route->GetSource ()
353  << " to destination " << dst << " via "
354  << rt.GetNextHop ());
355  if (oif != 0 && route->GetOutputDevice () != oif)
356  {
357  NS_LOG_DEBUG ("Output device doesn't match. Dropped.");
358  sockerr = Socket::ERROR_NOROUTETOHOST;
359  return Ptr<Ipv4Route> ();
360  }
361  return route;
362  }
363  }
364  }
365 
366  if (EnableBuffering)
367  {
368  uint32_t iif = (oif ? m_ipv4->GetInterfaceForDevice (oif) : -1);
369  DeferredRouteOutputTag tag (iif);
370  if (!p->PeekPacketTag (tag))
371  {
372  p->AddPacketTag (tag);
373  }
374  }
375  return LoopbackRoute (header,oif);
376 }
377 
378 void
380  const Ipv4Header & header,
382  ErrorCallback ecb)
383 {
384  NS_LOG_FUNCTION (this << p << header);
385  NS_ASSERT (p != 0 && p != Ptr<Packet> ());
386  QueueEntry newEntry (p,header,ucb,ecb);
387  bool result = m_queue.Enqueue (newEntry);
388  if (result)
389  {
390  NS_LOG_DEBUG ("Added packet " << p->GetUid () << " to queue.");
391  }
392 }
393 
394 bool
396  const Ipv4Header &header,
401  ErrorCallback ecb)
402 {
403  NS_LOG_FUNCTION (m_mainAddress << " received packet " << p->GetUid ()
404  << " from " << header.GetSource ()
405  << " on interface " << idev->GetAddress ()
406  << " to destination " << header.GetDestination ());
407  if (m_socketAddresses.empty ())
408  {
409  NS_LOG_DEBUG ("No dsdv interfaces");
410  return false;
411  }
412  NS_ASSERT (m_ipv4 != 0);
413  // Check if input device supports IP
414  NS_ASSERT (m_ipv4->GetInterfaceForDevice (idev) >= 0);
415  int32_t iif = m_ipv4->GetInterfaceForDevice (idev);
416 
417  Ipv4Address dst = header.GetDestination ();
418  Ipv4Address origin = header.GetSource ();
419 
420  // DSDV is not a multicast routing protocol
421  if (dst.IsMulticast ())
422  {
423  NS_LOG_FUNCTION(this << "DSDV is not a multicast routing protocol");
424  return false;
425  }
426 
427  // Deferred route request
428  if (EnableBuffering == true && idev == m_lo)
429  {
431  if (p->PeekPacketTag (tag))
432  {
433  DeferredRouteOutput (p,header,ucb,ecb);
434  return true;
435  }
436  }
437 
438  NS_LOG_FUNCTION(this << "DSDV 438");
439 
440  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j =
441  m_socketAddresses.begin (); j != m_socketAddresses.end (); ++j)
442  {
443  Ipv4InterfaceAddress iface = j->second;
444  if (origin == iface.GetLocal ())
445  {
446  return true;
447  }
448  }
449 
450  NS_LOG_FUNCTION(this << "DSDV 448");
451 
452  // LOCAL DELIVARY TO DSDV INTERFACES
453  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
454  != m_socketAddresses.end (); ++j)
455  {
456  Ipv4InterfaceAddress iface = j->second;
457  if (m_ipv4->GetInterfaceForAddress (iface.GetLocal ()) == iif)
458  {
459  if (dst == iface.GetBroadcast () || dst.IsBroadcast ())
460  {
461  Ptr<Packet> packet = p->Copy ();
462  if (lcb.IsNull () == false)
463  {
464  NS_LOG_LOGIC ("Broadcast local delivery to " << iface.GetLocal ());
465 
466  NS_LOG_FUNCTION(this << "Before lcb");
467  lcb (p, header, iif);
468  // Fall through to additional processing
469  NS_LOG_FUNCTION(this << "After lcb");
470  }
471  else
472  {
473  NS_LOG_ERROR ("Unable to deliver packet locally due to null callback " << p->GetUid () << " from " << origin);
474  ecb (p, header, Socket::ERROR_NOROUTETOHOST);
475  }
476  if (header.GetTtl () > 1)
477  {
478  NS_LOG_LOGIC ("Forward broadcast. TTL " << (uint16_t) header.GetTtl ());
479  RoutingTableEntry toBroadcast;
480  if (m_routingTable.LookupRoute (dst,toBroadcast,true))
481  {
482  Ptr<Ipv4Route> route = toBroadcast.GetRoute ();
483  ucb (route,packet,header);
484  }
485  else
486  {
487  NS_LOG_DEBUG ("No route to forward. Drop packet " << p->GetUid ());
488  }
489  }
490  return true;
491  }
492  }
493  }
494 
495  if (m_ipv4->IsDestinationAddress (dst, iif))
496  {
497  if (lcb.IsNull () == false)
498  {
499  NS_LOG_LOGIC ("Unicast local delivery to " << dst);
500  lcb (p, header, iif);
501  }
502  else
503  {
504  NS_LOG_ERROR ("Unable to deliver packet locally due to null callback " << p->GetUid () << " from " << origin);
505  ecb (p, header, Socket::ERROR_NOROUTETOHOST);
506  }
507  return true;
508  }
509 
510  // Check if input device supports IP forwarding
511  if (m_ipv4->IsForwarding (iif) == false)
512  {
513  NS_LOG_LOGIC ("Forwarding disabled for this interface");
514  ecb (p, header, Socket::ERROR_NOROUTETOHOST);
515  return true;
516  }
517 
518  RoutingTableEntry toDst;
519  if (m_routingTable.LookupRoute (dst,toDst))
520  {
522  if (m_routingTable.LookupRoute (toDst.GetNextHop (),ne))
523  {
524  Ptr<Ipv4Route> route = ne.GetRoute ();
525  NS_LOG_LOGIC (m_mainAddress << " is forwarding packet " << p->GetUid ()
526  << " to " << dst
527  << " from " << header.GetSource ()
528  << " via nexthop neighbor " << toDst.GetNextHop ());
529  ucb (route,p,header);
530  return true;
531  }
532  }
533  NS_LOG_LOGIC ("Drop packet " << p->GetUid ()
534  << " as there is no route to forward it.");
535  return false;
536 }
537 
540 {
541  NS_ASSERT (m_lo != 0);
542  Ptr<Ipv4Route> rt = Create<Ipv4Route> ();
543  rt->SetDestination (hdr.GetDestination ());
544  // rt->SetSource (hdr.GetSource ());
545  //
546  // Source address selection here is tricky. The loopback route is
547  // returned when DSDV does not have a route; this causes the packet
548  // to be looped back and handled (cached) in RouteInput() method
549  // while a route is found. However, connection-oriented protocols
550  // like TCP need to create an endpoint four-tuple (src, src port,
551  // dst, dst port) and create a pseudo-header for checksumming. So,
552  // DSDV needs to guess correctly what the eventual source address
553  // will be.
554  //
555  // For single interface, single address nodes, this is not a problem.
556  // When there are possibly multiple outgoing interfaces, the policy
557  // implemented here is to pick the first available DSDV interface.
558  // If RouteOutput() caller specified an outgoing interface, that
559  // further constrains the selection of source address
560  //
561  std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin ();
562  if (oif)
563  {
564  // Iterate to find an address on the oif device
565  for (j = m_socketAddresses.begin (); j != m_socketAddresses.end (); ++j)
566  {
567  Ipv4Address addr = j->second.GetLocal ();
568  int32_t interface = m_ipv4->GetInterfaceForAddress (addr);
569  if (oif == m_ipv4->GetNetDevice (static_cast<uint32_t> (interface)))
570  {
571  rt->SetSource (addr);
572  break;
573  }
574  }
575  }
576  else
577  {
578  rt->SetSource (j->second.GetLocal ());
579  }
580  NS_ASSERT_MSG (rt->GetSource () != Ipv4Address (), "Valid DSDV source address not found");
581  rt->SetGateway (Ipv4Address ("127.0.0.1"));
582  rt->SetOutputDevice (m_lo);
583  return rt;
584 }
585 
586 void
588 {
589  Address sourceAddress;
590  Ptr<Packet> advpacket = Create<Packet> ();
591  advpacket = m_ipv4->GetObject<Node> ()->GetObject<QKDManager> ()->MarkEncrypt (advpacket);
592 
593  Ptr<Packet> packet = socket->RecvFrom (sourceAddress);
594  InetSocketAddress inetSourceAddr = InetSocketAddress::ConvertFrom (sourceAddress);
595  Ipv4Address sender = inetSourceAddr.GetIpv4 ();
596  Ipv4Address receiver = m_socketAddresses[socket].GetLocal ();
597  Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (receiver));
598  uint32_t packetSize = packet->GetSize ();
599  NS_LOG_FUNCTION (m_mainAddress << " received dsdv packet of size: " << packetSize
600  << " and packet id: " << packet->GetUid ());
601  uint32_t count = 0;
602  for (; packetSize > 0; packetSize = packetSize - 12)
603  {
604  count = 0;
605  DsdvHeader dsdvHeader, tempDsdvHeader;
606  packet->RemoveHeader (dsdvHeader);
607  NS_LOG_DEBUG ("Processing new update for " << dsdvHeader.GetDst ());
608  /*Verifying if the packets sent by me were returned back to me. If yes, discarding them!*/
609  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
610  != m_socketAddresses.end (); ++j)
611  {
612  Ipv4InterfaceAddress interface = j->second;
613  if (dsdvHeader.GetDst () == interface.GetLocal ())
614  {
615  if (dsdvHeader.GetDstSeqno () % 2 == 1)
616  {
617  NS_LOG_DEBUG ("Sent Dsdv update back to the same Destination, "
618  "with infinite metric. Time left to send fwd update: "
620  count++;
621  }
622  else
623  {
624  NS_LOG_DEBUG ("Received update for my address. Discarding this.");
625  count++;
626  }
627  }
628  }
629  if (count > 0)
630  {
631  continue;
632  }
633  NS_LOG_DEBUG ("Received a DSDV packet from "
634  << sender << " to " << receiver << ". Details are: Destination: " << dsdvHeader.GetDst () << ", Seq No: "
635  << dsdvHeader.GetDstSeqno () << ", HopCount: " << dsdvHeader.GetHopCount ());
636  RoutingTableEntry fwdTableEntry, advTableEntry;
637  EventId event;
638  bool permanentTableVerifier = m_routingTable.LookupRoute (dsdvHeader.GetDst (),fwdTableEntry);
639  if (permanentTableVerifier == false)
640  {
641  if (dsdvHeader.GetDstSeqno () % 2 != 1)
642  {
643  NS_LOG_DEBUG ("Received New Route!");
644  RoutingTableEntry newEntry (
645  /*device=*/ dev, /*dst=*/
646  dsdvHeader.GetDst (), /*seqno=*/
647  dsdvHeader.GetDstSeqno (),
648  /*iface=*/ m_ipv4->GetAddress (m_ipv4->GetInterfaceForAddress (receiver), 0),
649  /*hops=*/ dsdvHeader.GetHopCount (), /*next hop=*/
650  sender, /*lifetime=*/
651  Simulator::Now (), /*settlingTime*/
652  m_settlingTime, /*entries changed*/
653  true);
654  newEntry.SetFlag (VALID);
655  m_routingTable.AddRoute (newEntry);
656  NS_LOG_DEBUG ("New Route added to both tables");
657  m_advRoutingTable.AddRoute (newEntry);
658  }
659  else
660  {
661  // received update not present in main routing table and also with infinite metric
662  NS_LOG_DEBUG ("Discarding this update as this route is not present in "
663  "main routing table and received with infinite metric");
664  }
665  }
666  else
667  {
668  if (!m_advRoutingTable.LookupRoute (dsdvHeader.GetDst (),advTableEntry))
669  {
671  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
673  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
674  {
675  NS_LOG_DEBUG ("ADV table routes are:" << i->second.GetDestination ());
676  }
677  // present in fwd table and not in advtable
678  m_advRoutingTable.AddRoute (fwdTableEntry);
679  m_advRoutingTable.LookupRoute (dsdvHeader.GetDst (),advTableEntry);
680  }
681  if (dsdvHeader.GetDstSeqno () % 2 != 1)
682  {
683  if (dsdvHeader.GetDstSeqno () > advTableEntry.GetSeqNo ())
684  {
685  // Received update with better seq number. Clear any old events that are running
686  if (m_advRoutingTable.ForceDeleteIpv4Event (dsdvHeader.GetDst ()))
687  {
688  NS_LOG_DEBUG ("Canceling the timer to update route with better seq number");
689  }
690  // if its a changed metric *nomatter* where the update came from, wait for WST
691  if (dsdvHeader.GetHopCount () != advTableEntry.GetHop ())
692  {
693  advTableEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
694  advTableEntry.SetLifeTime (Simulator::Now ());
695  advTableEntry.SetFlag (VALID);
696  advTableEntry.SetEntriesChanged (true);
697  advTableEntry.SetNextHop (sender);
698  advTableEntry.SetHop (dsdvHeader.GetHopCount ());
699  NS_LOG_DEBUG ("Received update with better sequence number and changed metric.Waiting for WST");
700  Time tempSettlingtime = GetSettlingTime (dsdvHeader.GetDst ());
701  advTableEntry.SetSettlingTime (tempSettlingtime);
702  NS_LOG_DEBUG ("Added Settling Time:" << tempSettlingtime.GetSeconds ()
703  << "s as there is no event running for this route");
704  event = Simulator::Schedule (tempSettlingtime,&RoutingProtocol::SendTriggeredUpdate,this);
705  m_advRoutingTable.AddIpv4Event (dsdvHeader.GetDst (),event);
706  NS_LOG_DEBUG ("EventCreated EventUID: " << event.GetUid ());
707  // if received changed metric, use it but adv it only after wst
708  m_routingTable.Update (advTableEntry);
709  m_advRoutingTable.Update (advTableEntry);
710  }
711  else
712  {
713  // Received update with better seq number and same metric.
714  advTableEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
715  advTableEntry.SetLifeTime (Simulator::Now ());
716  advTableEntry.SetFlag (VALID);
717  advTableEntry.SetEntriesChanged (true);
718  advTableEntry.SetNextHop (sender);
719  advTableEntry.SetHop (dsdvHeader.GetHopCount ());
720  m_advRoutingTable.Update (advTableEntry);
721  NS_LOG_DEBUG ("Route with better sequence number and same metric received. Advertised without WST");
722  }
723  }
724  else if (dsdvHeader.GetDstSeqno () == advTableEntry.GetSeqNo ())
725  {
726  if (dsdvHeader.GetHopCount () < advTableEntry.GetHop ())
727  {
728  /*Received update with same seq number and better hop count.
729  * As the metric is changed, we will have to wait for WST before sending out this update.
730  */
731  NS_LOG_DEBUG ("Canceling any existing timer to update route with same sequence number "
732  "and better hop count");
734  advTableEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
735  advTableEntry.SetLifeTime (Simulator::Now ());
736  advTableEntry.SetFlag (VALID);
737  advTableEntry.SetEntriesChanged (true);
738  advTableEntry.SetNextHop (sender);
739  advTableEntry.SetHop (dsdvHeader.GetHopCount ());
740  Time tempSettlingtime = GetSettlingTime (dsdvHeader.GetDst ());
741  advTableEntry.SetSettlingTime (tempSettlingtime);
742  NS_LOG_DEBUG ("Added Settling Time," << tempSettlingtime.GetSeconds ()
743  << " as there is no current event running for this route");
744  event = Simulator::Schedule (tempSettlingtime,&RoutingProtocol::SendTriggeredUpdate,this);
745  m_advRoutingTable.AddIpv4Event (dsdvHeader.GetDst (),event);
746  NS_LOG_DEBUG ("EventCreated EventUID: " << event.GetUid ());
747  // if received changed metric, use it but adv it only after wst
748  m_routingTable.Update (advTableEntry);
749  m_advRoutingTable.Update (advTableEntry);
750  }
751  else
752  {
753  /*Received update with same seq number but with same or greater hop count.
754  * Discard that update.
755  */
756  if (!m_advRoutingTable.AnyRunningEvent (dsdvHeader.GetDst ()))
757  {
758  /*update the timer only if nexthop address matches thus discarding
759  * updates to that destination from other nodes.
760  */
761  if (advTableEntry.GetNextHop () == sender)
762  {
763  advTableEntry.SetLifeTime (Simulator::Now ());
764  m_routingTable.Update (advTableEntry);
765  }
767  dsdvHeader.GetDst ());
768  }
769  NS_LOG_DEBUG ("Received update with same seq number and "
770  "same/worst metric for, " << dsdvHeader.GetDst () << ". Discarding the update.");
771  }
772  }
773  else
774  {
775  // Received update with an old sequence number. Discard the update
776  if (!m_advRoutingTable.AnyRunningEvent (dsdvHeader.GetDst ()))
777  {
778  m_advRoutingTable.DeleteRoute (dsdvHeader.GetDst ());
779  }
780  NS_LOG_DEBUG (dsdvHeader.GetDst () << " : Received update with old seq number. Discarding the update.");
781  }
782  }
783  else
784  {
785  NS_LOG_DEBUG ("Route with infinite metric received for "
786  << dsdvHeader.GetDst () << " from " << sender);
787  // Delete route only if update was received from my nexthop neighbor
788  if (sender == advTableEntry.GetNextHop ())
789  {
790  NS_LOG_DEBUG ("Triggering an update for this unreachable route:");
791  std::map<Ipv4Address, RoutingTableEntry> dstsWithNextHopSrc;
792  m_routingTable.GetListOfDestinationWithNextHop (dsdvHeader.GetDst (),dstsWithNextHopSrc);
793  m_routingTable.DeleteRoute (dsdvHeader.GetDst ());
794  advTableEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
795  advTableEntry.SetEntriesChanged (true);
796  m_advRoutingTable.Update (advTableEntry);
797  for (std::map<Ipv4Address, RoutingTableEntry>::iterator i = dstsWithNextHopSrc.begin (); i
798  != dstsWithNextHopSrc.end (); ++i)
799  {
800  i->second.SetSeqNo (i->second.GetSeqNo () + 1);
801  i->second.SetEntriesChanged (true);
802  m_advRoutingTable.AddRoute (i->second);
803  m_routingTable.DeleteRoute (i->second.GetDestination ());
804  }
805  }
806  else
807  {
808  if (!m_advRoutingTable.AnyRunningEvent (dsdvHeader.GetDst ()))
809  {
810  m_advRoutingTable.DeleteRoute (dsdvHeader.GetDst ());
811  }
812  NS_LOG_DEBUG (dsdvHeader.GetDst () <<
813  " : Discard this link break update as it was received from a different neighbor "
814  "and I can reach the destination");
815  }
816  }
817  }
818  }
819  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
821  if (EnableRouteAggregation && allRoutes.size () > 0)
822  {
824  }
825  else
826  {
828  }
829 }
830 
831 
832 void
834 {
835  this->PrintRoutingTable (routingStream, "SendTriggeredUpdate");
836 
837  NS_LOG_FUNCTION (m_mainAddress << " is sending a triggered update");
838  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
840  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
841  != m_socketAddresses.end (); ++j)
842  {
843  DsdvHeader dsdvHeader;
844  Ptr<Socket> socket = j->first;
845  Ipv4InterfaceAddress iface = j->second;
846  Ptr<Packet> packet = Create<Packet> ();
847  packet = m_ipv4->GetObject<Node> ()->GetObject<QKDManager> ()->MarkEncrypt (packet);
848 
849  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
850  {
851  NS_LOG_LOGIC ("Destination: " << i->second.GetDestination ()
852  << " SeqNo:" << i->second.GetSeqNo () << " HopCount:"
853  << i->second.GetHop () + 1);
854  RoutingTableEntry temp = i->second;
855  if ((i->second.GetEntriesChanged () == true) && (!m_advRoutingTable.AnyRunningEvent (temp.GetDestination ())))
856  {
857  dsdvHeader.SetDst (i->second.GetDestination ());
858  dsdvHeader.SetDstSeqno (i->second.GetSeqNo ());
859  dsdvHeader.SetHopCount (i->second.GetHop () + 1);
860  temp.SetFlag (VALID);
861  temp.SetEntriesChanged (false);
862  m_advRoutingTable.DeleteIpv4Event (temp.GetDestination ());
863  if (!(temp.GetSeqNo () % 2))
864  {
865  m_routingTable.Update (temp);
866  }
867  packet->AddHeader (dsdvHeader);
868  m_advRoutingTable.DeleteRoute (temp.GetDestination ());
869  NS_LOG_DEBUG ("Deleted this route from the advertised table");
870  }
871  else
872  {
873  EventId event = m_advRoutingTable.GetEventId (temp.GetDestination ());
874  NS_ASSERT (event.GetUid () != 0);
875  NS_LOG_DEBUG ("EventID " << event.GetUid () << " associated with "
876  << temp.GetDestination () << " has not expired, waiting in adv table");
877  }
878  }
879  if (packet->GetSize () >= 12)
880  {
881  RoutingTableEntry temp2;
882  // m_routingTable.LookupRoute (m_ipv4->GetAddress (1, 0).GetBroadcast (), temp2);
883  m_routingTable.LookupRoute (iface.GetBroadcast (), temp2);
884  //dsdvHeader.SetDst (m_ipv4->GetAddress (1, 0).GetLocal ());
885  dsdvHeader.SetDst (iface.GetLocal ());
886  dsdvHeader.SetDstSeqno (temp2.GetSeqNo ());
887  dsdvHeader.SetHopCount (temp2.GetHop () + 1);
888 
889  NS_LOG_DEBUG ("Adding my update as well to the packet");
890  packet->AddHeader (dsdvHeader);
891 
892 
894  // ADD INTERNAL QKD COMMAND TAG
896 
897  QKDCommandTag qkdCommandTag;
898  packet->RemovePacketTag(qkdCommandTag);
899  qkdCommandTag.SetCommand ('R');
901  packet->AddPacketTag (qkdCommandTag);
903 
904 
905  // Send to all-hosts broadcast if on /32 addr, subnet-directed otherwise
906  Ipv4Address destination;
907  if (iface.GetMask () == Ipv4Mask::GetOnes ())
908  {
909  destination = Ipv4Address ("255.255.255.255");
910  }
911  else
912  {
913  destination = iface.GetBroadcast ();
914  }
915  socket->SendTo (packet, 0, InetSocketAddress (destination, DSDV_PORT));
916  NS_LOG_FUNCTION ("Sent Triggered Update from "
917  << dsdvHeader.GetDst ()
918  << " with packet id : " << packet->GetUid () << " and packet Size: " << packet->GetSize ());
919  }
920  else
921  {
922  NS_LOG_FUNCTION ("Update not sent as there are no updates to be triggered");
923  }
924  }
925 }
926 
927 uint32_t
929 
930  NS_LOG_FUNCTION(this << dst);
931 
932  for(uint32_t i=1; i<m_ipv4->GetNInterfaces(); i++){
933  //if(m_ipv4->GetAddress (i,0).GetBroadcast() == dst || m_ipv4->GetAddress (i,0).GetLocal() == dst){
934  if(
935  dst.CombineMask( m_ipv4->GetAddress (i,0).GetMask() )
936  == m_ipv4->GetAddress (i,0).GetLocal().CombineMask( m_ipv4->GetAddress (i,0).GetMask() )
937  ){
938  NS_LOG_FUNCTION( "Node: " << m_ipv4->GetObject<Node> ()->GetId ()
939  << "LocalIP from device:"
940  << m_ipv4->GetAddress (i,0).GetLocal()
941  << "\tDestination:" << dst);
942  return i;
943  }
944  }
945 
946  //if nothing is not found then return the default interface
947  return 1;
948 }
949 
950 void
952 {
953  this->PrintRoutingTable (routingStream, "SendPeriodicUpdate");
954 
955  std::map<Ipv4Address, RoutingTableEntry> removedAddresses, allRoutes;
956  m_routingTable.Purge (removedAddresses);
959  if (allRoutes.empty ())
960  {
961  return;
962  }
963  NS_LOG_FUNCTION (m_mainAddress << " is sending out its periodic update");
964  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
965  != m_socketAddresses.end (); ++j)
966  {
967  Ptr<Socket> socket = j->first;
968  Ipv4InterfaceAddress iface = j->second;
969 
970  NS_LOG_FUNCTION(this << "Sending periodic update for interface " << iface.GetLocal());
971 
972  Ptr<Packet> packet = Create<Packet> ();
973  packet = m_ipv4->GetObject<Node> ()->GetObject<QKDManager> ()->MarkEncrypt (packet);
974 
975  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
976  {
977  DsdvHeader dsdvHeader;
978  if (i->second.GetHop () == 0)
979  {
980  uint32_t localInterface = FindLocalInterfaceForDestination(i->first);
981 
982  RoutingTableEntry ownEntry;
983  //dsdvHeader.SetDst (m_ipv4->GetAddress (1,0).GetLocal ());
984  dsdvHeader.SetDst (m_ipv4->GetAddress (localInterface,0).GetLocal ());
985  dsdvHeader.SetDstSeqno (i->second.GetSeqNo () + 2);
986  dsdvHeader.SetHopCount (i->second.GetHop () + 1);
987  m_routingTable.LookupRoute (m_ipv4->GetAddress (localInterface,0).GetBroadcast (),ownEntry);
988  ownEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
989  m_routingTable.Update (ownEntry);
990  packet->AddHeader (dsdvHeader);
991  }
992  else
993  {
994  dsdvHeader.SetDst (i->second.GetDestination ());
995  dsdvHeader.SetDstSeqno ((i->second.GetSeqNo ()));
996  dsdvHeader.SetHopCount (i->second.GetHop () + 1);
997  packet->AddHeader (dsdvHeader);
998  }
999  NS_LOG_DEBUG ("Forwarding the update for " << i->first);
1000  NS_LOG_DEBUG ("Forwarding details are, Destination: " << dsdvHeader.GetDst ()
1001  << ", SeqNo:" << dsdvHeader.GetDstSeqno ()
1002  << ", HopCount:" << dsdvHeader.GetHopCount ()
1003  << ", LifeTime: " << i->second.GetLifeTime ().GetSeconds ());
1004  }
1005  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator rmItr = removedAddresses.begin (); rmItr
1006  != removedAddresses.end (); ++rmItr)
1007  {
1008  DsdvHeader removedHeader;
1009  removedHeader.SetDst (rmItr->second.GetDestination ());
1010  removedHeader.SetDstSeqno (rmItr->second.GetSeqNo () + 1);
1011  removedHeader.SetHopCount (rmItr->second.GetHop () + 1);
1012  packet->AddHeader (removedHeader);
1013  NS_LOG_DEBUG ("Update for removed record is: Destination: " << removedHeader.GetDst ()
1014  << " SeqNo:" << removedHeader.GetDstSeqno ()
1015  << " HopCount:" << removedHeader.GetHopCount ());
1016  }
1018  // ADD INTERNAL QKD COMMAND TAG
1020 
1021  QKDCommandTag qkdCommandTag;
1022  packet->RemovePacketTag(qkdCommandTag);
1023  qkdCommandTag.SetCommand ('R');
1024  qkdCommandTag.SetRoutingProtocolNumber(DSDV_PACKET_HEADER_PROTOCOL_NUMBER);
1025  packet->AddPacketTag (qkdCommandTag);
1027 
1028  socket->Send (packet);
1029  // Send to all-hosts broadcast if on /32 addr, subnet-directed otherwise
1030  Ipv4Address destination;
1031  if (iface.GetMask () == Ipv4Mask::GetOnes ())
1032  {
1033  destination = Ipv4Address ("255.255.255.255");
1034  }
1035  else
1036  {
1037  destination = iface.GetBroadcast ();
1038  }
1039  socket->SendTo (packet, 0, InetSocketAddress (destination, DSDV_PORT));
1040  NS_LOG_FUNCTION ("PeriodicUpdate Packet UID is : " << packet->GetUid () << " destination " << destination );
1041  }
1043 }
1044 
1045 void
1047 {
1048  NS_ASSERT (ipv4 != 0);
1049  NS_ASSERT (m_ipv4 == 0);
1050  m_ipv4 = ipv4;
1051  // Create lo route. It is asserted that the only one interface up for now is loopback
1052  NS_ASSERT (m_ipv4->GetNInterfaces () == 1 && m_ipv4->GetAddress (0, 0).GetLocal () == Ipv4Address ("127.0.0.1"));
1053  m_lo = m_ipv4->GetNetDevice (0);
1054  NS_ASSERT (m_lo != 0);
1055  // Remember lo route
1056  RoutingTableEntry rt (
1057  /*device=*/ m_lo, /*dst=*/
1058  Ipv4Address::GetLoopback (), /*seqno=*/
1059  0,
1060  /*iface=*/ Ipv4InterfaceAddress (Ipv4Address::GetLoopback (),Ipv4Mask ("255.0.0.0")),
1061  /*hops=*/ 0, /*next hop=*/
1063  /*lifetime=*/ Simulator::GetMaximumSimulationTime ());
1064  rt.SetFlag (INVALID);
1065  rt.SetEntriesChanged (false);
1066  m_routingTable.AddRoute (rt);
1067 
1068  std::ostringstream temp;
1069  temp << "dsdv-routing-tables_" << m_ipv4->GetObject<Node>()->GetId() << ".txt";
1070  routingStream = Create<OutputStreamWrapper>(temp.str(), std::ios::out);
1071 
1073 }
1074 
1075 void
1077 {
1078  this->PrintRoutingTable (routingStream, "NotifyInterfaceUp");
1079 
1080  NS_LOG_FUNCTION (this << m_ipv4->GetAddress (i, 0).GetLocal ()
1081  << " interface is up");
1082  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
1083  Ipv4InterfaceAddress iface = l3->GetAddress (i,0);
1084  if (iface.GetLocal () == Ipv4Address ("127.0.0.1"))
1085  {
1086  return;
1087  }
1088  // Create a socket to listen only on this interface
1089  Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (),UdpSocketFactory::GetTypeId ());
1090  NS_ASSERT (socket != 0);
1092  InetSocketAddress inetAddr (m_ipv4->GetAddress (i, 0).GetLocal (), DSDV_PORT);
1093  //socket->SetIpTos(16); //16 - band 0; 2 - band 1
1094  if (socket->Bind (inetAddr))
1095  {
1096  NS_FATAL_ERROR ("Failed to bind() DSDV socket");
1097  }
1098  socket->BindToNetDevice (m_ipv4->GetNetDevice (i));
1099  socket->SetAllowBroadcast (true);
1100  socket->SetAttribute ("IpTtl",UintegerValue (1));
1101  m_socketAddresses.insert (std::make_pair (socket,iface));
1102 
1103  // Create a socket to listen on broadcast
1104  // From ns3.27 : "Sockets do not receive anymore broadcast packets, unless they are bound to an "Any" address (0.0.0.0) or to a subnet-directed broadcast packet (e.g., x.y.z.0 for a /24 noterok)."
1105  Ptr<Socket> socket2 = Socket::CreateSocket (GetObject<Node> (),UdpSocketFactory::GetTypeId ());
1106  NS_ASSERT (socket2 != 0);
1108  InetSocketAddress inetAddr2 (m_ipv4->GetAddress (i, 0).GetBroadcast (), DSDV_PORT);
1109  //socket->SetIpTos(16); //16 - band 0; 2 - band 1
1110  if (socket2->Bind (inetAddr2))
1111  {
1112  NS_FATAL_ERROR ("Failed to bind() DSDV socket");
1113  }
1114  socket2->BindToNetDevice (m_ipv4->GetNetDevice (i));
1115  socket2->SetAttribute ("IpTtl",UintegerValue (1));
1116  socket2->SetAllowBroadcast (true);
1117  socket2->SetRecvPktInfo (true);
1118  socket2->ShutdownSend ();
1119  m_socketAddresses.insert (std::make_pair (socket2,iface));
1120 
1121  // Add local broadcast record to the routing table
1122  Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (iface.GetLocal ()));
1123  RoutingTableEntry rt (/*device=*/ dev, /*dst=*/ iface.GetBroadcast (), /*seqno=*/ 0,/*iface=*/ iface,/*hops=*/ 0,
1124  /*next hop=*/ iface.GetBroadcast (), /*lifetime=*/ Simulator::GetMaximumSimulationTime ());
1125  m_routingTable.AddRoute (rt);
1126  if (m_mainAddress == Ipv4Address ())
1127  {
1128  m_mainAddress = iface.GetLocal ();
1129  }
1131 }
1132 
1133 void
1135 {
1136  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
1137  Ptr<NetDevice> dev = l3->GetNetDevice (i);
1138  Ptr<Socket> socket = FindSocketWithInterfaceAddress (m_ipv4->GetAddress (i,0));
1139  NS_ASSERT (socket);
1140  socket->Close ();
1141  m_socketAddresses.erase (socket);
1142  if (m_socketAddresses.empty ())
1143  {
1144  NS_LOG_LOGIC ("No dsdv interfaces");
1145  m_routingTable.Clear ();
1146  return;
1147  }
1150 }
1151 
1152 void
1155 {
1156  this->PrintRoutingTable (routingStream, "NotifyAddAddress");
1157 
1158  NS_LOG_FUNCTION (this << " interface " << i << " address " << address);
1159  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
1160  if (!l3->IsUp (i))
1161  {
1162  return;
1163  }
1164  Ipv4InterfaceAddress iface = l3->GetAddress (i,0);
1166  if (!socket)
1167  {
1168  if (iface.GetLocal () == Ipv4Address ("127.0.0.1"))
1169  {
1170  return;
1171  }
1172  Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (),UdpSocketFactory::GetTypeId ());
1173  NS_ASSERT (socket != 0);
1175  InetSocketAddress inetAddr (m_ipv4->GetAddress (i, 0).GetLocal (), DSDV_PORT);
1176  //socket->SetIpTos(16); //16 - band 0; 2 - band 1
1177  if (socket->Bind (inetAddr))
1178  {
1179  NS_FATAL_ERROR ("Failed to bind() DSDV socket");
1180  }
1181  socket->BindToNetDevice (m_ipv4->GetNetDevice (i));
1182  socket->SetAttribute ("IpTtl",UintegerValue (1));
1183  socket->SetAllowBroadcast (true);
1184  socket->SetRecvPktInfo (true);
1185  m_socketAddresses.insert (std::make_pair (socket,iface));
1186 
1187  // Create a socket to listen on broadcast
1188  // From ns3.27 : "Sockets do not receive anymore broadcast packets, unless they are bound to an "Any" address (0.0.0.0) or to a subnet-directed broadcast packet (e.g., x.y.z.0 for a /24 noterok)."
1189  Ptr<Socket> socket2 = Socket::CreateSocket (GetObject<Node> (),UdpSocketFactory::GetTypeId ());
1190  NS_ASSERT (socket2 != 0);
1192  InetSocketAddress inetAddr2 (m_ipv4->GetAddress (i, 0).GetBroadcast (), DSDV_PORT);
1193  //socket->SetIpTos(16); //16 - band 0; 2 - band 1
1194  if (socket2->Bind (inetAddr2))
1195  {
1196  NS_FATAL_ERROR ("Failed to bind() DSDV socket");
1197  }
1198  socket2->BindToNetDevice (m_ipv4->GetNetDevice (i));
1199  socket2->SetAttribute ("IpTtl",UintegerValue (1));
1200  socket2->SetAllowBroadcast (true);
1201  socket2->SetRecvPktInfo (true);
1202  socket2->ShutdownSend ();
1203  m_socketAddresses.insert (std::make_pair (socket2,iface));
1204 
1205 
1206  Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (iface.GetLocal ()));
1207  RoutingTableEntry rt (/*device=*/ dev, /*dst=*/ iface.GetBroadcast (),/*seqno=*/ 0, /*iface=*/ iface,/*hops=*/ 0,
1208  /*next hop=*/ iface.GetBroadcast (), /*lifetime=*/ Simulator::GetMaximumSimulationTime ());
1209  m_routingTable.AddRoute (rt);
1210  }
1211 }
1212 
1213 void
1216 {
1217  Ptr<Socket> socket = FindSocketWithInterfaceAddress (address);
1218  if (socket)
1219  {
1220  m_socketAddresses.erase (socket);
1221  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
1222  if (l3->GetNAddresses (i))
1223  {
1224  Ipv4InterfaceAddress iface = l3->GetAddress (i,0);
1225  // Create a socket to listen only on this interface
1226  Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (),UdpSocketFactory::GetTypeId ());
1227  NS_ASSERT (socket != 0);
1229  // Bind to any IP address so that broadcasts can be received
1231  socket->SetAllowBroadcast (true);
1232  m_socketAddresses.insert (std::make_pair (socket,iface));
1233  }
1234  }
1235 }
1236 
1239 {
1240  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
1241  != m_socketAddresses.end (); ++j)
1242  {
1243  Ptr<Socket> socket = j->first;
1244  Ipv4InterfaceAddress iface = j->second;
1245  if (iface == addr)
1246  {
1247  return socket;
1248  }
1249  }
1250  Ptr<Socket> socket;
1251  return socket;
1252 }
1253 
1254 void
1256  Ptr<const Packet> packet,
1257  const Ipv4Header & header)
1258 {
1259  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
1260  NS_ASSERT (l3 != 0);
1261  Ptr<Packet> p = packet->Copy ();
1262  l3->Send (p,route->GetSource (),header.GetDestination (),header.GetProtocol (),route);
1263 }
1264 
1265 void
1267  const Ipv4Header & header,
1268  Socket::SocketErrno err)
1269 {
1270  NS_LOG_DEBUG (m_mainAddress << " drop packet " << packet->GetUid () << " to "
1271  << header.GetDestination () << " from queue. Error " << err);
1272 }
1273 
1274 void
1276 {
1277  NS_LOG_FUNCTION (this);
1278  Ptr<Ipv4Route> route;
1279  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
1280  m_routingTable.GetListOfAllRoutes (allRoutes);
1281  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
1282  {
1283  RoutingTableEntry rt;
1284  rt = i->second;
1285  if (m_queue.Find (rt.GetDestination ()))
1286  {
1287  if (rt.GetHop () == 1)
1288  {
1289  route = rt.GetRoute ();
1290  NS_LOG_LOGIC ("A route exists from " << route->GetSource ()
1291  << " to neighboring destination "
1292  << route->GetDestination ());
1293  NS_ASSERT (route != 0);
1294  }
1295  else
1296  {
1297  RoutingTableEntry newrt;
1298  m_routingTable.LookupRoute (rt.GetNextHop (),newrt);
1299  route = newrt.GetRoute ();
1300  NS_LOG_LOGIC ("A route exists from " << route->GetSource ()
1301  << " to destination " << route->GetDestination () << " via "
1302  << rt.GetNextHop ());
1303  NS_ASSERT (route != 0);
1304  }
1305  SendPacketFromQueue (rt.GetDestination (),route);
1306  }
1307  }
1308 }
1309 
1310 void
1312  Ptr<Ipv4Route> route)
1313 {
1314  NS_LOG_DEBUG (m_mainAddress << " is sending a queued packet to destination " << dst);
1315  QueueEntry queueEntry;
1316  if (m_queue.Dequeue (dst,queueEntry))
1317  {
1319  Ptr<Packet> p = ConstCast<Packet> (queueEntry.GetPacket ());
1320  if (p->RemovePacketTag (tag))
1321  {
1322  if (tag.oif != -1 && tag.oif != m_ipv4->GetInterfaceForDevice (route->GetOutputDevice ()))
1323  {
1324  NS_LOG_DEBUG ("Output device doesn't match. Dropped.");
1325  return;
1326  }
1327  }
1329  Ipv4Header header = queueEntry.GetIpv4Header ();
1330  header.SetSource (route->GetSource ());
1331  header.SetTtl (header.GetTtl () + 1); // compensate extra TTL decrement by fake loopback routing
1332  ucb (route,p,header);
1333  if (m_queue.GetSize () != 0 && m_queue.Find (dst))
1334  {
1336  &RoutingProtocol::SendPacketFromQueue,this,dst,route);
1337  }
1338  }
1339 }
1340 
1341 Time
1343 {
1344  NS_LOG_FUNCTION ("Calculating the settling time for " << address);
1345  RoutingTableEntry mainrt;
1346  Time weightedTime;
1347  m_routingTable.LookupRoute (address,mainrt);
1348  if (EnableWST)
1349  {
1350  if (mainrt.GetSettlingTime () == Seconds (0))
1351  {
1352  return Seconds (0);
1353  }
1354  else
1355  {
1356  NS_LOG_DEBUG ("Route SettlingTime: " << mainrt.GetSettlingTime ().GetSeconds ()
1357  << " and LifeTime:" << mainrt.GetLifeTime ().GetSeconds ());
1358  weightedTime = Time (m_weightedFactor * mainrt.GetSettlingTime ().GetSeconds () + (1.0 - m_weightedFactor)
1359  * mainrt.GetLifeTime ().GetSeconds ());
1360  NS_LOG_DEBUG ("Calculated weightedTime:" << weightedTime.GetSeconds ());
1361  return weightedTime;
1362  }
1363  }
1364  return mainrt.GetSettlingTime ();
1365 }
1366 
1367 void
1369 {
1370  NS_LOG_FUNCTION ("Merging advertised table changes with main table before sending out periodic update");
1371  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
1373  if (allRoutes.size () > 0)
1374  {
1375  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
1376  {
1377  RoutingTableEntry advEntry = i->second;
1378  if ((advEntry.GetEntriesChanged () == true) && (!m_advRoutingTable.AnyRunningEvent (advEntry.GetDestination ())))
1379  {
1380  if (!(advEntry.GetSeqNo () % 2))
1381  {
1382  advEntry.SetFlag (VALID);
1383  advEntry.SetEntriesChanged (false);
1384  m_routingTable.Update (advEntry);
1385  NS_LOG_DEBUG ("Merged update for " << advEntry.GetDestination () << " with main routing Table");
1386  }
1388  }
1389  else
1390  {
1391  NS_LOG_DEBUG ("Event currently running. Cannot Merge Routing Tables");
1392  }
1393  }
1394  }
1395 }
1396 }
1397 }
void SetSource(Ipv4Address source)
Definition: ipv4-header.cc:285
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
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...
bool GetWSTFlag() const
Get weighted settling time (WST) flag.
Routing table entry.
Definition: dsdv-rtable.h:56
an Inet address class
Ipv4Address GetIpv4(void) const
static Ipv4Address GetAny(void)
void SetEntriesChanged(bool entriesChanged)
Set entries changed indicator.
Definition: dsdv-rtable.h:253
#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)
AttributeValue implementation for Boolean.
Definition: boolean.h:36
Ipv4Mask GetMask(void) const
Get the network mask.
Callback template class.
Definition: callback.h:1176
Ipv4Address GetNextHop() const
Get next hop.
Definition: dsdv-rtable.h:118
bool EnableRouteAggregation
This is a flag to enable route aggregation.
void MergeTriggerPeriodicUpdates()
Merge periodic updates.
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:45
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)
Set destination address.
Definition: dsdv-packet.h:88
Ipv4Header GetIpv4Header() const
Get IP header.
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:258
uint32_t GetHopCount() const
Get hop count.
Definition: dsdv-packet.h:115
virtual int ShutdownSend(void)=0
void SetRoutingProtocolNumber(uint32_t value)
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:84
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
void SetCommand(char value)
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:852
static TypeId GetTypeId()
Get the type ID.
uint64_t GetUid(void) const
Returns the packet&#39;s Uid.
Definition: packet.cc:390
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:1270
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)
Set route flags.
Definition: dsdv-rtable.h:235
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void SetDstSeqno(uint32_t sequenceNumber)
Set destination sequence number.
Definition: dsdv-packet.h:124
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1015
uint32_t GetSeqNo() const
Get sequence number.
Definition: dsdv-rtable.h:172
void SetMaxPacketsPerDst(uint32_t len)
Set maximum packets per destination.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:831
virtual void DoDispose()
Destructor implementation.
bool IsMulticast(void) const
virtual void NotifyInterfaceDown(uint32_t interface)
Ipv4Address CombineMask(Ipv4Mask const &mask) const
Combine this address with a network mask.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
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:733
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
TAG_BUFFER_INLINE uint32_t ReadU32(void)
Definition: tag-buffer.h:215
uint32_t GetDstSeqno() const
Get destination sequence number.
Definition: dsdv-packet.h:133
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
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
Get route.
Definition: dsdv-rtable.h:91
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
bool GetEnableRAFlag() const
Get enable route aggregation (RA) flag.
void SetSource(Ipv4Address src)
Definition: ipv4-route.cc:49
Ipv4Address GetDst() const
Get destination address.
Definition: dsdv-packet.h:97
uint32_t FindLocalInterfaceForDestination(Ipv4Address dst)
Ptr< NetDevice > GetOutputDevice(void) const
Definition: ipv4-route.cc:84
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
Definition: socket.cc:358
Packet header for IPv4.
Definition: ipv4-header.h:33
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
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:874
NS_ASSERT_MSG(false,"Ipv4AddressGenerator::MaskToIndex(): Impossible")
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:1381
AttributeValue implementation for Time.
Definition: nstime.h:1069
Introspection did not find any typical Config paths.
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
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)
Set sequence number.
Definition: dsdv-rtable.h:163
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:108
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:1489
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)
Route input packet.
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)
static TypeId GetTypeId(void)
Get the type ID.
Time GetSettlingTime() const
Get settling time.
Definition: dsdv-rtable.h:226
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
UnicastForwardCallback m_scb
Unicast callback for own packets.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
double f(double x, void *params)
Definition: 80211b.c:70
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 until 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.
address
Definition: first.py:37
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
Get unicast forward callback function.
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&#39;t yet exist in routing table.
Definition: dsdv-rtable.cc:128
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
void RecvDsdv(Ptr< Socket > socket)
Receive and process dsdv control packet.
void SetQueueTimeout(Time t)
Set queue timeout.
bool GetEnableBufferFlag() const
Get enable buffer flag.
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
Definition: simulator.h:1570
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:1070
Ptr< OutputStreamWrapper > routingStream
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
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.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
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)
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
Get hop.
Definition: dsdv-rtable.h:190
void Send(Ptr< Ipv4Route >, Ptr< const Packet >, const Ipv4Header &)
Send packet.
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
uint32_t GetId(void) const
Definition: node.cc:107
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
void SetEnableRAFlag(bool f)
Set enable route aggregation (RA) flag.
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:859
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:270
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1007
bool GetEntriesChanged() const
Get entries changed.
Definition: dsdv-rtable.h:262
void SetTtl(uint8_t ttl)
Definition: ipv4-header.cc:259
Ptr< const Packet > GetPacket() const
Get packet.
void SetHopCount(uint32_t hopCount)
Set hop count.
Definition: dsdv-packet.h:106
Tag used by DSDV implementation.
DSDV Update Packet Format.
Definition: dsdv-packet.h:60
void SetEnableBufferFlag(bool f)
Set enable buffer flag.
Abstract base class for IPv4 routing protocols.
Ipv4Address GetDestination() const
Get destination IP address.
Definition: dsdv-rtable.h:82
void Clear()
Delete all entries from routing table.
Definition: dsdv-rtable.h:383
DeferredRouteOutputTag(int32_t o=-1)
Constructor.
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)
Set hold down time (time until an invalid route may be deleted)
Definition: dsdv-rtable.h:457
RoutingTable m_advRoutingTable
Advertised Routing table for the node.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1023
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:365
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
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
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()
Get the number of entries.
void SetWSTFlag(bool f)
Set weighted settling time (WST) flag.
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 &#39;double&#39; or &#39;float&#39;...
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:185
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:915
Time GetLifeTime() const
Get lifetime.
Definition: dsdv-rtable.h:208
static Time GetMaximumSimulationTime(void)
Get the maximum representable simulation time.
Definition: simulator.cc:371
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
virtual Address GetAddress(void) const =0
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
void SetDestination(Ipv4Address dest)
Definition: ipv4-route.cc:35
#define DSDV_PACKET_HEADER_PROTOCOL_NUMBER
Definition: dsdv-packet.h:40
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...