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"
59 virtual void AddHeader (
void);
60 virtual bool Mark (
void);
70 m_ecnCapablePacket (ecnCapable)
108 virtual void DoRun (
void);
123 :
TestCase (
"Basic enqueue and dequeue operations, and attribute setting" + std::
to_string (mode))
134 uint32_t modeSize = 0;
139 "Verify that we can actually set the attribute Interval");
141 "Verify that we can actually set the attribute Target");
143 "Disable Blue enhancement");
154 true,
"Verify that we can actually set the attribute MaxSize");
155 queue->Initialize ();
165 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 0 * modeSize,
"There should be no packets in queue");
166 queue->Enqueue (Create<CobaltQueueDiscTestItem> (p1, dest,0,
false));
167 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 1 * modeSize,
"There should be one packet in queue");
168 queue->Enqueue (Create<CobaltQueueDiscTestItem> (p2, dest,0,
false));
169 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 2 * modeSize,
"There should be two packets in queue");
170 queue->Enqueue (Create<CobaltQueueDiscTestItem> (p3, dest,0,
false));
171 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 3 * modeSize,
"There should be three packets in queue");
172 queue->Enqueue (Create<CobaltQueueDiscTestItem> (p4, dest,0,
false));
173 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 4 * modeSize,
"There should be four packets in queue");
174 queue->Enqueue (Create<CobaltQueueDiscTestItem> (p5, dest,0,
false));
175 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 5 * modeSize,
"There should be five packets in queue");
176 queue->Enqueue (Create<CobaltQueueDiscTestItem> (p6, dest,0,
false));
177 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 6 * modeSize,
"There should be six packets in queue");
179 NS_TEST_ASSERT_MSG_EQ (queue->GetStats ().GetNDroppedPackets (CobaltQueueDisc::OVERLIMIT_DROP), 0,
"There should be no packets being dropped due to full queue");
183 item = queue->Dequeue ();
185 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 5 * modeSize,
"There should be five packets in queue");
188 item = queue->Dequeue ();
190 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 4 * modeSize,
"There should be four packets in queue");
193 item = queue->Dequeue ();
195 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 3 * modeSize,
"There should be three packets in queue");
198 item = queue->Dequeue ();
200 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 2 * modeSize,
"There should be two packets in queue");
203 item = queue->Dequeue ();
205 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 1 * modeSize,
"There should be one packet in queue");
208 item = queue->Dequeue ();
210 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 0 * modeSize,
"There should be zero packet in queue");
213 item = queue->Dequeue ();
216 NS_TEST_ASSERT_MSG_EQ (queue->GetStats ().GetNDroppedPackets (CobaltQueueDisc::TARGET_EXCEEDED_DROP), 0,
"There should be no packet drops according to Cobalt algorithm");
229 virtual void DoRun (
void);
255 :
TestCase (
"Drop tests verification for both packets and bytes mode")
264 uint32_t modeSize = 0;
276 queue = CreateObject<CobaltQueueDisc> ();
278 true,
"Verify that we can actually set the attribute MaxSize");
280 "Disable Blue enhancement");
281 queue->Initialize ();
292 Simulator::Stop (
Seconds (8.0));
307 for (uint32_t i = 0; i < nPkt; i++)
317 for (uint32_t i = 0; i < nPkt; i++)
319 queue->Enqueue (Create<CobaltQueueDiscTestItem> (Create<Packet> (size), dest, 0,
true));
328 Simulator::Destroy ();
346 virtual void DoRun (
void);
377 :
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_ASSERT_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_ASSERT_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_ASSERT_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");
664 virtual void DoRun (
void);
698 :
TestCase (
"Test CE Threshold marking")
711 for (uint32_t i = 0; i < nPkt; i++)
713 queue->Enqueue (Create<CobaltQueueDiscTestItem> (Create<Packet> (size), dest, 0,
true));
720 for (uint32_t i = 0; i < nPkt; i++)
733 NS_TEST_EXPECT_MSG_EQ (queue->GetStats ().GetNMarkedPackets (CobaltQueueDisc::CE_THRESHOLD_EXCEEDED_MARK), 1,
"There should be only 1 packet"
734 "mark, the delay between the enqueueing of the packets decreased after the"
735 "1st mark (packet enqueued at 11ms) and increased for the packet enqueued after 20.6ms."
736 "Queue delay remains below or equal to 1ms for the packet enqueued before 28ms");
740 NS_TEST_EXPECT_MSG_EQ (queue->GetStats ().GetNMarkedPackets (CobaltQueueDisc::CE_THRESHOLD_EXCEEDED_MARK), 3,
"There should be 3 packet"
741 "marks, the delay between the enqueueing of the packets decreased after 1st mark"
742 "(packet enqueued at 11ms) and increased for the packet enqueued after 20.6ms."
743 "Queue delay remains below 1ms for the packets enqueued before 28ms and increases"
744 "for the packets enqueued after 28ms.");
751 for (uint32_t i = 0; i < nPkt; i++)
762 uint32_t modeSize = 0;
774 true,
"Verify that we can actually set the attribute UseEcn");
776 true,
"Verify that we can actually set the attribute UseEcn");
778 "Disable Blue enhancement");
779 queue->Initialize ();
799 Time waitUntilDecreasingEnqueueDelay = waitUntilFirstMark +
MilliSeconds(9);
806 Simulator::Destroy ();
834 virtual void DoRun (
void);
858 :
TestCase (
"Enhanced Blue tests verification for both packets and bytes mode")
872 uint32_t modeSize = 0;
883 queue->Initialize ();
884 queue->AssignStreams (1);
885 Enqueue (queue, modeSize, 200);
888 Simulator::Stop (
Seconds (8.0));
894 NS_TEST_ASSERT_MSG_EQ (queue->GetPdrop (), 0.234375,
"Pdrop should be increased by 1/256 for every packet whose sojourn time is above 400ms."
895 " From the 41st dequeue until the last one, sojourn time is above 400ms, so 60 packets have sojourn time above 400ms"
896 "hence Pdrop should be increased 60*(1/256) which is 0.234375");
898 Simulator::Destroy ();
901 queue = CreateObject<CobaltQueueDisc> ();
903 true,
"Verify that we can actually set the attribute UseEcn");
905 "Disable Blue enhancement");
906 queue->Initialize ();
907 Enqueue (queue, modeSize, 200);
910 Simulator::Stop (
Seconds (8.0));
913 st = queue->GetStats ();
917 Simulator::Destroy ();
924 for (uint32_t i = 0; i < nPkt; i++)
926 queue->Enqueue (Create<CobaltQueueDiscTestItem> (Create<Packet> (size), dest, 0,
true));
939 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)
Constructor.
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)
Enqueue the given number of packets, each of the given size, at different times.
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)
Constructor.
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 &)=delete
virtual ~CobaltQueueDiscTestItem()
The COBALT queue disc test suite.
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.
AttributeValue implementation for QueueSize.
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
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_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report 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.
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.
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
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)