A Discrete-Event Network Simulator
API
tcp-hybla-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 Natale Patriciello, <natale.patriciello@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19 
20 #include "ns3/test.h"
21 #include "ns3/log.h"
22 #include "ns3/tcp-congestion-ops.h"
23 #include "ns3/tcp-socket-base.h"
24 #include "ns3/tcp-hybla.h"
25 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("TcpHyblaTestSuite");
29 
34 {
35 public:
36  TcpHyblaIncrementTest (uint32_t cWnd, uint32_t ssThresh,
37  uint32_t segmentSize, const Time& rtt,
38  const std::string &name);
39 
40 private:
41  virtual void DoRun (void);
42  void RhoUpdated (double oldVal, double newVal);
43 
44  uint32_t m_cWnd;
45  uint32_t m_ssThresh;
46  uint32_t m_segmentSize;
48  double m_rho;
50 };
51 
52 TcpHyblaIncrementTest::TcpHyblaIncrementTest (uint32_t cWnd, uint32_t ssThresh,
53  uint32_t segmentSize, const Time &rtt,
54  const std::string &name)
55  : TestCase (name),
56  m_cWnd (cWnd),
57  m_ssThresh (ssThresh),
58  m_segmentSize (segmentSize),
59  m_rtt (rtt),
60  m_rho (0)
61 {
62 }
63 
64 void
65 TcpHyblaIncrementTest::RhoUpdated (double oldVal, double newVal)
66 {
67  m_rho = newVal;
68 }
69 
70 void
72 {
73  m_state = CreateObject<TcpSocketState> ();
74 
75  m_state->m_cWnd = m_cWnd;
76  m_state->m_ssThresh = m_ssThresh;
77  m_state->m_segmentSize = m_segmentSize;
78 
79  Ptr<TcpHybla> cong = CreateObject <TcpHybla> ();
80 
81  cong->TraceConnectWithoutContext ("Rho",
83 
84  // Each received ACK weight is "coeffA". To see an increase of 1 MSS, we need
85  // to ACK at least segCwnd/coeffA ACK.
86 
87  TimeValue rRtt;
88  cong->GetAttribute ("RRTT", rRtt);
89  cong->PktsAcked (m_state, 1, m_rtt);
90 
91  double calcRho = std::max (m_rtt.GetSeconds () / rRtt.Get ().GetSeconds (), 1.0);
92 
94  "Rho never updated by implementation");
96  "Different rho values between implementation and test");
97 
98  cong->IncreaseWindow (m_state, 1);
99 
100  if (m_cWnd <= m_ssThresh)
101  {
102  // We expect an increment of 2^rho - 1, which does not go beyond ssThresh
103  double inc = std::pow (2, calcRho) - 1.0;
104  uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
105  NS_TEST_ASSERT_MSG_LT_OR_EQ (m_state->m_cWnd.Get (), m_state->m_ssThresh.Get (),
106  "Congestion window has gone too far");
107  NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), cWndExpected,
108  "Congestion window different than expected");
109  }
110  else
111  {
112  // We expect an increment of rho^2 / cWnd
113  uint32_t segCwnd = m_cWnd / m_segmentSize;
114  double inc = std::pow (m_rho, 2) / ((double) segCwnd);
115  uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
116 
117  if (inc >= 1.0)
118  {
119  // LT because implementation does not add value less than MSS.
120  NS_TEST_ASSERT_MSG_LT_OR_EQ (m_state->m_cWnd.Get (), cWndExpected,
121  "Congestion window different than expected");
122  }
123  }
124 
125 }
126 
127 // -------------------------------------------------------------------
128 
129 static class TcpHyblaTestSuite : public TestSuite
130 {
131 public:
132  TcpHyblaTestSuite () : TestSuite ("tcp-hybla-test", UNIT)
133  {
134  AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (55), "Rho=1.1, slow start"),
136  AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (100), "Rho=2, slow start"),
138  AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (750), "Rho=30, slow start"),
140  AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.55), "Rho=1.1, cong avoid"),
142  AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.1), "Rho=2, cong avoid"),
144  AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.75), "Rho=30, cong avoid"),
146  }
148 
149 } // namespace ns3
Time Get(void) const
Definition: time.cc:443
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Fast test.
Definition: test.h:1152
A suite of tests to run.
Definition: test.h:1333
Ptr< TcpSocketState > m_state
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:903
Testing the congestion avoidance increment on TcpHybla.
encapsulates test code
Definition: test.h:1147
This test suite implements a Unit Test.
Definition: test.h:1343
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
#define max(a, b)
Definition: 80211b.c:45
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
AttributeValue implementation for Time.
Definition: nstime.h:957
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:161
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition: test.h:373
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void RhoUpdated(double oldVal, double newVal)
virtual void DoRun(void)
Implementation to actually run this TestCase.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not...
Definition: test.h:617
TcpHyblaIncrementTest(uint32_t cWnd, uint32_t ssThresh, uint32_t segmentSize, const Time &rtt, const std::string &name)
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
#define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg)
Test that an actual value is less than or equal to a limit and report and abort if not...
Definition: test.h:825
ns3::TcpHyblaTestSuite g_tcpHyblaTest