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"
53 virtual void AddHeader (
void);
54 virtual bool Mark (
void);
57 double m_maxDropProbDiff = 0.0;
58 double m_prevDropProb = 0.0;
59 bool m_checkProb =
false;
62 double m_maxDropProb = 0.0;
63 bool m_ecnCapable =
false;
66 bool m_checkAccuProb =
false;
67 bool m_constAccuProb =
false;
68 bool m_checkMaxAccuProb =
false;
69 double m_accuProbError = 0.0;
70 double m_prevAccuProb = 0.0;
71 double m_setAccuProb = 0.0;
72 uint32_t m_expectedDrops = 0;
124 virtual void DoRun (
void);
181 :
TestCase (
"Sanity check on the pie queue disc implementation")
191 uint32_t modeSize = 1;
193 uint32_t qSize = 300;
207 qSize = qSize * modeSize;
211 true,
"Verify that we can actually set the attribute MaxSize");
223 queue->Initialize ();
224 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 0 * modeSize,
"There should be no packets in there");
225 queue->Enqueue (Create<PieQueueDiscTestItem> (p1, dest,
false));
226 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 1 * modeSize,
"There should be one packet in there");
227 queue->Enqueue (Create<PieQueueDiscTestItem> (p2, dest,
false));
228 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 2 * modeSize,
"There should be two packets in there");
229 queue->Enqueue (Create<PieQueueDiscTestItem> (p3, dest,
false));
230 queue->Enqueue (Create<PieQueueDiscTestItem> (p4, dest,
false));
231 queue->Enqueue (Create<PieQueueDiscTestItem> (p5, dest,
false));
232 queue->Enqueue (Create<PieQueueDiscTestItem> (p6, dest,
false));
233 queue->Enqueue (Create<PieQueueDiscTestItem> (p7, dest,
false));
234 queue->Enqueue (Create<PieQueueDiscTestItem> (p8, dest,
false));
235 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 8 * modeSize,
"There should be eight packets in there");
239 item = queue->Dequeue ();
241 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 7 * modeSize,
"There should be seven packets in there");
244 item = queue->Dequeue ();
246 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 6 * modeSize,
"There should be six packet in there");
249 item = queue->Dequeue ();
251 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 5 * modeSize,
"There should be five packets in there");
254 item = queue->Dequeue ();
255 item = queue->Dequeue ();
256 item = queue->Dequeue ();
257 item = queue->Dequeue ();
258 item = queue->Dequeue ();
260 item = queue->Dequeue ();
265 queue = CreateObject<PieQueueDisc> ();
267 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
270 true,
"Verify that we can actually set the attribute MaxSize");
272 "Verify that we can actually set the attribute Tupdate");
274 "Verify that we can actually set the attribute DequeueThreshold");
276 "Verify that we can actually set the attribute QueueDelayReference");
278 "Verify that we can actually set the attribute MaxBurstAllowance");
279 queue->Initialize ();
282 Simulator::Stop (
Seconds (8.0));
291 queue = CreateObject<PieQueueDisc> ();
293 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
295 true,
"Verify that we can actually set the attribute MaxSize");
297 "Verify that we can actually set the attribute Tupdate");
299 "Verify that we can actually set the attribute DequeueThreshold");
301 "Verify that we can actually set the attribute QueueDelayReference");
303 "Verify that we can actually set the attribute MaxBurstAllowance");
304 queue->Initialize ();
307 Simulator::Stop (
Seconds (8.0));
309 st = queue->GetStats ();
316 queue = CreateObject<PieQueueDisc> ();
318 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
320 true,
"Verify that we can actually set the attribute MaxSize");
322 "Verify that we can actually set the attribute Tupdate");
324 "Verify that we can actually set the attribute DequeueThreshold");
326 "Verify that we can actually set the attribute QueueDelayReference");
328 "Verify that we can actually set the attribute MaxBurstAllowance");
329 queue->Initialize ();
332 Simulator::Stop (
Seconds (8.0));
334 st = queue->GetStats ();
341 queue = CreateObject<PieQueueDisc> ();
343 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
345 true,
"Verify that we can actually set the attribute MaxSize");
347 "Verify that we can actually set the attribute Tupdate");
349 "Verify that we can actually set the attribute DequeueThreshold");
351 "Verify that we can actually set the attribute QueueDelayReference");
353 "Verify that we can actually set the attribute MaxBurstAllowance");
354 queue->Initialize ();
357 Simulator::Stop (
Seconds (8.0));
359 st = queue->GetStats ();
366 queue = CreateObject<PieQueueDisc> ();
368 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
370 true,
"Verify that we can actually set the attribute MaxSize");
372 "Verify that we can actually set the attribute UseTimestamp");
373 queue->Initialize ();
376 Simulator::Stop (
Seconds (8.0));
378 st = queue->GetStats ();
385 queue = CreateObject<PieQueueDisc> ();
387 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
389 true,
"Verify that we can actually set the attribute MaxSize");
391 "Verify that we can actually set the attribute UseCapDropAdjustment");
392 queue->Initialize ();
393 testAttributes->m_checkProb =
true;
396 Simulator::Stop (
Seconds (8.0));
398 st = queue->GetStats ();
403 "Maximum increase in drop probability should be greater than 0.02");
407 queue = CreateObject<PieQueueDisc> ();
409 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
411 true,
"Verify that we can actually set the attribute MaxSize");
413 "Verify that we can actually set the attribute UseCapDropAdjustment");
414 queue->Initialize ();
415 testAttributes->m_checkProb =
true;
418 Simulator::Stop (
Seconds (8.0));
420 st = queue->GetStats ();
425 "Maximum increase in drop probability should be less than or equal to 0.02");
429 queue = CreateObject<PieQueueDisc> ();
431 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
433 true,
"Verify that we can actually set the attribute MaxSize");
435 "Verify that we can actually set the attribute UseEcn");
437 "Verify that we can actually set the attribute MarkEcnThreshold");
438 queue->Initialize ();
441 Simulator::Stop (
Seconds (8.0));
443 st = queue->GetStats ();
451 queue = CreateObject<PieQueueDisc> ();
453 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
455 true,
"Verify that we can actually set the attribute MaxSize");
457 "Verify that we can actually set the attribute UseEcn");
459 "Verify that we can actually set the attribute MarkEcnThreshold");
460 queue->Initialize ();
461 testAttributes->m_ecnCapable =
true;
464 Simulator::Stop (
Seconds (8.0));
466 st = queue->GetStats ();
474 queue = CreateObject<PieQueueDisc> ();
476 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
478 true,
"Verify that we can actually set the attribute MaxSize");
480 "Verify that we can actually set the attribute UseEcn");
482 "Verify that we can actually set the attribute MarkEcnThreshold");
483 queue->Initialize ();
484 testAttributes->m_ecnCapable =
true;
485 testAttributes->m_checkProb =
true;
488 Simulator::Stop (
Seconds (8.0));
490 st = queue->GetStats ();
497 NS_TEST_EXPECT_MSG_GT (testAttributes->m_maxDropProb, 0.3,
"Maximum Drop probability should be greater than 0.3");
502 queue = CreateObject<PieQueueDisc> ();
504 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
506 true,
"Verify that we can actually set the attribute MaxSize");
508 "Verify that we can actually set the attribute UseDerandomization");
509 queue->Initialize ();
510 testAttributes->m_checkAccuProb =
true;
513 Simulator::Stop (
Seconds (8.0));
515 st = queue->GetStats ();
519 NS_TEST_EXPECT_MSG_EQ (testAttributes->m_accuProbError, 0.0,
"There should not be any error in setting accuProb");
523 queue = CreateObject<PieQueueDisc> ();
525 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
527 true,
"Verify that we can actually set the attribute MaxSize");
529 "Verify that we can actually set the attribute UseDerandomization");
530 queue->Initialize ();
531 testAttributes->m_constAccuProb =
true;
533 testAttributes->m_setAccuProb = -0.16;
536 Simulator::Stop (
Seconds (8.0));
538 st = queue->GetStats ();
545 queue = CreateObject<PieQueueDisc> ();
547 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
549 true,
"Verify that we can actually set the attribute MaxSize");
551 "Verify that we can actually set the attribute MaxBurstAllowance");
553 "Verify that we can actually set the attribute UseDerandomization");
554 queue->Initialize ();
555 testAttributes->m_constAccuProb =
true;
556 testAttributes->m_checkMaxAccuProb =
true;
558 testAttributes->m_setAccuProb = 8.6;
561 Simulator::Stop (
Seconds (8.0));
563 st = queue->GetStats ();
566 "The number of unforced drops should be equal to number of expected unforced drops");
572 queue = CreateObject<PieQueueDisc> ();
574 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
577 queue->Initialize ();
581 Simulator::Stop (
Seconds (8.0));
583 st = queue->GetStats ();
591 queue = CreateObject<PieQueueDisc> ();
593 testAttributes = Create<PieQueueDiscTestItem> (Create<Packet> (
pktSize), dest,
false);
595 queue->SetAttributeFailSafe (
"ActiveThreshold",
TimeValue (
Seconds (0.001)));
596 queue->Initialize ();
600 Simulator::Stop (
Seconds (8.0));
602 st = queue->GetStats ();
612 for (uint32_t i = 0; i < nPkt; i++)
614 if (testAttributes->m_constAccuProb)
616 queue->m_accuProb = testAttributes->m_setAccuProb;
617 if (testAttributes->m_checkMaxAccuProb)
622 queue->Enqueue (Create<PieQueueDiscTestItem> (Create<Packet> (size), dest, testAttributes->m_ecnCapable));
623 if (testAttributes->m_checkProb)
627 if (testAttributes->m_checkAccuProb)
637 double dropProb = queue->m_dropProb;
638 if (testAttributes->m_maxDropProb < dropProb)
640 testAttributes->m_maxDropProb = dropProb;
642 if (testAttributes->m_prevDropProb > 0.1)
644 double currentDiff = dropProb - testAttributes->m_prevDropProb;
645 if (testAttributes->m_maxDropProbDiff < currentDiff)
647 testAttributes->m_maxDropProbDiff = currentDiff;
650 testAttributes->m_prevDropProb = dropProb;
656 double dropProb = queue->m_dropProb;
657 double accuProb = queue->m_accuProb;
660 double expectedAccuProb = testAttributes->m_prevAccuProb + dropProb;
661 testAttributes->m_accuProbError = accuProb - expectedAccuProb;
663 testAttributes->m_prevAccuProb = accuProb;
669 queue->m_dropProb = 0.001;
670 QueueSize queueSize = queue->GetCurrentSize ();
673 testAttributes->m_expectedDrops = testAttributes->m_expectedDrops + 1;
682 for (uint32_t i = 0; i < nPkt; i++)
691 for (uint32_t i = 0; i < nPkt; i++)
700 for (uint32_t i = 0; i < nPkt; i++)
711 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 &)
Copy constructor Disable default implementation to avoid misuse.
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.
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_EXPECT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report if not.
#define NS_TEST_EXPECT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report if not.
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report 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)