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"
55 virtual void AddHeader (
void);
56 virtual bool Mark (
void);
103 virtual void DoRun (
void);
127 :
TestCase (
"Sanity check on the TBF queue implementation")
136 uint32_t modeSize = 1;
138 uint32_t burst = 6000;
158 qSize = qSize * modeSize;
162 true,
"Verify that we can actually set the attribute MaxSize");
164 "Verify that we can actually set the attribute Burst");
166 "Verify that we can actually set the attribute Mtu");
168 "Verify that we can actually set the attribute Rate");
170 "Verify that we can actually set the attribute PeakRate");
181 queue->Initialize ();
182 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 0 * modeSize,
"There should be no packets in there");
183 queue->Enqueue (Create<TbfQueueDiscTestItem> (p1, dest));
184 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 1 * modeSize,
"There should be one packet in there");
185 queue->Enqueue (Create<TbfQueueDiscTestItem> (p2, dest));
186 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 2 * modeSize,
"There should be two packets in there");
187 queue->Enqueue (Create<TbfQueueDiscTestItem> (p3, dest));
188 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 3 * modeSize,
"There should be three packets in there");
189 queue->Enqueue (Create<TbfQueueDiscTestItem> (p4, dest));
190 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 4 * modeSize,
"There should be four packets in there");
191 queue->Enqueue (Create<TbfQueueDiscTestItem> (p5, dest));
193 "There should still be four packets in there as this enqueue cannot happen since QueueLimit will be exceeded");
196 NS_TEST_EXPECT_MSG_EQ (queue->GetFirstBucketTokens (), burst,
"The first token bucket should be full");
197 item = queue->Dequeue ();
199 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 3 * modeSize,
"There should be three packets in there");
202 "The number of tokens in the first bucket should be one pktSize lesser");
204 item = queue->Dequeue ();
206 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 2 * modeSize,
"There should be two packets in there");
209 "The number of tokens in the first bucket should be two pktSizes lesser");
211 item = queue->Dequeue ();
213 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 1 * modeSize,
"There should be one packet in there");
216 "The number of tokens in the first bucket should be three pktSizes lesser");
218 item = queue->Dequeue ();
220 NS_TEST_EXPECT_MSG_EQ (queue->GetCurrentSize ().GetValue (), 0 * modeSize,
"There should be zero packet in there");
223 "The number of tokens in the first bucket should be four pktSizes lesser");
226 queue = CreateObject<TbfQueueDisc> ();
233 uint32_t nPkt = qSize;
238 qSize = qSize * modeSize;
242 true,
"Verify that we can actually set the attribute MaxSize");
244 "Verify that we can actually set the attribute Burst");
246 "Verify that we can actually set the attribute Mtu");
248 "Verify that we can actually set the attribute Rate");
250 "Verify that we can actually set the attribute PeakRate");
252 queue->Initialize ();
254 for (uint32_t i = 1; i <= nPkt; i++)
259 for (uint32_t i = 1; i <= nPkt; i++)
262 queue,
true,
"No packet should be blocked");
271 queue = CreateObject<TbfQueueDisc> ();
281 txDevA->SetChannel (channelA);
282 rxDevA->SetChannel (channelA);
283 txDevA->SetNode (nodesA.
Get (0));
284 rxDevA->SetNode (nodesA.
Get (1));
286 dest = txDevA->GetAddress ();
290 tcA->SetRootQueueDiscOnDevice (txDevA, queue);
301 qSize = qSize * modeSize;
305 true,
"Verify that we can actually set the attribute MaxSize");
307 "Verify that we can actually set the attribute Burst");
309 "Verify that we can actually set the attribute Mtu");
311 "Verify that we can actually set the attribute Rate");
313 "Verify that we can actually set the attribute PeakRate");
316 for (uint32_t i = 1; i <= nPkt; i++)
321 for (uint32_t i = 1; i <= nPkt; i++)
326 queue,
false,
"10th packet should be blocked");
331 queue,
true,
"This packet should not be blocked");
334 Simulator::Stop (
Seconds (1.3));
344 queue = CreateObject<TbfQueueDisc> ();
354 txDevB->SetChannel (channelB);
355 rxDevB->SetChannel (channelB);
356 txDevB->SetNode (nodesB.
Get (0));
357 rxDevB->SetNode (nodesB.
Get (1));
359 dest = txDevB->GetAddress ();
363 tcB->SetRootQueueDiscOnDevice (txDevB, queue);
374 qSize = qSize * modeSize;
378 true,
"Verify that we can actually set the attribute MaxSize");
380 "Verify that we can actually set the attribute Burst");
382 "Verify that we can actually set the attribute Mtu");
384 "Verify that we can actually set the attribute Rate");
386 "Verify that we can actually set the attribute PeakRate");
388 queue->Initialize ();
390 for (uint32_t i = 1; i <= nPkt; i++)
395 for (uint32_t i = 1; i <= nPkt; i++)
400 queue,
true,
"1st packet should not be blocked");
405 queue,
false,
"This packet should be blocked");
408 Simulator::Stop (
Seconds (0.55));
416 queue->Enqueue (Create<TbfQueueDiscTestItem> (Create<Packet> (size), dest));
431 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.
virtual void AddHeader(void)
Add the header to the packet.
virtual ~TbfQueueDiscTestItem()
TbfQueueDiscTestItem(const TbfQueueDiscTestItem &)
Copy constructor Disable default implementation to avoid misuse.
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.
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_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)