From b228fa8ac985eac57a147b1dba1d6fc2adb0f33f Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Sun, 2 Aug 2009 15:19:07 +0400 Subject: [PATCH] AODV cosmetics --- src/routing/aodv/aodv-routing-protocol.cc | 56 ++++++++++------------- src/routing/aodv/aodv-routing-protocol.h | 18 ++++---- src/routing/aodv/aodv-rqueue.cc | 1 - src/routing/aodv/aodv-rqueue.h | 19 ++++---- src/routing/aodv/aodv-rtable.h | 19 ++++---- 5 files changed, 53 insertions(+), 60 deletions(-) diff --git a/src/routing/aodv/aodv-routing-protocol.cc b/src/routing/aodv/aodv-routing-protocol.cc index 25f408cdc..da12ea17b 100644 --- a/src/routing/aodv/aodv-routing-protocol.cc +++ b/src/routing/aodv/aodv-routing-protocol.cc @@ -208,7 +208,7 @@ RoutingProtocol::GetTypeId (void) UintegerValue (2), MakeUintegerAccessor (&RoutingProtocol::RREQ_RETRIES), MakeUintegerChecker ()) - .AddAttribute ("NodeTraversalTime", "Conservative estimate of the average one hop traversal time for packets and should include" + .AddAttribute ("NodeTraversalTime", "Conservative estimate of the average one hop traversal time for packets and should include " "queuing delays, interrupt processing times and transfer times.", TimeValue (MilliSeconds (40)), MakeTimeAccessor (&RoutingProtocol::NODE_TRAVERSAL_TIME), @@ -238,8 +238,6 @@ RoutingProtocol::GetTypeId (void) UintegerValue (7), MakeUintegerAccessor (&RoutingProtocol::TTL_THRESHOLD), MakeUintegerChecker ()) - - ; return tid; } @@ -263,8 +261,8 @@ void RoutingProtocol::Start () { NS_LOG_FUNCTION (this); - // Open UDP sockets for control traffic on each IP interface - + + // Open sockets for control traffic on each IP interface const Ipv4Address loopback ("127.0.0.1"); for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++) { @@ -313,18 +311,19 @@ RoutingProtocol::RouteOutput (Ptr p, const Ipv4Header &header, uint32_t sockerr = Socket::ERROR_NOTERROR; NS_LOG_LOGIC("exist route to " << route->GetDestination() << " from iface " << route->GetSource()); UpdateRouteLifeTime(dst, ACTIVE_ROUTE_TIMEOUT); - return route; } else { QueueEntry newEntry (p, header, m_scb, m_ecb); m_queue.Enqueue (newEntry); sockerr = Socket::ERROR_NOROUTETOHOST; - if (rt.GetFlag() == RTF_DOWN) SendRequest (dst, false, true, rt.GetHop() + TTL_INCREMENT); - else if(rt.GetFlag() != RTF_IN_SEARCH) SendRequest (dst, false, true, TTL_START); - return route; + if (rt.GetFlag() == RTF_DOWN) + SendRequest (dst, false, true, rt.GetHop() + TTL_INCREMENT); + else + if(rt.GetFlag() != RTF_IN_SEARCH) + SendRequest (dst, false, true, TTL_START); } - + return route; } bool @@ -482,7 +481,6 @@ RoutingProtocol::IsMyOwnPacket (Ipv4Address src) return false; } -// TODO add use an expanding ring search technique void RoutingProtocol::SendRequest (Ipv4Address dst, bool D, bool G, uint16_t ttl) { @@ -505,8 +503,10 @@ RoutingProtocol::SendRequest (Ipv4Address dst, bool D, bool G, uint16_t ttl) } rreqHeader.SetHopCount (rt.GetHop ()); - if(rt.GetValidSeqNo()) rreqHeader.SetDstSeqno (rt.GetSeqNo ()); - else rreqHeader.SetUnknownSeqno (true); + if (rt.GetValidSeqNo()) + rreqHeader.SetDstSeqno (rt.GetSeqNo ()); + else + rreqHeader.SetUnknownSeqno (true); } else { @@ -529,10 +529,7 @@ RoutingProtocol::SendRequest (Ipv4Address dst, bool D, bool G, uint16_t ttl) rreqHeader.SetId (m_requestId); rreqHeader.SetHopCount (0); - - - // Send RREQ as subnet directed broadcast from each (own) interface - + // Send RREQ as subnet directed broadcast from each interface used by aodv for (std::map , Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j != m_socketAddresses.end (); ++j) { Ptr socket = j->first; @@ -549,10 +546,12 @@ RoutingProtocol::SendRequest (Ipv4Address dst, bool D, bool G, uint16_t ttl) socket->Send (packet); } - /** - * To reduce congestion in a network, repeated attempts by a source node at route discovery - * for a single destination MUST utilize a binary exponential backoff. - */ + /* + * Schedule RREQ retry. + * + * To reduce congestion in a network, repeated attempts by a source node at route discovery + * for a single destination MUST utilize a binary exponential backoff. + */ if (m_addressReqTimer.find(dst) == m_addressReqTimer.end()) { Timer timer (Timer::CANCEL_ON_DESTROY); @@ -773,7 +772,6 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s if(ipv4Header.GetTtl() < 2) return; - for (std::map , Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j != m_socketAddresses.end (); ++j) { Ptr socket = j->first; @@ -854,7 +852,6 @@ RoutingProtocol::SendReplyByIntermediateNode (RoutingTableEntry & toDst, Routing /*destination address*/toDst.GetNextHop(), /*id*/0 , /*TTL*/ toDst.GetHop()); socket = FindSocketWithInterfaceAddress (toDst.GetInterface ().GetLocal ()); socket->SendTo (packetToDst, 0, InetSocketAddress (toDst.GetNextHop(), AODV_PORT)); - } } @@ -945,7 +942,7 @@ RoutingProtocol::RecvReply (Ptr p, Ipv4Address receiver, Ipv4Address sen m_routingTable.AddRoute (newEntry); } // Acknowledge receipt of the RREP by sending a RREP-ACK message back - if(rrepHeader.GetAckRequired()) SendReplyAck(sender); + if (rrepHeader.GetAckRequired()) SendReplyAck(sender); NS_LOG_LOGIC ("receiver " << receiver << " origin " << rrepHeader.GetOrigin ()); if ( FindSocketWithInterfaceAddress (rrepHeader.GetOrigin ()) != 0 ) { @@ -967,7 +964,6 @@ RoutingProtocol::RecvReply (Ptr p, Ipv4Address receiver, Ipv4Address sen toOrigin.SetLifeTime ( std::max(ACTIVE_ROUTE_TIMEOUT, toOrigin.GetLifeTime ()) ); m_routingTable.Update (toOrigin.GetDestination (), toOrigin); - // Update information about precursors m_routingTable.LookupRoute (rrepHeader.GetDst (), toDst); toDst.InsertPrecursor (toOrigin.GetNextHop ()); @@ -1101,8 +1097,10 @@ RoutingProtocol::RouteRequestTimerExpire(Ipv4Address dst, uint16_t lastTtl) NS_LOG_LOGIC("Send new RREQ to " << dst); if (toDst.GetFlag() == RTF_IN_SEARCH) { - if(lastTtl > TTL_THRESHOLD) SendRequest (dst, false, true, NET_DIAMETER); - else SendRequest (dst, false, true, lastTtl + TTL_INCREMENT); + if (lastTtl > TTL_THRESHOLD) + SendRequest (dst, false, true, NET_DIAMETER); + else + SendRequest (dst, false, true, lastTtl + TTL_INCREMENT); } } @@ -1344,7 +1342,6 @@ RoutingProtocol::HandleLinkFailure (Ipv4Address addr) // TODO } - void RoutingProtocol::RtPurge () { @@ -1352,8 +1349,5 @@ RoutingProtocol::RtPurge () m_routingTable.Purge(DELETE_PERIOD); // TODO AODV::rt_purge() } -//----------------------------------------------------------------------------- -// TODO: NeighborList, RequestIdCache -//----------------------------------------------------------------------------- } } diff --git a/src/routing/aodv/aodv-routing-protocol.h b/src/routing/aodv/aodv-routing-protocol.h index 076d45f7e..5ea831143 100644 --- a/src/routing/aodv/aodv-routing-protocol.h +++ b/src/routing/aodv/aodv-routing-protocol.h @@ -47,7 +47,6 @@ namespace ns3 { namespace aodv { - /** * \ingroup aodv * \brief AODV routing protocol @@ -75,7 +74,6 @@ public: //\} private: - ///\name Protocol parameters. TODO document //\{ Time MAX_QUEUE_TIME; @@ -176,8 +174,6 @@ private: /// Routing table RoutingTable m_routingTable; - /// Routing entry for desired destination - std::vector m_desired; /// A "drop-front" queue used by the routing layer to buffer packets to which it does not have a route. AodvQueue m_queue; /// Broadcast ID @@ -221,7 +217,7 @@ private: /// Process hello message void ProcessHello(RrepHeader const & rrepHeader, Ipv4Address receiverIfaceAddr); - ///\name Recv + ///\name Receive control packets //\{ /// Receive and process control packet void RecvAodv (Ptr socket); @@ -229,7 +225,7 @@ private: void RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address src, Ipv4Header ipv4Header); /// Receive RREP void RecvReply (Ptr p, Ipv4Address my ,Ipv4Address src, Ipv4Header ipv4Header); - /// receive RREP_ACK + /// Receive RREP_ACK void RecvReplyAck(Ipv4Address neighbor); /// Receive RERR from node with address src void RecvError (Ptr p, Ipv4Address src); @@ -237,9 +233,11 @@ private: ///\name Send //\{ + /// Forward packet from route request queue void SendPacketFromQueue(Ipv4Address dst, Ptr route); + /// Aux. send helper void Send(Ptr, Ptr, const Ipv4Header &); - /// Send hello. TODO send independent hello per interface + /// Send hello void SendHello (); /// Send RREQ void SendRequest (Ipv4Address dst, bool D,bool G, uint16_t ttl); @@ -253,13 +251,13 @@ private: void SendReplyByIntermediateNode (RoutingTableEntry & toDst, RoutingTableEntry & toOrigin, bool gratRep); /// Send RREP_ACK void SendReplyAck (Ipv4Address neighbor); - ///\name Send RERR - //\{ + /// Initiate RERR void SendRerrWhenBreaksLinkToNextHop (Ipv4Address nextHop); + /// Forward RERR void SendRerrMessage(Ptr packet, std::vector precursors); //\} - //\} + /// Notify that packet is dropped for some reason void Drop(Ptr, const Ipv4Header &, Socket::SocketErrno) {} ///\name Timers. TODO comment each one diff --git a/src/routing/aodv/aodv-rqueue.cc b/src/routing/aodv/aodv-rqueue.cc index 511554e5b..816ae605b 100644 --- a/src/routing/aodv/aodv-rqueue.cc +++ b/src/routing/aodv/aodv-rqueue.cc @@ -72,7 +72,6 @@ AodvQueue::DropPacketWithDst (Ipv4Address dst) m_queue.erase (i, m_queue.end()); } - bool AodvQueue::Dequeue(Ipv4Address dst, QueueEntry & entry) { diff --git a/src/routing/aodv/aodv-rqueue.h b/src/routing/aodv/aodv-rqueue.h index 0b8a9ab3b..12fe44b23 100644 --- a/src/routing/aodv/aodv-rqueue.h +++ b/src/routing/aodv/aodv-rqueue.h @@ -34,12 +34,9 @@ #include #include "ns3/ipv4-routing-protocol.h" - namespace ns3 { namespace aodv { - - /// The maximum number of packets that we allow a routing protocol to buffer. #define AODV_RTQ_MAX_LEN 64 /// The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds. @@ -50,8 +47,8 @@ namespace aodv { */ struct QueueEntry { - typedef Callback, Ptr, const Ipv4Header &> UnicastForwardCallback; - typedef Callback, const Ipv4Header &, Socket::SocketErrno > ErrorCallback; + typedef Ipv4RoutingProtocol::UnicastForwardCallback UnicastForwardCallback; + typedef Ipv4RoutingProtocol::ErrorCallback ErrorCallback; Ptr m_packet; Ipv4Header m_header; @@ -60,8 +57,11 @@ struct QueueEntry /// Expire time for queue entry Time m_expire; /// c-tor - QueueEntry(Ptr pa = 0, Ipv4Header const & h = Ipv4Header(), UnicastForwardCallback ucb = 0, ErrorCallback ecb = 0, Time exp = Seconds(0)) : m_packet(pa), - m_header(h), m_ucb(ucb), m_ecb(ecb), m_expire(exp) {} + QueueEntry(Ptr pa = 0, Ipv4Header const & h = Ipv4Header(), + UnicastForwardCallback ucb = UnicastForwardCallback(), + ErrorCallback ecb = ErrorCallback(), + Time exp = Seconds(0)) + : m_packet(pa), m_header(h), m_ucb(ucb), m_ecb(ecb), m_expire(exp) {} /** * Compare queue entries * \return true if equal @@ -80,7 +80,9 @@ struct QueueEntry }; /** * \ingroup aodv - * \brief AODV Queue + * \brief AODV route request queue + * + * Since AODV is an on demand routing we queue requests while looking for route. */ class AodvQueue { @@ -100,7 +102,6 @@ public: /// Number of entries uint32_t GetSize (); - private: std::vector m_queue; /// Remove and return first entry from queue diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h index baf29f84b..930519229 100644 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -38,24 +38,26 @@ #include "ns3/timer.h" #include "ns3/net-device.h" - namespace ns3 { namespace aodv { #define INFINITY2 0xff -// #define DELETE_PERIOD 10 // seconds. TODO: remove defines +/** + * \ingroup aodv + * \brief Route record states + */ enum RouteFlags { - RTF_DOWN = 0, - RTF_UP = 1, - RTF_IN_REPAIR = 2, - RTF_IN_SEARCH = 3 + RTF_DOWN = 0, //!< RTF_DOWN + RTF_UP = 1, //!< RTF_UP + RTF_IN_REPAIR = 2,//!< RTF_IN_REPAIR + RTF_IN_SEARCH = 3 //!< RTF_IN_SEARCH }; /** * \ingroup aodv - * \brief Route Table Entry + * \brief Routing table entry */ class RoutingTableEntry { @@ -98,7 +100,6 @@ public: void GetPrecursors(std::vector & prec) const; //\} - /// Mark entry as "down" (i.e. disable it) void Invalidate (Time badLinkLifetime); ///\name Fields @@ -185,7 +186,7 @@ public: /** * \ingroup aodv - * The Routing Table + * The Routing table used by AODV protocol */ class RoutingTable {