A Discrete-Event Network Simulator
API
tcp-highspeed-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-highspeed.h"
25 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("TcpHighSpeedTestSuite");
29 
34 {
35 public:
36  TcpHighSpeedIncrementTest (uint32_t cWnd, uint32_t segmentSize,
37  const std::string &name);
38 
39 private:
40  virtual void DoRun (void);
41 
42  uint32_t m_cWnd;
43  uint32_t m_segmentSize;
45 };
46 
48  uint32_t segmentSize,
49  const std::string &name)
50  : TestCase (name),
51  m_cWnd (cWnd),
52  m_segmentSize (segmentSize)
53 {
54 }
55 
56 void
58 {
59  m_state = CreateObject<TcpSocketState> ();
60 
61  m_state->m_cWnd = m_cWnd;
62  m_state->m_segmentSize = m_segmentSize;
63 
64  Ptr<TcpHighSpeed> cong = CreateObject <TcpHighSpeed> ();
65 
66  uint32_t segCwnd = m_cWnd / m_segmentSize;
67  uint32_t coeffA = TcpHighSpeed::TableLookupA (segCwnd);
68 
69  // Each received ACK weight is "coeffA". To see an increase of 1 MSS, we need
70  // to ACK at least segCwnd/coeffA ACK.
71 
72  cong->IncreaseWindow (m_state, (segCwnd / coeffA) + 1);
73 
75  "CWnd has not increased");
76 }
77 
82 {
83 public:
84  TcpHighSpeedDecrementTest (uint32_t ssThresh, uint32_t segmentSize,
85  const std::string &name);
86 
87 private:
88  virtual void DoRun (void);
89 
90  uint32_t m_cWnd;
91  uint32_t m_segmentSize;
93 };
94 
96  uint32_t segmentSize,
97  const std::string &name)
98  : TestCase (name),
99  m_cWnd (cWnd),
100  m_segmentSize (segmentSize)
101 {
102 }
103 
104 void
106 {
107  m_state = CreateObject<TcpSocketState> ();
108 
109  m_state->m_cWnd = m_cWnd;
110  m_state->m_segmentSize = m_segmentSize;
111 
112  Ptr<TcpHighSpeed> cong = CreateObject <TcpHighSpeed> ();
113 
114  uint32_t segCwnd = m_cWnd / m_segmentSize;
115  double coeffB = 1.0 - TcpHighSpeed::TableLookupB (segCwnd);
116 
117  uint32_t ret = cong->GetSsThresh (m_state, m_state->m_cWnd);
118 
119  uint32_t ssThHS = std::max (2.0, segCwnd * coeffB);
120 
121  NS_TEST_ASSERT_MSG_EQ (ret / m_segmentSize, ssThHS,
122  "HighSpeed decrement fn not used");
123 }
124 
125 
126 // -------------------------------------------------------------------
127 
128 static const struct HighSpeedImportantValues
129 {
130  unsigned int cwnd;
131  unsigned int md;
133  { 38, 128, /* 0.50 */ },
134  { 118, 112, /* 0.44 */ },
135  { 221, 104, /* 0.41 */ },
136  { 347, 98, /* 0.38 */ },
137  { 495, 93, /* 0.37 */ },
138  { 663, 89, /* 0.35 */ },
139  { 851, 86, /* 0.34 */ },
140  { 1058, 83, /* 0.33 */ },
141  { 1284, 81, /* 0.32 */ },
142  { 1529, 78, /* 0.31 */ },
143  { 1793, 76, /* 0.30 */ },
144  { 2076, 74, /* 0.29 */ },
145  { 2378, 72, /* 0.28 */ },
146  { 2699, 71, /* 0.28 */ },
147  { 3039, 69, /* 0.27 */ },
148  { 3399, 68, /* 0.27 */ },
149  { 3778, 66, /* 0.26 */ },
150  { 4177, 65, /* 0.26 */ },
151  { 4596, 64, /* 0.25 */ },
152  { 5036, 62, /* 0.25 */ },
153  { 5497, 61, /* 0.24 */ },
154  { 5979, 60, /* 0.24 */ },
155  { 6483, 59, /* 0.23 */ },
156  { 7009, 58, /* 0.23 */ },
157  { 7558, 57, /* 0.22 */ },
158  { 8130, 56, /* 0.22 */ },
159  { 8726, 55, /* 0.22 */ },
160  { 9346, 54, /* 0.21 */ },
161  { 9991, 53, /* 0.21 */ },
162  { 10661, 52, /* 0.21 */ },
163  { 11358, 52, /* 0.20 */ },
164  { 12082, 51, /* 0.20 */ },
165  { 12834, 50, /* 0.20 */ },
166  { 13614, 49, /* 0.19 */ },
167  { 14424, 48, /* 0.19 */ },
168  { 15265, 48, /* 0.19 */ },
169  { 16137, 47, /* 0.19 */ },
170  { 17042, 46, /* 0.18 */ },
171  { 17981, 45, /* 0.18 */ },
172  { 18955, 45, /* 0.18 */ },
173  { 19965, 44, /* 0.17 */ },
174  { 21013, 43, /* 0.17 */ },
175  { 22101, 43, /* 0.17 */ },
176  { 23230, 42, /* 0.17 */ },
177  { 24402, 41, /* 0.16 */ },
178  { 25618, 41, /* 0.16 */ },
179  { 26881, 40, /* 0.16 */ },
180  { 28193, 39, /* 0.16 */ },
181  { 29557, 39, /* 0.15 */ },
182  { 30975, 38, /* 0.15 */ },
183  { 32450, 38, /* 0.15 */ },
184  { 33986, 37, /* 0.15 */ },
185  { 35586, 36, /* 0.14 */ },
186  { 37253, 36, /* 0.14 */ },
187  { 38992, 35, /* 0.14 */ },
188  { 40808, 35, /* 0.14 */ },
189  { 42707, 34, /* 0.13 */ },
190  { 44694, 33, /* 0.13 */ },
191  { 46776, 33, /* 0.13 */ },
192  { 48961, 32, /* 0.13 */ },
193  { 51258, 32, /* 0.13 */ },
194  { 53677, 31, /* 0.12 */ },
195  { 56230, 30, /* 0.12 */ },
196  { 58932, 30, /* 0.12 */ },
197  { 61799, 29, /* 0.12 */ },
198  { 64851, 28, /* 0.11 */ },
199  { 68113, 28, /* 0.11 */ },
200  { 71617, 27, /* 0.11 */ },
201  { 75401, 26, /* 0.10 */ },
202  { 79517, 26, /* 0.10 */ },
203  { 84035, 25, /* 0.10 */ },
204  { 89053, 24, /* 0.10 */ },
205 };
206 
207 #define HIGHSPEED_VALUES_N 71
208 
209 static class TcpHighSpeedTestSuite : public TestSuite
210 {
211 public:
212  TcpHighSpeedTestSuite () : TestSuite ("tcp-highspeed-test", UNIT)
213  {
214  std::stringstream ss;
215 
216  for (uint32_t i = 0; i < HIGHSPEED_VALUES_N; ++i)
217  {
220  "Highspeed increment test on cWnd " + ss.str ()),
223  "Highspeed increment test on cWnd " + ss.str ()),
226  "Highspeed increment test on cWnd " + ss.str ()),
229  "Highspeed Decrement test on cWnd " + ss.str ()),
232  "Highspeed Decrement test on cWnd " + ss.str ()),
235  "Highspeed Decrement test on cWnd " + ss.str ()),
237  ss.flush ();
238  }
239  }
241 
242 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Testing the congestion avoidance increment on TcpHighSpeed.
Fast test.
Definition: test.h:1152
A suite of tests to run.
Definition: test.h:1333
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
encapsulates test code
Definition: test.h:1147
This test suite implements a Unit Test.
Definition: test.h:1343
static double TableLookupB(uint32_t w)
Lookup table for the coefficent b (from RFC 3649)
TcpHighSpeedIncrementTest(uint32_t cWnd, uint32_t segmentSize, const std::string &name)
static uint32_t TableLookupA(uint32_t w)
Lookup table for the coefficent a (from RFC 3649)
virtual void DoRun(void)
Implementation to actually run this TestCase.
#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
#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
#define HIGHSPEED_VALUES_N
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Testing the congestion avoidance increment on TcpHighSpeed.
static const struct ns3::HighSpeedImportantValues highSpeedImportantValues[]
TcpHighSpeedDecrementTest(uint32_t ssThresh, uint32_t segmentSize, const std::string &name)
virtual void DoRun(void)
Implementation to actually run this TestCase.
ns3::TcpHighSpeedTestSuite g_tcpHighSpeedTest