|
Lines 236-241
RoutingTable::DeleteRoute (Ipv4Address d
|
Link Here
|
|---|
|
| 236 |
{ |
236 |
{ |
| 237 |
NS_LOG_FUNCTION (this << dst); |
237 |
NS_LOG_FUNCTION (this << dst); |
| 238 |
Purge (); |
238 |
Purge (); |
|
|
239 |
// DeleteRoute called only when no route is found after a route request, deleted entry is never in VALID state |
| 240 |
RoutingTableEntry rt; |
| 241 |
NS_ASSERT (LookupValidRoute (dst, rt) == false); |
| 239 |
if (m_ipv4AddressEntry.erase (dst) != 0) |
242 |
if (m_ipv4AddressEntry.erase (dst) != 0) |
| 240 |
{ |
243 |
{ |
| 241 |
NS_LOG_LOGIC ("Route deletion to " << dst << " successful"); |
244 |
NS_LOG_LOGIC ("Route deletion to " << dst << " successful"); |
|
Lines 254-259
RoutingTable::AddRoute (RoutingTableEntr
|
Link Here
|
|---|
|
| 254 |
rt.SetRreqCnt (0); |
257 |
rt.SetRreqCnt (0); |
| 255 |
std::pair<std::map<Ipv4Address, RoutingTableEntry>::iterator, bool> result = |
258 |
std::pair<std::map<Ipv4Address, RoutingTableEntry>::iterator, bool> result = |
| 256 |
m_ipv4AddressEntry.insert (std::make_pair (rt.GetDestination (), rt)); |
259 |
m_ipv4AddressEntry.insert (std::make_pair (rt.GetDestination (), rt)); |
|
|
260 |
UpdateActiveRoutes (rt); |
| 257 |
return result.second; |
261 |
return result.second; |
| 258 |
} |
262 |
} |
| 259 |
|
263 |
|
|
Lines 268-273
RoutingTable::Update (RoutingTableEntry
|
Link Here
|
|---|
|
| 268 |
NS_LOG_LOGIC ("Route update to " << rt.GetDestination () << " fails; not found"); |
272 |
NS_LOG_LOGIC ("Route update to " << rt.GetDestination () << " fails; not found"); |
| 269 |
return false; |
273 |
return false; |
| 270 |
} |
274 |
} |
|
|
275 |
UpdateActiveRoutes (rt); |
| 271 |
i->second = rt; |
276 |
i->second = rt; |
| 272 |
if (i->second.GetFlag () != IN_SEARCH) |
277 |
if (i->second.GetFlag () != IN_SEARCH) |
| 273 |
{ |
278 |
{ |
|
Lines 290-295
RoutingTable::SetEntryState (Ipv4Address
|
Link Here
|
|---|
|
| 290 |
} |
295 |
} |
| 291 |
i->second.SetFlag (state); |
296 |
i->second.SetFlag (state); |
| 292 |
i->second.SetRreqCnt (0); |
297 |
i->second.SetRreqCnt (0); |
|
|
298 |
UpdateActiveRoutes (i->second); |
| 293 |
NS_LOG_LOGIC ("Route set entry state to " << id << ": new state is " << state); |
299 |
NS_LOG_LOGIC ("Route set entry state to " << id << ": new state is " << state); |
| 294 |
return true; |
300 |
return true; |
| 295 |
} |
301 |
} |
|
Lines 326-337
RoutingTable::InvalidateRoutesWithDst (c
|
Link Here
|
|---|
|
| 326 |
{ |
332 |
{ |
| 327 |
NS_LOG_LOGIC ("Invalidate route with destination address " << i->first); |
333 |
NS_LOG_LOGIC ("Invalidate route with destination address " << i->first); |
| 328 |
i->second.Invalidate (m_badLinkLifetime); |
334 |
i->second.Invalidate (m_badLinkLifetime); |
|
|
335 |
UpdateActiveRoutes (i->second); |
| 329 |
} |
336 |
} |
| 330 |
} |
337 |
} |
| 331 |
} |
338 |
} |
| 332 |
} |
339 |
} |
| 333 |
|
340 |
|
| 334 |
void |
341 |
void |
|
|
342 |
RoutingTable::UpdateActiveRoutes (RoutingTableEntry & rt) |
| 343 |
{ |
| 344 |
NS_LOG_FUNCTION (this); |
| 345 |
if ((rt.GetFlag () != VALID || rt.IsPrecursorListEmpty () == true) && m_activeRoutes.erase (rt.GetDestination ()) > 0 |
| 346 |
&& m_activeRoutes.empty () == true && m_narc.IsNull () == false) |
| 347 |
{ |
| 348 |
NS_LOG_LOGIC ("Calling not in active route callback"); |
| 349 |
m_narc (); |
| 350 |
} |
| 351 |
else if (rt.GetFlag () == VALID && rt.IsPrecursorListEmpty() == false && m_activeRoutes.insert (rt.GetDestination ()).second == true |
| 352 |
&& m_activeRoutes.size () == 1 && m_arc.IsNull () == false) |
| 353 |
{ |
| 354 |
NS_LOG_LOGIC ("Calling in active route callback"); |
| 355 |
m_arc (); |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
void |
| 335 |
RoutingTable::DeleteAllRoutesFromInterface (Ipv4InterfaceAddress iface) |
360 |
RoutingTable::DeleteAllRoutesFromInterface (Ipv4InterfaceAddress iface) |
| 336 |
{ |
361 |
{ |
| 337 |
NS_LOG_FUNCTION (this); |
362 |
NS_LOG_FUNCTION (this); |
|
Lines 372-410
RoutingTable::Purge ()
|
Link Here
|
|---|
|
| 372 |
{ |
397 |
{ |
| 373 |
NS_LOG_LOGIC ("Invalidate route with destination address " << i->first); |
398 |
NS_LOG_LOGIC ("Invalidate route with destination address " << i->first); |
| 374 |
i->second.Invalidate (m_badLinkLifetime); |
399 |
i->second.Invalidate (m_badLinkLifetime); |
| 375 |
++i; |
400 |
UpdateActiveRoutes (i->second); |
| 376 |
} |
|
|
| 377 |
else |
| 378 |
++i; |
| 379 |
} |
| 380 |
else |
| 381 |
{ |
| 382 |
++i; |
| 383 |
} |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
void |
| 388 |
RoutingTable::Purge (std::map<Ipv4Address, RoutingTableEntry> &table) const |
| 389 |
{ |
| 390 |
NS_LOG_FUNCTION (this); |
| 391 |
if (table.empty ()) |
| 392 |
return; |
| 393 |
for (std::map<Ipv4Address, RoutingTableEntry>::iterator i = |
| 394 |
table.begin (); i != table.end ();) |
| 395 |
{ |
| 396 |
if (i->second.GetLifeTime () < Seconds (0)) |
| 397 |
{ |
| 398 |
if (i->second.GetFlag () == INVALID) |
| 399 |
{ |
| 400 |
std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i; |
| 401 |
++i; |
| 402 |
table.erase (tmp); |
| 403 |
} |
| 404 |
else if (i->second.GetFlag () == VALID) |
| 405 |
{ |
| 406 |
NS_LOG_LOGIC ("Invalidate route with destination address " << i->first); |
| 407 |
i->second.Invalidate (m_badLinkLifetime); |
| 408 |
++i; |
401 |
++i; |
| 409 |
} |
402 |
} |
| 410 |
else |
403 |
else |
|
|
| 439 |
RoutingTable::Print (Ptr<OutputStreamWrapper> stream) const |
432 |
RoutingTable::Print (Ptr<OutputStreamWrapper> stream) const |
| 440 |
{ |
433 |
{ |
| 441 |
std::map<Ipv4Address, RoutingTableEntry> table = m_ipv4AddressEntry; |
434 |
std::map<Ipv4Address, RoutingTableEntry> table = m_ipv4AddressEntry; |
| 442 |
Purge (table); |
|
|
| 443 |
*stream->GetStream () << "\nAODV Routing table\n" |
435 |
*stream->GetStream () << "\nAODV Routing table\n" |
| 444 |
<< "Destination\tGateway\t\tInterface\tFlag\tExpire\t\tHops\n"; |
436 |
<< "Destination\tGateway\t\tInterface\tFlag\tExpire\t\tHops\n"; |
| 445 |
for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = |
437 |
for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = |