25 #include "ns3/pie-queue-disc.h"
26 #include "ns3/packet.h"
27 #include "ns3/uinteger.h"
28 #include "ns3/string.h"
29 #include "ns3/double.h"
31 #include "ns3/simulator.h"
58 virtual void AddHeader (
void);
59 virtual bool Mark (
void);
62 double m_maxDropProbDiff = 0.0;
63 double m_prevDropProb = 0.0;
64 bool m_checkProb =
false;
67 double m_maxDropProb = 0.0;
68 bool m_ecnCapable =
false;
71 bool m_checkAccuProb =
false;
72 bool m_constAccuProb =
false;
73 bool m_checkMaxAccuProb =
false;
74 double m_accuProbError = 0.0;
75 double m_prevAccuProb = 0.0;
76 double m_setAccuProb = 0.0;
77 uint32_t m_expectedDrops = 0;
119 virtual void DoRun (
void);
176 :
TestCase (
"Sanity check on the pie queue disc implementation")
186 uint32_t modeSize = 1;
188 uint32_t qSize = 300;
202 qSize = qSize * modeSize;
206 true,
"Verify that we can actually set the attribute MaxSize");
218 queue->Initialize ();
219 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 0 * modeSize,
"There should be no packets in there");
220 queue->Enqueue (Create<PieQueueDiscTestItem> (p1, dest,
false));
221 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 1 * modeSize,
"There should be one packet in there");
222 queue->Enqueue (Create<PieQueueDiscTestItem> (p2, dest,
false));
223 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 2 * modeSize,
"There should be two packets in there");
224 queue->Enqueue (Create<PieQueueDiscTestItem> (p3, dest,
false));
225 queue->Enqueue (Create<PieQueueDiscTestItem> (p4, dest,
false));
226 queue->Enqueue (Create<PieQueueDiscTestItem> (p5, dest,
false));
227 queue->Enqueue (Create<PieQueueDiscTestItem> (p6, dest,
false));
228 queue->Enqueue (Create<PieQueueDiscTestItem> (p7, dest,
false));
229 queue->Enqueue (Create<PieQueueDiscTestItem> (p8, dest,
false));
230 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 8 * modeSize,
"There should be eight packets in there");
234 item = queue->Dequeue ();
236 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 7 * modeSize,
"There should be seven packets in there");
239 item = queue->Dequeue ();
241 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 6 * modeSize,
"There should be six packet in there");
244 item = queue->Dequeue ();
246 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 5 * modeSize,
"There should be five packets in there");
249 item = queue->Dequeue ();
250 item = queue->Dequeue ();
251 item = queue->Dequeue ();
252 item = queue->Dequeue ();
253 item = queue->Dequeue ();
255 item = queue->Dequeue ();
260 queue = CreateObject<PieQueueDisc> ();
262 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
265 true,
"Verify that we can actually set the attribute MaxSize");
267 "Verify that we can actually set the attribute Tupdate");
269 "Verify that we can actually set the attribute DequeueThreshold");
271 "Verify that we can actually set the attribute QueueDelayReference");
273 "Verify that we can actually set the attribute MaxBurstAllowance");
274 queue->Initialize ();
277 Simulator::Stop (
Seconds (8.0));
286 queue = CreateObject<PieQueueDisc> ();
288 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
290 true,
"Verify that we can actually set the attribute MaxSize");
292 "Verify that we can actually set the attribute Tupdate");
294 "Verify that we can actually set the attribute DequeueThreshold");
296 "Verify that we can actually set the attribute QueueDelayReference");
298 "Verify that we can actually set the attribute MaxBurstAllowance");
299 queue->Initialize ();
302 Simulator::Stop (
Seconds (8.0));
304 st = queue->GetStats ();
311 queue = CreateObject<PieQueueDisc> ();
313 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
315 true,
"Verify that we can actually set the attribute MaxSize");
317 "Verify that we can actually set the attribute Tupdate");
319 "Verify that we can actually set the attribute DequeueThreshold");
321 "Verify that we can actually set the attribute QueueDelayReference");
323 "Verify that we can actually set the attribute MaxBurstAllowance");
324 queue->Initialize ();
327 Simulator::Stop (
Seconds (8.0));
329 st = queue->GetStats ();
336 queue = CreateObject<PieQueueDisc> ();
338 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
340 true,
"Verify that we can actually set the attribute MaxSize");
342 "Verify that we can actually set the attribute Tupdate");
344 "Verify that we can actually set the attribute DequeueThreshold");
346 "Verify that we can actually set the attribute QueueDelayReference");
348 "Verify that we can actually set the attribute MaxBurstAllowance");
349 queue->Initialize ();
352 Simulator::Stop (
Seconds (8.0));
354 st = queue->GetStats ();
361 queue = CreateObject<PieQueueDisc> ();
363 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
365 true,
"Verify that we can actually set the attribute MaxSize");
367 "Verify that we can actually set the attribute UseTimestamp");
368 queue->Initialize ();
371 Simulator::Stop (
Seconds (8.0));
373 st = queue->GetStats ();
380 queue = CreateObject<PieQueueDisc> ();
382 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
384 true,
"Verify that we can actually set the attribute MaxSize");
386 "Verify that we can actually set the attribute UseCapDropAdjustment");
387 queue->Initialize ();
388 testAttributes->m_checkProb =
true;
391 Simulator::Stop (
Seconds (8.0));
393 st = queue->GetStats ();
398 "Maximum increase in drop probability should be greater than 0.02");
402 queue = CreateObject<PieQueueDisc> ();
404 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
406 true,
"Verify that we can actually set the attribute MaxSize");
408 "Verify that we can actually set the attribute UseCapDropAdjustment");
409 queue->Initialize ();
410 testAttributes->m_checkProb =
true;
413 Simulator::Stop (
Seconds (8.0));
415 st = queue->GetStats ();
420 "Maximum increase in drop probability should be less than or equal to 0.02");
424 queue = CreateObject<PieQueueDisc> ();
426 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
428 true,
"Verify that we can actually set the attribute MaxSize");
430 "Verify that we can actually set the attribute UseEcn");
432 "Verify that we can actually set the attribute MarkEcnThreshold");
433 queue->Initialize ();
436 Simulator::Stop (
Seconds (8.0));
438 st = queue->GetStats ();
446 queue = CreateObject<PieQueueDisc> ();
448 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
450 true,
"Verify that we can actually set the attribute MaxSize");
452 "Verify that we can actually set the attribute UseEcn");
454 "Verify that we can actually set the attribute MarkEcnThreshold");
455 queue->Initialize ();
456 testAttributes->m_ecnCapable =
true;
459 Simulator::Stop (
Seconds (8.0));
461 st = queue->GetStats ();
469 queue = CreateObject<PieQueueDisc> ();
471 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
473 true,
"Verify that we can actually set the attribute MaxSize");
475 "Verify that we can actually set the attribute UseEcn");
477 "Verify that we can actually set the attribute MarkEcnThreshold");
478 queue->Initialize ();
479 testAttributes->m_ecnCapable =
true;
480 testAttributes->m_checkProb =
true;
483 Simulator::Stop (
Seconds (8.0));
485 st = queue->GetStats ();
492 NS_TEST_ASSERT_MSG_GT (testAttributes->m_maxDropProb, 0.3,
"Maximum Drop probability should be greater than 0.3");
497 queue = CreateObject<PieQueueDisc> ();
499 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
501 true,
"Verify that we can actually set the attribute MaxSize");
503 "Verify that we can actually set the attribute UseDerandomization");
504 queue->Initialize ();
505 testAttributes->m_checkAccuProb =
true;
508 Simulator::Stop (
Seconds (8.0));
510 st = queue->GetStats ();
514 NS_TEST_ASSERT_MSG_EQ (testAttributes->m_accuProbError, 0.0,
"There should not be any error in setting accuProb");
518 queue = CreateObject<PieQueueDisc> ();
520 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
522 true,
"Verify that we can actually set the attribute MaxSize");
524 "Verify that we can actually set the attribute UseDerandomization");
525 queue->Initialize ();
526 testAttributes->m_constAccuProb =
true;
528 testAttributes->m_setAccuProb = -0.16;
531 Simulator::Stop (
Seconds (8.0));
533 st = queue->GetStats ();
540 queue = CreateObject<PieQueueDisc> ();
542 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
544 true,
"Verify that we can actually set the attribute MaxSize");
546 "Verify that we can actually set the attribute MaxBurstAllowance");
548 "Verify that we can actually set the attribute UseDerandomization");
549 queue->Initialize ();
550 testAttributes->m_constAccuProb =
true;
551 testAttributes->m_checkMaxAccuProb =
true;
553 testAttributes->m_setAccuProb = 8.6;
556 Simulator::Stop (
Seconds (8.0));
558 st = queue->GetStats ();
561 "The number of unforced drops should be equal to number of expected unforced drops");
567 queue = CreateObject<PieQueueDisc> ();
569 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
572 queue->Initialize ();
576 Simulator::Stop (
Seconds (8.0));
578 st = queue->GetStats ();
586 queue = CreateObject<PieQueueDisc> ();
588 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
590 queue->SetAttributeFailSafe (
"ActiveThreshold",
TimeValue (
Seconds (0.001)));
591 queue->Initialize ();
595 Simulator::Stop (
Seconds (8.0));
597 st = queue->GetStats ();
607 for (uint32_t i = 0; i < nPkt; i++)
609 if (testAttributes->m_constAccuProb)
611 queue->m_accuProb = testAttributes->m_setAccuProb;
612 if (testAttributes->m_checkMaxAccuProb)
617 queue->Enqueue (Create<PieQueueDiscTestItem> (Create<Packet> (size), dest, testAttributes->m_ecnCapable));
618 if (testAttributes->m_checkProb)
622 if (testAttributes->m_checkAccuProb)
632 double dropProb = queue->m_dropProb;
633 if (testAttributes->m_maxDropProb < dropProb)
635 testAttributes->m_maxDropProb = dropProb;
637 if (testAttributes->m_prevDropProb > 0.1)
639 double currentDiff = dropProb - testAttributes->m_prevDropProb;
640 if (testAttributes->m_maxDropProbDiff < currentDiff)
642 testAttributes->m_maxDropProbDiff = currentDiff;
645 testAttributes->m_prevDropProb = dropProb;
651 double dropProb = queue->m_dropProb;
652 double accuProb = queue->m_accuProb;
655 double expectedAccuProb = testAttributes->m_prevAccuProb + dropProb;
656 testAttributes->m_accuProbError = accuProb - expectedAccuProb;
658 testAttributes->m_prevAccuProb = accuProb;
664 queue->m_dropProb = 0.001;
665 QueueSize queueSize = queue->GetCurrentSize ();
668 testAttributes->m_expectedDrops = testAttributes->m_expectedDrops + 1;
677 for (uint32_t i = 0; i < nPkt; i++)
686 for (uint32_t i = 0; i < nPkt; i++)
695 for (uint32_t i = 0; i < nPkt; i++)
706 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.
virtual void DoRun(void)
Implementation to actually run this TestCase.
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.
Pie Queue Disc Test Item.
virtual bool Mark(void)
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
bool m_ecnCapablePacket
ECN capable packet?
PieQueueDiscTestItem(const PieQueueDiscTestItem &)=delete
virtual void AddHeader(void)
Add the header to the packet.
virtual ~PieQueueDiscTestItem()
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(void) 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.
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.
@ 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.
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)