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