24 #include "ns3/red-queue-disc.h"
25 #include "ns3/packet.h"
26 #include "ns3/uinteger.h"
27 #include "ns3/string.h"
28 #include "ns3/double.h"
30 #include "ns3/simulator.h"
56 virtual void AddHeader (
void);
57 virtual bool Mark(
void);
67 m_ecnCapablePacket (ecnCapable)
100 virtual void DoRun (
void);
118 :
TestCase (
"Sanity check on the red queue implementation")
127 uint32_t modeSize = 1;
135 "Verify that we can actually set the attribute MinTh");
137 "Verify that we can actually set the attribute MaxTh");
139 true,
"Verify that we can actually set the attribute MaxSize");
141 "Verify that we can actually set the attribute QW");
150 queue->SetTh (minTh * modeSize, maxTh * modeSize);
151 queue->SetMaxSize (
QueueSize (mode, qSize * modeSize));
164 queue->Initialize ();
165 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 0 * modeSize,
"There should be no packets in there");
166 queue->Enqueue (Create<RedQueueDiscTestItem> (p1, dest,
false));
167 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 1 * modeSize,
"There should be one packet in there");
168 queue->Enqueue (Create<RedQueueDiscTestItem> (p2, dest,
false));
169 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 2 * modeSize,
"There should be two packets in there");
170 queue->Enqueue (Create<RedQueueDiscTestItem> (p3, dest,
false));
171 queue->Enqueue (Create<RedQueueDiscTestItem> (p4, dest,
false));
172 queue->Enqueue (Create<RedQueueDiscTestItem> (p5, dest,
false));
173 queue->Enqueue (Create<RedQueueDiscTestItem> (p6, dest,
false));
174 queue->Enqueue (Create<RedQueueDiscTestItem> (p7, dest,
false));
175 queue->Enqueue (Create<RedQueueDiscTestItem> (p8, dest,
false));
176 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 8 * modeSize,
"There should be eight packets in there");
180 item = queue->Dequeue ();
182 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 7 * modeSize,
"There should be seven packets in there");
185 item = queue->Dequeue ();
187 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 6 * modeSize,
"There should be six packet in there");
190 item = queue->Dequeue ();
192 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 5 * modeSize,
"There should be five packets in there");
195 item = queue->Dequeue ();
196 item = queue->Dequeue ();
197 item = queue->Dequeue ();
198 item = queue->Dequeue ();
199 item = queue->Dequeue ();
201 item = queue->Dequeue ();
206 queue = CreateObject<RedQueueDisc> ();
207 minTh = 70 * modeSize;
208 maxTh = 150 * modeSize;
209 qSize = 300 * modeSize;
211 "Verify that we can actually set the attribute MinTh");
213 "Verify that we can actually set the attribute MaxTh");
215 true,
"Verify that we can actually set the attribute MaxSize");
216 queue->Initialize ();
220 "There should be zero unforced drops");
222 "There should be zero forced dropps");
224 "There should be zero drops due to queue limit");
240 queue = CreateObject<RedQueueDisc> ();
242 "Verify that we can actually set the attribute MinTh");
244 "Verify that we can actually set the attribute MaxTh");
246 true,
"Verify that we can actually set the attribute MaxSize");
248 "Verify that we can actually set the attribute QW");
249 queue->Initialize ();
251 st = queue->GetStats ();
259 maxTh = 100 * modeSize;
260 queue = CreateObject<RedQueueDisc> ();
262 "Verify that we can actually set the attribute MinTh");
264 "Verify that we can actually set the attribute MaxTh");
266 true,
"Verify that we can actually set the attribute MaxSize");
268 "Verify that we can actually set the attribute QW");
269 queue->Initialize ();
271 st = queue->GetStats ();
279 maxTh = 150 * modeSize;
280 queue = CreateObject<RedQueueDisc> ();
282 "Verify that we can actually set the attribute MinTh");
284 "Verify that we can actually set the attribute MaxTh");
286 true,
"Verify that we can actually set the attribute MaxSize");
288 "Verify that we can actually set the attribute QW");
290 "Verify that we can actually set the attribute LInterm");
291 queue->Initialize ();
293 st = queue->GetStats ();
301 queue = CreateObject<RedQueueDisc> ();
303 "Verify that we can actually set the attribute MinTh");
305 "Verify that we can actually set the attribute MaxTh");
307 true,
"Verify that we can actually set the attribute MaxSize");
309 "Verify that we can actually set the attribute QW");
311 "Verify that we can actually set the attribute Gentle");
312 queue->Initialize ();
314 st = queue->GetStats ();
322 queue = CreateObject<RedQueueDisc> ();
324 "Verify that we can actually set the attribute MinTh");
326 "Verify that we can actually set the attribute MaxTh");
328 true,
"Verify that we can actually set the attribute MaxSize");
330 "Verify that we can actually set the attribute QW");
332 "Verify that we can actually set the attribute Wait");
333 queue->Initialize ();
335 st = queue->GetStats ();
343 queue = CreateObject<RedQueueDisc> ();
344 minTh = 30 * modeSize;
345 maxTh = 90 * modeSize;
347 "Verify that we can actually set the attribute MinTh");
349 "Verify that we can actually set the attribute MaxTh");
351 true,
"Verify that we can actually set the attribute MaxSize");
353 "Verify that we can actually set the attribute QW");
355 "Verify that we can actually set the attribute LInterm");
357 "Verify that we can actually set the attribute Gentle");
359 "Verify that we can actually set the attribute UseECN");
360 queue->Initialize ();
362 st = queue->GetStats ();
365 "There should be some unforced drops");
367 "There should be no unforced marks");
371 queue = CreateObject<RedQueueDisc> ();
373 "Verify that we can actually set the attribute MinTh");
375 "Verify that we can actually set the attribute MaxTh");
377 true,
"Verify that we can actually set the attribute MaxSize");
379 "Verify that we can actually set the attribute QW");
381 "Verify that we can actually set the attribute LInterm");
383 "Verify that we can actually set the attribute Gentle");
385 "Verify that we can actually set the attribute UseECN");
386 queue->Initialize ();
388 st = queue->GetStats ();
391 "There should be some unforced drops");
393 "There should be no unforced marks");
397 queue = CreateObject<RedQueueDisc> ();
399 "Verify that we can actually set the attribute MinTh");
401 "Verify that we can actually set the attribute MaxTh");
403 true,
"Verify that we can actually set the attribute MaxSize");
405 "Verify that we can actually set the attribute QW");
407 "Verify that we can actually set the attribute LInterm");
409 "Verify that we can actually set the attribute Gentle");
411 "Verify that we can actually set the attribute UseECN");
412 queue->Initialize ();
414 st = queue->GetStats ();
417 "There should be no unforced drops");
419 "There should be some unforced marks");
423 queue = CreateObject<RedQueueDisc> ();
424 minTh = 30 * modeSize;
425 maxTh = 90 * modeSize;
427 "Verify that we can actually set the attribute MinTh");
429 "Verify that we can actually set the attribute MaxTh");
431 true,
"Verify that we can actually set the attribute MaxSize");
433 "Verify that we can actually set the attribute QW");
435 "Verify that we can actually set the attribute LInterm");
437 "Verify that we can actually set the attribute Gentle");
438 queue->Initialize ();
440 st = queue->GetStats ();
446 queue = CreateObject<RedQueueDisc> ();
448 "Verify that we can actually set the attribute MinTh");
450 "Verify that we can actually set the attribute MaxTh");
452 true,
"Verify that we can actually set the attribute MaxSize");
454 "Verify that we can actually set the attribute QW");
456 "Verify that we can actually set the attribute LInterm");
458 "Verify that we can actually set the attribute Gentle");
460 "Verify that we can actually set the attribute FengAdaptive");
461 queue->Initialize ();
463 st = queue->GetStats ();
465 NS_TEST_ASSERT_MSG_LT (drop.test12, drop.test11,
"Test 12 should have less drops due to probability mark than test 11");
469 queue = CreateObject<RedQueueDisc> ();
470 minTh = 30 * modeSize;
471 maxTh = 90 * modeSize;
473 "Verify that we can actually set the attribute MinTh");
475 "Verify that we can actually set the attribute MaxTh");
477 true,
"Verify that we can actually set the attribute MaxSize");
479 "Verify that we can actually set the attribute QW");
481 "Verify that we can actually set the attribute LInterm");
483 "Verify that we can actually set the attribute Gentle");
485 "Verify that we can actually set the attribute NLRED");
486 queue->Initialize ();
488 st = queue->GetStats ();
490 NS_TEST_ASSERT_MSG_LT (drop.test13, drop.test11,
"Test 13 should have less drops due to probability mark than test 11");
498 for (uint32_t i = 0; i < nPkt; i++)
500 queue->Enqueue (Create<RedQueueDiscTestItem> (Create<Packet> (size), dest, ecnCapable));
509 Simulator::Destroy ();
Red Queue Disc Test Case.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void RunRedTest(QueueSizeUnit mode)
Run RED test function.
void Enqueue(Ptr< RedQueueDisc > queue, uint32_t size, uint32_t nPkt, bool ecnCapable)
Enqueue function.
Red Queue Disc Test Item.
virtual ~RedQueueDiscTestItem()
virtual void AddHeader(void)
Add the header to the packet.
RedQueueDiscTestItem(const RedQueueDiscTestItem &)=delete
bool m_ecnCapablePacket
ECN capable packet?
virtual bool Mark(void)
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
Red 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.
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.
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.
RedQueueDiscTestSuite g_redQueueTestSuite
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)