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)
108 void DoRun()
override;
172 :
TestCase(
"Sanity check on the pie queue disc implementation")
182 uint32_t modeSize = 1;
184 uint32_t qSize = 300;
191 Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
199 qSize = qSize * modeSize;
203 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
205 "Verify that we can actually set the attribute MaxSize");
227 "There should be no packets in there");
228 queue->Enqueue(Create<PieQueueDiscTestItem>(p1, dest,
false));
231 "There should be one packet in there");
232 queue->Enqueue(Create<PieQueueDiscTestItem>(p2, dest,
false));
235 "There should be two packets in there");
236 queue->Enqueue(Create<PieQueueDiscTestItem>(p3, dest,
false));
237 queue->Enqueue(Create<PieQueueDiscTestItem>(p4, dest,
false));
238 queue->Enqueue(Create<PieQueueDiscTestItem>(p5, dest,
false));
239 queue->Enqueue(Create<PieQueueDiscTestItem>(p6, dest,
false));
240 queue->Enqueue(Create<PieQueueDiscTestItem>(p7, dest,
false));
241 queue->Enqueue(Create<PieQueueDiscTestItem>(p8, dest,
false));
244 "There should be eight packets in there");
248 item = queue->Dequeue();
252 "There should be seven packets in there");
255 item = queue->Dequeue();
259 "There should be six packet in there");
262 "Was this the second packet ?");
264 item = queue->Dequeue();
268 "There should be five packets in there");
271 item = queue->Dequeue();
272 item = queue->Dequeue();
273 item = queue->Dequeue();
274 item = queue->Dequeue();
275 item = queue->Dequeue();
277 item = queue->Dequeue();
281 queue = CreateObject<PieQueueDisc>();
283 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
286 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
288 "Verify that we can actually set the attribute MaxSize");
291 "Verify that we can actually set the attribute Tupdate");
294 "Verify that we can actually set the attribute DequeueThreshold");
296 queue->SetAttributeFailSafe(
"QueueDelayReference",
TimeValue(
Seconds(0.02))),
298 "Verify that we can actually set the attribute QueueDelayReference");
301 "Verify that we can actually set the attribute MaxBurstAllowance");
312 "There should be zero forced drops");
315 queue = CreateObject<PieQueueDisc>();
317 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
319 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
321 "Verify that we can actually set the attribute MaxSize");
324 "Verify that we can actually set the attribute Tupdate");
327 "Verify that we can actually set the attribute DequeueThreshold");
329 queue->SetAttributeFailSafe(
"QueueDelayReference",
TimeValue(
Seconds(0.08))),
331 "Verify that we can actually set the attribute QueueDelayReference");
334 "Verify that we can actually set the attribute MaxBurstAllowance");
340 st = queue->GetStats();
345 "There should be zero forced drops");
348 queue = CreateObject<PieQueueDisc>();
350 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
352 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
354 "Verify that we can actually set the attribute MaxSize");
357 "Verify that we can actually set the attribute Tupdate");
360 "Verify that we can actually set the attribute DequeueThreshold");
362 queue->SetAttributeFailSafe(
"QueueDelayReference",
TimeValue(
Seconds(0.02))),
364 "Verify that we can actually set the attribute QueueDelayReference");
367 "Verify that we can actually set the attribute MaxBurstAllowance");
373 st = queue->GetStats();
378 "There should be zero forced drops");
381 queue = CreateObject<PieQueueDisc>();
383 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
385 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
387 "Verify that we can actually set the attribute MaxSize");
390 "Verify that we can actually set the attribute Tupdate");
393 "Verify that we can actually set the attribute DequeueThreshold");
395 queue->SetAttributeFailSafe(
"QueueDelayReference",
TimeValue(
Seconds(0.02))),
397 "Verify that we can actually set the attribute QueueDelayReference");
400 "Verify that we can actually set the attribute MaxBurstAllowance");
406 st = queue->GetStats();
411 "There should be zero forced drops");
414 queue = CreateObject<PieQueueDisc>();
416 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
418 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
420 "Verify that we can actually set the attribute MaxSize");
422 queue->SetAttributeFailSafe(
"UseDequeueRateEstimator",
BooleanValue(
true)),
424 "Verify that we can actually set the attribute UseTimestamp");
430 st = queue->GetStats();
435 "There should be zero forced drops");
438 queue = CreateObject<PieQueueDisc>();
440 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
442 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
444 "Verify that we can actually set the attribute MaxSize");
447 "Verify that we can actually set the attribute UseCapDropAdjustment");
449 testAttributes->m_checkProb =
true;
454 st = queue->GetStats();
459 "There should be zero forced drops");
462 "Maximum increase in drop probability should be greater than 0.02");
465 queue = CreateObject<PieQueueDisc>();
467 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
469 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
471 "Verify that we can actually set the attribute MaxSize");
474 "Verify that we can actually set the attribute UseCapDropAdjustment");
476 testAttributes->m_checkProb =
true;
481 st = queue->GetStats();
486 "There should be zero forced drops");
488 testAttributes->m_maxDropProbDiff,
490 "Maximum increase in drop probability should be less than or equal to 0.02");
493 queue = CreateObject<PieQueueDisc>();
495 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
497 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
499 "Verify that we can actually set the attribute MaxSize");
502 "Verify that we can actually set the attribute UseEcn");
505 "Verify that we can actually set the attribute MarkEcnThreshold");
511 st = queue->GetStats();
516 "There should be some unforced drops");
519 "There should be zero forced drops");
522 queue = CreateObject<PieQueueDisc>();
524 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
526 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
528 "Verify that we can actually set the attribute MaxSize");
531 "Verify that we can actually set the attribute UseEcn");
534 "Verify that we can actually set the attribute MarkEcnThreshold");
536 testAttributes->m_ecnCapable =
true;
541 st = queue->GetStats();
546 "There should be some unforced drops");
549 "There should be zero forced drops");
552 queue = CreateObject<PieQueueDisc>();
554 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
556 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
558 "Verify that we can actually set the attribute MaxSize");
561 "Verify that we can actually set the attribute UseEcn");
564 "Verify that we can actually set the attribute MarkEcnThreshold");
566 testAttributes->m_ecnCapable =
true;
567 testAttributes->m_checkProb =
true;
572 st = queue->GetStats();
579 "There should be some unforced drops");
583 "Maximum Drop probability should be greater than 0.3");
586 "There should be zero forced drops");
589 queue = CreateObject<PieQueueDisc>();
591 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
593 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
595 "Verify that we can actually set the attribute MaxSize");
598 "Verify that we can actually set the attribute UseDerandomization");
600 testAttributes->m_checkAccuProb =
true;
605 st = queue->GetStats();
610 "There should be zero forced drops");
613 "There should not be any error in setting accuProb");
616 queue = CreateObject<PieQueueDisc>();
618 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
620 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
622 "Verify that we can actually set the attribute MaxSize");
625 "Verify that we can actually set the attribute UseDerandomization");
627 testAttributes->m_constAccuProb =
true;
630 testAttributes->m_setAccuProb = -0.16;
635 st = queue->GetStats();
640 "There should be zero forced drops");
643 queue = CreateObject<PieQueueDisc>();
645 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
647 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
649 "Verify that we can actually set the attribute MaxSize");
652 "Verify that we can actually set the attribute MaxBurstAllowance");
655 "Verify that we can actually set the attribute UseDerandomization");
657 testAttributes->m_constAccuProb =
true;
658 testAttributes->m_checkMaxAccuProb =
true;
661 testAttributes->m_setAccuProb = 8.6;
666 st = queue->GetStats();
670 testAttributes->m_expectedDrops,
671 "The number of unforced drops should be equal to number of expected unforced drops");
674 "There should be zero forced drops");
678 queue = CreateObject<PieQueueDisc>();
680 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
681 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize)));
689 st = queue->GetStats();
694 "There should be zero marks");
698 queue = CreateObject<PieQueueDisc>();
700 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
701 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize)));
709 st = queue->GetStats();
714 "There should be zero marks");
724 for (uint32_t i = 0; i < nPkt; i++)
726 if (testAttributes->m_constAccuProb)
728 queue->m_accuProb = testAttributes->m_setAccuProb;
729 if (testAttributes->m_checkMaxAccuProb)
735 Create<PieQueueDiscTestItem>(Create<Packet>(size), dest, testAttributes->m_ecnCapable));
736 if (testAttributes->m_checkProb)
740 if (testAttributes->m_checkAccuProb)
751 double dropProb = queue->m_dropProb;
752 if (testAttributes->m_maxDropProb < dropProb)
754 testAttributes->m_maxDropProb = dropProb;
756 if (testAttributes->m_prevDropProb > 0.1)
758 double currentDiff = dropProb - testAttributes->m_prevDropProb;
759 if (testAttributes->m_maxDropProbDiff < currentDiff)
761 testAttributes->m_maxDropProbDiff = currentDiff;
764 testAttributes->m_prevDropProb = dropProb;
771 double dropProb = queue->m_dropProb;
772 double accuProb = queue->m_accuProb;
775 double expectedAccuProb = testAttributes->m_prevAccuProb + dropProb;
776 testAttributes->m_accuProbError = accuProb - expectedAccuProb;
778 testAttributes->m_prevAccuProb = accuProb;
785 queue->m_dropProb = 0.001;
790 testAttributes->m_expectedDrops = testAttributes->m_expectedDrops + 1;
802 for (uint32_t i = 0; i < nPkt; i++)
804 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
817 for (uint32_t i = 0; i < nPkt; i++)
826 for (uint32_t i = 0; i < nPkt; i++)
828 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
841 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
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.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
@ UNIT
This test suite implements a Unit Test.
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)