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 using namespace ns3;
27 
28 NS_LOG_COMPONENT_DEFINE ("TcpHyblaTestSuite");
29 
37 {
38 public:
47  TcpHyblaIncrementTest (uint32_t cWnd, uint32_t ssThresh,
48  uint32_t segmentSize, const Time& rtt,
49  const std::string &name);
50 
51 private:
52  virtual void DoRun (void);
53 
59  void RhoUpdated (double oldVal, double newVal);
60 
61  uint32_t m_cWnd;
62  uint32_t m_ssThresh;
63  uint32_t m_segmentSize;
65  double m_rho;
67 };
68 
69 TcpHyblaIncrementTest::TcpHyblaIncrementTest (uint32_t cWnd, uint32_t ssThresh,
70  uint32_t segmentSize, const Time &rtt,
71  const std::string &name)
72  : TestCase (name),
73  m_cWnd (cWnd),
74  m_ssThresh (ssThresh),
75  m_segmentSize (segmentSize),
76  m_rtt (rtt),
77  m_rho (0)
78 {
79 }
80 
81 void
82 TcpHyblaIncrementTest::RhoUpdated (double oldVal, double newVal)
83 {
84  NS_UNUSED (oldVal);
85  m_rho = newVal;
86 }
87 
88 void
90 {
91  m_state = CreateObject<TcpSocketState> ();
92 
97 
98  Ptr<TcpHybla> cong = CreateObject <TcpHybla> ();
99 
100  cong->TraceConnectWithoutContext ("Rho",
102 
103  // Each received ACK weight is "coeffA". To see an increase of 1 MSS, we need
104  // to ACK at least segCwnd/coeffA ACK.
105 
106  TimeValue rRtt;
107  cong->GetAttribute ("RRTT", rRtt);
108  cong->PktsAcked (m_state, 1, m_rtt);
109 
110  double calcRho = std::max (m_rtt.GetSeconds () / rRtt.Get ().GetSeconds (), 1.0);
111 
113  "Rho never updated by implementation");
114  NS_TEST_ASSERT_MSG_EQ_TOL (calcRho, m_rho, 0.01,
115  "Different rho values between implementation and test");
116 
117  cong->IncreaseWindow (m_state, 1);
118 
119  if (m_cWnd <= m_ssThresh)
120  {
121  // We expect an increment of 2^rho - 1, which does not go beyond ssThresh
122  double inc = std::pow (2, calcRho) - 1.0;
123  uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
125  "Congestion window has gone too far");
126  NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), cWndExpected,
127  "Congestion window different than expected");
128  }
129  else
130  {
131  // We expect an increment of rho^2 / cWnd
132  uint32_t segCwnd = m_cWnd / m_segmentSize;
133  double inc = std::pow (m_rho, 2) / ((double) segCwnd);
134  uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
135 
136  if (inc >= 1.0)
137  {
138  // LT because implementation does not add value less than MSS.
139  NS_TEST_ASSERT_MSG_LT_OR_EQ (m_state->m_cWnd.Get (), cWndExpected,
140  "Congestion window different than expected");
141  }
142  }
143 
144 }
145 
146 
147 
155 {
156 public:
157  TcpHyblaTestSuite () : TestSuite ("tcp-hybla-test", UNIT)
158  {
159  AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (55), "Rho=1.1, slow start"),
160  TestCase::QUICK);
161  AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (100), "Rho=2, slow start"),
162  TestCase::QUICK);
163  AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (750), "Rho=30, slow start"),
164  TestCase::QUICK);
165  AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.55), "Rho=1.1, cong avoid"),
166  TestCase::QUICK);
167  AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.1), "Rho=2, cong avoid"),
168  TestCase::QUICK);
169  AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.75), "Rho=30, cong avoid"),
170  TestCase::QUICK);
171  }
172 };
173 
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
virtual void DoRun(void)
Implementation to actually run this TestCase.
A suite of tests to run.
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:361
void RhoUpdated(double oldVal, double newVal)
Tracks TCP Hybla rho parameter changes.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
TCP Hybla TestSuite.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1078
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
uint32_t m_segmentSize
Segment size.
double m_rho
TCP Hybla rho parameter.
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Try to increase the cWnd following the NewReno specification.
encapsulates test code
Definition: test.h:1153
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition: tcp-hybla.cc:82
uint32_t m_ssThresh
Slow Start Threshold.
#define max(a, b)
Definition: 80211b.c:43
AttributeValue implementation for Time.
Definition: nstime.h:1132
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
#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:166
uint32_t m_cWnd
Congestion window.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1610
#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:378
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:295
Every class exported by the ns3 library is enclosed in the ns3 namespace.
TcpHyblaIncrementTest(uint32_t cWnd, uint32_t ssThresh, uint32_t segmentSize, const Time &rtt, const std::string &name)
Constructor.
TracedValue< uint32_t > m_cWnd
Congestion window.
#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:622
Time m_rtt
Round trip time.
Time Get(void) const
Definition: time.cc:446
Ptr< TcpSocketState > m_state
TCP socket state.
T Get(void) const
Get the underlying value.
Definition: traced-value.h:227
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1070
Time m_minRtt
Minimum RTT observed throughout the connection.
#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:830
uint32_t m_segmentSize
Segment size.
This test suite implements a Unit Test.
Definition: test.h:1353
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:225
static TcpHyblaTestSuite g_tcpHyblaTest
Static variable for test initialization.
Testing the congestion avoidance increment on TcpHybla.