OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2017 Trinity College Dublin |
| 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: Rohit P. Tahiliani <rohit.tahil@gmail.com> |
| 19 * |
| 20 */ |
| 21 |
| 22 #include "ns3/test.h" |
| 23 #include "ns3/pi-square-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 |
| 31 using namespace ns3; |
| 32 |
| 33 class PiSquareQueueDiscTestItem : public QueueDiscItem |
| 34 { |
| 35 public: |
| 36 PiSquareQueueDiscTestItem (Ptr<Packet> p, const Address & addr, uint16_t proto
col); |
| 37 virtual ~PiSquareQueueDiscTestItem (); |
| 38 virtual void AddHeader (void); |
| 39 virtual bool Mark (void); |
| 40 virtual bool IsL4S (void); |
| 41 |
| 42 private: |
| 43 PiSquareQueueDiscTestItem (); |
| 44 PiSquareQueueDiscTestItem (const PiSquareQueueDiscTestItem &); |
| 45 PiSquareQueueDiscTestItem &operator = (const PiSquareQueueDiscTestItem &); |
| 46 }; |
| 47 |
| 48 PiSquareQueueDiscTestItem::PiSquareQueueDiscTestItem (Ptr<Packet> p, const Addre
ss & addr, uint16_t protocol) |
| 49 : QueueDiscItem (p, addr, protocol) |
| 50 { |
| 51 } |
| 52 |
| 53 PiSquareQueueDiscTestItem::~PiSquareQueueDiscTestItem () |
| 54 { |
| 55 } |
| 56 |
| 57 void |
| 58 PiSquareQueueDiscTestItem::AddHeader (void) |
| 59 { |
| 60 } |
| 61 |
| 62 bool |
| 63 PiSquareQueueDiscTestItem::Mark (void) |
| 64 { |
| 65 return false; |
| 66 } |
| 67 |
| 68 bool |
| 69 PiSquareQueueDiscTestItem::IsL4S (void) |
| 70 { |
| 71 return false; |
| 72 } |
| 73 |
| 74 class L4SQueueDiscTestItem : public QueueDiscItem |
| 75 { |
| 76 public: |
| 77 L4SQueueDiscTestItem (Ptr<Packet> p, const Address & addr, uint16_t protocol); |
| 78 virtual ~L4SQueueDiscTestItem (); |
| 79 virtual void AddHeader (void); |
| 80 virtual bool Mark (void); |
| 81 virtual bool IsL4S (void); |
| 82 |
| 83 private: |
| 84 L4SQueueDiscTestItem (); |
| 85 L4SQueueDiscTestItem (const L4SQueueDiscTestItem &); |
| 86 L4SQueueDiscTestItem &operator = (const L4SQueueDiscTestItem &); |
| 87 }; |
| 88 |
| 89 L4SQueueDiscTestItem::L4SQueueDiscTestItem (Ptr<Packet> p, const Address & addr,
uint16_t protocol) |
| 90 : QueueDiscItem (p, addr, protocol) |
| 91 { |
| 92 } |
| 93 |
| 94 L4SQueueDiscTestItem::~L4SQueueDiscTestItem () |
| 95 { |
| 96 } |
| 97 |
| 98 void |
| 99 L4SQueueDiscTestItem::AddHeader (void) |
| 100 { |
| 101 } |
| 102 |
| 103 bool |
| 104 L4SQueueDiscTestItem::Mark (void) |
| 105 { |
| 106 return true; |
| 107 } |
| 108 |
| 109 bool |
| 110 L4SQueueDiscTestItem::IsL4S (void) |
| 111 { |
| 112 return true; |
| 113 } |
| 114 |
| 115 class ClassicQueueDiscTestItem : public QueueDiscItem |
| 116 { |
| 117 public: |
| 118 ClassicQueueDiscTestItem (Ptr<Packet> p, const Address & addr, uint16_t protoc
ol); |
| 119 virtual ~ClassicQueueDiscTestItem (); |
| 120 virtual void AddHeader (void); |
| 121 virtual bool Mark (void); |
| 122 virtual bool IsL4S (void); |
| 123 |
| 124 private: |
| 125 ClassicQueueDiscTestItem (); |
| 126 ClassicQueueDiscTestItem (const ClassicQueueDiscTestItem &); |
| 127 ClassicQueueDiscTestItem &operator = (const ClassicQueueDiscTestItem &); |
| 128 }; |
| 129 |
| 130 ClassicQueueDiscTestItem::ClassicQueueDiscTestItem (Ptr<Packet> p, const Address
& addr, uint16_t protocol) |
| 131 : QueueDiscItem (p, addr, protocol) |
| 132 { |
| 133 } |
| 134 |
| 135 ClassicQueueDiscTestItem::~ClassicQueueDiscTestItem () |
| 136 { |
| 137 } |
| 138 |
| 139 void |
| 140 ClassicQueueDiscTestItem::AddHeader (void) |
| 141 { |
| 142 } |
| 143 |
| 144 bool |
| 145 ClassicQueueDiscTestItem::Mark (void) |
| 146 { |
| 147 return true; |
| 148 } |
| 149 |
| 150 bool |
| 151 ClassicQueueDiscTestItem::IsL4S (void) |
| 152 { |
| 153 return false; |
| 154 } |
| 155 |
| 156 class PiSquareQueueDiscTestCase : public TestCase |
| 157 { |
| 158 public: |
| 159 PiSquareQueueDiscTestCase (); |
| 160 virtual void DoRun (void); |
| 161 private: |
| 162 void Enqueue (Ptr<PiSquareQueueDisc> queue, uint32_t size, uint32_t nPkt, Stri
ngValue trafficType); |
| 163 void EnqueueWithDelay (Ptr<PiSquareQueueDisc> queue, uint32_t size, uint32_t n
Pkt, StringValue trafficType); |
| 164 void Dequeue (Ptr<PiSquareQueueDisc> queue, uint32_t nPkt); |
| 165 void DequeueWithDelay (Ptr<PiSquareQueueDisc> queue, double delay, uint32_t nP
kt); |
| 166 void RunPiSquareTest (StringValue mode); |
| 167 }; |
| 168 |
| 169 PiSquareQueueDiscTestCase::PiSquareQueueDiscTestCase () |
| 170 : TestCase ("Sanity check on the pi square queue implementation") |
| 171 { |
| 172 } |
| 173 |
| 174 void |
| 175 PiSquareQueueDiscTestCase::RunPiSquareTest (StringValue mode) |
| 176 { |
| 177 uint32_t pktSize = 0; |
| 178 |
| 179 // 1 for packets; pktSize for bytes |
| 180 uint32_t modeSize = 1; |
| 181 |
| 182 uint32_t qSize = 300; |
| 183 Ptr<PiSquareQueueDisc> queue = CreateObject<PiSquareQueueDisc> (); |
| 184 |
| 185 |
| 186 // test 1: simple enqueue/dequeue with defaults, no drops |
| 187 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true, |
| 188 "Verify that we can actually set the attribute Mode"); |
| 189 |
| 190 Address dest; |
| 191 |
| 192 if (queue->GetMode () == PiSquareQueueDisc::QUEUE_DISC_MODE_BYTES) |
| 193 { |
| 194 // pktSize should be same as MeanPktSize to avoid performance gap between
byte and packet mode |
| 195 pktSize = 1000; |
| 196 modeSize = pktSize; |
| 197 qSize = qSize * modeSize; |
| 198 } |
| 199 |
| 200 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueLimit", UintegerValu
e (qSize)), true, |
| 201 "Verify that we can actually set the attribute QueueLim
it"); |
| 202 |
| 203 Ptr<Packet> p1, p2, p3, p4, p5, p6, p7, p8; |
| 204 p1 = Create<Packet> (pktSize); |
| 205 p2 = Create<Packet> (pktSize); |
| 206 p3 = Create<Packet> (pktSize); |
| 207 p4 = Create<Packet> (pktSize); |
| 208 p5 = Create<Packet> (pktSize); |
| 209 p6 = Create<Packet> (pktSize); |
| 210 p7 = Create<Packet> (pktSize); |
| 211 p8 = Create<Packet> (pktSize); |
| 212 |
| 213 queue->Initialize (); |
| 214 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 0 * modeSize, "There should be
no packets in there"); |
| 215 queue->Enqueue (Create<PiSquareQueueDiscTestItem> (p1, dest, 0)); |
| 216 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 1 * modeSize, "There should be
one packet in there"); |
| 217 queue->Enqueue (Create<PiSquareQueueDiscTestItem> (p2, dest, 0)); |
| 218 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 2 * modeSize, "There should be
two packets in there"); |
| 219 queue->Enqueue (Create<PiSquareQueueDiscTestItem> (p3, dest, 0)); |
| 220 queue->Enqueue (Create<PiSquareQueueDiscTestItem> (p4, dest, 0)); |
| 221 queue->Enqueue (Create<PiSquareQueueDiscTestItem> (p5, dest, 0)); |
| 222 queue->Enqueue (Create<PiSquareQueueDiscTestItem> (p6, dest, 0)); |
| 223 queue->Enqueue (Create<PiSquareQueueDiscTestItem> (p7, dest, 0)); |
| 224 queue->Enqueue (Create<PiSquareQueueDiscTestItem> (p8, dest, 0)); |
| 225 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 8 * modeSize, "There should be
eight packets in there"); |
| 226 |
| 227 Ptr<QueueDiscItem> item; |
| 228 |
| 229 item = queue->Dequeue (); |
| 230 NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the first packet")
; |
| 231 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 7 * modeSize, "There should be
seven packets in there"); |
| 232 NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p1->GetUid (), "was this
the first packet ?"); |
| 233 |
| 234 item = queue->Dequeue (); |
| 235 NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the second packet"
); |
| 236 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 6 * modeSize, "There should be
six packet in there"); |
| 237 NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p2->GetUid (), "Was this
the second packet ?"); |
| 238 |
| 239 item = queue->Dequeue (); |
| 240 NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the third packet")
; |
| 241 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 5 * modeSize, "There should be
five packets in there"); |
| 242 NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p3->GetUid (), "Was this
the third packet ?"); |
| 243 |
| 244 item = queue->Dequeue (); |
| 245 item = queue->Dequeue (); |
| 246 item = queue->Dequeue (); |
| 247 item = queue->Dequeue (); |
| 248 item = queue->Dequeue (); |
| 249 |
| 250 item = queue->Dequeue (); |
| 251 NS_TEST_EXPECT_MSG_EQ ((item == 0), true, "There are really no packets in ther
e"); |
| 252 |
| 253 |
| 254 // test 2: more data with defaults, unforced drops but no forced drops |
| 255 queue = CreateObject<PiSquareQueueDisc> (); |
| 256 pktSize = 1000; // pktSize != 0 because DequeueThreshold always works in byte
s |
| 257 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true, |
| 258 "Verify that we can actually set the attribute Mode"); |
| 259 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueLimit", UintegerValu
e (qSize)), true, |
| 260 "Verify that we can actually set the attribute QueueLim
it"); |
| 261 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("A", DoubleValue (0.125)),
true, |
| 262 "Verify that we can actually set the attribute A"); |
| 263 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("B", DoubleValue (1.25)),
true, |
| 264 "Verify that we can actually set the attribute B"); |
| 265 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Tupdate", TimeValue (Seco
nds (0.03))), true, |
| 266 "Verify that we can actually set the attribute Tupdate"
); |
| 267 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Supdate", TimeValue (Seco
nds (0.0))), true, |
| 268 "Verify that we can actually set the attribute Supdate"
); |
| 269 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("DequeueThreshold", Uinteg
erValue (10000)), true, |
| 270 "Verify that we can actually set the attribute DequeueT
hreshold"); |
| 271 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueDelayReference", Tim
eValue (Seconds (0.02))), true, |
| 272 "Verify that we can actually set the attribute QueueDel
ayReference"); |
| 273 queue->Initialize (); |
| 274 EnqueueWithDelay (queue, pktSize, 400, StringValue ("Unclassified")); |
| 275 DequeueWithDelay (queue, 0.012, 400); |
| 276 Simulator::Stop (Seconds (8.0)); |
| 277 Simulator::Run (); |
| 278 PiSquareQueueDisc::Stats st = StaticCast<PiSquareQueueDisc> (queue)->GetStats
(); |
| 279 uint32_t test2 = st.unforcedDrop; |
| 280 NS_TEST_EXPECT_MSG_NE (test2, 0, "There should some unforced drops"); |
| 281 NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should zero forced drops"); |
| 282 |
| 283 |
| 284 // test 3: same as test 2, but with higher QueueDelayReference |
| 285 queue = CreateObject<PiSquareQueueDisc> (); |
| 286 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true, |
| 287 "Verify that we can actually set the attribute Mode"); |
| 288 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueLimit", UintegerValu
e (qSize)), true, |
| 289 "Verify that we can actually set the attribute QueueLim
it"); |
| 290 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("A", DoubleValue (0.125)),
true, |
| 291 "Verify that we can actually set the attribute A"); |
| 292 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("B", DoubleValue (1.25)),
true, |
| 293 "Verify that we can actually set the attribute B"); |
| 294 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Tupdate", TimeValue (Seco
nds (0.03))), true, |
| 295 "Verify that we can actually set the attribute Tupdate"
); |
| 296 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Supdate", TimeValue (Seco
nds (0.0))), true, |
| 297 "Verify that we can actually set the attribute Supdate"
); |
| 298 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("DequeueThreshold", Uinteg
erValue (10000)), true, |
| 299 "Verify that we can actually set the attribute DequeueT
hreshold"); |
| 300 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueDelayReference", Tim
eValue (Seconds (0.08))), true, |
| 301 "Verify that we can actually set the attribute QueueDel
ayReference"); |
| 302 queue->Initialize (); |
| 303 EnqueueWithDelay (queue, pktSize, 400, StringValue ("Unclassified")); |
| 304 DequeueWithDelay (queue, 0.012, 400); |
| 305 Simulator::Stop (Seconds (8.0)); |
| 306 Simulator::Run (); |
| 307 st = StaticCast<PiSquareQueueDisc> (queue)->GetStats (); |
| 308 uint32_t test3 = st.unforcedDrop; |
| 309 NS_TEST_EXPECT_MSG_LT (test3, test2, "Test 3 should have less unforced drops t
han test 2"); |
| 310 NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should zero forced drops"); |
| 311 |
| 312 |
| 313 // test 4: same as test 2, but with lesser dequeue rate |
| 314 queue = CreateObject<PiSquareQueueDisc> (); |
| 315 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true, |
| 316 "Verify that we can actually set the attribute Mode"); |
| 317 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueLimit", UintegerValu
e (qSize)), true, |
| 318 "Verify that we can actually set the attribute QueueLim
it"); |
| 319 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("A", DoubleValue (0.125)),
true, |
| 320 "Verify that we can actually set the attribute A"); |
| 321 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("B", DoubleValue (1.25)),
true, |
| 322 "Verify that we can actually set the attribute B"); |
| 323 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Tupdate", TimeValue (Seco
nds (0.03))), true, |
| 324 "Verify that we can actually set the attribute Tupdate"
); |
| 325 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Supdate", TimeValue (Seco
nds (0.0))), true, |
| 326 "Verify that we can actually set the attribute Supdate"
); |
| 327 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("DequeueThreshold", Uinteg
erValue (10000)), true, |
| 328 "Verify that we can actually set the attribute DequeueT
hreshold"); |
| 329 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueDelayReference", Tim
eValue (Seconds (0.02))), true, |
| 330 "Verify that we can actually set the attribute QueueDel
ayReference"); |
| 331 queue->Initialize (); |
| 332 EnqueueWithDelay (queue, pktSize, 400, StringValue ("Unclassified")); |
| 333 DequeueWithDelay (queue, 0.015, 400); // delay between two successive dequeue
events is increased |
| 334 Simulator::Stop (Seconds (8.0)); |
| 335 Simulator::Run (); |
| 336 st = StaticCast<PiSquareQueueDisc> (queue)->GetStats (); |
| 337 uint32_t test4 = st.unforcedDrop; |
| 338 NS_TEST_EXPECT_MSG_GT (test4, test2, "Test 4 should have more unforced drops t
han test 2"); |
| 339 NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should zero forced drops"); |
| 340 |
| 341 |
| 342 // test 5: verify the working of Coupled AQM functionality |
| 343 Ptr<PiSquareQueueDisc> queue1 = CreateObject<PiSquareQueueDisc> (); |
| 344 Ptr<PiSquareQueueDisc> queue2 = CreateObject<PiSquareQueueDisc> (); |
| 345 |
| 346 NS_TEST_EXPECT_MSG_EQ (queue1->SetAttributeFailSafe ("Mode", mode), true, |
| 347 "Verify that we can actually set the attribute Mode"); |
| 348 NS_TEST_EXPECT_MSG_EQ (queue2->SetAttributeFailSafe ("Mode", mode), true, |
| 349 "Verify that we can actually set the attribute Mode"); |
| 350 NS_TEST_EXPECT_MSG_EQ (queue1->SetAttributeFailSafe ("QueueLimit", UintegerVal
ue (qSize)), true, |
| 351 "Verify that we can actually set the attribute QueueLim
it"); |
| 352 NS_TEST_EXPECT_MSG_EQ (queue2->SetAttributeFailSafe ("QueueLimit", UintegerVal
ue (qSize)), true, |
| 353 "Verify that we can actually set the attribute QueueLim
it"); |
| 354 NS_TEST_EXPECT_MSG_EQ (queue1->SetAttributeFailSafe ("A", DoubleValue (0.125))
, true, |
| 355 "Verify that we can actually set the attribute A"); |
| 356 NS_TEST_EXPECT_MSG_EQ (queue2->SetAttributeFailSafe ("A", DoubleValue (0.125))
, true, |
| 357 "Verify that we can actually set the attribute A"); |
| 358 NS_TEST_EXPECT_MSG_EQ (queue1->SetAttributeFailSafe ("B", DoubleValue (1.25)),
true, |
| 359 "Verify that we can actually set the attribute B"); |
| 360 NS_TEST_EXPECT_MSG_EQ (queue2->SetAttributeFailSafe ("B", DoubleValue (1.25)),
true, |
| 361 "Verify that we can actually set the attribute B"); |
| 362 NS_TEST_EXPECT_MSG_EQ (queue1->SetAttributeFailSafe ("Tupdate", TimeValue (Sec
onds (0.03))), true, |
| 363 "Verify that we can actually set the attribute Tupdate"
); |
| 364 NS_TEST_EXPECT_MSG_EQ (queue2->SetAttributeFailSafe ("Tupdate", TimeValue (Sec
onds (0.03))), true, |
| 365 "Verify that we can actually set the attribute Tupdate"
); |
| 366 NS_TEST_EXPECT_MSG_EQ (queue1->SetAttributeFailSafe ("Supdate", TimeValue (Sec
onds (0.0))), true, |
| 367 "Verify that we can actually set the attribute Supdate"
); |
| 368 NS_TEST_EXPECT_MSG_EQ (queue2->SetAttributeFailSafe ("Tupdate", TimeValue (Sec
onds (0.03))), true, |
| 369 "Verify that we can actually set the attribute Tupdate"
); |
| 370 NS_TEST_EXPECT_MSG_EQ (queue1->SetAttributeFailSafe ("DequeueThreshold", Uinte
gerValue (10000)), true, |
| 371 "Verify that we can actually set the attribute DequeueT
hreshold"); |
| 372 NS_TEST_EXPECT_MSG_EQ (queue2->SetAttributeFailSafe ("Tupdate", TimeValue (Sec
onds (0.03))), true, |
| 373 "Verify that we can actually set the attribute Tupdate"
); |
| 374 NS_TEST_EXPECT_MSG_EQ (queue1->SetAttributeFailSafe ("QueueDelayReference", Ti
meValue (Seconds (0.02))), true, |
| 375 "Verify that we can actually set the attribute QueueDel
ayReference"); |
| 376 NS_TEST_EXPECT_MSG_EQ (queue2->SetAttributeFailSafe ("Tupdate", TimeValue (Sec
onds (0.03))), true, |
| 377 "Verify that we can actually set the attribute Tupdate"
); |
| 378 NS_TEST_EXPECT_MSG_EQ (queue1->SetAttributeFailSafe ("CoupledAqm", BooleanValu
e (true)), true, |
| 379 "Verify that we can actually set the attribute CoupledA
qm"); |
| 380 NS_TEST_EXPECT_MSG_EQ (queue2->SetAttributeFailSafe ("CoupledAqm", BooleanValu
e (true)), true, |
| 381 "Verify that we can actually set the attribute CoupledA
qm"); |
| 382 |
| 383 BooleanValue useEcn1; |
| 384 BooleanValue useEcn2; |
| 385 queue1->GetAttribute ("UseEcn", useEcn1); |
| 386 NS_TEST_EXPECT_MSG_EQ (useEcn1.Get (), true, |
| 387 "Verify that the attribute UseEcn of queue1 is set to t
rue when CoupledAqm is true"); |
| 388 queue2->GetAttribute ("UseEcn", useEcn2); |
| 389 NS_TEST_EXPECT_MSG_EQ (useEcn2.Get (), true, |
| 390 "Verify that the attribute UseEcn of queue2 is set to t
rue when CoupledAqm is true"); |
| 391 queue1->Initialize (); |
| 392 queue2->Initialize (); |
| 393 EnqueueWithDelay (queue1, pktSize, 400, StringValue ("L4S")); |
| 394 EnqueueWithDelay (queue2, pktSize, 400, StringValue ("Classic")); |
| 395 DequeueWithDelay (queue1, 0.015, 400); |
| 396 DequeueWithDelay (queue2, 0.015, 400); |
| 397 Simulator::Stop (Seconds (8.0)); |
| 398 Simulator::Run (); |
| 399 PiSquareQueueDisc::Stats st1 = StaticCast<PiSquareQueueDisc> (queue1)->GetStat
s (); |
| 400 PiSquareQueueDisc::Stats st2 = StaticCast<PiSquareQueueDisc> (queue2)->GetStat
s (); |
| 401 uint32_t mark1 = st1.unforcedMark; |
| 402 uint32_t mark2 = st2.unforcedMark; |
| 403 NS_TEST_EXPECT_MSG_GT (mark1, mark2, "Packets of L4S traffic should have more
unforced marks than packets of Classic traffic"); |
| 404 NS_TEST_EXPECT_MSG_EQ (st1.unforcedDrop, 0, "There should be zero unforced dro
ps for packets of L4S traffic"); |
| 405 NS_TEST_EXPECT_MSG_EQ (st2.unforcedDrop, 0, "There should be zero unforced dro
ps for packets of Classic traffic when its ECN capable"); |
| 406 } |
| 407 |
| 408 void |
| 409 PiSquareQueueDiscTestCase::Enqueue (Ptr<PiSquareQueueDisc> queue, uint32_t size,
uint32_t nPkt, StringValue trafficType) |
| 410 { |
| 411 Address dest; |
| 412 for (uint32_t i = 0; i < nPkt; i++) |
| 413 { |
| 414 if (trafficType.Get () == "L4S") |
| 415 { |
| 416 queue->Enqueue (Create<L4SQueueDiscTestItem> (Create<Packet> (size), d
est, 0)); |
| 417 } |
| 418 else if (trafficType.Get () == "Classic") |
| 419 { |
| 420 queue->Enqueue (Create<ClassicQueueDiscTestItem> (Create<Packet> (size
), dest, 0)); |
| 421 } |
| 422 else |
| 423 { |
| 424 queue->Enqueue (Create<PiSquareQueueDiscTestItem> (Create<Packet> (siz
e), dest, 0)); |
| 425 } |
| 426 } |
| 427 } |
| 428 |
| 429 void |
| 430 PiSquareQueueDiscTestCase::EnqueueWithDelay (Ptr<PiSquareQueueDisc> queue, uint3
2_t size, uint32_t nPkt, StringValue trafficType) |
| 431 { |
| 432 Address dest; |
| 433 double delay = 0.01; // enqueue packets with delay |
| 434 for (uint32_t i = 0; i < nPkt; i++) |
| 435 { |
| 436 Simulator::Schedule (Time (Seconds ((i + 1) * delay)), &PiSquareQueueDiscT
estCase::Enqueue, this, queue, size, 1, trafficType); |
| 437 } |
| 438 } |
| 439 |
| 440 void |
| 441 PiSquareQueueDiscTestCase::Dequeue (Ptr<PiSquareQueueDisc> queue, uint32_t nPkt) |
| 442 { |
| 443 for (uint32_t i = 0; i < nPkt; i++) |
| 444 { |
| 445 Ptr<QueueDiscItem> item = queue->Dequeue (); |
| 446 } |
| 447 } |
| 448 |
| 449 void |
| 450 PiSquareQueueDiscTestCase::DequeueWithDelay (Ptr<PiSquareQueueDisc> queue, doubl
e delay, uint32_t nPkt) |
| 451 { |
| 452 for (uint32_t i = 0; i < nPkt; i++) |
| 453 { |
| 454 Simulator::Schedule (Time (Seconds ((i + 1) * delay)), &PiSquareQueueDiscT
estCase::Dequeue, this, queue, 1); |
| 455 } |
| 456 } |
| 457 |
| 458 void |
| 459 PiSquareQueueDiscTestCase::DoRun (void) |
| 460 { |
| 461 RunPiSquareTest (StringValue ("QUEUE_DISC_MODE_PACKETS")); |
| 462 RunPiSquareTest (StringValue ("QUEUE_DISC_MODE_BYTES")); |
| 463 Simulator::Destroy (); |
| 464 } |
| 465 |
| 466 static class PiSquareQueueDiscTestSuite : public TestSuite |
| 467 { |
| 468 public: |
| 469 PiSquareQueueDiscTestSuite () |
| 470 : TestSuite ("pi-square-queue-disc", UNIT) |
| 471 { |
| 472 AddTestCase (new PiSquareQueueDiscTestCase (), TestCase::QUICK); |
| 473 } |
| 474 } g_piSquareQueueTestSuite; |
OLD | NEW |