diff --git a/src/traffic-control/test/red-queue-disc-test-suite.cc b/src/traffic-control/test/red-queue-disc-test-suite.cc
index 880d3eaae..6f26643f9 100644
--- a/src/traffic-control/test/red-queue-disc-test-suite.cc
+++ b/src/traffic-control/test/red-queue-disc-test-suite.cc
@@ -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
*
*/
#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 queue, uint32_t size, uint32_t nPkt);
+ void Enqueue (Ptr 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 queue = CreateObject ();
+ Ptr queue = CreateObject ();
// 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 p1, p2, p3, p4, p5, p6, p7, p8;
@@ -85,48 +91,49 @@ RedQueueTestCase::RunRedTest (StringValue mode)
p7 = Create (pktSize);
p8 = Create (pktSize);
+ queue->Initialize ();
NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 0 * modeSize, "There should be no packets in there");
- queue->Enqueue (Create (p1));
+ queue->Enqueue (Create (p1, dest, 0, ipHeader));
NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 1 * modeSize, "There should be one packet in there");
- queue->Enqueue (Create (p2));
+ queue->Enqueue (Create (p2, dest, 0, ipHeader));
NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 2 * modeSize, "There should be two packets in there");
- queue->Enqueue (Create (p3));
- queue->Enqueue (Create (p4));
- queue->Enqueue (Create (p5));
- queue->Enqueue (Create (p6));
- queue->Enqueue (Create (p7));
- queue->Enqueue (Create (p8));
+ queue->Enqueue (Create (p3, dest, 0, ipHeader));
+ queue->Enqueue (Create (p4, dest, 0, ipHeader));
+ queue->Enqueue (Create (p5, dest, 0, ipHeader));
+ queue->Enqueue (Create (p6, dest, 0, ipHeader));
+ queue->Enqueue (Create (p7, dest, 0, ipHeader));
+ queue->Enqueue (Create (p8, dest, 0, ipHeader));
NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 8 * modeSize, "There should be eight packets in there");
- Ptr item;
+ Ptr item;
- item = queue->Dequeue ();
+ item = StaticCast (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 (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 (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 (queue->Dequeue ());
+ item = StaticCast (queue->Dequeue ());
+ item = StaticCast (queue->Dequeue ());
+ item = StaticCast (queue->Dequeue ());
+ item = StaticCast (queue->Dequeue ());
- item = queue->Dequeue ();
+ item = StaticCast (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 ();
+ queue = CreateObject ();
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 (queue)->GetStats ();
+ RedQueueDisc::Stats st = StaticCast (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 ();
+ queue = CreateObject ();
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 (queue)->GetStats ();
+ st = StaticCast (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 ();
+ queue = CreateObject ();
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 (queue)->GetStats ();
+ st = StaticCast (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 ();
+ queue = CreateObject ();
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 (queue)->GetStats ();
+ st = StaticCast (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 ();
+ queue = CreateObject ();
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 (queue)->GetStats ();
+ st = StaticCast (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 ();
+ queue = CreateObject ();
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 (queue)->GetStats ();
+ st = StaticCast (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 queue, uint32_t size, uint32_t nPkt)
+RedQueueDiscTestCase::Enqueue (Ptr queue, uint32_t size, uint32_t nPkt)
{
+ Ipv4Header ipHeader;
+ Address dest;
for (uint32_t i = 0; i < nPkt; i++)
{
- queue->Enqueue (Create (Create (size)));
+ queue->Enqueue (Create (Create (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;
diff --git a/src/traffic-control/wscript b/src/traffic-control/wscript
index 5127b918d..3fbd0d1ed 100644
--- a/src/traffic-control/wscript
+++ b/src/traffic-control/wscript
@@ -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')