From bfab5891bb91a4ab8ab0ac05cfab677928774ebe Mon Sep 17 00:00:00 2001 From: Anna Poon Date: Tue, 1 Sep 2020 08:45:04 -0700 Subject: [PATCH] aodv: Update NS_LOG print format for ns3::Time Also fixed issue in which AodvRoutingProtocol::PrintRoutingTable () was not using the provided Time::Unit to format the routing table entry lifetimes. --- src/aodv/model/aodv-routing-protocol.cc | 12 ++++++------ src/aodv/model/aodv-rtable.cc | 12 ++++++------ src/aodv/model/aodv-rtable.h | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/aodv/model/aodv-routing-protocol.cc b/src/aodv/model/aodv-routing-protocol.cc index 85c8b598f..ef252b4b6 100644 --- a/src/aodv/model/aodv-routing-protocol.cc +++ b/src/aodv/model/aodv-routing-protocol.cc @@ -343,7 +343,7 @@ RoutingProtocol::PrintRoutingTable (Ptr stream, Time::Unit << ", Local time: " << GetObject ()->GetLocalTime ().As (unit) << ", AODV Routing table" << std::endl; - m_routingTable.Print (stream); + m_routingTable.Print (stream, unit); *stream->GetStream () << std::endl; } @@ -1106,7 +1106,7 @@ RoutingProtocol::ScheduleRreqRetry (Ipv4Address dst) retry = m_netTraversalTime * (1 << backoffFactor); } m_addressReqTimer[dst].Schedule (retry); - NS_LOG_LOGIC ("Scheduled RREQ retry in " << retry.GetSeconds () << " seconds"); + NS_LOG_LOGIC ("Scheduled RREQ retry in " << retry.As (Time::S)); } void @@ -1959,8 +1959,8 @@ RoutingProtocol::SendRerrWhenNoRouteToForward (Ipv4Address dst, // Just make sure that the RerrRateLimit timer is running and will expire NS_ASSERT (m_rerrRateLimitTimer.IsRunning ()); // discard the packet and return - NS_LOG_LOGIC ("RerrRateLimit reached at " << Simulator::Now ().GetSeconds () << " with timer delay left " - << m_rerrRateLimitTimer.GetDelayLeft ().GetSeconds () + NS_LOG_LOGIC ("RerrRateLimit reached at " << Simulator::Now ().As (Time::S) << " with timer delay left " + << m_rerrRateLimitTimer.GetDelayLeft ().As (Time::S) << "; suppressing RERR"); return; } @@ -2021,8 +2021,8 @@ RoutingProtocol::SendRerrMessage (Ptr packet, std::vector p // Just make sure that the RerrRateLimit timer is running and will expire NS_ASSERT (m_rerrRateLimitTimer.IsRunning ()); // discard the packet and return - NS_LOG_LOGIC ("RerrRateLimit reached at " << Simulator::Now ().GetSeconds () << " with timer delay left " - << m_rerrRateLimitTimer.GetDelayLeft ().GetSeconds () + NS_LOG_LOGIC ("RerrRateLimit reached at " << Simulator::Now ().As (Time::S) << " with timer delay left " + << m_rerrRateLimitTimer.GetDelayLeft ().As (Time::S) << "; suppressing RERR"); return; } diff --git a/src/aodv/model/aodv-rtable.cc b/src/aodv/model/aodv-rtable.cc index 51b1c0351..bc8ed1d18 100644 --- a/src/aodv/model/aodv-rtable.cc +++ b/src/aodv/model/aodv-rtable.cc @@ -160,7 +160,7 @@ RoutingTableEntry::GetPrecursors (std::vector & prec) const void RoutingTableEntry::Invalidate (Time badLinkLifetime) { - NS_LOG_FUNCTION (this << badLinkLifetime.GetSeconds ()); + NS_LOG_FUNCTION (this << badLinkLifetime.As (Time::S)); if (m_flag == INVALID) { return; @@ -171,7 +171,7 @@ RoutingTableEntry::Invalidate (Time badLinkLifetime) } void -RoutingTableEntry::Print (Ptr stream) const +RoutingTableEntry::Print (Ptr stream, Time::Unit unit /* = Time::S */) const { std::ostream* os = stream->GetStream (); *os << m_ipv4Route->GetDestination () << "\t" << m_ipv4Route->GetGateway () @@ -197,7 +197,7 @@ RoutingTableEntry::Print (Ptr stream) const *os << "\t"; *os << std::setiosflags (std::ios::fixed) << std::setiosflags (std::ios::left) << std::setprecision (2) << - std::setw (14) << (m_lifeTime - Simulator::Now ()).GetSeconds (); + std::setw (14) << (m_lifeTime - Simulator::Now ()).As (unit); *os << "\t" << m_hops << "\n"; } @@ -448,7 +448,7 @@ RoutingTable::Purge (std::map &table) const bool RoutingTable::MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout) { - NS_LOG_FUNCTION (this << neighbor << blacklistTimeout.GetSeconds ()); + NS_LOG_FUNCTION (this << neighbor << blacklistTimeout.As (Time::S)); std::map::iterator i = m_ipv4AddressEntry.find (neighbor); if (i == m_ipv4AddressEntry.end ()) @@ -464,7 +464,7 @@ RoutingTable::MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTime } void -RoutingTable::Print (Ptr stream) const +RoutingTable::Print (Ptr stream, Time::Unit unit /* = Time::S */) const { std::map table = m_ipv4AddressEntry; Purge (table); @@ -473,7 +473,7 @@ RoutingTable::Print (Ptr stream) const for (std::map::const_iterator i = table.begin (); i != table.end (); ++i) { - i->second.Print (stream); + i->second.Print (stream, unit); } *stream->GetStream () << "\n"; } diff --git a/src/aodv/model/aodv-rtable.h b/src/aodv/model/aodv-rtable.h index b70e30e8a..5b2587595 100644 --- a/src/aodv/model/aodv-rtable.h +++ b/src/aodv/model/aodv-rtable.h @@ -341,7 +341,7 @@ public: * Print packet to trace file * \param stream The output stream */ - void Print (Ptr stream) const; + void Print (Ptr stream, Time::Unit unit = Time::S) const; private: /// Valid Destination Sequence Number flag @@ -481,7 +481,7 @@ public: * Print routing table * \param stream the output stream */ - void Print (Ptr stream) const; + void Print (Ptr stream, Time::Unit unit = Time::S) const; private: /// The routing table