AODV cosmetics
authorPavel Boyko <boyko@iitp.ru>
Sun, 02 Aug 2009 15:19:07 +0400
changeset 5625 022e4ebc7afd
parent 5624 b89bf6234bb5
child 5626 f16ef78c73de
AODV cosmetics
src/routing/aodv/aodv-routing-protocol.cc
src/routing/aodv/aodv-routing-protocol.h
src/routing/aodv/aodv-rqueue.cc
src/routing/aodv/aodv-rqueue.h
src/routing/aodv/aodv-rtable.h
--- a/src/routing/aodv/aodv-routing-protocol.cc	Sun Aug 02 00:32:00 2009 +0400
+++ b/src/routing/aodv/aodv-routing-protocol.cc	Sun Aug 02 15:19:07 2009 +0400
@@ -208,7 +208,7 @@
                      UintegerValue (2),
                      MakeUintegerAccessor (&RoutingProtocol::RREQ_RETRIES),
                      MakeUintegerChecker<uint32_t> ())
-      .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 @@
                      UintegerValue (7),
                      MakeUintegerAccessor (&RoutingProtocol::TTL_THRESHOLD),
                      MakeUintegerChecker<uint16_t> ())
-
-
   ;
   return tid;
 }
@@ -263,8 +261,8 @@
 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 @@
     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 @@
   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 @@
     }
 
     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 @@
   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<Ptr<Socket> , Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j != m_socketAddresses.end (); ++j)
   {
     Ptr<Socket> socket = j->first;
@@ -549,10 +546,12 @@
     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 @@
   if(ipv4Header.GetTtl() < 2)
     return;
 
-
   for (std::map<Ptr<Socket> , Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j != m_socketAddresses.end (); ++j)
   {
     Ptr<Socket> socket = j->first;
@@ -854,7 +852,6 @@
                 /*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 @@
     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 @@
   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 @@
   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 @@
   // TODO
 }
 
-
 void
 RoutingProtocol::RtPurge ()
 {
@@ -1352,8 +1349,5 @@
   m_routingTable.Purge(DELETE_PERIOD);
   // TODO AODV::rt_purge()
 }
-//-----------------------------------------------------------------------------
-// TODO: NeighborList, RequestIdCache
-//-----------------------------------------------------------------------------
 }
 }
--- a/src/routing/aodv/aodv-routing-protocol.h	Sun Aug 02 00:32:00 2009 +0400
+++ b/src/routing/aodv/aodv-routing-protocol.h	Sun Aug 02 15:19:07 2009 +0400
@@ -47,7 +47,6 @@
 {
 namespace aodv
 {
-
 /**
  * \ingroup aodv
  * \brief AODV routing protocol
@@ -75,7 +74,6 @@
   //\}
   
 private:
-
   ///\name Protocol parameters. TODO document
   //\{
   Time MAX_QUEUE_TIME;
@@ -176,8 +174,6 @@
 
   /// Routing table
   RoutingTable m_routingTable;
-  /// Routing entry for desired destination
-  std::vector<RoutingTableEntry>  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 @@
   /// 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> socket);
@@ -229,7 +225,7 @@
   void RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address src, Ipv4Header ipv4Header);
   /// Receive RREP
   void RecvReply (Ptr<Packet> 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<Packet> p, Ipv4Address src);
@@ -237,9 +233,11 @@
   
   ///\name Send
   //\{
+  /// Forward packet from route request queue
   void SendPacketFromQueue(Ipv4Address dst, Ptr<Ipv4Route> route);
+  /// Aux. send helper
   void Send(Ptr<Ipv4Route>, Ptr<const Packet>, 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 @@
   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> packet,  std::vector<Ipv4Address> precursors);
   //\}
-  //\}
   
+  /// Notify that packet is dropped for some reason 
   void Drop(Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno) {}
 
   ///\name Timers. TODO comment each one
--- a/src/routing/aodv/aodv-rqueue.cc	Sun Aug 02 00:32:00 2009 +0400
+++ b/src/routing/aodv/aodv-rqueue.cc	Sun Aug 02 15:19:07 2009 +0400
@@ -72,7 +72,6 @@
   m_queue.erase (i, m_queue.end());
 }
 
-
 bool
 AodvQueue::Dequeue(Ipv4Address dst, QueueEntry & entry)
 {
--- a/src/routing/aodv/aodv-rqueue.h	Sun Aug 02 00:32:00 2009 +0400
+++ b/src/routing/aodv/aodv-rqueue.h	Sun Aug 02 15:19:07 2009 +0400
@@ -34,12 +34,9 @@
 #include <vector>
 #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 @@
  */
 struct QueueEntry
 {
-  typedef Callback<void, Ptr<Ipv4Route>, Ptr<const Packet>, const Ipv4Header &> UnicastForwardCallback;
-  typedef Callback<void, Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno > ErrorCallback;
+  typedef Ipv4RoutingProtocol::UnicastForwardCallback UnicastForwardCallback;
+  typedef Ipv4RoutingProtocol::ErrorCallback ErrorCallback;
 
   Ptr<const Packet> m_packet;
   Ipv4Header m_header;
@@ -60,8 +57,11 @@
   /// Expire time for queue entry
   Time m_expire;
   /// c-tor
-  QueueEntry(Ptr<const Packet> 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<const Packet> 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 @@
 };
 /**
  * \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 @@
   /// Number of entries
   uint32_t GetSize ();
 
-
 private:
   std::vector<QueueEntry> m_queue;
   /// Remove and return first entry from queue
--- a/src/routing/aodv/aodv-rtable.h	Sun Aug 02 00:32:00 2009 +0400
+++ b/src/routing/aodv/aodv-rtable.h	Sun Aug 02 15:19:07 2009 +0400
@@ -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 @@
   void GetPrecursors(std::vector<Ipv4Address> & prec) const;
   //\}
 
-
   /// Mark entry as "down" (i.e. disable it)
   void Invalidate (Time badLinkLifetime);
   ///\name Fields
@@ -185,7 +186,7 @@
 
 /**
  * \ingroup aodv
- * The Routing Table
+ * The Routing table used by AODV protocol
  */
 class RoutingTable
 {