22 #include "ns3/config.h"
23 #include "ns3/double.h"
25 #include "ns3/node-container.h"
26 #include "ns3/packet.h"
27 #include "ns3/simple-channel.h"
28 #include "ns3/simple-net-device.h"
29 #include "ns3/simulator.h"
30 #include "ns3/string.h"
31 #include "ns3/tbf-queue-disc.h"
33 #include "ns3/traffic-control-layer.h"
34 #include "ns3/uinteger.h"
60 void AddHeader()
override;
93 void DoRun()
override;
120 :
TestCase(
"Sanity check on the TBF queue implementation")
129 uint32_t modeSize = 1;
131 uint32_t burst = 6000;
151 qSize = qSize * modeSize;
155 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
157 "Verify that we can actually set the attribute MaxSize");
160 "Verify that we can actually set the attribute Burst");
163 "Verify that we can actually set the attribute Mtu");
166 "Verify that we can actually set the attribute Rate");
169 "Verify that we can actually set the attribute PeakRate");
187 "There should be no packets in there");
188 queue->Enqueue(Create<TbfQueueDiscTestItem>(p1, dest));
191 "There should be one packet in there");
192 queue->Enqueue(Create<TbfQueueDiscTestItem>(p2, dest));
195 "There should be two packets in there");
196 queue->Enqueue(Create<TbfQueueDiscTestItem>(p3, dest));
199 "There should be three packets in there");
200 queue->Enqueue(Create<TbfQueueDiscTestItem>(p4, dest));
203 "There should be four packets in there");
204 queue->Enqueue(Create<TbfQueueDiscTestItem>(p5, dest));
207 "There should still be four packets in there as this enqueue cannot "
208 "happen since QueueLimit will be exceeded");
213 "The first token bucket should be full");
214 item = queue->Dequeue();
218 "There should be three packets in there");
222 "The number of tokens in the first bucket should be one pktSize lesser");
224 item = queue->Dequeue();
228 "There should be two packets in there");
231 "Was this the second packet ?");
234 "The number of tokens in the first bucket should be two pktSizes lesser");
236 item = queue->Dequeue();
240 "There should be one packet in there");
243 queue->GetFirstBucketTokens(),
245 "The number of tokens in the first bucket should be three pktSizes lesser");
247 item = queue->Dequeue();
251 "There should be zero packet in there");
254 "Was this the fourth packet ?");
256 queue->GetFirstBucketTokens(),
258 "The number of tokens in the first bucket should be four pktSizes lesser");
261 queue = CreateObject<TbfQueueDisc>();
268 uint32_t nPkt = qSize;
273 qSize = qSize * modeSize;
277 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
279 "Verify that we can actually set the attribute MaxSize");
282 "Verify that we can actually set the attribute Burst");
285 "Verify that we can actually set the attribute Mtu");
288 "Verify that we can actually set the attribute Rate");
291 "Verify that we can actually set the attribute PeakRate");
295 for (uint32_t i = 1; i <= nPkt; i++)
297 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
305 for (uint32_t i = 1; i <= nPkt; i++)
307 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
312 "No packet should be blocked");
322 queue = CreateObject<TbfQueueDisc>();
332 txDevA->SetChannel(channelA);
333 rxDevA->SetChannel(channelA);
334 txDevA->SetNode(nodesA.
Get(0));
335 rxDevA->SetNode(nodesA.
Get(1));
337 dest = txDevA->GetAddress();
341 tcA->SetRootQueueDiscOnDevice(txDevA, queue);
352 qSize = qSize * modeSize;
356 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
358 "Verify that we can actually set the attribute MaxSize");
361 "Verify that we can actually set the attribute Burst");
364 "Verify that we can actually set the attribute Mtu");
367 "Verify that we can actually set the attribute Rate");
370 "Verify that we can actually set the attribute PeakRate");
373 for (uint32_t i = 1; i <= nPkt; i++)
375 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
383 for (uint32_t i = 1; i <= nPkt; i++)
387 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
392 "10th packet should be blocked");
396 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
401 "This packet should not be blocked");
416 queue = CreateObject<TbfQueueDisc>();
426 txDevB->SetChannel(channelB);
427 rxDevB->SetChannel(channelB);
428 txDevB->SetNode(nodesB.
Get(0));
429 rxDevB->SetNode(nodesB.
Get(1));
431 dest = txDevB->GetAddress();
435 tcB->SetRootQueueDiscOnDevice(txDevB, queue);
447 qSize = qSize * modeSize;
451 queue->SetAttributeFailSafe(
"MaxSize", QueueSizeValue(
QueueSize(mode, qSize))),
453 "Verify that we can actually set the attribute MaxSize");
456 "Verify that we can actually set the attribute Burst");
459 "Verify that we can actually set the attribute Mtu");
462 "Verify that we can actually set the attribute Rate");
465 "Verify that we can actually set the attribute PeakRate");
469 for (uint32_t i = 1; i <= nPkt; i++)
471 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
488 double nextDelay = (2 * delay) + 0.02;
489 for (uint32_t i = 1; i <= nPkt; i++)
493 Simulator::Schedule(
Seconds(nextDelay),
498 "1st packet should not be blocked");
503 Simulator::Schedule(
Seconds(nextDelay),
508 "This packet should be blocked");
513 Simulator::Stop(
Seconds(0.55));
520 queue->Enqueue(Create<TbfQueueDiscTestItem>(Create<Packet>(size), dest));
526 std::string printStatement)
537 Simulator::Destroy();
Tbf Queue Disc Test Case.
void RunTbfTest(QueueSizeUnit mode)
Run TBF test function.
void DoRun() override
Implementation to actually run this TestCase.
void Enqueue(Ptr< TbfQueueDisc > queue, Address dest, uint32_t size)
Enqueue function.
void DequeueAndCheck(Ptr< TbfQueueDisc > queue, bool flag, std::string printStatement)
DequeueAndCheck function to check if a packet is blocked or not after dequeuing and verify against ex...
Tbf Queue Disc Test Item.
~TbfQueueDiscTestItem() override
TbfQueueDiscTestItem()=delete
bool Mark() override
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
TbfQueueDiscTestItem(const TbfQueueDiscTestItem &)=delete
TbfQueueDiscTestItem & operator=(const TbfQueueDiscTestItem &)=delete
void AddHeader() override
Add the header to the packet.
Tbf Queue Disc Test Suite.
a polymophic address class
Class for representing data rates.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
uint64_t GetUid() const
Returns the packet's Uid.
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Class for representing queue sizes.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
@ UNIT
This test suite implements a Unit Test.
Hold an unsigned integer type.
void SetDefault(std::string name, const AttributeValue &value)
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
QueueSizeUnit
Enumeration of the operating modes of queues.
@ BYTES
Use number of bytes for queue size.
@ PACKETS
Use number of packets for queue size.
#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.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
#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.
Time Seconds(double value)
Construct a Time in the indicated unit.
TbfQueueDiscTestSuite g_tbfQueueTestSuite
the test suite
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t pktSize
packet size used for the simulation (in bytes)