23 #include "ns3/queue-disc.h"
24 #include "ns3/drop-tail-queue.h"
25 #include "ns3/packet.h"
26 #include "ns3/simulator.h"
48 virtual void AddHeader (
void);
49 virtual bool Mark (
void);
190 c->SetQueueDisc (CreateObject<TestChildQueueDisc> ());
329 virtual void DoRun (
void);
358 :
TestCase (
"Sanity check on the queue disc traces and statistics")
366 "Verify that the number of queued packets is computed correctly");
368 "Verify that the number of queued packets is computed correctly");
371 "Verify that the number of queued bytes is computed correctly");
373 "Verify that the number of queued bytes is computed correctly");
382 "Verify that the number of packets dropped before enqueue is computed correctly");
384 "Verify that the number of packets dropped before enqueue is computed correctly");
387 "Verify that the number of bytes dropped before enqueue is computed correctly");
389 "Verify that the number of bytes dropped before enqueue is computed correctly");
398 "Verify that the number of packets dropped after dequeue is computed correctly");
400 "Verify that the number of packets dropped after dequeue is computed correctly");
403 "Verify that the number of bytes dropped after dequeue is computed correctly");
405 "Verify that the number of bytes dropped after dequeue is computed correctly");
412 uint32_t pktSizeUnit = 100;
431 for (uint16_t i = 1; i <= 4; i++)
433 root->
Enqueue (Create<qdTestItem> (Create<Packet>(pktSizeUnit * i), dest));
435 CheckQueued (root, i, pktSizeUnit * i * (i+1) / 2);
439 CheckQueued (child, i, pktSizeUnit * i * (i+1) / 2);
446 root->
Enqueue (Create<qdTestItem> (Create<Packet>(pktSizeUnit * 5), dest));
465 item = root->
Peek ();
468 NS_TEST_ASSERT_MSG_EQ (item->GetSize (), pktSizeUnit * 3,
"The peeked packet has not the expected size");
479 item = root->
Peek ();
482 NS_TEST_ASSERT_MSG_EQ (item->GetSize (), pktSizeUnit * 3,
"The peeked packet has not the expected size");
496 NS_TEST_ASSERT_MSG_EQ (item->GetSize (), pktSizeUnit * 3,
"The dequeued packet has not the expected size");
510 NS_TEST_ASSERT_MSG_EQ (item->GetSize (), pktSizeUnit * 4,
"The dequeued packet has not the expected size");
521 item = root->
Peek ();
534 root->
Enqueue (Create<qdTestItem> (Create<Packet>(pktSizeUnit), dest));
548 NS_TEST_ASSERT_MSG_EQ (item->GetSize (), pktSizeUnit,
"The dequeued packet has not the expected size");
558 Simulator::Destroy ();
Queue Disc Traces Test Case.
QueueDiscTracesTestCase()
virtual void DoRun(void)
Implementation to actually run this TestCase.
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.
std::map< Ptr< QueueDisc >, TestCounter > m_counter
counters for the queue discs
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.
virtual bool CheckConfig(void)
Check whether the current configuration is correct.
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)
This function actually enqueues a packet into the queue disc.
virtual void InitializeParams(void)
Initialize parameters (if any) before the first packet is enqueued.
TestChildQueueDisc()
Constructor.
virtual ~TestChildQueueDisc()
static constexpr const char * BEFORE_ENQUEUE
Drop before enqueue.
virtual Ptr< QueueDiscItem > DoDequeue(void)
This function actually extracts a packet from the queue disc.
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.
virtual Ptr< QueueDiscItem > DoDequeue(void)
This function actually extracts a packet from the queue disc.
virtual ~TestParentQueueDisc()
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)
This function actually enqueues a packet into the queue disc.
virtual bool CheckConfig(void)
Check whether the current configuration is correct.
virtual void InitializeParams(void)
Initialize parameters (if any) before the first packet is enqueued.
a polymophic address class
Introspection did not find any typical Config paths.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
void Initialize(void)
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 GetNBytes(void) const
Get the amount of bytes stored by the queue disc.
Ptr< const QueueDiscItem > Peek(void)
Get a copy of the next packet the queue discipline will extract.
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
Ptr< QueueDiscItem > Dequeue(void)
Extract from the queue disc the packet that has been dequeued by calling Peek, if any,...
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.
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
const Stats & GetStats(void)
Retrieve all the collected statistics.
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.
virtual bool Mark(void)
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
qdTestItem(Ptr< Packet > p, const Address &addr)
Constructor.
virtual void AddHeader(void)
Add the header to the packet.
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, Ts... > MakeCallback(R(T::*memPtr)(Ts...), 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.