26 #include "ns3/cobalt-queue-disc.h"
27 #include "ns3/packet.h"
28 #include "ns3/uinteger.h"
29 #include "ns3/string.h"
30 #include "ns3/double.h"
32 #include "ns3/simulator.h"
54 virtual void AddHeader (
void);
55 virtual bool Mark (
void);
75 m_ecnCapablePacket (ecnCapable)
113 virtual void DoRun (
void);
128 :
TestCase (
"Basic enqueue and dequeue operations, and attribute setting" + std::to_string (mode))
139 uint32_t modeSize = 0;
144 "Verify that we can actually set the attribute Interval");
146 "Verify that we can actually set the attribute Target");
148 "Disable Blue enhancement");
159 true,
"Verify that we can actually set the attribute MaxSize");
160 queue->Initialize ();
170 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 0 * modeSize,
"There should be no packets in queue");
171 queue->Enqueue (Create<CobaltQueueDiscTestItem> (p1, dest,0,
false));
172 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 1 * modeSize,
"There should be one packet in queue");
173 queue->Enqueue (Create<CobaltQueueDiscTestItem> (p2, dest,0,
false));
174 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 2 * modeSize,
"There should be two packets in queue");
175 queue->Enqueue (Create<CobaltQueueDiscTestItem> (p3, dest,0,
false));
176 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 3 * modeSize,
"There should be three packets in queue");
177 queue->Enqueue (Create<CobaltQueueDiscTestItem> (p4, dest,0,
false));
178 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 4 * modeSize,
"There should be four packets in queue");
179 queue->Enqueue (Create<CobaltQueueDiscTestItem> (p5, dest,0,
false));
180 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 5 * modeSize,
"There should be five packets in queue");
181 queue->Enqueue (Create<CobaltQueueDiscTestItem> (p6, dest,0,
false));
182 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 6 * modeSize,
"There should be six packets in queue");
184 NS_TEST_EXPECT_MSG_EQ (queue->GetStats ().GetNDroppedPackets (CobaltQueueDisc::OVERLIMIT_DROP), 0,
"There should be no packets being dropped due to full queue");
188 item = queue->Dequeue ();
190 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 5 * modeSize,
"There should be five packets in queue");
193 item = queue->Dequeue ();
195 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 4 * modeSize,
"There should be four packets in queue");
198 item = queue->Dequeue ();
200 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 3 * modeSize,
"There should be three packets in queue");
203 item = queue->Dequeue ();
205 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 2 * modeSize,
"There should be two packets in queue");
208 item = queue->Dequeue ();
210 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 1 * modeSize,
"There should be one packet in queue");
213 item = queue->Dequeue ();
215 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 0 * modeSize,
"There should be zero packet in queue");
218 item = queue->Dequeue ();
221 NS_TEST_EXPECT_MSG_EQ (queue->GetStats ().GetNDroppedPackets (CobaltQueueDisc::TARGET_EXCEEDED_DROP), 0,
"There should be no packet drops according to Cobalt algorithm");
234 virtual void DoRun (
void);
253 :
TestCase (
"Drop tests verification for both packets and bytes mode")
262 uint32_t modeSize = 0;
274 queue = CreateObject<CobaltQueueDisc> ();
276 true,
"Verify that we can actually set the attribute MaxSize");
278 "Disable Blue enhancement");
279 queue->Initialize ();
290 Simulator::Stop (
Seconds (8.0));
305 for (uint32_t i = 0; i < nPkt; i++)
315 for (uint32_t i = 0; i < nPkt; i++)
317 queue->Enqueue (Create<CobaltQueueDiscTestItem> (Create<Packet> (size), dest, 0,
true));
326 Simulator::Destroy ();
344 virtual void DoRun (
void);
375 :
TestCase (
"Basic mark operations")
400 uint32_t modeSize = 0;
414 true,
"Verify that we can actually set the attribute MaxSize");
416 true,
"Verify that we can actually set the attribute UseEcn");
418 "Disable Blue enhancement");
419 queue->Initialize ();
423 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 20 * modeSize,
"There should be 20 packets in queue.");
427 Time waitUntilFirstDequeue = 2 * queue->GetTarget ();
431 Time waitUntilSecondDequeue = waitUntilFirstDequeue + 2 * queue->GetInterval ();
435 Simulator::Destroy ();
438 queue = CreateObject<CobaltQueueDisc> ();
440 true,
"Verify that we can actually set the attribute MaxSize");
442 true,
"Verify that we can actually set the attribute UseEcn");
444 "Disable Blue enhancement");
445 queue->Initialize ();
449 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 20 * modeSize,
"There should be 20 packets in queue.");
466 Simulator::Destroy ();
469 queue = CreateObject<CobaltQueueDisc> ();
471 true,
"Verify that we can actually set the attribute MaxSize");
473 true,
"Verify that we can actually set the attribute UseEcn");
475 "Disable Blue enhancement");
476 queue->Initialize ();
482 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 20 * modeSize,
"There should be 20 packets in queue.");
499 Simulator::Destroy ();
506 for (uint32_t i = 0; i < nPkt; i++)
508 queue->Enqueue (Create<CobaltQueueDiscTestItem> (Create<Packet> (size), dest, 0, ecnCapable));
515 uint32_t initialMarkCount = queue->GetStats ().GetNMarkedPackets (CobaltQueueDisc::FORCED_MARK);
516 uint32_t initialQSize = queue->GetCurrentSize ().GetValue ();
517 uint32_t initialDropNext = queue->GetDropNext ();
519 uint32_t currentDropCount = 0;
520 uint32_t currentMarkCount = 0;
522 if (initialMarkCount > 0 && currentTime.
GetNanoSeconds () > initialDropNext && testCase == 3)
527 if (initialQSize != 0)
532 currentDropCount = queue->GetStats ().GetNDroppedPackets (CobaltQueueDisc::TARGET_EXCEEDED_DROP);
533 if (currentDropCount != 0)
540 if (initialMarkCount == 0 && currentTime > queue->GetTarget ())
542 if (currentTime < queue->GetInterval ())
544 currentDropCount = queue->GetStats ().GetNDroppedPackets (CobaltQueueDisc::TARGET_EXCEEDED_DROP);
545 currentMarkCount = queue->GetStats ().GetNMarkedPackets (CobaltQueueDisc::FORCED_MARK);
546 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), initialQSize - modeSize,
"There should be 1 packet dequeued.");
549 "Sojourn time has just gone above target from below."
550 "Hence, there should be no marked packets");
552 else if (currentTime >= queue->GetInterval ())
555 currentDropCount = queue->GetStats ().GetNDroppedPackets (CobaltQueueDisc::TARGET_EXCEEDED_DROP);
556 currentMarkCount = queue->GetStats ().GetNMarkedPackets (CobaltQueueDisc::FORCED_MARK);
558 "Sojourn time has been above target for at least interval."
559 "We enter the dropping state and perform initial packet marking"
560 "So there should be only 1 more packet dequeued.");
565 else if (initialMarkCount > 0)
569 currentDropCount = queue->GetStats ().GetNDroppedPackets (CobaltQueueDisc::TARGET_EXCEEDED_DROP);
570 currentMarkCount = queue->GetStats ().GetNMarkedPackets (CobaltQueueDisc::FORCED_MARK);
571 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), initialQSize - modeSize,
"We are in dropping state."
572 "Sojourn is still above target."
573 "There should be only 1 more packet dequeued");
576 "current dropnext is equal to current time.");
580 currentDropCount = queue->GetStats ().GetNDroppedPackets (CobaltQueueDisc::TARGET_EXCEEDED_DROP);
581 currentMarkCount = queue->GetStats ().GetNMarkedPackets (CobaltQueueDisc::FORCED_MARK);
582 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), initialQSize - modeSize,
"We are in dropping state."
583 "It's time for packet to be marked"
584 "So there should be only 1 more packet dequeued");
588 "to number of packets in the queue before first mark as the behavior until packet N should be the same.");
592 else if (testCase == 3)
594 if (initialMarkCount == 0 && currentTime > queue->GetTarget ())
596 if (currentTime < queue->GetInterval ())
598 currentDropCount = queue->GetStats ().GetNDroppedPackets (CobaltQueueDisc::TARGET_EXCEEDED_DROP);
599 currentMarkCount = queue->GetStats ().GetNMarkedPackets (CobaltQueueDisc::FORCED_MARK);
600 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), initialQSize - modeSize,
"There should be 1 packet dequeued.");
603 "Sojourn time has just gone above target from below."
604 "Hence, there should be no marked packets");
606 else if (currentTime >= queue->GetInterval ())
608 currentDropCount = queue->GetStats ().GetNDroppedPackets (CobaltQueueDisc::TARGET_EXCEEDED_DROP);
609 currentMarkCount = queue->GetStats ().GetNMarkedPackets (CobaltQueueDisc::FORCED_MARK);
611 "Sojourn time has been above target for at least interval."
612 "We enter the dropping state and perform initial packet marking"
613 "So there should be only 1 more packet dequeued.");
618 else if (initialMarkCount > 0)
622 currentDropCount = queue->GetStats ().GetNDroppedPackets (CobaltQueueDisc::TARGET_EXCEEDED_DROP);
623 currentMarkCount = queue->GetStats ().GetNMarkedPackets (CobaltQueueDisc::FORCED_MARK);
624 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), initialQSize - modeSize,
"We are in dropping state."
625 "Sojourn is still above target."
626 "So there should be only 1 more packet dequeued");
629 "as dropnext is equal to current time");
633 currentDropCount = queue->GetStats ().GetNDroppedPackets (CobaltQueueDisc::TARGET_EXCEEDED_DROP);
634 currentMarkCount = queue->GetStats ().GetNMarkedPackets (CobaltQueueDisc::FORCED_MARK);
636 "It's time for packet to be dropped as packets are not ecnCapable"
637 "The number of packets dequeued equals to the number of times m_dropNext is updated plus initial dequeue");
659 virtual void DoRun (
void);
693 :
TestCase (
"Test CE Threshold marking")
706 for (uint32_t i = 0; i < nPkt; i++)
708 queue->Enqueue (Create<CobaltQueueDiscTestItem> (Create<Packet> (size), dest, 0,
true));
715 for (uint32_t i = 0; i < nPkt; i++)
728 NS_TEST_EXPECT_MSG_EQ (queue->GetStats ().GetNMarkedPackets (CobaltQueueDisc::CE_THRESHOLD_EXCEEDED_MARK), 1,
"There should be only 1 packet"
729 "mark, the delay between the enqueueing of the packets decreased after the"
730 "1st mark (packet enqueued at 11ms) and increased for the packet enqueued after 20.6ms."
731 "Queue delay remains below or equal to 1ms for the packet enqueued before 28ms");
735 NS_TEST_EXPECT_MSG_EQ (queue->GetStats ().GetNMarkedPackets (CobaltQueueDisc::CE_THRESHOLD_EXCEEDED_MARK), 3,
"There should be 3 packet"
736 "marks, the delay between the enqueueing of the packets decreased after 1st mark"
737 "(packet enqueued at 11ms) and increased for the packet enqueued after 20.6ms."
738 "Queue delay remains below 1ms for the packets enqueued before 28ms and increases"
739 "for the packets enqueued after 28ms.");
746 for (uint32_t i = 0; i < nPkt; i++)
757 uint32_t modeSize = 0;
769 true,
"Verify that we can actually set the attribute UseEcn");
771 true,
"Verify that we can actually set the attribute UseEcn");
773 "Disable Blue enhancement");
774 queue->Initialize ();
794 Time waitUntilDecreasingEnqueueDelay = waitUntilFirstMark +
MilliSeconds(9);
801 Simulator::Destroy ();
824 virtual void DoRun (
void);
848 :
TestCase (
"Enhanced Blue tests verification for both packets and bytes mode")
862 uint32_t modeSize = 0;
873 queue->Initialize ();
874 queue->AssignStreams (1);
875 Enqueue (queue, modeSize, 200);
878 Simulator::Stop (
Seconds (8.0));
884 NS_TEST_EXPECT_MSG_EQ (queue->GetPdrop (), 0.234375,
"Pdrop should be increased by 1/256 for every packet whose sojourn time is above 400ms."
885 " From the 41st dequeue until the last one, sojourn time is above 400ms, so 60 packets have sojourn time above 400ms"
886 "hence Pdrop should be increased 60*(1/256) which is 0.234375");
888 Simulator::Destroy ();
891 queue = CreateObject<CobaltQueueDisc> ();
893 true,
"Verify that we can actually set the attribute UseEcn");
895 "Disable Blue enhancement");
896 queue->Initialize ();
897 Enqueue (queue, modeSize, 200);
900 Simulator::Stop (
Seconds (8.0));
903 st = queue->GetStats ();
907 Simulator::Destroy ();
914 for (uint32_t i = 0; i < nPkt; i++)
916 queue->Enqueue (Create<CobaltQueueDiscTestItem> (Create<Packet> (size), dest, 0,
true));
929 for (uint32_t i = 0; i < nPkt; i++)
Test 1: simple enqueue/dequeue with no drops.
QueueSizeUnit m_mode
Queue test size function.
CobaltQueueDiscBasicEnqueueDequeue(QueueSizeUnit mode)
Constructor.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Test 4: Cobalt Queue Disc CE Threshold marking Test Item.
CobaltQueueDiscCeThresholdTest(QueueSizeUnit mode)
void DequeueWithDelay(Ptr< CobaltQueueDisc > queue, uint32_t modeSize, uint32_t nPkt, Time delay)
Dequeue with delay function.
void Enqueue(Ptr< CobaltQueueDisc > queue, uint32_t size, uint32_t nPkt)
Enqueue function.
virtual ~CobaltQueueDiscCeThresholdTest()
virtual void DoRun(void)
Implementation to actually run this TestCase.
void EnqueueWithDelay(Ptr< CobaltQueueDisc > queue, uint32_t size, uint32_t nPkt, Time delay)
Enqueue with delay function.
void Dequeue(Ptr< CobaltQueueDisc > queue, uint32_t modeSize)
Dequeue function.
Test 2: Cobalt Queue Disc Drop Test Item.
void RunDropTest(QueueSizeUnit mode)
Run Cobalt test function.
void Enqueue(Ptr< CobaltQueueDisc > queue, uint32_t size, uint32_t nPkt)
Enqueue function.
void EnqueueWithDelay(Ptr< CobaltQueueDisc > queue, uint32_t size, uint32_t nPkt)
virtual void DoRun(void)
Implementation to actually run this TestCase.
CobaltQueueDiscDropTest()
Test 5: Cobalt Queue Disc Enhanced Blue Test Item This test checks that the Blue Enhancement is worki...
CobaltQueueDiscEnhancedBlueTest(QueueSizeUnit mode)
void Dequeue(Ptr< CobaltQueueDisc > queue)
Dequeue function.
void Enqueue(Ptr< CobaltQueueDisc > queue, uint32_t size, uint32_t nPkt)
Enqueue function.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void DequeueWithDelay(Ptr< CobaltQueueDisc > queue, uint32_t nPkt, Time delay)
Dequeue with delay function.
virtual ~CobaltQueueDiscEnhancedBlueTest()
Test 3: Cobalt Queue Disc ECN marking Test Item.
CobaltQueueDiscMarkTest(QueueSizeUnit mode)
Constructor.
virtual void DoRun(void)
Implementation to actually run this TestCase.
uint32_t nPacketsBeforeFirstMark
Number of packets in the queue before first mark.
void Enqueue(Ptr< CobaltQueueDisc > queue, uint32_t size, uint32_t nPkt, bool ecnCapable)
Enqueue function.
void DropNextTracer(int64_t oldVal, int64_t newVal)
Drop next tracer function.
uint32_t nPacketsBeforeFirstDrop
Number of packets in the queue before first drop.
void Dequeue(Ptr< CobaltQueueDisc > queue, uint32_t modeSize, uint32_t testCase)
Dequeue function.
uint32_t m_dropNextCount
count the number of times m_dropNext is recalculated
Cobalt Queue Disc Test Item.
CobaltQueueDiscTestItem()
bool m_ecnCapablePacket
ECN capable packet?
virtual void AddHeader(void)
Add the header to the packet.
virtual bool Mark(void)
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
CobaltQueueDiscTestItem(const CobaltQueueDiscTestItem &)
Copy constructor Disable default implementation to avoid misuse.
virtual ~CobaltQueueDiscTestItem()
CobaltQueueDiscTestSuite()
a polymophic address class
AttributeValue implementation for Boolean.
uint64_t GetUid(void) const
Returns the packet's Uid.
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Class for representing queue sizes.
Hold variables of type string.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
@ UNIT
This test suite implements a Unit Test.
Simulation virtual time values and global simulation resolution.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
AttributeValue implementation for Time.
CobaltQueueDiscTestSuite g_cobaltQueueTestSuite
the test suite
#define NS_UNUSED(x)
Mark a local variable as unused.
QueueSizeUnit
Enumeration of the operating modes of queues.
@ BYTES
Use number of bytes for queue size.
@ PACKETS
Use number of packets for queue size.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
#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_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
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.
uint32_t GetNDroppedPackets(std::string reason) const
Get the number of packets dropped for the given reason.
uint32_t pktSize
packet size used for the simulation (in bytes)