diff --git a/src/routing/aodv/aodv-routing-protocol.cc b/src/routing/aodv/aodv-routing-protocol.cc index fc54cce29..2ad88e9f0 100644 --- a/src/routing/aodv/aodv-routing-protocol.cc +++ b/src/routing/aodv/aodv-routing-protocol.cc @@ -25,6 +25,9 @@ * Authors: Elena Buchatskaia * Pavel Boyko */ +#define NS_LOG_APPEND_CONTEXT \ + if (m_ipv4) { std::clog << "[node " << m_ipv4->GetObject ()->GetId () << "] "; } + #include "aodv-routing-protocol.h" #include "ns3/log.h" #include "ns3/boolean.h" diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc index 3bec99e30..37f9c2d3c 100644 --- a/src/routing/aodv/aodv-rtable.cc +++ b/src/routing/aodv/aodv-rtable.cc @@ -25,6 +25,7 @@ * Authors: Elena Buchatskaia * Pavel Boyko */ + #include "aodv-rtable.h" #include #include "ns3/simulator.h" @@ -62,6 +63,7 @@ RoutingTableEntry::~RoutingTableEntry () bool RoutingTableEntry::InsertPrecursor (Ipv4Address id) { + NS_LOG_FUNCTION (this << id); if (!LookupPrecursor (id)) { m_precursorList.push_back (id); @@ -74,30 +76,43 @@ RoutingTableEntry::InsertPrecursor (Ipv4Address id) bool RoutingTableEntry::LookupPrecursor (Ipv4Address id) { + NS_LOG_FUNCTION (this << id); for (std::vector::const_iterator i = m_precursorList.begin (); i != m_precursorList.end (); ++i) { if (*i == id) - return true; + { + NS_LOG_LOGIC ("Precursor " << id << " found"); + return true; + } } + NS_LOG_LOGIC ("Precursor " << id << " not found"); return false; } bool RoutingTableEntry::DeletePrecursor (Ipv4Address id) { + NS_LOG_FUNCTION (this << id); std::vector::iterator i = std::remove (m_precursorList.begin (), m_precursorList.end (), id); if (i == m_precursorList.end ()) - return false; + { + NS_LOG_LOGIC ("Precursor " << id << " not found"); + return false; + } else - m_precursorList.erase (i, m_precursorList.end ()); + { + NS_LOG_LOGIC ("Precursor " << id << " found"); + m_precursorList.erase (i, m_precursorList.end ()); + } return true; } void RoutingTableEntry::DeleteAllPrecursors () { + NS_LOG_FUNCTION (this); m_precursorList.clear (); } @@ -110,6 +125,7 @@ RoutingTableEntry::IsPrecursorListEmpty () const void RoutingTableEntry::GetPrecursors (std::vector & prec) const { + NS_LOG_FUNCTION (this); if (IsPrecursorListEmpty ()) return; for (std::vector::const_iterator i = m_precursorList.begin (); i @@ -130,6 +146,7 @@ RoutingTableEntry::GetPrecursors (std::vector & prec) const void RoutingTableEntry::Invalidate (Time badLinkLifetime) { + NS_LOG_FUNCTION (this << badLinkLifetime.GetSeconds ()); if (m_flag == INVALID) return; m_flag = INVALID; @@ -176,37 +193,57 @@ RoutingTable::RoutingTable (Time t) : bool RoutingTable::LookupRoute (Ipv4Address id, RoutingTableEntry & rt) { + NS_LOG_FUNCTION (this << id); Purge (); if (m_ipv4AddressEntry.empty ()) - return false; + { + NS_LOG_LOGIC ("Route to " << id << " not found; m_ipv4AddressEntry is empty"); + return false; + } std::map::const_iterator i = m_ipv4AddressEntry.find (id); if (i == m_ipv4AddressEntry.end ()) - return false; + { + NS_LOG_LOGIC ("Route to " << id << " not found"); + return false; + } rt = i->second; + NS_LOG_LOGIC ("Route to " << id << " found"); return true; } bool RoutingTable::LookupValidRoute (Ipv4Address id, RoutingTableEntry & rt) { + NS_LOG_FUNCTION (this << id); if (! LookupRoute (id, rt)) - return false; + { + NS_LOG_LOGIC ("Route to " << id << " not found"); + return false; + } + NS_LOG_LOGIC ("Route to " << id << " flag is " << ((rt.GetFlag () == VALID) ? "valid" : "not valid")); return (rt.GetFlag () == VALID); } bool RoutingTable::DeleteRoute (Ipv4Address dst) { + NS_LOG_FUNCTION (this << dst); Purge (); if (m_ipv4AddressEntry.erase (dst) != 0) - return true; + { + NS_LOG_LOGIC ("Route deletion to " << dst << " successful"); + return true; + } + NS_LOG_LOGIC ("Route deletion to " << dst << " not successful"); return false; } bool RoutingTable::AddRoute (RoutingTableEntry & rt) { + NS_LOG_FUNCTION (this); + Purge (); if (rt.GetFlag () != IN_SEARCH) rt.SetRreqCnt (0); std::pair::iterator, bool> result = @@ -217,31 +254,44 @@ RoutingTable::AddRoute (RoutingTableEntry & rt) bool RoutingTable::Update (RoutingTableEntry & rt) { + NS_LOG_FUNCTION (this); std::map::iterator i = m_ipv4AddressEntry.find (rt.GetDestination ()); if (i == m_ipv4AddressEntry.end ()) - return false; + { + NS_LOG_LOGIC ("Route update to " << rt.GetDestination () << " fails; not found"); + return false; + } i->second = rt; if (i->second.GetFlag () != IN_SEARCH) - i->second.SetRreqCnt (0); + { + NS_LOG_LOGIC ("Route update to " << rt.GetDestination () << " set RreqCnt to 0"); + i->second.SetRreqCnt (0); + } return true; } bool RoutingTable::SetEntryState (Ipv4Address id, RouteFlags state) { + NS_LOG_FUNCTION (this); std::map::iterator i = m_ipv4AddressEntry.find (id); if (i == m_ipv4AddressEntry.end ()) - return false; + { + NS_LOG_LOGIC ("Route set entry state to " << id << " fails; not found"); + return false; + } i->second.SetFlag (state); i->second.SetRreqCnt (0); + NS_LOG_LOGIC ("Route set entry state to " << id << ": new state is " << state); return true; } void RoutingTable::GetListOfDestinationWithNextHop (Ipv4Address nextHop, std::map & unreachable ) { + NS_LOG_FUNCTION (this); Purge (); unreachable.clear (); for (std::map::const_iterator i = @@ -249,6 +299,7 @@ RoutingTable::GetListOfDestinationWithNextHop (Ipv4Address nextHop, std::mapsecond.GetNextHop () == nextHop) { + NS_LOG_LOGIC ("Unreachable insert " << i->first << " " << i->second.GetSeqNo ()); unreachable.insert (std::make_pair (i->first, i->second.GetSeqNo ())); } } @@ -257,6 +308,7 @@ RoutingTable::GetListOfDestinationWithNextHop (Ipv4Address nextHop, std::map & unreachable) { + NS_LOG_FUNCTION (this); Purge (); for (std::map::iterator i = m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ++i) @@ -276,6 +328,7 @@ RoutingTable::InvalidateRoutesWithDst (const std::map & u void RoutingTable::DeleteAllRoutesFromInterface (Ipv4InterfaceAddress iface) { + NS_LOG_FUNCTION (this); if (m_ipv4AddressEntry.empty ()) return; for (std::map::iterator i = @@ -295,6 +348,7 @@ RoutingTable::DeleteAllRoutesFromInterface (Ipv4InterfaceAddress iface) void RoutingTable::Purge () { + NS_LOG_FUNCTION (this); if (m_ipv4AddressEntry.empty ()) return; for (std::map::iterator i = @@ -327,13 +381,18 @@ RoutingTable::Purge () bool RoutingTable::MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout) { + NS_LOG_FUNCTION (this << neighbor << blacklistTimeout.GetSeconds ()); std::map::iterator i = m_ipv4AddressEntry.find (neighbor); if (i == m_ipv4AddressEntry.end ()) - return false; + { + NS_LOG_LOGIC ("Mark link unidirectional to " << neighbor << " fails; not found"); + return false; + } i->second.SetUnidirectional (true); i->second.SetBalcklistTimeout (blacklistTimeout); i->second.SetRreqCnt (0); + NS_LOG_LOGIC ("Set link to " << neighbor << " to unidirectional"); return true; }