21 #include "ns3/drop-tail-queue.h"
22 #include "ns3/packet.h"
23 #include "ns3/queue-disc.h"
24 #include "ns3/simulator.h"
47 void AddHeader()
override;
185 c->SetQueueDisc(CreateObject<TestChildQueueDisc>());
320 void DoRun()
override;
349 :
TestCase(
"Sanity check on the queue disc traces and statistics")
358 "Verify that the number of queued packets is computed correctly");
361 "Verify that the number of queued packets is computed correctly");
365 "Verify that the number of queued bytes is computed correctly");
368 "Verify that the number of queued bytes is computed correctly");
373 uint32_t nDbePackets,
381 "Verify that the number of packets dropped before enqueue is computed correctly");
385 "Verify that the number of packets dropped before enqueue is computed correctly");
390 "Verify that the number of bytes dropped before enqueue is computed correctly");
394 "Verify that the number of bytes dropped before enqueue is computed correctly");
399 uint32_t nDadPackets,
407 "Verify that the number of packets dropped after dequeue is computed correctly");
411 "Verify that the number of packets dropped after dequeue is computed correctly");
416 "Verify that the number of bytes dropped after dequeue is computed correctly");
420 "Verify that the number of bytes dropped after dequeue is computed correctly");
427 uint32_t pktSizeUnit = 100;
446 for (uint16_t i = 1; i <= 4; i++)
448 root->
Enqueue(Create<QdTestItem>(Create<Packet>(pktSizeUnit * i), dest));
450 CheckQueued(root, i, pktSizeUnit * i * (i + 1) / 2);
454 CheckQueued(child, i, pktSizeUnit * i * (i + 1) / 2);
461 root->
Enqueue(Create<QdTestItem>(Create<Packet>(pktSizeUnit * 5), dest));
485 "The peeked packet has not the expected size");
501 "The peeked packet has not the expected size");
517 "The dequeued packet has not the expected size");
533 "The dequeued packet has not the expected size");
557 root->
Enqueue(Create<QdTestItem>(Create<Packet>(pktSizeUnit), dest));
573 "The dequeued packet has not the expected size");
583 Simulator::Destroy();
void AddHeader() override
Add the header to the packet.
bool Mark() override
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
QdTestItem(Ptr< Packet > p, const Address &addr)
Constructor.
Queue Disc Traces Test Case.
QueueDiscTracesTestCase()
void DoRun() override
Implementation to actually run this TestCase.
std::map< Ptr< QueueDisc >, TestCounter > m_counter
counters for the queue discs
void CheckDroppedAfterDequeue(Ptr< QueueDisc > qd, uint32_t nDadPackets, uint32_t nDadBytes)
Check that packets/bytes dropped after dequeue are consistent with what is expected.
void CheckDroppedBeforeEnqueue(Ptr< QueueDisc > qd, uint32_t nDbePackets, uint32_t nDbeBytes)
Check that packets/bytes dropped before enqueue are consistent with what is expected.
void CheckQueued(Ptr< QueueDisc > qd, uint32_t nPackets, uint32_t nBytes)
Check that queued packets/bytes are consistent with what is expected.
Queue Disc Traces Test Suite.
QueueDiscTracesTestSuite()
Test Child Queue Disc that may drop packets before enqueue or after dequeue.
static constexpr const char * AFTER_DEQUEUE
Drop after dequeue.
~TestChildQueueDisc() override
bool DoEnqueue(Ptr< QueueDiscItem > item) override
This function actually enqueues a packet into the queue disc.
Ptr< QueueDiscItem > DoDequeue() override
This function actually extracts a packet from the queue disc.
TestChildQueueDisc()
Constructor.
void InitializeParams() override
Initialize parameters (if any) before the first packet is enqueued.
static constexpr const char * BEFORE_ENQUEUE
Drop before enqueue.
bool CheckConfig() override
Check whether the current configuration is correct.
Keep statistics based on traces.
void PacketDequeued(Ptr< const QueueDiscItem > item)
Update statistics after a packet has been dequeued.
void PacketDad(Ptr< const QueueDiscItem > item, const char *reason)
Update statistics after a packet has been dropped after dequeue.
void PacketDbe(Ptr< const QueueDiscItem > item, const char *reason)
Update statistics after a packet has been dropped before enqueue.
uint32_t m_nDbeBytes
Number of packets dropped before enqueue.
void PacketEnqueued(Ptr< const QueueDiscItem > item)
Update statistics after a packet has been enqueued.
uint32_t m_nPackets
Number of queued packets.
uint32_t m_nBytes
Number of queued bytes.
TestCounter()
Constructor.
uint32_t m_nDbePackets
Number of packets dropped before enqueue.
uint32_t m_nDadBytes
Number of packets dropped after dequeue.
uint32_t m_nDadPackets
Number of packets dropped after dequeue.
void ConnectTraces(Ptr< QueueDisc > qd)
Connect private methods to the queue disc traces.
Test Parent Queue Disc having a child of type TestChildQueueDisc.
TestParentQueueDisc()
Constructor.
Ptr< QueueDiscItem > DoDequeue() override
This function actually extracts a packet from the queue disc.
bool CheckConfig() override
Check whether the current configuration is correct.
void InitializeParams() override
Initialize parameters (if any) before the first packet is enqueued.
bool DoEnqueue(Ptr< QueueDiscItem > item) override
This function actually enqueues a packet into the queue disc.
~TestParentQueueDisc() override
a polymophic address class
A FIFO packet queue that drops tail-end packets on overflow.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
void Initialize()
Invoke DoInitialize on all Objects aggregated to this one.
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
void AddQueueDiscClass(Ptr< QueueDiscClass > qdClass)
Add a queue disc class to the tail of the list of classes.
uint32_t GetNPackets() const
Get the number of packets stored by the queue disc.
uint32_t GetNBytes() const
Get the amount of bytes stored by the queue disc.
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
void DropAfterDequeue(Ptr< const QueueDiscItem > item, const char *reason)
Perform the actions required when the queue disc is notified of a packet dropped after dequeue.
const Stats & GetStats()
Retrieve all the collected statistics.
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
Ptr< QueueDiscItem > Dequeue()
Extract from the queue disc the packet that has been dequeued by calling Peek, if any,...
Ptr< const QueueDiscItem > Peek()
Get a copy of the next packet the queue discipline will extract.
void DropBeforeEnqueue(Ptr< const QueueDiscItem > item, const char *reason)
Perform the actions required when the queue disc is notified of a packet dropped before enqueue.
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
@ UNIT
This test suite implements a Unit Test.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
QueueDiscTracesTestSuite g_queueDiscTracesTestSuite
the test suite
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
@ SINGLE_INTERNAL_QUEUE
Used by queue discs with single internal queue.
@ SINGLE_CHILD_QUEUE_DISC
Used by queue discs with single child queue disc.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Structure that keeps the queue disc statistics.
uint64_t nTotalDroppedBytesBeforeEnqueue
Total bytes dropped before enqueue.
uint64_t nTotalDroppedBytesAfterDequeue
Total bytes dropped after dequeue.
uint32_t nTotalDroppedPacketsBeforeEnqueue
Total packets dropped before enqueue.
uint32_t nTotalDroppedPacketsAfterDequeue
Total packets dropped after dequeue.