24#include "ns3/tbf-queue-disc.h"
25#include "ns3/packet.h"
26#include "ns3/uinteger.h"
27#include "ns3/string.h"
28#include "ns3/double.h"
30#include "ns3/simulator.h"
31#include "ns3/node-container.h"
32#include "ns3/simple-net-device.h"
33#include "ns3/simple-channel.h"
34#include "ns3/traffic-control-layer.h"
35#include "ns3/config.h"
62 virtual bool Mark (
void);
95 virtual void DoRun (
void);
119 :
TestCase (
"Sanity check on the TBF queue implementation")
150 qSize = qSize * modeSize;
154 true,
"Verify that we can actually set the attribute MaxSize");
156 "Verify that we can actually set the attribute Burst");
158 "Verify that we can actually set the attribute Mtu");
160 "Verify that we can actually set the attribute Rate");
162 "Verify that we can actually set the attribute PeakRate");
173 queue->Initialize ();
174 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 0 * modeSize,
"There should be no packets in there");
175 queue->Enqueue (Create<TbfQueueDiscTestItem> (p1, dest));
176 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 1 * modeSize,
"There should be one packet in there");
177 queue->Enqueue (Create<TbfQueueDiscTestItem> (p2, dest));
178 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 2 * modeSize,
"There should be two packets in there");
179 queue->Enqueue (Create<TbfQueueDiscTestItem> (p3, dest));
180 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 3 * modeSize,
"There should be three packets in there");
181 queue->Enqueue (Create<TbfQueueDiscTestItem> (p4, dest));
182 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 4 * modeSize,
"There should be four packets in there");
183 queue->Enqueue (Create<TbfQueueDiscTestItem> (p5, dest));
185 "There should still be four packets in there as this enqueue cannot happen since QueueLimit will be exceeded");
188 NS_TEST_ASSERT_MSG_EQ (queue->GetFirstBucketTokens (), burst,
"The first token bucket should be full");
189 item = queue->Dequeue ();
191 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 3 * modeSize,
"There should be three packets in there");
194 "The number of tokens in the first bucket should be one pktSize lesser");
196 item = queue->Dequeue ();
198 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 2 * modeSize,
"There should be two packets in there");
201 "The number of tokens in the first bucket should be two pktSizes lesser");
203 item = queue->Dequeue ();
205 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 1 * modeSize,
"There should be one packet in there");
208 "The number of tokens in the first bucket should be three pktSizes lesser");
210 item = queue->Dequeue ();
212 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 0 * modeSize,
"There should be zero packet in there");
215 "The number of tokens in the first bucket should be four pktSizes lesser");
218 queue = CreateObject<TbfQueueDisc> ();
230 qSize = qSize * modeSize;
234 true,
"Verify that we can actually set the attribute MaxSize");
236 "Verify that we can actually set the attribute Burst");
238 "Verify that we can actually set the attribute Mtu");
240 "Verify that we can actually set the attribute Rate");
242 "Verify that we can actually set the attribute PeakRate");
244 queue->Initialize ();
246 for (
uint32_t i = 1; i <= nPkt; i++)
251 for (
uint32_t i = 1; i <= nPkt; i++)
254 queue,
true,
"No packet should be blocked");
263 queue = CreateObject<TbfQueueDisc> ();
273 txDevA->SetChannel (channelA);
274 rxDevA->SetChannel (channelA);
275 txDevA->SetNode (nodesA.
Get (0));
276 rxDevA->SetNode (nodesA.
Get (1));
278 dest = txDevA->GetAddress ();
282 tcA->SetRootQueueDiscOnDevice (txDevA, queue);
293 qSize = qSize * modeSize;
297 true,
"Verify that we can actually set the attribute MaxSize");
299 "Verify that we can actually set the attribute Burst");
301 "Verify that we can actually set the attribute Mtu");
303 "Verify that we can actually set the attribute Rate");
305 "Verify that we can actually set the attribute PeakRate");
308 for (
uint32_t i = 1; i <= nPkt; i++)
313 for (
uint32_t i = 1; i <= nPkt; i++)
318 queue,
false,
"10th packet should be blocked");
323 queue,
true,
"This packet should not be blocked");
326 Simulator::Stop (
Seconds (1.3));
336 queue = CreateObject<TbfQueueDisc> ();
346 txDevB->SetChannel (channelB);
347 rxDevB->SetChannel (channelB);
348 txDevB->SetNode (nodesB.
Get (0));
349 rxDevB->SetNode (nodesB.
Get (1));
351 dest = txDevB->GetAddress ();
355 tcB->SetRootQueueDiscOnDevice (txDevB, queue);
367 qSize = qSize * modeSize;
371 true,
"Verify that we can actually set the attribute MaxSize");
373 "Verify that we can actually set the attribute Burst");
375 "Verify that we can actually set the attribute Mtu");
377 "Verify that we can actually set the attribute Rate");
379 "Verify that we can actually set the attribute PeakRate");
381 queue->Initialize ();
383 for (
uint32_t i = 1; i <= nPkt; i++)
395 double nextDelay = (2 * delay) + 0.02;
396 for (
uint32_t i = 1; i <= nPkt; i++)
401 queue,
true,
"1st packet should not be blocked");
407 queue,
false,
"This packet should be blocked");
411 Simulator::Stop (
Seconds (0.55));
419 queue->Enqueue (Create<TbfQueueDiscTestItem> (Create<Packet> (size), dest));
434 Simulator::Destroy ();
Tbf Queue Disc Test Case.
void RunTbfTest(QueueSizeUnit mode)
Run TBF test function.
virtual void DoRun(void)
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()=delete
virtual bool Mark(void)
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
TbfQueueDiscTestItem(const TbfQueueDiscTestItem &)=delete
virtual void AddHeader(void)
Add the header to the packet.
virtual ~TbfQueueDiscTestItem()
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.
uint64_t GetUid(void) 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.
AttributeValue implementation for QueueSize.
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)
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.
TbfQueueDiscTestSuite g_tbfQueueTestSuite
the test suite
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t pktSize
packet size used for the simulation (in bytes)