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/drop-tail-queue.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 #include "ns3/ipv4-queue-disc-item.h"
31 
32 #include "ns3/core-module.h"
33 #include "ns3/network-module.h"
34 #include "ns3/internet-module.h"
35 #include "ns3/point-to-point-module.h"
36 #include "ns3/applications-module.h"
37 #include "ns3/point-to-point-layout-module.h"
38 #include "ns3/traffic-control-module.h"
39 
40 using namespace ns3;
41 
42 // Tests to verify the working of *automatically set* parameters in ARED
44 {
45 public:
47  virtual void DoRun (void);
48 private:
49  void Enqueue (Ptr<RedQueueDisc> queue, uint32_t size, uint32_t nPkt);
50  void RunAutoRedDiscTest (StringValue mode);
51 };
52 
54  : TestCase ("Sanity check on automatically set parameters of ARED")
55 {
56 }
57 
58 void
60 {
61  uint32_t pktSize = 0;
62  uint32_t modeSize = 1; // 1 for packets; pktSize for bytes
63  Ptr<RedQueueDisc> queue = CreateObject<RedQueueDisc> ();
64 
65  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
66  "Verify that we can actually set the attribute Mode");
67 
68  Ipv4Header ipHeader;
69  Address dest;
70 
71  if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
72  {
73  pktSize = 500;
74  modeSize = pktSize + ipHeader.GetSerializedSize ();
75  }
76 
77  double minTh = 70 * modeSize;
78  double maxTh = 150 * modeSize;
79  uint32_t qSize = 300 * modeSize;
80 
81  // test 1: Verify automatic setting of QW. [QW = 0.0 with default LinkBandwidth]
82  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
83  "Verify that we can actually set the attribute Mode");
84  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
85  "Verify that we can actually set the attribute MinTh");
86  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (maxTh)), true,
87  "Verify that we can actually set the attribute MaxTh");
88  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueLimit", UintegerValue (qSize)), true,
89  "Verify that we can actually set the attribute QueueLimit");
90  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (0.0)), true,
91  "Verify that we can actually set the attribute QW");
92  queue->Initialize ();
93  Enqueue (queue, pktSize, 300);
94  RedQueueDisc::Stats st = StaticCast<RedQueueDisc> (queue)->GetStats ();
95  if (queue->GetMode () == Queue::QUEUE_MODE_PACKETS)
96  {
97  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 0, "There should be zero dropped packets due to probability mark");
98  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
99  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
100  }
101  else if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
102  {
103  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 0, "There should be zero dropped packets due to probability mark");
104  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
105  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
106  }
107 
108 
109  // test 2: Verify automatic setting of QW. [QW = 0.0 with lesser LinkBandwidth]
110  queue = CreateObject<RedQueueDisc> ();
111  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
112  "Verify that we can actually set the attribute Mode");
113  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
114  "Verify that we can actually set the attribute MinTh");
115  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (maxTh)), true,
116  "Verify that we can actually set the attribute MaxTh");
117  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueLimit", UintegerValue (qSize)), true,
118  "Verify that we can actually set the attribute QueueLimit");
119  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (0.0)), true,
120  "Verify that we can actually set the attribute QW");
121  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("LinkBandwidth", DataRateValue (DataRate ("0.015Mbps"))), true,
122  "Verify that we can actually set the attribute LinkBandwidth");
123  queue->Initialize ();
124  Enqueue (queue, pktSize, 300);
125  st = StaticCast<RedQueueDisc> (queue)->GetStats ();
126  if (queue->GetMode () == Queue::QUEUE_MODE_PACKETS)
127  {
128  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 44, "There should be 44 dropped packets due to probability mark");
129  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
130  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
131  }
132  else if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
133  {
134  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 45, "There should be 45 dropped packets due to probability mark");
135  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
136  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
137  }
138 
139 
140  // test 3: Verify automatic setting of QW. [QW = -1.0 with default LinkBandwidth]
141  queue = CreateObject<RedQueueDisc> ();
142  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
143  "Verify that we can actually set the attribute Mode");
144  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
145  "Verify that we can actually set the attribute MinTh");
146  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (maxTh)), true,
147  "Verify that we can actually set the attribute MaxTh");
148  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueLimit", UintegerValue (qSize)), true,
149  "Verify that we can actually set the attribute QueueLimit");
150  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (-1.0)), true,
151  "Verify that we can actually set the attribute QW");
152  queue->Initialize ();
153  Enqueue (queue, pktSize, 300);
154  st = StaticCast<RedQueueDisc> (queue)->GetStats ();
155  if (queue->GetMode () == Queue::QUEUE_MODE_PACKETS)
156  {
157  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 0, "There should be zero dropped packets due to probability mark");
158  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
159  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
160  }
161  else if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
162  {
163  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 0, "There should be zero dropped packets due to probability mark");
164  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
165  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
166  }
167 
168 
169  // test 4: Verify automatic setting of QW. [QW = -1.0 with lesser LinkBandwidth]
170  queue = CreateObject<RedQueueDisc> ();
171  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
172  "Verify that we can actually set the attribute Mode");
173  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
174  "Verify that we can actually set the attribute MinTh");
175  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (maxTh)), true,
176  "Verify that we can actually set the attribute MaxTh");
177  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueLimit", UintegerValue (qSize)), true,
178  "Verify that we can actually set the attribute QueueLimit");
179  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (-1.0)), true,
180  "Verify that we can actually set the attribute QW");
181  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("LinkBandwidth", DataRateValue (DataRate ("0.015Mbps"))), true,
182  "Verify that we can actually set the attribute LinkBandwidth");
183  queue->Initialize ();
184  Enqueue (queue, pktSize, 300);
185  st = StaticCast<RedQueueDisc> (queue)->GetStats ();
186  if (queue->GetMode () == Queue::QUEUE_MODE_PACKETS)
187  {
188  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 32, "There should be 32 dropped packets due to probability mark");
189  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
190  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
191  }
192  else if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
193  {
194  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 33, "There should be 33 dropped packets due to probability mark");
195  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
196  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
197  }
198 
199 
200  // test 5: Verify automatic setting of QW. [QW = -2.0 with default LinkBandwidth]
201  queue = CreateObject<RedQueueDisc> ();
202  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
203  "Verify that we can actually set the attribute Mode");
204  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
205  "Verify that we can actually set the attribute MinTh");
206  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (maxTh)), true,
207  "Verify that we can actually set the attribute MaxTh");
208  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueLimit", UintegerValue (qSize)), true,
209  "Verify that we can actually set the attribute QueueLimit");
210  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (-2.0)), true,
211  "Verify that we can actually set the attribute QW");
212  queue->Initialize ();
213  Enqueue (queue, pktSize, 300);
214  st = StaticCast<RedQueueDisc> (queue)->GetStats ();
215  if (queue->GetMode () == Queue::QUEUE_MODE_PACKETS)
216  {
217  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 29, "There should be 29 dropped packets due to probability mark");
218  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
219  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
220  }
221  else if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
222  {
223  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 30, "There should be 30 dropped packets due to probability mark");
224  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
225  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
226  }
227 
228 
229  // test 6: Verify automatic setting of QW. [QW = -2.0 with lesser LinkBandwidth]
230  queue = CreateObject<RedQueueDisc> ();
231  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
232  "Verify that we can actually set the attribute Mode");
233  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
234  "Verify that we can actually set the attribute MinTh");
235  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (maxTh)), true,
236  "Verify that we can actually set the attribute MaxTh");
237  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueLimit", UintegerValue (qSize)), true,
238  "Verify that we can actually set the attribute QueueLimit");
239  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (-2.0)), true,
240  "Verify that we can actually set the attribute QW");
241  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("LinkBandwidth", DataRateValue (DataRate ("0.015Mbps"))), true,
242  "Verify that we can actually set the attribute LinkBandwidth");
243  queue->Initialize ();
244  Enqueue (queue, pktSize, 300);
245  st = StaticCast<RedQueueDisc> (queue)->GetStats ();
246  if (queue->GetMode () == Queue::QUEUE_MODE_PACKETS)
247  {
248  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 44, "There should be 44 dropped packets due to probability mark");
249  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
250  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
251  }
252  else if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
253  {
254  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 46, "There should be 46 dropped packets due to probability mark");
255  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
256  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
257  }
258 
259 
260  // test 7: Verify automatic setting of minTh and maxTh. [minTh = maxTh = 0.0, with default LinkBandwidth]
261  queue = CreateObject<RedQueueDisc> ();
262  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
263  "Verify that we can actually set the attribute Mode");
264  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (0.0)), true,
265  "Verify that we can actually set the attribute MinTh");
266  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (0.0)), true,
267  "Verify that we can actually set the attribute MaxTh");
268  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueLimit", UintegerValue (qSize)), true,
269  "Verify that we can actually set the attribute QueueLimit");
270  if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
271  {
272  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MeanPktSize", UintegerValue (modeSize)), true,
273  "Verify that we can actually set the attribute MeanPktSize");
274  }
275  queue->Initialize ();
276  Enqueue (queue, pktSize, 300);
277  st = StaticCast<RedQueueDisc> (queue)->GetStats ();
278  if (queue->GetMode () == Queue::QUEUE_MODE_PACKETS)
279  {
280  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 20, "There should be 20 dropped packets due to probability mark");
281  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 113, "There should be 113 dropped packets due to hard mark");
282  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
283  }
284  else if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
285  {
286  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 21, "There should be 21 dropped packets due to probability mark");
287  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 113, "There should be 113 dropped packets due to hard mark");
288  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
289  }
290 
291 
292  // test 8: Verify automatic setting of minTh and maxTh. [minTh = maxTh = 0.0, with higher LinkBandwidth]
293  queue = CreateObject<RedQueueDisc> ();
294  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
295  "Verify that we can actually set the attribute Mode");
296  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (0.0)), true,
297  "Verify that we can actually set the attribute MinTh");
298  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxTh", DoubleValue (0.0)), true,
299  "Verify that we can actually set the attribute MaxTh");
300  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueLimit", UintegerValue (qSize)), true,
301  "Verify that we can actually set the attribute QueueLimit");
302  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("LinkBandwidth", DataRateValue (DataRate ("150Mbps"))), true,
303  "Verify that we can actually set the attribute LinkBandwidth");
304  if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
305  {
306  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MeanPktSize", UintegerValue (modeSize)), true,
307  "Verify that we can actually set the attribute MeanPktSize");
308  }
309  queue->Initialize ();
310  Enqueue (queue, pktSize, 300);
311  st = StaticCast<RedQueueDisc> (queue)->GetStats ();
312  if (queue->GetMode () == Queue::QUEUE_MODE_PACKETS)
313  {
314  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 0, "There should be zero dropped packets due to probability mark");
315  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
316  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
317  }
318  else if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
319  {
320  NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 0, "There should be zero dropped packets due to probability mark");
321  NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should be zero dropped packets due to hard mark");
322  NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should be zero dropped packets due to queue full");
323  }
324 }
325 
326 void
327 AutoRedQueueDiscTestCase::Enqueue (Ptr<RedQueueDisc> queue, uint32_t size, uint32_t nPkt)
328 {
329  Ipv4Header ipHeader;
330  Address dest;
331  for (uint32_t i = 0; i < nPkt; i++)
332  {
333  queue->Enqueue (Create<Ipv4QueueDiscItem> (Create<Packet> (size), dest, 0, ipHeader));
334  }
335 }
336 
337 void
339 {
340  RunAutoRedDiscTest (StringValue ("QUEUE_MODE_PACKETS"));
341  RunAutoRedDiscTest (StringValue ("QUEUE_MODE_BYTES"));
342  Simulator::Destroy ();
343 }
344 
345 
346 // Tests to verify the working of *adaptive* parameter in ARED
348 {
349 public:
351  virtual void DoRun (void);
352 private:
354 };
355 
357  : TestCase ("Sanity check on adaptive parameter of ARED")
358 {
359 }
360 
361 void
363 {
364  uint32_t pktSize = 500;
365  uint32_t modeSize = 1; // 1 for packets; pktSize for bytes
366  uint32_t nLeaf = 3;
367 
368  Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (pktSize));
369  Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("10Mbps"));
370 
371  Ptr<RedQueueDisc> queue = CreateObject<RedQueueDisc> ();
372 
373  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
374  "Verify that we can actually set the attribute Mode");
375 
376  Ipv4Header ipHeader;
377 
378  if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
379  {
380  modeSize = pktSize + ipHeader.GetSerializedSize ();
381  }
382 
383  uint32_t qSize = 100 * modeSize;
384 
385  Config::SetDefault ("ns3::RedQueueDisc::ARED", BooleanValue (true));
386  Config::SetDefault ("ns3::RedQueueDisc::LInterm", DoubleValue (10.0));
387  Config::SetDefault ("ns3::RedQueueDisc::QueueLimit", UintegerValue (qSize));
388  Config::SetDefault ("ns3::RedQueueDisc::MeanPktSize", UintegerValue (pktSize + ipHeader.GetSerializedSize ()));
389 
390  // Create the point-to-point link helpers
391  PointToPointHelper bottleNeckLink;
392  bottleNeckLink.SetDeviceAttribute ("DataRate", StringValue ("1.5Mbps"));
393  bottleNeckLink.SetChannelAttribute ("Delay", StringValue ("20ms"));
394 
395  PointToPointHelper pointToPointLeaf;
396  pointToPointLeaf.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
397  pointToPointLeaf.SetChannelAttribute ("Delay", StringValue ("1ms"));
398 
399  PointToPointDumbbellHelper d (nLeaf, pointToPointLeaf,
400  nLeaf, pointToPointLeaf,
401  bottleNeckLink);
402 
403  // Install Stack
405  for (uint32_t i = 0; i < d.LeftCount (); ++i)
406  {
407  stack.Install (d.GetLeft (i));
408  }
409  for (uint32_t i = 0; i < d.RightCount (); ++i)
410  {
411  stack.Install (d.GetRight (i));
412  }
413 
414  stack.Install (d.GetLeft ());
415  stack.Install (d.GetRight ());
416  TrafficControlHelper tchBottleneck;
417  tchBottleneck.SetRootQueueDisc ("ns3::RedQueueDisc");
418  tchBottleneck.Install (d.GetLeft ()->GetDevice (0));
419  tchBottleneck.Install (d.GetRight ()->GetDevice (0));
420 
421  // Assign IP Addresses
422  d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
423  Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"),
424  Ipv4AddressHelper ("10.3.1.0", "255.255.255.0"));
425 
426  // Install on/off app on all right side nodes
427  OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ());
428  clientHelper.SetAttribute ("OnTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
429  clientHelper.SetAttribute ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
430  Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), 5001));
431  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress);
432  ApplicationContainer sinkApps;
433  for (uint32_t i = 0; i < d.LeftCount (); ++i)
434  {
435  sinkApps.Add (packetSinkHelper.Install (d.GetLeft (i)));
436  }
437  sinkApps.Start (Seconds (0.0));
438  sinkApps.Stop (Seconds (30.0));
439 
441  for (uint32_t i = 0; i < d.RightCount (); ++i)
442  {
443  // Create an on/off app sending packets to the left side
444  AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), 5001));
445  clientHelper.SetAttribute ("Remote", remoteAddress);
446  clientApps.Add (clientHelper.Install (d.GetRight (i)));
447  }
448  clientApps.Start (Seconds (1.0)); // Start 1 second after sink
449  clientApps.Stop (Seconds (15.0)); // Stop before the sink
450 
451  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
452 
453  Simulator::Run ();
454 
455  uint32_t totalRxBytesCounter = 0;
456  for (uint32_t i = 0; i < sinkApps.GetN (); i++)
457  {
458  Ptr <Application> app = sinkApps.Get (i);
459  Ptr <PacketSink> pktSink = DynamicCast <PacketSink> (app);
460  totalRxBytesCounter += pktSink->GetTotalRx ();
461  }
462 
463  if (queue->GetMode () == Queue::QUEUE_MODE_PACKETS)
464  {
465  NS_TEST_EXPECT_MSG_EQ (totalRxBytesCounter, 2605000, "Total received bytes should be 2605000");
466  }
467  else if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
468  {
469  NS_TEST_EXPECT_MSG_EQ (totalRxBytesCounter, 2557000, "Total received bytes should be 2557000");
470  }
471 
472  Simulator::Destroy ();
473 }
474 
475 void
477 {
478  RunAdaptiveRedDiscTest (StringValue ("QUEUE_MODE_PACKETS"));
479  RunAdaptiveRedDiscTest (StringValue ("QUEUE_MODE_BYTES"));
480  Simulator::Destroy ();
481 }
482 
483 static class AredQueueDiscTestSuite : public TestSuite
484 {
485 public:
487  : TestSuite ("adaptive-red-queue-disc", UNIT)
488  {
489  AddTestCase (new AutoRedQueueDiscTestCase (), TestCase::QUICK); // Tests for automatically set parameters of ARED
490  AddTestCase (new AdaptiveRedQueueDiscTestCase (), TestCase::QUICK); // Tests for adaptive parameter of ARED
491  }
holds a vector of ns3::Application pointers.
an Inet address class
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
AttributeValue implementation for Boolean.
Definition: boolean.h:34
QueueDiscContainer Install(NetDeviceContainer c)
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
Definition: queue-disc.cc:411
Hold variables of type string.
Definition: string.h:41
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
A suite of tests to run.
Definition: test.h:1333
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:278
void Enqueue(Ptr< RedQueueDisc > queue, uint32_t size, uint32_t nPkt)
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
Set a single attribute without raising errors.
Definition: object-base.cc:211
AredQueueDiscTestSuite g_aredQueueDiscTestSuite
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
Build a set of PointToPointNetDevice objects.
encapsulates test code
Definition: test.h:1147
This test suite implements a Unit Test.
Definition: test.h:1343
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
a polymophic address class
Definition: address.h:90
tuple clientApps
Definition: first.py:54
Class for representing data rates.
Definition: data-rate.h:88
Packet header for IPv4.
Definition: ipv4-header.h:31
uint32_t forcedDrop
Forced drops, qavg > max threshold.
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:297
virtual void DoRun(void)
Implementation to actually run this TestCase.
Hold an unsigned integer type.
Definition: uinteger.h:44
uint32_t qLimDrop
Drops due to queue limits.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:142
Build a set of QueueDisc objects.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
uint32_t GetSerializedSize(void) const
Get the number of bytes needed to serialize the underlying Address Typically, this is GetLength () + ...
Definition: address.cc:147
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< Application > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
uint16_t SetRootQueueDisc(std::string type, std::string n01="", const AttributeValue &v01=EmptyAttributeValue(), std::string n02="", const AttributeValue &v02=EmptyAttributeValue(), std::string n03="", const AttributeValue &v03=EmptyAttributeValue(), std::string n04="", const AttributeValue &v04=EmptyAttributeValue(), std::string n05="", const AttributeValue &v05=EmptyAttributeValue(), std::string n06="", const AttributeValue &v06=EmptyAttributeValue(), std::string n07="", const AttributeValue &v07=EmptyAttributeValue(), std::string n08="", const AttributeValue &v08=EmptyAttributeValue(), std::string n09="", const AttributeValue &v09=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue(), std::string n11="", const AttributeValue &v11=EmptyAttributeValue(), std::string n12="", const AttributeValue &v12=EmptyAttributeValue(), std::string n13="", const AttributeValue &v13=EmptyAttributeValue(), std::string n14="", const AttributeValue &v14=EmptyAttributeValue(), std::string n15="", const AttributeValue &v15=EmptyAttributeValue())
Helper function used to set a root queue disc of the given type and with the given attributes...
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Queue::QueueMode GetMode(void)
Get the encapsulation mode of this queue.
void AssignIpv4Addresses(Ipv4AddressHelper leftIp, Ipv4AddressHelper rightIp, Ipv4AddressHelper routerIp)
uint32_t GetTotalRx() const
Definition: packet-sink.cc:78
tuple stack
Definition: first.py:34
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
AttributeValue implementation for Address.
Definition: address.h:278
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
AttributeValue implementation for DataRate.
Definition: data-rate.h:241
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:774
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
A helper to make it easier to create a dumbbell topology with p2p links.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
virtual void DoRun(void)
Implementation to actually run this TestCase.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
Ipv4Address GetLeftIpv4Address(uint32_t i) const
virtual uint32_t GetSerializedSize(void) const
Definition: ipv4-header.cc:375
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
void Initialize(void)
Invoke DoInitialize on all Objects aggregated to this one.
Definition: object.cc:183
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
uint32_t unforcedDrop
Early probability drops.