24 #include "ns3/cobalt-queue-disc.h"
25 #include "ns3/double.h"
27 #include "ns3/packet.h"
28 #include "ns3/simulator.h"
29 #include "ns3/string.h"
31 #include "ns3/uinteger.h"
58 void AddHeader()
override;
69 m_ecnCapablePacket(ecnCapable)
102 void DoRun()
override;
117 :
TestCase(
"Basic enqueue and dequeue operations, and attribute setting" + std::
to_string(mode))
128 uint32_t modeSize = 0;
134 "Verify that we can actually set the attribute Interval");
137 "Verify that we can actually set the attribute Target");
140 "Disable Blue enhancement");
151 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(
m_mode, modeSize * 1500))),
153 "Verify that we can actually set the attribute MaxSize");
171 "There should be no packets in queue");
172 queue->Enqueue(Create<CobaltQueueDiscTestItem>(p1, dest,
false));
175 "There should be one packet in queue");
176 queue->Enqueue(Create<CobaltQueueDiscTestItem>(p2, dest,
false));
179 "There should be two packets in queue");
180 queue->Enqueue(Create<CobaltQueueDiscTestItem>(p3, dest,
false));
183 "There should be three packets in queue");
184 queue->Enqueue(Create<CobaltQueueDiscTestItem>(p4, dest,
false));
187 "There should be four packets in queue");
188 queue->Enqueue(Create<CobaltQueueDiscTestItem>(p5, dest,
false));
191 "There should be five packets in queue");
192 queue->Enqueue(Create<CobaltQueueDiscTestItem>(p6, dest,
false));
195 "There should be six packets in queue");
199 "There should be no packets being dropped due to full queue");
203 item = queue->Dequeue();
207 "There should be five packets in queue");
210 item = queue->Dequeue();
214 "There should be four packets in queue");
217 "Was this the second packet ?");
219 item = queue->Dequeue();
223 "There should be three packets in queue");
226 item = queue->Dequeue();
230 "There should be two packets in queue");
233 "Was this the fourth packet ?");
235 item = queue->Dequeue();
239 "There should be one packet in queue");
242 item = queue->Dequeue();
246 "There should be zero packet in queue");
249 item = queue->Dequeue();
253 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP),
255 "There should be no packet drops according to Cobalt algorithm");
267 void DoRun()
override;
292 :
TestCase(
"Drop tests verification for both packets and bytes mode")
301 uint32_t modeSize = 0;
313 queue = CreateObject<CobaltQueueDisc>();
315 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, modeSize * 100))),
317 "Verify that we can actually set the attribute MaxSize");
320 "Disable Blue enhancement");
341 "Drops due to queue overflow should be non-zero");
349 for (uint32_t i = 0; i < nPkt; i++)
351 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
364 for (uint32_t i = 0; i < nPkt; i++)
366 queue->Enqueue(Create<CobaltQueueDiscTestItem>(Create<Packet>(size), dest,
true));
375 Simulator::Destroy();
392 void DoRun()
override;
446 uint32_t modeSize = 0;
460 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(
m_mode, modeSize * 500))),
462 "Verify that we can actually set the attribute MaxSize");
465 "Verify that we can actually set the attribute UseEcn");
468 "Disable Blue enhancement");
475 "There should be 20 packets in queue.");
479 Time waitUntilFirstDequeue = 2 * queue->GetTarget();
480 Simulator::Schedule(waitUntilFirstDequeue,
488 Time waitUntilSecondDequeue = waitUntilFirstDequeue + 2 * queue->GetInterval();
489 Simulator::Schedule(waitUntilSecondDequeue,
497 Simulator::Destroy();
500 queue = CreateObject<CobaltQueueDisc>();
502 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(
m_mode, modeSize * 500))),
504 "Verify that we can actually set the attribute MaxSize");
507 "Verify that we can actually set the attribute UseEcn");
510 "Disable Blue enhancement");
517 "There should be 20 packets in queue.");
521 Simulator::Schedule(waitUntilFirstDequeue,
529 Simulator::Schedule(waitUntilSecondDequeue,
537 Simulator::Schedule(waitUntilSecondDequeue,
546 Simulator::Schedule(waitUntilSecondDequeue * 2,
554 Simulator::Destroy();
557 queue = CreateObject<CobaltQueueDisc>();
559 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(
m_mode, modeSize * 500))),
561 "Verify that we can actually set the attribute MaxSize");
564 "Verify that we can actually set the attribute UseEcn");
567 "Disable Blue enhancement");
576 "There should be 20 packets in queue.");
580 Simulator::Schedule(waitUntilFirstDequeue,
588 Simulator::Schedule(waitUntilSecondDequeue,
596 Simulator::Schedule(waitUntilSecondDequeue,
605 Simulator::Schedule(waitUntilSecondDequeue * 2,
613 Simulator::Destroy();
623 for (uint32_t i = 0; i < nPkt; i++)
625 queue->Enqueue(Create<CobaltQueueDiscTestItem>(Create<Packet>(size), dest, ecnCapable));
632 uint32_t initialMarkCount = queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
633 uint32_t initialQSize = queue->GetCurrentSize().GetValue();
634 uint32_t initialDropNext = queue->GetDropNext();
636 uint32_t currentDropCount = 0;
637 uint32_t currentMarkCount = 0;
639 if (initialMarkCount > 0 && currentTime.
GetNanoSeconds() > initialDropNext && testCase == 3)
641 queue->TraceConnectWithoutContext(
646 if (initialQSize != 0)
652 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
653 if (currentDropCount != 0)
660 if (initialMarkCount == 0 && currentTime > queue->GetTarget())
662 if (currentTime < queue->GetInterval())
665 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
667 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
669 initialQSize - modeSize,
670 "There should be 1 packet dequeued.");
673 "There should not be any packet drops");
676 "We are not in dropping state."
677 "Sojourn time has just gone above target from below."
678 "Hence, there should be no marked packets");
680 else if (currentTime >= queue->GetInterval())
684 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
686 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
688 queue->GetCurrentSize().GetValue(),
689 initialQSize - modeSize,
690 "Sojourn time has been above target for at least interval."
691 "We enter the dropping state and perform initial packet marking"
692 "So there should be only 1 more packet dequeued.");
695 "There should not be any packet drops");
699 else if (initialMarkCount > 0)
704 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
706 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
708 initialQSize - modeSize,
709 "We are in dropping state."
710 "Sojourn is still above target."
711 "There should be only 1 more packet dequeued");
714 "There should not be any packet drops");
717 "There should be 2 marked packet as."
718 "current dropnext is equal to current time.");
723 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
725 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
727 initialQSize - modeSize,
728 "We are in dropping state."
729 "It's time for packet to be marked"
730 "So there should be only 1 more packet dequeued");
733 "There should not be any packet drops");
738 "Number of packets in the queue before drop should be equal"
739 "to number of packets in the queue before first mark as the behavior until "
740 "packet N should be the same.");
744 else if (testCase == 3)
746 if (initialMarkCount == 0 && currentTime > queue->GetTarget())
748 if (currentTime < queue->GetInterval())
751 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
753 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
755 initialQSize - modeSize,
756 "There should be 1 packet dequeued.");
759 "There should not be any packet drops");
762 "We are not in dropping state."
763 "Sojourn time has just gone above target from below."
764 "Hence, there should be no marked packets");
766 else if (currentTime >= queue->GetInterval())
769 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
771 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
773 queue->GetCurrentSize().GetValue(),
774 initialQSize - modeSize,
775 "Sojourn time has been above target for at least interval."
776 "We enter the dropping state and perform initial packet marking"
777 "So there should be only 1 more packet dequeued.");
780 "There should not be any packet drops");
784 else if (initialMarkCount > 0)
789 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
791 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
793 initialQSize - modeSize,
794 "We are in dropping state."
795 "Sojourn is still above target."
796 "So there should be only 1 more packet dequeued");
799 "There should not be any packet drops");
802 "There should be 2 marked packet"
803 "as dropnext is equal to current time");
808 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
810 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
812 queue->GetCurrentSize().GetValue(),
814 "We are in dropping state."
815 "It's time for packet to be dropped as packets are not ecnCapable"
816 "The number of packets dequeued equals to the number of times m_dropNext "
817 "is updated plus initial dequeue");
821 "The number of drops equals to the number of times m_dropNext is updated");
824 "There should still be only 2 marked packet");
848 void DoRun()
override;
882 :
TestCase(
"Test CE Threshold marking")
895 for (uint32_t i = 0; i < nPkt; i++)
897 queue->Enqueue(Create<CobaltQueueDiscTestItem>(Create<Packet>(size), dest,
true));
907 for (uint32_t i = 0; i < nPkt; i++)
926 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::CE_THRESHOLD_EXCEEDED_MARK),
928 "There should be only 1 packet"
929 "mark, the delay between the enqueueing of the packets decreased after the"
930 "1st mark (packet enqueued at 11ms) and increased for the packet enqueued after 20.6ms."
931 "Queue delay remains below or equal to 1ms for the packet enqueued before 28ms");
936 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::CE_THRESHOLD_EXCEEDED_MARK),
938 "There should be 3 packet"
939 "marks, the delay between the enqueueing of the packets decreased after 1st mark"
940 "(packet enqueued at 11ms) and increased for the packet enqueued after 20.6ms."
941 "Queue delay remains below 1ms for the packets enqueued before 28ms and increases"
942 "for the packets enqueued after 28ms.");
952 for (uint32_t i = 0; i < nPkt; i++)
967 uint32_t modeSize = 0;
980 "Verify that we can actually set the attribute UseEcn");
983 "Verify that we can actually set the attribute UseEcn");
986 "Disable Blue enhancement");
1001 Simulator::Schedule(waitUntilFirstMark,
1010 Simulator::Schedule(waitUntilFirstMark,
1020 Time waitUntilDecreasingEnqueueDelay = waitUntilFirstMark +
MilliSeconds(9);
1021 Simulator::Schedule(waitUntilDecreasingEnqueueDelay,
1030 Simulator::Schedule(waitUntilFirstMark,
1039 Simulator::Destroy();
1066 void DoRun()
override;
1090 :
TestCase(
"Enhanced Blue tests verification for both packets and bytes mode")
1104 uint32_t modeSize = 0;
1115 queue->Initialize();
1116 queue->AssignStreams(1);
1117 Enqueue(queue, modeSize, 200);
1120 Simulator::Stop(
Seconds(8.0));
1129 "Pdrop should be increased by 1/256 for every packet whose sojourn time is above 400ms."
1130 " From the 41st dequeue until the last one, sojourn time is above 400ms, so 60 packets "
1131 "have sojourn time above 400ms"
1132 "hence Pdrop should be increased 60*(1/256) which is 0.234375");
1135 "There should a fixed number of drops (49 here)");
1136 Simulator::Destroy();
1138 queue = CreateObject<CobaltQueueDisc>();
1141 "Verify that we can actually set the attribute UseEcn");
1144 "Disable Blue enhancement");
1145 queue->Initialize();
1146 Enqueue(queue, modeSize, 200);
1149 Simulator::Stop(
Seconds(8.0));
1152 st = queue->GetStats();
1157 "There should not any dropped packets");
1158 Simulator::Destroy();
1165 for (uint32_t i = 0; i < nPkt; i++)
1167 queue->Enqueue(Create<CobaltQueueDiscTestItem>(Create<Packet>(size), dest,
true));
1182 for (uint32_t i = 0; i < nPkt; i++)
Test 1: simple enqueue/dequeue with no drops.
QueueSizeUnit m_mode
Queue test size function.
void DoRun() override
Implementation to actually run this TestCase.
CobaltQueueDiscBasicEnqueueDequeue(QueueSizeUnit mode)
Constructor.
Test 4: Cobalt Queue Disc CE Threshold marking Test Item.
~CobaltQueueDiscCeThresholdTest() override
CobaltQueueDiscCeThresholdTest(QueueSizeUnit mode)
Constructor.
void DoRun() override
Implementation to actually run this TestCase.
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.
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 DoRun() override
Implementation to actually run this TestCase.
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.
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 DoRun() override
Implementation to actually run this TestCase.
void Enqueue(Ptr< CobaltQueueDisc > queue, uint32_t size, uint32_t nPkt)
Enqueue function.
void DequeueWithDelay(Ptr< CobaltQueueDisc > queue, uint32_t nPkt, Time delay)
Dequeue with delay function.
~CobaltQueueDiscEnhancedBlueTest() override
Test 3: Cobalt Queue Disc ECN marking Test Item.
CobaltQueueDiscMarkTest(QueueSizeUnit mode)
Constructor.
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 DoRun() override
Implementation to actually run this TestCase.
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.
bool m_ecnCapablePacket
ECN capable packet?
CobaltQueueDiscTestItem()=delete
~CobaltQueueDiscTestItem() override
void AddHeader() override
Add the header to the packet.
CobaltQueueDiscTestItem & operator=(const CobaltQueueDiscTestItem &)=delete
CobaltQueueDiscTestItem(const CobaltQueueDiscTestItem &)=delete
bool Mark() override
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
The COBALT queue disc test suite.
CobaltQueueDiscTestSuite()
a polymophic address class
uint64_t GetUid() 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.
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
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()
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.
CobaltQueueDiscTestSuite g_cobaltQueueTestSuite
the test suite
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
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.
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)