21#include "ns3/codel-queue-disc.h"
22#include "ns3/fq-codel-queue-disc.h"
23#include "ns3/ipv4-address.h"
24#include "ns3/ipv4-header.h"
25#include "ns3/ipv4-packet-filter.h"
26#include "ns3/ipv4-queue-disc-item.h"
27#include "ns3/ipv6-header.h"
28#include "ns3/ipv6-packet-filter.h"
29#include "ns3/ipv6-queue-disc-item.h"
30#include "ns3/pointer.h"
31#include "ns3/simulator.h"
32#include "ns3/string.h"
33#include "ns3/tcp-header.h"
35#include "ns3/udp-header.h"
80 .SetGroupName(
"Internet")
117 void DoRun()
override;
121 :
TestCase(
"Test packets that are not classified by any filter")
134 CreateObjectWithAttributes<FqCoDelQueueDisc>(
"MaxSize",
StringValue(
"4p"));
136 queueDisc->AddPacketFilter(filter);
139 queueDisc->SetQuantum(1500);
140 queueDisc->Initialize();
143 p = Create<Packet>();
147 item = Create<Ipv6QueueDiscItem>(p, dest, 0, ipv6Header);
148 queueDisc->Enqueue(item);
151 "no flow queue should have been created");
153 p = Create<Packet>(
reinterpret_cast<const uint8_t*
>(
"hello, world"), 12);
154 item = Create<Ipv6QueueDiscItem>(p, dest, 0, ipv6Header);
155 queueDisc->Enqueue(item);
158 "no flow queue should have been created");
175 void DoRun()
override;
185 :
TestCase(
"Test IP flows separation and packet limit")
200 queue->Enqueue(item);
207 CreateObjectWithAttributes<FqCoDelQueueDisc>(
"MaxSize",
StringValue(
"4p"));
209 queueDisc->SetQuantum(1500);
210 queueDisc->Initialize();
224 "unexpected number of packets in the queue disc");
227 "unexpected number of packets in the flow queue");
235 "unexpected number of packets in the queue disc");
238 "unexpected number of packets in the flow queue");
241 "unexpected number of packets in the flow queue");
247 "unexpected number of packets in the queue disc");
250 "unexpected number of packets in the flow queue");
253 "unexpected number of packets in the flow queue");
270 void DoRun()
override;
280 :
TestCase(
"Test credits and flows status")
294 queue->Enqueue(item);
302 queueDisc->SetQuantum(90);
303 queueDisc->Initialize();
315 "unexpected number of packets in the queue disc");
318 "unexpected number of packets in the first flow queue");
319 Ptr<FqCoDelFlow> flow1 = StaticCast<FqCoDelFlow>(queueDisc->GetQueueDiscClass(0));
321 static_cast<int32_t>(queueDisc->GetQuantum()),
322 "the deficit of the first flow must equal the quantum");
325 "the first flow must be in the list of new queues");
327 queueDisc->Dequeue();
330 "unexpected number of packets in the queue disc");
333 "unexpected number of packets in the first flow queue");
342 "unexpected number of packets in the queue disc");
345 "unexpected number of packets in the first flow queue");
348 "the first flow must still be in the list of new queues");
356 "unexpected number of packets in the queue disc");
359 "unexpected number of packets in the first flow queue");
362 "unexpected number of packets in the second flow queue");
363 Ptr<FqCoDelFlow> flow2 = StaticCast<FqCoDelFlow>(queueDisc->GetQueueDiscClass(1));
365 static_cast<int32_t>(queueDisc->GetQuantum()),
366 "the deficit of the second flow must equal the quantum");
369 "the second flow must be in the list of new queues");
372 queueDisc->Dequeue();
375 "unexpected number of packets in the queue disc");
378 "unexpected number of packets in the first flow queue");
381 "unexpected number of packets in the second flow queue");
387 "the first flow must be in the list of old queues");
392 "the second flow must be in the list of new queues");
395 queueDisc->Dequeue();
398 "unexpected number of packets in the queue disc");
401 "unexpected number of packets in the first flow queue");
404 "unexpected number of packets in the second flow queue");
409 "the first flow must be in the list of old queues");
415 "the second flow must be in the list of new queues");
418 queueDisc->Dequeue();
421 "unexpected number of packets in the queue disc");
424 "unexpected number of packets in the first flow queue");
427 "unexpected number of packets in the second flow queue");
433 "the first flow must be in the list of old queues");
438 "the second flow must be in the list of new queues");
441 queueDisc->Dequeue();
444 "unexpected number of packets in the queue disc");
447 "unexpected number of packets in the first flow queue");
450 "unexpected number of packets in the second flow queue");
455 "the first flow must be in the list of old queues");
461 "the second flow must be in the list of new queues");
464 queueDisc->Dequeue();
475 "the first flow must be inactive");
479 "the second flow must be inactive");
496 void DoRun()
override;
507 :
TestCase(
"Test TCP flows separation")
521 p->AddHeader(tcpHdr);
524 queue->Enqueue(item);
531 CreateObjectWithAttributes<FqCoDelQueueDisc>(
"MaxSize",
StringValue(
"10p"));
533 queueDisc->SetQuantum(1500);
534 queueDisc->Initialize();
552 "unexpected number of packets in the queue disc");
555 "unexpected number of packets in the first flow queue");
562 "unexpected number of packets in the queue disc");
565 "unexpected number of packets in the first flow queue");
568 "unexpected number of packets in the second flow queue");
575 "unexpected number of packets in the queue disc");
578 "unexpected number of packets in the first flow queue");
581 "unexpected number of packets in the second flow queue");
584 "unexpected number of packets in the third flow queue");
592 "unexpected number of packets in the queue disc");
595 "unexpected number of packets in the first flow queue");
598 "unexpected number of packets in the second flow queue");
601 "unexpected number of packets in the third flow queue");
604 "unexpected number of packets in the third flow queue");
621 void DoRun()
override;
632 :
TestCase(
"Test UDP flows separation")
646 p->AddHeader(udpHdr);
649 queue->Enqueue(item);
656 CreateObjectWithAttributes<FqCoDelQueueDisc>(
"MaxSize",
StringValue(
"10p"));
658 queueDisc->SetQuantum(1500);
659 queueDisc->Initialize();
677 "unexpected number of packets in the queue disc");
680 "unexpected number of packets in the first flow queue");
687 "unexpected number of packets in the queue disc");
690 "unexpected number of packets in the first flow queue");
693 "unexpected number of packets in the second flow queue");
700 "unexpected number of packets in the queue disc");
703 "unexpected number of packets in the first flow queue");
706 "unexpected number of packets in the second flow queue");
709 "unexpected number of packets in the third flow queue");
717 "unexpected number of packets in the queue disc");
720 "unexpected number of packets in the first flow queue");
723 "unexpected number of packets in the second flow queue");
726 "unexpected number of packets in the third flow queue");
729 "unexpected number of packets in the third flow queue");
749 void DoRun()
override;
799 queue->Enqueue(item);
803 "unexpected number of flow queues");
806 "unexpected number of enqueued packets");
844 CreateObjectWithAttributes<FqCoDelQueueDisc>(
"MaxSize",
851 queueDisc->SetQuantum(1514);
852 queueDisc->Initialize();
921 queueDisc->GetQueueDiscClass(0)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
923 queueDisc->GetQueueDiscClass(1)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
925 queueDisc->GetQueueDiscClass(2)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
927 queueDisc->GetQueueDiscClass(3)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
929 queueDisc->GetQueueDiscClass(4)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
935 "There should be some remaining packets");
938 "There should be some remaining packets");
941 "There should be some remaining packets");
944 "There should be some remaining packets");
947 "There should be some remaining packets");
952 "There should be 6 marked packets"
953 "with 20 packets, total bytes in the queue = 120 * 20 = 2400. First "
954 "packet dequeues at 110ms which is greater than"
955 "test's default target value 5ms. Sojourn time has just gone above "
956 "target from below, need to stay above for at"
957 "least q->interval before packet can be dropped. Second packet dequeues "
958 "at 220ms which is greater than last dequeue"
959 "time plus q->interval(test default 100ms) so the packet is marked. "
960 "Third packet dequeues at 330ms and the sojourn"
961 "time stayed above the target and dropnext value is less than 320 hence "
962 "the packet is marked. 4 subsequent packets"
963 "are marked as the sojourn time stays above the target. With 8th dequeue "
964 "number of bytes in queue = 120 * 12 = 1440"
965 "which is less m_minBytes(test's default value 1500 bytes) hence the "
966 "packets stop getting marked");
969 "There should not be any dropped packets");
972 "There should be 6 marked packets");
975 "There should not be any dropped packets");
978 "There should be 6 marked packets");
981 "There should not be any dropped packets");
987 "There should be 4 dropped packets"
988 "with 20 packets, total bytes in the queue = 120 * 20 = 2400. First packet dequeues at "
989 "110ms which is greater than"
990 "test's default target value 5ms. Sojourn time has just gone above target from below, need "
991 "to stay above for at"
992 "least q->interval before packet can be dropped. Second packet dequeues at 220ms which is "
993 "greater than last dequeue"
994 "time plus q->interval(test default 100ms) so packet is dropped and next is dequeued. 4th "
995 "packet dequeues at 330ms"
996 "and the sojourn time stayed above the target and dropnext value is less than 320 hence "
997 "the packet is dropped and next"
998 "packet is dequeued. 6th packet dequeues at 440ms and 2 more packets are dropped as "
999 "dropnext value is increased twice."
1000 "12 Packets remaining in the queue, total number of bytes int the queue = 120 * 12 = 1440 "
1002 "m_minBytes(test's default value 1500 bytes) hence the packets stop getting dropped");
1005 "There should not be any marked packets");
1008 "There should be 4 dropped packets");
1011 "There should not be any marked packets");
1017 "flow queue should have ECT0 packets");
1021 "flow queue should have ECT0 packets");
1025 "flow queue should have ECT0 packets");
1030 queueDisc = CreateObjectWithAttributes<FqCoDelQueueDisc>(
"MaxSize",
1036 queueDisc->SetQuantum(1514);
1037 queueDisc->Initialize();
1101 q0 = queueDisc->GetQueueDiscClass(0)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
1102 q1 = queueDisc->GetQueueDiscClass(1)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
1103 q2 = queueDisc->GetQueueDiscClass(2)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
1104 q3 = queueDisc->GetQueueDiscClass(3)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
1105 q4 = queueDisc->GetQueueDiscClass(4)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
1111 "There should be some remaining packets");
1114 "There should be some remaining packets");
1117 "There should be some remaining packets");
1120 "There should be some remaining packets");
1123 "There should be some remaining packets");
1128 "There should not be any dropped packets");
1132 "There should not be any marked packets"
1133 "with quantum of 1514, 13 packets of size 120 bytes can be dequeued. sojourn time of 13th "
1134 "packet is 1.3ms which is"
1135 "less than CE threshold");
1138 "There should not be any dropped packets");
1142 "There should be 6 marked packets"
1143 "with quantum of 1514, 13 packets of size 120 bytes can be dequeued. sojourn time of 8th "
1144 "packet is 2.1ms which is greater"
1145 "than CE threshold and subsequent packet also have sojourn time more 8th packet hence "
1146 "remaining packet are marked.");
1149 "There should not be any dropped packets");
1153 "There should be 13 marked packets"
1154 "with quantum of 1514, 13 packets of size 120 bytes can be dequeued and all of them have "
1155 "sojourn time more than CE threshold");
1161 "There should not be any marked packets");
1164 "There should not be any dropped packets");
1168 "There should not be any marked packets");
1171 "There should not be any dropped packets");
1175 pktQ0 = DynamicCast<const Ipv4QueueDiscItem>(q0->Peek());
1178 "flow queue should have ECT0 packets");
1179 pktQ1 = DynamicCast<const Ipv4QueueDiscItem>(q1->Peek());
1182 "flow queue should have ECT0 packets");
1183 pktQ2 = DynamicCast<const Ipv4QueueDiscItem>(q2->Peek());
1186 "flow queue should have ECT0 packets");
1191 queueDisc = CreateObjectWithAttributes<FqCoDelQueueDisc>(
"MaxSize",
1197 queueDisc->SetQuantum(1514);
1198 queueDisc->Initialize();
1262 q0 = queueDisc->GetQueueDiscClass(0)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
1263 q1 = queueDisc->GetQueueDiscClass(1)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
1264 q2 = queueDisc->GetQueueDiscClass(2)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
1265 q3 = queueDisc->GetQueueDiscClass(3)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
1266 q4 = queueDisc->GetQueueDiscClass(4)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
1272 "There should be some remaining packets");
1275 "There should be some remaining packets");
1278 "There should be some remaining packets");
1281 "There should be some remaining packets");
1284 "There should be some remaining packets");
1289 "There should not be any dropped packets");
1293 20 - q0->GetNPackets(),
1294 "Number of CE threshold"
1295 " exceeded marks plus Number of Target exceeded marks should be equal to total number of "
1296 "packets dequeued");
1299 "There should not be any dropped packets");
1303 20 - q1->GetNPackets(),
1304 "Number of CE threshold"
1305 " exceeded marks plus Number of Target exceeded marks should be equal to total number of "
1306 "packets dequeued");
1309 "There should not be any dropped packets");
1313 20 - q2->GetNPackets(),
1314 "Number of CE threshold"
1315 " exceeded marks plus Number of Target exceeded marks should be equal to total number of "
1316 "packets dequeued");
1322 "There should not be any marked packets");
1326 "There should be 4 dropped packets"
1327 " As queue delay is same as in test case 1, number of dropped packets should also be same");
1331 "There should not be any marked packets");
1334 "There should be 4 dropped packets");
1338 pktQ0 = DynamicCast<const Ipv4QueueDiscItem>(q0->Peek());
1341 "flow queue should have ECT0 packets");
1342 pktQ1 = DynamicCast<const Ipv4QueueDiscItem>(q1->Peek());
1345 "flow queue should have ECT0 packets");
1346 pktQ2 = DynamicCast<const Ipv4QueueDiscItem>(q2->Peek());
1349 "flow queue should have ECT0 packets");
1385 void DoRun()
override;
1395 :
TestCase(
"Test credits and flows status")
1409 queue->Enqueue(item);
1416 CreateObjectWithAttributes<FqCoDelQueueDisc>(
"EnableSetAssociativeHash",
1418 queueDisc->SetQuantum(90);
1419 queueDisc->Initialize();
1422 queueDisc->AddPacketFilter(filter);
1453 "unexpected number of packets in the queue disc");
1456 "unexpected number of packets in the first flow queue of set one");
1459 "unexpected number of packets in the second flow queue of set one");
1462 "unexpected number of packets in the third flow queue of set one");
1465 "unexpected number of packets in the fourth flow queue of set one");
1468 "unexpected number of packets in the fifth flow queue of set one");
1471 "unexpected number of packets in the sixth flow queue of set one");
1474 "unexpected number of packets in the seventh flow queue of set one");
1477 "unexpected number of packets in the eighth flow queue of set one");
1482 "unexpected number of packets in the first flow of set one");
1487 "unexpected number of packets in the first flow of set two");
1505 void DoRun()
override;
1556 for (
uint32_t i = 0; i < nPkt; i++)
1559 queue->Enqueue(item);
1569 for (
uint32_t i = 0; i < nPkt; i++)
1583 for (
uint32_t i = 0; i < nPkt; i++)
1592 for (
uint32_t i = 0; i < nPkt; i++)
1611 CreateObjectWithAttributes<FqCoDelQueueDisc>(
"MaxSize",
1622 queueDisc->SetQuantum(1514);
1623 queueDisc->Initialize();
1633 double delay = 0.0005;
1659 queueDisc->GetQueueDiscClass(0)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
1661 queueDisc->GetQueueDiscClass(1)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
1666 "There should be 66 marked packets"
1667 "4th packet is enqueued at 2ms and dequeued at 4ms hence the delay of 2ms which not "
1668 "greater than CE threshold"
1669 "5th packet is enqueued at 2.5ms and dequeued at 5ms hence the delay of 2.5ms and "
1670 "subsequent packet also do have delay"
1671 "greater than CE threshold so all the packets after 4th packet are marked");
1674 "There should not be any dropped packets");
1677 "There should not be any marked packets");
1680 "There should be 1 marked packets");
1683 "There should not be any dropped packets");
1688 queueDisc = CreateObjectWithAttributes<FqCoDelQueueDisc>(
"MaxSize",
1699 queueDisc->SetQuantum(1514);
1700 queueDisc->Initialize();
1738 q0 = queueDisc->GetQueueDiscClass(0)->GetQueueDisc()->GetObject<
CoDelQueueDisc>();
1743 "There should be 68 marked packets"
1744 "2nd ECT1 packet is enqueued at 1.5ms and dequeued at 3ms hence the delay of 1.5ms which "
1745 "not greater than CE threshold"
1746 "3rd packet is enqueued at 2.5ms and dequeued at 5ms hence the delay of 2.5ms and "
1747 "subsequent packet also do have delay"
1748 "greater than CE threshold so all the packets after 2nd packet are marked");
1751 "There should not be any dropped packets");
1754 "There should be 1 marked packets");
1771 :
TestSuite(
"fq-codel-queue-disc", UNIT)
This class tests the deficit per flow.
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr)
Enqueue a packet.
void DoRun() override
Implementation to actually run this TestCase.
~FqCoDelQueueDiscDeficit() override
FqCoDelQueueDiscDeficit()
This class tests ECN marking.
void Dequeue(Ptr< FqCoDelQueueDisc > queue, uint32_t nPkt)
Dequeue some packets.
void DoRun() override
Implementation to actually run this TestCase.
FqCoDelQueueDiscECNMarking()
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr, uint32_t nPkt, uint32_t nPktEnqueued, uint32_t nQueueFlows)
Enqueue some packets.
void DequeueWithDelay(Ptr< FqCoDelQueueDisc > queue, double delay, uint32_t nPkt)
Dequeue some packets with delay.
~FqCoDelQueueDiscECNMarking() override
This class tests the IP flows separation and the packet limit.
void DoRun() override
Implementation to actually run this TestCase.
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr)
Enqueue a packet.
~FqCoDelQueueDiscIPFlowsSeparationAndPacketLimit() override
FqCoDelQueueDiscIPFlowsSeparationAndPacketLimit()
This class tests L4S mode.
void DoRun() override
Implementation to actually run this TestCase.
~FqCoDelQueueDiscL4sMode() override
FqCoDelQueueDiscL4sMode()
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr, uint32_t nPkt)
Enqueue some packets.
void AddPacketWithDelay(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr, double delay, uint32_t nPkt)
Enqueue some packets with delay.
void DequeueWithDelay(Ptr< FqCoDelQueueDisc > queue, double delay, uint32_t nPkt)
Dequeue some packets with delay.
void Dequeue(Ptr< FqCoDelQueueDisc > queue, uint32_t nPkt)
Dequeue some packets.
This class tests packets for which there is no suitable filter.
~FqCoDelQueueDiscNoSuitableFilter() override
void DoRun() override
Implementation to actually run this TestCase.
FqCoDelQueueDiscNoSuitableFilter()
This class tests linear probing, collision response, and set creation capability of set associative h...
FqCoDelQueueDiscSetLinearProbing()
~FqCoDelQueueDiscSetLinearProbing() override
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr)
Enqueue a packet.
void DoRun() override
Implementation to actually run this TestCase.
This class tests the TCP flows separation.
FqCoDelQueueDiscTCPFlowsSeparation()
void DoRun() override
Implementation to actually run this TestCase.
~FqCoDelQueueDiscTCPFlowsSeparation() override
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header ipHdr, TcpHeader tcpHdr)
Enqueue a packet.
FQ-CoDel queue disc test suite.
FqCoDelQueueDiscTestSuite()
This class tests the UDP flows separation.
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header ipHdr, UdpHeader udpHdr)
Enqueue a packet.
~FqCoDelQueueDiscUDPFlowsSeparation() override
void DoRun() override
Implementation to actually run this TestCase.
FqCoDelQueueDiscUDPFlowsSeparation()
Simple test packet filter able to classify IPv4 packets.
bool CheckProtocol(Ptr< QueueDiscItem > item) const override
Check the protocol.
int32_t DoClassify(Ptr< QueueDiscItem > item) const override
Classify a QueueDiscItem.
static TypeId GetTypeId()
Get the type ID.
~Ipv4TestPacketFilter() override
a polymophic address class
AttributeValue implementation for Boolean.
A CoDel packet queue disc.
static constexpr const char * TARGET_EXCEEDED_DROP
Sojourn time above target.
static constexpr const char * CE_THRESHOLD_EXCEEDED_MARK
Sojourn time above CE threshold.
static constexpr const char * TARGET_EXCEEDED_MARK
Sojourn time above target.
Ipv4 addresses are stored in host order in this class.
Ipv4PacketFilter is the abstract base class for filters defined for IPv4 packets.
Smart pointer class similar to boost::intrusive_ptr.
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 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.
Simulation virtual time values and global simulation resolution.
AttributeValue implementation for Time.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
static FqCoDelQueueDiscTestSuite g_fqCoDelQueueDiscTestSuite
Do not forget to allocate an instance of this TestSuite.
static int32_t g_hash
Variable to assign g_hash to a new packet's flow.
#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 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.