From 3f387016b9d30cefd55f017af4cbbcc9f78a084b Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Mon, 27 Mar 2017 11:08:38 +0200 Subject: [PATCH] network: Fix valgrind errors due to ConnectQueueTraces --- .../utils/net-device-queue-interface.cc | 14 +++++++++++ .../utils/net-device-queue-interface.h | 23 +++++++++---------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/network/utils/net-device-queue-interface.cc b/src/network/utils/net-device-queue-interface.cc index d875574b6..699021fa2 100644 --- a/src/network/utils/net-device-queue-interface.cc +++ b/src/network/utils/net-device-queue-interface.cc @@ -193,6 +193,20 @@ void NetDeviceQueueInterface::DoDispose (void) { NS_LOG_FUNCTION (this); + + for (auto t : m_traceMap) + { + if (!t.first->TraceDisconnectWithoutContext ("Enqueue", t.second[0]) + || !t.first->TraceDisconnectWithoutContext ("Dequeue", t.second[1]) + || !t.first->TraceDisconnectWithoutContext ("DropAfterDequeue", t.second[1]) + || !t.first->TraceDisconnectWithoutContext ("DropBeforeEnqueue", t.second[2])) + { + NS_LOG_WARN ("NetDeviceQueueInterface: Trying to disconnected a callback that" + " has not been connected to a traced callback"); + } + } + + m_traceMap.clear (); m_txQueuesVector.clear (); Object::DoDispose (); } diff --git a/src/network/utils/net-device-queue-interface.h b/src/network/utils/net-device-queue-interface.h index 85d3c0c4b..274ba2c71 100644 --- a/src/network/utils/net-device-queue-interface.h +++ b/src/network/utils/net-device-queue-interface.h @@ -21,6 +21,7 @@ #define NET_DEVICE_QUEUE_INTERFACE_H #include +#include #include "ns3/callback.h" #include "ns3/object.h" #include "ns3/ptr.h" @@ -333,6 +334,7 @@ private: SelectQueueCallback m_selectQueueCallback; //!< Select queue callback uint8_t m_numTxQueues; //!< Number of transmission queues to create bool m_lateTxQueuesCreation; //!< True if a device wants to create the TX queues by itself + std::map, std::vector > m_traceMap; //!< Map storing all the connected traces }; @@ -355,18 +357,15 @@ NetDeviceQueueInterface::ConnectQueueTraces (Ptr > queue, uint8_t tx NS_ASSERT (queue != 0); NS_ASSERT (txq < GetNTxQueues ()); - queue->TraceConnectWithoutContext ("Enqueue", - MakeBoundCallback (&NetDeviceQueue::PacketEnqueued, - queue, this, txq)); - queue->TraceConnectWithoutContext ("Dequeue", - MakeBoundCallback (&NetDeviceQueue::PacketDequeued, - queue, this, txq)); - queue->TraceConnectWithoutContext ("DropAfterDequeue", - MakeBoundCallback (&NetDeviceQueue::PacketDequeued, - queue, this, txq)); - queue->TraceConnectWithoutContext ("DropBeforeEnqueue", - MakeBoundCallback (&NetDeviceQueue::PacketDiscarded, - queue, this, txq)); + m_traceMap.emplace (queue, std::initializer_list { + MakeBoundCallback (&NetDeviceQueue::PacketEnqueued, queue, this, txq), + MakeBoundCallback (&NetDeviceQueue::PacketDequeued, queue, this, txq), + MakeBoundCallback (&NetDeviceQueue::PacketDiscarded, queue, this, txq) }); + + queue->TraceConnectWithoutContext ("Enqueue", m_traceMap[queue][0]); + queue->TraceConnectWithoutContext ("Dequeue", m_traceMap[queue][1]); + queue->TraceConnectWithoutContext ("DropAfterDequeue", m_traceMap[queue][1]); + queue->TraceConnectWithoutContext ("DropBeforeEnqueue", m_traceMap[queue][2]); } template