21 #include "ns3/simulator.h"
22 #include "ns3/pfifo-fast-queue-disc.h"
23 #include "ns3/drop-tail-queue.h"
24 #include "ns3/ipv4-queue-disc-item.h"
25 #include "ns3/ipv6-queue-disc-item.h"
27 #include "ns3/string.h"
28 #include "ns3/pointer.h"
29 #include "ns3/object-factory.h"
30 #include "ns3/socket.h"
46 virtual void DoRun (
void);
58 :
TestCase (
"Test TOS-based prioritization")
75 priorityTag.
SetPriority (Socket::IpTos2Priority (tos));
79 queue->Enqueue (item);
80 NS_TEST_ASSERT_MSG_EQ (queue->GetInternalQueue (band)->GetNPackets (), 1,
"enqueued to unexpected band");
89 for (uint16_t i = 0; i < 3; i++)
92 bool ok = queue->SetAttributeFailSafe (
"MaxSize",
StringValue (
"1000p"));
94 queueDisc->AddInternalQueue (queue);
117 Simulator::Destroy ();
132 virtual void DoRun (
void);
144 :
TestCase (
"Test DSCP-based prioritization")
165 queue->Enqueue (item);
166 NS_TEST_ASSERT_MSG_EQ (queue->GetInternalQueue (band)->GetNPackets (), 1,
"enqueued to unexpected band");
175 for (uint16_t i = 0; i < 3; i++)
178 bool ok = queue->SetAttributeFailSafe (
"MaxSize",
StringValue (
"1000p"));
180 queueDisc->AddInternalQueue (queue);
208 Simulator::Destroy ();
223 virtual void DoRun (
void);
255 queue->Enqueue (item);
265 queueDisc->AddInternalQueue (band0);
266 queueDisc->AddInternalQueue (band1);
267 queueDisc->AddInternalQueue (band2);
270 AddPacket (queueDisc, Ipv4Header::DSCP_AF42);
271 AddPacket (queueDisc, Ipv4Header::DSCP_AF42);
272 AddPacket (queueDisc, Ipv4Header::DSCP_AF13);
273 AddPacket (queueDisc, Ipv4Header::DSCP_AF13);
274 AddPacket (queueDisc, Ipv4Header::DSCP_AF11);
275 AddPacket (queueDisc, Ipv4Header::DSCP_AF11);
276 NS_TEST_ASSERT_MSG_EQ (queueDisc->GetInternalQueue (0)->GetNPackets (), 2,
"unexpected queue depth");
277 NS_TEST_ASSERT_MSG_EQ (queueDisc->GetInternalQueue (1)->GetNPackets (), 2,
"unexpected queue depth");
278 NS_TEST_ASSERT_MSG_EQ (queueDisc->GetInternalQueue (2)->GetNPackets (), 2,
"unexpected queue depth");
281 AddPacket (queueDisc, Ipv4Header::DSCP_AF42);
282 AddPacket (queueDisc, Ipv4Header::DSCP_AF13);
283 AddPacket (queueDisc, Ipv4Header::DSCP_AF11);
285 NS_TEST_ASSERT_MSG_EQ (queueDisc->GetInternalQueue (0)->GetNPackets (), 2,
"unexpected queue depth");
286 NS_TEST_ASSERT_MSG_EQ (queueDisc->GetInternalQueue (1)->GetNPackets (), 2,
"unexpected queue depth");
287 NS_TEST_ASSERT_MSG_EQ (queueDisc->GetInternalQueue (2)->GetNPackets (), 2,
"unexpected queue depth");
289 Simulator::Destroy ();
305 virtual void DoRun (
void);
309 :
TestCase (
"Test queue with no priority tag")
322 for (uint16_t i = 0; i < 3; i++)
325 bool ok = queue->SetAttributeFailSafe (
"MaxSize",
StringValue (
"1000p"));
327 queueDisc->AddInternalQueue (queue);
329 NS_TEST_ASSERT_MSG_EQ (queueDisc->GetInternalQueue (1)->GetNPackets (), 0,
"unexpected queue depth");
331 p = Create<Packet> ();
335 item = Create<Ipv6QueueDiscItem> (p, dest, 0, ipv6Header);
336 queueDisc->Enqueue (item);
337 NS_TEST_ASSERT_MSG_EQ (queueDisc->GetInternalQueue (1)->GetNPackets (), 1,
"unexpected queue depth");
338 p = Create<Packet> (
reinterpret_cast<const uint8_t*
> (
"hello, world"), 12);
339 item = Create<Ipv6QueueDiscItem> (p, dest, 0, ipv6Header);
340 queueDisc->Enqueue (item);
341 NS_TEST_ASSERT_MSG_EQ (queueDisc->GetInternalQueue (1)->GetNPackets (), 2,
"unexpected queue depth");
342 p = Create<Packet> (100);
343 uint8_t *buf =
new uint8_t[100];
345 for (uint32_t i = 0; i < 100; i++)
350 item = Create<Ipv6QueueDiscItem> (p, dest, 0, ipv6Header);
351 queueDisc->Enqueue (item);
352 NS_TEST_ASSERT_MSG_EQ (queueDisc->GetInternalQueue (1)->GetNPackets (), 3,
"unexpected queue depth");
354 Simulator::Destroy ();
369 :
TestSuite (
"pfifo-fast-queue-disc", UNIT)
This class tests that each possible DSCP is enqueued in the right band.
PfifoFastQueueDiscDscpPrioritization()
void TestDscpValue(Ptr< PfifoFastQueueDisc > queue, Ipv4Header::DscpType dscp, uint32_t band)
Enqueue a packet and checks that it's added to the proper band.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~PfifoFastQueueDiscDscpPrioritization()
This class tests that packets without a priority tag are handled by placing them into band 1.
virtual void DoRun(void)
Implementation to actually run this TestCase.
PfifoFastQueueDiscNoPriority()
virtual ~PfifoFastQueueDiscNoPriority()
This class tests that each band is txqueuelen deep.
virtual ~PfifoFastQueueDiscOverflow()
PfifoFastQueueDiscOverflow()
virtual void DoRun(void)
Implementation to actually run this TestCase.
void AddPacket(Ptr< PfifoFastQueueDisc > queue, Ipv4Header::DscpType dscp)
Enqueue a packet.
PfifoFast queue disc test suite.
PfifoFastQueueDiscTestSuite()
This class tests that each possible TOS is enqueued in the right band.
PfifoFastQueueDiscTosPrioritization()
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~PfifoFastQueueDiscTosPrioritization()
void TestTosValue(Ptr< PfifoFastQueueDisc > queue, uint8_t tos, uint32_t band)
Enqueue a packet and checks that it's added to the proper band.
a polymophic address class
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Smart pointer class similar to boost::intrusive_ptr.
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.
#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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static PfifoFastQueueDiscTestSuite g_pfifoFastQueueTestSuite
Do not forget to allocate an instance of this TestSuite.