|
|
| 49 |
|
49 |
|
| 50 |
namespace ns3 { |
50 |
namespace ns3 { |
| 51 |
|
51 |
|
| 52 |
NS_LOG_COMPONENT_DEFINE ("RouteCache"); |
52 |
NS_LOG_COMPONENT_DEFINE ("DsrRouteCache"); |
| 53 |
|
53 |
|
| 54 |
namespace dsr { |
54 |
namespace dsr { |
| 55 |
|
55 |
|
| 56 |
bool CompareRoutesBoth (const RouteCacheEntry &a, const RouteCacheEntry &b) |
56 |
bool CompareRoutesBoth (const DsrRouteCacheEntry &a, const DsrRouteCacheEntry &b) |
| 57 |
{ |
57 |
{ |
| 58 |
// compare based on both with hop count considered priority |
58 |
// compare based on both with hop count considered priority |
| 59 |
return (a.GetVector ().size () < b.GetVector ().size ()) |
59 |
return (a.GetVector ().size () < b.GetVector ().size ()) |
|
|
| 61 |
; |
61 |
; |
| 62 |
} |
62 |
} |
| 63 |
|
63 |
|
| 64 |
bool CompareRoutesHops (const RouteCacheEntry &a, const RouteCacheEntry &b) |
64 |
bool CompareRoutesHops (const DsrRouteCacheEntry &a, const DsrRouteCacheEntry &b) |
| 65 |
{ |
65 |
{ |
| 66 |
// compare based on hops |
66 |
// compare based on hops |
| 67 |
return a.GetVector ().size () < b.GetVector ().size (); |
67 |
return a.GetVector ().size () < b.GetVector ().size (); |
| 68 |
} |
68 |
} |
| 69 |
|
69 |
|
| 70 |
bool CompareRoutesExpire (const RouteCacheEntry &a, const RouteCacheEntry &b) |
70 |
bool CompareRoutesExpire (const DsrRouteCacheEntry &a, const DsrRouteCacheEntry &b) |
| 71 |
{ |
71 |
{ |
| 72 |
// compare based on expire time |
72 |
// compare based on expire time |
| 73 |
return a.GetExpireTime () > b.GetExpireTime (); |
73 |
return a.GetExpireTime () > b.GetExpireTime (); |
|
|
| 78 |
NS_LOG_DEBUG (m_low << "----" << m_high); |
78 |
NS_LOG_DEBUG (m_low << "----" << m_high); |
| 79 |
} |
79 |
} |
| 80 |
|
80 |
|
| 81 |
NodeStab::NodeStab (Time nodeStab) |
81 |
DsrNodeStab::DsrNodeStab (Time nodeStab) |
| 82 |
: m_nodeStability (nodeStab + Simulator::Now ()) |
82 |
: m_nodeStability (nodeStab + Simulator::Now ()) |
| 83 |
{ |
83 |
{ |
| 84 |
} |
84 |
} |
| 85 |
|
85 |
|
| 86 |
NodeStab::~NodeStab () |
86 |
DsrNodeStab::~DsrNodeStab () |
| 87 |
{ |
87 |
{ |
| 88 |
} |
88 |
} |
| 89 |
|
89 |
|
| 90 |
LinkStab::LinkStab (Time linkStab) |
90 |
DsrLinkStab::DsrLinkStab (Time linkStab) |
| 91 |
: m_linkStability (linkStab + Simulator::Now ()) |
91 |
: m_linkStability (linkStab + Simulator::Now ()) |
| 92 |
{ |
92 |
{ |
| 93 |
} |
93 |
} |
| 94 |
|
94 |
|
| 95 |
LinkStab::~LinkStab () |
95 |
DsrLinkStab::~DsrLinkStab () |
| 96 |
{ |
96 |
{ |
| 97 |
} |
97 |
} |
| 98 |
|
98 |
|
| 99 |
void LinkStab::Print ( ) const |
99 |
void DsrLinkStab::Print ( ) const |
| 100 |
{ |
100 |
{ |
| 101 |
NS_LOG_LOGIC ("LifeTime: " << GetLinkStability ().GetSeconds ()); |
101 |
NS_LOG_LOGIC ("LifeTime: " << GetLinkStability ().GetSeconds ()); |
| 102 |
} |
102 |
} |
| 103 |
|
103 |
|
| 104 |
typedef std::list<RouteCacheEntry>::value_type route_pair; |
104 |
typedef std::list<DsrRouteCacheEntry>::value_type route_pair; |
| 105 |
|
105 |
|
| 106 |
RouteCacheEntry::RouteCacheEntry (IP_VECTOR const & ip, Ipv4Address dst, Time exp) |
106 |
DsrRouteCacheEntry::DsrRouteCacheEntry (IP_VECTOR const & ip, Ipv4Address dst, Time exp) |
| 107 |
: m_ackTimer (Timer::CANCEL_ON_DESTROY), |
107 |
: m_ackTimer (Timer::CANCEL_ON_DESTROY), |
| 108 |
m_dst (dst), |
108 |
m_dst (dst), |
| 109 |
m_path (ip), |
109 |
m_path (ip), |
|
|
| 114 |
{ |
114 |
{ |
| 115 |
} |
115 |
} |
| 116 |
|
116 |
|
| 117 |
RouteCacheEntry::~RouteCacheEntry () |
117 |
DsrRouteCacheEntry::~DsrRouteCacheEntry () |
| 118 |
{ |
118 |
{ |
| 119 |
} |
119 |
} |
| 120 |
|
120 |
|
| 121 |
void |
121 |
void |
| 122 |
RouteCacheEntry::Invalidate (Time badLinkLifetime) |
122 |
DsrRouteCacheEntry::Invalidate (Time badLinkLifetime) |
| 123 |
{ |
123 |
{ |
| 124 |
m_reqCount = 0; |
124 |
m_reqCount = 0; |
| 125 |
m_expire = badLinkLifetime + Simulator::Now (); |
125 |
m_expire = badLinkLifetime + Simulator::Now (); |
| 126 |
} |
126 |
} |
| 127 |
|
127 |
|
| 128 |
void |
128 |
void |
| 129 |
RouteCacheEntry::Print (std::ostream & os) const |
129 |
DsrRouteCacheEntry::Print (std::ostream & os) const |
| 130 |
{ |
130 |
{ |
| 131 |
os << m_dst << "\t" << (m_expire - Simulator::Now ()).GetSeconds () |
131 |
os << m_dst << "\t" << (m_expire - Simulator::Now ()).GetSeconds () |
| 132 |
<< "\t"; |
132 |
<< "\t"; |
| 133 |
} |
133 |
} |
| 134 |
|
134 |
|
| 135 |
NS_OBJECT_ENSURE_REGISTERED (RouteCache); |
135 |
NS_OBJECT_ENSURE_REGISTERED (DsrRouteCache); |
| 136 |
|
136 |
|
| 137 |
TypeId RouteCache::GetTypeId () |
137 |
TypeId DsrRouteCache::GetTypeId () |
| 138 |
{ |
138 |
{ |
| 139 |
static TypeId tid = TypeId ("ns3::dsr::RouteCache") |
139 |
static TypeId tid = TypeId ("ns3::dsr::DsrRouteCache") |
| 140 |
.SetParent<Object> () |
140 |
.SetParent<Object> () |
| 141 |
.SetGroupName ("Dsr") |
141 |
.SetGroupName ("Dsr") |
| 142 |
.AddConstructor<RouteCache> () |
142 |
.AddConstructor<DsrRouteCache> () |
| 143 |
; |
143 |
; |
| 144 |
return tid; |
144 |
return tid; |
| 145 |
} |
145 |
} |
| 146 |
|
146 |
|
| 147 |
RouteCache::RouteCache () |
147 |
DsrRouteCache::DsrRouteCache () |
| 148 |
: m_vector (0), |
148 |
: m_vector (0), |
| 149 |
m_maxEntriesEachDst (3), |
149 |
m_maxEntriesEachDst (3), |
| 150 |
m_isLinkCache (false), |
150 |
m_isLinkCache (false), |
|
|
| 155 |
* The timer to set layer 2 notification, not fully supported by ns3 yet |
155 |
* The timer to set layer 2 notification, not fully supported by ns3 yet |
| 156 |
*/ |
156 |
*/ |
| 157 |
m_ntimer.SetDelay (m_delay); |
157 |
m_ntimer.SetDelay (m_delay); |
| 158 |
m_ntimer.SetFunction (&RouteCache::PurgeMac, this); |
158 |
m_ntimer.SetFunction (&DsrRouteCache::PurgeMac, this); |
| 159 |
m_txErrorCallback = MakeCallback (&RouteCache::ProcessTxError, this); |
159 |
m_txErrorCallback = MakeCallback (&DsrRouteCache::ProcessTxError, this); |
| 160 |
} |
160 |
} |
| 161 |
|
161 |
|
| 162 |
RouteCache::~RouteCache () |
162 |
DsrRouteCache::~DsrRouteCache () |
| 163 |
{ |
163 |
{ |
| 164 |
NS_LOG_FUNCTION_NOARGS (); |
164 |
NS_LOG_FUNCTION_NOARGS (); |
| 165 |
// clear the route cache when done |
165 |
// clear the route cache when done |
|
|
| 167 |
} |
167 |
} |
| 168 |
|
168 |
|
| 169 |
void |
169 |
void |
| 170 |
RouteCache::RemoveLastEntry (std::list<RouteCacheEntry> & rtVector) |
170 |
DsrRouteCache::RemoveLastEntry (std::list<DsrRouteCacheEntry> & rtVector) |
| 171 |
{ |
171 |
{ |
| 172 |
NS_LOG_FUNCTION (this); |
172 |
NS_LOG_FUNCTION (this); |
| 173 |
// Release the last entry of route list |
173 |
// Release the last entry of route list |
|
|
| 175 |
} |
175 |
} |
| 176 |
|
176 |
|
| 177 |
bool |
177 |
bool |
| 178 |
RouteCache::UpdateRouteEntry (Ipv4Address dst) |
178 |
DsrRouteCache::UpdateRouteEntry (Ipv4Address dst) |
| 179 |
{ |
179 |
{ |
| 180 |
NS_LOG_FUNCTION (this << dst); |
180 |
NS_LOG_FUNCTION (this << dst); |
| 181 |
std::map<Ipv4Address, std::list<RouteCacheEntry> >::const_iterator i = |
181 |
std::map<Ipv4Address, std::list<DsrRouteCacheEntry> >::const_iterator i = |
| 182 |
m_sortedRoutes.find (dst); |
182 |
m_sortedRoutes.find (dst); |
| 183 |
if (i == m_sortedRoutes.end ()) |
183 |
if (i == m_sortedRoutes.end ()) |
| 184 |
{ |
184 |
{ |
|
|
| 187 |
} |
187 |
} |
| 188 |
else |
188 |
else |
| 189 |
{ |
189 |
{ |
| 190 |
std::list<RouteCacheEntry> rtVector = i->second; |
190 |
std::list<DsrRouteCacheEntry> rtVector = i->second; |
| 191 |
RouteCacheEntry successEntry = rtVector.front (); |
191 |
DsrRouteCacheEntry successEntry = rtVector.front (); |
| 192 |
successEntry.SetExpireTime (RouteCacheTimeout); |
192 |
successEntry.SetExpireTime (RouteCacheTimeout); |
| 193 |
rtVector.pop_front (); |
193 |
rtVector.pop_front (); |
| 194 |
rtVector.push_back (successEntry); |
194 |
rtVector.push_back (successEntry); |
|
|
| 197 |
/* |
197 |
/* |
| 198 |
* Save the new route cache along with the destination address in map |
198 |
* Save the new route cache along with the destination address in map |
| 199 |
*/ |
199 |
*/ |
| 200 |
std::pair<std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator, bool> result = |
200 |
std::pair<std::map<Ipv4Address, std::list<DsrRouteCacheEntry> >::iterator, bool> result = |
| 201 |
m_sortedRoutes.insert (std::make_pair (dst, rtVector)); |
201 |
m_sortedRoutes.insert (std::make_pair (dst, rtVector)); |
| 202 |
return result.second; |
202 |
return result.second; |
| 203 |
} |
203 |
} |
|
|
| 205 |
} |
205 |
} |
| 206 |
|
206 |
|
| 207 |
bool |
207 |
bool |
| 208 |
RouteCache::LookupRoute (Ipv4Address id, RouteCacheEntry & rt) |
208 |
DsrRouteCache::LookupRoute (Ipv4Address id, DsrRouteCacheEntry & rt) |
| 209 |
{ |
209 |
{ |
| 210 |
NS_LOG_FUNCTION (this << id); |
210 |
NS_LOG_FUNCTION (this << id); |
| 211 |
if (IsLinkCache ()) |
211 |
if (IsLinkCache ()) |
|
|
| 220 |
NS_LOG_LOGIC ("Route to " << id << " not found; m_sortedRoutes is empty"); |
220 |
NS_LOG_LOGIC ("Route to " << id << " not found; m_sortedRoutes is empty"); |
| 221 |
return false; |
221 |
return false; |
| 222 |
} |
222 |
} |
| 223 |
std::map<Ipv4Address, std::list<RouteCacheEntry> >::const_iterator i = m_sortedRoutes.find (id); |
223 |
std::map<Ipv4Address, std::list<DsrRouteCacheEntry> >::const_iterator i = m_sortedRoutes.find (id); |
| 224 |
if (i == m_sortedRoutes.end ()) |
224 |
if (i == m_sortedRoutes.end ()) |
| 225 |
{ |
225 |
{ |
| 226 |
NS_LOG_LOGIC ("No Direct Route to " << id << " found"); |
226 |
NS_LOG_LOGIC ("No Direct Route to " << id << " found"); |
| 227 |
for (std::map<Ipv4Address, std::list<RouteCacheEntry> >::const_iterator j = |
227 |
for (std::map<Ipv4Address, std::list<DsrRouteCacheEntry> >::const_iterator j = |
| 228 |
m_sortedRoutes.begin (); j != m_sortedRoutes.end (); ++j) |
228 |
m_sortedRoutes.begin (); j != m_sortedRoutes.end (); ++j) |
| 229 |
{ |
229 |
{ |
| 230 |
std::list<RouteCacheEntry> rtVector = j->second; // The route cache vector linked with destination address |
230 |
std::list<DsrRouteCacheEntry> rtVector = j->second; // The route cache vector linked with destination address |
| 231 |
/* |
231 |
/* |
| 232 |
* Loop through the possibly multiple routes within the route vector |
232 |
* Loop through the possibly multiple routes within the route vector |
| 233 |
*/ |
233 |
*/ |
| 234 |
for (std::list<RouteCacheEntry>::const_iterator k = rtVector.begin (); k != rtVector.end (); ++k) |
234 |
for (std::list<DsrRouteCacheEntry>::const_iterator k = rtVector.begin (); k != rtVector.end (); ++k) |
| 235 |
{ |
235 |
{ |
| 236 |
// return the first route in the route vector |
236 |
// return the first route in the route vector |
| 237 |
RouteCacheEntry::IP_VECTOR routeVector = k->GetVector (); |
237 |
DsrRouteCacheEntry::IP_VECTOR routeVector = k->GetVector (); |
| 238 |
RouteCacheEntry::IP_VECTOR changeVector; |
238 |
DsrRouteCacheEntry::IP_VECTOR changeVector; |
| 239 |
|
239 |
|
| 240 |
for (RouteCacheEntry::IP_VECTOR::iterator l = routeVector.begin (); l != routeVector.end (); ++l) |
240 |
for (DsrRouteCacheEntry::IP_VECTOR::iterator l = routeVector.begin (); l != routeVector.end (); ++l) |
| 241 |
{ |
241 |
{ |
| 242 |
if (*l != id) |
242 |
if (*l != id) |
| 243 |
{ |
243 |
{ |
|
|
| 255 |
*/ |
255 |
*/ |
| 256 |
if ((changeVector.size () < routeVector.size ()) && (changeVector.size () > 1)) |
256 |
if ((changeVector.size () < routeVector.size ()) && (changeVector.size () > 1)) |
| 257 |
{ |
257 |
{ |
| 258 |
RouteCacheEntry changeEntry; // Create the route entry |
258 |
DsrRouteCacheEntry changeEntry; // Create the route entry |
| 259 |
changeEntry.SetVector (changeVector); |
259 |
changeEntry.SetVector (changeVector); |
| 260 |
changeEntry.SetDestination (id); |
260 |
changeEntry.SetDestination (id); |
| 261 |
// Use the expire time from original route entry |
261 |
// Use the expire time from original route entry |
| 262 |
changeEntry.SetExpireTime (k->GetExpireTime ()); |
262 |
changeEntry.SetExpireTime (k->GetExpireTime ()); |
| 263 |
// We need to add new route entry here |
263 |
// We need to add new route entry here |
| 264 |
std::list<RouteCacheEntry> newVector; |
264 |
std::list<DsrRouteCacheEntry> newVector; |
| 265 |
newVector.push_back (changeEntry); |
265 |
newVector.push_back (changeEntry); |
| 266 |
newVector.sort (CompareRoutesExpire); // sort the route vector first |
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 |
267 |
m_sortedRoutes[id] = newVector; // Only get the first sub route and add it in route cache |
|
|
| 271 |
} |
271 |
} |
| 272 |
} |
272 |
} |
| 273 |
NS_LOG_INFO ("Here we check the route cache again after updated the sub routes"); |
273 |
NS_LOG_INFO ("Here we check the route cache again after updated the sub routes"); |
| 274 |
std::map<Ipv4Address, std::list<RouteCacheEntry> >::const_iterator m = m_sortedRoutes.find (id); |
274 |
std::map<Ipv4Address, std::list<DsrRouteCacheEntry> >::const_iterator m = m_sortedRoutes.find (id); |
| 275 |
if (m == m_sortedRoutes.end ()) |
275 |
if (m == m_sortedRoutes.end ()) |
| 276 |
{ |
276 |
{ |
| 277 |
NS_LOG_LOGIC ("No updated route till last time"); |
277 |
NS_LOG_LOGIC ("No updated route till last time"); |
|
|
| 280 |
/* |
280 |
/* |
| 281 |
* We have a direct route to the destination address |
281 |
* We have a direct route to the destination address |
| 282 |
*/ |
282 |
*/ |
| 283 |
std::list<RouteCacheEntry> rtVector = m->second; |
283 |
std::list<DsrRouteCacheEntry> rtVector = m->second; |
| 284 |
rt = rtVector.front (); // use the first entry in the route vector |
284 |
rt = rtVector.front (); // use the first entry in the route vector |
| 285 |
NS_LOG_LOGIC ("Route to " << id << " with route size " << rtVector.size ()); |
285 |
NS_LOG_LOGIC ("Route to " << id << " with route size " << rtVector.size ()); |
| 286 |
return true; |
286 |
return true; |
|
|
| 288 |
} |
288 |
} |
| 289 |
|
289 |
|
| 290 |
void |
290 |
void |
| 291 |
RouteCache::SetCacheType (std::string type) |
291 |
DsrRouteCache::SetCacheType (std::string type) |
| 292 |
{ |
292 |
{ |
| 293 |
NS_LOG_FUNCTION (this << type); |
293 |
NS_LOG_FUNCTION (this << type); |
| 294 |
if (type == std::string ("LinkCache")) |
294 |
if (type == std::string ("LinkCache")) |
|
|
| 307 |
} |
307 |
} |
| 308 |
|
308 |
|
| 309 |
bool |
309 |
bool |
| 310 |
RouteCache::IsLinkCache () |
310 |
DsrRouteCache::IsLinkCache () |
| 311 |
{ |
311 |
{ |
| 312 |
NS_LOG_FUNCTION (this); |
312 |
NS_LOG_FUNCTION (this); |
| 313 |
return m_isLinkCache; |
313 |
return m_isLinkCache; |
| 314 |
} |
314 |
} |
| 315 |
|
315 |
|
| 316 |
void |
316 |
void |
| 317 |
RouteCache::RebuildBestRouteTable (Ipv4Address source) |
317 |
DsrRouteCache::RebuildBestRouteTable (Ipv4Address source) |
| 318 |
{ |
318 |
{ |
| 319 |
NS_LOG_FUNCTION (this << source); |
319 |
NS_LOG_FUNCTION (this << source); |
| 320 |
/** |
320 |
/** |
|
|
| 381 |
*/ |
381 |
*/ |
| 382 |
else if (d[k->first] == d[tempip] + k->second) |
382 |
else if (d[k->first] == d[tempip] + k->second) |
| 383 |
{ |
383 |
{ |
| 384 |
std::map<Link, LinkStab>::iterator oldlink = m_linkCache.find (Link (k->first, pre[k->first])); |
384 |
std::map<Link, DsrLinkStab>::iterator oldlink = m_linkCache.find (Link (k->first, pre[k->first])); |
| 385 |
std::map<Link, LinkStab>::iterator newlink = m_linkCache.find (Link (k->first, tempip)); |
385 |
std::map<Link, DsrLinkStab>::iterator newlink = m_linkCache.find (Link (k->first, tempip)); |
| 386 |
if (oldlink != m_linkCache.end () && newlink != m_linkCache.end ()) |
386 |
if (oldlink != m_linkCache.end () && newlink != m_linkCache.end ()) |
| 387 |
{ |
387 |
{ |
| 388 |
if (oldlink->second.GetLinkStability () < newlink->second.GetLinkStability ()) |
388 |
if (oldlink->second.GetLinkStability () < newlink->second.GetLinkStability ()) |
|
|
| 405 |
for (std::map<Ipv4Address, Ipv4Address>::iterator i = pre.begin (); i != pre.end (); ++i) |
405 |
for (std::map<Ipv4Address, Ipv4Address>::iterator i = pre.begin (); i != pre.end (); ++i) |
| 406 |
{ |
406 |
{ |
| 407 |
// loop for all vertexes |
407 |
// loop for all vertexes |
| 408 |
RouteCacheEntry::IP_VECTOR route; |
408 |
DsrRouteCacheEntry::IP_VECTOR route; |
| 409 |
Ipv4Address iptemp = i->first; |
409 |
Ipv4Address iptemp = i->first; |
| 410 |
|
410 |
|
| 411 |
if (!i->second.IsBroadcast () && iptemp != source) |
411 |
if (!i->second.IsBroadcast () && iptemp != source) |
|
|
| 417 |
} |
417 |
} |
| 418 |
route.push_back (source); |
418 |
route.push_back (source); |
| 419 |
// Reverse the route |
419 |
// Reverse the route |
| 420 |
RouteCacheEntry::IP_VECTOR reverseroute; |
420 |
DsrRouteCacheEntry::IP_VECTOR reverseroute; |
| 421 |
for (RouteCacheEntry::IP_VECTOR::reverse_iterator j = route.rbegin (); j != route.rend (); ++j) |
421 |
for (DsrRouteCacheEntry::IP_VECTOR::reverse_iterator j = route.rbegin (); j != route.rend (); ++j) |
| 422 |
{ |
422 |
{ |
| 423 |
reverseroute.push_back (*j); |
423 |
reverseroute.push_back (*j); |
| 424 |
} |
424 |
} |
|
|
| 430 |
} |
430 |
} |
| 431 |
|
431 |
|
| 432 |
bool |
432 |
bool |
| 433 |
RouteCache::LookupRoute_Link (Ipv4Address id, RouteCacheEntry & rt) |
433 |
DsrRouteCache::LookupRoute_Link (Ipv4Address id, DsrRouteCacheEntry & rt) |
| 434 |
{ |
434 |
{ |
| 435 |
NS_LOG_FUNCTION (this << id); |
435 |
NS_LOG_FUNCTION (this << id); |
| 436 |
/// We need to purge the link node cache |
436 |
/// We need to purge the link node cache |
| 437 |
PurgeLinkNode (); |
437 |
PurgeLinkNode (); |
| 438 |
std::map<Ipv4Address, RouteCacheEntry::IP_VECTOR>::const_iterator i = m_bestRoutesTable_link.find (id); |
438 |
std::map<Ipv4Address, DsrRouteCacheEntry::IP_VECTOR>::const_iterator i = m_bestRoutesTable_link.find (id); |
| 439 |
if (i == m_bestRoutesTable_link.end ()) |
439 |
if (i == m_bestRoutesTable_link.end ()) |
| 440 |
{ |
440 |
{ |
| 441 |
NS_LOG_INFO ("No route find to " << id); |
441 |
NS_LOG_INFO ("No route find to " << id); |
|
|
| 449 |
return false; |
449 |
return false; |
| 450 |
} |
450 |
} |
| 451 |
|
451 |
|
| 452 |
RouteCacheEntry newEntry; // Create the route entry |
452 |
DsrRouteCacheEntry newEntry; // Create the route entry |
| 453 |
newEntry.SetVector (i->second); |
453 |
newEntry.SetVector (i->second); |
| 454 |
newEntry.SetDestination (id); |
454 |
newEntry.SetDestination (id); |
| 455 |
newEntry.SetExpireTime (RouteCacheTimeout); |
455 |
newEntry.SetExpireTime (RouteCacheTimeout); |
|
|
| 462 |
} |
462 |
} |
| 463 |
|
463 |
|
| 464 |
void |
464 |
void |
| 465 |
RouteCache::PurgeLinkNode () |
465 |
DsrRouteCache::PurgeLinkNode () |
| 466 |
{ |
466 |
{ |
| 467 |
NS_LOG_FUNCTION (this); |
467 |
NS_LOG_FUNCTION (this); |
| 468 |
for (std::map<Link, LinkStab>::iterator i = m_linkCache.begin (); i != m_linkCache.end (); ) |
468 |
for (std::map<Link, DsrLinkStab>::iterator i = m_linkCache.begin (); i != m_linkCache.end (); ) |
| 469 |
{ |
469 |
{ |
| 470 |
NS_LOG_DEBUG ("The link stability " << i->second.GetLinkStability ().GetSeconds ()); |
470 |
NS_LOG_DEBUG ("The link stability " << i->second.GetLinkStability ().GetSeconds ()); |
| 471 |
std::map<Link, LinkStab>::iterator itmp = i; |
471 |
std::map<Link, DsrLinkStab>::iterator itmp = i; |
| 472 |
if (i->second.GetLinkStability () <= Seconds (0)) |
472 |
if (i->second.GetLinkStability () <= Seconds (0)) |
| 473 |
{ |
473 |
{ |
| 474 |
++i; |
474 |
++i; |
|
|
| 480 |
} |
480 |
} |
| 481 |
} |
481 |
} |
| 482 |
/// may need to remove them after verify |
482 |
/// may need to remove them after verify |
| 483 |
for (std::map<Ipv4Address, NodeStab>::iterator i = m_nodeCache.begin (); i != m_nodeCache.end (); ) |
483 |
for (std::map<Ipv4Address, DsrNodeStab>::iterator i = m_nodeCache.begin (); i != m_nodeCache.end (); ) |
| 484 |
{ |
484 |
{ |
| 485 |
NS_LOG_DEBUG ("The node stability " << i->second.GetNodeStability ().GetSeconds ()); |
485 |
NS_LOG_DEBUG ("The node stability " << i->second.GetNodeStability ().GetSeconds ()); |
| 486 |
std::map<Ipv4Address, NodeStab>::iterator itmp = i; |
486 |
std::map<Ipv4Address, DsrNodeStab>::iterator itmp = i; |
| 487 |
if (i->second.GetNodeStability () <= Seconds (0)) |
487 |
if (i->second.GetNodeStability () <= Seconds (0)) |
| 488 |
{ |
488 |
{ |
| 489 |
++i; |
489 |
++i; |
|
|
| 497 |
} |
497 |
} |
| 498 |
|
498 |
|
| 499 |
void |
499 |
void |
| 500 |
RouteCache::UpdateNetGraph () |
500 |
DsrRouteCache::UpdateNetGraph () |
| 501 |
{ |
501 |
{ |
| 502 |
NS_LOG_FUNCTION (this); |
502 |
NS_LOG_FUNCTION (this); |
| 503 |
m_netGraph.clear (); |
503 |
m_netGraph.clear (); |
| 504 |
for (std::map<Link, LinkStab>::iterator i = m_linkCache.begin (); i != m_linkCache.end (); ++i) |
504 |
for (std::map<Link, DsrLinkStab>::iterator i = m_linkCache.begin (); i != m_linkCache.end (); ++i) |
| 505 |
{ |
505 |
{ |
| 506 |
// Here the weight is set as 1 |
506 |
// Here the weight is set as 1 |
| 507 |
/// \todo May need to set different weight for different link here later |
507 |
/// \todo May need to set different weight for different link here later |
|
|
| 512 |
} |
512 |
} |
| 513 |
|
513 |
|
| 514 |
bool |
514 |
bool |
| 515 |
RouteCache::IncStability (Ipv4Address node) |
515 |
DsrRouteCache::IncStability (Ipv4Address node) |
| 516 |
{ |
516 |
{ |
| 517 |
NS_LOG_FUNCTION (this << node); |
517 |
NS_LOG_FUNCTION (this << node); |
| 518 |
std::map<Ipv4Address, NodeStab>::const_iterator i = m_nodeCache.find (node); |
518 |
std::map<Ipv4Address, DsrNodeStab>::const_iterator i = m_nodeCache.find (node); |
| 519 |
if (i == m_nodeCache.end ()) |
519 |
if (i == m_nodeCache.end ()) |
| 520 |
{ |
520 |
{ |
| 521 |
NS_LOG_INFO ("The initial stability " << m_initStability.GetSeconds ()); |
521 |
NS_LOG_INFO ("The initial stability " << m_initStability.GetSeconds ()); |
| 522 |
NodeStab ns (m_initStability); |
522 |
DsrNodeStab ns (m_initStability); |
| 523 |
m_nodeCache[node] = ns; |
523 |
m_nodeCache[node] = ns; |
| 524 |
return false; |
524 |
return false; |
| 525 |
} |
525 |
} |
|
|
| 528 |
/// \todo get rid of the debug here |
528 |
/// \todo get rid of the debug here |
| 529 |
NS_LOG_INFO ("The node stability " << i->second.GetNodeStability ().GetSeconds ()); |
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 ()); |
530 |
NS_LOG_INFO ("The stability here " << Time (i->second.GetNodeStability () * m_stabilityIncrFactor).GetSeconds ()); |
| 531 |
NodeStab ns (Time (i->second.GetNodeStability () * m_stabilityIncrFactor)); |
531 |
DsrNodeStab ns (Time (i->second.GetNodeStability () * m_stabilityIncrFactor)); |
| 532 |
m_nodeCache[node] = ns; |
532 |
m_nodeCache[node] = ns; |
| 533 |
return true; |
533 |
return true; |
| 534 |
} |
534 |
} |
|
|
| 536 |
} |
536 |
} |
| 537 |
|
537 |
|
| 538 |
bool |
538 |
bool |
| 539 |
RouteCache::DecStability (Ipv4Address node) |
539 |
DsrRouteCache::DecStability (Ipv4Address node) |
| 540 |
{ |
540 |
{ |
| 541 |
NS_LOG_FUNCTION (this << node); |
541 |
NS_LOG_FUNCTION (this << node); |
| 542 |
std::map<Ipv4Address, NodeStab>::const_iterator i = m_nodeCache.find (node); |
542 |
std::map<Ipv4Address, DsrNodeStab>::const_iterator i = m_nodeCache.find (node); |
| 543 |
if (i == m_nodeCache.end ()) |
543 |
if (i == m_nodeCache.end ()) |
| 544 |
{ |
544 |
{ |
| 545 |
NodeStab ns (m_initStability); |
545 |
DsrNodeStab ns (m_initStability); |
| 546 |
m_nodeCache[node] = ns; |
546 |
m_nodeCache[node] = ns; |
| 547 |
return false; |
547 |
return false; |
| 548 |
} |
548 |
} |
|
|
| 551 |
/// \todo remove it here |
551 |
/// \todo remove it here |
| 552 |
NS_LOG_INFO ("The stability here " << i->second.GetNodeStability ().GetSeconds ()); |
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 ()); |
553 |
NS_LOG_INFO ("The stability here " << Time (i->second.GetNodeStability () / m_stabilityDecrFactor).GetSeconds ()); |
| 554 |
NodeStab ns (Time (i->second.GetNodeStability () / m_stabilityDecrFactor)); |
554 |
DsrNodeStab ns (Time (i->second.GetNodeStability () / m_stabilityDecrFactor)); |
| 555 |
m_nodeCache[node] = ns; |
555 |
m_nodeCache[node] = ns; |
| 556 |
return true; |
556 |
return true; |
| 557 |
} |
557 |
} |
|
|
| 559 |
} |
559 |
} |
| 560 |
|
560 |
|
| 561 |
bool |
561 |
bool |
| 562 |
RouteCache::AddRoute_Link (RouteCacheEntry::IP_VECTOR nodelist, Ipv4Address source) |
562 |
DsrRouteCache::AddRoute_Link (DsrRouteCacheEntry::IP_VECTOR nodelist, Ipv4Address source) |
| 563 |
{ |
563 |
{ |
| 564 |
NS_LOG_FUNCTION (this << source); |
564 |
NS_LOG_FUNCTION (this << source); |
| 565 |
NS_LOG_LOGIC ("Use Link Cache"); |
565 |
NS_LOG_LOGIC ("Use Link Cache"); |
|
|
| 567 |
PurgeLinkNode (); |
567 |
PurgeLinkNode (); |
| 568 |
for (uint32_t i = 0; i < nodelist.size () - 1; i++) |
568 |
for (uint32_t i = 0; i < nodelist.size () - 1; i++) |
| 569 |
{ |
569 |
{ |
| 570 |
NodeStab ns; /// This is the node stability |
570 |
DsrNodeStab ns; /// This is the node stability |
| 571 |
ns.SetNodeStability (m_initStability); |
571 |
ns.SetNodeStability (m_initStability); |
| 572 |
|
572 |
|
| 573 |
if (m_nodeCache.find (nodelist[i]) == m_nodeCache.end ()) |
573 |
if (m_nodeCache.find (nodelist[i]) == m_nodeCache.end ()) |
|
|
| 579 |
m_nodeCache[nodelist[i + 1]] = ns; |
579 |
m_nodeCache[nodelist[i + 1]] = ns; |
| 580 |
} |
580 |
} |
| 581 |
Link link (nodelist[i], nodelist[i + 1]); /// Link represent the one link for the route |
581 |
Link link (nodelist[i], nodelist[i + 1]); /// Link represent the one link for the route |
| 582 |
LinkStab stab; /// Link stability |
582 |
DsrLinkStab stab; /// Link stability |
| 583 |
stab.SetLinkStability (m_initStability); |
583 |
stab.SetLinkStability (m_initStability); |
| 584 |
/// Set the link stability as the smallest node stability |
584 |
/// Set the link stability as the smallest node stability |
| 585 |
if (m_nodeCache[nodelist[i]].GetNodeStability () < m_nodeCache[nodelist[i + 1]].GetNodeStability ()) |
585 |
if (m_nodeCache[nodelist[i]].GetNodeStability () < m_nodeCache[nodelist[i + 1]].GetNodeStability ()) |
|
|
| 608 |
} |
608 |
} |
| 609 |
|
609 |
|
| 610 |
void |
610 |
void |
| 611 |
RouteCache::UseExtends (RouteCacheEntry::IP_VECTOR rt) |
611 |
DsrRouteCache::UseExtends (DsrRouteCacheEntry::IP_VECTOR rt) |
| 612 |
{ |
612 |
{ |
| 613 |
NS_LOG_FUNCTION (this); |
613 |
NS_LOG_FUNCTION (this); |
| 614 |
/// Purge the link node cache first |
614 |
/// Purge the link node cache first |
|
|
| 618 |
NS_LOG_INFO ("The route is too short"); |
618 |
NS_LOG_INFO ("The route is too short"); |
| 619 |
return; |
619 |
return; |
| 620 |
} |
620 |
} |
| 621 |
for (RouteCacheEntry::IP_VECTOR::iterator i = rt.begin (); i != rt.end () - 1; ++i) |
621 |
for (DsrRouteCacheEntry::IP_VECTOR::iterator i = rt.begin (); i != rt.end () - 1; ++i) |
| 622 |
{ |
622 |
{ |
| 623 |
Link link (*i, *(i + 1)); |
623 |
Link link (*i, *(i + 1)); |
| 624 |
if (m_linkCache.find (link) != m_linkCache.end ()) |
624 |
if (m_linkCache.find (link) != m_linkCache.end ()) |
|
|
| 636 |
} |
636 |
} |
| 637 |
} |
637 |
} |
| 638 |
/// Increase the stability of the node cache |
638 |
/// Increase the stability of the node cache |
| 639 |
for (RouteCacheEntry::IP_VECTOR::iterator i = rt.begin (); i != rt.end (); ++i) |
639 |
for (DsrRouteCacheEntry::IP_VECTOR::iterator i = rt.begin (); i != rt.end (); ++i) |
| 640 |
{ |
640 |
{ |
| 641 |
if (m_nodeCache.find (*i) != m_nodeCache.end ()) |
641 |
if (m_nodeCache.find (*i) != m_nodeCache.end ()) |
| 642 |
{ |
642 |
{ |
|
|
| 654 |
} |
654 |
} |
| 655 |
|
655 |
|
| 656 |
bool |
656 |
bool |
| 657 |
RouteCache::AddRoute (RouteCacheEntry & rt) |
657 |
DsrRouteCache::AddRoute (DsrRouteCacheEntry & rt) |
| 658 |
{ |
658 |
{ |
| 659 |
NS_LOG_FUNCTION (this); |
659 |
NS_LOG_FUNCTION (this); |
| 660 |
Purge (); |
660 |
Purge (); |
| 661 |
std::list<RouteCacheEntry> rtVector; // Declare the route cache entry vector |
661 |
std::list<DsrRouteCacheEntry> rtVector; // Declare the route cache entry vector |
| 662 |
Ipv4Address dst = rt.GetDestination (); |
662 |
Ipv4Address dst = rt.GetDestination (); |
| 663 |
std::vector<Ipv4Address> route = rt.GetVector (); |
663 |
std::vector<Ipv4Address> route = rt.GetVector (); |
| 664 |
|
664 |
|
| 665 |
NS_LOG_DEBUG ("The route destination we have " << dst); |
665 |
NS_LOG_DEBUG ("The route destination we have " << dst); |
| 666 |
std::map<Ipv4Address, std::list<RouteCacheEntry> >::const_iterator i = |
666 |
std::map<Ipv4Address, std::list<DsrRouteCacheEntry> >::const_iterator i = |
| 667 |
m_sortedRoutes.find (dst); |
667 |
m_sortedRoutes.find (dst); |
| 668 |
|
668 |
|
| 669 |
if (i == m_sortedRoutes.end ()) |
669 |
if (i == m_sortedRoutes.end ()) |
|
|
| 673 |
/** |
673 |
/** |
| 674 |
* Save the new route cache along with the destination address in map |
674 |
* Save the new route cache along with the destination address in map |
| 675 |
*/ |
675 |
*/ |
| 676 |
std::pair<std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator, bool> result = |
676 |
std::pair<std::map<Ipv4Address, std::list<DsrRouteCacheEntry> >::iterator, bool> result = |
| 677 |
m_sortedRoutes.insert (std::make_pair (dst, rtVector)); |
677 |
m_sortedRoutes.insert (std::make_pair (dst, rtVector)); |
| 678 |
return result.second; |
678 |
return result.second; |
| 679 |
} |
679 |
} |
|
|
| 711 |
/** |
711 |
/** |
| 712 |
* Save the new route cache along with the destination address in map |
712 |
* Save the new route cache along with the destination address in map |
| 713 |
*/ |
713 |
*/ |
| 714 |
std::pair<std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator, bool> result = |
714 |
std::pair<std::map<Ipv4Address, std::list<DsrRouteCacheEntry> >::iterator, bool> result = |
| 715 |
m_sortedRoutes.insert (std::make_pair (dst, rtVector)); |
715 |
m_sortedRoutes.insert (std::make_pair (dst, rtVector)); |
| 716 |
return result.second; |
716 |
return result.second; |
| 717 |
} |
717 |
} |
|
|
| 724 |
return false; |
724 |
return false; |
| 725 |
} |
725 |
} |
| 726 |
|
726 |
|
| 727 |
bool RouteCache::FindSameRoute (RouteCacheEntry & rt, std::list<RouteCacheEntry> & rtVector) |
727 |
bool DsrRouteCache::FindSameRoute (DsrRouteCacheEntry & rt, std::list<DsrRouteCacheEntry> & rtVector) |
| 728 |
{ |
728 |
{ |
| 729 |
NS_LOG_FUNCTION (this); |
729 |
NS_LOG_FUNCTION (this); |
| 730 |
for (std::list<RouteCacheEntry>::iterator i = rtVector.begin (); i != rtVector.end (); ++i) |
730 |
for (std::list<DsrRouteCacheEntry>::iterator i = rtVector.begin (); i != rtVector.end (); ++i) |
| 731 |
{ |
731 |
{ |
| 732 |
// return the first route in the route vector |
732 |
// return the first route in the route vector |
| 733 |
RouteCacheEntry::IP_VECTOR routeVector = i->GetVector (); |
733 |
DsrRouteCacheEntry::IP_VECTOR routeVector = i->GetVector (); |
| 734 |
RouteCacheEntry::IP_VECTOR newVector = rt.GetVector (); |
734 |
DsrRouteCacheEntry::IP_VECTOR newVector = rt.GetVector (); |
| 735 |
|
735 |
|
| 736 |
if (routeVector == newVector) |
736 |
if (routeVector == newVector) |
| 737 |
{ |
737 |
{ |
|
|
| 748 |
/* |
748 |
/* |
| 749 |
* Save the new route cache along with the destination address in map |
749 |
* Save the new route cache along with the destination address in map |
| 750 |
*/ |
750 |
*/ |
| 751 |
std::pair<std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator, bool> result = |
751 |
std::pair<std::map<Ipv4Address, std::list<DsrRouteCacheEntry> >::iterator, bool> result = |
| 752 |
m_sortedRoutes.insert (std::make_pair (rt.GetDestination (), rtVector)); |
752 |
m_sortedRoutes.insert (std::make_pair (rt.GetDestination (), rtVector)); |
| 753 |
return result.second; |
753 |
return result.second; |
| 754 |
} |
754 |
} |
|
|
| 757 |
} |
757 |
} |
| 758 |
|
758 |
|
| 759 |
bool |
759 |
bool |
| 760 |
RouteCache::DeleteRoute (Ipv4Address dst) |
760 |
DsrRouteCache::DeleteRoute (Ipv4Address dst) |
| 761 |
{ |
761 |
{ |
| 762 |
NS_LOG_FUNCTION (this << dst); |
762 |
NS_LOG_FUNCTION (this << dst); |
| 763 |
Purge (); // purge the route cache first to remove timeout entries |
763 |
Purge (); // purge the route cache first to remove timeout entries |
|
|
| 771 |
} |
771 |
} |
| 772 |
|
772 |
|
| 773 |
void |
773 |
void |
| 774 |
RouteCache::DeleteAllRoutesIncludeLink (Ipv4Address errorSrc, Ipv4Address unreachNode, Ipv4Address node) |
774 |
DsrRouteCache::DeleteAllRoutesIncludeLink (Ipv4Address errorSrc, Ipv4Address unreachNode, Ipv4Address node) |
| 775 |
{ |
775 |
{ |
| 776 |
NS_LOG_FUNCTION (this << errorSrc << unreachNode << node); |
776 |
NS_LOG_FUNCTION (this << errorSrc << unreachNode << node); |
| 777 |
if (IsLinkCache ()) |
777 |
if (IsLinkCache ()) |
|
|
| 792 |
m_linkCache.erase (link2); |
792 |
m_linkCache.erase (link2); |
| 793 |
NS_LOG_DEBUG ("The link cache size " << m_linkCache.size()); |
793 |
NS_LOG_DEBUG ("The link cache size " << m_linkCache.size()); |
| 794 |
|
794 |
|
| 795 |
std::map<Ipv4Address, NodeStab>::iterator i = m_nodeCache.find (errorSrc); |
795 |
std::map<Ipv4Address, DsrNodeStab>::iterator i = m_nodeCache.find (errorSrc); |
| 796 |
if (i == m_nodeCache.end ()) |
796 |
if (i == m_nodeCache.end ()) |
| 797 |
{ |
797 |
{ |
| 798 |
NS_LOG_LOGIC ("Update the node stability unsuccessfully"); |
798 |
NS_LOG_LOGIC ("Update the node stability unsuccessfully"); |
|
|
| 827 |
/* |
827 |
/* |
| 828 |
* Loop all the routes saved in the route cache |
828 |
* Loop all the routes saved in the route cache |
| 829 |
*/ |
829 |
*/ |
| 830 |
for (std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator j = |
830 |
for (std::map<Ipv4Address, std::list<DsrRouteCacheEntry> >::iterator j = |
| 831 |
m_sortedRoutes.begin (); j != m_sortedRoutes.end (); ) |
831 |
m_sortedRoutes.begin (); j != m_sortedRoutes.end (); ) |
| 832 |
{ |
832 |
{ |
| 833 |
std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator jtmp = j; |
833 |
std::map<Ipv4Address, std::list<DsrRouteCacheEntry> >::iterator jtmp = j; |
| 834 |
Ipv4Address address = j->first; |
834 |
Ipv4Address address = j->first; |
| 835 |
std::list<RouteCacheEntry> rtVector = j->second; |
835 |
std::list<DsrRouteCacheEntry> rtVector = j->second; |
| 836 |
/* |
836 |
/* |
| 837 |
* Loop all the routes for a single destination |
837 |
* Loop all the routes for a single destination |
| 838 |
*/ |
838 |
*/ |
| 839 |
for (std::list<RouteCacheEntry>::iterator k = rtVector.begin (); k != rtVector.end (); ) |
839 |
for (std::list<DsrRouteCacheEntry>::iterator k = rtVector.begin (); k != rtVector.end (); ) |
| 840 |
{ |
840 |
{ |
| 841 |
// return the first route in the route vector |
841 |
// return the first route in the route vector |
| 842 |
RouteCacheEntry::IP_VECTOR routeVector = k->GetVector (); |
842 |
DsrRouteCacheEntry::IP_VECTOR routeVector = k->GetVector (); |
| 843 |
RouteCacheEntry::IP_VECTOR changeVector; |
843 |
DsrRouteCacheEntry::IP_VECTOR changeVector; |
| 844 |
/* |
844 |
/* |
| 845 |
* Loop the ip addresses within a single route entry |
845 |
* Loop the ip addresses within a single route entry |
| 846 |
*/ |
846 |
*/ |
| 847 |
for (RouteCacheEntry::IP_VECTOR::iterator i = routeVector.begin (); i != routeVector.end (); ++i) |
847 |
for (DsrRouteCacheEntry::IP_VECTOR::iterator i = routeVector.begin (); i != routeVector.end (); ++i) |
| 848 |
{ |
848 |
{ |
| 849 |
if (*i != errorSrc) |
849 |
if (*i != errorSrc) |
| 850 |
{ |
850 |
{ |
|
|
| 881 |
* Remove the route first |
881 |
* Remove the route first |
| 882 |
*/ |
882 |
*/ |
| 883 |
k = rtVector.erase (k); |
883 |
k = rtVector.erase (k); |
| 884 |
RouteCacheEntry changeEntry; |
884 |
DsrRouteCacheEntry changeEntry; |
| 885 |
changeEntry.SetVector (changeVector); |
885 |
changeEntry.SetVector (changeVector); |
| 886 |
Ipv4Address destination = changeVector.back (); |
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 ()); |
887 |
NS_LOG_DEBUG ("The destination of the newly formed route " << destination << " and the size of the route " << changeVector.size ()); |
|
|
| 929 |
} |
929 |
} |
| 930 |
|
930 |
|
| 931 |
void |
931 |
void |
| 932 |
RouteCache::PrintVector (std::vector<Ipv4Address>& vec) |
932 |
DsrRouteCache::PrintVector (std::vector<Ipv4Address>& vec) |
| 933 |
{ |
933 |
{ |
| 934 |
NS_LOG_FUNCTION (this); |
934 |
NS_LOG_FUNCTION (this); |
| 935 |
/* |
935 |
/* |
|
|
| 950 |
} |
950 |
} |
| 951 |
|
951 |
|
| 952 |
void |
952 |
void |
| 953 |
RouteCache::PrintRouteVector (std::list<RouteCacheEntry> route) |
953 |
DsrRouteCache::PrintRouteVector (std::list<DsrRouteCacheEntry> route) |
| 954 |
{ |
954 |
{ |
| 955 |
NS_LOG_FUNCTION (this); |
955 |
NS_LOG_FUNCTION (this); |
| 956 |
for (std::list<RouteCacheEntry>::iterator i = route.begin (); i != route.end (); i++) |
956 |
for (std::list<DsrRouteCacheEntry>::iterator i = route.begin (); i != route.end (); i++) |
| 957 |
{ |
957 |
{ |
| 958 |
std::vector<Ipv4Address> path = i->GetVector (); |
958 |
std::vector<Ipv4Address> path = i->GetVector (); |
| 959 |
NS_LOG_INFO ("Route NO. "); |
959 |
NS_LOG_INFO ("Route NO. "); |
|
|
| 962 |
} |
962 |
} |
| 963 |
|
963 |
|
| 964 |
void |
964 |
void |
| 965 |
RouteCache::Purge () |
965 |
DsrRouteCache::Purge () |
| 966 |
{ |
966 |
{ |
| 967 |
NS_LOG_FUNCTION (this); |
967 |
NS_LOG_FUNCTION (this); |
| 968 |
//Trying to purge the route cache |
968 |
//Trying to purge the route cache |
|
|
| 971 |
NS_LOG_DEBUG ("The route cache is empty"); |
971 |
NS_LOG_DEBUG ("The route cache is empty"); |
| 972 |
return; |
972 |
return; |
| 973 |
} |
973 |
} |
| 974 |
for (std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator i = |
974 |
for (std::map<Ipv4Address, std::list<DsrRouteCacheEntry> >::iterator i = |
| 975 |
m_sortedRoutes.begin (); i != m_sortedRoutes.end (); ) |
975 |
m_sortedRoutes.begin (); i != m_sortedRoutes.end (); ) |
| 976 |
{ |
976 |
{ |
| 977 |
// Loop of route cache entry with the route size |
977 |
// Loop of route cache entry with the route size |
| 978 |
std::map<Ipv4Address, std::list<RouteCacheEntry> >::iterator itmp = i; |
978 |
std::map<Ipv4Address, std::list<DsrRouteCacheEntry> >::iterator itmp = i; |
| 979 |
/* |
979 |
/* |
| 980 |
* The route cache entry vector |
980 |
* The route cache entry vector |
| 981 |
*/ |
981 |
*/ |
| 982 |
Ipv4Address dst = i->first; |
982 |
Ipv4Address dst = i->first; |
| 983 |
std::list<RouteCacheEntry> rtVector = i->second; |
983 |
std::list<DsrRouteCacheEntry> rtVector = i->second; |
| 984 |
NS_LOG_DEBUG ("The route vector size of 1 " << dst << " " << rtVector.size ()); |
984 |
NS_LOG_DEBUG ("The route vector size of 1 " << dst << " " << rtVector.size ()); |
| 985 |
if (rtVector.size ()) |
985 |
if (rtVector.size ()) |
| 986 |
{ |
986 |
{ |
| 987 |
for (std::list<RouteCacheEntry>::iterator j = rtVector.begin (); j != rtVector.end (); ) |
987 |
for (std::list<DsrRouteCacheEntry>::iterator j = rtVector.begin (); j != rtVector.end (); ) |
| 988 |
{ |
988 |
{ |
| 989 |
NS_LOG_DEBUG ("The expire time of every entry with expire time " << j->GetExpireTime ()); |
989 |
NS_LOG_DEBUG ("The expire time of every entry with expire time " << j->GetExpireTime ()); |
| 990 |
/* |
990 |
/* |
|
|
| 1029 |
} |
1029 |
} |
| 1030 |
|
1030 |
|
| 1031 |
void |
1031 |
void |
| 1032 |
RouteCache::Print (std::ostream &os) |
1032 |
DsrRouteCache::Print (std::ostream &os) |
| 1033 |
{ |
1033 |
{ |
| 1034 |
NS_LOG_FUNCTION (this); |
1034 |
NS_LOG_FUNCTION (this); |
| 1035 |
Purge (); |
1035 |
Purge (); |
| 1036 |
os << "\nDSR Route Cache\n" |
1036 |
os << "\nDSR Route Cache\n" |
| 1037 |
<< "Destination\tGateway\t\tInterface\tFlag\tExpire\tHops\n"; |
1037 |
<< "Destination\tGateway\t\tInterface\tFlag\tExpire\tHops\n"; |
| 1038 |
for (std::list<RouteCacheEntry>::const_iterator i = |
1038 |
for (std::list<DsrRouteCacheEntry>::const_iterator i = |
| 1039 |
m_routeEntryVector.begin (); i != m_routeEntryVector.end (); ++i) |
1039 |
m_routeEntryVector.begin (); i != m_routeEntryVector.end (); ++i) |
| 1040 |
{ |
1040 |
{ |
| 1041 |
i->Print (os); |
1041 |
i->Print (os); |
|
|
| 1048 |
* This part of code maintains an Acknowledgment id cache for next hop and remove duplicate ids |
1048 |
* This part of code maintains an Acknowledgment id cache for next hop and remove duplicate ids |
| 1049 |
*/ |
1049 |
*/ |
| 1050 |
uint16_t |
1050 |
uint16_t |
| 1051 |
RouteCache::CheckUniqueAckId (Ipv4Address nextHop) |
1051 |
DsrRouteCache::CheckUniqueAckId (Ipv4Address nextHop) |
| 1052 |
{ |
1052 |
{ |
| 1053 |
NS_LOG_FUNCTION (this); |
1053 |
NS_LOG_FUNCTION (this); |
| 1054 |
std::map<Ipv4Address, uint16_t>::const_iterator i = |
1054 |
std::map<Ipv4Address, uint16_t>::const_iterator i = |
|
|
| 1070 |
} |
1070 |
} |
| 1071 |
|
1071 |
|
| 1072 |
uint16_t |
1072 |
uint16_t |
| 1073 |
RouteCache::GetAckSize () |
1073 |
DsrRouteCache::GetAckSize () |
| 1074 |
{ |
1074 |
{ |
| 1075 |
return m_ackIdCache.size (); |
1075 |
return m_ackIdCache.size (); |
| 1076 |
} |
1076 |
} |
|
|
| 1080 |
* This part maintains a neighbor list to handle unidirectional links and link-layer acks |
1080 |
* This part maintains a neighbor list to handle unidirectional links and link-layer acks |
| 1081 |
*/ |
1081 |
*/ |
| 1082 |
bool |
1082 |
bool |
| 1083 |
RouteCache::IsNeighbor (Ipv4Address addr) |
1083 |
DsrRouteCache::IsNeighbor (Ipv4Address addr) |
| 1084 |
{ |
1084 |
{ |
| 1085 |
NS_LOG_FUNCTION (this); |
1085 |
NS_LOG_FUNCTION (this); |
| 1086 |
PurgeMac (); // purge the mac cache |
1086 |
PurgeMac (); // purge the mac cache |
|
|
| 1096 |
} |
1096 |
} |
| 1097 |
|
1097 |
|
| 1098 |
Time |
1098 |
Time |
| 1099 |
RouteCache::GetExpireTime (Ipv4Address addr) |
1099 |
DsrRouteCache::GetExpireTime (Ipv4Address addr) |
| 1100 |
{ |
1100 |
{ |
| 1101 |
NS_LOG_FUNCTION (this); |
1101 |
NS_LOG_FUNCTION (this); |
| 1102 |
PurgeMac (); |
1102 |
PurgeMac (); |
|
|
| 1112 |
} |
1112 |
} |
| 1113 |
|
1113 |
|
| 1114 |
void |
1114 |
void |
| 1115 |
RouteCache::UpdateNeighbor (std::vector<Ipv4Address> nodeList, Time expire) |
1115 |
DsrRouteCache::UpdateNeighbor (std::vector<Ipv4Address> nodeList, Time expire) |
| 1116 |
{ |
1116 |
{ |
| 1117 |
NS_LOG_FUNCTION (this); |
1117 |
NS_LOG_FUNCTION (this); |
| 1118 |
for (std::vector<Neighbor>::iterator i = m_nb.begin (); i != m_nb.end (); ++i) |
1118 |
for (std::vector<Neighbor>::iterator i = m_nb.begin (); i != m_nb.end (); ++i) |
|
|
| 1140 |
} |
1140 |
} |
| 1141 |
|
1141 |
|
| 1142 |
void |
1142 |
void |
| 1143 |
RouteCache::AddNeighbor (std::vector<Ipv4Address> nodeList, Ipv4Address ownAddress, Time expire) |
1143 |
DsrRouteCache::AddNeighbor (std::vector<Ipv4Address> nodeList, Ipv4Address ownAddress, Time expire) |
| 1144 |
{ |
1144 |
{ |
| 1145 |
NS_LOG_LOGIC ("Add neighbor number " << nodeList.size ()); |
1145 |
NS_LOG_LOGIC ("Add neighbor number " << nodeList.size ()); |
| 1146 |
for (std::vector<Ipv4Address>::iterator j = nodeList.begin (); j != nodeList.end ();) |
1146 |
for (std::vector<Ipv4Address>::iterator j = nodeList.begin (); j != nodeList.end ();) |
|
|
| 1163 |
|
1163 |
|
| 1164 |
struct CloseNeighbor |
1164 |
struct CloseNeighbor |
| 1165 |
{ |
1165 |
{ |
| 1166 |
bool operator() (const RouteCache::Neighbor & nb) const |
1166 |
bool operator() (const DsrRouteCache::Neighbor & nb) const |
| 1167 |
{ |
1167 |
{ |
| 1168 |
return ((nb.m_expireTime < Simulator::Now ()) || nb.close); |
1168 |
return ((nb.m_expireTime < Simulator::Now ()) || nb.close); |
| 1169 |
} |
1169 |
} |
| 1170 |
}; |
1170 |
}; |
| 1171 |
|
1171 |
|
| 1172 |
void |
1172 |
void |
| 1173 |
RouteCache::PurgeMac () |
1173 |
DsrRouteCache::PurgeMac () |
| 1174 |
{ |
1174 |
{ |
| 1175 |
if (m_nb.empty ()) |
1175 |
if (m_nb.empty ()) |
| 1176 |
{ |
1176 |
{ |
|
|
| 1196 |
} |
1196 |
} |
| 1197 |
|
1197 |
|
| 1198 |
void |
1198 |
void |
| 1199 |
RouteCache::ScheduleTimer () |
1199 |
DsrRouteCache::ScheduleTimer () |
| 1200 |
{ |
1200 |
{ |
| 1201 |
m_ntimer.Cancel (); |
1201 |
m_ntimer.Cancel (); |
| 1202 |
m_ntimer.Schedule (); |
1202 |
m_ntimer.Schedule (); |
| 1203 |
} |
1203 |
} |
| 1204 |
|
1204 |
|
| 1205 |
void |
1205 |
void |
| 1206 |
RouteCache::AddArpCache (Ptr<ArpCache> a) |
1206 |
DsrRouteCache::AddArpCache (Ptr<ArpCache> a) |
| 1207 |
{ |
1207 |
{ |
| 1208 |
m_arp.push_back (a); |
1208 |
m_arp.push_back (a); |
| 1209 |
} |
1209 |
} |
| 1210 |
|
1210 |
|
| 1211 |
void |
1211 |
void |
| 1212 |
RouteCache::DelArpCache (Ptr<ArpCache> a) |
1212 |
DsrRouteCache::DelArpCache (Ptr<ArpCache> a) |
| 1213 |
{ |
1213 |
{ |
| 1214 |
m_arp.erase (std::remove (m_arp.begin (), m_arp.end (), a), m_arp.end ()); |
1214 |
m_arp.erase (std::remove (m_arp.begin (), m_arp.end (), a), m_arp.end ()); |
| 1215 |
} |
1215 |
} |
| 1216 |
|
1216 |
|
| 1217 |
Mac48Address |
1217 |
Mac48Address |
| 1218 |
RouteCache::LookupMacAddress (Ipv4Address addr) |
1218 |
DsrRouteCache::LookupMacAddress (Ipv4Address addr) |
| 1219 |
{ |
1219 |
{ |
| 1220 |
Mac48Address hwaddr; |
1220 |
Mac48Address hwaddr; |
| 1221 |
for (std::vector<Ptr<ArpCache> >::const_iterator i = m_arp.begin (); |
1221 |
for (std::vector<Ptr<ArpCache> >::const_iterator i = m_arp.begin (); |
|
|
| 1232 |
} |
1232 |
} |
| 1233 |
|
1233 |
|
| 1234 |
void |
1234 |
void |
| 1235 |
RouteCache::ProcessTxError (WifiMacHeader const & hdr) |
1235 |
DsrRouteCache::ProcessTxError (WifiMacHeader const & hdr) |
| 1236 |
{ |
1236 |
{ |
| 1237 |
Mac48Address addr = hdr.GetAddr1 (); |
1237 |
Mac48Address addr = hdr.GetAddr1 (); |
| 1238 |
|
1238 |
|