23 #include "ns3/simulator.h" 24 #include "ns3/fq-codel-queue-disc.h" 25 #include "ns3/codel-queue-disc.h" 26 #include "ns3/ipv4-header.h" 27 #include "ns3/ipv4-packet-filter.h" 28 #include "ns3/ipv4-queue-disc-item.h" 29 #include "ns3/ipv4-address.h" 30 #include "ns3/ipv6-header.h" 31 #include "ns3/ipv6-packet-filter.h" 32 #include "ns3/ipv6-queue-disc-item.h" 33 #include "ns3/tcp-header.h" 34 #include "ns3/udp-header.h" 35 #include "ns3/string.h" 36 #include "ns3/pointer.h" 53 static TypeId GetTypeId (
void);
68 .SetGroupName (
"Internet")
104 virtual void DoRun (
void);
108 :
TestCase (
"Test packets that are not classified by any filter")
129 p = Create<Packet> ();
133 item = Create<Ipv6QueueDiscItem> (p, dest, 0, ipv6Header);
137 p = Create<Packet> (
reinterpret_cast<const uint8_t*
> (
"hello, world"), 12);
138 item = Create<Ipv6QueueDiscItem> (p, dest, 0, ipv6Header);
142 Simulator::Destroy ();
155 virtual void DoRun (
void);
160 :
TestCase (
"Test IP flows separation and packet limit")
195 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 3,
"unexpected number of packets in the queue disc");
202 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 4,
"unexpected number of packets in the queue disc");
207 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 3,
"unexpected number of packets in the queue disc");
211 Simulator::Destroy ();
224 virtual void DoRun (
void);
229 :
TestCase (
"Test credits and flows status")
262 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 1,
"unexpected number of packets in the queue disc");
266 NS_TEST_ASSERT_MSG_EQ (flow1->GetStatus (), FqCoDelFlow::NEW_FLOW,
"the first flow must be in the list of new queues");
269 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 0,
"unexpected number of packets in the queue disc");
277 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 2,
"unexpected number of packets in the queue disc");
279 NS_TEST_ASSERT_MSG_EQ (flow1->GetStatus (), FqCoDelFlow::NEW_FLOW,
"the first flow must still be in the list of new queues");
285 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 4,
"unexpected number of packets in the queue disc");
289 NS_TEST_ASSERT_MSG_EQ (flow2->GetDeficit (),
static_cast<int32_t
> (queueDisc->
GetQuantum ()),
"the deficit of the second flow must equal the quantum");
290 NS_TEST_ASSERT_MSG_EQ (flow2->GetStatus (), FqCoDelFlow::NEW_FLOW,
"the second flow must be in the list of new queues");
294 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 3,
"unexpected number of packets in the queue disc");
299 NS_TEST_ASSERT_MSG_EQ (flow1->GetStatus (), FqCoDelFlow::OLD_FLOW,
"the first flow must be in the list of old queues");
302 NS_TEST_ASSERT_MSG_EQ (flow2->GetStatus (), FqCoDelFlow::NEW_FLOW,
"the second flow must be in the list of new queues");
306 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 2,
"unexpected number of packets in the queue disc");
311 NS_TEST_ASSERT_MSG_EQ (flow1->GetStatus (), FqCoDelFlow::OLD_FLOW,
"the first flow must be in the list of old queues");
314 NS_TEST_ASSERT_MSG_EQ (flow2->GetStatus (), FqCoDelFlow::OLD_FLOW,
"the second flow must be in the list of new queues");
318 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 1,
"unexpected number of packets in the queue disc");
323 NS_TEST_ASSERT_MSG_EQ (flow1->GetStatus (), FqCoDelFlow::OLD_FLOW,
"the first flow must be in the list of old queues");
326 NS_TEST_ASSERT_MSG_EQ (flow2->GetStatus (), FqCoDelFlow::OLD_FLOW,
"the second flow must be in the list of new queues");
330 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 0,
"unexpected number of packets in the queue disc");
335 NS_TEST_ASSERT_MSG_EQ (flow1->GetStatus (), FqCoDelFlow::OLD_FLOW,
"the first flow must be in the list of old queues");
338 NS_TEST_ASSERT_MSG_EQ (flow2->GetStatus (), FqCoDelFlow::OLD_FLOW,
"the second flow must be in the list of new queues");
353 Simulator::Destroy ();
366 virtual void DoRun (
void);
371 :
TestCase (
"Test TCP flows separation")
411 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 3,
"unexpected number of packets in the queue disc");
417 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 4,
"unexpected number of packets in the queue disc");
424 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 5,
"unexpected number of packets in the queue disc");
433 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 7,
"unexpected number of packets in the queue disc");
439 Simulator::Destroy ();
452 virtual void DoRun (
void);
457 :
TestCase (
"Test UDP flows separation")
497 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 3,
"unexpected number of packets in the queue disc");
503 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 4,
"unexpected number of packets in the queue disc");
510 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 5,
"unexpected number of packets in the queue disc");
519 NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 7,
"unexpected number of packets in the queue disc");
525 Simulator::Destroy ();
539 virtual void DoRun (
void);
559 for (uint32_t i = 0; i < nPkt; i++)
571 for (uint32_t i = 0; i < nPkt; i++)
580 for (uint32_t i = 0; i < nPkt; i++)
605 hdr.
SetEcn (Ipv4Header::ECN_ECT0);
620 hdr.
SetEcn (Ipv4Header::ECN_NotECT);
630 Simulator::Stop (
Seconds (8.0));
647 "with 20 packets, total bytes in the queue = 120 * 20 = 2400. First packet dequeues at 110ms which is greater than" 648 "test's default target value 5ms. Sojourn time has just gone above target from below, need to stay above for at" 649 "least q->interval before packet can be dropped. Second packet dequeues at 220ms which is greater than last dequeue" 650 "time plus q->interval(test default 100ms) so the packet is marked. Third packet dequeues at 330ms and the sojourn" 651 "time stayed above the target and dropnext value is less than 320 hence the packet is marked. 4 subsequent packets" 652 "are marked as the sojourn time stays above the target. With 8th dequeue number of bytes in queue = 120 * 12 = 1440" 653 "which is less m_minBytes(test's default value 1500 bytes) hence the packets stop getting marked");
655 NS_TEST_EXPECT_MSG_EQ (q1->GetStats ().GetNMarkedPackets (CoDelQueueDisc::TARGET_EXCEEDED_MARK), 6,
"There should be 6 marked packets");
656 NS_TEST_EXPECT_MSG_EQ (q1->GetStats ().GetNDroppedPackets (CoDelQueueDisc::TARGET_EXCEEDED_DROP), 0,
"There should not be any dropped packets");
657 NS_TEST_EXPECT_MSG_EQ (q2->GetStats ().GetNMarkedPackets (CoDelQueueDisc::TARGET_EXCEEDED_MARK), 6,
"There should be 6 marked packets");
658 NS_TEST_EXPECT_MSG_EQ (q2->GetStats ().GetNDroppedPackets (CoDelQueueDisc::TARGET_EXCEEDED_DROP), 0,
"There should not be any dropped packets");
661 NS_TEST_EXPECT_MSG_EQ (q3->GetStats ().GetNDroppedPackets (CoDelQueueDisc::TARGET_EXCEEDED_DROP), 4,
"There should be 4 dropped packets" 662 "with 20 packets, total bytes in the queue = 120 * 20 = 2400. First packet dequeues at 110ms which is greater than" 663 "test's default target value 5ms. Sojourn time has just gone above target from below, need to stay above for at" 664 "least q->interval before packet can be dropped. Second packet dequeues at 220ms which is greater than last dequeue" 665 "time plus q->interval(test default 100ms) so packet is dropped and next is dequeued. 4th packet dequeues at 330ms" 666 "and the sojourn time stayed above the target and dropnext value is less than 320 hence the packet is dropped and next" 667 "packet is dequeued. 6th packet dequeues at 440ms and 2 more packets are dropped as dropnext value is increased twice." 668 "12 Packets remaining in the queue, total number of bytes int the queue = 120 * 12 = 1440 which is less" 669 "m_minBytes(test's default value 1500 bytes) hence the packets stop getting dropped");
670 NS_TEST_EXPECT_MSG_EQ (q3->GetStats ().GetNMarkedPackets (CoDelQueueDisc::TARGET_EXCEEDED_MARK), 0,
"There should not be any marked packets");
671 NS_TEST_EXPECT_MSG_EQ (q4->GetStats ().GetNDroppedPackets (CoDelQueueDisc::TARGET_EXCEEDED_DROP), 4,
"There should be 4 dropped packets");
672 NS_TEST_EXPECT_MSG_EQ (q4->GetStats ().GetNMarkedPackets (CoDelQueueDisc::TARGET_EXCEEDED_MARK), 0,
"There should not be any marked packets");
676 NS_TEST_EXPECT_MSG_NE (pktQ0->GetHeader ().GetEcn (), Ipv4Header::ECN_NotECT,
"flow queue should have ECT0 packets");
678 NS_TEST_EXPECT_MSG_NE (pktQ1->GetHeader ().GetEcn (), Ipv4Header::ECN_NotECT,
"flow queue should have ECT0 packets");
680 NS_TEST_EXPECT_MSG_NE (pktQ2->GetHeader ().GetEcn (), Ipv4Header::ECN_NotECT,
"flow queue should have ECT0 packets");
682 Simulator::Destroy ();
685 queueDisc = CreateObjectWithAttributes<FqCoDelQueueDisc> (
"MaxSize",
StringValue (
"10240p"),
"UseEcn",
BooleanValue (
true),
692 hdr.
SetEcn (Ipv4Header::ECN_ECT0);
705 hdr.
SetEcn (Ipv4Header::ECN_NotECT);
715 Simulator::Stop (
Seconds (8.0));
732 "with quantum of 1514, 13 packets of size 120 bytes can be dequeued. sojourn time of 13th packet is 1.3ms which is" 733 "less than CE threshold");
736 "with quantum of 1514, 13 packets of size 120 bytes can be dequeued. sojourn time of 8th packet is 2.1ms which is greater" 737 "than CE threshold and subsequent packet also have sojourn time more 8th packet hence remaining packet are marked.");
740 "with quantum of 1514, 13 packets of size 120 bytes can be dequeued and all of them have sojourn time more than CE threshold");
750 pktQ0 = DynamicCast<const Ipv4QueueDiscItem> (q0->
Peek ());
751 NS_TEST_EXPECT_MSG_NE (pktQ0->GetHeader ().GetEcn (), Ipv4Header::ECN_NotECT,
"flow queue should have ECT0 packets");
752 pktQ1 = DynamicCast<const Ipv4QueueDiscItem> (q1->
Peek ());
753 NS_TEST_EXPECT_MSG_NE (pktQ1->GetHeader ().GetEcn (), Ipv4Header::ECN_NotECT,
"flow queue should have ECT0 packets");
754 pktQ2 = DynamicCast<const Ipv4QueueDiscItem> (q2->
Peek ());
755 NS_TEST_EXPECT_MSG_NE (pktQ2->GetHeader ().GetEcn (), Ipv4Header::ECN_NotECT,
"flow queue should have ECT0 packets");
757 Simulator::Destroy ();
760 queueDisc = CreateObjectWithAttributes<FqCoDelQueueDisc> (
"MaxSize",
StringValue (
"10240p"),
"UseEcn",
BooleanValue (
true),
767 hdr.
SetEcn (Ipv4Header::ECN_ECT0);
780 hdr.
SetEcn (Ipv4Header::ECN_NotECT);
790 Simulator::Stop (
Seconds (8.0));
808 " exceeded marks plus Number of Target exceeded marks should be equal to total number of packets dequeued");
812 " exceeded marks plus Number of Target exceeded marks should be equal to total number of packets dequeued");
816 " exceeded marks plus Number of Target exceeded marks should be equal to total number of packets dequeued");
821 " As queue delay is same as in test case 1, number of dropped packets should also be same");
827 pktQ0 = DynamicCast<const Ipv4QueueDiscItem> (q0->
Peek ());
828 NS_TEST_EXPECT_MSG_NE (pktQ0->GetHeader ().GetEcn (), Ipv4Header::ECN_NotECT,
"flow queue should have ECT0 packets");
829 pktQ1 = DynamicCast<const Ipv4QueueDiscItem> (q1->
Peek ());
830 NS_TEST_EXPECT_MSG_NE (pktQ1->GetHeader ().GetEcn (), Ipv4Header::ECN_NotECT,
"flow queue should have ECT0 packets");
831 pktQ2 = DynamicCast<const Ipv4QueueDiscItem> (q2->
Peek ());
832 NS_TEST_EXPECT_MSG_NE (pktQ2->GetHeader ().GetEcn (), Ipv4Header::ECN_NotECT,
"flow queue should have ECT0 packets");
834 Simulator::Destroy ();
865 virtual void DoRun (
void);
870 :
TestCase (
"Test credits and flows status")
925 "unexpected number of packets in the queue disc");
927 "unexpected number of packets in the first flow queue of set one");
929 "unexpected number of packets in the second flow queue of set one");
931 "unexpected number of packets in the third flow queue of set one");
933 "unexpected number of packets in the fourth flow queue of set one");
935 "unexpected number of packets in the fifth flow queue of set one");
937 "unexpected number of packets in the sixth flow queue of set one");
939 "unexpected number of packets in the seventh flow queue of set one");
941 "unexpected number of packets in the eighth flow queue of set one");
945 "unexpected number of packets in the first flow of set one");
949 "unexpected number of packets in the first flow of set two");
950 Simulator::Destroy ();
965 virtual void DoRun (
void);
986 for (uint32_t i = 0; i < nPkt; i++)
996 for (uint32_t i = 0; i < nPkt; i++)
1005 for (uint32_t i = 0; i < nPkt; i++)
1014 for (uint32_t i = 0; i < nPkt; i++)
1039 hdr.
SetEcn (Ipv4Header::ECN_ECT1);
1043 double delay = 0.0005;
1047 hdr.
SetEcn (Ipv4Header::ECN_ECT0);
1055 Simulator::Stop (
Seconds (8.0));
1060 "4th packet is enqueued at 2ms and dequeued at 4ms hence the delay of 2ms which not greater than CE threshold" 1061 "5th packet is enqueued at 2.5ms and dequeued at 5ms hence the delay of 2.5ms and subsequent packet also do have delay" 1062 "greater than CE threshold so all the packets after 4th packet are marked");
1065 NS_TEST_EXPECT_MSG_EQ (q1->GetStats ().GetNMarkedPackets (CoDelQueueDisc::TARGET_EXCEEDED_MARK), 1,
"There should be 1 marked packets");
1066 NS_TEST_EXPECT_MSG_EQ (q1->GetStats ().GetNDroppedPackets (CoDelQueueDisc::TARGET_EXCEEDED_DROP), 0,
"There should not be any dropped packets");
1068 Simulator::Destroy ();
1071 queueDisc = CreateObjectWithAttributes<FqCoDelQueueDisc> (
"MaxSize",
StringValue (
"10240p"),
"UseEcn",
BooleanValue (
true),
1081 hdr.
SetEcn (Ipv4Header::ECN_ECT1);
1090 hdr.
SetEcn (Ipv4Header::ECN_ECT0);
1096 Simulator::Stop (
Seconds (8.0));
1100 "2nd ECT1 packet is enqueued at 1.5ms and dequeued at 3ms hence the delay of 1.5ms which not greater than CE threshold" 1101 "3rd packet is enqueued at 2.5ms and dequeued at 5ms hence the delay of 2.5ms and subsequent packet also do have delay" 1102 "greater than CE threshold so all the packets after 2nd packet are marked");
1106 Simulator::Destroy ();
1116 :
TestSuite (
"fq-codel-queue-disc", UNIT)
FqCoDelQueueDiscTestSuite()
void AddPacketWithDelay(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr, double delay, uint32_t nPkt)
Ptr< const QueueDiscItem > Peek(void)
Get a copy of the next packet the queue discipline will extract.
virtual int32_t DoClassify(Ptr< QueueDiscItem > item) const
Classify a packet.
void DequeueWithDelay(Ptr< FqCoDelQueueDisc > queue, double delay, uint32_t nPkt)
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr, u_int32_t nPkt, u_int32_t nPktEnqueued, u_int32_t nQueueFlows)
virtual void DoRun(void)
Implementation to actually run this TestCase.
Simulation virtual time values and global simulation resolution.
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Smart pointer class similar to boost::intrusive_ptr.
AttributeValue implementation for Boolean.
FqCoDelQueueDiscECNMarking()
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
void DequeueWithDelay(Ptr< FqCoDelQueueDisc > queue, double delay, uint32_t nPkt)
Hold variables of type string.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
void Dequeue(Ptr< FqCoDelQueueDisc > queue, uint32_t nPkt)
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
virtual ~FqCoDelQueueDiscUDPFlowsSeparation()
virtual ~FqCoDelQueueDiscTCPFlowsSeparation()
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr)
virtual void DoRun(void)
Implementation to actually run this TestCase.
a polymophic address class
This class tests the TCP flows separation.
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr, u_int32_t nPkt)
virtual ~Ipv4TestPacketFilter()
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr)
AttributeValue implementation for Time.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
FqCoDelQueueDiscUDPFlowsSeparation()
Hold an unsigned integer type.
uint32_t GetNDroppedPackets(std::string reason) const
Get the number of packets dropped for the given reason.
#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.
This class tests packets for which there is no suitable filter.
uint32_t GetQuantum(void) const
Get the quantum value.
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header ipHdr, TcpHeader tcpHdr)
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header ipHdr, UdpHeader udpHdr)
virtual ~FqCoDelQueueDiscECNMarking()
virtual void DoRun(void)
Implementation to actually run this TestCase.
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr)
const Stats & GetStats(void)
Retrieve all the collected statistics.
virtual ~FqCoDelQueueDiscNoSuitableFilter()
FqCoDelQueueDiscTCPFlowsSeparation()
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
This class tests L4S mode Any future classifier options (e.g.
Ptr< QueueDiscItem > Dequeue(void)
Extract from the queue disc the packet that has been dequeued by calling Peek, if any...
virtual void DoRun(void)
Implementation to actually run this TestCase.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::size_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
void SetQuantum(uint32_t quantum)
Set the quantum value.
virtual ~FqCoDelQueueDiscSetLinearProbing()
This class tests the UDP flows separation.
virtual bool CheckProtocol(Ptr< QueueDiscItem > item) const
Checks if the filter is able to classify a kind of items.
This class tests ECN marking Any future classifier options (e.g.
uint32_t GetNMarkedPackets(std::string reason) const
Get the number of packets marked for the given reason.
virtual ~FqCoDelQueueDiscDeficit()
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report if not.
static FqCoDelQueueDiscTestSuite fqCoDelQueueDiscTestSuite
A CoDel packet queue disc.
This class tests the IP flows separation and the packet limit.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ipv4 addresses are stored in host order in this class.
static TypeId GetTypeId(void)
Get the type ID.
FqCoDelQueueDiscIPFlowsSeparationAndPacketLimit()
Ipv4PacketFilter is the abstract base class for filters defined for IPv4 packets. ...
Time Seconds(double value)
Construct a Time in the indicated unit.
This class tests the deficit per flow.
void AddPacketFilter(Ptr< PacketFilter > filter)
Add a packet filter to the tail of the list of filters used to classify packets.
FqCoDelQueueDiscL4sMode()
FqCoDelQueueDiscSetLinearProbing()
Simple test packet filter able to classify IPv4 packets.
virtual ~FqCoDelQueueDiscL4sMode()
void Dequeue(Ptr< FqCoDelQueueDisc > queue, uint32_t nPkt)
a unique identifier for an interface.
FqCoDelQueueDiscNoSuitableFilter()
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Inactive Period or unslotted CSMA-CA.
void Initialize(void)
Invoke DoInitialize on all Objects aggregated to this one.
FqCoDelQueueDiscDeficit()
void AddHeader(const Header &header)
Add header to this packet.
virtual ~FqCoDelQueueDiscIPFlowsSeparationAndPacketLimit()