A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
adaptive-red-queue-disc-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 NITK Surathkal
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mohit P. Tahiliani <tahiliani@nitk.edu.in>
7 *
8 */
9
10#include "ns3/double.h"
11#include "ns3/log.h"
12#include "ns3/packet.h"
13#include "ns3/red-queue-disc.h"
14#include "ns3/simulator.h"
15#include "ns3/string.h"
16#include "ns3/test.h"
17#include "ns3/uinteger.h"
18
19using namespace ns3;
20
21/**
22 * @ingroup traffic-control
23 * @ingroup tests
24 * @defgroup traffic-control-test traffic-control module tests
25 */
26
27/**
28 * @ingroup traffic-control-test
29 *
30 * @brief Ared Queue Disc Test Item
31 */
33{
34 public:
35 /**
36 * Constructor
37 *
38 * @param p packet
39 * @param addr address
40 */
42 ~AredQueueDiscTestItem() override;
43
44 // Delete default constructor, copy constructor and assignment operator to avoid misuse
48
49 void AddHeader() override;
50 bool Mark() override;
51};
52
57
61
62void
66
67bool
69{
70 return false;
71}
72
73/**
74 * @ingroup traffic-control-test
75 *
76 * @brief Ared Queue Disc Test Case
77 */
79{
80 public:
82 void DoRun() override;
83
84 private:
85 /**
86 * Enqueue function
87 * @param queue the queue disc
88 * @param size the size
89 * @param nPkt the number of packets
90 */
91 void Enqueue(Ptr<RedQueueDisc> queue, uint32_t size, uint32_t nPkt);
92 /**
93 * Enqueue with delay function
94 * @param queue the queue disc
95 * @param size the size
96 * @param nPkt the number of packets
97 */
99 /**
100 * Run ARED queue disc test function
101 * @param mode the test mode
102 */
104};
105
107 : TestCase("Sanity check on the functionality of Adaptive RED")
108{
109}
110
111void
113{
114 uint32_t pktSize = 0;
115 uint32_t modeSize = 1; // 1 for packets; pktSize for bytes
116 double minTh = 70;
117 double maxTh = 150;
118 uint32_t qSize = 300;
119 Address dest;
120
121 // test 1: Verify automatic setting of QW. [QW = 0.0 with default LinkBandwidth]
123
124 if (mode == QueueSizeUnit::BYTES)
125 {
126 pktSize = 500;
127 modeSize = pktSize;
128 minTh = minTh * modeSize;
129 maxTh = maxTh * modeSize;
130 qSize = qSize * modeSize;
131 }
132
133 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
134 true,
135 "Verify that we can actually set the attribute MinTh");
136 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
137 true,
138 "Verify that we can actually set the attribute MaxTh");
140 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
141 true,
142 "Verify that we can actually set the attribute MaxSize");
143 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(0.0)),
144 true,
145 "Verify that we can actually set the attribute QW");
146 queue->Initialize();
147 Enqueue(queue, pktSize, 300);
148 QueueDisc::Stats st = queue->GetStats();
150 0,
151 "There should be zero unforced drops");
152
153 // test 2: Verify automatic setting of QW. [QW = 0.0 with lesser LinkBandwidth]
155 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
156 true,
157 "Verify that we can actually set the attribute MinTh");
158 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
159 true,
160 "Verify that we can actually set the attribute MaxTh");
162 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
163 true,
164 "Verify that we can actually set the attribute MaxSize");
165 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(0.0)),
166 true,
167 "Verify that we can actually set the attribute QW");
169 queue->SetAttributeFailSafe("LinkBandwidth", DataRateValue(DataRate("0.015Mbps"))),
170 true,
171 "Verify that we can actually set the attribute LinkBandwidth");
172 queue->Initialize();
173 Enqueue(queue, pktSize, 300);
174 st = queue->GetStats();
176 0,
177 "There should be some unforced drops");
178
179 // test 3: Verify automatic setting of QW. [QW = -1.0 with default LinkBandwidth]
181 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
182 true,
183 "Verify that we can actually set the attribute MinTh");
184 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
185 true,
186 "Verify that we can actually set the attribute MaxTh");
188 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
189 true,
190 "Verify that we can actually set the attribute MaxSize");
191 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(-1.0)),
192 true,
193 "Verify that we can actually set the attribute QW");
194 queue->Initialize();
195 Enqueue(queue, pktSize, 300);
196 st = queue->GetStats();
198 0,
199 "There should be zero unforced drops");
200
201 // test 4: Verify automatic setting of QW. [QW = -1.0 with lesser LinkBandwidth]
203 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
204 true,
205 "Verify that we can actually set the attribute MinTh");
206 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
207 true,
208 "Verify that we can actually set the attribute MaxTh");
210 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
211 true,
212 "Verify that we can actually set the attribute MaxSize");
213 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(-1.0)),
214 true,
215 "Verify that we can actually set the attribute QW");
217 queue->SetAttributeFailSafe("LinkBandwidth", DataRateValue(DataRate("0.015Mbps"))),
218 true,
219 "Verify that we can actually set the attribute LinkBandwidth");
220 queue->Initialize();
221 Enqueue(queue, pktSize, 300);
222 st = queue->GetStats();
224 0,
225 "There should be some unforced drops");
226
227 // test 5: Verify automatic setting of QW. [QW = -2.0 with default LinkBandwidth]
229 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
230 true,
231 "Verify that we can actually set the attribute MinTh");
232 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
233 true,
234 "Verify that we can actually set the attribute MaxTh");
236 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
237 true,
238 "Verify that we can actually set the attribute MaxSize");
239 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(-2.0)),
240 true,
241 "Verify that we can actually set the attribute QW");
242 queue->Initialize();
243 Enqueue(queue, pktSize, 300);
244 st = queue->GetStats();
246 NS_TEST_ASSERT_MSG_NE(test5, 0, "There should be some unforced drops");
247
248 // test 6: Verify automatic setting of QW. [QW = -2.0 with lesser LinkBandwidth]
250 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
251 true,
252 "Verify that we can actually set the attribute MinTh");
253 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
254 true,
255 "Verify that we can actually set the attribute MaxTh");
257 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
258 true,
259 "Verify that we can actually set the attribute MaxSize");
260 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(-2.0)),
261 true,
262 "Verify that we can actually set the attribute QW");
264 queue->SetAttributeFailSafe("LinkBandwidth", DataRateValue(DataRate("0.015Mbps"))),
265 true,
266 "Verify that we can actually set the attribute LinkBandwidth");
267 queue->Initialize();
268 Enqueue(queue, pktSize, 300);
269 st = queue->GetStats();
271 NS_TEST_ASSERT_MSG_NE(test6, test5, "Test 6 should have more unforced drops than Test 5");
272
273 // test 7: Verify automatic setting of minTh and maxTh. [minTh = maxTh = 0.0, with default
274 // LinkBandwidth]
276 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(0.0)),
277 true,
278 "Verify that we can actually set the attribute MinTh");
279 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(0.0)),
280 true,
281 "Verify that we can actually set the attribute MaxTh");
283 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
284 true,
285 "Verify that we can actually set the attribute MaxSize");
286 queue->Initialize();
287 Enqueue(queue, pktSize, 300);
288 st = queue->GetStats();
290 0,
291 "There should be some unforced drops");
292
293 // test 8: Verify automatic setting of minTh and maxTh. [minTh = maxTh = 0.0, with higher
294 // LinkBandwidth]
296 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(0.0)),
297 true,
298 "Verify that we can actually set the attribute MinTh");
299 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(0.0)),
300 true,
301 "Verify that we can actually set the attribute MaxTh");
303 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
304 true,
305 "Verify that we can actually set the attribute MaxSize");
307 queue->SetAttributeFailSafe("LinkBandwidth", DataRateValue(DataRate("150Mbps"))),
308 true,
309 "Verify that we can actually set the attribute LinkBandwidth");
310 queue->Initialize();
311 Enqueue(queue, pktSize, 300);
312 st = queue->GetStats();
314 0,
315 "There should be zero unforced drops");
316
317 // test 9: Default RED (automatic and adaptive settings disabled)
319 minTh = 5 * modeSize;
320 maxTh = 15 * modeSize;
321 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
322 true,
323 "Verify that we can actually set the attribute MinTh");
324 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
325 true,
326 "Verify that we can actually set the attribute MaxTh");
328 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
329 true,
330 "Verify that we can actually set the attribute MaxSize");
331 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(0.002)),
332 true,
333 "Verify that we can actually set the attribute QW");
334 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("LInterm", DoubleValue(2)),
335 true,
336 "Verify that we can actually set the attribute LInterm");
337 queue->Initialize();
338 EnqueueWithDelay(queue, pktSize, 300);
341 st = queue->GetStats();
344 0,
345 "There should be some unforced drops");
346
347 // test 10: Adaptive RED (automatic and adaptive settings enabled)
350 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
351 true,
352 "Verify that we can actually set the attribute MaxSize");
353 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("LInterm", DoubleValue(2)),
354 true,
355 "Verify that we can actually set the attribute LInterm");
356 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("ARED", BooleanValue(true)),
357 true,
358 "Verify that we can actually set the attribute ARED");
359 queue->Initialize();
360 EnqueueWithDelay(queue, pktSize, 300);
363 st = queue->GetStats();
365 NS_TEST_ASSERT_MSG_LT(test10, test9, "Test 10 should have less unforced drops than test 9");
366}
367
368void
370{
371 Address dest;
372 for (uint32_t i = 0; i < nPkt; i++)
373 {
374 queue->Enqueue(Create<AredQueueDiscTestItem>(Create<Packet>(size), dest));
375 }
376}
377
378void
380{
381 Address dest;
382 double delay = 0.01; // enqueue packets with delay to allow m_curMaxP to adapt
383 for (uint32_t i = 0; i < nPkt; i++)
384 {
385 Simulator::Schedule(Seconds((i + 1) * delay),
387 this,
388 queue,
389 size,
390 1);
391 }
392}
393
394void
396{
397 RunAredDiscTest(QueueSizeUnit::PACKETS);
398 RunAredDiscTest(QueueSizeUnit::BYTES);
400}
401
402/**
403 * @ingroup traffic-control-test
404 *
405 * @brief Ared Queue Disc Test Suite
406 */
408{
409 public:
411 : TestSuite("adaptive-red-queue-disc", Type::UNIT)
412 {
413 AddTestCase(new AredQueueDiscTestCase(), TestCase::Duration::QUICK);
414 }
415} g_aredQueueDiscTestSuite; ///< the test suite
void RunAredDiscTest(QueueSizeUnit mode)
Run ARED queue disc test function.
void Enqueue(Ptr< RedQueueDisc > queue, uint32_t size, uint32_t nPkt)
Enqueue function.
void EnqueueWithDelay(Ptr< RedQueueDisc > queue, uint32_t size, uint32_t nPkt)
Enqueue with delay function.
void DoRun() override
Implementation to actually run this TestCase.
AredQueueDiscTestItem()=delete
void AddHeader() override
Add the header to the packet.
AredQueueDiscTestItem(const AredQueueDiscTestItem &)=delete
AredQueueDiscTestItem & operator=(const AredQueueDiscTestItem &)=delete
bool Mark() override
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
a polymophic address class
Definition address.h:90
AttributeValue implementation for Boolean.
Definition boolean.h:26
Class for representing data rates.
Definition data-rate.h:78
AttributeValue implementation for DataRate.
Definition data-rate.h:285
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Smart pointer class similar to boost::intrusive_ptr.
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Definition queue-item.h:122
Class for representing queue sizes.
Definition queue-size.h:85
AttributeValue implementation for QueueSize.
Definition queue-size.h:210
static constexpr const char * UNFORCED_DROP
Early probability drops.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition queue-size.h:33
#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.
Definition test.h:699
#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.
Definition test.h:134
#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.
Definition test.h:554
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
AredQueueDiscTestSuite g_aredQueueDiscTestSuite
the test suite
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Structure that keeps the queue disc statistics.
Definition queue-disc.h:177
uint32_t GetNDroppedPackets(std::string reason) const
Get the number of packets dropped for the given reason.
uint32_t pktSize
packet size used for the simulation (in bytes)