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"
69 m_ecnCapablePacket(ecnCapable)
102 void DoRun()
override;
117 :
TestCase(
"Basic enqueue and dequeue operations, and attribute setting" +
std::to_string(mode))
134 "Verify that we can actually set the attribute Interval");
137 "Verify that we can actually set the attribute Target");
140 "Disable Blue enhancement");
142 if (
m_mode == QueueSizeUnit::BYTES)
146 else if (
m_mode == QueueSizeUnit::PACKETS)
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();
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")
304 if (mode == QueueSizeUnit::BYTES)
308 else if (mode == QueueSizeUnit::PACKETS)
313 queue = CreateObject<CobaltQueueDisc>();
317 "Verify that we can actually set the attribute MaxSize");
320 "Disable Blue enhancement");
323 if (mode == QueueSizeUnit::BYTES)
341 "Drops due to queue overflow should be non-zero");
366 queue->Enqueue(Create<CobaltQueueDiscTestItem>(Create<Packet>(size), dest,
true));
392 void DoRun()
override;
450 if (
m_mode == QueueSizeUnit::BYTES)
454 else if (
m_mode == QueueSizeUnit::PACKETS)
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();
488 Time waitUntilSecondDequeue = waitUntilFirstDequeue + 2 * queue->GetInterval();
500 queue = CreateObject<CobaltQueueDisc>();
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.");
557 queue = CreateObject<CobaltQueueDisc>();
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.");
625 queue->Enqueue(Create<CobaltQueueDiscTestItem>(Create<Packet>(size), dest, ecnCapable));
633 uint32_t initialQSize = queue->GetCurrentSize().GetValue();
634 uint32_t initialDropNext = queue->GetDropNext();
639 if (initialMarkCount > 0 && currentTime.
GetNanoSeconds() > initialDropNext && testCase == 3)
641 queue->TraceConnectWithoutContext(
646 if (initialQSize != 0)
653 if (currentDropCount != 0)
660 if (initialMarkCount == 0 && currentTime > queue->GetTarget())
662 if (currentTime < queue->GetInterval())
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())
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)
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.");
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())
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())
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)
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");
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")
897 queue->Enqueue(Create<CobaltQueueDiscTestItem>(Create<Packet>(size), dest,
true));
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");
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.");
969 if (
m_mode == QueueSizeUnit::BYTES)
973 else if (
m_mode == QueueSizeUnit::PACKETS)
980 "Verify that we can actually set the attribute UseEcn");
983 "Verify that we can actually set the attribute UseEcn");
986 "Disable Blue enhancement");
1020 Time waitUntilDecreasingEnqueueDelay = waitUntilFirstMark +
MilliSeconds(9);
1066 void DoRun()
override;
1090 :
TestCase(
"Enhanced Blue tests verification for both packets and bytes mode")
1107 if (
m_mode == QueueSizeUnit::BYTES)
1111 else if (
m_mode == QueueSizeUnit::PACKETS)
1115 queue->Initialize();
1116 queue->AssignStreams(1);
1117 Enqueue(queue, modeSize, 200);
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)");
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);
1152 st = queue->GetStats();
1157 "There should not any dropped packets");
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
CobaltQueueDiscTestItem & operator=(const CobaltQueueDiscTestItem &)=delete
void AddHeader() override
Add the header to the packet.
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
AttributeValue implementation for Boolean.
static constexpr const char * CE_THRESHOLD_EXCEEDED_MARK
Sojourn time above CE threshold.
static constexpr const char * TARGET_EXCEEDED_DROP
Sojourn time above target.
static constexpr const char * FORCED_MARK
forced marks by Codel on ECN-enabled
static constexpr const char * OVERLIMIT_DROP
Overlimit dropped packet.
Smart pointer class similar to boost::intrusive_ptr.
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Class for representing queue sizes.
AttributeValue implementation for QueueSize.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
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.
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
AttributeValue implementation for Time.
QueueSizeUnit
Enumeration of the operating modes of queues.
@ BYTES
Use number of bytes for queue size.
@ PACKETS
Use number of packets for queue size.
#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
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)