traffic-control: Fix the RED test suite after the move to the traffic-control module
This commit is contained in:
@@ -16,36 +16,39 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Marcos Talau (talau@users.sourceforge.net)
|
||||
* Modified by: Pasquale Imputato <p.imputato@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ns3/test.h"
|
||||
#include "ns3/red-queue.h"
|
||||
#include "ns3/red-queue-disc.h"
|
||||
#include "ns3/drop-tail-queue.h"
|
||||
#include "ns3/uinteger.h"
|
||||
#include "ns3/string.h"
|
||||
#include "ns3/double.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/ipv4-queue-disc-item.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
class RedQueueTestCase : public TestCase
|
||||
class RedQueueDiscTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
RedQueueTestCase ();
|
||||
RedQueueDiscTestCase ();
|
||||
virtual void DoRun (void);
|
||||
private:
|
||||
void Enqueue (Ptr<RedQueue> queue, uint32_t size, uint32_t nPkt);
|
||||
void Enqueue (Ptr<RedQueueDisc> queue, uint32_t size, uint32_t nPkt);
|
||||
void RunRedTest (StringValue mode);
|
||||
};
|
||||
|
||||
RedQueueTestCase::RedQueueTestCase ()
|
||||
RedQueueDiscTestCase::RedQueueDiscTestCase ()
|
||||
: TestCase ("Sanity check on the red queue implementation")
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
RedQueueTestCase::RunRedTest (StringValue mode)
|
||||
RedQueueDiscTestCase::RunRedTest (StringValue mode)
|
||||
{
|
||||
uint32_t pktSize = 0;
|
||||
// 1 for packets; pktSize for bytes
|
||||
@@ -53,7 +56,7 @@ RedQueueTestCase::RunRedTest (StringValue mode)
|
||||
double minTh = 2;
|
||||
double maxTh = 5;
|
||||
uint32_t qSize = 8;
|
||||
Ptr<RedQueue> queue = CreateObject<RedQueue> ();
|
||||
Ptr<RedQueueDisc> queue = CreateObject<RedQueueDisc> ();
|
||||
|
||||
// test 1: simple enqueue/dequeue with no drops
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
|
||||
@@ -67,12 +70,15 @@ RedQueueTestCase::RunRedTest (StringValue mode)
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (0.002)), true,
|
||||
"Verify that we can actually set the attribute QW");
|
||||
|
||||
if (queue->GetMode () == RedQueue::QUEUE_MODE_BYTES)
|
||||
Ipv4Header ipHeader;
|
||||
Address dest;
|
||||
|
||||
if (queue->GetMode () == Queue::QUEUE_MODE_BYTES)
|
||||
{
|
||||
pktSize = 1000;
|
||||
modeSize = pktSize;
|
||||
queue->SetTh (minTh * pktSize, maxTh * pktSize);
|
||||
queue->SetQueueLimit (qSize * pktSize);
|
||||
modeSize = pktSize + ipHeader.GetSerializedSize ();
|
||||
queue->SetTh (minTh * modeSize, maxTh * modeSize);
|
||||
queue->SetQueueLimit (qSize * modeSize);
|
||||
}
|
||||
|
||||
Ptr<Packet> p1, p2, p3, p4, p5, p6, p7, p8;
|
||||
@@ -85,48 +91,49 @@ RedQueueTestCase::RunRedTest (StringValue mode)
|
||||
p7 = Create<Packet> (pktSize);
|
||||
p8 = Create<Packet> (pktSize);
|
||||
|
||||
queue->Initialize ();
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 0 * modeSize, "There should be no packets in there");
|
||||
queue->Enqueue (Create<QueueItem> (p1));
|
||||
queue->Enqueue (Create<Ipv4QueueDiscItem> (p1, dest, 0, ipHeader));
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 1 * modeSize, "There should be one packet in there");
|
||||
queue->Enqueue (Create<QueueItem> (p2));
|
||||
queue->Enqueue (Create<Ipv4QueueDiscItem> (p2, dest, 0, ipHeader));
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 2 * modeSize, "There should be two packets in there");
|
||||
queue->Enqueue (Create<QueueItem> (p3));
|
||||
queue->Enqueue (Create<QueueItem> (p4));
|
||||
queue->Enqueue (Create<QueueItem> (p5));
|
||||
queue->Enqueue (Create<QueueItem> (p6));
|
||||
queue->Enqueue (Create<QueueItem> (p7));
|
||||
queue->Enqueue (Create<QueueItem> (p8));
|
||||
queue->Enqueue (Create<Ipv4QueueDiscItem> (p3, dest, 0, ipHeader));
|
||||
queue->Enqueue (Create<Ipv4QueueDiscItem> (p4, dest, 0, ipHeader));
|
||||
queue->Enqueue (Create<Ipv4QueueDiscItem> (p5, dest, 0, ipHeader));
|
||||
queue->Enqueue (Create<Ipv4QueueDiscItem> (p6, dest, 0, ipHeader));
|
||||
queue->Enqueue (Create<Ipv4QueueDiscItem> (p7, dest, 0, ipHeader));
|
||||
queue->Enqueue (Create<Ipv4QueueDiscItem> (p8, dest, 0, ipHeader));
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 8 * modeSize, "There should be eight packets in there");
|
||||
|
||||
Ptr<QueueItem> item;
|
||||
Ptr<Ipv4QueueDiscItem> item;
|
||||
|
||||
item = queue->Dequeue ();
|
||||
item = StaticCast<Ipv4QueueDiscItem> (queue->Dequeue ());
|
||||
NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the first packet");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 7 * modeSize, "There should be seven packets in there");
|
||||
NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p1->GetUid (), "was this the first packet ?");
|
||||
|
||||
item = queue->Dequeue ();
|
||||
item = StaticCast<Ipv4QueueDiscItem> (queue->Dequeue ());
|
||||
NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the second packet");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 6 * modeSize, "There should be six packet in there");
|
||||
NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p2->GetUid (), "Was this the second packet ?");
|
||||
|
||||
item = queue->Dequeue ();
|
||||
item = StaticCast<Ipv4QueueDiscItem> (queue->Dequeue ());
|
||||
NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the third packet");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 5 * modeSize, "There should be five packets in there");
|
||||
NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p3->GetUid (), "Was this the third packet ?");
|
||||
|
||||
item = queue->Dequeue ();
|
||||
item = queue->Dequeue ();
|
||||
item = queue->Dequeue ();
|
||||
item = queue->Dequeue ();
|
||||
item = queue->Dequeue ();
|
||||
item = StaticCast<Ipv4QueueDiscItem> (queue->Dequeue ());
|
||||
item = StaticCast<Ipv4QueueDiscItem> (queue->Dequeue ());
|
||||
item = StaticCast<Ipv4QueueDiscItem> (queue->Dequeue ());
|
||||
item = StaticCast<Ipv4QueueDiscItem> (queue->Dequeue ());
|
||||
item = StaticCast<Ipv4QueueDiscItem> (queue->Dequeue ());
|
||||
|
||||
item = queue->Dequeue ();
|
||||
item = StaticCast<Ipv4QueueDiscItem> (queue->Dequeue ());
|
||||
NS_TEST_EXPECT_MSG_EQ ((item == 0), true, "There are really no packets in there");
|
||||
|
||||
|
||||
// test 2: more data, but with no drops
|
||||
queue = CreateObject<RedQueue> ();
|
||||
queue = CreateObject<RedQueueDisc> ();
|
||||
minTh = 70 * modeSize;
|
||||
maxTh = 150 * modeSize;
|
||||
qSize = 300 * modeSize;
|
||||
@@ -138,8 +145,9 @@ RedQueueTestCase::RunRedTest (StringValue mode)
|
||||
"Verify that we can actually set the attribute MaxTh");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QueueLimit", UintegerValue (qSize)), true,
|
||||
"Verify that we can actually set the attribute QueueLimit");
|
||||
queue->Initialize ();
|
||||
Enqueue (queue, pktSize, 300);
|
||||
RedQueue::Stats st = StaticCast<RedQueue> (queue)->GetStats ();
|
||||
RedQueueDisc::Stats st = StaticCast<RedQueueDisc> (queue)->GetStats ();
|
||||
NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 0, "There should zero dropped packets due probability mark");
|
||||
NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0, "There should zero dropped packets due hardmark mark");
|
||||
NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0, "There should zero dropped packets due queue full");
|
||||
@@ -155,7 +163,7 @@ RedQueueTestCase::RunRedTest (StringValue mode)
|
||||
|
||||
|
||||
// test 3: more data, now drops due QW change
|
||||
queue = CreateObject<RedQueue> ();
|
||||
queue = CreateObject<RedQueueDisc> ();
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
|
||||
"Verify that we can actually set the attribute Mode");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
|
||||
@@ -166,15 +174,16 @@ RedQueueTestCase::RunRedTest (StringValue mode)
|
||||
"Verify that we can actually set the attribute QueueLimit");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (0.020)), true,
|
||||
"Verify that we can actually set the attribute QW");
|
||||
queue->Initialize ();
|
||||
Enqueue (queue, pktSize, 300);
|
||||
st = StaticCast<RedQueue> (queue)->GetStats ();
|
||||
st = StaticCast<RedQueueDisc> (queue)->GetStats ();
|
||||
drop.test3 = st.unforcedDrop + st.forcedDrop + st.qLimDrop;
|
||||
NS_TEST_EXPECT_MSG_NE (drop.test3, 0, "There should be some dropped packets");
|
||||
|
||||
|
||||
// test 4: reduced maxTh, this causes more drops
|
||||
maxTh = 100 * modeSize;
|
||||
queue = CreateObject<RedQueue> ();
|
||||
queue = CreateObject<RedQueueDisc> ();
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
|
||||
"Verify that we can actually set the attribute Mode");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
|
||||
@@ -185,15 +194,16 @@ RedQueueTestCase::RunRedTest (StringValue mode)
|
||||
"Verify that we can actually set the attribute QueueLimit");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("QW", DoubleValue (0.020)), true,
|
||||
"Verify that we can actually set the attribute QW");
|
||||
queue->Initialize ();
|
||||
Enqueue (queue, pktSize, 300);
|
||||
st = StaticCast<RedQueue> (queue)->GetStats ();
|
||||
st = StaticCast<RedQueueDisc> (queue)->GetStats ();
|
||||
drop.test4 = st.unforcedDrop + st.forcedDrop + st.qLimDrop;
|
||||
NS_TEST_EXPECT_MSG_GT (drop.test4, drop.test3, "Test 4 should have more drops than test 3");
|
||||
|
||||
|
||||
// test 5: change drop probability to a high value (LInterm)
|
||||
maxTh = 150 * modeSize;
|
||||
queue = CreateObject<RedQueue> ();
|
||||
queue = CreateObject<RedQueueDisc> ();
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
|
||||
"Verify that we can actually set the attribute Mode");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
|
||||
@@ -206,14 +216,15 @@ RedQueueTestCase::RunRedTest (StringValue mode)
|
||||
"Verify that we can actually set the attribute QW");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("LInterm", DoubleValue (5)), true,
|
||||
"Verify that we can actually set the attribute LInterm");
|
||||
queue->Initialize ();
|
||||
Enqueue (queue, pktSize, 300);
|
||||
st = StaticCast<RedQueue> (queue)->GetStats ();
|
||||
st = StaticCast<RedQueueDisc> (queue)->GetStats ();
|
||||
drop.test5 = st.unforcedDrop + st.forcedDrop + st.qLimDrop;
|
||||
NS_TEST_EXPECT_MSG_GT (drop.test5, drop.test3, "Test 5 should have more drops than test 3");
|
||||
|
||||
|
||||
// test 6: disable Gentle param
|
||||
queue = CreateObject<RedQueue> ();
|
||||
queue = CreateObject<RedQueueDisc> ();
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
|
||||
"Verify that we can actually set the attribute Mode");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
|
||||
@@ -226,14 +237,15 @@ RedQueueTestCase::RunRedTest (StringValue mode)
|
||||
"Verify that we can actually set the attribute QW");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Gentle", BooleanValue (false)), true,
|
||||
"Verify that we can actually set the attribute Gentle");
|
||||
queue->Initialize ();
|
||||
Enqueue (queue, pktSize, 300);
|
||||
st = StaticCast<RedQueue> (queue)->GetStats ();
|
||||
st = StaticCast<RedQueueDisc> (queue)->GetStats ();
|
||||
drop.test6 = st.unforcedDrop + st.forcedDrop + st.qLimDrop;
|
||||
NS_TEST_EXPECT_MSG_GT (drop.test6, drop.test3, "Test 6 should have more drops than test 3");
|
||||
|
||||
|
||||
// test 7: disable Wait param
|
||||
queue = CreateObject<RedQueue> ();
|
||||
queue = CreateObject<RedQueueDisc> ();
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Mode", mode), true,
|
||||
"Verify that we can actually set the attribute Mode");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MinTh", DoubleValue (minTh)), true,
|
||||
@@ -246,23 +258,26 @@ RedQueueTestCase::RunRedTest (StringValue mode)
|
||||
"Verify that we can actually set the attribute QW");
|
||||
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("Wait", BooleanValue (false)), true,
|
||||
"Verify that we can actually set the attribute Wait");
|
||||
queue->Initialize ();
|
||||
Enqueue (queue, pktSize, 300);
|
||||
st = StaticCast<RedQueue> (queue)->GetStats ();
|
||||
st = StaticCast<RedQueueDisc> (queue)->GetStats ();
|
||||
drop.test7 = st.unforcedDrop + st.forcedDrop + st.qLimDrop;
|
||||
NS_TEST_EXPECT_MSG_GT (drop.test7, drop.test3, "Test 7 should have more drops than test 3");
|
||||
}
|
||||
|
||||
void
|
||||
RedQueueTestCase::Enqueue (Ptr<RedQueue> queue, uint32_t size, uint32_t nPkt)
|
||||
RedQueueDiscTestCase::Enqueue (Ptr<RedQueueDisc> queue, uint32_t size, uint32_t nPkt)
|
||||
{
|
||||
Ipv4Header ipHeader;
|
||||
Address dest;
|
||||
for (uint32_t i = 0; i < nPkt; i++)
|
||||
{
|
||||
queue->Enqueue (Create<QueueItem> (Create<Packet> (size)));
|
||||
queue->Enqueue (Create<Ipv4QueueDiscItem> (Create<Packet> (size), dest, 0, ipHeader));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RedQueueTestCase::DoRun (void)
|
||||
RedQueueDiscTestCase::DoRun (void)
|
||||
{
|
||||
RunRedTest (StringValue ("QUEUE_MODE_PACKETS"));
|
||||
RunRedTest (StringValue ("QUEUE_MODE_BYTES"));
|
||||
@@ -270,12 +285,12 @@ RedQueueTestCase::DoRun (void)
|
||||
|
||||
}
|
||||
|
||||
static class RedQueueTestSuite : public TestSuite
|
||||
static class RedQueueDiscTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
RedQueueTestSuite ()
|
||||
: TestSuite ("red-queue", UNIT)
|
||||
RedQueueDiscTestSuite ()
|
||||
: TestSuite ("red-queue-disc", UNIT)
|
||||
{
|
||||
AddTestCase (new RedQueueTestCase (), TestCase::QUICK);
|
||||
AddTestCase (new RedQueueDiscTestCase (), TestCase::QUICK);
|
||||
}
|
||||
} g_redQueueTestSuite;
|
||||
|
||||
@@ -21,6 +21,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',
|
||||
'test/red-queue-disc-test-suite.cc',
|
||||
]
|
||||
|
||||
headers = bld(features='ns3header')
|
||||
|
||||
Reference in New Issue
Block a user