A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-lp-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 NITK Surathkal
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Charitha Sangaraju <charitha29193@gmail.com>
7 * Nandita G <gm.nandita@gmail.com>
8 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
9 *
10 */
11
12#include "ns3/log.h"
13#include "ns3/tcp-congestion-ops.h"
14#include "ns3/tcp-lp.h"
15#include "ns3/tcp-socket-base.h"
16#include "ns3/test.h"
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("TcpLpTestSuite");
22
23/**
24 * @ingroup internet-test
25 *
26 * @brief Testing the behaviour common to New Reno
27 */
29{
30 public:
31 /**
32 * Constructor
33 * @param cWnd Congestion window size
34 * @param segmentSize Segment size
35 * @param segmentsAcked Segments acked
36 * @param ssThresh Slow start threshold
37 * @param rtt RTT
38 * @param name Test case name
39 */
42 uint32_t segmentsAcked,
43 uint32_t ssThresh,
44 Time rtt,
45 const std::string& name);
46
47 private:
48 void DoRun() override;
49 uint32_t m_cWnd; //!< Congestion window size
50 uint32_t m_segmentSize; //!< Segment size
51 uint32_t m_ssThresh; //!< Slow start threshold
52 uint32_t m_segmentsAcked; //!< Segments acked
53 Time m_rtt; //!< RTT
54 Ptr<TcpSocketState> m_state; //!< TCP socket state
55};
56
59 uint32_t segmentsAcked,
60 uint32_t ssThresh,
61 Time rtt,
62 const std::string& name)
63 : TestCase(name),
64 m_cWnd(cWnd),
65 m_segmentSize(segmentSize),
66 m_ssThresh(ssThresh),
67 m_segmentsAcked(segmentsAcked),
68 m_rtt(rtt)
69{
70}
71
72void
74{
76 m_state->m_cWnd = m_cWnd;
77 m_state->m_ssThresh = m_ssThresh;
78 m_state->m_segmentSize = m_segmentSize;
79
81 state->m_cWnd = m_cWnd;
82 state->m_ssThresh = m_ssThresh;
83 state->m_segmentSize = m_segmentSize;
84
86
87 m_state->m_rcvTimestampValue = 2;
88 m_state->m_rcvTimestampEchoReply = 1;
89
90 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
91 cong->IncreaseWindow(m_state, m_segmentsAcked);
92
94 NewRenoCong->IncreaseWindow(state, m_segmentsAcked);
95
96 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(),
97 state->m_cWnd.Get(),
98 "cWnd has not updated correctly");
101}
102
103/**
104 * @ingroup internet-test
105 *
106 * @brief Testing TcpLp when cwd exceeds threshold
107 */
109{
110 public:
111 /**
112 * Constructor
113 * @param cWnd Congestion window size
114 * @param segmentSize Segment size
115 * @param segmentsAcked Segments acked
116 * @param rtt RTT
117 * @param name Test case name
118 */
121 uint32_t segmentsAcked,
122 Time rtt,
123 const std::string& name);
124
125 private:
126 void DoRun() override;
127
128 uint32_t m_cWnd; //!< Congestion window size
129 uint32_t m_segmentSize; //!< Segment size
130 uint32_t m_segmentsAcked; //!< Segments acked
131 Time m_rtt; //!< RTT
132 Ptr<TcpSocketState> m_state; //!< TCP socket state
133};
134
137 uint32_t segmentsAcked,
138 Time rtt,
139 const std::string& name)
140 : TestCase(name),
141 m_cWnd(cWnd),
142 m_segmentSize(segmentSize),
143 m_segmentsAcked(segmentsAcked),
144 m_rtt(rtt)
145{
146}
147
148void
150{
152 m_state->m_cWnd = m_cWnd;
153 m_state->m_segmentSize = m_segmentSize;
154
156
157 m_state->m_rcvTimestampValue = 2;
158 m_state->m_rcvTimestampEchoReply = 1;
159
160 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
161
162 m_state->m_rcvTimestampValue = 14;
163 m_state->m_rcvTimestampEchoReply = 4;
164 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
165
166 m_cWnd = m_cWnd / 2;
167 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(), m_cWnd, "cWnd has not updated correctly");
170}
171
172/**
173 * @ingroup internet-test
174 *
175 * @brief Testing TcpLp when it is inference phase
176 */
178{
179 public:
180 /**
181 * Constructor
182 * @param cWnd Congestion window size
183 * @param segmentSize Segment size
184 * @param segmentsAcked Segments acked
185 * @param rtt RTT
186 * @param name Test case name
187 */
190 uint32_t segmentsAcked,
191 Time rtt,
192 const std::string& name);
193
194 private:
195 void DoRun() override;
196
197 uint32_t m_cWnd; //!< Congestion window size
198 uint32_t m_segmentSize; //!< Segment size
199 uint32_t m_segmentsAcked; //!< Segments acked
200 Time m_rtt; //!< RTT
201 Ptr<TcpSocketState> m_state; //!< TCP socket state
202};
203
206 uint32_t segmentsAcked,
207 Time rtt,
208 const std::string& name)
209 : TestCase(name),
210 m_cWnd(cWnd),
211 m_segmentSize(segmentSize),
212 m_segmentsAcked(segmentsAcked),
213 m_rtt(rtt)
214{
215}
216
217void
219{
221 m_state->m_cWnd = m_cWnd;
222 m_state->m_segmentSize = m_segmentSize;
223
225
226 m_state->m_rcvTimestampValue = 2;
227 m_state->m_rcvTimestampEchoReply = 1;
228 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
229
230 m_state->m_rcvTimestampValue = 14;
231 m_state->m_rcvTimestampEchoReply = 4;
232 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
233
234 m_state->m_rcvTimestampValue = 25;
235 m_state->m_rcvTimestampEchoReply = 15;
236 cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
237
238 m_cWnd = 1U * m_segmentSize;
239
240 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(), m_cWnd, "cWnd has not updated correctly");
243}
244
245/**
246 * @ingroup internet-test
247 *
248 * Test the behaviour common to New Reno
249 */
251{
252 public:
254 : TestSuite("tcp-lp-test", Type::UNIT)
255 {
256 AddTestCase(new TcpLpToNewReno(4 * 1446,
257 1446,
258 2,
259 2 * 1446,
260 MilliSeconds(100),
261 "LP falls to New Reno if the cwd is within threshold"),
263
265 2 * 1446,
266 1446,
267 2,
268 MilliSeconds(100),
269 "LP enters Inference phase when cwd exceeds threshold for the first time"),
271
273 2 * 1446,
274 1446,
275 2,
276 MilliSeconds(100),
277 "LP reduces cWnd to 1 if cwd exceeds threshold in inference phase"),
279 }
280};
281
282static TcpLpTestSuite g_tcplpTest; //!< static var for test initialization
283
284} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
Testing TcpLp when cwd exceeds threshold.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_cWnd
Congestion window size.
TcpLpInferenceTest1(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, Time rtt, const std::string &name)
Constructor.
uint32_t m_segmentsAcked
Segments acked.
Ptr< TcpSocketState > m_state
TCP socket state.
uint32_t m_segmentSize
Segment size.
Testing TcpLp when it is inference phase.
uint32_t m_segmentsAcked
Segments acked.
uint32_t m_cWnd
Congestion window size.
TcpLpInferenceTest2(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, Time rtt, const std::string &name)
Constructor.
uint32_t m_segmentSize
Segment size.
void DoRun() override
Implementation to actually run this TestCase.
Ptr< TcpSocketState > m_state
TCP socket state.
Test the behaviour common to New Reno.
Testing the behaviour common to New Reno.
uint32_t m_ssThresh
Slow start threshold.
uint32_t m_segmentsAcked
Segments acked.
void DoRun() override
Implementation to actually run this TestCase.
Ptr< TcpSocketState > m_state
TCP socket state.
TcpLpToNewReno(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, uint32_t ssThresh, Time rtt, const std::string &name)
Constructor.
uint32_t m_cWnd
Congestion window size.
uint32_t m_segmentSize
Segment size.
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:134
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1356
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpLpTestSuite g_tcplpTest
static var for test initialization