A Discrete-Event Network Simulator
API
fq-codel-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) 2016 Universita' degli Studi di Napoli Federico II
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  * Authors: Pasquale Imputato <p.imputato@gmail.com>
19  * Stefano Avallone <stefano.avallone@unina.it>
20 */
21 
22 #include "ns3/test.h"
23 #include "ns3/simulator.h"
24 #include "ns3/fq-codel-queue-disc.h"
25 #include "ns3/ipv4-header.h"
26 #include "ns3/ipv4-packet-filter.h"
27 #include "ns3/ipv4-queue-disc-item.h"
28 #include "ns3/ipv4-address.h"
29 #include "ns3/ipv6-header.h"
30 #include "ns3/ipv6-packet-filter.h"
31 #include "ns3/ipv6-queue-disc-item.h"
32 #include "ns3/tcp-header.h"
33 #include "ns3/udp-header.h"
34 #include "ns3/string.h"
35 #include "ns3/pointer.h"
36 
37 using namespace ns3;
38 
44 public:
49  static TypeId GetTypeId (void);
50 
52  virtual ~Ipv4TestPacketFilter ();
53 
54 private:
55  virtual int32_t DoClassify (Ptr<QueueDiscItem> item) const;
56 };
57 
58 TypeId
60 {
61  static TypeId tid = TypeId ("ns3::Ipv4TestPacketFilter")
63  .SetGroupName ("Internet")
64  .AddConstructor<Ipv4TestPacketFilter> ()
65  ;
66  return tid;
67 }
68 
70 {
71 }
72 
74 {
75 }
76 
77 int32_t
79 {
80  return 0;
81 }
82 
87 {
88 public:
91 
92 private:
93  virtual void DoRun (void);
94 };
95 
97  : TestCase ("Test packets that are not classified by any filter")
98 {
99 }
100 
102 {
103 }
104 
105 void
107 {
108  // Packets that cannot be classified by the available filters should be dropped
109  Ptr<FqCoDelQueueDisc> queueDisc = CreateObjectWithAttributes<FqCoDelQueueDisc> ("MaxSize", StringValue ("4p"));
110  Ptr<Ipv4TestPacketFilter> filter = CreateObject<Ipv4TestPacketFilter> ();
111  queueDisc->AddPacketFilter (filter);
112 
113  queueDisc->SetQuantum (1500);
114  queueDisc->Initialize ();
115 
116  Ptr<Packet> p;
117  p = Create<Packet> ();
119  Ipv6Header ipv6Header;
120  Address dest;
121  item = Create<Ipv6QueueDiscItem> (p, dest, 0, ipv6Header);
122  queueDisc->Enqueue (item);
123  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetNQueueDiscClasses (), 0, "no flow queue should have been created");
124 
125  p = Create<Packet> (reinterpret_cast<const uint8_t*> ("hello, world"), 12);
126  item = Create<Ipv6QueueDiscItem> (p, dest, 0, ipv6Header);
127  queueDisc->Enqueue (item);
128  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetNQueueDiscClasses (), 0, "no flow queue should have been created");
129 
130  Simulator::Destroy ();
131 }
132 
137 {
138 public:
141 
142 private:
143  virtual void DoRun (void);
144  void AddPacket (Ptr<FqCoDelQueueDisc> queue, Ipv4Header hdr);
145 };
146 
148  : TestCase ("Test IP flows separation and packet limit")
149 {
150 }
151 
153 {
154 }
155 
156 void
158 {
159  Ptr<Packet> p = Create<Packet> (100);
160  Address dest;
161  Ptr<Ipv4QueueDiscItem> item = Create<Ipv4QueueDiscItem> (p, dest, 0, hdr);
162  queue->Enqueue (item);
163 }
164 
165 void
167 {
168  Ptr<FqCoDelQueueDisc> queueDisc = CreateObjectWithAttributes<FqCoDelQueueDisc> ("MaxSize", StringValue ("4p"));
169 
170  queueDisc->SetQuantum (1500);
171  queueDisc->Initialize ();
172 
173  Ipv4Header hdr;
174  hdr.SetPayloadSize (100);
175  hdr.SetSource (Ipv4Address ("10.10.1.1"));
176  hdr.SetDestination (Ipv4Address ("10.10.1.2"));
177  hdr.SetProtocol (7);
178 
179  // Add three packets from the first flow
180  AddPacket (queueDisc, hdr);
181  AddPacket (queueDisc, hdr);
182  AddPacket (queueDisc, hdr);
183  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 3, "unexpected number of packets in the queue disc");
184  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 3, "unexpected number of packets in the flow queue");
185 
186  // Add two packets from the second flow
187  hdr.SetDestination (Ipv4Address ("10.10.1.7"));
188  // Add the first packet
189  AddPacket (queueDisc, hdr);
190  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 4, "unexpected number of packets in the queue disc");
191  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 3, "unexpected number of packets in the flow queue");
192  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (1)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the flow queue");
193  // Add the second packet that causes two packets to be dropped from the fat flow (max backlog = 300, threshold = 150)
194  AddPacket (queueDisc, hdr);
195  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 3, "unexpected number of packets in the queue disc");
196  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the flow queue");
197  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (1)->GetQueueDisc ()->GetNPackets (), 2, "unexpected number of packets in the flow queue");
198 
199  Simulator::Destroy ();
200 }
201 
206 {
207 public:
209  virtual ~FqCoDelQueueDiscDeficit ();
210 
211 private:
212  virtual void DoRun (void);
213  void AddPacket (Ptr<FqCoDelQueueDisc> queue, Ipv4Header hdr);
214 };
215 
217  : TestCase ("Test credits and flows status")
218 {
219 }
220 
222 {
223 }
224 
225 void
227 {
228  Ptr<Packet> p = Create<Packet> (100);
229  Address dest;
230  Ptr<Ipv4QueueDiscItem> item = Create<Ipv4QueueDiscItem> (p, dest, 0, hdr);
231  queue->Enqueue (item);
232 }
233 
234 void
236 {
237  Ptr<FqCoDelQueueDisc> queueDisc = CreateObjectWithAttributes<FqCoDelQueueDisc> ();
238 
239  queueDisc->SetQuantum (90);
240  queueDisc->Initialize ();
241 
242  Ipv4Header hdr;
243  hdr.SetPayloadSize (100);
244  hdr.SetSource (Ipv4Address ("10.10.1.1"));
245  hdr.SetDestination (Ipv4Address ("10.10.1.2"));
246  hdr.SetProtocol (7);
247 
248  // Add a packet from the first flow
249  AddPacket (queueDisc, hdr);
250  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 1, "unexpected number of packets in the queue disc");
251  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the first flow queue");
252  Ptr<FqCoDelFlow> flow1 = StaticCast<FqCoDelFlow> (queueDisc->GetQueueDiscClass (0));
253  NS_TEST_ASSERT_MSG_EQ (flow1->GetDeficit (), static_cast<int32_t> (queueDisc->GetQuantum ()), "the deficit of the first flow must equal the quantum");
254  NS_TEST_ASSERT_MSG_EQ (flow1->GetStatus (), FqCoDelFlow::NEW_FLOW, "the first flow must be in the list of new queues");
255  // Dequeue a packet
256  queueDisc->Dequeue ();
257  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 0, "unexpected number of packets in the queue disc");
258  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 0, "unexpected number of packets in the first flow queue");
259  // the deficit for the first flow becomes 90 - (100+20) = -30
260  NS_TEST_ASSERT_MSG_EQ (flow1->GetDeficit (), -30, "unexpected deficit for the first flow");
261 
262  // Add two packets from the first flow
263  AddPacket (queueDisc, hdr);
264  AddPacket (queueDisc, hdr);
265  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 2, "unexpected number of packets in the queue disc");
266  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 2, "unexpected number of packets in the first flow queue");
267  NS_TEST_ASSERT_MSG_EQ (flow1->GetStatus (), FqCoDelFlow::NEW_FLOW, "the first flow must still be in the list of new queues");
268 
269  // Add two packets from the second flow
270  hdr.SetDestination (Ipv4Address ("10.10.1.10"));
271  AddPacket (queueDisc, hdr);
272  AddPacket (queueDisc, hdr);
273  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 4, "unexpected number of packets in the queue disc");
274  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 2, "unexpected number of packets in the first flow queue");
275  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (1)->GetQueueDisc ()->GetNPackets (), 2, "unexpected number of packets in the second flow queue");
276  Ptr<FqCoDelFlow> flow2 = StaticCast<FqCoDelFlow> (queueDisc->GetQueueDiscClass (1));
277  NS_TEST_ASSERT_MSG_EQ (flow2->GetDeficit (), static_cast<int32_t> (queueDisc->GetQuantum ()), "the deficit of the second flow must equal the quantum");
278  NS_TEST_ASSERT_MSG_EQ (flow2->GetStatus (), FqCoDelFlow::NEW_FLOW, "the second flow must be in the list of new queues");
279 
280  // Dequeue a packet (from the second flow, as the first flow has a negative deficit)
281  queueDisc->Dequeue ();
282  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 3, "unexpected number of packets in the queue disc");
283  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 2, "unexpected number of packets in the first flow queue");
284  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (1)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the second flow queue");
285  // the first flow got a quantum of deficit (-30+90=60) and has been moved to the end of the list of old queues
286  NS_TEST_ASSERT_MSG_EQ (flow1->GetDeficit (), 60, "unexpected deficit for the first flow");
287  NS_TEST_ASSERT_MSG_EQ (flow1->GetStatus (), FqCoDelFlow::OLD_FLOW, "the first flow must be in the list of old queues");
288  // the second flow has a negative deficit (-30) and is still in the list of new queues
289  NS_TEST_ASSERT_MSG_EQ (flow2->GetDeficit (), -30, "unexpected deficit for the second flow");
290  NS_TEST_ASSERT_MSG_EQ (flow2->GetStatus (), FqCoDelFlow::NEW_FLOW, "the second flow must be in the list of new queues");
291 
292  // Dequeue a packet (from the first flow, as the second flow has a negative deficit)
293  queueDisc->Dequeue ();
294  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 2, "unexpected number of packets in the queue disc");
295  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the first flow queue");
296  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (1)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the second flow queue");
297  // the first flow has a negative deficit (60-(100+20)= -60) and stays in the list of old queues
298  NS_TEST_ASSERT_MSG_EQ (flow1->GetDeficit (), -60, "unexpected deficit for the first flow");
299  NS_TEST_ASSERT_MSG_EQ (flow1->GetStatus (), FqCoDelFlow::OLD_FLOW, "the first flow must be in the list of old queues");
300  // the second flow got a quantum of deficit (-30+90=60) and has been moved to the end of the list of old queues
301  NS_TEST_ASSERT_MSG_EQ (flow2->GetDeficit (), 60, "unexpected deficit for the second flow");
302  NS_TEST_ASSERT_MSG_EQ (flow2->GetStatus (), FqCoDelFlow::OLD_FLOW, "the second flow must be in the list of new queues");
303 
304  // Dequeue a packet (from the second flow, as the first flow has a negative deficit)
305  queueDisc->Dequeue ();
306  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 1, "unexpected number of packets in the queue disc");
307  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the first flow queue");
308  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (1)->GetQueueDisc ()->GetNPackets (), 0, "unexpected number of packets in the second flow queue");
309  // the first flow got a quantum of deficit (-60+90=30) and has been moved to the end of the list of old queues
310  NS_TEST_ASSERT_MSG_EQ (flow1->GetDeficit (), 30, "unexpected deficit for the first flow");
311  NS_TEST_ASSERT_MSG_EQ (flow1->GetStatus (), FqCoDelFlow::OLD_FLOW, "the first flow must be in the list of old queues");
312  // the second flow has a negative deficit (60-(100+20)= -60)
313  NS_TEST_ASSERT_MSG_EQ (flow2->GetDeficit (), -60, "unexpected deficit for the second flow");
314  NS_TEST_ASSERT_MSG_EQ (flow2->GetStatus (), FqCoDelFlow::OLD_FLOW, "the second flow must be in the list of new queues");
315 
316  // Dequeue a packet (from the first flow, as the second flow has a negative deficit)
317  queueDisc->Dequeue ();
318  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 0, "unexpected number of packets in the queue disc");
319  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 0, "unexpected number of packets in the first flow queue");
320  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (1)->GetQueueDisc ()->GetNPackets (), 0, "unexpected number of packets in the second flow queue");
321  // the first flow has a negative deficit (30-(100+20)= -90)
322  NS_TEST_ASSERT_MSG_EQ (flow1->GetDeficit (), -90, "unexpected deficit for the first flow");
323  NS_TEST_ASSERT_MSG_EQ (flow1->GetStatus (), FqCoDelFlow::OLD_FLOW, "the first flow must be in the list of old queues");
324  // the second flow got a quantum of deficit (-60+90=30) and has been moved to the end of the list of old queues
325  NS_TEST_ASSERT_MSG_EQ (flow2->GetDeficit (), 30, "unexpected deficit for the second flow");
326  NS_TEST_ASSERT_MSG_EQ (flow2->GetStatus (), FqCoDelFlow::OLD_FLOW, "the second flow must be in the list of new queues");
327 
328  // Dequeue a packet
329  queueDisc->Dequeue ();
330  // the first flow is at the head of the list of old queues but has a negative deficit, thus it gets a quantun
331  // of deficit (-90+90=0) and is moved to the end of the list of old queues. Then, the second flow (which has a
332  // positive deficit) is selected, but the second flow is empty and thus it is set to inactive. The first flow is
333  // reconsidered, but it has a null deficit, hence it gets another quantum of deficit (0+90=90). Then, the first
334  // flow is reconsidered again, now it has a positive deficit and hence it is selected. But, it is empty and
335  // therefore is set to inactive, too.
336  NS_TEST_ASSERT_MSG_EQ (flow1->GetDeficit (), 90, "unexpected deficit for the first flow");
337  NS_TEST_ASSERT_MSG_EQ (flow1->GetStatus (), FqCoDelFlow::INACTIVE, "the first flow must be inactive");
338  NS_TEST_ASSERT_MSG_EQ (flow2->GetDeficit (), 30, "unexpected deficit for the second flow");
339  NS_TEST_ASSERT_MSG_EQ (flow2->GetStatus (), FqCoDelFlow::INACTIVE, "the second flow must be inactive");
340 
341  Simulator::Destroy ();
342 }
343 
348 {
349 public:
352 
353 private:
354  virtual void DoRun (void);
355  void AddPacket (Ptr<FqCoDelQueueDisc> queue, Ipv4Header ipHdr, TcpHeader tcpHdr);
356 };
357 
359  : TestCase ("Test TCP flows separation")
360 {
361 }
362 
364 {
365 }
366 
367 void
369 {
370  Ptr<Packet> p = Create<Packet> (100);
371  p->AddHeader (tcpHdr);
372  Address dest;
373  Ptr<Ipv4QueueDiscItem> item = Create<Ipv4QueueDiscItem> (p, dest, 0, ipHdr);
374  queue->Enqueue (item);
375 }
376 
377 void
379 {
380  Ptr<FqCoDelQueueDisc> queueDisc = CreateObjectWithAttributes<FqCoDelQueueDisc> ("MaxSize", StringValue ("10p"));
381 
382  queueDisc->SetQuantum (1500);
383  queueDisc->Initialize ();
384 
385  Ipv4Header hdr;
386  hdr.SetPayloadSize (100);
387  hdr.SetSource (Ipv4Address ("10.10.1.1"));
388  hdr.SetDestination (Ipv4Address ("10.10.1.2"));
389  hdr.SetProtocol (6);
390 
391  TcpHeader tcpHdr;
392  tcpHdr.SetSourcePort (7);
393  tcpHdr.SetDestinationPort (27);
394 
395  // Add three packets from the first flow
396  AddPacket (queueDisc, hdr, tcpHdr);
397  AddPacket (queueDisc, hdr, tcpHdr);
398  AddPacket (queueDisc, hdr, tcpHdr);
399  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 3, "unexpected number of packets in the queue disc");
400  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 3, "unexpected number of packets in the first flow queue");
401 
402  // Add a packet from the second flow
403  tcpHdr.SetSourcePort (8);
404  AddPacket (queueDisc, hdr, tcpHdr);
405  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 4, "unexpected number of packets in the queue disc");
406  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 3, "unexpected number of packets in the first flow queue");
407  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (1)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the second flow queue");
408 
409  // Add a packet from the third flow
410  tcpHdr.SetDestinationPort (28);
411  AddPacket (queueDisc, hdr, tcpHdr);
412  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 5, "unexpected number of packets in the queue disc");
413  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 3, "unexpected number of packets in the first flow queue");
414  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (1)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the second flow queue");
415  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (2)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the third flow queue");
416 
417  // Add two packets from the fourth flow
418  tcpHdr.SetSourcePort (7);
419  AddPacket (queueDisc, hdr, tcpHdr);
420  AddPacket (queueDisc, hdr, tcpHdr);
421  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 7, "unexpected number of packets in the queue disc");
422  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 3, "unexpected number of packets in the first flow queue");
423  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (1)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the second flow queue");
424  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (2)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the third flow queue");
425  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (3)->GetQueueDisc ()->GetNPackets (), 2, "unexpected number of packets in the third flow queue");
426 
427  Simulator::Destroy ();
428 }
429 
434 {
435 public:
438 
439 private:
440  virtual void DoRun (void);
441  void AddPacket (Ptr<FqCoDelQueueDisc> queue, Ipv4Header ipHdr, UdpHeader udpHdr);
442 };
443 
445  : TestCase ("Test UDP flows separation")
446 {
447 }
448 
450 {
451 }
452 
453 void
455 {
456  Ptr<Packet> p = Create<Packet> (100);
457  p->AddHeader (udpHdr);
458  Address dest;
459  Ptr<Ipv4QueueDiscItem> item = Create<Ipv4QueueDiscItem> (p, dest, 0, ipHdr);
460  queue->Enqueue (item);
461 }
462 
463 void
465 {
466  Ptr<FqCoDelQueueDisc> queueDisc = CreateObjectWithAttributes<FqCoDelQueueDisc> ("MaxSize", StringValue ("10p"));
467 
468  queueDisc->SetQuantum (1500);
469  queueDisc->Initialize ();
470 
471  Ipv4Header hdr;
472  hdr.SetPayloadSize (100);
473  hdr.SetSource (Ipv4Address ("10.10.1.1"));
474  hdr.SetDestination (Ipv4Address ("10.10.1.2"));
475  hdr.SetProtocol (17);
476 
477  UdpHeader udpHdr;
478  udpHdr.SetSourcePort (7);
479  udpHdr.SetDestinationPort (27);
480 
481  // Add three packets from the first flow
482  AddPacket (queueDisc, hdr, udpHdr);
483  AddPacket (queueDisc, hdr, udpHdr);
484  AddPacket (queueDisc, hdr, udpHdr);
485  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 3, "unexpected number of packets in the queue disc");
486  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 3, "unexpected number of packets in the first flow queue");
487 
488  // Add a packet from the second flow
489  udpHdr.SetSourcePort (8);
490  AddPacket (queueDisc, hdr, udpHdr);
491  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 4, "unexpected number of packets in the queue disc");
492  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 3, "unexpected number of packets in the first flow queue");
493  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (1)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the second flow queue");
494 
495  // Add a packet from the third flow
496  udpHdr.SetDestinationPort (28);
497  AddPacket (queueDisc, hdr, udpHdr);
498  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 5, "unexpected number of packets in the queue disc");
499  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 3, "unexpected number of packets in the first flow queue");
500  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (1)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the second flow queue");
501  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (2)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the third flow queue");
502 
503  // Add two packets from the fourth flow
504  udpHdr.SetSourcePort (7);
505  AddPacket (queueDisc, hdr, udpHdr);
506  AddPacket (queueDisc, hdr, udpHdr);
507  NS_TEST_ASSERT_MSG_EQ (queueDisc->QueueDisc::GetNPackets (), 7, "unexpected number of packets in the queue disc");
508  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (0)->GetQueueDisc ()->GetNPackets (), 3, "unexpected number of packets in the first flow queue");
509  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (1)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the second flow queue");
510  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (2)->GetQueueDisc ()->GetNPackets (), 1, "unexpected number of packets in the third flow queue");
511  NS_TEST_ASSERT_MSG_EQ (queueDisc->GetQueueDiscClass (3)->GetQueueDisc ()->GetNPackets (), 2, "unexpected number of packets in the third flow queue");
512 
513  Simulator::Destroy ();
514 }
515 
517 {
518 public:
520 };
521 
523  : TestSuite ("fq-codel-queue-disc", UNIT)
524 {
525  AddTestCase (new FqCoDelQueueDiscNoSuitableFilter, TestCase::QUICK);
527  AddTestCase (new FqCoDelQueueDiscDeficit, TestCase::QUICK);
528  AddTestCase (new FqCoDelQueueDiscTCPFlowsSeparation, TestCase::QUICK);
529  AddTestCase (new FqCoDelQueueDiscUDPFlowsSeparation, TestCase::QUICK);
530 }
531 
void SetSource(Ipv4Address source)
Definition: ipv4-header.cc:285
void SetPayloadSize(uint16_t size)
Definition: ipv4-header.cc:56
virtual int32_t DoClassify(Ptr< QueueDiscItem > item) const
Classify a packet.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Packet header for IPv6.
Definition: ipv6-header.h:34
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:298
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
Definition: queue-disc.cc:844
Hold variables of type string.
Definition: string.h:41
virtual void DoRun(void)
Implementation to actually run this TestCase.
A suite of tests to run.
Definition: test.h:1342
void SetDestinationPort(uint16_t port)
Definition: udp-header.cc:55
void SetSourcePort(uint16_t port)
Definition: udp-header.cc:60
void SetProtocol(uint8_t num)
Definition: ipv4-header.cc:278
encapsulates test code
Definition: test.h:1155
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr)
a polymophic address class
Definition: address.h:90
This class tests the TCP flows separation.
Packet header for IPv4.
Definition: ipv4-header.h:33
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
#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:168
This class tests packets for which there is no suitable filter.
uint32_t GetQuantum(void) const
Get the quantum value.
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header ipHdr, TcpHeader tcpHdr)
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header ipHdr, UdpHeader udpHdr)
virtual void DoRun(void)
Implementation to actually run this TestCase.
void AddPacket(Ptr< FqCoDelQueueDisc > queue, Ipv4Header hdr)
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
Definition: queue-disc.cc:645
void SetDestinationPort(uint16_t port)
Set the destination port.
Definition: tcp-header.cc:95
Ptr< QueueDiscItem > Dequeue(void)
Extract from the queue disc the packet that has been dequeued by calling Peek, if any...
Definition: queue-disc.cc:879
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::size_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
Definition: queue-disc.cc:652
void SetQuantum(uint32_t quantum)
Set the quantum value.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
This class tests the UDP flows separation.
void SetSourcePort(uint16_t port)
Set the source port.
Definition: tcp-header.cc:89
Packet header for UDP packets.
Definition: udp-header.h:39
static FqCoDelQueueDiscTestSuite fqCoDelQueueDiscTestSuite
This class tests the IP flows separation and the packet limit.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
static TypeId GetTypeId(void)
Get the type ID.
Ipv4PacketFilter is the abstract base class for filters defined for IPv4 packets. ...
This class tests the deficit per flow.
void AddPacketFilter(Ptr< PacketFilter > filter)
Add a packet filter to the tail of the list of filters used to classify packets.
Definition: queue-disc.cc:600
Simple test packet filter able to classify IPv4 packets.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void Initialize(void)
Invoke DoInitialize on all Objects aggregated to this one.
Definition: object.cc:183
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256