From d795a4bb47c3e2e545b1dc113cbaf0c557b364d4 Mon Sep 17 00:00:00 2001 From: Robert Ammon Date: Thu, 11 May 2017 11:10:25 -0700 Subject: [PATCH] aodv: Fix various coding style issues --- src/aodv/model/aodv-dpd.cc | 6 +- src/aodv/model/aodv-id-cache.cc | 18 +- src/aodv/model/aodv-neighbor.cc | 62 ++-- src/aodv/model/aodv-packet.cc | 128 +++++--- src/aodv/model/aodv-routing-protocol.cc | 414 ++++++++++++++---------- src/aodv/model/aodv-rqueue.cc | 31 +- src/aodv/model/aodv-rtable.cc | 90 ++++-- 7 files changed, 454 insertions(+), 295 deletions(-) diff --git a/src/aodv/model/aodv-dpd.cc b/src/aodv/model/aodv-dpd.cc index 73ca2c071..9350533d4 100644 --- a/src/aodv/model/aodv-dpd.cc +++ b/src/aodv/model/aodv-dpd.cc @@ -22,10 +22,8 @@ #include "aodv-dpd.h" -namespace ns3 -{ -namespace aodv -{ +namespace ns3 { +namespace aodv { bool DuplicatePacketDetection::IsDuplicate (Ptr p, const Ipv4Header & header) diff --git a/src/aodv/model/aodv-id-cache.cc b/src/aodv/model/aodv-id-cache.cc index fae34e976..bc7135f6b 100644 --- a/src/aodv/model/aodv-id-cache.cc +++ b/src/aodv/model/aodv-id-cache.cc @@ -28,20 +28,24 @@ #include "aodv-id-cache.h" #include -namespace ns3 -{ -namespace aodv -{ +namespace ns3 { +namespace aodv { bool IdCache::IsDuplicate (Ipv4Address addr, uint32_t id) { Purge (); 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; + { + if (i->m_context == addr && i->m_id == id) + { + return true; + } + } struct UniqueId uniqueId = - { addr, id, m_lifetime + Simulator::Now () }; + { + addr, id, m_lifetime + Simulator::Now () + }; m_idCache.push_back (uniqueId); return false; } diff --git a/src/aodv/model/aodv-neighbor.cc b/src/aodv/model/aodv-neighbor.cc index 090d59647..0f894fb6c 100644 --- a/src/aodv/model/aodv-neighbor.cc +++ b/src/aodv/model/aodv-neighbor.cc @@ -31,15 +31,13 @@ #include -namespace ns3 -{ - +namespace ns3 { + NS_LOG_COMPONENT_DEFINE ("AodvNeighbors"); -namespace aodv -{ -Neighbors::Neighbors (Time delay) : - m_ntimer (Timer::CANCEL_ON_DESTROY) +namespace aodv { +Neighbors::Neighbors (Time delay) + : m_ntimer (Timer::CANCEL_ON_DESTROY) { m_ntimer.SetDelay (delay); m_ntimer.SetFunction (&Neighbors::Purge, this); @@ -54,7 +52,9 @@ Neighbors::IsNeighbor (Ipv4Address addr) i != m_nb.end (); ++i) { if (i->m_neighborAddress == addr) - return true; + { + return true; + } } return false; } @@ -67,7 +67,9 @@ Neighbors::GetExpireTime (Ipv4Address addr) != m_nb.end (); ++i) { if (i->m_neighborAddress == addr) - return (i->m_expireTime - Simulator::Now ()); + { + return (i->m_expireTime - Simulator::Now ()); + } } return Seconds (0); } @@ -76,14 +78,18 @@ void Neighbors::Update (Ipv4Address addr, Time expire) { for (std::vector::iterator i = m_nb.begin (); i != m_nb.end (); ++i) - if (i->m_neighborAddress == addr) - { - i->m_expireTime - = std::max (expire + Simulator::Now (), i->m_expireTime); - if (i->m_hardwareAddress == Mac48Address ()) - i->m_hardwareAddress = LookupMacAddress (i->m_neighborAddress); - return; - } + { + if (i->m_neighborAddress == addr) + { + i->m_expireTime + = std::max (expire + Simulator::Now (), i->m_expireTime); + if (i->m_hardwareAddress == Mac48Address ()) + { + i->m_hardwareAddress = LookupMacAddress (i->m_neighborAddress); + } + return; + } + } NS_LOG_LOGIC ("Open link to " << addr); Neighbor neighbor (addr, LookupMacAddress (addr), expire + Simulator::Now ()); @@ -91,8 +97,17 @@ Neighbors::Update (Ipv4Address addr, Time expire) Purge (); } +/** + * \brief CloseNeighbor structure + */ struct CloseNeighbor { + /** + * Check if the entry is expired + * + * \param nb Neighbors::Neighbor entry + * \return true if expired, false otherwise + */ bool operator() (const Neighbors::Neighbor & nb) const { return ((nb.m_expireTime < Simulator::Now ()) || nb.close); @@ -103,7 +118,9 @@ void Neighbors::Purge () { if (m_nb.empty ()) - return; + { + return; + } CloseNeighbor pred; if (!m_handleLinkFailure.IsNull ()) @@ -166,10 +183,13 @@ Neighbors::ProcessTxError (WifiMacHeader const & hdr) for (std::vector::iterator i = m_nb.begin (); i != m_nb.end (); ++i) { if (i->m_hardwareAddress == addr) - i->close = true; + { + i->close = true; + } } Purge (); } -} -} + +} // namespace aodv +} // namespace ns3 diff --git a/src/aodv/model/aodv-packet.cc b/src/aodv/model/aodv-packet.cc index 6471a283a..4a54a2ecd 100644 --- a/src/aodv/model/aodv-packet.cc +++ b/src/aodv/model/aodv-packet.cc @@ -15,10 +15,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Based on + * Based on * NS-2 AODV model developed by the CMU/MONARCH group and optimized and * tuned by Samir Das and Mahesh Marina, University of Cincinnati; - * + * * AODV-UU implementation by Erik Nordström of Uppsala University * http://core.it.uu.se/core/index.php/AODV-UU * @@ -29,15 +29,14 @@ #include "ns3/address-utils.h" #include "ns3/packet.h" -namespace ns3 -{ -namespace aodv -{ +namespace ns3 { +namespace aodv { NS_OBJECT_ENSURE_REGISTERED (TypeHeader); -TypeHeader::TypeHeader (MessageType t) : - m_type (t), m_valid (true) +TypeHeader::TypeHeader (MessageType t) + : m_type (t), + m_valid (true) { } @@ -46,7 +45,7 @@ TypeHeader::GetTypeId () { static TypeId tid = TypeId ("ns3::aodv::TypeHeader") .SetParent
() - .SetGroupName("Aodv") + .SetGroupName ("Aodv") .AddConstructor () ; return tid; @@ -141,9 +140,15 @@ operator<< (std::ostream & os, TypeHeader const & h) // RREQ //----------------------------------------------------------------------------- RreqHeader::RreqHeader (uint8_t flags, uint8_t reserved, uint8_t hopCount, uint32_t requestID, Ipv4Address dst, - uint32_t dstSeqNo, Ipv4Address origin, uint32_t originSeqNo) : - m_flags (flags), m_reserved (reserved), m_hopCount (hopCount), m_requestID (requestID), m_dst (dst), - m_dstSeqNo (dstSeqNo), m_origin (origin), m_originSeqNo (originSeqNo) + uint32_t dstSeqNo, Ipv4Address origin, uint32_t originSeqNo) + : m_flags (flags), + m_reserved (reserved), + m_hopCount (hopCount), + m_requestID (requestID), + m_dst (dst), + m_dstSeqNo (dstSeqNo), + m_origin (origin), + m_originSeqNo (originSeqNo) { } @@ -154,7 +159,7 @@ RreqHeader::GetTypeId () { static TypeId tid = TypeId ("ns3::aodv::RreqHeader") .SetParent
() - .SetGroupName("Aodv") + .SetGroupName ("Aodv") .AddConstructor () ; return tid; @@ -225,9 +230,13 @@ void RreqHeader::SetGratiousRrep (bool f) { if (f) - m_flags |= (1 << 5); + { + m_flags |= (1 << 5); + } else - m_flags &= ~(1 << 5); + { + m_flags &= ~(1 << 5); + } } bool @@ -240,9 +249,13 @@ void RreqHeader::SetDestinationOnly (bool f) { if (f) - m_flags |= (1 << 4); + { + m_flags |= (1 << 4); + } else - m_flags &= ~(1 << 4); + { + m_flags &= ~(1 << 4); + } } bool @@ -255,9 +268,13 @@ void RreqHeader::SetUnknownSeqno (bool f) { if (f) - m_flags |= (1 << 3); + { + m_flags |= (1 << 3); + } else - m_flags &= ~(1 << 3); + { + m_flags &= ~(1 << 3); + } } bool @@ -269,10 +286,10 @@ RreqHeader::GetUnknownSeqno () const bool RreqHeader::operator== (RreqHeader const & o) const { - return (m_flags == o.m_flags && m_reserved == o.m_reserved && - m_hopCount == o.m_hopCount && m_requestID == o.m_requestID && - m_dst == o.m_dst && m_dstSeqNo == o.m_dstSeqNo && - m_origin == o.m_origin && m_originSeqNo == o.m_originSeqNo); + return (m_flags == o.m_flags && m_reserved == o.m_reserved + && m_hopCount == o.m_hopCount && m_requestID == o.m_requestID + && m_dst == o.m_dst && m_dstSeqNo == o.m_dstSeqNo + && m_origin == o.m_origin && m_originSeqNo == o.m_originSeqNo); } //----------------------------------------------------------------------------- @@ -280,9 +297,13 @@ RreqHeader::operator== (RreqHeader const & o) const //----------------------------------------------------------------------------- RrepHeader::RrepHeader (uint8_t prefixSize, uint8_t hopCount, Ipv4Address dst, - uint32_t dstSeqNo, Ipv4Address origin, Time lifeTime) : - m_flags (0), m_prefixSize (prefixSize), m_hopCount (hopCount), - m_dst (dst), m_dstSeqNo (dstSeqNo), m_origin (origin) + uint32_t dstSeqNo, Ipv4Address origin, Time lifeTime) + : m_flags (0), + m_prefixSize (prefixSize), + m_hopCount (hopCount), + m_dst (dst), + m_dstSeqNo (dstSeqNo), + m_origin (origin) { m_lifeTime = uint32_t (lifeTime.GetMilliSeconds ()); } @@ -294,7 +315,7 @@ RrepHeader::GetTypeId () { static TypeId tid = TypeId ("ns3::aodv::RrepHeader") .SetParent
() - .SetGroupName("Aodv") + .SetGroupName ("Aodv") .AddConstructor () ; return tid; @@ -371,9 +392,13 @@ void RrepHeader::SetAckRequired (bool f) { if (f) - m_flags |= (1 << 6); + { + m_flags |= (1 << 6); + } else - m_flags &= ~(1 << 6); + { + m_flags &= ~(1 << 6); + } } bool @@ -397,9 +422,9 @@ RrepHeader::GetPrefixSize () const bool RrepHeader::operator== (RrepHeader const & o) const { - return (m_flags == o.m_flags && m_prefixSize == o.m_prefixSize && - m_hopCount == o.m_hopCount && m_dst == o.m_dst && m_dstSeqNo == o.m_dstSeqNo && - m_origin == o.m_origin && m_lifeTime == o.m_lifeTime); + return (m_flags == o.m_flags && m_prefixSize == o.m_prefixSize + && m_hopCount == o.m_hopCount && m_dst == o.m_dst && m_dstSeqNo == o.m_dstSeqNo + && m_origin == o.m_origin && m_lifeTime == o.m_lifeTime); } void @@ -425,19 +450,19 @@ operator<< (std::ostream & os, RrepHeader const & h) // RREP-ACK //----------------------------------------------------------------------------- -RrepAckHeader::RrepAckHeader () : - m_reserved (0) +RrepAckHeader::RrepAckHeader () + : m_reserved (0) { } NS_OBJECT_ENSURE_REGISTERED (RrepAckHeader); - + TypeId RrepAckHeader::GetTypeId () { static TypeId tid = TypeId ("ns3::aodv::RrepAckHeader") .SetParent
() - .SetGroupName("Aodv") + .SetGroupName ("Aodv") .AddConstructor () ; return tid; @@ -492,8 +517,9 @@ operator<< (std::ostream & os, RrepAckHeader const & h ) //----------------------------------------------------------------------------- // RERR //----------------------------------------------------------------------------- -RerrHeader::RerrHeader () : - m_flag (0), m_reserved (0) +RerrHeader::RerrHeader () + : m_flag (0), + m_reserved (0) { } @@ -504,7 +530,7 @@ RerrHeader::GetTypeId () { static TypeId tid = TypeId ("ns3::aodv::RerrHeader") .SetParent
() - .SetGroupName("Aodv") + .SetGroupName ("Aodv") .AddConstructor () ; return tid; @@ -574,9 +600,13 @@ void RerrHeader::SetNoDelete (bool f ) { if (f) - m_flag |= (1 << 0); + { + m_flag |= (1 << 0); + } else - m_flag &= ~(1 << 0); + { + m_flag &= ~(1 << 0); + } } bool @@ -589,7 +619,9 @@ bool RerrHeader::AddUnDestination (Ipv4Address dst, uint32_t seqNo ) { if (m_unreachableDstSeqNo.find (dst) != m_unreachableDstSeqNo.end ()) - return true; + { + return true; + } NS_ASSERT (GetDestCount () < 255); // can't support more than 255 destinations in single RERR m_unreachableDstSeqNo.insert (std::make_pair (dst, seqNo)); @@ -600,7 +632,9 @@ bool RerrHeader::RemoveUnDestination (std::pair & un ) { if (m_unreachableDstSeqNo.empty ()) - return false; + { + return false; + } std::map::iterator i = m_unreachableDstSeqNo.begin (); un = *i; m_unreachableDstSeqNo.erase (i); @@ -619,14 +653,18 @@ bool RerrHeader::operator== (RerrHeader const & o ) const { if (m_flag != o.m_flag || m_reserved != o.m_reserved || GetDestCount () != o.GetDestCount ()) - return false; + { + return false; + } std::map::const_iterator j = m_unreachableDstSeqNo.begin (); std::map::const_iterator k = o.m_unreachableDstSeqNo.begin (); for (uint8_t i = 0; i < GetDestCount (); ++i) { if ((j->first != k->first) || (j->second != k->second)) - return false; + { + return false; + } j++; k++; diff --git a/src/aodv/model/aodv-routing-protocol.cc b/src/aodv/model/aodv-routing-protocol.cc index 5082f7d4e..6d627e37a 100644 --- a/src/aodv/model/aodv-routing-protocol.cc +++ b/src/aodv/model/aodv-routing-protocol.cc @@ -15,10 +15,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Based on + * Based on * NS-2 AODV model developed by the CMU/MONARCH group and optimized and * tuned by Samir Das and Mahesh Marina, University of Cincinnati; - * + * * AODV-UU implementation by Erik Nordström of Uppsala University * http://core.it.uu.se/core/index.php/AODV-UU * @@ -26,7 +26,7 @@ * Pavel Boyko */ #define NS_LOG_APPEND_CONTEXT \ - if (m_ipv4) { std::clog << "[node " << m_ipv4->GetObject ()->GetId () << "] "; } + if (m_ipv4) { std::clog << "[node " << m_ipv4->GetObject ()->GetId () << "] "; } #include "aodv-routing-protocol.h" #include "ns3/log.h" @@ -44,48 +44,66 @@ #include #include -namespace ns3 -{ +namespace ns3 { NS_LOG_COMPONENT_DEFINE ("AodvRoutingProtocol"); -namespace aodv -{ +namespace aodv { NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol); /// UDP Port for AODV control traffic const uint32_t RoutingProtocol::AODV_PORT = 654; -//----------------------------------------------------------------------------- -/// Tag used by AODV implementation - +/** +* \ingroup aodv +* \brief Tag used by AODV implementation +*/ class DeferredRouteOutputTag : public Tag { public: - DeferredRouteOutputTag (int32_t o = -1) : Tag (), m_oif (o) {} + /** + * \brief Constructor + * \param o the output interface + */ + DeferredRouteOutputTag (int32_t o = -1) : Tag (), + m_oif (o) + { + } + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId () { static TypeId tid = TypeId ("ns3::aodv::DeferredRouteOutputTag") .SetParent () - .SetGroupName("Aodv") + .SetGroupName ("Aodv") .AddConstructor () ; return tid; } - TypeId GetInstanceTypeId () const + TypeId GetInstanceTypeId () const { return GetTypeId (); } - int32_t GetInterface() const + /** + * \brief Get the output interface + * \return the output interface + */ + int32_t GetInterface () const { return m_oif; } - void SetInterface(int32_t oif) + /** + * \brief Set the output interface + * \param oif the output interface + */ + void SetInterface (int32_t oif) { m_oif = oif; } @@ -119,43 +137,43 @@ NS_OBJECT_ENSURE_REGISTERED (DeferredRouteOutputTag); //----------------------------------------------------------------------------- -RoutingProtocol::RoutingProtocol () : - m_rreqRetries (2), - m_ttlStart (1), - m_ttlIncrement (2), - m_ttlThreshold (7), - m_timeoutBuffer (2), - m_rreqRateLimit (10), - m_rerrRateLimit (10), - m_activeRouteTimeout (Seconds (3)), - m_netDiameter (35), - m_nodeTraversalTime (MilliSeconds (40)), - m_netTraversalTime (Time ((2 * m_netDiameter) * m_nodeTraversalTime)), - m_pathDiscoveryTime ( Time (2 * m_netTraversalTime)), - m_myRouteTimeout (Time (2 * std::max (m_pathDiscoveryTime, m_activeRouteTimeout))), - m_helloInterval (Seconds (1)), - m_allowedHelloLoss (2), - m_deletePeriod (Time (5 * std::max (m_activeRouteTimeout, m_helloInterval))), - m_nextHopWait (m_nodeTraversalTime + MilliSeconds (10)), - m_blackListTimeout (Time (m_rreqRetries * m_netTraversalTime)), - m_maxQueueLen (64), - m_maxQueueTime (Seconds (30)), - m_destinationOnly (false), - m_gratuitousReply (true), - m_enableHello (false), - m_routingTable (m_deletePeriod), - m_queue (m_maxQueueLen, m_maxQueueTime), - m_requestId (0), - m_seqNo (0), - m_rreqIdCache (m_pathDiscoveryTime), - m_dpd (m_pathDiscoveryTime), - m_nb (m_helloInterval), - m_rreqCount (0), - m_rerrCount (0), - m_htimer (Timer::CANCEL_ON_DESTROY), - m_rreqRateLimitTimer (Timer::CANCEL_ON_DESTROY), - m_rerrRateLimitTimer (Timer::CANCEL_ON_DESTROY), - m_lastBcastTime (Seconds (0)) +RoutingProtocol::RoutingProtocol () + : m_rreqRetries (2), + m_ttlStart (1), + m_ttlIncrement (2), + m_ttlThreshold (7), + m_timeoutBuffer (2), + m_rreqRateLimit (10), + m_rerrRateLimit (10), + m_activeRouteTimeout (Seconds (3)), + m_netDiameter (35), + m_nodeTraversalTime (MilliSeconds (40)), + m_netTraversalTime (Time ((2 * m_netDiameter) * m_nodeTraversalTime)), + m_pathDiscoveryTime ( Time (2 * m_netTraversalTime)), + m_myRouteTimeout (Time (2 * std::max (m_pathDiscoveryTime, m_activeRouteTimeout))), + m_helloInterval (Seconds (1)), + m_allowedHelloLoss (2), + m_deletePeriod (Time (5 * std::max (m_activeRouteTimeout, m_helloInterval))), + m_nextHopWait (m_nodeTraversalTime + MilliSeconds (10)), + m_blackListTimeout (Time (m_rreqRetries * m_netTraversalTime)), + m_maxQueueLen (64), + m_maxQueueTime (Seconds (30)), + m_destinationOnly (false), + m_gratuitousReply (true), + m_enableHello (false), + m_routingTable (m_deletePeriod), + m_queue (m_maxQueueLen, m_maxQueueTime), + m_requestId (0), + m_seqNo (0), + m_rreqIdCache (m_pathDiscoveryTime), + m_dpd (m_pathDiscoveryTime), + m_nb (m_helloInterval), + m_rreqCount (0), + m_rerrCount (0), + m_htimer (Timer::CANCEL_ON_DESTROY), + m_rreqRateLimitTimer (Timer::CANCEL_ON_DESTROY), + m_rerrRateLimitTimer (Timer::CANCEL_ON_DESTROY), + m_lastBcastTime (Seconds (0)) { m_nb.SetCallback (MakeCallback (&RoutingProtocol::SendRerrWhenBreaksLinkToNextHop, this)); } @@ -165,7 +183,7 @@ RoutingProtocol::GetTypeId (void) { static TypeId tid = TypeId ("ns3::aodv::RoutingProtocol") .SetParent () - .SetGroupName("Aodv") + .SetGroupName ("Aodv") .AddConstructor () .AddAttribute ("HelloInterval", "HELLO messages emission interval.", TimeValue (Seconds (1)), @@ -321,7 +339,7 @@ void RoutingProtocol::PrintRoutingTable (Ptr stream, Time::Unit unit) const { *stream->GetStream () << "Node: " << m_ipv4->GetObject ()->GetId () - << "; Time: " << Now().As (unit) + << "; Time: " << Now ().As (unit) << ", Local time: " << GetObject ()->GetLocalTime ().As (unit) << ", AODV Routing table" << std::endl; @@ -362,7 +380,7 @@ RoutingProtocol::RouteOutput (Ptr p, const Ipv4Header &header, NS_LOG_FUNCTION (this << header << (oif ? oif->GetIfIndex () : 0)); if (!p) { - NS_LOG_DEBUG("Packet is == 0"); + NS_LOG_DEBUG ("Packet is == 0"); return LoopbackRoute (header, oif); // later } if (m_socketAddresses.empty ()) @@ -392,8 +410,8 @@ RoutingProtocol::RouteOutput (Ptr p, const Ipv4Header &header, return route; } - // Valid route not found, in this case we return loopback. - // Actual route request will be deferred until packet will be fully formed, + // Valid route not found, in this case we return loopback. + // Actual route request will be deferred until packet will be fully formed, // routed to loopback, received from loopback and passed to RouteInput (see below) uint32_t iif = (oif ? m_ipv4->GetInterfaceForDevice (oif) : -1); DeferredRouteOutputTag tag (iif); @@ -406,7 +424,7 @@ RoutingProtocol::RouteOutput (Ptr p, const Ipv4Header &header, } void -RoutingProtocol::DeferredRouteOutput (Ptr p, const Ipv4Header & header, +RoutingProtocol::DeferredRouteOutput (Ptr p, const Ipv4Header & header, UnicastForwardCallback ucb, ErrorCallback ecb) { NS_LOG_FUNCTION (this << p << header); @@ -419,9 +437,9 @@ RoutingProtocol::DeferredRouteOutput (Ptr p, const Ipv4Header & he NS_LOG_LOGIC ("Add packet " << p->GetUid () << " to queue. Protocol " << (uint16_t) header.GetProtocol ()); RoutingTableEntry rt; bool result = m_routingTable.LookupRoute (header.GetDestination (), rt); - if(!result || ((rt.GetFlag () != IN_SEARCH) && result)) + if (!result || ((rt.GetFlag () != IN_SEARCH) && result)) { - NS_LOG_LOGIC ("Send new RREQ for outbound packet to " < p, const Ipv4Header &header, // Duplicate of own packet if (IsMyOwnAddress (origin)) - return true; + { + return true; + } // AODV is not a multicast routing protocol if (dst.IsMulticast ()) { - return false; + return false; } // Broadcast local delivery/forwarding @@ -474,60 +494,62 @@ RoutingProtocol::RouteInput (Ptr p, const Ipv4Header &header, { Ipv4InterfaceAddress iface = j->second; if (m_ipv4->GetInterfaceForAddress (iface.GetLocal ()) == iif) - if (dst == iface.GetBroadcast () || dst.IsBroadcast ()) - { - if (m_dpd.IsDuplicate (p, header)) - { - NS_LOG_DEBUG ("Duplicated packet " << p->GetUid () << " from " << origin << ". Drop."); - return true; - } - UpdateRouteLifeTime (origin, m_activeRouteTimeout); - Ptr packet = p->Copy (); - if (lcb.IsNull () == false) - { - NS_LOG_LOGIC ("Broadcast local delivery to " << iface.GetLocal ()); - lcb (p, header, iif); - // Fall through to additional processing - } - else - { - NS_LOG_ERROR ("Unable to deliver packet locally due to null callback " << p->GetUid () << " from " << origin); - ecb (p, header, Socket::ERROR_NOROUTETOHOST); - } - if (!m_enableBroadcast) - { - return true; - } - if (header.GetProtocol () == UdpL4Protocol::PROT_NUMBER) - { - UdpHeader udpHeader; - p->PeekHeader (udpHeader); - if (udpHeader.GetDestinationPort () == AODV_PORT) - { - // AODV packets sent in broadcast are already managed - return true; - } - } - if (header.GetTtl () > 1) - { - NS_LOG_LOGIC ("Forward broadcast. TTL " << (uint16_t) header.GetTtl ()); - RoutingTableEntry toBroadcast; - if (m_routingTable.LookupRoute (dst, toBroadcast)) - { - Ptr route = toBroadcast.GetRoute (); - ucb (route, packet, header); - } - else - { - NS_LOG_DEBUG ("No route to forward broadcast. Drop packet " << p->GetUid ()); - } - } - else - { - NS_LOG_DEBUG ("TTL exceeded. Drop packet " << p->GetUid ()); - } - return true; - } + { + if (dst == iface.GetBroadcast () || dst.IsBroadcast ()) + { + if (m_dpd.IsDuplicate (p, header)) + { + NS_LOG_DEBUG ("Duplicated packet " << p->GetUid () << " from " << origin << ". Drop."); + return true; + } + UpdateRouteLifeTime (origin, m_activeRouteTimeout); + Ptr packet = p->Copy (); + if (lcb.IsNull () == false) + { + NS_LOG_LOGIC ("Broadcast local delivery to " << iface.GetLocal ()); + lcb (p, header, iif); + // Fall through to additional processing + } + else + { + NS_LOG_ERROR ("Unable to deliver packet locally due to null callback " << p->GetUid () << " from " << origin); + ecb (p, header, Socket::ERROR_NOROUTETOHOST); + } + if (!m_enableBroadcast) + { + return true; + } + if (header.GetProtocol () == UdpL4Protocol::PROT_NUMBER) + { + UdpHeader udpHeader; + p->PeekHeader (udpHeader); + if (udpHeader.GetDestinationPort () == AODV_PORT) + { + // AODV packets sent in broadcast are already managed + return true; + } + } + if (header.GetTtl () > 1) + { + NS_LOG_LOGIC ("Forward broadcast. TTL " << (uint16_t) header.GetTtl ()); + RoutingTableEntry toBroadcast; + if (m_routingTable.LookupRoute (dst, toBroadcast)) + { + Ptr route = toBroadcast.GetRoute (); + ucb (route, packet, header); + } + else + { + NS_LOG_DEBUG ("No route to forward broadcast. Drop packet " << p->GetUid ()); + } + } + else + { + NS_LOG_DEBUG ("TTL exceeded. Drop packet " << p->GetUid ()); + } + return true; + } + } } // Unicast local delivery @@ -579,7 +601,7 @@ RoutingProtocol::Forwarding (Ptr p, const Ipv4Header & header, if (toDst.GetFlag () == VALID) { Ptr route = toDst.GetRoute (); - NS_LOG_LOGIC (route->GetSource ()<<" forwarding to " << dst << " from " << origin << " packet " << p->GetUid ()); + NS_LOG_LOGIC (route->GetSource () << " forwarding to " << dst << " from " << origin << " packet " << p->GetUid ()); /* * Each time a route is used to forward a data packet, its Active Route @@ -615,7 +637,7 @@ RoutingProtocol::Forwarding (Ptr p, const Ipv4Header & header, } } } - NS_LOG_LOGIC ("route not found to "<< dst << ". Send RERR message."); + NS_LOG_LOGIC ("route not found to " << dst << ". Send RERR message."); NS_LOG_DEBUG ("Drop packet " << p->GetUid () << " because no route to forward it."); SendRerrWhenNoRouteToForward (dst, 0, origin); return false; @@ -654,8 +676,10 @@ RoutingProtocol::NotifyInterfaceUp (uint32_t i) } Ipv4InterfaceAddress iface = l3->GetAddress (i, 0); if (iface.GetLocal () == Ipv4Address ("127.0.0.1")) - return; - + { + return; + } + // Create a socket to listen only on this interface Ptr socket = Socket::CreateSocket (GetObject (), UdpSocketFactory::GetTypeId ()); @@ -692,10 +716,14 @@ RoutingProtocol::NotifyInterfaceUp (uint32_t i) // Allow neighbor manager use this interface for layer 2 feedback if possible Ptr wifi = dev->GetObject (); if (wifi == 0) - return; + { + return; + } Ptr mac = wifi->GetMac (); if (mac == 0) - return; + { + return; + } mac->TraceConnectWithoutContext ("TxErrHeader", m_nb.GetTxErrorCallback ()); } @@ -720,7 +748,7 @@ RoutingProtocol::NotifyInterfaceDown (uint32_t i) } } - // Close socket + // Close socket Ptr socket = FindSocketWithInterfaceAddress (m_ipv4->GetAddress (i, 0)); NS_ASSERT (socket); socket->Close (); @@ -749,7 +777,9 @@ RoutingProtocol::NotifyAddAddress (uint32_t i, Ipv4InterfaceAddress address) NS_LOG_FUNCTION (this << " interface " << i << " address " << address); Ptr l3 = m_ipv4->GetObject (); if (!l3->IsUp (i)) - return; + { + return; + } if (l3->GetNAddresses (i) == 1) { Ipv4InterfaceAddress iface = l3->GetAddress (i, 0); @@ -757,7 +787,9 @@ RoutingProtocol::NotifyAddAddress (uint32_t i, Ipv4InterfaceAddress address) if (!socket) { if (iface.GetLocal () == Ipv4Address ("127.0.0.1")) - return; + { + return; + } // Create a socket to listen only on this interface Ptr socket = Socket::CreateSocket (GetObject (), UdpSocketFactory::GetTypeId ()); @@ -770,7 +802,7 @@ RoutingProtocol::NotifyAddAddress (uint32_t i, Ipv4InterfaceAddress address) // create also a subnet directed broadcast socket socket = Socket::CreateSocket (GetObject (), - UdpSocketFactory::GetTypeId ()); + UdpSocketFactory::GetTypeId ()); NS_ASSERT (socket != 0); socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); socket->Bind (InetSocketAddress (iface.GetBroadcast (), AODV_PORT)); @@ -830,7 +862,7 @@ RoutingProtocol::NotifyRemoveAddress (uint32_t i, Ipv4InterfaceAddress address) // create also a unicast socket socket = Socket::CreateSocket (GetObject (), - UdpSocketFactory::GetTypeId ()); + UdpSocketFactory::GetTypeId ()); NS_ASSERT (socket != 0); socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); socket->Bind (InetSocketAddress (iface.GetBroadcast (), AODV_PORT)); @@ -876,7 +908,7 @@ RoutingProtocol::IsMyOwnAddress (Ipv4Address src) return false; } -Ptr +Ptr RoutingProtocol::LoopbackRoute (const Ipv4Header & hdr, Ptr oif) const { NS_LOG_FUNCTION (this << hdr); @@ -896,7 +928,7 @@ RoutingProtocol::LoopbackRoute (const Ipv4Header & hdr, Ptr oif) cons // For single interface, single address nodes, this is not a problem. // When there are possibly multiple outgoing interfaces, the policy // implemented here is to pick the first available AODV interface. - // If RouteOutput() caller specified an outgoing interface, that + // If RouteOutput() caller specified an outgoing interface, that // further constrains the selection of source address // std::map, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); @@ -936,7 +968,9 @@ RoutingProtocol::SendRequest (Ipv4Address dst) return; } else - m_rreqCount++; + { + m_rreqCount++; + } // Create RREQ header RreqHeader rreqHeader; rreqHeader.SetDst (dst); @@ -954,14 +988,22 @@ RoutingProtocol::SendRequest (Ipv4Address dst) { ttl = rt.GetHop () + m_ttlIncrement; if (ttl > m_ttlThreshold) - ttl = m_netDiameter; + { + ttl = m_netDiameter; + } } if (ttl == m_netDiameter) - rt.IncrementRreqCnt (); + { + rt.IncrementRreqCnt (); + } if (rt.GetValidSeqNo ()) - rreqHeader.SetDstSeqno (rt.GetSeqNo ()); + { + rreqHeader.SetDstSeqno (rt.GetSeqNo ()); + } else - rreqHeader.SetUnknownSeqno (true); + { + rreqHeader.SetUnknownSeqno (true); + } rt.SetHop (ttl); rt.SetFlag (IN_SEARCH); rt.SetLifeTime (m_pathDiscoveryTime); @@ -976,15 +1018,21 @@ RoutingProtocol::SendRequest (Ipv4Address dst) /*nextHop=*/ Ipv4Address (), /*lifeTime=*/ m_pathDiscoveryTime); // Check if TtlStart == NetDiameter if (ttl == m_netDiameter) - newEntry.IncrementRreqCnt (); + { + newEntry.IncrementRreqCnt (); + } newEntry.SetFlag (IN_SEARCH); m_routingTable.AddRoute (newEntry); } if (m_gratuitousReply) - rreqHeader.SetGratiousRrep (true); + { + rreqHeader.SetGratiousRrep (true); + } if (m_destinationOnly) - rreqHeader.SetDestinationOnly (true); + { + rreqHeader.SetDestinationOnly (true); + } m_seqNo++; rreqHeader.SetOriginSeqno (m_seqNo); @@ -1015,12 +1063,12 @@ RoutingProtocol::SendRequest (Ipv4Address dst) destination = Ipv4Address ("255.255.255.255"); } else - { + { destination = iface.GetBroadcast (); } NS_LOG_DEBUG ("Send RREQ with id " << rreqHeader.GetId () << " to socket"); m_lastBcastTime = Simulator::Now (); - Simulator::Schedule (Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))), &RoutingProtocol::SendTo, this, socket, packet, destination); + Simulator::Schedule (Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))), &RoutingProtocol::SendTo, this, socket, packet, destination); } ScheduleRreqRetry (dst); } @@ -1028,7 +1076,7 @@ RoutingProtocol::SendRequest (Ipv4Address dst) void RoutingProtocol::SendTo (Ptr socket, Ptr packet, Ipv4Address destination) { - socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT)); + socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT)); } void @@ -1073,7 +1121,7 @@ RoutingProtocol::RecvAodv (Ptr socket) { receiver = m_socketAddresses[socket].GetLocal (); } - else if(m_socketSubnetBroadcastAddresses.find (socket) != m_socketSubnetBroadcastAddresses.end ()) + else if (m_socketSubnetBroadcastAddresses.find (socket) != m_socketSubnetBroadcastAddresses.end ()) { receiver = m_socketSubnetBroadcastAddresses[socket].GetLocal (); } @@ -1225,10 +1273,14 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s if (toOrigin.GetValidSeqNo ()) { if (int32_t (rreqHeader.GetOriginSeqno ()) - int32_t (toOrigin.GetSeqNo ()) > 0) - toOrigin.SetSeqNo (rreqHeader.GetOriginSeqno ()); + { + toOrigin.SetSeqNo (rreqHeader.GetOriginSeqno ()); + } } else - toOrigin.SetSeqNo (rreqHeader.GetOriginSeqno ()); + { + toOrigin.SetSeqNo (rreqHeader.GetOriginSeqno ()); + } toOrigin.SetValidSeqNo (true); toOrigin.SetNextHop (src); toOrigin.SetOutputDevice (m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (receiver))); @@ -1244,18 +1296,18 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s RoutingTableEntry toNeighbor; if (!m_routingTable.LookupRoute (src, toNeighbor)) { - NS_LOG_DEBUG ("Neighbor:" << src << " not found in routing table. Creating an entry"); + NS_LOG_DEBUG ("Neighbor:" << src << " not found in routing table. Creating an entry"); Ptr dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (receiver)); RoutingTableEntry newEntry (dev, src, false, rreqHeader.GetOriginSeqno (), - m_ipv4->GetAddress (m_ipv4->GetInterfaceForAddress (receiver), 0), - 1, src, m_activeRouteTimeout); + m_ipv4->GetAddress (m_ipv4->GetInterfaceForAddress (receiver), 0), + 1, src, m_activeRouteTimeout); m_routingTable.AddRoute (newEntry); } else { toNeighbor.SetLifeTime (m_activeRouteTimeout); toNeighbor.SetValidSeqNo (false); - toNeighbor.SetSeqNo (rreqHeader.GetOriginSeqno ()); + toNeighbor.SetSeqNo (rreqHeader.GetOriginSeqno ()); toNeighbor.SetFlag (VALID); toNeighbor.SetOutputDevice (m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (receiver))); toNeighbor.SetInterface (m_ipv4->GetAddress (m_ipv4->GetInterfaceForAddress (receiver), 0)); @@ -1265,7 +1317,7 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s } m_nb.Update (src, Time (m_allowedHelloLoss * m_helloInterval)); - NS_LOG_LOGIC (receiver << " receive RREQ with hop count " << static_cast(rreqHeader.GetHopCount ()) + NS_LOG_LOGIC (receiver << " receive RREQ with hop count " << static_cast (rreqHeader.GetHopCount ()) << " ID " << rreqHeader.GetId () << " to destination " << rreqHeader.GetDst ()); @@ -1341,11 +1393,11 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s destination = Ipv4Address ("255.255.255.255"); } else - { + { destination = iface.GetBroadcast (); } m_lastBcastTime = Simulator::Now (); - Simulator::Schedule (Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))), &RoutingProtocol::SendTo, this, socket, packet, destination); + Simulator::Schedule (Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))), &RoutingProtocol::SendTo, this, socket, packet, destination); } } @@ -1359,7 +1411,9 @@ RoutingProtocol::SendReply (RreqHeader const & rreqHeader, RoutingTableEntry con * incremented value. Otherwise, the destination does not change its sequence number before generating the RREP message. */ if (!rreqHeader.GetUnknownSeqno () && (rreqHeader.GetDstSeqno () == m_seqNo + 1)) - m_seqNo++; + { + m_seqNo++; + } RrepHeader rrepHeader ( /*prefixSize=*/ 0, /*hops=*/ 0, /*dst=*/ rreqHeader.GetDst (), /*dstSeqNo=*/ m_seqNo, /*origin=*/ toOrigin.GetDestination (), /*lifeTime=*/ m_myRouteTimeout); Ptr packet = Create (); @@ -1564,7 +1618,7 @@ RoutingProtocol::RecvReply (Ptr p, Ipv4Address receiver, Ipv4Address sen m_routingTable.Update (toNextHopToOrigin); } SocketIpTtlTag tag; - p->RemovePacketTag(tag); + p->RemovePacketTag (tag); if (tag.GetTtl () < 2) { NS_LOG_DEBUG ("TTL exceeded. Drop RREP destination " << dst << " origin " << rrepHeader.GetOrigin ()); @@ -1573,7 +1627,7 @@ RoutingProtocol::RecvReply (Ptr p, Ipv4Address receiver, Ipv4Address sen Ptr packet = Create (); SocketIpTtlTag ttl; - ttl.SetTtl (tag.GetTtl() - 1); + ttl.SetTtl (tag.GetTtl () - 1); packet->AddPacketTag (ttl); packet->AddHeader (rrepHeader); TypeHeader tHeader (AODVTYPE_RREP); @@ -1588,7 +1642,7 @@ RoutingProtocol::RecvReplyAck (Ipv4Address neighbor) { NS_LOG_FUNCTION (this); RoutingTableEntry rt; - if(m_routingTable.LookupRoute (neighbor, rt)) + if (m_routingTable.LookupRoute (neighbor, rt)) { rt.m_ackTimer.Cancel (); rt.SetFlag (VALID); @@ -1645,18 +1699,18 @@ RoutingProtocol::RecvError (Ptr p, Ipv4Address src ) while (rerrHeader.RemoveUnDestination (un)) { for (std::map::const_iterator i = - dstWithNextHopSrc.begin (); i != dstWithNextHopSrc.end (); ++i) - { - if (i->first == un.first) - { - unreachable.insert (un); - } - } + dstWithNextHopSrc.begin (); i != dstWithNextHopSrc.end (); ++i) + { + if (i->first == un.first) + { + unreachable.insert (un); + } + } } std::vector precursors; for (std::map::const_iterator i = unreachable.begin (); - i != unreachable.end ();) + i != unreachable.end (); ) { if (!rerrHeader.AddUnDestination (i->first, i->second)) { @@ -1805,11 +1859,11 @@ RoutingProtocol::SendHello () destination = Ipv4Address ("255.255.255.255"); } else - { + { destination = iface.GetBroadcast (); } Time jitter = Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))); - Simulator::Schedule (jitter, &RoutingProtocol::SendTo, this , socket, packet, destination); + Simulator::Schedule (jitter, &RoutingProtocol::SendTo, this, socket, packet, destination); } } @@ -1822,9 +1876,9 @@ RoutingProtocol::SendPacketFromQueue (Ipv4Address dst, Ptr route) { DeferredRouteOutputTag tag; Ptr p = ConstCast (queueEntry.GetPacket ()); - if (p->RemovePacketTag (tag) && - tag.GetInterface() != -1 && - tag.GetInterface() != m_ipv4->GetInterfaceForDevice (route->GetOutputDevice ())) + if (p->RemovePacketTag (tag) + && tag.GetInterface () != -1 + && tag.GetInterface () != m_ipv4->GetInterfaceForDevice (route->GetOutputDevice ())) { NS_LOG_DEBUG ("Output device doesn't match. Dropped."); return; @@ -1847,12 +1901,14 @@ RoutingProtocol::SendRerrWhenBreaksLinkToNextHop (Ipv4Address nextHop) RoutingTableEntry toNextHop; if (!m_routingTable.LookupRoute (nextHop, toNextHop)) - return; + { + return; + } toNextHop.GetPrecursors (precursors); rerrHeader.AddUnDestination (nextHop, toNextHop.GetSeqNo ()); m_routingTable.GetListOfDestinationWithNextHop (nextHop, unreachable); for (std::map::const_iterator i = unreachable.begin (); i - != unreachable.end ();) + != unreachable.end (); ) { if (!rerrHeader.AddUnDestination (i->first, i->second)) { @@ -1901,7 +1957,7 @@ 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 " + NS_LOG_LOGIC ("RerrRateLimit reached at " << Simulator::Now ().GetSeconds () << " with timer delay left " << m_rerrRateLimitTimer.GetDelayLeft ().GetSeconds () << "; suppressing RERR"); return; @@ -1939,7 +1995,7 @@ RoutingProtocol::SendRerrWhenNoRouteToForward (Ipv4Address dst, destination = Ipv4Address ("255.255.255.255"); } else - { + { destination = iface.GetBroadcast (); } socket->SendTo (packet->Copy (), 0, InetSocketAddress (destination, AODV_PORT)); @@ -1963,7 +2019,7 @@ 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 " + NS_LOG_LOGIC ("RerrRateLimit reached at " << Simulator::Now ().GetSeconds () << " with timer delay left " << m_rerrRateLimitTimer.GetDelayLeft ().GetSeconds () << "; suppressing RERR"); return; @@ -1988,8 +2044,8 @@ RoutingProtocol::SendRerrMessage (Ptr packet, std::vector p RoutingTableEntry toPrecursor; for (std::vector::const_iterator i = precursors.begin (); i != precursors.end (); ++i) { - if (m_routingTable.LookupValidRoute (*i, toPrecursor) && - std::find (ifaces.begin (), ifaces.end (), toPrecursor.GetInterface ()) == ifaces.end ()) + if (m_routingTable.LookupValidRoute (*i, toPrecursor) + && std::find (ifaces.begin (), ifaces.end (), toPrecursor.GetInterface ()) == ifaces.end ()) { ifaces.push_back (toPrecursor.GetInterface ()); } @@ -2009,7 +2065,7 @@ RoutingProtocol::SendRerrMessage (Ptr packet, std::vector p destination = Ipv4Address ("255.255.255.255"); } else - { + { destination = i->GetBroadcast (); } Simulator::Schedule (Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))), &RoutingProtocol::SendTo, this, socket, p, destination); @@ -2026,7 +2082,9 @@ RoutingProtocol::FindSocketWithInterfaceAddress (Ipv4InterfaceAddress addr ) con Ptr socket = j->first; Ipv4InterfaceAddress iface = j->second; if (iface == addr) - return socket; + { + return socket; + } } Ptr socket; return socket; @@ -2042,7 +2100,9 @@ RoutingProtocol::FindSubnetBroadcastSocketWithInterfaceAddress (Ipv4InterfaceAdd Ptr socket = j->first; Ipv4InterfaceAddress iface = j->second; if (iface == addr) - return socket; + { + return socket; + } } Ptr socket; return socket; diff --git a/src/aodv/model/aodv-rqueue.cc b/src/aodv/model/aodv-rqueue.cc index e9e3b7dc4..8b79c1182 100644 --- a/src/aodv/model/aodv-rqueue.cc +++ b/src/aodv/model/aodv-rqueue.cc @@ -15,10 +15,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Based on + * Based on * NS-2 AODV model developed by the CMU/MONARCH group and optimized and * tuned by Samir Das and Mahesh Marina, University of Cincinnati; - * + * * AODV-UU implementation by Erik Nordström of Uppsala University * http://core.it.uu.se/core/index.php/AODV-UU * @@ -32,13 +32,11 @@ #include "ns3/socket.h" #include "ns3/log.h" -namespace ns3 -{ +namespace ns3 { NS_LOG_COMPONENT_DEFINE ("AodvRequestQueue"); -namespace aodv -{ +namespace aodv { uint32_t RequestQueue::GetSize () { @@ -56,7 +54,9 @@ RequestQueue::Enqueue (QueueEntry & entry) if ((i->GetPacket ()->GetUid () == entry.GetPacket ()->GetUid ()) && (i->GetIpv4Header ().GetDestination () == entry.GetIpv4Header ().GetDestination ())) - return false; + { + return false; + } } entry.SetExpireTime (m_queueTimeout); if (m_queue.size () == m_maxLen) @@ -108,14 +108,25 @@ RequestQueue::Find (Ipv4Address dst) != m_queue.end (); ++i) { if (i->GetIpv4Header ().GetDestination () == dst) - return true; + { + return true; + } } return false; } +/** + * \brief IsExpired structure + */ struct IsExpired { bool + /** + * Check if the entry is expired + * + * \param e QueueEntry entry + * \return true if expired, false otherwise + */ operator() (QueueEntry const & e) const { return (e.GetExpireTime () < Seconds (0)); @@ -147,5 +158,5 @@ RequestQueue::Drop (QueueEntry en, std::string reason) return; } -} -} +} // namespace aodv +} // namespace ns3 diff --git a/src/aodv/model/aodv-rtable.cc b/src/aodv/model/aodv-rtable.cc index bf26525e1..51b1c0351 100644 --- a/src/aodv/model/aodv-rtable.cc +++ b/src/aodv/model/aodv-rtable.cc @@ -15,10 +15,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Based on + * Based on * NS-2 AODV model developed by the CMU/MONARCH group and optimized and * tuned by Samir Das and Mahesh Marina, University of Cincinnati; - * + * * AODV-UU implementation by Erik Nordström of Uppsala University * http://core.it.uu.se/core/index.php/AODV-UU * @@ -32,24 +32,28 @@ #include "ns3/simulator.h" #include "ns3/log.h" -namespace ns3 -{ +namespace ns3 { NS_LOG_COMPONENT_DEFINE ("AodvRoutingTable"); -namespace aodv -{ +namespace aodv { /* The Routing Table */ RoutingTableEntry::RoutingTableEntry (Ptr dev, Ipv4Address dst, bool vSeqNo, uint32_t seqNo, - Ipv4InterfaceAddress iface, uint16_t hops, Ipv4Address nextHop, Time lifetime) : - m_ackTimer (Timer::CANCEL_ON_DESTROY), - 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 ()) + Ipv4InterfaceAddress iface, uint16_t hops, Ipv4Address nextHop, Time lifetime) + : m_ackTimer (Timer::CANCEL_ON_DESTROY), + 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_ipv4Route = Create (); m_ipv4Route->SetDestination (dst); @@ -72,7 +76,9 @@ RoutingTableEntry::InsertPrecursor (Ipv4Address id) return true; } else - return false; + { + return false; + } } bool @@ -129,7 +135,9 @@ RoutingTableEntry::GetPrecursors (std::vector & prec) const { NS_LOG_FUNCTION (this); if (IsPrecursorListEmpty ()) - return; + { + return; + } for (std::vector::const_iterator i = m_precursorList.begin (); i != m_precursorList.end (); ++i) { @@ -138,10 +146,14 @@ RoutingTableEntry::GetPrecursors (std::vector & prec) const != prec.end (); ++j) { if (*j == *i) - result = false; + { + result = false; + } } if (result) - prec.push_back (*i); + { + prec.push_back (*i); + } } } @@ -150,7 +162,9 @@ RoutingTableEntry::Invalidate (Time badLinkLifetime) { NS_LOG_FUNCTION (this << badLinkLifetime.GetSeconds ()); if (m_flag == INVALID) - return; + { + return; + } m_flag = INVALID; m_reqCount = 0; m_lifeTime = badLinkLifetime + Simulator::Now (); @@ -181,7 +195,7 @@ RoutingTableEntry::Print (Ptr stream) const } } *os << "\t"; - *os << std::setiosflags (std::ios::fixed) << + *os << std::setiosflags (std::ios::fixed) << std::setiosflags (std::ios::left) << std::setprecision (2) << std::setw (14) << (m_lifeTime - Simulator::Now ()).GetSeconds (); *os << "\t" << m_hops << "\n"; @@ -191,8 +205,8 @@ RoutingTableEntry::Print (Ptr stream) const The Routing Table */ -RoutingTable::RoutingTable (Time t) : - m_badLinkLifetime (t) +RoutingTable::RoutingTable (Time t) + : m_badLinkLifetime (t) { } @@ -251,7 +265,9 @@ RoutingTable::AddRoute (RoutingTableEntry & rt) NS_LOG_FUNCTION (this); Purge (); if (rt.GetFlag () != IN_SEARCH) - rt.SetRreqCnt (0); + { + rt.SetRreqCnt (0); + } std::pair::iterator, bool> result = m_ipv4AddressEntry.insert (std::make_pair (rt.GetDestination (), rt)); return result.second; @@ -336,9 +352,11 @@ RoutingTable::DeleteAllRoutesFromInterface (Ipv4InterfaceAddress iface) { NS_LOG_FUNCTION (this); if (m_ipv4AddressEntry.empty ()) - return; + { + return; + } for (std::map::iterator i = - m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end ();) + m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ) { if (i->second.GetInterface () == iface) { @@ -347,7 +365,9 @@ RoutingTable::DeleteAllRoutesFromInterface (Ipv4InterfaceAddress iface) m_ipv4AddressEntry.erase (tmp); } else - ++i; + { + ++i; + } } } @@ -356,9 +376,11 @@ RoutingTable::Purge () { NS_LOG_FUNCTION (this); if (m_ipv4AddressEntry.empty ()) - return; + { + return; + } for (std::map::iterator i = - m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end ();) + m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ) { if (i->second.GetLifeTime () < Seconds (0)) { @@ -375,9 +397,11 @@ RoutingTable::Purge () ++i; } else - ++i; + { + ++i; + } } - else + else { ++i; } @@ -389,9 +413,11 @@ RoutingTable::Purge (std::map &table) const { NS_LOG_FUNCTION (this); if (table.empty ()) - return; + { + return; + } for (std::map::iterator i = - table.begin (); i != table.end ();) + table.begin (); i != table.end (); ) { if (i->second.GetLifeTime () < Seconds (0)) { @@ -408,9 +434,11 @@ RoutingTable::Purge (std::map &table) const ++i; } else - ++i; + { + ++i; + } } - else + else { ++i; }