Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
187d091
Added Traffic Control Layer
natale-p Oct 7, 2015
eb9a024
Internet depends on traffic-control
natale-p Oct 7, 2015
262931f
Made public ProtocolHandlerEntry struct in node.h
natale-p Oct 7, 2015
80baa0f
Aggregate TrafficControlLayer on any Internet-enabled node
natale-p Oct 7, 2015
9285b11
Aggregate TCLayer by default on tests
natale-p Oct 7, 2015
cbafa49
Register callbacks on TCLayer and NetDevices, RX side
natale-p Oct 7, 2015
11f20e7
Use traffic-control to send packets
natale-p Oct 7, 2015
0c814e4
Initial support for multiple transmission queues inside NetDevices
stavallo Nov 19, 2015
ef2c685
WifiNetDevices can return the number of transmission queues based on …
stavallo Nov 19, 2015
bb27480
Flow control Part I: NetDeviceQueues can be started, stopped and woken
stavallo Oct 20, 2015
610f9c7
PointToPointNetDevice: Add support for flow control
stavallo Nov 12, 2015
251787d
NetDevices return the index of the transmission queue they select for…
stavallo Nov 20, 2015
bd130e8
Make Queue store QueueItem objects
stavallo Jan 5, 2016
2bf15fb
Add the QueueDisc base class
stavallo Oct 23, 2015
6e6ba99
The traffic control layer enqueues packets in the queue disc
stavallo Dec 4, 2015
4dd14d5
Defer the addition of the IP header until the packet is extracted fro…
stavallo Jan 6, 2016
9881fe5
Ipv4Header: Add GetVersion and make DscpTypeToString static
stavallo Jan 8, 2016
106f8f2
Add the pfifo_fast queue disc
stavallo Jan 9, 2016
7d99326
Add a queue disc helper to ease the installation of queue discs
stavallo Dec 2, 2015
d850946
Add a traffic control example
pasquimp Nov 25, 2015
0815e6b
Add a pfifo_fast test suite
pasquimp Dec 14, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add a pfifo_fast test suite
  • Loading branch information
pasquimp authored and stavallo committed Jan 15, 2016
commit 0815e6b7d1dfe158f2e740728ee67ee2b851e263
332 changes: 332 additions & 0 deletions src/traffic-control/test/pfifo-fast-queue-disc-test-suite.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,332 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014 University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/

#include "ns3/test.h"
#include "ns3/pfifo-fast-queue-disc.h"
#include "ns3/drop-tail-queue.h"
#include "ns3/ipv4-header.h"
#include "ns3/enum.h"
#include "ns3/uinteger.h"
#include "ns3/pointer.h"
#include "ns3/object-factory.h"

using namespace ns3;

/**
* This class tests that each possible TOS is enqueued in the right band
*/
class PfifoFastQueueDiscTosPrioritization : public TestCase
{
public:
PfifoFastQueueDiscTosPrioritization ();
virtual ~PfifoFastQueueDiscTosPrioritization ();

private:
virtual void DoRun (void);
Ptr<Packet> CreatePacketWithTos (uint8_t tos);
void TestTosValue (Ptr<PfifoFastQueueDisc> queue, uint8_t tos, uint32_t band);
};

PfifoFastQueueDiscTosPrioritization::PfifoFastQueueDiscTosPrioritization ()
: TestCase ("Test TOS-based prioritization")
{
}

PfifoFastQueueDiscTosPrioritization::~PfifoFastQueueDiscTosPrioritization ()
{
}

Ptr<Packet>
PfifoFastQueueDiscTosPrioritization::CreatePacketWithTos (uint8_t tos)
{
Ptr<Packet> p = Create<Packet> (100);
Ipv4Header ipHeader;
ipHeader.SetPayloadSize (100);
ipHeader.SetTos (tos);
ipHeader.SetProtocol (6);
p->AddHeader (ipHeader);
return p;
}

void
PfifoFastQueueDiscTosPrioritization::TestTosValue (Ptr<PfifoFastQueueDisc> queue, uint8_t tos, uint32_t band)
{
Ptr<Packet> p = CreatePacketWithTos (tos);
Ipv4Header ipHeader;
p->RemoveHeader (ipHeader);
Address dest;
Ptr<QueueDiscItem> item = Create<QueueDiscItem> (p, ipHeader, dest, 0, 0);
queue->Enqueue (item);
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (band), 1, "enqueued to unexpected band");
item = queue->Dequeue ();
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (band), 0, "unable to dequeue");
}

void
PfifoFastQueueDiscTosPrioritization::DoRun (void)
{
Ptr<PfifoFastQueueDisc> queue = CreateObject<PfifoFastQueueDisc> ();
bool ok = queue->SetAttributeFailSafe ("Mode", EnumValue (PfifoFastQueueDisc::QUEUE_MODE_TOS));
NS_TEST_ASSERT_MSG_EQ (ok, true, "unable to set attribute");
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (0), 0, "initialized non-zero");
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (1), 0, "initialized non-zero");
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (2), 0, "initialized non-zero");

TestTosValue (queue, 0x0, 1);
TestTosValue (queue, 0x2, 2);
TestTosValue (queue, 0x4, 1);
TestTosValue (queue, 0x6, 1);
TestTosValue (queue, 0x8, 2);
TestTosValue (queue, 0xa, 2);
TestTosValue (queue, 0xc, 2);
TestTosValue (queue, 0xe, 2);
TestTosValue (queue, 0x10, 0);
TestTosValue (queue, 0x12, 0);
TestTosValue (queue, 0x14, 0);
TestTosValue (queue, 0x16, 0);
TestTosValue (queue, 0x18, 1);
TestTosValue (queue, 0x1a, 1);
TestTosValue (queue, 0x1c, 1);
TestTosValue (queue, 0x1e, 1);
}

/**
* This class tests that each possible DSCP is enqueued in the right band
*/
class PfifoFastQueueDiscDscpPrioritization : public TestCase
{
public:
PfifoFastQueueDiscDscpPrioritization ();
virtual ~PfifoFastQueueDiscDscpPrioritization ();

private:
virtual void DoRun (void);
Ptr<Packet> CreatePacketWithDscp (Ipv4Header::DscpType dscp);
void TestDscpValue (Ptr<PfifoFastQueueDisc> queue, Ipv4Header::DscpType dscp, uint32_t band);
};

PfifoFastQueueDiscDscpPrioritization::PfifoFastQueueDiscDscpPrioritization ()
: TestCase ("Test DSCP-based prioritization")
{
}

PfifoFastQueueDiscDscpPrioritization::~PfifoFastQueueDiscDscpPrioritization ()
{
}

Ptr<Packet>
PfifoFastQueueDiscDscpPrioritization::CreatePacketWithDscp (Ipv4Header::DscpType dscp)
{
Ptr<Packet> p = Create<Packet> (100);
Ipv4Header ipHeader;
ipHeader.SetPayloadSize (100);
ipHeader.SetProtocol (6);
ipHeader.SetDscp (dscp);
p->AddHeader (ipHeader);
return p;
}

void
PfifoFastQueueDiscDscpPrioritization::TestDscpValue (Ptr<PfifoFastQueueDisc> queue, Ipv4Header::DscpType dscp, uint32_t band)
{
Ptr<Packet> p = CreatePacketWithDscp (dscp);
Ipv4Header ipHeader;
p->RemoveHeader (ipHeader);
Address dest;
Ptr<QueueDiscItem> item = Create<QueueDiscItem> (p, ipHeader, dest, 0, 0);
queue->Enqueue (item);
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (band), 1, "enqueued to unexpected band");
item = queue->Dequeue ();
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (band), 0, "unable to dequeue");
}

void
PfifoFastQueueDiscDscpPrioritization::DoRun (void)
{
Ptr<PfifoFastQueueDisc> queue = CreateObject<PfifoFastQueueDisc> ();
bool ok = queue->SetAttributeFailSafe ("Mode", EnumValue (PfifoFastQueueDisc::QUEUE_MODE_DSCP));
NS_TEST_ASSERT_MSG_EQ (ok, true, "unable to set attribute");
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (0), 0, "initialized non-zero");
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (1), 0, "initialized non-zero");
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (2), 0, "initialized non-zero");

TestDscpValue (queue, Ipv4Header::DscpDefault, 1);
TestDscpValue (queue, Ipv4Header::DSCP_EF, 1);
TestDscpValue (queue, Ipv4Header::DSCP_AF11, 2);
TestDscpValue (queue, Ipv4Header::DSCP_AF21, 2);
TestDscpValue (queue, Ipv4Header::DSCP_AF31, 2);
TestDscpValue (queue, Ipv4Header::DSCP_AF41, 2);
TestDscpValue (queue, Ipv4Header::DSCP_AF12, 0);
TestDscpValue (queue, Ipv4Header::DSCP_AF22, 0);
TestDscpValue (queue, Ipv4Header::DSCP_AF32, 0);
TestDscpValue (queue, Ipv4Header::DSCP_AF42, 0);
TestDscpValue (queue, Ipv4Header::DSCP_AF13, 1);
TestDscpValue (queue, Ipv4Header::DSCP_AF23, 1);
TestDscpValue (queue, Ipv4Header::DSCP_AF33, 1);
TestDscpValue (queue, Ipv4Header::DSCP_AF43, 1);
TestDscpValue (queue, Ipv4Header::DSCP_CS1, 2);
TestDscpValue (queue, Ipv4Header::DSCP_CS2, 1);
TestDscpValue (queue, Ipv4Header::DSCP_CS3, 1);
TestDscpValue (queue, Ipv4Header::DSCP_CS4, 0);
TestDscpValue (queue, Ipv4Header::DSCP_CS5, 0);
TestDscpValue (queue, Ipv4Header::DSCP_CS6, 0);
TestDscpValue (queue, Ipv4Header::DSCP_CS7, 0);
}

/**
* This class tests that each band is txqueuelen deep
*/
class PfifoFastQueueDiscOverflow : public TestCase
{
public:
PfifoFastQueueDiscOverflow ();
virtual ~PfifoFastQueueDiscOverflow ();

private:
virtual void DoRun (void);
void AddPacket (Ptr<PfifoFastQueueDisc> queue, Ipv4Header::DscpType dscp);
};

PfifoFastQueueDiscOverflow::PfifoFastQueueDiscOverflow ()
: TestCase ("Test queue overflow")
{
}

PfifoFastQueueDiscOverflow::~PfifoFastQueueDiscOverflow ()
{
}

void
PfifoFastQueueDiscOverflow::AddPacket (Ptr<PfifoFastQueueDisc> queue, Ipv4Header::DscpType dscp)
{
Ptr<Packet> p = Create<Packet> (100);
Ipv4Header ipHeader;
ipHeader.SetPayloadSize (100);
ipHeader.SetProtocol (6);
ipHeader.SetDscp (dscp);
Address dest;
Ptr<QueueDiscItem> item = Create<QueueDiscItem> (p, ipHeader, dest, 0, 0);
queue->Enqueue (item);
}

void
PfifoFastQueueDiscOverflow::DoRun (void)
{
Ptr<DropTailQueue> band0 = CreateObjectWithAttributes<DropTailQueue> ("MaxPackets", UintegerValue (2));
Ptr<DropTailQueue> band1 = CreateObjectWithAttributes<DropTailQueue> ("MaxPackets", UintegerValue (2));
Ptr<DropTailQueue> band2 = CreateObjectWithAttributes<DropTailQueue> ("MaxPackets", UintegerValue (2));
Ptr<PfifoFastQueueDisc> queue = CreateObjectWithAttributes<PfifoFastQueueDisc> ("Band0", PointerValue (band0),
"Band1", PointerValue (band1),
"Band2", PointerValue (band2));
bool ok = queue->SetAttributeFailSafe ("Mode", EnumValue (PfifoFastQueueDisc::QUEUE_MODE_DSCP));
NS_TEST_ASSERT_MSG_EQ (ok, true, "unable to set attribute");

// Add two packets per each band
AddPacket (queue, Ipv4Header::DSCP_AF42); // 0
AddPacket (queue, Ipv4Header::DSCP_AF42); // 0
AddPacket (queue, Ipv4Header::DSCP_AF13); // 1
AddPacket (queue, Ipv4Header::DSCP_AF13); // 1
AddPacket (queue, Ipv4Header::DSCP_AF11); // 2
AddPacket (queue, Ipv4Header::DSCP_AF11); // 2
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (0), 2, "unexpected queue depth");
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (1), 2, "unexpected queue depth");
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (2), 2, "unexpected queue depth");
NS_TEST_ASSERT_MSG_EQ (queue->QueueDisc::GetNPackets (), 6, "unexpected queue depth");
// Add a third packet to each band
AddPacket (queue, Ipv4Header::DSCP_AF42); // 0
AddPacket (queue, Ipv4Header::DSCP_AF13); // 1
AddPacket (queue, Ipv4Header::DSCP_AF11); // 2
// Bands should still have two packets each
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (0), 2, "unexpected queue depth");
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (1), 2, "unexpected queue depth");
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (2), 2, "unexpected queue depth");
NS_TEST_ASSERT_MSG_EQ (queue->QueueDisc::GetNPackets (), 6, "unexpected queue depth");
}

/**
* This class tests that non-IP packets are handled by placing them into
* band 1
*/
class PfifoFastQueueDiscNonIpHeader : public TestCase
{
public:
PfifoFastQueueDiscNonIpHeader ();
virtual ~PfifoFastQueueDiscNonIpHeader ();

private:
virtual void DoRun (void);
};

PfifoFastQueueDiscNonIpHeader::PfifoFastQueueDiscNonIpHeader ()
: TestCase ("Test queue with non IP header")
{
}

PfifoFastQueueDiscNonIpHeader::~PfifoFastQueueDiscNonIpHeader ()
{
}

void
PfifoFastQueueDiscNonIpHeader::DoRun (void)
{
// all packets with non-IP headers should enqueue in band 1
Ptr<PfifoFastQueueDisc> queue = CreateObject<PfifoFastQueueDisc> ();
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (1), 0, "unexpected queue depth");
Ptr<Packet> p;
p = Create<Packet> ();
Ptr<QueueDiscItem> item;
Ipv6Header ipv6Header;
Address dest;
item = Create<QueueDiscItem> (p, ipv6Header, dest, 0, 0);
queue->Enqueue (item);
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (1), 1, "unexpected queue depth");
p = Create<Packet> (reinterpret_cast<const uint8_t*> ("hello, world"), 12);
item = Create<QueueDiscItem> (p, ipv6Header, dest, 0, 0);
queue->Enqueue (item);
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (1), 2, "unexpected queue depth");
p = Create<Packet> (100);
uint8_t *buf = new uint8_t[100];
uint8_t counter = 0;
for (uint32_t i = 0; i < 100; i++)
{
buf[i] = counter++;
}
p->CopyData (buf, 100);
item = Create<QueueDiscItem> (p, ipv6Header, dest, 0, 0);
queue->Enqueue (item);
NS_TEST_ASSERT_MSG_EQ (queue->GetNPackets (1), 3, "unexpected queue depth");
delete[] buf;
}

class PfifoFastQueueDiscTestSuite : public TestSuite
{
public:
PfifoFastQueueDiscTestSuite ();
};

PfifoFastQueueDiscTestSuite::PfifoFastQueueDiscTestSuite ()
: TestSuite ("pfifo-fast-queue-disc", UNIT)
{
AddTestCase (new PfifoFastQueueDiscTosPrioritization, TestCase::QUICK);
AddTestCase (new PfifoFastQueueDiscDscpPrioritization, TestCase::QUICK);
AddTestCase (new PfifoFastQueueDiscOverflow, TestCase::QUICK);
AddTestCase (new PfifoFastQueueDiscNonIpHeader, TestCase::QUICK);
}

static PfifoFastQueueDiscTestSuite pfifoFastQueueTestSuite;
1 change: 1 addition & 0 deletions src/traffic-control/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def build(bld):

module_test = bld.create_ns3_module_test_library('traffic-control')
module_test.source = [
'test/pfifo-fast-queue-disc-test-suite.cc',
]

headers = bld(features='ns3header')
Expand Down