From fb12ef3a8bddc19c735b271cd32302c72f117565 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Wed, 8 Mar 2017 18:01:51 +0100 Subject: [PATCH] network: Add support for flow control and BQL to SimpleNetDevice --- src/lte/test/lte-simple-net-device.cc | 2 +- src/network/utils/simple-net-device.cc | 37 +++++++++++++++++++++++++- src/network/utils/simple-net-device.h | 5 ++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/lte/test/lte-simple-net-device.cc b/src/lte/test/lte-simple-net-device.cc index e1e189676..3fab47611 100644 --- a/src/lte/test/lte-simple-net-device.cc +++ b/src/lte/test/lte-simple-net-device.cc @@ -21,7 +21,7 @@ #include "ns3/simulator.h" #include "ns3/pointer.h" #include "ns3/log.h" -#include "ns3/queue.h" +#include "ns3/net-device-queue-interface.h" #include "lte-simple-net-device.h" namespace ns3 { diff --git a/src/network/utils/simple-net-device.cc b/src/network/utils/simple-net-device.cc index 412620a1f..2f451bfda 100644 --- a/src/network/utils/simple-net-device.cc +++ b/src/network/utils/simple-net-device.cc @@ -29,7 +29,7 @@ #include "ns3/string.h" #include "ns3/tag.h" #include "ns3/simulator.h" -#include "ns3/queue.h" +#include "ns3/net-device-queue-interface.h" namespace ns3 { @@ -229,6 +229,40 @@ SimpleNetDevice::SimpleNetDevice () NS_LOG_FUNCTION (this); } +void +SimpleNetDevice::DoInitialize (void) +{ + if (m_queueInterface) + { + NS_ASSERT_MSG (m_queue != 0, "A Queue object has not been attached to the device"); + + // connect the traced callbacks of m_queue to the static methods provided by + // the NetDeviceQueue class to support flow control and dynamic queue limits. + // This could not be done in NotifyNewAggregate because at that time we are + // not guaranteed that a queue has been attached to the netdevice + m_queueInterface->ConnectQueueTraces (m_queue, 0); + } + + NetDevice::DoInitialize (); +} + +void +SimpleNetDevice::NotifyNewAggregate (void) +{ + NS_LOG_FUNCTION (this); + if (m_queueInterface == 0) + { + Ptr ndqi = this->GetObject (); + //verify that it's a valid netdevice queue interface and that + //the netdevice queue interface was not set before + if (ndqi != 0) + { + m_queueInterface = ndqi; + } + } + NetDevice::NotifyNewAggregate (); +} + void SimpleNetDevice::Receive (Ptr packet, uint16_t protocol, Mac48Address to, Mac48Address from) @@ -538,6 +572,7 @@ SimpleNetDevice::DoDispose (void) m_node = 0; m_receiveErrorModel = 0; m_queue->Flush (); + m_queueInterface = 0; if (TransmitCompleteEvent.IsRunning ()) { TransmitCompleteEvent.Cancel (); diff --git a/src/network/utils/simple-net-device.h b/src/network/utils/simple-net-device.h index c4f0bef6d..79c13244d 100644 --- a/src/network/utils/simple-net-device.h +++ b/src/network/utils/simple-net-device.h @@ -36,6 +36,7 @@ template class Queue; class SimpleChannel; class Node; class ErrorModel; +class NetDeviceQueueInterface; /** * \ingroup netdevice @@ -137,11 +138,15 @@ public: protected: virtual void DoDispose (void); + virtual void DoInitialize (void); + virtual void NotifyNewAggregate (void); + private: Ptr m_channel; //!< the channel the device is connected to NetDevice::ReceiveCallback m_rxCallback; //!< Receive callback NetDevice::PromiscReceiveCallback m_promiscCallback; //!< Promiscuous receive callback Ptr m_node; //!< Node this netDevice is associated to + Ptr m_queueInterface; //!< NetDevice queue interface uint16_t m_mtu; //!< MTU uint32_t m_ifIndex; //!< Interface index Mac48Address m_address; //!< MAC address