A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
fifo-queue-disc-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Universita' degli Studi di Napoli Federico II
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Stefano Avallone <stavallo@unina.it>
7 *
8 */
9
10#include "ns3/double.h"
11#include "ns3/fifo-queue-disc.h"
12#include "ns3/log.h"
13#include "ns3/object-factory.h"
14#include "ns3/packet.h"
15#include "ns3/queue.h"
16#include "ns3/simulator.h"
17#include "ns3/string.h"
18#include "ns3/test.h"
19#include "ns3/uinteger.h"
20
21#include <vector>
22
23using namespace ns3;
24
25/**
26 * @ingroup traffic-control-test
27 *
28 * @brief Fifo Queue Disc Test Item
29 */
31{
32 public:
33 /**
34 * Constructor
35 *
36 * @param p the packet
37 * @param addr the address
38 */
40 ~FifoQueueDiscTestItem() override;
41
42 // Delete default constructor, copy constructor and assignment operator to avoid misuse
46
47 void AddHeader() override;
48 bool Mark() override;
49};
50
55
59
60void
64
65bool
67{
68 return false;
69}
70
71/**
72 * @ingroup traffic-control-test
73 *
74 * @brief Fifo Queue Disc Test Case
75 */
77{
78 public:
80 void DoRun() override;
81
82 private:
83 /**
84 * Run test function
85 * @param mode the test mode
86 */
87 void RunFifoTest(QueueSizeUnit mode);
88 /**
89 * Run test function
90 * @param q the queue disc
91 * @param qSize the expected size of the queue disc
92 * @param pktSize the packet size
93 */
95};
96
98 : TestCase("Sanity check on the fifo queue disc implementation")
99{
100}
101
102void
104{
105 std::vector<uint64_t> uids;
106 Ptr<Packet> p;
108 Address dest;
109 uint32_t modeSize = (q->GetMaxSize().GetUnit() == QueueSizeUnit::PACKETS ? 1 : pktSize);
110 uint32_t numPackets = qSize / modeSize;
111
112 NS_TEST_ASSERT_MSG_EQ(q->GetCurrentSize().GetValue(), 0, "The queue disc should be empty");
113
114 // create and enqueue numPackets packets and store their UIDs; check they are all enqueued
115 for (uint32_t i = 1; i <= numPackets; i++)
116 {
118 uids.push_back(p->GetUid());
119 q->Enqueue(Create<FifoQueueDiscTestItem>(p, dest));
120 NS_TEST_ASSERT_MSG_EQ(q->GetCurrentSize().GetValue(),
121 i * modeSize,
122 "There should be " << i << " packet(s) in there");
123 }
124
125 // no room for another packet
127 false,
128 "There should be no room for another packet");
129
130 // dequeue and check packet order
131 for (uint32_t i = 1; i <= numPackets; i++)
132 {
133 item = q->Dequeue();
134 NS_TEST_ASSERT_MSG_NE(item, nullptr, "A packet should have been dequeued");
135 NS_TEST_ASSERT_MSG_EQ(q->GetCurrentSize().GetValue(),
136 (numPackets - i) * modeSize,
137 "There should be " << numPackets - i << " packet(s) in there");
138 NS_TEST_ASSERT_MSG_EQ(item->GetPacket()->GetUid(),
139 uids[i - 1],
140 "was this the right packet?");
141 }
142
143 item = q->Dequeue();
144 NS_TEST_ASSERT_MSG_EQ(item, nullptr, "There are really no packets in there");
145}
146
147void
149{
150 Ptr<FifoQueueDisc> queue;
151 uint32_t numPackets = 10;
152 uint32_t pktSize = 1000;
153 uint32_t modeSize = (mode == QueueSizeUnit::PACKETS ? 1 : pktSize);
154
155 // test 1: set the limit on the queue disc before initialization
157
158 NS_TEST_ASSERT_MSG_EQ(queue->GetNInternalQueues(),
159 0,
160 "Verify that the queue disc has no internal queue");
161
163 queue->SetAttributeFailSafe("MaxSize",
164 QueueSizeValue(QueueSize(mode, numPackets * modeSize))),
165 true,
166 "Verify that we can actually set the attribute MaxSize");
167
168 queue->Initialize();
169
170 DoRunFifoTest(queue, numPackets * modeSize, pktSize);
171
172 // test 2: set the limit on the queue disc after initialization
174
175 NS_TEST_ASSERT_MSG_EQ(queue->GetNInternalQueues(),
176 0,
177 "Verify that the queue disc has no internal queue");
178
179 queue->Initialize();
180
182 queue->SetAttributeFailSafe("MaxSize",
183 QueueSizeValue(QueueSize(mode, numPackets * modeSize))),
184 true,
185 "Verify that we can actually set the attribute MaxSize");
186
187 DoRunFifoTest(queue, numPackets * modeSize, pktSize);
188
189 // test 3: set the limit on the internal queue before initialization
191
192 NS_TEST_ASSERT_MSG_EQ(queue->GetNInternalQueues(),
193 0,
194 "Verify that the queue disc has no internal queue");
195
196 ObjectFactory factory;
197 factory.SetTypeId("ns3::DropTailQueue<QueueDiscItem>");
198 if (mode == QueueSizeUnit::PACKETS)
199 {
200 factory.Set("MaxSize", QueueSizeValue(QueueSize(QueueSizeUnit::PACKETS, numPackets)));
201 }
202 else
203 {
204 factory.Set("MaxSize",
205 QueueSizeValue(QueueSize(QueueSizeUnit::BYTES, numPackets * pktSize)));
206 }
207 queue->AddInternalQueue(factory.Create<QueueDisc::InternalQueue>());
208
209 queue->Initialize();
210
211 DoRunFifoTest(queue, numPackets * modeSize, pktSize);
212
213 // test 4: set the limit on the internal queue after initialization
215
216 NS_TEST_ASSERT_MSG_EQ(queue->GetNInternalQueues(),
217 0,
218 "Verify that the queue disc has no internal queue");
219
220 queue->Initialize();
221
222 NS_TEST_ASSERT_MSG_EQ(queue->GetNInternalQueues(),
223 1,
224 "Verify that the queue disc got an internal queue");
225
226 Ptr<QueueDisc::InternalQueue> iq = queue->GetInternalQueue(0);
227
228 if (mode == QueueSizeUnit::PACKETS)
229 {
231 iq->SetAttributeFailSafe("MaxSize",
232 QueueSizeValue(QueueSize(QueueSizeUnit::PACKETS, numPackets))),
233 true,
234 "Verify that we can actually set the attribute MaxSize on the internal queue");
235 }
236 else
237 {
239 iq->SetAttributeFailSafe(
240 "MaxSize",
241 QueueSizeValue(QueueSize(QueueSizeUnit::BYTES, numPackets * pktSize))),
242 true,
243 "Verify that we can actually set the attribute MaxSize on the internal queue");
244 }
245
246 DoRunFifoTest(queue, numPackets * modeSize, pktSize);
247}
248
249void
251{
252 RunFifoTest(QueueSizeUnit::PACKETS);
253 RunFifoTest(QueueSizeUnit::BYTES);
255}
256
257/**
258 * @ingroup traffic-control-test
259 *
260 * @brief Fifo Queue Disc Test Suite
261 */
263{
264 public:
266 : TestSuite("fifo-queue-disc", Type::UNIT)
267 {
268 AddTestCase(new FifoQueueDiscTestCase(), TestCase::Duration::QUICK);
269 }
270} g_fifoQueueTestSuite; ///< the test suite
Fifo Queue Disc Test Case.
void RunFifoTest(QueueSizeUnit mode)
Run test function.
void DoRun() override
Implementation to actually run this TestCase.
void DoRunFifoTest(Ptr< FifoQueueDisc > q, uint32_t qSize, uint32_t pktSize)
Run test function.
Fifo Queue Disc Test Item.
void AddHeader() override
Add the header to the packet.
FifoQueueDiscTestItem()=delete
FifoQueueDiscTestItem(const FifoQueueDiscTestItem &)=delete
FifoQueueDiscTestItem & operator=(const FifoQueueDiscTestItem &)=delete
bool Mark() override
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
Fifo Queue Disc Test Suite.
a polymophic address class
Definition address.h:90
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Introspection did not find any typical Config paths.
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Definition queue-item.h:122
Class for representing queue sizes.
Definition queue-size.h:85
AttributeValue implementation for QueueSize.
Definition queue-size.h:210
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition queue-size.h:33
#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.
Definition test.h:134
#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.
Definition test.h:554
FifoQueueDiscTestSuite g_fifoQueueTestSuite
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)