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"
72 m_ecnCapablePacket(ecnCapable)
110 void DoRun()
override;
125 :
TestCase(
"Basic enqueue and dequeue operations, and attribute setting" +
std::to_string(mode))
142 "Verify that we can actually set the attribute Interval");
145 "Verify that we can actually set the attribute Target");
148 "Disable Blue enhancement");
161 "Verify that we can actually set the attribute MaxSize");
179 "There should be no packets in queue");
180 queue->Enqueue(Create<CobaltQueueDiscTestItem>(p1, dest, 0,
false));
183 "There should be one packet in queue");
184 queue->Enqueue(Create<CobaltQueueDiscTestItem>(p2, dest, 0,
false));
187 "There should be two packets in queue");
188 queue->Enqueue(Create<CobaltQueueDiscTestItem>(p3, dest, 0,
false));
191 "There should be three packets in queue");
192 queue->Enqueue(Create<CobaltQueueDiscTestItem>(p4, dest, 0,
false));
195 "There should be four packets in queue");
196 queue->Enqueue(Create<CobaltQueueDiscTestItem>(p5, dest, 0,
false));
199 "There should be five packets in queue");
200 queue->Enqueue(Create<CobaltQueueDiscTestItem>(p6, dest, 0,
false));
203 "There should be six packets in queue");
207 "There should be no packets being dropped due to full queue");
211 item = queue->Dequeue();
215 "There should be five packets in queue");
218 item = queue->Dequeue();
222 "There should be four packets in queue");
225 "Was this the second packet ?");
227 item = queue->Dequeue();
231 "There should be three packets in queue");
234 item = queue->Dequeue();
238 "There should be two packets in queue");
241 "Was this the fourth packet ?");
243 item = queue->Dequeue();
247 "There should be one packet in queue");
250 item = queue->Dequeue();
254 "There should be zero packet in queue");
257 item = queue->Dequeue();
261 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP),
263 "There should be no packet drops according to Cobalt algorithm");
276 void DoRun()
override;
301 :
TestCase(
"Drop tests verification for both packets and bytes mode")
322 queue = CreateObject<CobaltQueueDisc>();
326 "Verify that we can actually set the attribute MaxSize");
329 "Disable Blue enhancement");
350 "Drops due to queue overflow should be non-zero");
360 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
375 queue->Enqueue(Create<CobaltQueueDiscTestItem>(Create<Packet>(size), dest, 0,
true));
384 Simulator::Destroy();
402 void DoRun()
override;
472 "Verify that we can actually set the attribute MaxSize");
475 "Verify that we can actually set the attribute UseEcn");
478 "Disable Blue enhancement");
485 "There should be 20 packets in queue.");
489 Time waitUntilFirstDequeue = 2 * queue->GetTarget();
490 Simulator::Schedule(waitUntilFirstDequeue,
498 Time waitUntilSecondDequeue = waitUntilFirstDequeue + 2 * queue->GetInterval();
499 Simulator::Schedule(waitUntilSecondDequeue,
507 Simulator::Destroy();
510 queue = CreateObject<CobaltQueueDisc>();
514 "Verify that we can actually set the attribute MaxSize");
517 "Verify that we can actually set the attribute UseEcn");
520 "Disable Blue enhancement");
527 "There should be 20 packets in queue.");
531 Simulator::Schedule(waitUntilFirstDequeue,
539 Simulator::Schedule(waitUntilSecondDequeue,
547 Simulator::Schedule(waitUntilSecondDequeue,
556 Simulator::Schedule(waitUntilSecondDequeue * 2,
564 Simulator::Destroy();
567 queue = CreateObject<CobaltQueueDisc>();
571 "Verify that we can actually set the attribute MaxSize");
574 "Verify that we can actually set the attribute UseEcn");
577 "Disable Blue enhancement");
586 "There should be 20 packets in queue.");
590 Simulator::Schedule(waitUntilFirstDequeue,
598 Simulator::Schedule(waitUntilSecondDequeue,
606 Simulator::Schedule(waitUntilSecondDequeue,
615 Simulator::Schedule(waitUntilSecondDequeue * 2,
623 Simulator::Destroy();
635 queue->Enqueue(Create<CobaltQueueDiscTestItem>(Create<Packet>(size), dest, 0, ecnCapable));
642 uint32_t initialMarkCount = queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
643 uint32_t initialQSize = queue->GetCurrentSize().GetValue();
644 uint32_t initialDropNext = queue->GetDropNext();
649 if (initialMarkCount > 0 && currentTime.
GetNanoSeconds() > initialDropNext && testCase == 3)
651 queue->TraceConnectWithoutContext(
656 if (initialQSize != 0)
662 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
663 if (currentDropCount != 0)
670 if (initialMarkCount == 0 && currentTime > queue->GetTarget())
672 if (currentTime < queue->GetInterval())
675 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
677 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
679 initialQSize - modeSize,
680 "There should be 1 packet dequeued.");
683 "There should not be any packet drops");
686 "We are not in dropping state."
687 "Sojourn time has just gone above target from below."
688 "Hence, there should be no marked packets");
690 else if (currentTime >= queue->GetInterval())
694 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
696 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
698 queue->GetCurrentSize().GetValue(),
699 initialQSize - modeSize,
700 "Sojourn time has been above target for at least interval."
701 "We enter the dropping state and perform initial packet marking"
702 "So there should be only 1 more packet dequeued.");
705 "There should not be any packet drops");
709 else if (initialMarkCount > 0)
714 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
716 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
718 initialQSize - modeSize,
719 "We are in dropping state."
720 "Sojourn is still above target."
721 "There should be only 1 more packet dequeued");
724 "There should not be any packet drops");
727 "There should be 2 marked packet as."
728 "current dropnext is equal to current time.");
733 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
735 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
737 initialQSize - modeSize,
738 "We are in dropping state."
739 "It's time for packet to be marked"
740 "So there should be only 1 more packet dequeued");
743 "There should not be any packet drops");
748 "Number of packets in the queue before drop should be equal"
749 "to number of packets in the queue before first mark as the behavior until "
750 "packet N should be the same.");
754 else if (testCase == 3)
756 if (initialMarkCount == 0 && currentTime > queue->GetTarget())
758 if (currentTime < queue->GetInterval())
761 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
763 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
765 initialQSize - modeSize,
766 "There should be 1 packet dequeued.");
769 "There should not be any packet drops");
772 "We are not in dropping state."
773 "Sojourn time has just gone above target from below."
774 "Hence, there should be no marked packets");
776 else if (currentTime >= queue->GetInterval())
779 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
781 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
783 queue->GetCurrentSize().GetValue(),
784 initialQSize - modeSize,
785 "Sojourn time has been above target for at least interval."
786 "We enter the dropping state and perform initial packet marking"
787 "So there should be only 1 more packet dequeued.");
790 "There should not be any packet drops");
794 else if (initialMarkCount > 0)
799 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
801 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
803 initialQSize - modeSize,
804 "We are in dropping state."
805 "Sojourn is still above target."
806 "So there should be only 1 more packet dequeued");
809 "There should not be any packet drops");
812 "There should be 2 marked packet"
813 "as dropnext is equal to current time");
818 queue->GetStats().GetNDroppedPackets(CobaltQueueDisc::TARGET_EXCEEDED_DROP);
820 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::FORCED_MARK);
822 queue->GetCurrentSize().GetValue(),
824 "We are in dropping state."
825 "It's time for packet to be dropped as packets are not ecnCapable"
826 "The number of packets dequeued equals to the number of times m_dropNext "
827 "is updated plus initial dequeue");
831 "The number of drops equals to the number of times m_dropNext is updated");
834 "There should still be only 2 marked packet");
859 void DoRun()
override;
893 :
TestCase(
"Test CE Threshold marking")
908 queue->Enqueue(Create<CobaltQueueDiscTestItem>(Create<Packet>(size), dest, 0,
true));
937 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::CE_THRESHOLD_EXCEEDED_MARK),
939 "There should be only 1 packet"
940 "mark, the delay between the enqueueing of the packets decreased after the"
941 "1st mark (packet enqueued at 11ms) and increased for the packet enqueued after 20.6ms."
942 "Queue delay remains below or equal to 1ms for the packet enqueued before 28ms");
947 queue->GetStats().GetNMarkedPackets(CobaltQueueDisc::CE_THRESHOLD_EXCEEDED_MARK),
949 "There should be 3 packet"
950 "marks, the delay between the enqueueing of the packets decreased after 1st mark"
951 "(packet enqueued at 11ms) and increased for the packet enqueued after 20.6ms."
952 "Queue delay remains below 1ms for the packets enqueued before 28ms and increases"
953 "for the packets enqueued after 28ms.");
991 "Verify that we can actually set the attribute UseEcn");
994 "Verify that we can actually set the attribute UseEcn");
997 "Disable Blue enhancement");
1012 Simulator::Schedule(waitUntilFirstMark,
1021 Simulator::Schedule(waitUntilFirstMark,
1031 Time waitUntilDecreasingEnqueueDelay = waitUntilFirstMark +
MilliSeconds(9);
1032 Simulator::Schedule(waitUntilDecreasingEnqueueDelay,
1041 Simulator::Schedule(waitUntilFirstMark,
1050 Simulator::Destroy();
1078 void DoRun()
override;
1102 :
TestCase(
"Enhanced Blue tests verification for both packets and bytes mode")
1127 queue->Initialize();
1128 queue->AssignStreams(1);
1129 Enqueue(queue, modeSize, 200);
1132 Simulator::Stop(
Seconds(8.0));
1141 "Pdrop should be increased by 1/256 for every packet whose sojourn time is above 400ms."
1142 " From the 41st dequeue until the last one, sojourn time is above 400ms, so 60 packets "
1143 "have sojourn time above 400ms"
1144 "hence Pdrop should be increased 60*(1/256) which is 0.234375");
1147 "There should a fixed number of drops (49 here)");
1148 Simulator::Destroy();
1150 queue = CreateObject<CobaltQueueDisc>();
1153 "Verify that we can actually set the attribute UseEcn");
1156 "Disable Blue enhancement");
1157 queue->Initialize();
1158 Enqueue(queue, modeSize, 200);
1161 Simulator::Stop(
Seconds(8.0));
1164 st = queue->GetStats();
1169 "There should not any dropped packets");
1170 Simulator::Destroy();
1177 for (
uint32_t i = 0; i < nPkt; i++)
1179 queue->Enqueue(Create<CobaltQueueDiscTestItem>(Create<Packet>(size), dest, 0,
true));
1194 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.
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.
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.
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.
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()
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.
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)