From c40e3aa9958a0694677a4ca22eb179d9caeb40e0 Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Thu, 20 Aug 2009 13:28:49 +0400 Subject: [PATCH] coding style + comments --- src/routing/aodv/aodv-rtable.cc | 258 +++++++++++++++++--------------- src/routing/aodv/aodv-rtable.h | 94 ++++++------ src/routing/aodv/id-cache.cc | 23 +-- src/routing/aodv/id-cache.h | 6 +- 4 files changed, 203 insertions(+), 178 deletions(-) diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc index 8353628f2..b8ccbdbac 100644 --- a/src/routing/aodv/aodv-rtable.cc +++ b/src/routing/aodv/aodv-rtable.cc @@ -42,10 +42,12 @@ namespace aodv The Routing Table */ -RoutingTableEntry::RoutingTableEntry (Ptr dev, Ipv4Address dst, bool vSeqNo, u_int32_t seqNo, Ipv4InterfaceAddress iface, u_int16_t hops, - Ipv4Address nextHop, Time lifetime ) : m_validSeqNo (vSeqNo), m_seqNo (seqNo), m_hops (hops), m_lifeTime (lifetime + Simulator::Now ()), - m_iface (iface), m_flag (VALID), m_reqCount (0), m_blackListState (false), m_blackListTimeout (Simulator::Now ()), - m_ackTimer (Timer::CANCEL_ON_DESTROY) +RoutingTableEntry::RoutingTableEntry (Ptr dev, Ipv4Address dst, bool vSeqNo, u_int32_t seqNo, + Ipv4InterfaceAddress iface, u_int16_t hops, Ipv4Address nextHop, Time lifetime) : + m_validSeqNo (vSeqNo), m_seqNo (seqNo), m_hops (hops), + m_lifeTime (lifetime + Simulator::Now ()), m_iface (iface), m_flag (VALID), + m_reqCount (0), m_blackListState (false), m_blackListTimeout (Simulator::Now ()), + m_ackTimer (Timer::CANCEL_ON_DESTROY) { m_ipv4Route = Create (); m_ipv4Route->SetDestination (dst); @@ -59,7 +61,7 @@ RoutingTableEntry::~RoutingTableEntry () } bool -RoutingTableEntry::InsertPrecursor (Ipv4Address id ) +RoutingTableEntry::InsertPrecursor (Ipv4Address id) { if (!LookupPrecursor (id)) { @@ -71,18 +73,20 @@ RoutingTableEntry::InsertPrecursor (Ipv4Address id ) } bool -RoutingTableEntry::LookupPrecursor (Ipv4Address id ) +RoutingTableEntry::LookupPrecursor (Ipv4Address id) { - for (std::vector::const_iterator i = m_precursorList.begin (); i != m_precursorList.end (); ++i) + for (std::vector::const_iterator i = m_precursorList.begin (); i + != m_precursorList.end (); ++i) if (*i == id) return true; return false; } bool -RoutingTableEntry::DeletePrecursor (Ipv4Address id ) +RoutingTableEntry::DeletePrecursor (Ipv4Address id) { - std::vector::iterator i = std::remove (m_precursorList.begin (), m_precursorList.end (), id); + std::vector::iterator i = std::remove (m_precursorList.begin (), + m_precursorList.end (), id); if (i == m_precursorList.end ()) return false; else @@ -94,7 +98,6 @@ void RoutingTableEntry::DeleteAllPrecursors () { m_precursorList.clear (); - NS_ASSERT(m_precursorList.empty ()); } bool @@ -104,14 +107,16 @@ RoutingTableEntry::IsPrecursorListEmpty () const } void -RoutingTableEntry::GetPrecursors (std::vector & prec ) const +RoutingTableEntry::GetPrecursors (std::vector & prec) const { if (IsPrecursorListEmpty ()) return; - for (std::vector::const_iterator i = m_precursorList.begin (); i != m_precursorList.end (); ++i) + for (std::vector::const_iterator i = m_precursorList.begin (); i + != m_precursorList.end (); ++i) { bool result = true; - for (std::vector::const_iterator j = prec.begin (); j != prec.end (); ++j) + for (std::vector::const_iterator j = prec.begin (); j + != prec.end (); ++j) if (*j == *i) result = false; if (result) @@ -120,7 +125,7 @@ RoutingTableEntry::GetPrecursors (std::vector & prec ) const } void -RoutingTableEntry::Invalidate (Time badLinkLifetime ) +RoutingTableEntry::Invalidate (Time badLinkLifetime) { if (m_flag == INVALID) return; @@ -130,9 +135,10 @@ RoutingTableEntry::Invalidate (Time badLinkLifetime ) } void -RoutingTableEntry::Print (std::ostream & os ) const +RoutingTableEntry::Print (std::ostream & os) const { - os << m_ipv4Route->GetDestination () << "\t" << m_ipv4Route->GetGateway () << "\t" << m_iface.GetLocal ()<< "\t"; + os << m_ipv4Route->GetDestination () << "\t" << m_ipv4Route->GetGateway () + << "\t" << m_iface.GetLocal () << "\t"; switch (m_flag) { case VALID: @@ -151,7 +157,8 @@ RoutingTableEntry::Print (std::ostream & os ) const break; } } - os << "\t" << (m_lifeTime - Simulator::Now ()).GetSeconds () << "\t" << m_hops <<"\n"; + os << "\t" << (m_lifeTime - Simulator::Now ()).GetSeconds () << "\t" + << m_hops << "\n"; } #ifdef RUN_SELF_TESTS @@ -175,69 +182,69 @@ AodvRtableEntryTest::RunTests () RoutingTableEntry rt (/*output device*/dev, /*dst*/Ipv4Address("1.2.3.4"), /*validSeqNo*/true, /*seqNo*/10, /*interface*/iface, /*hop*/5, /*next hop*/Ipv4Address("3.3.3.3"), /*lifetime*/Seconds(10)); NS_TEST_ASSERT_EQUAL (rt.GetOutputDevice (), dev); - NS_TEST_ASSERT_EQUAL (rt.GetDestination (), Ipv4Address("1.2.3.4")); + NS_TEST_ASSERT_EQUAL (rt.GetDestination (), Ipv4Address ("1.2.3.4")); NS_TEST_ASSERT_EQUAL (rt.GetValidSeqNo (), true); NS_TEST_ASSERT_EQUAL (rt.GetSeqNo (), 10); - NS_TEST_ASSERT_EQUAL (rt.GetInterface(), iface); - NS_TEST_ASSERT_EQUAL (rt.GetHop(), 5); + NS_TEST_ASSERT_EQUAL (rt.GetInterface (), iface); + NS_TEST_ASSERT_EQUAL (rt.GetHop (), 5); NS_TEST_ASSERT_EQUAL (rt.GetNextHop (), Ipv4Address ("3.3.3.3")); NS_TEST_ASSERT_EQUAL (rt.GetLifeTime (), Seconds (10)); NS_TEST_ASSERT_EQUAL (rt.GetFlag (), VALID); - NS_TEST_ASSERT_EQUAL (rt.GetRreqCnt(), 0); - NS_TEST_ASSERT_EQUAL (rt.IsPrecursorListEmpty(), true); + NS_TEST_ASSERT_EQUAL (rt.GetRreqCnt (), 0); + NS_TEST_ASSERT_EQUAL (rt.IsPrecursorListEmpty (), true); Ptr dev2; Ipv4InterfaceAddress iface2; - rt.SetOutputDevice(dev2); + rt.SetOutputDevice (dev2); NS_TEST_ASSERT_EQUAL (rt.GetOutputDevice (), dev2); - rt.SetInterface(iface2); - NS_TEST_ASSERT_EQUAL (rt.GetInterface(), iface2); - rt.SetValidSeqNo(false); + rt.SetInterface (iface2); + NS_TEST_ASSERT_EQUAL (rt.GetInterface (), iface2); + rt.SetValidSeqNo (false); NS_TEST_ASSERT_EQUAL (rt.GetValidSeqNo (), false); - rt.SetFlag(INVALID); + rt.SetFlag (INVALID); NS_TEST_ASSERT_EQUAL (rt.GetFlag (), INVALID); - rt.SetFlag(IN_SEARCH); + rt.SetFlag (IN_SEARCH); NS_TEST_ASSERT_EQUAL (rt.GetFlag (), IN_SEARCH); - rt.SetHop(12); + rt.SetHop (12); NS_TEST_ASSERT_EQUAL (rt.GetHop (), 12); - rt.SetLifeTime(Seconds(1)); - NS_TEST_ASSERT_EQUAL (rt.GetLifeTime (), Seconds(1)); - rt.SetNextHop(Ipv4Address("1.1.1.1")); + rt.SetLifeTime (Seconds (1)); + NS_TEST_ASSERT_EQUAL (rt.GetLifeTime (), Seconds (1)); + rt.SetNextHop (Ipv4Address ("1.1.1.1")); NS_TEST_ASSERT_EQUAL (rt.GetNextHop (), Ipv4Address ("1.1.1.1")); - rt.SetUnidirectional(true); + rt.SetUnidirectional (true); NS_TEST_ASSERT_EQUAL (rt.IsUnidirectional (), true); - rt.SetBalcklistTimeout (Seconds(7)); - NS_TEST_ASSERT_EQUAL (rt.GetBlacklistTimeout(), Seconds (7)); - rt.SetRreqCnt(2); - NS_TEST_ASSERT_EQUAL (rt.GetRreqCnt(), 2); - rt.IncrementRreqCnt(); - NS_TEST_ASSERT_EQUAL (rt.GetRreqCnt(), 3); - rt.Invalidate(Seconds(13)); + rt.SetBalcklistTimeout (Seconds (7)); + NS_TEST_ASSERT_EQUAL (rt.GetBlacklistTimeout (), Seconds (7)); + rt.SetRreqCnt (2); + NS_TEST_ASSERT_EQUAL (rt.GetRreqCnt (), 2); + rt.IncrementRreqCnt (); + NS_TEST_ASSERT_EQUAL (rt.GetRreqCnt (), 3); + rt.Invalidate (Seconds (13)); NS_TEST_ASSERT_EQUAL (rt.GetFlag (), INVALID); NS_TEST_ASSERT_EQUAL (rt.GetLifeTime (), Seconds (13)); - rt.SetLifeTime(Seconds(0.1)); + rt.SetLifeTime (Seconds (0.1)); NS_TEST_ASSERT_EQUAL (rt.GetLifeTime (), Seconds (0.1)); - Ptr route = rt.GetRoute(); - NS_TEST_ASSERT_EQUAL (route->GetDestination(), Ipv4Address("1.2.3.4")); + Ptr route = rt.GetRoute (); + NS_TEST_ASSERT_EQUAL (route->GetDestination (), Ipv4Address ("1.2.3.4")); - NS_TEST_ASSERT_EQUAL (rt.InsertPrecursor(Ipv4Address("10.0.0.1")), true); - NS_TEST_ASSERT_EQUAL (rt.IsPrecursorListEmpty(), false); - NS_TEST_ASSERT_EQUAL (rt.InsertPrecursor(Ipv4Address("10.0.0.2")), true); - NS_TEST_ASSERT_EQUAL (rt.InsertPrecursor(Ipv4Address("10.0.0.2")), false); - NS_TEST_ASSERT_EQUAL (rt.LookupPrecursor(Ipv4Address("10.0.0.3")), false); - NS_TEST_ASSERT_EQUAL (rt.LookupPrecursor(Ipv4Address("10.0.0.1")), true); - NS_TEST_ASSERT_EQUAL (rt.DeletePrecursor(Ipv4Address("10.0.0.2")), true); - NS_TEST_ASSERT_EQUAL (rt.LookupPrecursor(Ipv4Address("10.0.0.2")), false); + NS_TEST_ASSERT_EQUAL (rt.InsertPrecursor (Ipv4Address ("10.0.0.1")), true); + NS_TEST_ASSERT_EQUAL (rt.IsPrecursorListEmpty (), false); + NS_TEST_ASSERT_EQUAL (rt.InsertPrecursor (Ipv4Address ("10.0.0.2")), true); + NS_TEST_ASSERT_EQUAL (rt.InsertPrecursor (Ipv4Address ("10.0.0.2")), false); + NS_TEST_ASSERT_EQUAL (rt.LookupPrecursor (Ipv4Address ("10.0.0.3")), false); + NS_TEST_ASSERT_EQUAL (rt.LookupPrecursor (Ipv4Address ("10.0.0.1")), true); + NS_TEST_ASSERT_EQUAL (rt.DeletePrecursor (Ipv4Address ("10.0.0.2")), true); + NS_TEST_ASSERT_EQUAL (rt.LookupPrecursor (Ipv4Address ("10.0.0.2")), false); std::vector prec; - rt.GetPrecursors(prec); - NS_TEST_ASSERT_EQUAL (prec.size(), 1); - NS_TEST_ASSERT_EQUAL (rt.InsertPrecursor(Ipv4Address("10.0.0.4")), true); - NS_TEST_ASSERT_EQUAL (rt.DeletePrecursor(Ipv4Address("10.0.0.5")), false); - rt.GetPrecursors(prec); - NS_TEST_ASSERT_EQUAL (prec.size(), 2); - rt.DeleteAllPrecursors(); - NS_TEST_ASSERT_EQUAL (rt.IsPrecursorListEmpty(), true); - rt.GetPrecursors(prec); + rt.GetPrecursors (prec); + NS_TEST_ASSERT_EQUAL (prec.size (), 1); + NS_TEST_ASSERT_EQUAL (rt.InsertPrecursor (Ipv4Address ("10.0.0.4")), true); + NS_TEST_ASSERT_EQUAL (rt.DeletePrecursor (Ipv4Address ("10.0.0.5")), false); + rt.GetPrecursors (prec); + NS_TEST_ASSERT_EQUAL (prec.size (), 2); + rt.DeleteAllPrecursors (); + NS_TEST_ASSERT_EQUAL (rt.IsPrecursorListEmpty (), true); + rt.GetPrecursors (prec); NS_TEST_ASSERT_EQUAL (prec.size (), 2); return result; @@ -253,12 +260,13 @@ RoutingTable::RoutingTable (Time t) : m_badLinkLifetime (t) } bool -RoutingTable::LookupRoute (Ipv4Address id, RoutingTableEntry & rt ) +RoutingTable::LookupRoute (Ipv4Address id, RoutingTableEntry & rt) { Purge (); if (m_ipv4AddressEntry.empty ()) return false; - std::map::const_iterator i = m_ipv4AddressEntry.find (id); + std::map::const_iterator i = + m_ipv4AddressEntry.find (id); if (i == m_ipv4AddressEntry.end ()) return false; rt = i->second; @@ -266,7 +274,7 @@ RoutingTable::LookupRoute (Ipv4Address id, RoutingTableEntry & rt ) } bool -RoutingTable::DeleteRoute (Ipv4Address dst ) +RoutingTable::DeleteRoute (Ipv4Address dst) { Purge (); if (m_ipv4AddressEntry.erase (dst) != 0) @@ -275,18 +283,20 @@ RoutingTable::DeleteRoute (Ipv4Address dst ) } bool -RoutingTable::AddRoute (RoutingTableEntry & rt ) +RoutingTable::AddRoute (RoutingTableEntry & rt) { if (rt.GetFlag () != IN_SEARCH) rt.SetRreqCnt (0); - std::pair::iterator, bool> result = m_ipv4AddressEntry.insert (std::make_pair (rt.GetDestination (), rt)); + std::pair::iterator, bool> result = + m_ipv4AddressEntry.insert (std::make_pair (rt.GetDestination (), rt)); return result.second; } bool -RoutingTable::Update (RoutingTableEntry & rt ) +RoutingTable::Update (RoutingTableEntry & rt) { - std::map::iterator i = m_ipv4AddressEntry.find (rt.GetDestination ()); + std::map::iterator i = + m_ipv4AddressEntry.find (rt.GetDestination ()); if (i == m_ipv4AddressEntry.end ()) return false; i->second = rt; @@ -296,13 +306,14 @@ RoutingTable::Update (RoutingTableEntry & rt ) } bool -RoutingTable::SetEntryState (Ipv4Address id, RouteFlags state ) +RoutingTable::SetEntryState (Ipv4Address id, RouteFlags state) { - std::map::iterator i = m_ipv4AddressEntry.find (id); + std::map::iterator i = + m_ipv4AddressEntry.find (id); if (i == m_ipv4AddressEntry.end ()) return false; i->second.SetFlag (state); - i->second.SetRreqCnt(0); + i->second.SetRreqCnt (0); return true; } @@ -311,34 +322,38 @@ RoutingTable::GetListOfDestinationWithNextHop (Ipv4Address nextHop, std::map::const_iterator i = m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ++i) - if (i->second.GetNextHop () == nextHop) - { - unreachable.insert (std::make_pair (i->first, i->second.GetSeqNo ())); - } + for (std::map::const_iterator i = + m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ++i) + if (i->second.GetNextHop () == nextHop) + { + unreachable.insert (std::make_pair (i->first, i->second.GetSeqNo ())); + } } void -RoutingTable::InvalidateRoutesWithDst (const std::map & unreachable ) +RoutingTable::InvalidateRoutesWithDst (const std::map & unreachable) { Purge (); - for (std::map::iterator i = m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ++i) + for (std::map::iterator i = + m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ++i) { - for (std::map::const_iterator j = unreachable.begin (); j != unreachable.end (); ++j) + for (std::map::const_iterator j = + unreachable.begin (); j != unreachable.end (); ++j) if ((i->first == j->first) && (i->second.GetFlag () == VALID)) { - NS_LOG_LOGIC ("invalidate route with dst " << i->first); + NS_LOG_LOGIC ("Invalidate route with destination address " << i->first); i->second.Invalidate (m_badLinkLifetime); } } - } void RoutingTable::DeleteAllRoutesFromInterface (Ipv4InterfaceAddress iface) { - if (m_ipv4AddressEntry.empty ()) return; - for (std::map::iterator i = m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end ();) + if (m_ipv4AddressEntry.empty ()) + return; + for (std::map::iterator i = + m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end ();) { if (i->second.GetInterface () == iface) { @@ -346,7 +361,8 @@ RoutingTable::DeleteAllRoutesFromInterface (Ipv4InterfaceAddress iface) ++i; m_ipv4AddressEntry.erase (tmp); } - else ++i; + else + ++i; } } @@ -355,7 +371,8 @@ RoutingTable::Purge () { if (m_ipv4AddressEntry.empty ()) return; - for (std::map::iterator i = m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end ();) + for (std::map::iterator i = + m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end ();) { if (i->second.GetLifeTime () < Seconds (0)) { @@ -367,9 +384,8 @@ RoutingTable::Purge () } else if (i->second.GetFlag () == VALID) { - NS_LOG_LOGIC ("invalidate route with dst " << i->first ); + NS_LOG_LOGIC ("Invalidate route with destination address " << i->first); i->second.Invalidate (m_badLinkLifetime); - NS_LOG_LOGIC (Simulator::Now().GetSeconds()); ++i; } else @@ -380,23 +396,26 @@ RoutingTable::Purge () } bool -RoutingTable::MarkLinkAsUinidirectional (Ipv4Address neighbor, Time blacklistTimeout ) +RoutingTable::MarkLinkAsUinidirectional (Ipv4Address neighbor, Time blacklistTimeout) { - std::map::iterator i = m_ipv4AddressEntry.find (neighbor); + std::map::iterator i = + m_ipv4AddressEntry.find (neighbor); if (i == m_ipv4AddressEntry.end ()) return false; i->second.SetUnidirectional (true); i->second.SetBalcklistTimeout (blacklistTimeout); - i->second.SetRreqCnt(0); + i->second.SetRreqCnt (0); return true; } void -RoutingTable::Print (std::ostream &os ) +RoutingTable::Print (std::ostream &os) { Purge (); - os << "\nAODV Routing table\n" << "Destination\tGateway\t\tInterface\tFlag\tExpire\tHops\n"; - for (std::map::const_iterator i = m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ++i) + os << "\nAODV Routing table\n" + << "Destination\tGateway\t\tInterface\tFlag\tExpire\tHops\n"; + for (std::map::const_iterator i = + m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ++i) { i->second.Print (os); } @@ -419,10 +438,10 @@ static AodvRtableTest g_AodvRtableTest; bool AodvRtableTest::RunTests () { - RoutingTable rtable (Seconds(2)); - NS_TEST_ASSERT_EQUAL (rtable.GetBadLinkLifetime(), Seconds(2)); - rtable.SetBadLinkLifetime(Seconds(1)); - NS_TEST_ASSERT_EQUAL (rtable.GetBadLinkLifetime(), Seconds(1)); + RoutingTable rtable (Seconds (2)); + NS_TEST_ASSERT_EQUAL (rtable.GetBadLinkLifetime (), Seconds (2)); + rtable.SetBadLinkLifetime (Seconds (1)); + NS_TEST_ASSERT_EQUAL (rtable.GetBadLinkLifetime (), Seconds (1)); Ptr dev; Ipv4InterfaceAddress iface; RoutingTableEntry rt (/*output device*/dev, /*dst*/Ipv4Address("1.2.3.4"), /*validSeqNo*/true, /*seqNo*/10, @@ -432,37 +451,36 @@ AodvRtableTest::RunTests () RoutingTableEntry rt2 (/*output device*/dev, /*dst*/Ipv4Address("4.3.2.1"), /*validSeqNo*/false, /*seqNo*/0, /*interface*/iface, /*hop*/15, /*next hop*/Ipv4Address("1.1.1.1"), /*lifetime*/Seconds(1)); NS_TEST_ASSERT_EQUAL (rtable.AddRoute (rt2), true); - NS_TEST_ASSERT_EQUAL (rtable.LookupRoute(rt2.GetDestination(), rt), true); + NS_TEST_ASSERT_EQUAL (rtable.LookupRoute (rt2.GetDestination (), rt), true); NS_TEST_ASSERT_EQUAL (rt2.GetDestination (), rt.GetDestination ()); - rt.SetHop(20); - rt.InsertPrecursor(Ipv4Address("10.0.0.3")); + rt.SetHop (20); + rt.InsertPrecursor (Ipv4Address ("10.0.0.3")); NS_TEST_ASSERT_EQUAL (rtable.Update (rt), true); RoutingTableEntry rt3; - NS_TEST_ASSERT_EQUAL (rtable.LookupRoute(Ipv4Address("10.0.0.1"), rt), false); + NS_TEST_ASSERT_EQUAL (rtable.LookupRoute (Ipv4Address ("10.0.0.1"), rt), false); NS_TEST_ASSERT_EQUAL (rtable.Update (rt3), false); - NS_TEST_ASSERT_EQUAL (rtable.SetEntryState(Ipv4Address("10.0.0.1"), INVALID), false); - NS_TEST_ASSERT_EQUAL (rtable.SetEntryState(Ipv4Address("1.2.3.4"), IN_SEARCH), true); - NS_TEST_ASSERT_EQUAL (rtable.DeleteRoute(Ipv4Address("5.5.5.5")), false); - RoutingTableEntry rt4 (/*output device*/dev, /*dst*/Ipv4Address("5.5.5.5"), /*validSeqNo*/false, /*seqNo*/0, - /*interface*/iface, /*hop*/15, /*next hop*/Ipv4Address("1.1.1.1"), /*lifetime*/Seconds(-10)); + NS_TEST_ASSERT_EQUAL (rtable.SetEntryState (Ipv4Address ("10.0.0.1"), INVALID), false); + NS_TEST_ASSERT_EQUAL (rtable.SetEntryState (Ipv4Address ("1.2.3.4"), IN_SEARCH), true); + NS_TEST_ASSERT_EQUAL (rtable.DeleteRoute (Ipv4Address ("5.5.5.5")), false); + RoutingTableEntry rt4 (/*output device*/dev, /*dst*/Ipv4Address ("5.5.5.5"), /*validSeqNo*/false, /*seqNo*/0, + /*interface*/iface, /*hop*/15, /*next hop*/Ipv4Address ("1.1.1.1"), /*lifetime*/Seconds (-10)); NS_TEST_ASSERT_EQUAL (rtable.AddRoute (rt4), true); - NS_TEST_ASSERT_EQUAL (rtable.SetEntryState(Ipv4Address("5.5.5.5"), INVALID), true); - NS_TEST_ASSERT_EQUAL (rtable.LookupRoute(Ipv4Address("5.5.5.5"), rt), false); - - NS_TEST_ASSERT_EQUAL (rtable.MarkLinkAsUinidirectional(Ipv4Address("1.2.3.4"), Seconds(2)), true); - NS_TEST_ASSERT_EQUAL (rtable.LookupRoute(Ipv4Address("1.2.3.4"), rt), true); - NS_TEST_ASSERT_EQUAL (rt.IsUnidirectional(), true); - rt.SetLifeTime(Seconds(-5)); + NS_TEST_ASSERT_EQUAL (rtable.SetEntryState (Ipv4Address ("5.5.5.5"), INVALID), true); + NS_TEST_ASSERT_EQUAL (rtable.LookupRoute (Ipv4Address ("5.5.5.5"), rt), false); + NS_TEST_ASSERT_EQUAL (rtable.MarkLinkAsUinidirectional (Ipv4Address ("1.2.3.4"), Seconds (2)), true); + NS_TEST_ASSERT_EQUAL (rtable.LookupRoute (Ipv4Address ("1.2.3.4"), rt), true); + NS_TEST_ASSERT_EQUAL (rt.IsUnidirectional (), true); + rt.SetLifeTime (Seconds (-5)); NS_TEST_ASSERT_EQUAL (rtable.Update (rt), true); std::map unreachable; - rtable.GetListOfDestinationWithNextHop (Ipv4Address("1.1.1.1"), unreachable); - NS_TEST_ASSERT_EQUAL (unreachable.size (), 1); - unreachable.insert (std::make_pair(Ipv4Address("4.3.2.1"), 3)); - rtable.InvalidateRoutesWithDst(unreachable); - NS_TEST_ASSERT_EQUAL (rtable.LookupRoute(Ipv4Address("4.3.2.1"), rt), true); - NS_TEST_ASSERT_EQUAL (rt.GetFlag(), INVALID); - NS_TEST_ASSERT_EQUAL (rtable.DeleteRoute(Ipv4Address("1.2.3.4")), true); - NS_TEST_ASSERT_EQUAL (rtable.DeleteRoute(Ipv4Address("1.2.3.4")), false); + rtable.GetListOfDestinationWithNextHop (Ipv4Address ("1.1.1.1"), unreachable); + NS_TEST_ASSERT_EQUAL (unreachable.size (), 2); + unreachable.insert (std::make_pair (Ipv4Address ("4.3.2.1"), 3)); + rtable.InvalidateRoutesWithDst (unreachable); + NS_TEST_ASSERT_EQUAL (rtable.LookupRoute (Ipv4Address ("4.3.2.1"), rt), true); + NS_TEST_ASSERT_EQUAL (rt.GetFlag (), INVALID); + NS_TEST_ASSERT_EQUAL (rtable.DeleteRoute (Ipv4Address ("1.2.3.4")), true); + NS_TEST_ASSERT_EQUAL (rtable.DeleteRoute (Ipv4Address ("1.2.3.4")), false); return result; } diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h index fc2f96f51..a794bd6df 100644 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -59,11 +59,12 @@ enum RouteFlags class RoutingTableEntry { public: - RoutingTableEntry(Ptr dev = 0,Ipv4Address dst = Ipv4Address(), bool vSeqNo = false, u_int32_t m_seqNo = 0, - Ipv4InterfaceAddress iface = Ipv4InterfaceAddress(), u_int16_t hops = 0, - Ipv4Address nextHop = Ipv4Address(), Time lifetime = Simulator::Now()); + /// c-to + RoutingTableEntry (Ptr dev = 0,Ipv4Address dst = Ipv4Address(), bool vSeqNo = false, u_int32_t m_seqNo = 0, + Ipv4InterfaceAddress iface = Ipv4InterfaceAddress(), u_int16_t hops = 0, + Ipv4Address nextHop = Ipv4Address(), Time lifetime = Simulator::Now()); - ~RoutingTableEntry(); + ~RoutingTableEntry (); ///\name Precursors management //\{ @@ -72,70 +73,71 @@ public: * \param id precursor address * \return true on success */ - bool InsertPrecursor(Ipv4Address id); + bool InsertPrecursor (Ipv4Address id); /** * Lookup precursor by address * \param id precursor address * \return true on success */ - bool LookupPrecursor(Ipv4Address id); + bool LookupPrecursor (Ipv4Address id); /** * \brief Delete precursor * \param id precursor address * \return true on success */ - bool DeletePrecursor(Ipv4Address id); + bool DeletePrecursor (Ipv4Address id); /// Delete all precursors - void DeleteAllPrecursors(); + void DeleteAllPrecursors (); /** + * Check that precursor list empty * \return true if precursor list empty */ - bool IsPrecursorListEmpty() const; + bool IsPrecursorListEmpty () const; /** * Inserts precursors in vector prec if they does not yet exist in vector */ - void GetPrecursors(std::vector & prec) const; + void GetPrecursors (std::vector & prec) const; //\} /// Mark entry as "down" (i.e. disable it) void Invalidate (Time badLinkLifetime); ///\name Fields //\{ - Ipv4Address GetDestination() const { return m_ipv4Route->GetDestination(); } - Ptr GetRoute() const { return m_ipv4Route; } - void SetRoute(Ptr r) { m_ipv4Route = r; } + Ipv4Address GetDestination () const { return m_ipv4Route->GetDestination(); } + Ptr GetRoute () const { return m_ipv4Route; } + void SetRoute (Ptr r) { m_ipv4Route = r; } void SetNextHop (Ipv4Address nextHop) { m_ipv4Route->SetGateway(nextHop); } Ipv4Address GetNextHop () const { return m_ipv4Route->GetGateway(); } - void SetOutputDevice(Ptr dev) { m_ipv4Route->SetOutputDevice(dev); } - Ptr GetOutputDevice() const { return m_ipv4Route->GetOutputDevice(); } - Ipv4InterfaceAddress GetInterface() const { return m_iface;} + void SetOutputDevice (Ptr dev) { m_ipv4Route->SetOutputDevice(dev); } + Ptr GetOutputDevice () const { return m_ipv4Route->GetOutputDevice(); } + Ipv4InterfaceAddress GetInterface () const { return m_iface;} void SetInterface (Ipv4InterfaceAddress iface) { m_iface = iface; } - void SetValidSeqNo(bool s) { m_validSeqNo = s; } - bool GetValidSeqNo() const { return m_validSeqNo; } - void SetSeqNo(uint32_t sn) { m_seqNo = sn; } - uint32_t GetSeqNo() const { return m_seqNo; } - void SetHop(uint16_t hop) { m_hops = hop; } - uint16_t GetHop() const {return m_hops; } - void SetLifeTime(Time lt) { m_lifeTime = lt + Simulator::Now(); } - Time GetLifeTime() const { return m_lifeTime - Simulator::Now(); } - void SetFlag(RouteFlags flag) { m_flag = flag; } - RouteFlags GetFlag() const { return m_flag; } - void SetRreqCnt(uint8_t n) { m_reqCount = n; } - uint8_t GetRreqCnt() const { return m_reqCount; } - void IncrementRreqCnt() { m_reqCount++; } - void SetUnidirectional(bool u) { m_blackListState = u; } + void SetValidSeqNo (bool s) { m_validSeqNo = s; } + bool GetValidSeqNo () const { return m_validSeqNo; } + void SetSeqNo (uint32_t sn) { m_seqNo = sn; } + uint32_t GetSeqNo () const { return m_seqNo; } + void SetHop (uint16_t hop) { m_hops = hop; } + uint16_t GetHop () const {return m_hops; } + void SetLifeTime (Time lt) { m_lifeTime = lt + Simulator::Now(); } + Time GetLifeTime () const { return m_lifeTime - Simulator::Now(); } + void SetFlag (RouteFlags flag) { m_flag = flag; } + RouteFlags GetFlag () const { return m_flag; } + void SetRreqCnt (uint8_t n) { m_reqCount = n; } + uint8_t GetRreqCnt () const { return m_reqCount; } + void IncrementRreqCnt () { m_reqCount++; } + void SetUnidirectional (bool u) { m_blackListState = u; } bool IsUnidirectional () const { return m_blackListState; } void SetBalcklistTimeout (Time t) { m_blackListTimeout = t; } - Time GetBlacklistTimeout () { return m_blackListTimeout; } + Time GetBlacklistTimeout () const { return m_blackListTimeout; } //\} /** * \brief Compare destination address * \return true if equal */ - bool operator==(Ipv4Address const dst) const + bool operator== (Ipv4Address const dst) const { - return (m_ipv4Route->GetDestination() == dst); + return (m_ipv4Route->GetDestination () == dst); } void Print(std::ostream & os) const; @@ -162,7 +164,7 @@ private: Ptr m_ipv4Route; /// Output interface address Ipv4InterfaceAddress m_iface; - /// Routing flags: down, up or in repair + /// Routing flags: valid, invalid or in search RouteFlags m_flag; /// List of precursors @@ -173,6 +175,7 @@ private: uint8_t m_reqCount; /// Indicate if this entry is in "blacklist" bool m_blackListState; + /// Time for which the node is put into the blacklist Time m_blackListTimeout; public: /// RREP_ACK timer @@ -186,7 +189,8 @@ public: class RoutingTable { public: - RoutingTable(Time t); + /// c-tor + RoutingTable (Time t); ///\name Handle life time of invalid route //\{ Time GetBadLinkLifetime () const { return m_badLinkLifetime; } @@ -197,27 +201,25 @@ public: * \param r routing table entry * \return true in success */ - bool AddRoute(RoutingTableEntry & r); + bool AddRoute (RoutingTableEntry & r); /** - * Delete routing table entry + * Delete routing table entry with destination address dst, if it exists. * \param dst destination address * \return true on success */ - bool DeleteRoute(Ipv4Address dst); + bool DeleteRoute (Ipv4Address dst); /** - * Lookup routing table entry + * Lookup routing table entry with destination address dst * \param dst destination address * \param rt entry with destination address dst, if exists * \return true on success */ - bool LookupRoute(Ipv4Address dst, RoutingTableEntry & rt); + bool LookupRoute (Ipv4Address dst, RoutingTableEntry & rt); /// Update routing table - bool Update(RoutingTableEntry & rt); + bool Update (RoutingTableEntry & rt); /// Set routing table entry flags - bool SetEntryState (Ipv4Address dst, RouteFlags state /*TODO use enum*/); - /** - * Lookup valid routing entries with next hop Address dst and not empty list of precursors. - */ + bool SetEntryState (Ipv4Address dst, RouteFlags state); + /// Lookup routing entries with next hop Address dst and not empty list of precursors. void GetListOfDestinationWithNextHop (Ipv4Address nextHop, std::map & unreachable); /** * Update routing entries with this destinations as follows: @@ -229,6 +231,7 @@ public: void InvalidateRoutesWithDst (std::map const & unreachable); /// Delete all route from interface with address iface void DeleteAllRoutesFromInterface (Ipv4InterfaceAddress iface); + /// Delete all entries from routing table void Clear () { m_ipv4AddressEntry.clear (); } /// Delete all outdated entries and invalidate valid entry if Lifetime is expired void Purge (); @@ -242,6 +245,7 @@ public: private: std::map m_ipv4AddressEntry; + /// Deletion time for invalid routes Time m_badLinkLifetime; }; diff --git a/src/routing/aodv/id-cache.cc b/src/routing/aodv/id-cache.cc index c23058e03..9e4b84559 100644 --- a/src/routing/aodv/id-cache.cc +++ b/src/routing/aodv/id-cache.cc @@ -34,7 +34,7 @@ namespace ns3 namespace aodv { void -IdCache::InsertId (Ipv4Address addr, uint32_t id, Time saveTime ) +IdCache::InsertId (Ipv4Address addr, uint32_t id, Time saveTime) { if (LookupId (addr, id)) return; @@ -43,10 +43,11 @@ IdCache::InsertId (Ipv4Address addr, uint32_t id, Time saveTime ) m_idCache.push_back (uniqueId); } bool -IdCache::LookupId (Ipv4Address addr, uint32_t id ) +IdCache::LookupId (Ipv4Address addr, uint32_t id) { Purge (); - for (std::vector::const_iterator i = m_idCache.begin (); i != m_idCache.end (); ++i) + for (std::vector::const_iterator i = m_idCache.begin (); + i != m_idCache.end (); ++i) if (i->m_context == addr && i->m_id == id) return true; return false; @@ -54,7 +55,8 @@ IdCache::LookupId (Ipv4Address addr, uint32_t id ) void IdCache::Purge () { - m_idCache.erase (remove_if (m_idCache.begin (), m_idCache.end (), IsExpired ()), m_idCache.end ()); + m_idCache.erase (remove_if (m_idCache.begin (), m_idCache.end (), + IsExpired ()), m_idCache.end ()); } uint32_t @@ -68,7 +70,8 @@ IdCache::GetSize () /// Unit test for id cache struct IdCacheTest : public Test { - IdCacheTest () : Test ("AODV/IdCache"), result(true) {} + IdCacheTest () : Test ("AODV/IdCache"), result(true) + {} virtual bool RunTests(); void CheckTimeout1 (); void CheckTimeout2 (); @@ -84,14 +87,14 @@ static IdCacheTest g_IdCacheTest; bool IdCacheTest::RunTests () { - cache.InsertId(Ipv4Address ("1.2.3.4"), 3, Seconds(5)); + cache.InsertId (Ipv4Address ("1.2.3.4"), 3, Seconds(5)); NS_TEST_ASSERT_EQUAL (cache.LookupId (Ipv4Address ("1.2.3.4"), 4), false); NS_TEST_ASSERT_EQUAL (cache.LookupId (Ipv4Address ("4.3.2.1"), 3), false); NS_TEST_ASSERT_EQUAL (cache.LookupId (Ipv4Address ("1.2.3.4"), 3), true); - cache.InsertId(Ipv4Address ("1.1.1.1"), 4, Seconds(5)); - cache.InsertId(Ipv4Address ("1.1.1.1"), 4, Seconds(5)); - cache.InsertId(Ipv4Address ("2.2.2.2"), 5, Seconds(16)); - cache.InsertId(Ipv4Address ("3.3.3.3"), 6, Seconds(27)); + cache.InsertId (Ipv4Address ("1.1.1.1"), 4, Seconds(5)); + cache.InsertId (Ipv4Address ("1.1.1.1"), 4, Seconds(5)); + cache.InsertId (Ipv4Address ("2.2.2.2"), 5, Seconds(16)); + cache.InsertId (Ipv4Address ("3.3.3.3"), 6, Seconds(27)); NS_TEST_ASSERT_EQUAL (cache.GetSize (), 4); Simulator::Schedule (Seconds(1), &IdCacheTest::CheckTimeout1, this); diff --git a/src/routing/aodv/id-cache.h b/src/routing/aodv/id-cache.h index f9fc8a34c..9fd9957a6 100644 --- a/src/routing/aodv/id-cache.h +++ b/src/routing/aodv/id-cache.h @@ -55,7 +55,8 @@ public: /// Remove all expired entries void Purge (); /// Return number of entries in cache - uint32_t GetSize (); + uint32_t + GetSize (); private: struct UniqueId { @@ -65,8 +66,7 @@ private: }; struct IsExpired { - bool - operator() (const struct UniqueId & u ) const + bool operator() (const struct UniqueId & u) const { return (u.m_expire < Simulator::Now ()); }