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"
95 void DoRun()
override;
122 :
TestCase(
"Sanity check on the TBF queue implementation")
153 qSize = qSize * modeSize;
159 "Verify that we can actually set the attribute MaxSize");
162 "Verify that we can actually set the attribute Burst");
165 "Verify that we can actually set the attribute Mtu");
168 "Verify that we can actually set the attribute Rate");
171 "Verify that we can actually set the attribute PeakRate");
189 "There should be no packets in there");
190 queue->Enqueue(Create<TbfQueueDiscTestItem>(p1, dest));
193 "There should be one packet in there");
194 queue->Enqueue(Create<TbfQueueDiscTestItem>(p2, dest));
197 "There should be two packets in there");
198 queue->Enqueue(Create<TbfQueueDiscTestItem>(p3, dest));
201 "There should be three packets in there");
202 queue->Enqueue(Create<TbfQueueDiscTestItem>(p4, dest));
205 "There should be four packets in there");
206 queue->Enqueue(Create<TbfQueueDiscTestItem>(p5, dest));
209 "There should still be four packets in there as this enqueue cannot "
210 "happen since QueueLimit will be exceeded");
215 "The first token bucket should be full");
216 item = queue->Dequeue();
220 "There should be three packets in there");
224 "The number of tokens in the first bucket should be one pktSize lesser");
226 item = queue->Dequeue();
230 "There should be two packets in there");
233 "Was this the second packet ?");
236 "The number of tokens in the first bucket should be two pktSizes lesser");
238 item = queue->Dequeue();
242 "There should be one packet in there");
245 queue->GetFirstBucketTokens(),
247 "The number of tokens in the first bucket should be three pktSizes lesser");
249 item = queue->Dequeue();
253 "There should be zero packet in there");
256 "Was this the fourth packet ?");
258 queue->GetFirstBucketTokens(),
260 "The number of tokens in the first bucket should be four pktSizes lesser");
263 queue = CreateObject<TbfQueueDisc>();
275 qSize = qSize * modeSize;
281 "Verify that we can actually set the attribute MaxSize");
284 "Verify that we can actually set the attribute Burst");
287 "Verify that we can actually set the attribute Mtu");
290 "Verify that we can actually set the attribute Rate");
293 "Verify that we can actually set the attribute PeakRate");
297 for (
uint32_t i = 1; i <= nPkt; i++)
299 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
307 for (
uint32_t i = 1; i <= nPkt; i++)
309 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
314 "No packet should be blocked");
324 queue = CreateObject<TbfQueueDisc>();
334 txDevA->SetChannel(channelA);
335 rxDevA->SetChannel(channelA);
336 txDevA->SetNode(nodesA.
Get(0));
337 rxDevA->SetNode(nodesA.
Get(1));
339 dest = txDevA->GetAddress();
343 tcA->SetRootQueueDiscOnDevice(txDevA, queue);
354 qSize = qSize * modeSize;
360 "Verify that we can actually set the attribute MaxSize");
363 "Verify that we can actually set the attribute Burst");
366 "Verify that we can actually set the attribute Mtu");
369 "Verify that we can actually set the attribute Rate");
372 "Verify that we can actually set the attribute PeakRate");
375 for (
uint32_t i = 1; i <= nPkt; i++)
377 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
385 for (
uint32_t i = 1; i <= nPkt; i++)
389 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
394 "10th packet should be blocked");
398 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
403 "This packet should not be blocked");
418 queue = CreateObject<TbfQueueDisc>();
428 txDevB->SetChannel(channelB);
429 rxDevB->SetChannel(channelB);
430 txDevB->SetNode(nodesB.
Get(0));
431 rxDevB->SetNode(nodesB.
Get(1));
433 dest = txDevB->GetAddress();
437 tcB->SetRootQueueDiscOnDevice(txDevB, queue);
449 qSize = qSize * modeSize;
455 "Verify that we can actually set the attribute MaxSize");
458 "Verify that we can actually set the attribute Burst");
461 "Verify that we can actually set the attribute Mtu");
464 "Verify that we can actually set the attribute Rate");
467 "Verify that we can actually set the attribute PeakRate");
471 for (
uint32_t i = 1; i <= nPkt; i++)
473 Simulator::Schedule(
Time(
Seconds((i + 1) * delay)),
490 double nextDelay = (2 * delay) + 0.02;
491 for (
uint32_t i = 1; i <= nPkt; i++)
495 Simulator::Schedule(
Seconds(nextDelay),
500 "1st packet should not be blocked");
505 Simulator::Schedule(
Seconds(nextDelay),
510 "This packet should be blocked");
515 Simulator::Stop(
Seconds(0.55));
522 queue->Enqueue(Create<TbfQueueDiscTestItem>(Create<Packet>(size), dest));
528 std::string printStatement)
539 Simulator::Destroy();
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.
uint64_t GetUid() 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.
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.
#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.
TbfQueueDiscTestSuite g_tbfQueueTestSuite
the test suite
Time Seconds(double value)
Construct a Time in the indicated unit.
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t pktSize
packet size used for the simulation (in bytes)