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  m_rho = newVal;
85 }
86 
87 void
89 {
90  m_state = CreateObject<TcpSocketState> ();
91 
95 
96  Ptr<TcpHybla> cong = CreateObject <TcpHybla> ();
97 
98  cong->TraceConnectWithoutContext ("Rho",
100 
101  // Each received ACK weight is "coeffA". To see an increase of 1 MSS, we need
102  // to ACK at least segCwnd/coeffA ACK.
103 
104  TimeValue rRtt;
105  cong->GetAttribute ("RRTT", rRtt);
106  cong->PktsAcked (m_state, 1, m_rtt);
107 
108  double calcRho = std::max (m_rtt.GetSeconds () / rRtt.Get ().GetSeconds (), 1.0);
109 
111  "Rho never updated by implementation");
113  "Different rho values between implementation and test");
114 
115  cong->IncreaseWindow (m_state, 1);
116 
117  if (m_cWnd <= m_ssThresh)
118  {
119  // We expect an increment of 2^rho - 1, which does not go beyond ssThresh
120  double inc = std::pow (2, calcRho) - 1.0;
121  uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
123  "Congestion window has gone too far");
124  NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), cWndExpected,
125  "Congestion window different than expected");
126  }
127  else
128  {
129  // We expect an increment of rho^2 / cWnd
130  uint32_t segCwnd = m_cWnd / m_segmentSize;
131  double inc = std::pow (m_rho, 2) / ((double) segCwnd);
132  uint32_t cWndExpected = m_cWnd + (inc * m_segmentSize);
133 
134  if (inc >= 1.0)
135  {
136  // LT because implementation does not add value less than MSS.
137  NS_TEST_ASSERT_MSG_LT_OR_EQ (m_state->m_cWnd.Get (), cWndExpected,
138  "Congestion window different than expected");
139  }
140  }
141 
142 }
143 
144 
145 
153 {
154 public:
155  TcpHyblaTestSuite () : TestSuite ("tcp-hybla-test", UNIT)
156  {
157  AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (55), "Rho=1.1, slow start"),
158  TestCase::QUICK);
159  AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (100), "Rho=2, slow start"),
160  TestCase::QUICK);
161  AddTestCase (new TcpHyblaIncrementTest (1000, 0xFFFFFFFF, 500, MilliSeconds (750), "Rho=30, slow start"),
162  TestCase::QUICK);
163  AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.55), "Rho=1.1, cong avoid"),
164  TestCase::QUICK);
165  AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.1), "Rho=2, cong avoid"),
166  TestCase::QUICK);
167  AddTestCase (new TcpHyblaIncrementTest (1000, 500, 500, Seconds (0.75), "Rho=30, cong avoid"),
168  TestCase::QUICK);
169  }
170 };
171 
Time Get(void) const
Definition: time.cc:443
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-hybla.cc:83
virtual void DoRun(void)
Implementation to actually run this TestCase.
A suite of tests to run.
Definition: test.h:1342
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:201
TCP Hybla TestSuite.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1001
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:1155
This test suite implements a Unit Test.
Definition: test.h:1352
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
uint32_t m_ssThresh
Slow Start Threshold.
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
AttributeValue implementation for Time.
Definition: nstime.h:1055
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:168
uint32_t m_cWnd
Congestion window.
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:380
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:293
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.
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:223
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:624
Time m_rtt
Round trip time.
Ptr< TcpSocketState > m_state
TCP socket state.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
#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:832
uint32_t m_segmentSize
Segment size.
static TcpHyblaTestSuite g_tcpHyblaTest
Static variable for test initialization.
Testing the congestion avoidance increment on TcpHybla.