11#include "ns3/config.h"
12#include "ns3/double.h"
14#include "ns3/node-container.h"
15#include "ns3/packet.h"
16#include "ns3/simple-channel.h"
17#include "ns3/simple-net-device.h"
18#include "ns3/simulator.h"
19#include "ns3/string.h"
20#include "ns3/tbf-queue-disc.h"
22#include "ns3/traffic-control-layer.h"
23#include "ns3/uinteger.h"
82 void DoRun()
override;
109 :
TestCase(
"Sanity check on the TBF queue implementation")
140 qSize = qSize * modeSize;
146 "Verify that we can actually set the attribute MaxSize");
149 "Verify that we can actually set the attribute Burst");
152 "Verify that we can actually set the attribute Mtu");
155 "Verify that we can actually set the attribute Rate");
158 "Verify that we can actually set the attribute PeakRate");
176 "There should be no packets in there");
180 "There should be one packet in there");
184 "There should be two packets in there");
188 "There should be three packets in there");
192 "There should be four packets in there");
196 "There should still be four packets in there as this enqueue cannot "
197 "happen since QueueLimit will be exceeded");
202 "The first token bucket should be full");
203 item = queue->Dequeue();
207 "There should be three packets in there");
211 "The number of tokens in the first bucket should be one pktSize lesser");
213 item = queue->Dequeue();
217 "There should be two packets in there");
220 "Was this the second packet ?");
223 "The number of tokens in the first bucket should be two pktSizes lesser");
225 item = queue->Dequeue();
229 "There should be one packet in there");
232 queue->GetFirstBucketTokens(),
234 "The number of tokens in the first bucket should be three pktSizes lesser");
236 item = queue->Dequeue();
240 "There should be zero packet in there");
243 "Was this the fourth packet ?");
245 queue->GetFirstBucketTokens(),
247 "The number of tokens in the first bucket should be four pktSizes lesser");
262 qSize = qSize * modeSize;
268 "Verify that we can actually set the attribute MaxSize");
271 "Verify that we can actually set the attribute Burst");
274 "Verify that we can actually set the attribute Mtu");
277 "Verify that we can actually set the attribute Rate");
280 "Verify that we can actually set the attribute PeakRate");
284 for (
uint32_t i = 1; i <= nPkt; i++)
294 for (
uint32_t i = 1; i <= nPkt; i++)
301 "No packet should be blocked");
321 txDevA->SetChannel(channelA);
322 rxDevA->SetChannel(channelA);
323 txDevA->SetNode(nodesA.
Get(0));
324 rxDevA->SetNode(nodesA.
Get(1));
326 dest = txDevA->GetAddress();
330 tcA->SetRootQueueDiscOnDevice(txDevA, queue);
341 qSize = qSize * modeSize;
347 "Verify that we can actually set the attribute MaxSize");
350 "Verify that we can actually set the attribute Burst");
353 "Verify that we can actually set the attribute Mtu");
356 "Verify that we can actually set the attribute Rate");
359 "Verify that we can actually set the attribute PeakRate");
362 for (
uint32_t i = 1; i <= nPkt; i++)
372 for (
uint32_t i = 1; i <= nPkt; i++)
381 "10th packet should be blocked");
390 "This packet should not be blocked");
415 txDevB->SetChannel(channelB);
416 rxDevB->SetChannel(channelB);
417 txDevB->SetNode(nodesB.
Get(0));
418 rxDevB->SetNode(nodesB.
Get(1));
420 dest = txDevB->GetAddress();
424 tcB->SetRootQueueDiscOnDevice(txDevB, queue);
436 qSize = qSize * modeSize;
442 "Verify that we can actually set the attribute MaxSize");
445 "Verify that we can actually set the attribute Burst");
448 "Verify that we can actually set the attribute Mtu");
451 "Verify that we can actually set the attribute Rate");
454 "Verify that we can actually set the attribute PeakRate");
458 for (
uint32_t i = 1; i <= nPkt; i++)
477 double nextDelay = (2 * delay) + 0.02;
478 for (
uint32_t i = 1; i <= nPkt; i++)
487 "1st packet should not be blocked");
497 "This packet should be blocked");
515 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...
TbfQueueDiscTestItem(Ptr< Packet > p, const Address &addr)
Constructor.
~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
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.
Smart pointer class similar to boost::intrusive_ptr.
QueueDiscItem(Ptr< Packet > p, const Address &addr, uint16_t protocol)
Create a queue disc item.
Class for representing queue sizes.
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, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
TestCase(const TestCase &)=delete
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
static constexpr auto UNIT
Hold an unsigned integer type.
void SetDefault(std::string name, const AttributeValue &value)
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t pktSize
packet size used for the simulation (in bytes)