Implement the promiscuous receive callback for CsmaNetDevice.
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Fri, 04 Jul 2008 15:37:54 +0100
changeset 3438 86e262420fbf
parent 3437 7cec39fe195c
child 3439 a64d1da0d6bf
Implement the promiscuous receive callback for CsmaNetDevice.
src/devices/csma/csma-net-device.cc
src/devices/csma/csma-net-device.h
--- a/src/devices/csma/csma-net-device.cc	Fri Jul 04 15:37:03 2008 +0100
+++ b/src/devices/csma/csma-net-device.cc	Fri Jul 04 15:37:54 2008 +0100
@@ -470,6 +470,7 @@
   if (m_encapMode == RAW)
     {
       m_rxTrace (packet);
+      m_promiscRxCallback (this, packet->Copy (), 0, GetAddress (), GetBroadcast (), true);
       m_rxCallback (this, packet, 0, GetBroadcast ());
       return;
     }
@@ -522,15 +523,6 @@
   Mac48Address broadcast = Mac48Address::ConvertFrom (GetBroadcast ());
   Mac48Address destination = Mac48Address::ConvertFrom (GetAddress ());
 
-  if ((header.GetDestination () != broadcast) &&
-      (mcDest != multicast) &&
-      (header.GetDestination () != destination))
-    {
-      NS_LOG_LOGIC ("Dropping pkt ");
-      m_dropTrace (packet);
-      return;
-    }
-
   if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) )
     {
       NS_LOG_LOGIC ("Dropping pkt due to error model ");
@@ -561,6 +553,18 @@
           NS_ASSERT (false);
           break;
         }
+
+      if ((header.GetDestination () != broadcast) &&
+          (mcDest != multicast) &&
+          (header.GetDestination () != destination))
+        {
+          NS_LOG_LOGIC ("Not for me: promisc rx, then dropping pkt ");
+          m_promiscRxCallback (this, packet->Copy (), protocol, header.GetSource (), header.GetDestination (), false);
+          m_dropTrace (packet);
+          return;
+        }
+
+      m_promiscRxCallback (this, packet->Copy (), protocol, header.GetSource (), header.GetDestination (), true);
       m_rxTrace (originalPacket);
       m_rxCallback (this, packet, protocol, header.GetSource ());
     }
@@ -828,7 +832,7 @@
 void 
 CsmaNetDevice::SetPromiscuousReceiveCallback (NetDevice::PromiscuousReceiveCallback cb)
 {
-  // TODO
+  m_promiscRxCallback = cb;
 }
 
 } // namespace ns3
--- a/src/devices/csma/csma-net-device.h	Fri Jul 04 15:37:03 2008 +0100
+++ b/src/devices/csma/csma-net-device.h	Fri Jul 04 15:37:54 2008 +0100
@@ -529,6 +529,11 @@
   NetDevice::ReceiveCallback m_rxCallback;
 
   /**
+   * The callback used to notify higher layers that a packet has been received in promiscuous mode.
+   */
+  NetDevice::PromiscuousReceiveCallback m_promiscRxCallback;
+
+  /**
    * The interface index (really net evice index) that has been assigned to 
    * this network device.
    */