21#include "ns3/fifo-queue-disc.h"
23#include "ns3/packet-filter.h"
24#include "ns3/packet.h"
25#include "ns3/prio-queue-disc.h"
26#include "ns3/simulator.h"
27#include "ns3/socket.h"
28#include "ns3/string.h"
145 void DoRun()
override;
149 :
TestCase(
"Sanity check on the prio queue disc implementation")
158 std::string priomap(
"0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3");
160 std::array<std::queue<uint64_t>, 4> uids;
165 qdisc = CreateObject<PrioQueueDisc>();
168 for (uint8_t i = 0; i < 4; i++)
173 c->SetQueueDisc(child);
174 qdisc->AddQueueDiscClass(c);
180 "Verify that the queue disc has 4 child queue discs");
184 "Verify that we can actually set the attribute Priomap");
189 "Verify that we can actually get the attribute Priomap");
198 for (uint16_t i = 0; i < 4; i++)
202 "There should be no packets in the child queue disc " << i);
204 item = Create<PrioQueueDiscTestItem>(Create<Packet>(100), dest, i);
205 qdisc->Enqueue(item);
207 uids[i].push(item->GetPacket()->GetUid());
211 "There should be one packet in the child queue disc " << i);
220 qdisc->AddPacketFilter(pf1);
223 for (uint16_t i = 0; i < 4; i++)
227 "There should be one packet in the child queue disc " << i);
229 item = Create<PrioQueueDiscTestItem>(Create<Packet>(100), dest, i + 4);
230 qdisc->Enqueue(item);
232 uids[i].push(item->GetPacket()->GetUid());
236 "There should be two packets in the child queue disc " << i);
244 qdisc->AddPacketFilter(pf2);
247 for (uint16_t i = 0; i < 4; i++)
249 pf2->SetReturnValue(i);
252 "There should be two packets in the child queue disc " << i);
254 item = Create<PrioQueueDiscTestItem>(Create<Packet>(100), dest, 0);
255 qdisc->Enqueue(item);
257 uids[i].push(item->GetPacket()->GetUid());
261 "There should be three packets in the child queue disc " << i);
271 for (uint16_t i = 0; i < 4; i++)
273 pf2->SetReturnValue(4 + i);
276 "The band for priority 0 must be band 0");
279 "There should be " << i + 3 <<
" packets in the child queue disc "
280 << qdisc->GetBandForPriority(0));
282 item = Create<PrioQueueDiscTestItem>(Create<Packet>(100), dest, 1);
283 qdisc->Enqueue(item);
285 uids[0].push(item->GetPacket()->GetUid());
289 "There should be " << i + 4 <<
" packets in the child queue disc "
290 << qdisc->GetBandForPriority(0));
297 while ((item = qdisc->Dequeue()))
299 for (uint16_t i = 0; i < 4; i++)
305 "Band " << i <<
" should be empty");
309 item->GetPacket()->GetUid(),
310 "The dequeued packet is not the one we expected");
316 Simulator::Destroy();
Prio Queue Disc Test Case.
void DoRun() override
Implementation to actually run this TestCase.
Prio Queue Disc Test Packet Filter.
~PrioQueueDiscTestFilter() override
PrioQueueDiscTestFilter(bool cls)
Constructor.
bool m_cls
whether this filter is able to classify a PrioQueueDiscTestItem
int32_t DoClassify(Ptr< QueueDiscItem > item) const override
Classify a packet.
bool CheckProtocol(Ptr< QueueDiscItem > item) const override
Checks if the filter is able to classify a kind of items.
void SetReturnValue(int32_t ret)
Set the value returned by DoClassify.
int32_t m_ret
the value that DoClassify returns if m_cls is true
Prio Queue Disc Test Item.
bool Mark() override
Marks the packet as a substitute for dropping it, such as for Explicit Congestion Notification.
PrioQueueDiscTestItem(Ptr< Packet > p, const Address &addr, uint8_t priority)
Constructor.
void AddHeader() override
Add the header to the packet.
Prio Queue Disc Test Suite.
a polymophic address class
PacketFilter is the abstract base class for filters used by queue discs to classify packets.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
indicates whether the socket has a priority set.
void SetPriority(uint8_t priority)
Set the tag's priority.
Hold variables of type string.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
@ UNIT
This test suite implements a Unit Test.
Empty class, used as a default parent class for SimpleRefCount.
#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.
PrioQueueDiscTestSuite g_prioQueueTestSuite
the test suite
Every class exported by the ns3 library is enclosed in the ns3 namespace.