A Discrete-Event Network Simulator
API
tcp-lp-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 NITK Surathkal
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  * Authors: Charitha Sangaraju <charitha29193@gmail.com>
19  * Nandita G <gm.nandita@gmail.com>
20  * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
21  *
22  */
23 
24 #include "ns3/test.h"
25 #include "ns3/log.h"
26 #include "ns3/tcp-congestion-ops.h"
27 #include "ns3/tcp-socket-base.h"
28 #include "ns3/tcp-lp.h"
29 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("TcpLpTestSuite");
33 
40 class TcpLpToNewReno : public TestCase
41 {
42 public:
52  TcpLpToNewReno (uint32_t cWnd, uint32_t segmentSize,
53  uint32_t segmentsAcked, uint32_t ssThresh, Time rtt, const std::string &name);
54 
55 private:
56  virtual void DoRun (void);
57  uint32_t m_cWnd;
58  uint32_t m_segmentSize;
59  uint32_t m_ssThresh;
60  uint32_t m_segmentsAcked;
63 };
64 
66  uint32_t segmentsAcked, uint32_t ssThresh, Time rtt, const std::string &name)
67  : TestCase (name),
68  m_cWnd (cWnd),
69  m_segmentSize (segmentSize),
70  m_ssThresh (ssThresh),
71  m_segmentsAcked (segmentsAcked),
72  m_rtt (rtt)
73 {
74 }
75 
76 void
78 {
79  m_state = CreateObject <TcpSocketState> ();
83 
84  Ptr<TcpSocketState> state = CreateObject <TcpSocketState> ();
85  state->m_cWnd = m_cWnd;
86  state->m_ssThresh = m_ssThresh;
88 
89  Ptr<TcpLp> cong = CreateObject <TcpLp> ();
90 
93 
94  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
95  cong->IncreaseWindow (m_state, m_segmentsAcked);
96 
97  Ptr<TcpNewReno> NewRenoCong = CreateObject <TcpNewReno> ();
98  NewRenoCong->IncreaseWindow (state, m_segmentsAcked);
99 
101  "cWnd has not updated correctly");
102  Simulator::Run ();
104 }
105 
113 {
114 public:
123  TcpLpInferenceTest1 (uint32_t cWnd, uint32_t segmentSize,
124  uint32_t segmentsAcked, Time rtt, const std::string &name);
125 
126 private:
127  virtual void DoRun (void);
128 
129  uint32_t m_cWnd;
130  uint32_t m_segmentSize;
131  uint32_t m_segmentsAcked;
134 };
135 
137  uint32_t segmentsAcked, Time rtt, const std::string &name)
138  : TestCase (name),
139  m_cWnd (cWnd),
140  m_segmentSize (segmentSize),
141  m_segmentsAcked (segmentsAcked),
142  m_rtt (rtt)
143 {
144 }
145 
146 void
148 {
149  m_state = CreateObject <TcpSocketState> ();
150  m_state->m_cWnd = m_cWnd;
152 
153  Ptr<TcpLp> cong = CreateObject <TcpLp> ();
154 
157 
158  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
159 
162  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
163 
164  m_cWnd = m_cWnd / 2;
166  "cWnd has not updated correctly");
167  Simulator::Run ();
169 }
170 
178 {
179 public:
188  TcpLpInferenceTest2 (uint32_t cWnd, uint32_t segmentSize,
189  uint32_t segmentsAcked, Time rtt, const std::string &name);
190 
191 private:
192  virtual void DoRun (void);
193 
194  uint32_t m_cWnd;
195  uint32_t m_segmentSize;
196  uint32_t m_segmentsAcked;
199 };
200 
201 TcpLpInferenceTest2::TcpLpInferenceTest2 (uint32_t cWnd, uint32_t segmentSize,uint32_t segmentsAcked, Time rtt, const std::string &name)
202  : TestCase (name),
203  m_cWnd (cWnd),
204  m_segmentSize (segmentSize),
205  m_segmentsAcked (segmentsAcked),
206  m_rtt (rtt)
207 {
208 }
209 
210 void
212 {
213  m_state = CreateObject <TcpSocketState> ();
214  m_state->m_cWnd = m_cWnd;
216 
217  Ptr<TcpLp> cong = CreateObject <TcpLp> ();
218 
221  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
222 
225  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
226 
229  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
230 
231  m_cWnd = 1U * m_segmentSize;
232 
234  "cWnd has not updated correctly");
235  Simulator::Run ();
237 }
238 
245 class TcpLpTestSuite : public TestSuite
246 {
247 public:
248  TcpLpTestSuite () : TestSuite ("tcp-lp-test", UNIT)
249  {
250  AddTestCase (new TcpLpToNewReno (4 * 1446, 1446, 2, 2 * 1446, MilliSeconds (100), "LP falls to New Reno if the cwd is within threshold"), TestCase::QUICK);
251 
252  AddTestCase (new TcpLpInferenceTest1 (2 * 1446, 1446, 2, MilliSeconds (100), "LP enters Inference phase when cwd exceeds threshold for the first time"), TestCase::QUICK);
253 
254  AddTestCase (new TcpLpInferenceTest2 (2 * 1446, 1446, 2, MilliSeconds (100), "LP reduces cWnd to 1 if cwd exceeds threshold in inference phase"), TestCase::QUICK);
255  }
256 };
257 
259 
260 }
Testing the behaviour common to New Reno.
Definition: tcp-lp-test.cc:40
uint32_t m_rcvTimestampValue
Receiver Timestamp value.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Ptr< TcpSocketState > m_state
TCP socket state.
Definition: tcp-lp-test.cc:62
A suite of tests to run.
Definition: test.h:1343
uint32_t m_rcvTimestampEchoReply
Sender Timestamp echoed by the receiver.
uint32_t m_cWnd
Congestion window size.
Definition: tcp-lp-test.cc:129
uint32_t segmentSize
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1297
uint32_t m_segmentSize
Segment size.
Definition: tcp-lp-test.cc:195
uint32_t m_segmentSize
Segment size.
uint32_t m_segmentsAcked
Segments acked.
Definition: tcp-lp-test.cc:60
TcpLpToNewReno(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, uint32_t ssThresh, Time rtt, const std::string &name)
Constructor.
Definition: tcp-lp-test.cc:65
encapsulates test code
Definition: test.h:1153
TcpLpInferenceTest2(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, Time rtt, const std::string &name)
Constructor.
Definition: tcp-lp-test.cc:201
Ptr< TcpSocketState > m_state
TCP socket state.
Definition: tcp-lp-test.cc:133
uint32_t m_segmentSize
Segment size.
Definition: tcp-lp-test.cc:130
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_segmentsAcked
Segments acked.
Definition: tcp-lp-test.cc:131
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
Test the behaviour common to New Reno.
Definition: tcp-lp-test.cc:245
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpLpTestSuite g_tcplpTest
static var for test initialization
Definition: tcp-lp-test.cc:258
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: tcp-lp-test.cc:211
Ptr< TcpSocketState > m_state
TCP socket state.
Definition: tcp-lp-test.cc:198
uint32_t m_cWnd
Congestion window size.
Definition: tcp-lp-test.cc:57
TracedValue< uint32_t > m_cWnd
Congestion window.
Fast test.
Definition: test.h:1159
Testing TcpLp when cwd exceeds threshold.
Definition: tcp-lp-test.cc:112
T Get(void) const
Get the underlying value.
Definition: traced-value.h:229
TcpLpInferenceTest1(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, Time rtt, const std::string &name)
Constructor.
Definition: tcp-lp-test.cc:136
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: tcp-lp-test.cc:77
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: tcp-lp-test.cc:147
uint32_t m_segmentsAcked
Segments acked.
Definition: tcp-lp-test.cc:196
uint32_t m_ssThresh
Slow start threshold.
Definition: tcp-lp-test.cc:59
This test suite implements a Unit Test.
Definition: test.h:1353
Testing TcpLp when it is inference phase.
Definition: tcp-lp-test.cc:177
uint32_t m_cWnd
Congestion window size.
Definition: tcp-lp-test.cc:194
uint32_t m_segmentSize
Segment size.
Definition: tcp-lp-test.cc:58