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"
52 void AddHeader()
override;
142 void DoRun()
override;
146 :
TestCase(
"Sanity check on the prio queue disc implementation")
155 std::string priomap(
"0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3");
157 std::array<std::queue<uint64_t>, 4> uids;
162 qdisc = CreateObject<PrioQueueDisc>();
165 for (uint8_t i = 0; i < 4; i++)
170 c->SetQueueDisc(child);
171 qdisc->AddQueueDiscClass(c);
177 "Verify that the queue disc has 4 child queue discs");
181 "Verify that we can actually set the attribute Priomap");
186 "Verify that we can actually get the attribute Priomap");
195 for (uint16_t i = 0; i < 4; i++)
199 "There should be no packets in the child queue disc " << i);
201 item = Create<PrioQueueDiscTestItem>(Create<Packet>(100), dest, i);
202 qdisc->Enqueue(item);
204 uids[i].push(item->GetPacket()->GetUid());
208 "There should be one packet in the child queue disc " << i);
217 qdisc->AddPacketFilter(pf1);
220 for (uint16_t i = 0; i < 4; i++)
224 "There should be one packet in the child queue disc " << i);
226 item = Create<PrioQueueDiscTestItem>(Create<Packet>(100), dest, i + 4);
227 qdisc->Enqueue(item);
229 uids[i].push(item->GetPacket()->GetUid());
233 "There should be two packets in the child queue disc " << i);
241 qdisc->AddPacketFilter(pf2);
244 for (uint16_t i = 0; i < 4; i++)
246 pf2->SetReturnValue(i);
249 "There should be two packets in the child queue disc " << i);
251 item = Create<PrioQueueDiscTestItem>(Create<Packet>(100), dest, 0);
252 qdisc->Enqueue(item);
254 uids[i].push(item->GetPacket()->GetUid());
258 "There should be three packets in the child queue disc " << i);
268 for (uint16_t i = 0; i < 4; i++)
270 pf2->SetReturnValue(4 + i);
273 "The band for priority 0 must be band 0");
276 "There should be " << i + 3 <<
" packets in the child queue disc "
277 << qdisc->GetBandForPriority(0));
279 item = Create<PrioQueueDiscTestItem>(Create<Packet>(100), dest, 1);
280 qdisc->Enqueue(item);
282 uids[0].push(item->GetPacket()->GetUid());
286 "There should be " << i + 4 <<
" packets in the child queue disc "
287 << qdisc->GetBandForPriority(0));
294 while ((item = qdisc->Dequeue()))
296 for (uint16_t i = 0; i < 4; i++)
302 "Band " << i <<
" should be empty");
306 item->GetPacket()->GetUid(),
307 "The dequeued packet is not the one we expected");
313 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.
#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.