src/internet-node/arp-cache.cc
changeset 3151 428f8ec6da29
parent 3146 98629e087bb1
--- a/src/internet-node/arp-cache.cc	Sun May 25 14:44:14 2008 -0700
+++ b/src/internet-node/arp-cache.cc	Sun May 25 14:44:36 2008 -0700
@@ -20,11 +20,15 @@
 #include "ns3/assert.h"
 #include "ns3/packet.h"
 #include "ns3/simulator.h"
+#include "ns3/uinteger.h"
+#include "ns3/log.h"
 
 #include "arp-cache.h"
 #include "arp-header.h"
 #include "ipv4-interface.h"
 
+NS_LOG_COMPONENT_DEFINE ("ArpCache");
+
 namespace ns3 {
 
 TypeId 
@@ -47,6 +51,11 @@
                    TimeValue (Seconds (1)),
                    MakeTimeAccessor (&ArpCache::m_waitReplyTimeout),
                    MakeTimeChecker ())
+    .AddAttribute ("PendingQueueSize",
+                   "The size of the queue for packets pending an arp reply.",
+                   UintegerValue (3),
+                   MakeUintegerAccessor (&ArpCache::m_pendingQueueSize),
+                   MakeUintegerChecker<uint32_t> ())
     ;
   return tid;
 }
@@ -54,11 +63,23 @@
 ArpCache::ArpCache ()
   : m_device (0), 
     m_interface (0)
-{}
+{
+  NS_LOG_FUNCTION (this);
+}
 
 ArpCache::~ArpCache ()
 {
+  NS_LOG_FUNCTION (this);
+}
+
+void 
+ArpCache::DoDispose (void)
+{
+  NS_LOG_FUNCTION (this);
   Flush ();
+  m_device = 0;
+  m_interface = 0;
+  Object::DoDispose ();
 }
 
 void
@@ -145,8 +166,7 @@
 
 ArpCache::Entry::Entry (ArpCache *arp)
   : m_arp (arp),
-    m_state (ALIVE),
-    m_waiting ()
+    m_state (ALIVE)
 {}
 
 
@@ -171,23 +191,18 @@
 ArpCache::Entry::MarkDead (void) 
 {
   m_state = DEAD;
-  //NS_ASSERT (m_waiting != 0);
   UpdateSeen ();
 }
-Ptr<Packet>
+void
 ArpCache::Entry::MarkAlive (Address macAddress) 
 {
   NS_ASSERT (m_state == WAIT_REPLY);
-  //NS_ASSERT (m_waiting != 0);
   m_macAddress = macAddress;
   m_state = ALIVE;
   UpdateSeen ();
-  Ptr<Packet> waiting = m_waiting;
-  //m_waiting = 0;
-  return waiting;
 }
 
-Ptr<Packet>
+bool
 ArpCache::Entry::UpdateWaitReply (Ptr<Packet> waiting)
 {
   NS_ASSERT (m_state == WAIT_REPLY);
@@ -195,17 +210,20 @@
    * we dump the previously waiting packet and
    * replace it with this one.
    */
-  Ptr<Packet> old = m_waiting;
-  m_waiting = waiting;
-  return old;
+  if (m_pending.size () >= m_arp->m_pendingQueueSize)
+    {
+      return false;
+    }
+  m_pending.push_back (waiting);
+  return true;
 }
 void 
 ArpCache::Entry::MarkWaitReply (Ptr<Packet> waiting)
 {
   NS_ASSERT (m_state == ALIVE || m_state == DEAD);
-  //NS_ASSERT (m_waiting == 0);
+  NS_ASSERT (m_pending.empty ());
   m_state = WAIT_REPLY;
-  m_waiting = waiting;
+  m_pending.push_back (waiting);
   UpdateSeen ();
 }
 
@@ -245,6 +263,20 @@
       return false;
     }
 }
+Ptr<Packet> 
+ArpCache::Entry::DequeuePending (void)
+{
+  if (m_pending.empty ())
+    {
+      return 0;
+    }
+  else
+    {
+      Ptr<Packet> p = m_pending.front ();
+      m_pending.pop_front ();
+      return p;
+    }
+}
 void 
 ArpCache::Entry::UpdateSeen (void)
 {