A Discrete-Event Network Simulator
API
adaptive-red-queue-disc-test-suite.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2015 NITK Surathkal
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Mohit P. Tahiliani <tahiliani@nitk.edu.in>
19 *
20 */
21
22#include "ns3/test.h"
23#include "ns3/red-queue-disc.h"
24#include "ns3/packet.h"
25#include "ns3/uinteger.h"
26#include "ns3/string.h"
27#include "ns3/double.h"
28#include "ns3/log.h"
29#include "ns3/simulator.h"
30
31using namespace ns3;
32
46public:
54 virtual ~AredQueueDiscTestItem ();
55
56 // Delete default constructor, copy constructor and assignment operator to avoid misuse
60
61 virtual void AddHeader (void);
62 virtual bool Mark(void);
63};
64
66 : QueueDiscItem (p, addr, 0)
67{
68}
69
71{
72}
73
74void
76{
77}
78
79bool
81{
82 return false;
83}
84
92{
93public:
95 virtual void DoRun (void);
96private:
103 void Enqueue (Ptr<RedQueueDisc> queue, uint32_t size, uint32_t nPkt);
110 void EnqueueWithDelay (Ptr<RedQueueDisc> queue, uint32_t size, uint32_t nPkt);
115 void RunAredDiscTest (QueueSizeUnit mode);
116};
117
119 : TestCase ("Sanity check on the functionality of Adaptive RED")
120{
121}
122
123void
125{
126 uint32_t pktSize = 0;
127 uint32_t modeSize = 1; // 1 for packets; pktSize for bytes
128 double minTh = 70;
129 double maxTh = 150;
130 uint32_t qSize = 300;
131 Address dest;
132
133 // test 1: Verify automatic setting of QW. [QW = 0.0 with default LinkBandwidth]
134 Ptr<RedQueueDisc> queue = CreateObject<RedQueueDisc> ();
135
136 if (mode == QueueSizeUnit::BYTES)
137 {
138 pktSize = 500;
139 modeSize = pktSize;
140 minTh = minTh * modeSize;
141 maxTh = maxTh * modeSize;
142 qSize = qSize * modeSize;
143 }
144
145 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
146 "Verify that we can actually set the attribute MinTh");
147 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (maxTh)), true,
148 "Verify that we can actually set the attribute MaxTh");
149 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxSize", QueueSizeValue (QueueSize (mode, qSize))),
150 true, "Verify that we can actually set the attribute MaxSize");
151 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (0.0)), true,
152 "Verify that we can actually set the attribute QW");
153 queue->Initialize ();
154 Enqueue (queue, pktSize, 300);
155 QueueDisc::Stats st = queue->GetStats ();
156 NS_TEST_ASSERT_MSG_EQ (st.GetNDroppedPackets (RedQueueDisc::UNFORCED_DROP), 0,
157 "There should be zero unforced drops");
158
159
160 // test 2: Verify automatic setting of QW. [QW = 0.0 with lesser LinkBandwidth]
161 queue = CreateObject<RedQueueDisc> ();
162 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
163 "Verify that we can actually set the attribute MinTh");
164 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (maxTh)), true,
165 "Verify that we can actually set the attribute MaxTh");
166 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxSize", QueueSizeValue (QueueSize (mode, qSize))),
167 true, "Verify that we can actually set the attribute MaxSize");
168 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (0.0)), true,
169 "Verify that we can actually set the attribute QW");
170 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("LinkBandwidth", DataRateValue (DataRate ("0.015Mbps"))), true,
171 "Verify that we can actually set the attribute LinkBandwidth");
172 queue->Initialize ();
173 Enqueue (queue, pktSize, 300);
174 st = queue->GetStats ();
175 NS_TEST_ASSERT_MSG_NE (st.GetNDroppedPackets (RedQueueDisc::UNFORCED_DROP), 0,
176 "There should be some unforced drops");
177
178
179 // test 3: Verify automatic setting of QW. [QW = -1.0 with default LinkBandwidth]
180 queue = CreateObject<RedQueueDisc> ();
181 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
182 "Verify that we can actually set the attribute MinTh");
183 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (maxTh)), true,
184 "Verify that we can actually set the attribute MaxTh");
185 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxSize", QueueSizeValue (QueueSize (mode, qSize))),
186 true, "Verify that we can actually set the attribute MaxSize");
187 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (-1.0)), true,
188 "Verify that we can actually set the attribute QW");
189 queue->Initialize ();
190 Enqueue (queue, pktSize, 300);
191 st = queue->GetStats ();
192 NS_TEST_ASSERT_MSG_EQ (st.GetNDroppedPackets (RedQueueDisc::UNFORCED_DROP), 0,
193 "There should be zero unforced drops");
194
195
196 // test 4: Verify automatic setting of QW. [QW = -1.0 with lesser LinkBandwidth]
197 queue = CreateObject<RedQueueDisc> ();
198 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
199 "Verify that we can actually set the attribute MinTh");
200 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (maxTh)), true,
201 "Verify that we can actually set the attribute MaxTh");
202 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxSize", QueueSizeValue (QueueSize (mode, qSize))),
203 true, "Verify that we can actually set the attribute MaxSize");
204 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (-1.0)), true,
205 "Verify that we can actually set the attribute QW");
206 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("LinkBandwidth", DataRateValue (DataRate ("0.015Mbps"))), true,
207 "Verify that we can actually set the attribute LinkBandwidth");
208 queue->Initialize ();
209 Enqueue (queue, pktSize, 300);
210 st = queue->GetStats ();
211 NS_TEST_ASSERT_MSG_NE (st.GetNDroppedPackets (RedQueueDisc::UNFORCED_DROP), 0,
212 "There should be some unforced drops");
213
214
215 // test 5: Verify automatic setting of QW. [QW = -2.0 with default LinkBandwidth]
216 queue = CreateObject<RedQueueDisc> ();
217 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
218 "Verify that we can actually set the attribute MinTh");
219 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (maxTh)), true,
220 "Verify that we can actually set the attribute MaxTh");
221 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxSize", QueueSizeValue (QueueSize (mode, qSize))),
222 true, "Verify that we can actually set the attribute MaxSize");
223 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (-2.0)), true,
224 "Verify that we can actually set the attribute QW");
225 queue->Initialize ();
226 Enqueue (queue, pktSize, 300);
227 st = queue->GetStats ();
228 uint32_t test5 = st.GetNDroppedPackets (RedQueueDisc::UNFORCED_DROP);
229 NS_TEST_ASSERT_MSG_NE (test5, 0, "There should be some unforced drops");
230
231
232 // test 6: Verify automatic setting of QW. [QW = -2.0 with lesser LinkBandwidth]
233 queue = CreateObject<RedQueueDisc> ();
234 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
235 "Verify that we can actually set the attribute MinTh");
236 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (maxTh)), true,
237 "Verify that we can actually set the attribute MaxTh");
238 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxSize", QueueSizeValue (QueueSize (mode, qSize))),
239 true, "Verify that we can actually set the attribute MaxSize");
240 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (-2.0)), true,
241 "Verify that we can actually set the attribute QW");
242 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("LinkBandwidth", DataRateValue (DataRate ("0.015Mbps"))), true,
243 "Verify that we can actually set the attribute LinkBandwidth");
244 queue->Initialize ();
245 Enqueue (queue, pktSize, 300);
246 st = queue->GetStats ();
247 uint32_t test6 = st.GetNDroppedPackets (RedQueueDisc::UNFORCED_DROP);
248 NS_TEST_ASSERT_MSG_NE (test6, test5, "Test 6 should have more unforced drops than Test 5");
249
250
251 // test 7: Verify automatic setting of minTh and maxTh. [minTh = maxTh = 0.0, with default LinkBandwidth]
252 queue = CreateObject<RedQueueDisc> ();
253 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (0.0)), true,
254 "Verify that we can actually set the attribute MinTh");
255 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (0.0)), true,
256 "Verify that we can actually set the attribute MaxTh");
257 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxSize", QueueSizeValue (QueueSize (mode, qSize))),
258 true, "Verify that we can actually set the attribute MaxSize");
259 queue->Initialize ();
260 Enqueue (queue, pktSize, 300);
261 st = queue->GetStats ();
262 NS_TEST_ASSERT_MSG_NE (st.GetNDroppedPackets (RedQueueDisc::UNFORCED_DROP), 0,
263 "There should be some unforced drops");
264
265
266 // test 8: Verify automatic setting of minTh and maxTh. [minTh = maxTh = 0.0, with higher LinkBandwidth]
267 queue = CreateObject<RedQueueDisc> ();
268 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (0.0)), true,
269 "Verify that we can actually set the attribute MinTh");
270 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (0.0)), true,
271 "Verify that we can actually set the attribute MaxTh");
272 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxSize", QueueSizeValue (QueueSize (mode, qSize))),
273 true, "Verify that we can actually set the attribute MaxSize");
274 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("LinkBandwidth", DataRateValue (DataRate ("150Mbps"))), true,
275 "Verify that we can actually set the attribute LinkBandwidth");
276 queue->Initialize ();
277 Enqueue (queue, pktSize, 300);
278 st = queue->GetStats ();
279 NS_TEST_ASSERT_MSG_EQ (st.GetNDroppedPackets (RedQueueDisc::UNFORCED_DROP), 0,
280 "There should be zero unforced drops");
281
282
283 // test 9: Default RED (automatic and adaptive settings disabled)
284 queue = CreateObject<RedQueueDisc> ();
285 minTh = 5 * modeSize;
286 maxTh = 15 * modeSize;
287 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
288 "Verify that we can actually set the attribute MinTh");
289 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (maxTh)), true,
290 "Verify that we can actually set the attribute MaxTh");
291 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxSize", QueueSizeValue (QueueSize (mode, qSize))),
292 true, "Verify that we can actually set the attribute MaxSize");
293 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (0.002)), true,
294 "Verify that we can actually set the attribute QW");
295 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("LInterm", DoubleValue (2)), true,
296 "Verify that we can actually set the attribute LInterm");
297 queue->Initialize ();
298 EnqueueWithDelay (queue, pktSize, 300);
299 Simulator::Stop (Seconds (5));
301 st = queue->GetStats ();
302 uint32_t test9 = st.GetNDroppedPackets (RedQueueDisc::UNFORCED_DROP);
303 NS_TEST_ASSERT_MSG_NE (st.GetNDroppedPackets (RedQueueDisc::UNFORCED_DROP), 0,
304 "There should be some unforced drops");
305
306
307 // test 10: Adaptive RED (automatic and adaptive settings enabled)
308 queue = CreateObject<RedQueueDisc> ();
309 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("MaxSize", QueueSizeValue (QueueSize (mode, qSize))),
310 true, "Verify that we can actually set the attribute MaxSize");
311 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("LInterm", DoubleValue (2)), true,
312 "Verify that we can actually set the attribute LInterm");
313 NS_TEST_ASSERT_MSG_EQ (queue->SetAttributeFailSafe ("ARED", BooleanValue (true)), true,
314 "Verify that we can actually set the attribute ARED");
315 queue->Initialize ();
316 EnqueueWithDelay (queue, pktSize, 300);
317 Simulator::Stop (Seconds (5));
319 st = queue->GetStats ();
320 uint32_t test10 = st.GetNDroppedPackets (RedQueueDisc::UNFORCED_DROP);
321 NS_TEST_ASSERT_MSG_LT (test10, test9, "Test 10 should have less unforced drops than test 9");
322}
323
324void
326{
327 Address dest;
328 for (uint32_t i = 0; i < nPkt; i++)
329 {
330 queue->Enqueue (Create<AredQueueDiscTestItem> (Create<Packet> (size), dest));
331 }
332}
333
334void
336{
337 Address dest;
338 double delay = 0.01; // enqueue packets with delay to allow m_curMaxP to adapt
339 for (uint32_t i = 0; i < nPkt; i++)
340 {
341 Simulator::Schedule (Time (Seconds ((i + 1) * delay)), &AredQueueDiscTestCase::Enqueue, this, queue, size, 1);
342 }
343}
344
345void
347{
350 Simulator::Destroy ();
351}
352
360{
361public:
363 : TestSuite ("adaptive-red-queue-disc", UNIT)
364 {
365 AddTestCase (new AredQueueDiscTestCase (), TestCase::QUICK);
366 }
void Run(ObjectFactory &factory, uint32_t pop, uint32_t total, uint32_t runs, Ptr< RandomVariableStream > eventStream, bool calRev)
Perform the runs for a single scheduler type.
virtual void DoRun(void)
Implementation to actually run this TestCase.
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.
virtual bool Mark(void)
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
AredQueueDiscTestItem()=delete
virtual void AddHeader(void)
Add the header to the packet.
AredQueueDiscTestItem(const AredQueueDiscTestItem &)=delete
AredQueueDiscTestItem & operator=(const AredQueueDiscTestItem &)=delete
a polymophic address class
Definition: address.h:91
AttributeValue implementation for Boolean.
Definition: boolean.h:37
Class for representing data rates.
Definition: data-rate.h:89
AttributeValue implementation for DataRate.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Definition: queue-item.h:133
Class for representing queue sizes.
Definition: queue-size.h:95
AttributeValue implementation for QueueSize.
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1197
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition: queue-size.h:43
@ BYTES
Use number of bytes for queue size.
Definition: queue-size.h:45
@ PACKETS
Use number of packets for queue size.
Definition: queue-size.h:44
#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:675
#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:141
#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:542
AredQueueDiscTestSuite g_aredQueueDiscTestSuite
the test suite
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1245
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Structure that keeps the queue disc statistics.
Definition: queue-disc.h:186
uint32_t GetNDroppedPackets(std::string reason) const
Get the number of packets dropped for the given reason.
Definition: queue-disc.cc:109
uint32_t pktSize
packet size used for the simulation (in bytes)
Definition: wifi-bianchi.cc:89