A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
dsr-rcache.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 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: Yufei Cheng <yfcheng@ittc.ku.edu>
19  * Song Luan <lsuper@mail.ustc.edu.cn> (Implemented Link Cache using Dijsktra algorithm)
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 "dsr-rcache.h"
34 #include <map>
35 #include <cmath>
36 #include <algorithm>
37 #include <iostream>
38 #include <list>
39 #include <vector>
40 #include <functional>
41 #include <iomanip>
42 
43 #include "ns3/simulator.h"
44 #include "ns3/ipv4-route.h"
45 #include "ns3/socket.h"
46 #include "ns3/log.h"
47 #include "ns3/address-utils.h"
48 #include "ns3/packet.h"
49 
50 NS_LOG_COMPONENT_DEFINE ("RouteCache");
51 
52 namespace ns3 {
53 namespace dsr {
54 
56 {
57  // compare based on both with hop count considered priority
58  return (a.GetVector ().size () < b.GetVector ().size ())
59  || ((a.GetVector ().size () == b.GetVector ().size ()) && (a.GetExpireTime () > b.GetExpireTime ()))
60  ;
61 }
62 
64 {
65  // compare based on hops
66  return a.GetVector ().size () < b.GetVector ().size ();
67 }
68 
70 {
71  // compare based on expire time
72  return a.GetExpireTime () > b.GetExpireTime ();
73 }
74 
75 void Link::Print () const
76 {
77  NS_LOG_DEBUG (m_low << "----" << m_high);
78 }
79 
81  : m_nodeStability (nodeStab + Simulator::Now ())
82 {
83 }
84 
86 {
87 }
88 
90  : m_linkStability (linkStab + Simulator::Now ())
91 {
92 }
93 
95 {
96 }
97 
98 void LinkStab::Print ( ) const
99 {
100  NS_LOG_LOGIC ("LifeTime: " << GetLinkStability ().GetSeconds ());
101 }
102 
103 typedef std::list<RouteCacheEntry>::value_type route_pair;
104 
106  : m_ackTimer (Timer::CANCEL_ON_DESTROY),
107  m_dst (dst),
108  m_path (ip),
109  m_expire (exp + Simulator::Now ()),
110  m_reqCount (0),
111  m_blackListState (false),
112  m_blackListTimeout (Simulator::Now ())
113 {
114 }
115 
117 {
118 }
119 
120 void
122 {
123  m_reqCount = 0;
124  m_expire = badLinkLifetime + Simulator::Now ();
125 }
126 
127 void
128 RouteCacheEntry::Print (std::ostream & os) const
129 {
130  os << m_dst << "\t" << (m_expire - Simulator::Now ()).GetSeconds ()
131  << "\t";
132 }
133 
135  ;
136 
138 {
139  static TypeId tid = TypeId ("ns3::dsr::RouteCache")
140  .SetParent<Object> ()
141  .AddConstructor<RouteCache> ()
142  ;
143  return tid;
144 }
145 
147  : m_vector (0),
148  m_maxEntriesEachDst (3),
149  m_isLinkCache (false),
150  m_ntimer (Timer::CANCEL_ON_DESTROY),
151  m_delay (MilliSeconds (100))
152 {
153  /*
154  * The timer to set layer 2 notification, not fully supported by ns3 yet
155  */
159 }
160 
162 {
164  // clear the route cache when done
165  m_sortedRoutes.clear ();
166 }
167 
168 void
169 RouteCache::RemoveLastEntry (std::list<RouteCacheEntry> & rtVector)
170 {
171  NS_LOG_FUNCTION (this);
172  // Release the last entry of route list
173  rtVector.pop_back ();
174 }
175 
176 bool
178 {
179  NS_LOG_FUNCTION (this << dst);
180  std::map<Ipv4Address, std::list<RouteCacheEntry> >::const_iterator i =
181  m_sortedRoutes.find (dst);
182  if (i == m_sortedRoutes.end ())
183  {
184  NS_LOG_LOGIC ("Failed to find the route entry for the destination " << dst);
185  return false;
186  }
187  else
188  {
189  std::list<RouteCacheEntry> rtVector = i->second;
190  RouteCacheEntry successEntry = rtVector.front ();
191  successEntry.SetExpireTime (RouteCacheTimeout);
192  rtVector.pop_front ();
193  rtVector.push_back (successEntry);
194  rtVector.sort (CompareRoutesExpire); // sort the route vector first
195  m_sortedRoutes.erase (dst); // erase the entry first
196  /*
197  * Save the new route cache along with the destination address in map
198  */
199  std::pair<std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator, bool> result =
200  m_sortedRoutes.insert (std::make_pair (dst, rtVector));
201  return result.second;
202  }
203  return false;
204 }
205 
206 bool
208 {
209  NS_LOG_FUNCTION (this << id);
210  if (IsLinkCache ())
211  {
212  return LookupRoute_Link (id, rt);
213  }
214  else
215  {
216  Purge (); // Purge first to remove expired entries
217  if (m_sortedRoutes.empty ())
218  {
219  NS_LOG_LOGIC ("Route to " << id << " not found; m_sortedRoutes is empty");
220  return false;
221  }
222  std::map<Ipv4Address, std::list<RouteCacheEntry> >::const_iterator i = m_sortedRoutes.find (id);
223  if (i == m_sortedRoutes.end ())
224  {
225  NS_LOG_LOGIC ("No Direct Route to " << id << " found");
226  for (std::map<Ipv4Address, std::list<RouteCacheEntry> >::const_iterator j =
227  m_sortedRoutes.begin (); j != m_sortedRoutes.end (); ++j)
228  {
229  std::list<RouteCacheEntry> rtVector = j->second; // The route cache vector linked with destination address
230  /*
231  * Loop through the possibly multiple routes within the route vector
232  */
233  for (std::list<RouteCacheEntry>::const_iterator k = rtVector.begin (); k != rtVector.end (); ++k)
234  {
235  // return the first route in the route vector
236  RouteCacheEntry::IP_VECTOR routeVector = k->GetVector ();
237  RouteCacheEntry::IP_VECTOR changeVector;
238 
239  for (RouteCacheEntry::IP_VECTOR::iterator l = routeVector.begin (); l != routeVector.end (); ++l)
240  {
241  if (*l != id)
242  {
243  changeVector.push_back (*l);
244  }
245  else
246  {
247  changeVector.push_back (*l);
248  break;
249  }
250  }
251  /*
252  * When the changed vector is smaller in size and larger than 1, which means we have found a route with the destination
253  * address we are looking for
254  */
255  if ((changeVector.size () < routeVector.size ()) && (changeVector.size () > 1))
256  {
257  RouteCacheEntry changeEntry; // Create the route entry
258  changeEntry.SetVector (changeVector);
259  changeEntry.SetDestination (id);
260  // Use the expire time from original route entry
261  changeEntry.SetExpireTime (k->GetExpireTime ());
262  // We need to add new route entry here
263  std::list<RouteCacheEntry> newVector;
264  newVector.push_back (changeEntry);
265  newVector.sort (CompareRoutesExpire); // sort the route vector first
266  m_sortedRoutes[id] = newVector; // Only get the first sub route and add it in route cache
267  NS_LOG_INFO ("We have a sub-route to " << id << " add it in route cache");
268  }
269  }
270  }
271  }
272  NS_LOG_INFO ("Here we check the route cache again after updated the sub routes");
273  std::map<Ipv4Address, std::list<RouteCacheEntry> >::const_iterator m = m_sortedRoutes.find (id);
274  if (m == m_sortedRoutes.end ())
275  {
276  NS_LOG_LOGIC ("No updated route till last time");
277  return false;
278  }
279  /*
280  * We have a direct route to the destination address
281  */
282  std::list<RouteCacheEntry> rtVector = m->second;
283  rt = rtVector.front (); // use the first entry in the route vector
284  NS_LOG_LOGIC ("Route to " << id << " with route size " << rtVector.size ());
285  return true;
286  }
287 }
288 
289 void
290 RouteCache::SetCacheType (std::string type)
291 {
292  NS_LOG_FUNCTION (this << type);
293  if (type == std::string ("LinkCache"))
294  {
295  m_isLinkCache = true;
296  }
297  else if (type == std::string ("PathCache"))
298  {
299  m_isLinkCache = false;
300  }
301  else
302  {
303  m_isLinkCache = true; // use link cache as default
304  NS_LOG_INFO ("Error Cache Type");
305  }
306 }
307 
308 bool
310 {
311  NS_LOG_FUNCTION (this);
312  return m_isLinkCache;
313 }
314 
315 void
317 {
318  NS_LOG_FUNCTION (this << source);
322  // @d shortest-path estimate
323  std::map<Ipv4Address, uint32_t> d;
324  // @pre preceeding node
325  std::map<Ipv4Address, Ipv4Address> pre;
326  for (std::map<Ipv4Address, std::map<Ipv4Address, uint32_t> >::iterator i = m_netGraph.begin (); i != m_netGraph.end (); ++i)
327  {
328  if (i->second.find (source) != i->second.end ())
329  {
330  d[i->first] = i->second[source];
331  pre[i->first] = source;
332  }
333  else
334  {
335  d[i->first] = MAXWEIGHT;
336  pre[i->first] = Ipv4Address ("255.255.255.255");
337  }
338  }
339  d[source] = 0;
343  // the node set which shortest distance has been calculated, if true calculated
344  std::map<Ipv4Address, bool> s;
345  double temp = MAXWEIGHT;
346  Ipv4Address tempip = Ipv4Address ("255.255.255.255");
347  for (uint32_t i = 0; i < m_netGraph.size (); i++)
348  {
349  temp = MAXWEIGHT;
350  for (std::map<Ipv4Address,uint32_t>::const_iterator j = d.begin (); j != d.end (); ++j)
351  {
352  Ipv4Address ip = j->first;
353  if (s.find (ip) == s.end ())
354  {
355  /*
356  * \brief The followings are for comparison
357  */
358  if (j->second <= temp)
359  {
360  temp = j->second;
361  tempip = ip;
362  }
363  }
364  }
365  if (!tempip.IsBroadcast ())
366  {
367  s[tempip] = true;
368  for (std::map<Ipv4Address, uint32_t>::const_iterator k = m_netGraph[tempip].begin (); k != m_netGraph[tempip].end (); ++k)
369  {
370  if (s.find (k->first) == s.end () && d[k->first] > d[tempip] + k->second)
371  {
372  d[k->first] = d[tempip] + k->second;
373  pre[k->first] = tempip;
374  }
375  /*
376  * Selects the shortest-length route that has the longest expected lifetime
377  * (highest minimum timeout of any link in the route)
378  * For the computation overhead and complexity
379  * Here I just implement kind of greedy strategy to select link with the longest expected lifetime when there is two options
380  */
381  else if (d[k->first] == d[tempip] + k->second)
382  {
383  std::map<Link, LinkStab>::iterator oldlink = m_linkCache.find (Link (k->first, pre[k->first]));
384  std::map<Link, LinkStab>::iterator newlink = m_linkCache.find (Link (k->first, tempip));
385  if (oldlink != m_linkCache.end () && newlink != m_linkCache.end ())
386  {
387  if (oldlink->second.GetLinkStability () < newlink->second.GetLinkStability ())
388  {
389  NS_LOG_INFO ("Select the link with longest expected lifetime");
390  d[k->first] = d[tempip] + k->second;
391  pre[k->first] = tempip;
392  }
393  }
394  else
395  {
396  NS_LOG_INFO ("Link Stability Info Corrupt");
397  }
398  }
399  }
400  }
401  }
402  // clean the best route table
403  m_bestRoutesTable_link.clear ();
404  for (std::map<Ipv4Address, Ipv4Address>::iterator i = pre.begin (); i != pre.end (); ++i)
405  {
406  // loop for all vertexes
408  Ipv4Address iptemp = i->first;
409 
410  if (!i->second.IsBroadcast () && iptemp != source)
411  {
412  while (iptemp != source)
413  {
414  route.push_back (iptemp);
415  iptemp = pre[iptemp];
416  }
417  route.push_back (source);
418  // Reverse the route
419  RouteCacheEntry::IP_VECTOR reverseroute;
420  for (RouteCacheEntry::IP_VECTOR::reverse_iterator j = route.rbegin (); j != route.rend (); ++j)
421  {
422  reverseroute.push_back (*j);
423  }
424  NS_LOG_LOGIC ("Add newly calculated best routes");
425  PrintVector (reverseroute);
426  m_bestRoutesTable_link[i->first] = reverseroute;
427  }
428  }
429 }
430 
431 bool
433 {
434  NS_LOG_FUNCTION (this << id);
436  PurgeLinkNode ();
437  std::map<Ipv4Address, RouteCacheEntry::IP_VECTOR>::const_iterator i = m_bestRoutesTable_link.find (id);
438  if (i == m_bestRoutesTable_link.end ())
439  {
440  NS_LOG_INFO ("No route find to " << id);
441  return false;
442  }
443  else
444  {
445  if (i->second.size () < 2)
446  {
447  NS_LOG_LOGIC ("Route to " << id << " error");
448  return false;
449  }
450 
451  RouteCacheEntry newEntry; // Create the route entry
452  newEntry.SetVector (i->second);
453  newEntry.SetDestination (id);
454  newEntry.SetExpireTime (RouteCacheTimeout);
455  NS_LOG_INFO ("Route to " << id << " found with the length " << i->second.size ());
456  rt = newEntry;
457  std::vector<Ipv4Address> path = rt.GetVector ();
458  PrintVector (path);
459  return true;
460  }
461 }
462 
463 void
465 {
466  NS_LOG_FUNCTION (this);
467  for (std::map<Link, LinkStab>::iterator i = m_linkCache.begin (); i != m_linkCache.end (); )
468  {
469  NS_LOG_DEBUG ("The link stability " << i->second.GetLinkStability ().GetSeconds ());
470  std::map<Link, LinkStab>::iterator itmp = i;
471  if (i->second.GetLinkStability () <= Seconds (0))
472  {
473  ++i;
474  m_linkCache.erase (itmp);
475  }
476  else
477  {
478  ++i;
479  }
480  }
482  for (std::map<Ipv4Address, NodeStab>::iterator i = m_nodeCache.begin (); i != m_nodeCache.end (); )
483  {
484  NS_LOG_DEBUG ("The node stability " << i->second.GetNodeStability ().GetSeconds ());
485  std::map<Ipv4Address, NodeStab>::iterator itmp = i;
486  if (i->second.GetNodeStability () <= Seconds (0))
487  {
488  ++i;
489  m_nodeCache.erase (itmp);
490  }
491  else
492  {
493  ++i;
494  }
495  }
496 }
497 
498 void
500 {
501  NS_LOG_FUNCTION (this);
502  m_netGraph.clear ();
503  for (std::map<Link, LinkStab>::iterator i = m_linkCache.begin (); i != m_linkCache.end (); ++i)
504  {
505  // Here the weight is set as 1
507  uint32_t weight = 1;
508  m_netGraph[i->first.m_low][i->first.m_high] = weight;
509  m_netGraph[i->first.m_high][i->first.m_low] = weight;
510  }
511 }
512 
513 bool
515 {
516  NS_LOG_FUNCTION (this << node);
517  std::map<Ipv4Address, NodeStab>::const_iterator i = m_nodeCache.find (node);
518  if (i == m_nodeCache.end ())
519  {
520  NS_LOG_INFO ("The initial stability " << m_initStability.GetSeconds ());
522  m_nodeCache[node] = ns;
523  return false;
524  }
525  else
526  {
528  NS_LOG_INFO ("The node stability " << i->second.GetNodeStability ().GetSeconds ());
529  NS_LOG_INFO ("The stability here " << Time (i->second.GetNodeStability () * m_stabilityIncrFactor).GetSeconds ());
530  NodeStab ns (Time (i->second.GetNodeStability () * m_stabilityIncrFactor));
531  m_nodeCache[node] = ns;
532  return true;
533  }
534  return false;
535 }
536 
537 bool
539 {
540  NS_LOG_FUNCTION (this << node);
541  std::map<Ipv4Address, NodeStab>::const_iterator i = m_nodeCache.find (node);
542  if (i == m_nodeCache.end ())
543  {
545  m_nodeCache[node] = ns;
546  return false;
547  }
548  else
549  {
551  NS_LOG_INFO ("The stability here " << i->second.GetNodeStability ().GetSeconds ());
552  NS_LOG_INFO ("The stability here " << Time (i->second.GetNodeStability () / m_stabilityDecrFactor).GetSeconds ());
553  NodeStab ns (Time (i->second.GetNodeStability () / m_stabilityDecrFactor));
554  m_nodeCache[node] = ns;
555  return true;
556  }
557  return false;
558 }
559 
560 bool
562 {
563  NS_LOG_FUNCTION (this << source);
564  NS_LOG_LOGIC ("Use Link Cache");
566  PurgeLinkNode ();
567  for (uint32_t i = 0; i < nodelist.size () - 1; i++)
568  {
569  NodeStab ns;
571 
572  if (m_nodeCache.find (nodelist[i]) == m_nodeCache.end ())
573  {
574  m_nodeCache[nodelist[i]] = ns;
575  }
576  if (m_nodeCache.find (nodelist[i + 1]) == m_nodeCache.end ())
577  {
578  m_nodeCache[nodelist[i + 1]] = ns;
579  }
580  Link link (nodelist[i], nodelist[i + 1]);
581  LinkStab stab;
584  if (m_nodeCache[nodelist[i]].GetNodeStability () < m_nodeCache[nodelist[i + 1]].GetNodeStability ())
585  {
586  stab.SetLinkStability (m_nodeCache[nodelist[i]].GetNodeStability ());
587  }
588  else
589  {
590  stab.SetLinkStability (m_nodeCache[nodelist[i + 1]].GetNodeStability ());
591  }
592  if (stab.GetLinkStability () < m_minLifeTime)
593  {
594  NS_LOG_LOGIC ("Stability: " << stab.GetLinkStability ().GetSeconds ());
597  }
598  m_linkCache[link] = stab;
599  NS_LOG_DEBUG ("Add a new link");
600  link.Print ();
601  NS_LOG_DEBUG ("Link Info");
602  stab.Print ();
603  }
604  UpdateNetGraph ();
605  RebuildBestRouteTable (source);
606  return true;
607 }
608 
609 void
611 {
612  NS_LOG_FUNCTION (this);
614  PurgeLinkNode ();
615  if (rt.size () < 2)
616  {
617  NS_LOG_INFO ("The route is too short");
618  return;
619  }
620  for (RouteCacheEntry::IP_VECTOR::iterator i = rt.begin (); i != rt.end () - 1; ++i)
621  {
622  Link link (*i, *(i + 1));
623  if (m_linkCache.find (link) != m_linkCache.end ())
624  {
625  if (m_linkCache[link].GetLinkStability () < m_useExtends)
626  {
627  m_linkCache[link].SetLinkStability (m_useExtends);
629  NS_LOG_INFO ("The time of the link " << m_linkCache[link].GetLinkStability ().GetSeconds ());
630  }
631  }
632  else
633  {
634  NS_LOG_INFO ("We cannot find a link in cache");
635  }
636  }
638  for (RouteCacheEntry::IP_VECTOR::iterator i = rt.begin (); i != rt.end (); ++i)
639  {
640  if (m_nodeCache.find (*i) != m_nodeCache.end ())
641  {
642  NS_LOG_LOGIC ("Increase the stability");
643  if (m_nodeCache[*i].GetNodeStability () <= m_initStability)
644  {
645  IncStability (*i);
646  }
647  else
648  {
649  NS_LOG_INFO ("The node stability has already been increased");
650  }
651  }
652  }
653 }
654 
655 bool
657 {
658  NS_LOG_FUNCTION (this);
659  Purge ();
660  std::list<RouteCacheEntry> rtVector; // Declare the route cache entry vector
661  Ipv4Address dst = rt.GetDestination ();
662  std::vector<Ipv4Address> route = rt.GetVector ();
663 
664  NS_LOG_DEBUG ("The route destination we have " << dst);
665  std::map<Ipv4Address, std::list<RouteCacheEntry> >::const_iterator i =
666  m_sortedRoutes.find (dst);
667 
668  if (i == m_sortedRoutes.end ())
669  {
670  rtVector.push_back (rt);
671  m_sortedRoutes.erase (dst); // Erase the route entries for dst first
675  std::pair<std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator, bool> result =
676  m_sortedRoutes.insert (std::make_pair (dst, rtVector));
677  return result.second;
678  }
679  else
680  {
681  rtVector = i->second;
682  NS_LOG_DEBUG ("The existing route size " << rtVector.size () << " for destination address " << dst);
686  if (rtVector.size () >= m_maxEntriesEachDst)
687  {
688  RemoveLastEntry (rtVector); // Drop the last entry for the sorted route cache, the route has already been sorted
689  }
690 
691  if (FindSameRoute (rt, rtVector))
692  {
693  NS_LOG_DEBUG ("Find same vector, the FindSameRoute function will update the route expire time");
694  return true;
695  }
696  else
697  {
698  // Check if the expire time for the new route has expired or not
699  if (rt.GetExpireTime () > 0)
700  {
701  rtVector.push_back (rt);
702  // This sort function will sort the route cache entries based on the size of route in each of the
703  // route entries
704  rtVector.sort (CompareRoutesExpire);
705  NS_LOG_DEBUG ("The first time" << rtVector.front ().GetExpireTime ().GetSeconds () << " The second time "
706  << rtVector.back ().GetExpireTime ().GetSeconds ());
707  NS_LOG_DEBUG ("The first hop" << rtVector.front ().GetVector ().size () << " The second hop "
708  << rtVector.back ().GetVector ().size ());
709  m_sortedRoutes.erase (dst); // erase the route entries for dst first
713  std::pair<std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator, bool> result =
714  m_sortedRoutes.insert (std::make_pair (dst, rtVector));
715  return result.second;
716  }
717  else
718  {
719  NS_LOG_INFO ("The newly found route is already expired");
720  }
721  }
722  }
723  return false;
724 }
725 
726 bool RouteCache::FindSameRoute (RouteCacheEntry & rt, std::list<RouteCacheEntry> & rtVector)
727 {
728  NS_LOG_FUNCTION (this);
729  for (std::list<RouteCacheEntry>::iterator i = rtVector.begin (); i != rtVector.end (); ++i)
730  {
731  // return the first route in the route vector
732  RouteCacheEntry::IP_VECTOR routeVector = i->GetVector ();
733  RouteCacheEntry::IP_VECTOR newVector = rt.GetVector ();
734 
735  if (routeVector == newVector)
736  {
737  NS_LOG_DEBUG ("Found same routes in the route cache with the vector size "
738  << rt.GetDestination () << " " << rtVector.size ());
739  NS_LOG_DEBUG ("The new route expire time " << rt.GetExpireTime ().GetSeconds ()
740  << " the original expire time " << i->GetExpireTime ().GetSeconds ());
741  if (rt.GetExpireTime () > i->GetExpireTime ())
742  {
743  i->SetExpireTime (rt.GetExpireTime ());
744  }
745  m_sortedRoutes.erase (rt.GetDestination ()); // erase the entry first
746  rtVector.sort (CompareRoutesExpire); // sort the route vector first
747  /*
748  * Save the new route cache along with the destination address in map
749  */
750  std::pair<std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator, bool> result =
751  m_sortedRoutes.insert (std::make_pair (rt.GetDestination (), rtVector));
752  return result.second;
753  }
754  }
755  return false;
756 }
757 
758 bool
760 {
761  NS_LOG_FUNCTION (this << dst);
762  Purge (); // purge the route cache first to remove timeout entries
763  if (m_sortedRoutes.erase (dst) != 0)
764  {
765  NS_LOG_LOGIC ("Route deletion to " << dst << " successful");
766  return true;
767  }
768  NS_LOG_LOGIC ("Route deletion to " << dst << " not successful");
769  return false;
770 }
771 
772 void
774 {
775  NS_LOG_FUNCTION (this << errorSrc << unreachNode << node);
776  if (IsLinkCache ())
777  {
778  // Purge the link node cache first
779  PurgeLinkNode ();
780  /*
781  * The followings are for cleaning the broken link in link cache
782  * We basically remove the link between errorSrc and unreachNode
783  */
784  Link link1 (errorSrc, unreachNode);
785  Link link2 (unreachNode, errorSrc);
786  // erase the two kind of links to make sure the link is removed from the link cache
787  NS_LOG_DEBUG ("Erase the route");
788  m_linkCache.erase (link1);
790  NS_LOG_DEBUG ("The link cache size " << m_linkCache.size());
791  m_linkCache.erase (link2);
792  NS_LOG_DEBUG ("The link cache size " << m_linkCache.size());
793 
794  std::map<Ipv4Address, NodeStab>::iterator i = m_nodeCache.find (errorSrc);
795  if (i == m_nodeCache.end ())
796  {
797  NS_LOG_LOGIC ("Update the node stability unsuccessfully");
798  }
799  else
800  {
801  DecStability (i->first);
802  }
803  i = m_nodeCache.find (unreachNode);
804  if (i == m_nodeCache.end ())
805  {
806  NS_LOG_LOGIC ("Update the node stability unsuccessfully");
807  }
808  else
809  {
810  DecStability (i->first);
811  }
812  UpdateNetGraph ();
813  RebuildBestRouteTable (node);
814  }
815  else
816  {
817  /*
818  * the followings are for cleaning the broken link in pathcache
819  *
820  */
821  Purge ();
822  if (m_sortedRoutes.empty ())
823  {
824  return;
825  }
826  /*
827  * Loop all the routes saved in the route cache
828  */
829  for (std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator j =
830  m_sortedRoutes.begin (); j != m_sortedRoutes.end (); )
831  {
832  std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator jtmp = j;
833  Ipv4Address address = j->first;
834  std::list<RouteCacheEntry> rtVector = j->second;
835  /*
836  * Loop all the routes for a single destination
837  */
838  for (std::list<RouteCacheEntry>::iterator k = rtVector.begin (); k != rtVector.end (); )
839  {
840  // return the first route in the route vector
841  RouteCacheEntry::IP_VECTOR routeVector = k->GetVector ();
842  RouteCacheEntry::IP_VECTOR changeVector;
843  /*
844  * Loop the ip addresses within a single route entry
845  */
846  for (RouteCacheEntry::IP_VECTOR::iterator i = routeVector.begin (); i != routeVector.end (); ++i)
847  {
848  if (*i != errorSrc)
849  {
850  changeVector.push_back (*i);
851  }
852  else
853  {
854  if (*(i + 1) == unreachNode)
855  {
856  changeVector.push_back (*i);
857  break;
858  }
859  else
860  {
861  changeVector.push_back (*i);
862  }
863  }
864  }
865  /*
866  * Verify if need to remove some affected links
867  */
868  if (changeVector.size () == routeVector.size ())
869  {
870  NS_LOG_DEBUG ("The route does not contain the broken link");
871  ++k;
872  }
873  else if ((changeVector.size () < routeVector.size ()) && (changeVector.size () > 1))
874  {
875  NS_LOG_DEBUG ("sub route " << m_subRoute);
876  if (m_subRoute)
877  {
878  Time expire = k->GetExpireTime ();
879  /*
880  * Remove the route first
881  */
882  k = rtVector.erase (k);
883  RouteCacheEntry changeEntry;
884  changeEntry.SetVector (changeVector);
885  Ipv4Address destination = changeVector.back ();
886  NS_LOG_DEBUG ("The destination of the newly formed route " << destination << " and the size of the route " << changeVector.size ());
887  changeEntry.SetDestination (destination);
888  changeEntry.SetExpireTime (expire); // Initialize the timeout value to the one it has
889  rtVector.push_back (changeEntry); // Add the route entry to the route list
890  NS_LOG_DEBUG ("We have a sub-route to " << destination);
891  }
892  else
893  {
894  /*
895  * Remove the route
896  */
897  k = rtVector.erase (k);
898  }
899  }
900  else
901  {
902  NS_LOG_LOGIC ("Cut route unsuccessful and erase the route");
903  /*
904  * Remove the route
905  */
906  k = rtVector.erase (k);
907  }
908  }
909  ++j;
910  if (!IsLinkCache ())
911  {
912  m_sortedRoutes.erase (jtmp);
913  }
914  if (rtVector.size ())
915  {
916  /*
917  * Save the new route cache along with the destination address in map
918  */
919  rtVector.sort (CompareRoutesExpire);
920  m_sortedRoutes[address] = rtVector;
921  }
922  else
923  {
924  NS_LOG_DEBUG ("There is no route left for that destination " << address);
925  }
926  }
927  }
928 }
929 
930 void
931 RouteCache::PrintVector (std::vector<Ipv4Address>& vec)
932 {
933  NS_LOG_FUNCTION (this);
934  /*
935  * Check elements in a route vector, used when one wants to check the IP addresses saved in
936  */
937  if (!vec.size ())
938  {
939  NS_LOG_DEBUG ("The vector is empty");
940  }
941  else
942  {
943  NS_LOG_DEBUG ("Print all the elements in a vector");
944  for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
945  {
946  NS_LOG_DEBUG ("The ip address " << *i);
947  }
948  }
949 }
950 
951 void
952 RouteCache::PrintRouteVector (std::list<RouteCacheEntry> route)
953 {
954  NS_LOG_FUNCTION (this);
955  for (std::list<RouteCacheEntry>::iterator i = route.begin (); i != route.end (); i++)
956  {
957  std::vector<Ipv4Address> path = i->GetVector ();
958  NS_LOG_INFO ("Route NO. ");
959  PrintVector (path);
960  }
961 }
962 
963 void
965 {
966  NS_LOG_FUNCTION (this);
967  //Trying to purge the route cache
968  if (m_sortedRoutes.empty ())
969  {
970  NS_LOG_DEBUG ("The route cache is empty");
971  return;
972  }
973  for (std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator i =
974  m_sortedRoutes.begin (); i != m_sortedRoutes.end (); )
975  {
976  // Loop of route cache entry with the route size
977  std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator itmp = i;
978  /*
979  * The route cache entry vector
980  */
981  Ipv4Address dst = i->first;
982  std::list<RouteCacheEntry> rtVector = i->second;
983  NS_LOG_DEBUG ("The route vector size of 1 " << dst << " " << rtVector.size ());
984  if (rtVector.size ())
985  {
986  for (std::list<RouteCacheEntry>::iterator j = rtVector.begin (); j != rtVector.end (); )
987  {
988  NS_LOG_DEBUG ("The expire time of every entry with expire time " << j->GetExpireTime ());
989  /*
990  * First verify if the route has expired or not
991  */
992  if (j->GetExpireTime () <= Seconds (0))
993  {
994  /*
995  * When the expire time has passed, erase the certain route
996  */
997  NS_LOG_DEBUG ("Erase the expired route for " << dst << " with expire time " << j->GetExpireTime ());
998  j = rtVector.erase (j);
999  }
1000  else
1001  {
1002  ++j;
1003  }
1004  }
1005  NS_LOG_DEBUG ("The route vector size of 2 " << dst << " " << rtVector.size ());
1006  if (rtVector.size ())
1007  {
1008  ++i;
1009  m_sortedRoutes.erase (itmp); // erase the entry first
1010  /*
1011  * Save the new route cache along with the destination address in map
1012  */
1013  m_sortedRoutes.insert (std::make_pair (dst, rtVector));
1014  }
1015  else
1016  {
1017  ++i;
1018  m_sortedRoutes.erase (itmp);
1019  }
1020  }
1021  else
1022  {
1023  ++i;
1024  m_sortedRoutes.erase (itmp);
1025  }
1026  }
1027  return;
1028 }
1029 
1030 void
1031 RouteCache::Print (std::ostream &os)
1032 {
1033  NS_LOG_FUNCTION (this);
1034  Purge ();
1035  os << "\nDSR Route Cache\n"
1036  << "Destination\tGateway\t\tInterface\tFlag\tExpire\tHops\n";
1037  for (std::list<RouteCacheEntry>::const_iterator i =
1038  m_routeEntryVector.begin (); i != m_routeEntryVector.end (); ++i)
1039  {
1040  i->Print (os);
1041  }
1042  os << "\n";
1043 }
1044 
1045 // ----------------------------------------------------------------------------------------------------------
1049 uint16_t
1051 {
1052  NS_LOG_FUNCTION (this);
1053  std::map<Ipv4Address, uint16_t>::const_iterator i =
1054  m_ackIdCache.find (nextHop);
1055  if (i == m_ackIdCache.end ())
1056  {
1057  NS_LOG_LOGIC ("No Ack id for " << nextHop << " found and use id 1 for the first network ack id");
1058  m_ackIdCache[nextHop] = 1;
1059  return 1;
1060  }
1061  else
1062  {
1063  uint16_t ackId = m_ackIdCache[nextHop];
1064  NS_LOG_LOGIC ("Ack id for " << nextHop << " found in the cache has value " << ackId);
1065  ackId++;
1066  m_ackIdCache[nextHop] = ackId;
1067  return ackId;
1068  }
1069 }
1070 
1071 uint16_t
1073 {
1074  return m_ackIdCache.size ();
1075 }
1076 
1077 // ----------------------------------------------------------------------------------------------------------
1081 bool
1083 {
1084  NS_LOG_FUNCTION (this);
1085  PurgeMac (); // purge the mac cache
1086  for (std::vector<Neighbor>::const_iterator i = m_nb.begin ();
1087  i != m_nb.end (); ++i)
1088  {
1089  if (i->m_neighborAddress == addr)
1090  {
1091  return true;
1092  }
1093  }
1094  return false;
1095 }
1096 
1097 Time
1099 {
1100  NS_LOG_FUNCTION (this);
1101  PurgeMac ();
1102  for (std::vector<Neighbor>::const_iterator i = m_nb.begin (); i
1103  != m_nb.end (); ++i)
1104  {
1105  if (i->m_neighborAddress == addr)
1106  {
1107  return (i->m_expireTime - Simulator::Now ());
1108  }
1109  }
1110  return Seconds (0);
1111 }
1112 
1113 void
1114 RouteCache::UpdateNeighbor (std::vector<Ipv4Address> nodeList, Time expire)
1115 {
1116  NS_LOG_FUNCTION (this);
1117  for (std::vector<Neighbor>::iterator i = m_nb.begin (); i != m_nb.end (); ++i)
1118  {
1119  for (std::vector<Ipv4Address>::iterator j = nodeList.begin (); j != nodeList.end (); ++j)
1120  {
1121  if (i->m_neighborAddress == (*j))
1122  {
1123  i->m_expireTime
1124  = std::max (expire + Simulator::Now (), i->m_expireTime);
1125  if (i->m_hardwareAddress == Mac48Address ())
1126  {
1127  i->m_hardwareAddress = LookupMacAddress (i->m_neighborAddress);
1128  }
1129  return;
1130  }
1131  }
1132  }
1133 
1134  Ipv4Address addr;
1135  NS_LOG_LOGIC ("Open link to " << addr);
1136  Neighbor neighbor (addr, LookupMacAddress (addr), expire + Simulator::Now ());
1137  m_nb.push_back (neighbor);
1138  PurgeMac ();
1139 }
1140 
1141 void
1142 RouteCache::AddNeighbor (std::vector<Ipv4Address> nodeList, Ipv4Address ownAddress, Time expire)
1143 {
1144  NS_LOG_LOGIC ("Add neighbor number " << nodeList.size ());
1145  for (std::vector<Ipv4Address>::iterator j = nodeList.begin (); j != nodeList.end ();)
1146  {
1147  Ipv4Address addr = *j;
1148  if (addr == ownAddress)
1149  {
1150  j = nodeList.erase (j);
1151  NS_LOG_DEBUG ("The node list size " << nodeList.size ());
1152  }
1153  else
1154  {
1155  ++j;
1156  }
1157  Neighbor neighbor (addr, LookupMacAddress (addr), expire + Simulator::Now ());
1158  m_nb.push_back (neighbor);
1159  PurgeMac ();
1160  }
1161 }
1162 
1164 {
1165  bool operator() (const RouteCache::Neighbor & nb) const
1166  {
1167  return ((nb.m_expireTime < Simulator::Now ()) || nb.close);
1168  }
1169 };
1170 
1171 void
1173 {
1174  if (m_nb.empty ())
1175  {
1176  return;
1177  }
1178 
1179  CloseNeighbor pred;
1180  if (!m_handleLinkFailure.IsNull ())
1181  {
1182  for (std::vector<Neighbor>::iterator j = m_nb.begin (); j != m_nb.end (); ++j)
1183  {
1184  if (pred (*j))
1185  {
1186  NS_LOG_LOGIC ("Close link to " << j->m_neighborAddress);
1188 // m_handleLinkFailure (j->m_neighborAddress);
1189  }
1190  }
1191  }
1192  m_nb.erase (std::remove_if (m_nb.begin (), m_nb.end (), pred), m_nb.end ());
1193  m_ntimer.Cancel ();
1194  m_ntimer.Schedule ();
1195 }
1196 
1197 void
1199 {
1200  m_ntimer.Cancel ();
1201  m_ntimer.Schedule ();
1202 }
1203 
1204 void
1206 {
1207  m_arp.push_back (a);
1208 }
1209 
1210 void
1212 {
1213  m_arp.erase (std::remove (m_arp.begin (), m_arp.end (), a), m_arp.end ());
1214 }
1215 
1218 {
1219  Mac48Address hwaddr;
1220  for (std::vector<Ptr<ArpCache> >::const_iterator i = m_arp.begin ();
1221  i != m_arp.end (); ++i)
1222  {
1223  ArpCache::Entry * entry = (*i)->Lookup (addr);
1224  if (entry != 0 && entry->IsAlive () && !entry->IsExpired ())
1225  {
1226  hwaddr = Mac48Address::ConvertFrom (entry->GetMacAddress ());
1227  break;
1228  }
1229  }
1230  return hwaddr;
1231 }
1232 
1233 void
1235 {
1236  Mac48Address addr = hdr.GetAddr1 ();
1237 
1238  for (std::vector<Neighbor>::iterator i = m_nb.begin (); i != m_nb.end (); ++i)
1239  {
1240  if (i->m_hardwareAddress == addr)
1241  {
1242  i->close = true;
1243  }
1244  }
1245  PurgeMac ();
1246 }
1247 } // namespace dsr
1248 } // namespace ns3
bool CompareRoutesBoth(const RouteCacheEntry &a, const RouteCacheEntry &b)
Definition: dsr-rcache.cc:55
bool DeleteRoute(Ipv4Address dst)
Delete the route with certain destination address.
Definition: dsr-rcache.cc:759
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
void PurgeMac()
Remove all expired mac entries.
Definition: dsr-rcache.cc:1172
void Purge()
Delete all outdated entries and invalidate valid entry if Lifetime is expired.
Definition: dsr-rcache.cc:964
Control the scheduling of simulation events.
Definition: simulator.h:62
void SetVector(IP_VECTOR v)
Definition: dsr-rcache.h:215
a simple Timer class
Definition: timer.h:45
bool CompareRoutesHops(const RouteCacheEntry &a, const RouteCacheEntry &b)
Definition: dsr-rcache.cc:63
bool IncStability(Ipv4Address node)
increase the stability of the node
Definition: dsr-rcache.cc:514
Ipv4Address m_dst
The destination Ip address.
Definition: dsr-rcache.h:270
Ipv4Address GetDestination() const
Definition: dsr-rcache.h:203
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
Time RouteCacheTimeout
The maximum period of time that dsr is allowed to for an unused route.
Definition: dsr-rcache.h:539
bool AddRoute(RouteCacheEntry &rt)
Add route cache entry if it doesn't yet exist in route cache.
Definition: dsr-rcache.cc:656
#define NS_LOG_INFO(msg)
Definition: log.h:298
void RebuildBestRouteTable(Ipv4Address source)
USE MAXWEIGHT TO REPRESENT MAX; USE BROADCAST ADDRESS TO REPRESENT NULL PRECEEDING ADDRESS...
Definition: dsr-rcache.cc:316
NodeStab(Time nodeStab=Simulator::Now())
Definition: dsr-rcache.cc:80
void Print(std::ostream &os)
Print route cache.
Definition: dsr-rcache.cc:1031
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
bool LookupRoute_Link(Ipv4Address id, RouteCacheEntry &rt)
used by LookupRoute when LinkCache
Definition: dsr-rcache.cc:432
std::map< Ipv4Address, std::map< Ipv4Address, uint32_t > > m_netGraph
Current network graph state for this node, double is weight, which is calculated by the node informat...
Definition: dsr-rcache.h:575
bool CompareRoutesExpire(const RouteCacheEntry &a, const RouteCacheEntry &b)
Definition: dsr-rcache.cc:69
bool IsAlive(void)
Definition: arp-cache.cc:286
uint32_t m_stabilityDecrFactor
Define the parameters for link cache type.
Definition: dsr-rcache.h:544
std::map< Ipv4Address, uint16_t > m_ackIdCache
The id cache to ensure all the ids are unique.
Definition: dsr-rcache.h:560
void SetCacheType(std::string type)
Dijsktra algorithm to get the best route from m_netGraph and update the m_bestRoutesTable_link when c...
Definition: dsr-rcache.cc:290
double GetSeconds(void) const
Definition: nstime.h:274
void UseExtends(RouteCacheEntry::IP_VECTOR rt)
When a link from the Route Cache is used in routing a packet originated or salvaged by that node...
Definition: dsr-rcache.cc:610
uint16_t CheckUniqueAckId(Ipv4Address nextHop)
Check for duplicate ids and save new entries if the id is not present in the table.
Definition: dsr-rcache.cc:1050
std::list< RouteCacheEntry::IP_VECTOR > routeVector
Define the vector of route entries.
Definition: dsr-rcache.h:301
void Schedule(void)
Schedule a new event using the currently-configured delay, function, and arguments.
Definition: timer.cc:152
void AddNeighbor(std::vector< Ipv4Address > nodeList, Ipv4Address ownAddress, Time expire)
Add to the neighbor list.
Definition: dsr-rcache.cc:1142
void UpdateNeighbor(std::vector< Ipv4Address > nodeList, Time expire)
Update expire time for entry with address addr, if it exists, else add new entry. ...
Definition: dsr-rcache.cc:1114
void SetFunction(FN fn)
Definition: timer.h:254
void ScheduleTimer()
Schedule m_ntimer.
Definition: dsr-rcache.cc:1198
std::vector< Ipv4Address > IP_VECTOR
Define the vector to hold Ip address.
Definition: dsr-rcache.h:177
bool m_subRoute
Check if save the sub route entries or not.
Definition: dsr-rcache.h:564
Ptr< SampleEmitter > s
bool IsBroadcast(void) const
bool UpdateRouteEntry(Ipv4Address dst)
Update route cache entry if it has been recently used and successfully delivered the data packet...
Definition: dsr-rcache.cc:177
bool operator()(const RouteCache::Neighbor &nb) const
Definition: dsr-rcache.cc:1165
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1238
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e. disable it)
Definition: dsr-rcache.cc:121
void DelArpCache(Ptr< ArpCache >)
Don't use given ARP cache any more (interface is down)
Definition: dsr-rcache.cc:1211
bool IsExpired(void) const
Definition: arp-cache.cc:383
RouteCacheEntry(IP_VECTOR const &ip=IP_VECTOR(), Ipv4Address dst=Ipv4Address(), Time exp=Simulator::Now())
Definition: dsr-rcache.cc:105
Definition: dsr-rcache.h:174
void PrintRouteVector(std::list< RouteCacheEntry > route)
Print all the route vector elements from the route list.
Definition: dsr-rcache.cc:952
std::map< Link, LinkStab > m_linkCache
The data structure to store link info.
Definition: dsr-rcache.h:578
void SetDelay(const Time &delay)
Definition: timer.cc:69
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
Address GetMacAddress(void) const
Definition: arp-cache.cc:347
virtual ~RouteCacheEntry()
Definition: dsr-rcache.cc:116
Callback< void, WifiMacHeader const & > m_txErrorCallback
TX error callback.
Definition: dsr-rcache.h:629
void ProcessTxError(WifiMacHeader const &)
Process layer 2 TX error notification.
Definition: dsr-rcache.cc:1234
uint32_t m_stabilityIncrFactor
Definition: dsr-rcache.h:545
Mac48Address LookupMacAddress(Ipv4Address)
Find MAC address by IP using list of ARP caches.
Definition: dsr-rcache.cc:1217
uint8_t m_reqCount
Number of route requests.
Definition: dsr-rcache.h:274
bool AddRoute_Link(RouteCacheEntry::IP_VECTOR nodelist, Ipv4Address node)
Definition: dsr-rcache.cc:561
static Mac48Address ConvertFrom(const Address &address)
void RemoveLastEntry(std::list< RouteCacheEntry > &rtVector)
Remove the aged route cache entries when the route cache is full.
Definition: dsr-rcache.cc:169
void PrintVector(std::vector< Ipv4Address > &vec)
Print the route vector elements.
Definition: dsr-rcache.cc:931
void Print(std::ostream &os) const
Print necessary fields.
Definition: dsr-rcache.cc:128
static TypeId GetTypeId()
Definition: dsr-rcache.cc:137
an EUI-48 address
Definition: mac48-address.h:41
DSR route request queue Since DSR is an on demand routing we queue requests while looking for route...
Definition: dsr-rcache.h:285
A record that that holds information about an ArpCache entry.
Definition: arp-cache.h:160
The following code handles link-layer acks.
Definition: dsr-rcache.h:459
uint16_t GetAckSize()
Get the ack table size.
Definition: dsr-rcache.cc:1072
Time GetExpireTime() const
Definition: dsr-rcache.h:223
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
IP_VECTOR GetVector() const
Definition: dsr-rcache.h:211
std::vector< Ptr< ArpCache > > m_arp
list of ARP cached to be used for layer 2 notifications processing
Definition: dsr-rcache.h:635
std::list< RouteCacheEntry >::value_type route_pair
Definition: dsr-rcache.cc:103
void SetExpireTime(Time exp)
Definition: dsr-rcache.h:219
bool LookupRoute(Ipv4Address id, RouteCacheEntry &rt)
Lookup route cache entry with destination address dst.
Definition: dsr-rcache.cc:207
void SetNodeStability(Time nodeStab)
Definition: dsr-rcache.h:162
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
uint32_t m_maxEntriesEachDst
number of entries for each destination
Definition: dsr-rcache.h:558
Timer m_ntimer
Timer for neighbor's list. Schedule Purge().
Definition: dsr-rcache.h:631
virtual ~NodeStab()
Definition: dsr-rcache.cc:85
std::map< Ipv4Address, RouteCacheEntry::IP_VECTOR > m_bestRoutesTable_link
for link route cache
Definition: dsr-rcache.h:577
#define MAXWEIGHT
The link cache to update all the link status, bi-link is two link for link is a struct when the weigh...
Definition: dsr-rcache.h:569
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
void Cancel(void)
Cancel the currently-running event if there is one.
Definition: timer.cc:103
std::map< Ipv4Address, routeEntryVector > m_sortedRoutes
Map the ipv4Address to route entry vector.
Definition: dsr-rcache.h:554
Time m_expire
Expire time for queue entry.
Definition: dsr-rcache.h:272
void UpdateNetGraph()
Update the Net Graph for the link and node cache has changed.
Definition: dsr-rcache.cc:499
Callback< void, Ipv4Address, uint8_t > m_handleLinkFailure
The following code handles link-layer acks.
Definition: dsr-rcache.h:627
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
bool FindSameRoute(RouteCacheEntry &rt, std::list< RouteCacheEntry > &rtVector)
Find the same route in the route cache.
Definition: dsr-rcache.cc:726
a base class which provides memory management and object aggregation
Definition: object.h:63
tuple address
Definition: first.py:37
void DeleteAllRoutesIncludeLink(Ipv4Address errorSrc, Ipv4Address unreachNode, Ipv4Address node)
Delete all the routes which includes the link from next hop address that has just been notified as un...
Definition: dsr-rcache.cc:773
bool DecStability(Ipv4Address node)
decrease the stability of the node
Definition: dsr-rcache.cc:538
std::vector< Neighbor > m_nb
vector of entries
Definition: dsr-rcache.h:633
routeEntryVector m_routeEntryVector
Define the route vector.
Definition: dsr-rcache.h:556
bool m_isLinkCache
Check if the route is using path cache or link cache.
Definition: dsr-rcache.h:562
a unique identifier for an interface.
Definition: type-id.h:49
bool IsNeighbor(Ipv4Address addr)
Check that node with address addr is neighbor.
Definition: dsr-rcache.cc:1082
Time GetExpireTime(Ipv4Address addr)
Return expire time for neighbor node with address addr, if exists, else return 0. ...
Definition: dsr-rcache.cc:1098
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
NS_LOG_COMPONENT_DEFINE("RouteCache")
void SetDestination(Ipv4Address d)
Definition: dsr-rcache.h:207
Time m_delay
This timeout deals with the passive ack.
Definition: dsr-rcache.h:637
Implements the IEEE 802.11 MAC header.
void AddArpCache(Ptr< ArpCache >)
Add ARP cache to be used to allow layer 2 notifications processing.
Definition: dsr-rcache.cc:1205
std::map< Ipv4Address, NodeStab > m_nodeCache
The data structure to store node info.
Definition: dsr-rcache.h:579