completed ControlLaw unit test draft
authorAnh Nguyen <trucanh524@gmail.com>
Tue, 19 Aug 2014 17:04:46 -0500
changeset 10856 ae79f9e9114d
parent 10855 cc364a7ff1ae
child 10857 be264fca83da
completed ControlLaw unit test
src/internet/model/codel-queue.cc
src/internet/test/codel-queue-test-suite.cc
--- a/src/internet/model/codel-queue.cc	Tue Aug 19 15:38:03 2014 -0500
+++ b/src/internet/model/codel-queue.cc	Tue Aug 19 17:04:46 2014 -0500
@@ -215,7 +215,6 @@
 CoDelQueue::NewtonStep (void)
 {
   NS_LOG_FUNCTION (this); 
-  NS_LOG_LOGIC ("m_count: " << m_count << "m_recInvSqrt: " << (uint32_t)m_recInvSqrt);
   uint32_t invsqrt = ((uint32_t) m_recInvSqrt) << REC_INV_SQRT_SHIFT;
   uint32_t invsqrt2 = ((uint64_t) invsqrt * invsqrt) >> 32;
   uint64_t val = (3ll << 32) - ((uint64_t) m_count * invsqrt2);
--- a/src/internet/test/codel-queue-test-suite.cc	Tue Aug 19 15:38:03 2014 -0500
+++ b/src/internet/test/codel-queue-test-suite.cc	Tue Aug 19 17:04:46 2014 -0500
@@ -248,7 +248,8 @@
 {
   Ptr<CoDelQueue> queue = CreateObject<CoDelQueue> ();
 
-  // Spot check a few points in the expected operational range of CoDelQueue's m_count and m_recInvSqrt variables
+  // Spot check a few points in the expected operational range of
+  // CoDelQueue's m_count and m_recInvSqrt variables
   uint32_t count = 2;
   uint16_t recInvSqrt = 65535;
   queue->m_count = count;
@@ -275,7 +276,6 @@
 public:
   CoDelQueueControlLawTest ();
   virtual void DoRun (void);
-  // The following routine borrowed from Linux codel.h
   uint32_t _codel_control_law (Ptr<CoDelQueue> queue, uint32_t t);
 };
 
@@ -284,19 +284,35 @@
 {
 }
 
-// The following code borrowed from Linux codel.h, except the addition of queue parameter
+// The following code borrowed from Linux codel.h,
+// except the addition of queue parameter
 uint32_t
 CoDelQueueControlLawTest::_codel_control_law (Ptr<CoDelQueue> queue, uint32_t t)
 {
   return t + _reciprocal_scale(queue->Time2CoDel (queue->m_interval), queue->m_recInvSqrt << REC_INV_SQRT_SHIFT_ns3);
 }
+// End Linux borrrow
 
 void
 CoDelQueueControlLawTest::DoRun (void)
 {
   Ptr<CoDelQueue> queue = CreateObject<CoDelQueue> ();
-  NS_TEST_ASSERT_MSG_NE (_codel_control_law (queue, 292299), queue->ControlLaw (292249),
-     			                                 "ns-3 NewtonStep() fails to match Linux equivalent");
+
+  /* Spot check a few points of m_dropNext
+   The integer approximations in Linux should be within
+   2% of the true floating point value obtained in ns-3
+   */
+  uint32_t dropNextTestVals [4] = {292299, 341128, 9804717, 55885007};
+
+  for (int i = 0; i < 4; ++i)
+  {
+    uint32_t ns3Result = queue->ControlLaw (dropNextTestVals[i]);
+    uint32_t upperBound = ns3Result + 0.02 * ns3Result;
+    uint32_t lowerBound = ns3Result - 0.02 * ns3Result;
+    uint32_t linuxResult = _codel_control_law (queue, dropNextTestVals[i]);
+    NS_TEST_EXPECT_MSG_EQ ((lowerBound < linuxResult || linuxResult < upperBound), true,
+                                              "Linux result should stay within 2% of ns-3 result");
+  }
 }
 
 // Test 5: enqueue/dequeue with drops according to CoDel algorithm