23 #include "ns3/red-queue.h"
24 #include "ns3/uinteger.h"
25 #include "ns3/string.h"
26 #include "ns3/double.h"
28 #include "ns3/simulator.h"
36 virtual void DoRun (
void);
38 void Enqueue (
Ptr<RedQueue> queue, uint32_t size, uint32_t nPkt);
42 RedQueueTestCase::RedQueueTestCase ()
43 :
TestCase (
"Sanity check on the red queue implementation")
52 uint32_t modeSize = 1;
60 "Verify that we can actually set the attribute Mode");
62 "Verify that we can actually set the attribute MinTh");
64 "Verify that we can actually set the attribute MaxTh");
66 "Verify that we can actually set the attribute QueueLimit");
68 "Verify that we can actually set the attribute QW");
70 if (queue->GetMode () == RedQueue::QUEUE_MODE_BYTES)
74 queue->SetTh (minTh * pktSize, maxTh * pktSize);
75 queue->SetQueueLimit (qSize * pktSize);
79 p1 = Create<Packet> (pktSize);
80 p2 = Create<Packet> (pktSize);
81 p3 = Create<Packet> (pktSize);
82 p4 = Create<Packet> (pktSize);
83 p5 = Create<Packet> (pktSize);
84 p6 = Create<Packet> (pktSize);
85 p7 = Create<Packet> (pktSize);
86 p8 = Create<Packet> (pktSize);
88 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 0 * modeSize,
"There should be no packets in there");
90 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 1 * modeSize,
"There should be one packet in there");
92 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 2 * modeSize,
"There should be two packets in there");
99 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 8 * modeSize,
"There should be eight packets in there");
104 NS_TEST_EXPECT_MSG_EQ ((p != 0),
true,
"I want to remove the first packet");
105 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 7 * modeSize,
"There should be seven packets in there");
106 NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p1->
GetUid (),
"was this the first packet ?");
109 NS_TEST_EXPECT_MSG_EQ ((p != 0),
true,
"I want to remove the second packet");
110 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 6 * modeSize,
"There should be six packet in there");
111 NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p2->GetUid (),
"Was this the second packet ?");
114 NS_TEST_EXPECT_MSG_EQ ((p != 0),
true,
"I want to remove the third packet");
115 NS_TEST_EXPECT_MSG_EQ (queue->GetQueueSize (), 5 * modeSize,
"There should be five packets in there");
116 NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p3->GetUid (),
"Was this the third packet ?");
125 NS_TEST_EXPECT_MSG_EQ ((p == 0),
true,
"There are really no packets in there");
129 queue = CreateObject<RedQueue> ();
130 minTh = 70 * modeSize;
131 maxTh = 150 * modeSize;
132 qSize = 300 * modeSize;
134 "Verify that we can actually set the attribute Mode");
136 "Verify that we can actually set the attribute MinTh");
138 "Verify that we can actually set the attribute MaxTh");
140 "Verify that we can actually set the attribute QueueLimit");
141 Enqueue (queue, pktSize, 300);
143 NS_TEST_EXPECT_MSG_EQ (st.unforcedDrop, 0,
"There should zero dropped packets due probability mark");
144 NS_TEST_EXPECT_MSG_EQ (st.forcedDrop, 0,
"There should zero dropped packets due hardmark mark");
145 NS_TEST_EXPECT_MSG_EQ (st.qLimDrop, 0,
"There should zero dropped packets due queue full");
158 queue = CreateObject<RedQueue> ();
160 "Verify that we can actually set the attribute Mode");
162 "Verify that we can actually set the attribute MinTh");
164 "Verify that we can actually set the attribute MaxTh");
166 "Verify that we can actually set the attribute QueueLimit");
168 "Verify that we can actually set the attribute QW");
169 Enqueue (queue, pktSize, 300);
170 st = StaticCast<RedQueue> (queue)->GetStats ();
171 drop.test3 = st.unforcedDrop + st.forcedDrop + st.qLimDrop;
172 NS_TEST_EXPECT_MSG_NE (drop.test3, 0,
"There should be some dropped packets");
176 maxTh = 100 * modeSize;
177 queue = CreateObject<RedQueue> ();
179 "Verify that we can actually set the attribute Mode");
181 "Verify that we can actually set the attribute MinTh");
183 "Verify that we can actually set the attribute MaxTh");
185 "Verify that we can actually set the attribute QueueLimit");
187 "Verify that we can actually set the attribute QW");
188 Enqueue (queue, pktSize, 300);
189 st = StaticCast<RedQueue> (queue)->GetStats ();
190 drop.test4 = st.unforcedDrop + st.forcedDrop + st.qLimDrop;
191 NS_TEST_EXPECT_MSG_GT (drop.test4, drop.test3,
"Test 4 should have more drops than test 3");
195 maxTh = 150 * modeSize;
196 queue = CreateObject<RedQueue> ();
198 "Verify that we can actually set the attribute Mode");
200 "Verify that we can actually set the attribute MinTh");
202 "Verify that we can actually set the attribute MaxTh");
204 "Verify that we can actually set the attribute QueueLimit");
206 "Verify that we can actually set the attribute QW");
208 "Verify that we can actually set the attribute LInterm");
209 Enqueue (queue, pktSize, 300);
210 st = StaticCast<RedQueue> (queue)->GetStats ();
211 drop.test5 = st.unforcedDrop + st.forcedDrop + st.qLimDrop;
212 NS_TEST_EXPECT_MSG_GT (drop.test5, drop.test3,
"Test 5 should have more drops than test 3");
216 queue = CreateObject<RedQueue> ();
218 "Verify that we can actually set the attribute Mode");
220 "Verify that we can actually set the attribute MinTh");
222 "Verify that we can actually set the attribute MaxTh");
224 "Verify that we can actually set the attribute QueueLimit");
226 "Verify that we can actually set the attribute QW");
228 "Verify that we can actually set the attribute Gentle");
229 Enqueue (queue, pktSize, 300);
230 st = StaticCast<RedQueue> (queue)->GetStats ();
231 drop.test6 = st.unforcedDrop + st.forcedDrop + st.qLimDrop;
232 NS_TEST_EXPECT_MSG_GT (drop.test6, drop.test3,
"Test 6 should have more drops than test 3");
236 queue = CreateObject<RedQueue> ();
238 "Verify that we can actually set the attribute Mode");
240 "Verify that we can actually set the attribute MinTh");
242 "Verify that we can actually set the attribute MaxTh");
244 "Verify that we can actually set the attribute QueueLimit");
246 "Verify that we can actually set the attribute QW");
248 "Verify that we can actually set the attribute Wait");
249 Enqueue (queue, pktSize, 300);
250 st = StaticCast<RedQueue> (queue)->GetStats ();
251 drop.test7 = st.unforcedDrop + st.forcedDrop + st.qLimDrop;
252 NS_TEST_EXPECT_MSG_GT (drop.test7, drop.test3,
"Test 7 should have more drops than test 3");
256 RedQueueTestCase::Enqueue (
Ptr<RedQueue> queue, uint32_t size, uint32_t nPkt)
258 for (uint32_t i = 0; i < nPkt; i++)
260 queue->
Enqueue (Create<Packet> (size));
269 Simulator::Destroy ();
281 } g_redQueueTestSuite;
smart pointer class similar to boost::intrusive_ptr
bool Enqueue(Ptr< Packet > p)
hold variables of type string
uint64_t GetUid(void) const
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
Hold an unsigned integer type.
Ptr< Packet > Dequeue(void)
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Hold an floating point type.
virtual void DoRun(void)
Implementation to actually run this test case.