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