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 
65  double m_rho;
67 };
68 
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 ([[maybe_unused]] double oldVal, double newVal)
83 {
84  m_rho = newVal;
85 }
86 
87 void
89 {
90  m_state = CreateObject<TcpSocketState> ();
91 
96 
97  Ptr<TcpHybla> cong = CreateObject <TcpHybla> ();
98 
99  cong->TraceConnectWithoutContext ("Rho",
101 
102  // Each received ACK weight is "coeffA". To see an increase of 1 MSS, we need
103  // to ACK at least segCwnd/coeffA ACK.
104 
105  TimeValue rRtt;
106  cong->GetAttribute ("RRTT", rRtt);
107  cong->PktsAcked (m_state, 1, m_rtt);
108 
109  double calcRho = std::max (m_rtt.GetSeconds () / rRtt.Get ().GetSeconds (), 1.0);
110 
112  "Rho never updated by implementation");
113  NS_TEST_ASSERT_MSG_EQ_TOL (calcRho, m_rho, 0.01,
114  "Different rho values between implementation and test");
115 
116  cong->IncreaseWindow (m_state, 1);
117 
118  if (m_cWnd <= m_ssThresh)
119  {
120  // We expect an increment of 2^rho - 1, which does not go beyond ssThresh
121  double inc = std::pow (2, calcRho) - 1.0;
122  uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
124  "Congestion window has gone too far");
125  NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), cWndExpected,
126  "Congestion window different than expected");
127  }
128  else
129  {
130  // We expect an increment of rho^2 / cWnd
131  uint32_t segCwnd = m_cWnd / m_segmentSize;
132  double inc = std::pow (m_rho, 2) / ((double) segCwnd);
133  uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
134 
135  if (inc >= 1.0)
136  {
137  // LT because implementation does not add value less than MSS.
138  NS_TEST_ASSERT_MSG_LT_OR_EQ (m_state->m_cWnd.Get (), cWndExpected,
139  "Congestion window different than expected");
140  }
141  }
142 
143 }
144 
145 
146 
154 {
155 public:
156  TcpHyblaTestSuite () : TestSuite ("tcp-hybla-test", UNIT)
157  {
158  AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (55), "Rho=1.1, slow start"),
159  TestCase::QUICK);
160  AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (100), "Rho=2, slow start"),
161  TestCase::QUICK);
162  AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (750), "Rho=30, slow start"),
163  TestCase::QUICK);
164  AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.55), "Rho=1.1, cong avoid"),
165  TestCase::QUICK);
166  AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.1), "Rho=2, cong avoid"),
167  TestCase::QUICK);
168  AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.75), "Rho=30, cong avoid"),
169  TestCase::QUICK);
170  }
171 };
172 
ns3::TcpHybla::PktsAcked
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition: tcp-hybla.cc:82
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_TEST_ASSERT_MSG_LT_OR_EQ
#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:712
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
ns3::TracedValue::Get
T Get(void) const
Get the underlying value.
Definition: traced-value.h:232
TcpHyblaIncrementTest
Testing the congestion avoidance increment on TcpHybla.
Definition: tcp-hybla-test.cc:37
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TcpSocketState::m_segmentSize
uint32_t m_segmentSize
Segment size.
Definition: tcp-socket-state.h:177
TcpHyblaIncrementTest::m_state
Ptr< TcpSocketState > m_state
TCP socket state.
Definition: tcp-hybla-test.cc:66
TcpHyblaIncrementTest::TcpHyblaIncrementTest
TcpHyblaIncrementTest(uint32_t cWnd, uint32_t ssThresh, uint32_t segmentSize, const Time &rtt, const std::string &name)
Constructor.
Definition: tcp-hybla-test.cc:69
TcpHyblaIncrementTest::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: tcp-hybla-test.cc:88
NS_TEST_ASSERT_MSG_NE
#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:542
TcpHyblaTestSuite
TCP Hybla TestSuite.
Definition: tcp-hybla-test.cc:154
ns3::TestCase
encapsulates test code
Definition: test.h:994
ns3::TimeValue::Get
Time Get(void) const
Definition: time.cc:533
ns3::Ptr< TcpSocketState >
max
#define max(a, b)
Definition: 80211b.c:43
double
ns3::ObjectBase::GetAttribute
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:294
NS_TEST_ASSERT_MSG_EQ_TOL
#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:323
ns3::MilliSeconds
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
TcpHyblaIncrementTest::m_rtt
Time m_rtt
Round trip time.
Definition: tcp-hybla-test.cc:64
g_tcpHyblaTest
static TcpHyblaTestSuite g_tcpHyblaTest
Static variable for test initialization.
Definition: tcp-hybla-test.cc:173
TcpHyblaIncrementTest::m_ssThresh
uint32_t m_ssThresh
Slow Start Threshold.
Definition: tcp-hybla-test.cc:62
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
TcpHyblaIncrementTest::m_rho
double m_rho
TCP Hybla rho parameter.
Definition: tcp-hybla-test.cc:65
ns3::MakeCallback
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
ns3::TestSuite
A suite of tests to run.
Definition: test.h:1188
uint32_t
NS_TEST_ASSERT_MSG_EQ
#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:141
ns3::TestSuite::UNIT
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1197
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
TcpHyblaTestSuite::TcpHyblaTestSuite
TcpHyblaTestSuite()
Definition: tcp-hybla-test.cc:156
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1308
segmentSize
uint32_t segmentSize
Definition: tcp-linux-reno.cc:53
ns3::TcpSocketState::m_cWnd
TracedValue< uint32_t > m_cWnd
Congestion window.
Definition: tcp-socket-state.h:165
TcpHyblaIncrementTest::m_segmentSize
uint32_t m_segmentSize
Segment size.
Definition: tcp-hybla-test.cc:63
TcpHyblaIncrementTest::RhoUpdated
void RhoUpdated(double oldVal, double newVal)
Tracks TCP Hybla rho parameter changes.
Definition: tcp-hybla-test.cc:82
ns3::ObjectBase::TraceConnectWithoutContext
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:364
TcpHyblaIncrementTest::m_cWnd
uint32_t m_cWnd
Congestion window.
Definition: tcp-hybla-test.cc:61
ns3::TcpSocketState::m_minRtt
Time m_minRtt
Minimum RTT observed throughout the connection.
Definition: tcp-socket-state.h:198
ns3::TcpSocketState::m_ssThresh
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
Definition: tcp-socket-state.h:167
ns3::Time::GetSeconds
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
ns3::TcpNewReno::IncreaseWindow
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Try to increase the cWnd following the NewReno specification.
Definition: tcp-congestion-ops.cc:212