From 8a0bcd18ba31cb0f6e760416dd2e44b0ca945b41 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Fri, 4 Jul 2008 15:37:54 +0100 Subject: [PATCH] Implement the promiscuous receive callback for CsmaNetDevice. --- src/devices/csma/csma-net-device.cc | 24 ++++++++++++++---------- src/devices/csma/csma-net-device.h | 5 +++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index 532f2b695..4c8371e36 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -470,6 +470,7 @@ CsmaNetDevice::Receive (Ptr packet) 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 @@ CsmaNetDevice::Receive (Ptr packet) 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 @@ CsmaNetDevice::Receive (Ptr packet) 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 @@ CsmaNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb) void CsmaNetDevice::SetPromiscuousReceiveCallback (NetDevice::PromiscuousReceiveCallback cb) { - // TODO + m_promiscRxCallback = cb; } } // namespace ns3 diff --git a/src/devices/csma/csma-net-device.h b/src/devices/csma/csma-net-device.h index f283c9c47..6649c5991 100644 --- a/src/devices/csma/csma-net-device.h +++ b/src/devices/csma/csma-net-device.h @@ -528,6 +528,11 @@ private: */ 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.