A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
18
namespace
ns3
19
{
20
21
NS_LOG_COMPONENT_DEFINE
(
"TcpLpTestSuite"
);
22
23
/**
24
* @ingroup internet-test
25
*
26
* @brief Testing the behaviour common to New Reno
27
*/
28
class
TcpLpToNewReno
:
public
TestCase
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
*/
40
TcpLpToNewReno
(
uint32_t
cWnd
,
41
uint32_t
segmentSize
,
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
57
TcpLpToNewReno::TcpLpToNewReno
(
uint32_t
cWnd
,
58
uint32_t
segmentSize
,
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
72
void
73
TcpLpToNewReno::DoRun
()
74
{
75
m_state
=
CreateObject<TcpSocketState>
();
76
m_state
->m_cWnd =
m_cWnd
;
77
m_state
->m_ssThresh =
m_ssThresh
;
78
m_state
->m_segmentSize =
m_segmentSize
;
79
80
Ptr<TcpSocketState>
state =
CreateObject<TcpSocketState>
();
81
state->m_cWnd =
m_cWnd
;
82
state->m_ssThresh =
m_ssThresh
;
83
state->m_segmentSize =
m_segmentSize
;
84
85
Ptr<TcpLp>
cong
=
CreateObject<TcpLp>
();
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
93
Ptr<TcpNewReno>
NewRenoCong
=
CreateObject<TcpNewReno>
();
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"
);
99
Simulator::Run
();
100
Simulator::Destroy
();
101
}
102
103
/**
104
* @ingroup internet-test
105
*
106
* @brief Testing TcpLp when cwd exceeds threshold
107
*/
108
class
TcpLpInferenceTest1
:
public
TestCase
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
*/
119
TcpLpInferenceTest1
(
uint32_t
cWnd
,
120
uint32_t
segmentSize
,
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
135
TcpLpInferenceTest1::TcpLpInferenceTest1
(
uint32_t
cWnd
,
136
uint32_t
segmentSize
,
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
148
void
149
TcpLpInferenceTest1::DoRun
()
150
{
151
m_state
=
CreateObject<TcpSocketState>
();
152
m_state
->m_cWnd =
m_cWnd
;
153
m_state
->m_segmentSize =
m_segmentSize
;
154
155
Ptr<TcpLp>
cong
=
CreateObject<TcpLp>
();
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"
);
168
Simulator::Run
();
169
Simulator::Destroy
();
170
}
171
172
/**
173
* @ingroup internet-test
174
*
175
* @brief Testing TcpLp when it is inference phase
176
*/
177
class
TcpLpInferenceTest2
:
public
TestCase
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
*/
188
TcpLpInferenceTest2
(
uint32_t
cWnd
,
189
uint32_t
segmentSize
,
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
204
TcpLpInferenceTest2::TcpLpInferenceTest2
(
uint32_t
cWnd
,
205
uint32_t
segmentSize
,
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
217
void
218
TcpLpInferenceTest2::DoRun
()
219
{
220
m_state
=
CreateObject<TcpSocketState>
();
221
m_state
->m_cWnd =
m_cWnd
;
222
m_state
->m_segmentSize =
m_segmentSize
;
223
224
Ptr<TcpLp>
cong
=
CreateObject<TcpLp>
();
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"
);
241
Simulator::Run
();
242
Simulator::Destroy
();
243
}
244
245
/**
246
* @ingroup internet-test
247
*
248
* Test the behaviour common to New Reno
249
*/
250
class
TcpLpTestSuite
:
public
TestSuite
251
{
252
public
:
253
TcpLpTestSuite
()
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"
),
262
TestCase::Duration::QUICK
);
263
264
AddTestCase
(
new
TcpLpInferenceTest1
(
265
2 * 1446,
266
1446,
267
2,
268
MilliSeconds
(100),
269
"LP enters Inference phase when cwd exceeds threshold for the first time"
),
270
TestCase::Duration::QUICK
);
271
272
AddTestCase
(
new
TcpLpInferenceTest2
(
273
2 * 1446,
274
1446,
275
2,
276
MilliSeconds
(100),
277
"LP reduces cWnd to 1 if cwd exceeds threshold in inference phase"
),
278
TestCase::Duration::QUICK
);
279
}
280
};
281
282
static
TcpLpTestSuite
g_tcplpTest
;
//!< static var for test initialization
283
284
}
// namespace ns3
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::TcpLpInferenceTest1
Testing TcpLp when cwd exceeds threshold.
Definition
tcp-lp-test.cc:109
ns3::TcpLpInferenceTest1::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
tcp-lp-test.cc:149
ns3::TcpLpInferenceTest1::m_cWnd
uint32_t m_cWnd
Congestion window size.
Definition
tcp-lp-test.cc:128
ns3::TcpLpInferenceTest1::TcpLpInferenceTest1
TcpLpInferenceTest1(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, Time rtt, const std::string &name)
Constructor.
Definition
tcp-lp-test.cc:135
ns3::TcpLpInferenceTest1::m_rtt
Time m_rtt
RTT.
Definition
tcp-lp-test.cc:131
ns3::TcpLpInferenceTest1::m_segmentsAcked
uint32_t m_segmentsAcked
Segments acked.
Definition
tcp-lp-test.cc:130
ns3::TcpLpInferenceTest1::m_state
Ptr< TcpSocketState > m_state
TCP socket state.
Definition
tcp-lp-test.cc:132
ns3::TcpLpInferenceTest1::m_segmentSize
uint32_t m_segmentSize
Segment size.
Definition
tcp-lp-test.cc:129
ns3::TcpLpInferenceTest2
Testing TcpLp when it is inference phase.
Definition
tcp-lp-test.cc:178
ns3::TcpLpInferenceTest2::m_segmentsAcked
uint32_t m_segmentsAcked
Segments acked.
Definition
tcp-lp-test.cc:199
ns3::TcpLpInferenceTest2::m_cWnd
uint32_t m_cWnd
Congestion window size.
Definition
tcp-lp-test.cc:197
ns3::TcpLpInferenceTest2::TcpLpInferenceTest2
TcpLpInferenceTest2(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, Time rtt, const std::string &name)
Constructor.
Definition
tcp-lp-test.cc:204
ns3::TcpLpInferenceTest2::m_segmentSize
uint32_t m_segmentSize
Segment size.
Definition
tcp-lp-test.cc:198
ns3::TcpLpInferenceTest2::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
tcp-lp-test.cc:218
ns3::TcpLpInferenceTest2::m_rtt
Time m_rtt
RTT.
Definition
tcp-lp-test.cc:200
ns3::TcpLpInferenceTest2::m_state
Ptr< TcpSocketState > m_state
TCP socket state.
Definition
tcp-lp-test.cc:201
ns3::TcpLpTestSuite
Test the behaviour common to New Reno.
Definition
tcp-lp-test.cc:251
ns3::TcpLpTestSuite::TcpLpTestSuite
TcpLpTestSuite()
Definition
tcp-lp-test.cc:253
ns3::TcpLpToNewReno
Testing the behaviour common to New Reno.
Definition
tcp-lp-test.cc:29
ns3::TcpLpToNewReno::m_ssThresh
uint32_t m_ssThresh
Slow start threshold.
Definition
tcp-lp-test.cc:51
ns3::TcpLpToNewReno::m_segmentsAcked
uint32_t m_segmentsAcked
Segments acked.
Definition
tcp-lp-test.cc:52
ns3::TcpLpToNewReno::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
tcp-lp-test.cc:73
ns3::TcpLpToNewReno::m_state
Ptr< TcpSocketState > m_state
TCP socket state.
Definition
tcp-lp-test.cc:54
ns3::TcpLpToNewReno::TcpLpToNewReno
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:57
ns3::TcpLpToNewReno::m_rtt
Time m_rtt
RTT.
Definition
tcp-lp-test.cc:53
ns3::TcpLpToNewReno::m_cWnd
uint32_t m_cWnd
Congestion window size.
Definition
tcp-lp-test.cc:49
ns3::TcpLpToNewReno::m_segmentSize
uint32_t m_segmentSize
Segment size.
Definition
tcp-lp-test.cc:50
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestCase::Duration::QUICK
@ QUICK
Fast test.
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::TestSuite::UNIT
static constexpr auto UNIT
Definition
test.h:1291
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition
nstime.h:94
uint32_t
segmentSize
uint32_t segmentSize
Definition
tcp-linux-reno.cc:42
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
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:134
ns3::MilliSeconds
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition
nstime.h:1356
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::g_tcplpTest
static TcpLpTestSuite g_tcplpTest
static var for test initialization
Definition
tcp-lp-test.cc:282
src
internet
test
tcp-lp-test.cc
Generated on Mon Dec 15 2025 15:21:55 for ns-3 by
1.9.8