Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Mon, 07 Jul 2008 10:37:09 +0100
changeset 3447 48f371a8ae8e
parent 3446 8491c6c05d22
child 3448 0bd851bb1225
Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
src/devices/csma/csma-channel.cc
src/devices/csma/csma-net-device.cc
src/devices/csma/csma-net-device.h
--- a/src/devices/csma/csma-channel.cc	Mon Jul 07 10:26:00 2008 +0100
+++ b/src/devices/csma/csma-channel.cc	Mon Jul 07 10:37:09 2008 +0100
@@ -235,9 +235,9 @@
   uint32_t devId = 0;
   for (it = m_deviceList.begin (); it < m_deviceList.end(); it++) 
     {
-      if (it->IsActive () && m_currentSrc != devId)
+      if (it->IsActive ())
       {
-        it->devicePtr->Receive (m_currentPkt->Copy ());
+        it->devicePtr->Receive (m_currentPkt->Copy (), m_deviceList[m_currentSrc].devicePtr);
       }
       devId++;
     }
--- a/src/devices/csma/csma-net-device.cc	Mon Jul 07 10:26:00 2008 +0100
+++ b/src/devices/csma/csma-net-device.cc	Mon Jul 07 10:37:09 2008 +0100
@@ -452,12 +452,23 @@
   m_receiveErrorModel = em; 
 }
 
-  void
-CsmaNetDevice::Receive (Ptr<Packet> packet)
+void
+CsmaNetDevice::Receive (Ptr<Packet> packet, Ptr<CsmaNetDevice> senderDevice)
 {
   NS_LOG_FUNCTION_NOARGS ();
   NS_LOG_LOGIC ("UID is " << packet->GetUid ());
 
+
+  //
+  // We never forward up packets that we sent. Real devices don't do this since
+  // their receivers are disabled during send, so we don't. Drop the packet
+  // silently (no tracing) since it would really never get here in a real device.
+  // 
+  if (senderDevice == this)
+    {
+      return;
+    }
+
 // 
 // Only receive if the send side of net device is enabled
 //
--- a/src/devices/csma/csma-net-device.h	Mon Jul 07 10:26:00 2008 +0100
+++ b/src/devices/csma/csma-net-device.h	Mon Jul 07 10:37:09 2008 +0100
@@ -158,8 +158,9 @@
    *
    * @see CsmaChannel
    * \param p a reference to the received packet
+   * \param sender the CsmaNetDevice that transmitted the packet in the first place
    */
-  void Receive (Ptr<Packet> p);
+  void Receive (Ptr<Packet> p, Ptr<CsmaNetDevice> sender);
 
   /**
    * Is the send side of the network device enabled?