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"
60 virtual void AddHeader (
void);
61 virtual bool Mark (
void);
97 virtual void DoRun (
void);
121 :
TestCase (
"Sanity check on the TBF queue implementation")
130 uint32_t modeSize = 1;
132 uint32_t burst = 6000;
152 qSize = qSize * modeSize;
156 true,
"Verify that we can actually set the attribute MaxSize");
158 "Verify that we can actually set the attribute Burst");
160 "Verify that we can actually set the attribute Mtu");
162 "Verify that we can actually set the attribute Rate");
164 "Verify that we can actually set the attribute PeakRate");
175 queue->Initialize ();
176 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 0 * modeSize,
"There should be no packets in there");
177 queue->Enqueue (Create<TbfQueueDiscTestItem> (p1, dest));
178 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 1 * modeSize,
"There should be one packet in there");
179 queue->Enqueue (Create<TbfQueueDiscTestItem> (p2, dest));
180 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 2 * modeSize,
"There should be two packets in there");
181 queue->Enqueue (Create<TbfQueueDiscTestItem> (p3, dest));
182 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 3 * modeSize,
"There should be three packets in there");
183 queue->Enqueue (Create<TbfQueueDiscTestItem> (p4, dest));
184 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 4 * modeSize,
"There should be four packets in there");
185 queue->Enqueue (Create<TbfQueueDiscTestItem> (p5, dest));
187 "There should still be four packets in there as this enqueue cannot happen since QueueLimit will be exceeded");
190 NS_TEST_ASSERT_MSG_EQ (queue->GetFirstBucketTokens (), burst,
"The first token bucket should be full");
191 item = queue->Dequeue ();
193 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 3 * modeSize,
"There should be three packets in there");
196 "The number of tokens in the first bucket should be one pktSize lesser");
198 item = queue->Dequeue ();
200 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 2 * modeSize,
"There should be two packets in there");
203 "The number of tokens in the first bucket should be two pktSizes lesser");
205 item = queue->Dequeue ();
207 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 1 * modeSize,
"There should be one packet in there");
210 "The number of tokens in the first bucket should be three pktSizes lesser");
212 item = queue->Dequeue ();
214 NS_TEST_ASSERT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 0 * modeSize,
"There should be zero packet in there");
217 "The number of tokens in the first bucket should be four pktSizes lesser");
220 queue = CreateObject<TbfQueueDisc> ();
227 uint32_t nPkt = qSize;
232 qSize = qSize * modeSize;
236 true,
"Verify that we can actually set the attribute MaxSize");
238 "Verify that we can actually set the attribute Burst");
240 "Verify that we can actually set the attribute Mtu");
242 "Verify that we can actually set the attribute Rate");
244 "Verify that we can actually set the attribute PeakRate");
246 queue->Initialize ();
248 for (uint32_t i = 1; i <= nPkt; i++)
253 for (uint32_t i = 1; i <= nPkt; i++)
256 queue,
true,
"No packet should be blocked");
265 queue = CreateObject<TbfQueueDisc> ();
275 txDevA->SetChannel (channelA);
276 rxDevA->SetChannel (channelA);
277 txDevA->SetNode (nodesA.
Get (0));
278 rxDevA->SetNode (nodesA.
Get (1));
280 dest = txDevA->GetAddress ();
284 tcA->SetRootQueueDiscOnDevice (txDevA, queue);
295 qSize = qSize * modeSize;
299 true,
"Verify that we can actually set the attribute MaxSize");
301 "Verify that we can actually set the attribute Burst");
303 "Verify that we can actually set the attribute Mtu");
305 "Verify that we can actually set the attribute Rate");
307 "Verify that we can actually set the attribute PeakRate");
310 for (uint32_t i = 1; i <= nPkt; i++)
315 for (uint32_t i = 1; i <= nPkt; i++)
320 queue,
false,
"10th packet should be blocked");
325 queue,
true,
"This packet should not be blocked");
328 Simulator::Stop (
Seconds (1.3));
338 queue = CreateObject<TbfQueueDisc> ();
348 txDevB->SetChannel (channelB);
349 rxDevB->SetChannel (channelB);
350 txDevB->SetNode (nodesB.
Get (0));
351 rxDevB->SetNode (nodesB.
Get (1));
353 dest = txDevB->GetAddress ();
357 tcB->SetRootQueueDiscOnDevice (txDevB, queue);
369 qSize = qSize * modeSize;
373 true,
"Verify that we can actually set the attribute MaxSize");
375 "Verify that we can actually set the attribute Burst");
377 "Verify that we can actually set the attribute Mtu");
379 "Verify that we can actually set the attribute Rate");
381 "Verify that we can actually set the attribute PeakRate");
383 queue->Initialize ();
385 for (uint32_t i = 1; i <= nPkt; i++)
397 double nextDelay = (2 * delay) + 0.02;
398 for (uint32_t i = 1; i <= nPkt; i++)
403 queue,
true,
"1st packet should not be blocked");
409 queue,
false,
"This packet should be blocked");
413 Simulator::Stop (
Seconds (0.55));
421 queue->Enqueue (Create<TbfQueueDiscTestItem> (Create<Packet> (size), dest));
436 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.
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()
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)