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"
93 void DoRun()
override;
120 :
TestCase(
"Sanity check on the TBF queue implementation")
148 if (mode == QueueSizeUnit::BYTES)
151 qSize = qSize * modeSize;
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>();
270 if (mode == QueueSizeUnit::BYTES)
273 qSize = qSize * modeSize;
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++)
305 for (
uint32_t i = 1; i <= nPkt; i++)
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);
349 if (mode == QueueSizeUnit::BYTES)
352 qSize = qSize * modeSize;
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++)
383 for (
uint32_t i = 1; i <= nPkt; i++)
392 "10th packet should be blocked");
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);
444 if (mode == QueueSizeUnit::BYTES)
447 qSize = qSize * modeSize;
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++)
488 double nextDelay = (2 * delay) + 0.02;
489 for (
uint32_t i = 1; i <= nPkt; i++)
498 "1st packet should not be blocked");
508 "This packet should be blocked");
520 queue->Enqueue(Create<TbfQueueDiscTestItem>(Create<Packet>(size), dest));
526 std::string printStatement)
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
void AddHeader() override
Add the header to the packet.
TbfQueueDiscTestItem & operator=(const TbfQueueDiscTestItem &)=delete
Tbf Queue Disc Test Suite.
a polymophic address class
Class for representing data rates.
AttributeValue implementation for DataRate.
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.
Smart pointer class similar to boost::intrusive_ptr.
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Class for representing queue sizes.
AttributeValue implementation for QueueSize.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
@ UNIT
This test suite implements a Unit Test.
Simulation virtual time values and global simulation resolution.
Hold an unsigned integer type.
void SetDefault(std::string name, const AttributeValue &value)
QueueSizeUnit
Enumeration of the operating modes of queues.
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t pktSize
packet size used for the simulation (in bytes)