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
120 // test 1: Verify automatic setting of QW. [QW = 0.0 with default LinkBandwidth]
122
123 if (mode == QueueSizeUnit::BYTES)
124 {
125 pktSize = 500;
126 modeSize = pktSize;
127 minTh = minTh * modeSize;
128 maxTh = maxTh * modeSize;
129 qSize = qSize * modeSize;
130 }
131
132 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
133 true,
134 "Verify that we can actually set the attribute MinTh");
135 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
136 true,
137 "Verify that we can actually set the attribute MaxTh");
139 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
140 true,
141 "Verify that we can actually set the attribute MaxSize");
142 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(0.0)),
143 true,
144 "Verify that we can actually set the attribute QW");
145 queue->Initialize();
146 Enqueue(queue, pktSize, 300);
147 QueueDisc::Stats st = queue->GetStats();
149 0,
150 "There should be zero unforced drops");
151
152 // test 2: Verify automatic setting of QW. [QW = 0.0 with lesser LinkBandwidth]
154 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
155 true,
156 "Verify that we can actually set the attribute MinTh");
157 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
158 true,
159 "Verify that we can actually set the attribute MaxTh");
161 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
162 true,
163 "Verify that we can actually set the attribute MaxSize");
164 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(0.0)),
165 true,
166 "Verify that we can actually set the attribute QW");
168 queue->SetAttributeFailSafe("LinkBandwidth", DataRateValue(DataRate("0.015Mbps"))),
169 true,
170 "Verify that we can actually set the attribute LinkBandwidth");
171 queue->Initialize();
172 Enqueue(queue, pktSize, 300);
173 st = queue->GetStats();
175 0,
176 "There should be some unforced drops");
177
178 // test 3: Verify automatic setting of QW. [QW = -1.0 with default LinkBandwidth]
180 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
181 true,
182 "Verify that we can actually set the attribute MinTh");
183 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
184 true,
185 "Verify that we can actually set the attribute MaxTh");
187 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
188 true,
189 "Verify that we can actually set the attribute MaxSize");
190 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(-1.0)),
191 true,
192 "Verify that we can actually set the attribute QW");
193 queue->Initialize();
194 Enqueue(queue, pktSize, 300);
195 st = queue->GetStats();
197 0,
198 "There should be zero unforced drops");
199
200 // test 4: Verify automatic setting of QW. [QW = -1.0 with lesser LinkBandwidth]
202 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
203 true,
204 "Verify that we can actually set the attribute MinTh");
205 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
206 true,
207 "Verify that we can actually set the attribute MaxTh");
209 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
210 true,
211 "Verify that we can actually set the attribute MaxSize");
212 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(-1.0)),
213 true,
214 "Verify that we can actually set the attribute QW");
216 queue->SetAttributeFailSafe("LinkBandwidth", DataRateValue(DataRate("0.015Mbps"))),
217 true,
218 "Verify that we can actually set the attribute LinkBandwidth");
219 queue->Initialize();
220 Enqueue(queue, pktSize, 300);
221 st = queue->GetStats();
223 0,
224 "There should be some unforced drops");
225
226 // test 5: Verify automatic setting of QW. [QW = -2.0 with default LinkBandwidth]
228 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
229 true,
230 "Verify that we can actually set the attribute MinTh");
231 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
232 true,
233 "Verify that we can actually set the attribute MaxTh");
235 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
236 true,
237 "Verify that we can actually set the attribute MaxSize");
238 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(-2.0)),
239 true,
240 "Verify that we can actually set the attribute QW");
241 queue->Initialize();
242 Enqueue(queue, pktSize, 300);
243 st = queue->GetStats();
245 NS_TEST_ASSERT_MSG_NE(test5, 0, "There should be some unforced drops");
246
247 // test 6: Verify automatic setting of QW. [QW = -2.0 with lesser LinkBandwidth]
249 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
250 true,
251 "Verify that we can actually set the attribute MinTh");
252 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
253 true,
254 "Verify that we can actually set the attribute MaxTh");
256 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
257 true,
258 "Verify that we can actually set the attribute MaxSize");
259 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(-2.0)),
260 true,
261 "Verify that we can actually set the attribute QW");
263 queue->SetAttributeFailSafe("LinkBandwidth", DataRateValue(DataRate("0.015Mbps"))),
264 true,
265 "Verify that we can actually set the attribute LinkBandwidth");
266 queue->Initialize();
267 Enqueue(queue, pktSize, 300);
268 st = queue->GetStats();
270 NS_TEST_ASSERT_MSG_NE(test6, test5, "Test 6 should have more unforced drops than Test 5");
271
272 // test 7: Verify automatic setting of minTh and maxTh. [minTh = maxTh = 0.0, with default
273 // LinkBandwidth]
275 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(0.0)),
276 true,
277 "Verify that we can actually set the attribute MinTh");
278 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(0.0)),
279 true,
280 "Verify that we can actually set the attribute MaxTh");
282 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
283 true,
284 "Verify that we can actually set the attribute MaxSize");
285 queue->Initialize();
286 Enqueue(queue, pktSize, 300);
287 st = queue->GetStats();
289 0,
290 "There should be some unforced drops");
291
292 // test 8: Verify automatic setting of minTh and maxTh. [minTh = maxTh = 0.0, with higher
293 // LinkBandwidth]
295 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(0.0)),
296 true,
297 "Verify that we can actually set the attribute MinTh");
298 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(0.0)),
299 true,
300 "Verify that we can actually set the attribute MaxTh");
302 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
303 true,
304 "Verify that we can actually set the attribute MaxSize");
306 queue->SetAttributeFailSafe("LinkBandwidth", DataRateValue(DataRate("150Mbps"))),
307 true,
308 "Verify that we can actually set the attribute LinkBandwidth");
309 queue->Initialize();
310 Enqueue(queue, pktSize, 300);
311 st = queue->GetStats();
313 0,
314 "There should be zero unforced drops");
315
316 // test 9: Default RED (automatic and adaptive settings disabled)
318 minTh = 5 * modeSize;
319 maxTh = 15 * modeSize;
320 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MinTh", DoubleValue(minTh)),
321 true,
322 "Verify that we can actually set the attribute MinTh");
323 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("MaxTh", DoubleValue(maxTh)),
324 true,
325 "Verify that we can actually set the attribute MaxTh");
327 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
328 true,
329 "Verify that we can actually set the attribute MaxSize");
330 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("QW", DoubleValue(0.002)),
331 true,
332 "Verify that we can actually set the attribute QW");
333 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("LInterm", DoubleValue(2)),
334 true,
335 "Verify that we can actually set the attribute LInterm");
336 queue->Initialize();
337 EnqueueWithDelay(queue, pktSize, 300);
340 st = queue->GetStats();
343 0,
344 "There should be some unforced drops");
345
346 // test 10: Adaptive RED (automatic and adaptive settings enabled)
349 queue->SetAttributeFailSafe("MaxSize", QueueSizeValue(QueueSize(mode, qSize))),
350 true,
351 "Verify that we can actually set the attribute MaxSize");
352 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("LInterm", DoubleValue(2)),
353 true,
354 "Verify that we can actually set the attribute LInterm");
355 NS_TEST_ASSERT_MSG_EQ(queue->SetAttributeFailSafe("ARED", BooleanValue(true)),
356 true,
357 "Verify that we can actually set the attribute ARED");
358 queue->Initialize();
359 EnqueueWithDelay(queue, pktSize, 300);
362 st = queue->GetStats();
364 NS_TEST_ASSERT_MSG_LT(test10, test9, "Test 10 should have less unforced drops than test 9");
365}
366
367void
369{
370 Address dest;
371 for (uint32_t i = 0; i < nPkt; i++)
372 {
373 queue->Enqueue(Create<AredQueueDiscTestItem>(Create<Packet>(size), dest));
374 }
375}
376
377void
379{
380 double delay = 0.01; // enqueue packets with delay to allow m_curMaxP to adapt
381 for (uint32_t i = 0; i < nPkt; i++)
382 {
383 Simulator::Schedule(Seconds((i + 1) * delay),
385 this,
386 queue,
387 size,
388 1);
389 }
390}
391
392void
399
400/**
401 * @ingroup traffic-control-test
402 *
403 * @brief Ared Queue Disc Test Suite
404 */
406{
407 public:
409 : TestSuite("adaptive-red-queue-disc", Type::UNIT)
410 {
412 }
413} 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(Ptr< Packet > p, const Address &addr)
Constructor.
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:114
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.
Definition ptr.h:70
QueueDiscItem(Ptr< Packet > p, const Address &addr, uint16_t protocol)
Create a queue disc item.
Definition queue-item.cc:66
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:580
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static void Run()
Run the simulation.
Definition simulator.cc:161
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:169
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
@ UNIT
This test suite implements a Unit Test.
Definition test.h:1273
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:454
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition queue-size.h:33
@ BYTES
Use number of bytes for queue size.
Definition queue-size.h:35
@ PACKETS
Use number of packets for queue size.
Definition queue-size.h:34
#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:698
#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:133
#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:553
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1381
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.