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"
85 m_ecnCapablePacket(ecnCapable)
114 void DoRun()
override;
178 :
TestCase(
"Sanity check on the pie queue disc implementation")
197 Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
205 qSize = qSize * modeSize;
211 "Verify that we can actually set the attribute MaxSize");
233 "There should be no packets in there");
234 queue->Enqueue(Create<PieQueueDiscTestItem>(p1, dest,
false));
237 "There should be one packet in there");
238 queue->Enqueue(Create<PieQueueDiscTestItem>(p2, dest,
false));
241 "There should be two packets in there");
242 queue->Enqueue(Create<PieQueueDiscTestItem>(p3, dest,
false));
243 queue->Enqueue(Create<PieQueueDiscTestItem>(p4, dest,
false));
244 queue->Enqueue(Create<PieQueueDiscTestItem>(p5, dest,
false));
245 queue->Enqueue(Create<PieQueueDiscTestItem>(p6, dest,
false));
246 queue->Enqueue(Create<PieQueueDiscTestItem>(p7, dest,
false));
247 queue->Enqueue(Create<PieQueueDiscTestItem>(p8, dest,
false));
250 "There should be eight packets in there");
254 item = queue->Dequeue();
258 "There should be seven packets in there");
261 item = queue->Dequeue();
265 "There should be six packet in there");
268 "Was this the second packet ?");
270 item = queue->Dequeue();
274 "There should be five packets in there");
277 item = queue->Dequeue();
278 item = queue->Dequeue();
279 item = queue->Dequeue();
280 item = queue->Dequeue();
281 item = queue->Dequeue();
283 item = queue->Dequeue();
287 queue = CreateObject<PieQueueDisc>();
289 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
294 "Verify that we can actually set the attribute MaxSize");
297 "Verify that we can actually set the attribute Tupdate");
300 "Verify that we can actually set the attribute DequeueThreshold");
302 queue->SetAttributeFailSafe(
"QueueDelayReference",
TimeValue(
Seconds(0.02))),
304 "Verify that we can actually set the attribute QueueDelayReference");
307 "Verify that we can actually set the attribute MaxBurstAllowance");
318 "There should be zero forced drops");
321 queue = CreateObject<PieQueueDisc>();
323 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
327 "Verify that we can actually set the attribute MaxSize");
330 "Verify that we can actually set the attribute Tupdate");
333 "Verify that we can actually set the attribute DequeueThreshold");
335 queue->SetAttributeFailSafe(
"QueueDelayReference",
TimeValue(
Seconds(0.08))),
337 "Verify that we can actually set the attribute QueueDelayReference");
340 "Verify that we can actually set the attribute MaxBurstAllowance");
346 st = queue->GetStats();
351 "There should be zero forced drops");
354 queue = CreateObject<PieQueueDisc>();
356 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
360 "Verify that we can actually set the attribute MaxSize");
363 "Verify that we can actually set the attribute Tupdate");
366 "Verify that we can actually set the attribute DequeueThreshold");
368 queue->SetAttributeFailSafe(
"QueueDelayReference",
TimeValue(
Seconds(0.02))),
370 "Verify that we can actually set the attribute QueueDelayReference");
373 "Verify that we can actually set the attribute MaxBurstAllowance");
379 st = queue->GetStats();
384 "There should be zero forced drops");
387 queue = CreateObject<PieQueueDisc>();
389 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
393 "Verify that we can actually set the attribute MaxSize");
396 "Verify that we can actually set the attribute Tupdate");
399 "Verify that we can actually set the attribute DequeueThreshold");
401 queue->SetAttributeFailSafe(
"QueueDelayReference",
TimeValue(
Seconds(0.02))),
403 "Verify that we can actually set the attribute QueueDelayReference");
406 "Verify that we can actually set the attribute MaxBurstAllowance");
412 st = queue->GetStats();
417 "There should be zero forced drops");
420 queue = CreateObject<PieQueueDisc>();
422 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
426 "Verify that we can actually set the attribute MaxSize");
428 queue->SetAttributeFailSafe(
"UseDequeueRateEstimator",
BooleanValue(
true)),
430 "Verify that we can actually set the attribute UseTimestamp");
436 st = queue->GetStats();
441 "There should be zero forced drops");
444 queue = CreateObject<PieQueueDisc>();
446 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
450 "Verify that we can actually set the attribute MaxSize");
453 "Verify that we can actually set the attribute UseCapDropAdjustment");
455 testAttributes->m_checkProb =
true;
460 st = queue->GetStats();
465 "There should be zero forced drops");
468 "Maximum increase in drop probability should be greater than 0.02");
471 queue = CreateObject<PieQueueDisc>();
473 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
477 "Verify that we can actually set the attribute MaxSize");
480 "Verify that we can actually set the attribute UseCapDropAdjustment");
482 testAttributes->m_checkProb =
true;
487 st = queue->GetStats();
492 "There should be zero forced drops");
494 testAttributes->m_maxDropProbDiff,
496 "Maximum increase in drop probability should be less than or equal to 0.02");
499 queue = CreateObject<PieQueueDisc>();
501 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
505 "Verify that we can actually set the attribute MaxSize");
508 "Verify that we can actually set the attribute UseEcn");
511 "Verify that we can actually set the attribute MarkEcnThreshold");
517 st = queue->GetStats();
522 "There should be some unforced drops");
525 "There should be zero forced drops");
528 queue = CreateObject<PieQueueDisc>();
530 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
534 "Verify that we can actually set the attribute MaxSize");
537 "Verify that we can actually set the attribute UseEcn");
540 "Verify that we can actually set the attribute MarkEcnThreshold");
542 testAttributes->m_ecnCapable =
true;
547 st = queue->GetStats();
552 "There should be some unforced drops");
555 "There should be zero forced drops");
558 queue = CreateObject<PieQueueDisc>();
560 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
564 "Verify that we can actually set the attribute MaxSize");
567 "Verify that we can actually set the attribute UseEcn");
570 "Verify that we can actually set the attribute MarkEcnThreshold");
572 testAttributes->m_ecnCapable =
true;
573 testAttributes->m_checkProb =
true;
578 st = queue->GetStats();
585 "There should be some unforced drops");
589 "Maximum Drop probability should be greater than 0.3");
592 "There should be zero forced drops");
595 queue = CreateObject<PieQueueDisc>();
597 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
601 "Verify that we can actually set the attribute MaxSize");
604 "Verify that we can actually set the attribute UseDerandomization");
606 testAttributes->m_checkAccuProb =
true;
611 st = queue->GetStats();
616 "There should be zero forced drops");
619 "There should not be any error in setting accuProb");
622 queue = CreateObject<PieQueueDisc>();
624 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
628 "Verify that we can actually set the attribute MaxSize");
631 "Verify that we can actually set the attribute UseDerandomization");
633 testAttributes->m_constAccuProb =
true;
636 testAttributes->m_setAccuProb = -0.16;
641 st = queue->GetStats();
646 "There should be zero forced drops");
649 queue = CreateObject<PieQueueDisc>();
651 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
655 "Verify that we can actually set the attribute MaxSize");
658 "Verify that we can actually set the attribute MaxBurstAllowance");
661 "Verify that we can actually set the attribute UseDerandomization");
663 testAttributes->m_constAccuProb =
true;
664 testAttributes->m_checkMaxAccuProb =
true;
667 testAttributes->m_setAccuProb = 8.6;
672 st = queue->GetStats();
676 testAttributes->m_expectedDrops,
677 "The number of unforced drops should be equal to number of expected unforced drops");
680 "There should be zero forced drops");
684 queue = CreateObject<PieQueueDisc>();
686 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
695 st = queue->GetStats();
700 "There should be zero marks");
704 queue = CreateObject<PieQueueDisc>();
706 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
715 st = queue->GetStats();
720 "There should be zero marks");
732 if (testAttributes->m_constAccuProb)
734 queue->m_accuProb = testAttributes->m_setAccuProb;
735 if (testAttributes->m_checkMaxAccuProb)
741 Create<PieQueueDiscTestItem>(Create<Packet>(size), dest, testAttributes->m_ecnCapable));
742 if (testAttributes->m_checkProb)
746 if (testAttributes->m_checkAccuProb)
757 double dropProb = queue->m_dropProb;
758 if (testAttributes->m_maxDropProb < dropProb)
760 testAttributes->m_maxDropProb = dropProb;
762 if (testAttributes->m_prevDropProb > 0.1)
764 double currentDiff = dropProb - testAttributes->m_prevDropProb;
765 if (testAttributes->m_maxDropProbDiff < currentDiff)
767 testAttributes->m_maxDropProbDiff = currentDiff;
770 testAttributes->m_prevDropProb = dropProb;
777 double dropProb = queue->m_dropProb;
778 double accuProb = queue->m_accuProb;
781 double expectedAccuProb = testAttributes->m_prevAccuProb + dropProb;
782 testAttributes->m_accuProbError = accuProb - expectedAccuProb;
784 testAttributes->m_prevAccuProb = accuProb;
791 queue->m_dropProb = 0.001;
792 QueueSize queueSize = queue->GetCurrentSize();
796 testAttributes->m_expectedDrops = testAttributes->m_expectedDrops + 1;
810 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
834 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
847 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.
double m_prevDropProb
Previous drop probability.
bool m_checkAccuProb
Enable/Disable accumulated drop probability checks.
bool m_ecnCapable
Enable/Disable ECN capability.
double m_maxDropProbDiff
Maximum difference between two consecutive drop probability values.
bool m_constAccuProb
Enable/Disable fixed accumulated drop probability.
bool m_ecnCapablePacket
ECN capable packet?
PieQueueDiscTestItem & operator=(const PieQueueDiscTestItem &)=delete
PieQueueDiscTestItem(const PieQueueDiscTestItem &)=delete
bool m_checkProb
Enable/Disable drop probability checks.
bool m_checkMaxAccuProb
Enable/Disable Maximum accumulated drop probability checks.
double m_maxDropProb
Maximum value of drop probability.
double m_prevAccuProb
Previous accumulated drop probability.
PieQueueDiscTestItem()=delete
void AddHeader() override
Add the header to the packet.
uint32_t m_expectedDrops
Number of expected unforced drops.
double m_setAccuProb
Value to be set for accumulated drop probability.
bool Mark() override
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
double m_accuProbError
Error in accumulated drop probability.
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.
PieQueueDiscTestSuite g_pieQueueTestSuite
the test suite
Time Seconds(double 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.
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)