23 #include "ns3/double.h"
25 #include "ns3/packet.h"
26 #include "ns3/pie-queue-disc.h"
27 #include "ns3/simulator.h"
28 #include "ns3/string.h"
30 #include "ns3/uinteger.h"
56 void AddHeader()
override;
60 double m_maxDropProbDiff =
62 double m_prevDropProb = 0.0;
63 bool m_checkProb =
false;
66 double m_maxDropProb = 0.0;
67 bool m_ecnCapable =
false;
70 bool m_checkAccuProb =
false;
71 bool m_constAccuProb =
false;
72 bool m_checkMaxAccuProb =
false;
73 double m_accuProbError = 0.0;
74 double m_prevAccuProb = 0.0;
75 double m_setAccuProb = 0.0;
76 uint32_t m_expectedDrops = 0;
84 m_ecnCapablePacket(ecnCapable)
112 void DoRun()
override;
176 :
TestCase(
"Sanity check on the pie queue disc implementation")
186 uint32_t modeSize = 1;
188 uint32_t qSize = 300;
195 Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
203 qSize = qSize * modeSize;
209 "Verify that we can actually set the attribute MaxSize");
231 "There should be no packets in there");
232 queue->Enqueue(Create<PieQueueDiscTestItem>(p1, dest,
false));
235 "There should be one packet in there");
236 queue->Enqueue(Create<PieQueueDiscTestItem>(p2, dest,
false));
239 "There should be two packets in there");
240 queue->Enqueue(Create<PieQueueDiscTestItem>(p3, dest,
false));
241 queue->Enqueue(Create<PieQueueDiscTestItem>(p4, dest,
false));
242 queue->Enqueue(Create<PieQueueDiscTestItem>(p5, dest,
false));
243 queue->Enqueue(Create<PieQueueDiscTestItem>(p6, dest,
false));
244 queue->Enqueue(Create<PieQueueDiscTestItem>(p7, dest,
false));
245 queue->Enqueue(Create<PieQueueDiscTestItem>(p8, dest,
false));
248 "There should be eight packets in there");
252 item = queue->Dequeue();
256 "There should be seven packets in there");
259 item = queue->Dequeue();
263 "There should be six packet in there");
266 "Was this the second packet ?");
268 item = queue->Dequeue();
272 "There should be five packets in there");
275 item = queue->Dequeue();
276 item = queue->Dequeue();
277 item = queue->Dequeue();
278 item = queue->Dequeue();
279 item = queue->Dequeue();
281 item = queue->Dequeue();
285 queue = CreateObject<PieQueueDisc>();
287 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
292 "Verify that we can actually set the attribute MaxSize");
295 "Verify that we can actually set the attribute Tupdate");
298 "Verify that we can actually set the attribute DequeueThreshold");
300 queue->SetAttributeFailSafe(
"QueueDelayReference",
TimeValue(
Seconds(0.02))),
302 "Verify that we can actually set the attribute QueueDelayReference");
305 "Verify that we can actually set the attribute MaxBurstAllowance");
316 "There should be zero forced drops");
319 queue = CreateObject<PieQueueDisc>();
321 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
325 "Verify that we can actually set the attribute MaxSize");
328 "Verify that we can actually set the attribute Tupdate");
331 "Verify that we can actually set the attribute DequeueThreshold");
333 queue->SetAttributeFailSafe(
"QueueDelayReference",
TimeValue(
Seconds(0.08))),
335 "Verify that we can actually set the attribute QueueDelayReference");
338 "Verify that we can actually set the attribute MaxBurstAllowance");
344 st = queue->GetStats();
349 "There should be zero forced drops");
352 queue = CreateObject<PieQueueDisc>();
354 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
358 "Verify that we can actually set the attribute MaxSize");
361 "Verify that we can actually set the attribute Tupdate");
364 "Verify that we can actually set the attribute DequeueThreshold");
366 queue->SetAttributeFailSafe(
"QueueDelayReference",
TimeValue(
Seconds(0.02))),
368 "Verify that we can actually set the attribute QueueDelayReference");
371 "Verify that we can actually set the attribute MaxBurstAllowance");
377 st = queue->GetStats();
382 "There should be zero forced drops");
385 queue = CreateObject<PieQueueDisc>();
387 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
391 "Verify that we can actually set the attribute MaxSize");
394 "Verify that we can actually set the attribute Tupdate");
397 "Verify that we can actually set the attribute DequeueThreshold");
399 queue->SetAttributeFailSafe(
"QueueDelayReference",
TimeValue(
Seconds(0.02))),
401 "Verify that we can actually set the attribute QueueDelayReference");
404 "Verify that we can actually set the attribute MaxBurstAllowance");
410 st = queue->GetStats();
415 "There should be zero forced drops");
418 queue = CreateObject<PieQueueDisc>();
420 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
424 "Verify that we can actually set the attribute MaxSize");
426 queue->SetAttributeFailSafe(
"UseDequeueRateEstimator",
BooleanValue(
true)),
428 "Verify that we can actually set the attribute UseTimestamp");
434 st = queue->GetStats();
439 "There should be zero forced drops");
442 queue = CreateObject<PieQueueDisc>();
444 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
448 "Verify that we can actually set the attribute MaxSize");
451 "Verify that we can actually set the attribute UseCapDropAdjustment");
453 testAttributes->m_checkProb =
true;
458 st = queue->GetStats();
463 "There should be zero forced drops");
466 "Maximum increase in drop probability should be greater than 0.02");
469 queue = CreateObject<PieQueueDisc>();
471 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
475 "Verify that we can actually set the attribute MaxSize");
478 "Verify that we can actually set the attribute UseCapDropAdjustment");
480 testAttributes->m_checkProb =
true;
485 st = queue->GetStats();
490 "There should be zero forced drops");
492 testAttributes->m_maxDropProbDiff,
494 "Maximum increase in drop probability should be less than or equal to 0.02");
497 queue = CreateObject<PieQueueDisc>();
499 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
503 "Verify that we can actually set the attribute MaxSize");
506 "Verify that we can actually set the attribute UseEcn");
509 "Verify that we can actually set the attribute MarkEcnThreshold");
515 st = queue->GetStats();
520 "There should be some unforced drops");
523 "There should be zero forced drops");
526 queue = CreateObject<PieQueueDisc>();
528 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
532 "Verify that we can actually set the attribute MaxSize");
535 "Verify that we can actually set the attribute UseEcn");
538 "Verify that we can actually set the attribute MarkEcnThreshold");
540 testAttributes->m_ecnCapable =
true;
545 st = queue->GetStats();
550 "There should be some unforced drops");
553 "There should be zero forced drops");
556 queue = CreateObject<PieQueueDisc>();
558 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
562 "Verify that we can actually set the attribute MaxSize");
565 "Verify that we can actually set the attribute UseEcn");
568 "Verify that we can actually set the attribute MarkEcnThreshold");
570 testAttributes->m_ecnCapable =
true;
571 testAttributes->m_checkProb =
true;
576 st = queue->GetStats();
583 "There should be some unforced drops");
587 "Maximum Drop probability should be greater than 0.3");
590 "There should be zero forced drops");
593 queue = CreateObject<PieQueueDisc>();
595 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
599 "Verify that we can actually set the attribute MaxSize");
602 "Verify that we can actually set the attribute UseDerandomization");
604 testAttributes->m_checkAccuProb =
true;
609 st = queue->GetStats();
614 "There should be zero forced drops");
617 "There should not be any error in setting accuProb");
620 queue = CreateObject<PieQueueDisc>();
622 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
626 "Verify that we can actually set the attribute MaxSize");
629 "Verify that we can actually set the attribute UseDerandomization");
631 testAttributes->m_constAccuProb =
true;
634 testAttributes->m_setAccuProb = -0.16;
639 st = queue->GetStats();
644 "There should be zero forced drops");
647 queue = CreateObject<PieQueueDisc>();
649 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
653 "Verify that we can actually set the attribute MaxSize");
656 "Verify that we can actually set the attribute MaxBurstAllowance");
659 "Verify that we can actually set the attribute UseDerandomization");
661 testAttributes->m_constAccuProb =
true;
662 testAttributes->m_checkMaxAccuProb =
true;
665 testAttributes->m_setAccuProb = 8.6;
670 st = queue->GetStats();
674 testAttributes->m_expectedDrops,
675 "The number of unforced drops should be equal to number of expected unforced drops");
678 "There should be zero forced drops");
682 queue = CreateObject<PieQueueDisc>();
684 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
693 st = queue->GetStats();
698 "There should be zero marks");
702 queue = CreateObject<PieQueueDisc>();
704 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
713 st = queue->GetStats();
718 "There should be zero marks");
728 for (uint32_t i = 0; i < nPkt; i++)
730 if (testAttributes->m_constAccuProb)
732 queue->m_accuProb = testAttributes->m_setAccuProb;
733 if (testAttributes->m_checkMaxAccuProb)
739 Create<PieQueueDiscTestItem>(Create<Packet>(size), dest, testAttributes->m_ecnCapable));
740 if (testAttributes->m_checkProb)
744 if (testAttributes->m_checkAccuProb)
755 double dropProb = queue->m_dropProb;
756 if (testAttributes->m_maxDropProb < dropProb)
758 testAttributes->m_maxDropProb = dropProb;
760 if (testAttributes->m_prevDropProb > 0.1)
762 double currentDiff = dropProb - testAttributes->m_prevDropProb;
763 if (testAttributes->m_maxDropProbDiff < currentDiff)
765 testAttributes->m_maxDropProbDiff = currentDiff;
768 testAttributes->m_prevDropProb = dropProb;
775 double dropProb = queue->m_dropProb;
776 double accuProb = queue->m_accuProb;
779 double expectedAccuProb = testAttributes->m_prevAccuProb + dropProb;
780 testAttributes->m_accuProbError = accuProb - expectedAccuProb;
782 testAttributes->m_prevAccuProb = accuProb;
789 queue->m_dropProb = 0.001;
790 QueueSize queueSize = queue->GetCurrentSize();
794 testAttributes->m_expectedDrops = testAttributes->m_expectedDrops + 1;
806 for (uint32_t i = 0; i < nPkt; i++)
808 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
821 for (uint32_t i = 0; i < nPkt; i++)
830 for (uint32_t i = 0; i < nPkt; i++)
832 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
845 Simulator::Destroy();
Pie Queue Disc Test Case.
void Dequeue(Ptr< PieQueueDisc > queue, uint32_t nPkt)
Dequeue function.
void RunPieTest(QueueSizeUnit mode)
Run test function.
void CheckMaxAccuProb(Ptr< PieQueueDisc > queue, Ptr< PieQueueDiscTestItem > testAttributes)
Check Maximum Accumulated Drop Probability.
void EnqueueWithDelay(Ptr< PieQueueDisc > queue, uint32_t size, uint32_t nPkt, Ptr< PieQueueDiscTestItem > testAttributes)
Enqueue with delay function.
void CheckAccuProb(Ptr< PieQueueDisc > queue, Ptr< PieQueueDiscTestItem > testAttributes)
Check Accumulated Drop Probability.
void CheckDropProb(Ptr< PieQueueDisc > queue, Ptr< PieQueueDiscTestItem > testAttributes)
Check Drop Probability.
void DequeueWithDelay(Ptr< PieQueueDisc > queue, double delay, uint32_t nPkt)
Dequeue with delay function.
void Enqueue(Ptr< PieQueueDisc > queue, uint32_t size, uint32_t nPkt, Ptr< PieQueueDiscTestItem > testAttributes)
Enqueue function.
void DoRun() override
Implementation to actually run this TestCase.
Pie Queue Disc Test Item.
bool m_ecnCapablePacket
ECN capable packet?
PieQueueDiscTestItem(const PieQueueDiscTestItem &)=delete
PieQueueDiscTestItem()=delete
PieQueueDiscTestItem & operator=(const PieQueueDiscTestItem &)=delete
void AddHeader() override
Add the header to the packet.
bool Mark() override
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
Pie Queue Disc Test Suite.
a polymophic address class
AttributeValue implementation for Boolean.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
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.
QueueSizeUnit GetUnit() const
Get the underlying unit.
uint32_t GetValue() const
Get the underlying value.
AttributeValue implementation for QueueSize.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
@ UNIT
This test suite implements a Unit Test.
AttributeValue implementation for Time.
Hold an unsigned integer type.
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_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
#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_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
Time Seconds(double value)
Construct a Time in the indicated unit.
PieQueueDiscTestSuite g_pieQueueTestSuite
the test suite
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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 GetNMarkedPackets(std::string reason) const
Get the number of packets marked for the given reason.
uint32_t pktSize
packet size used for the simulation (in bytes)