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"
84 m_ecnCapablePacket(ecnCapable)
108 void DoRun()
override;
172 :
TestCase(
"Sanity check on the pie queue disc implementation")
191 Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
193 if (mode == QueueSizeUnit::BYTES)
199 qSize = qSize * modeSize;
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
689 st = queue->GetStats();
694 "There should be zero marks");
698 queue = CreateObject<PieQueueDisc>();
700 testAttributes = Create<PieQueueDiscTestItem>(Create<Packet>(
pktSize), dest,
false);
709 st = queue->GetStats();
714 "There should be zero marks");
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;
786 QueueSize queueSize = queue->GetCurrentSize();
787 if ((queueSize.
GetUnit() == QueueSizeUnit::PACKETS && queueSize.
GetValue() > 2) ||
788 (queueSize.
GetUnit() == QueueSizeUnit::BYTES && queueSize.
GetValue() > 2000))
790 testAttributes->m_expectedDrops = testAttributes->m_expectedDrops + 1;
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'.
static constexpr const char * UNFORCED_DROP
Early probability drops: proactive.
static constexpr const char * FORCED_DROP
Drops due to queue limit: reactive.
static constexpr const char * UNFORCED_MARK
Early probability marks: proactive.
Smart pointer class similar to boost::intrusive_ptr.
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.
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.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
@ UNIT
This test suite implements a Unit Test.
Simulation virtual time values and global simulation resolution.
AttributeValue implementation for Time.
Hold an unsigned integer type.
QueueSizeUnit
Enumeration of the operating modes of queues.
#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
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)