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-classic-recovery-test.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2018 NITK Surathkal
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Viyom Mittal <viyommittal@gmail.com>
7
* Vivek Jain <jain.vivek.anand@gmail.com>
8
* Mohit P. Tahiliani <tahiliani@nitk.edu.in>
9
*
10
*/
11
12
#include "ns3/log.h"
13
#include "ns3/string.h"
14
#include "ns3/tcp-congestion-ops.h"
15
#include "ns3/tcp-recovery-ops.h"
16
#include "ns3/tcp-socket-base.h"
17
#include "ns3/test.h"
18
19
using namespace
ns3
;
20
21
NS_LOG_COMPONENT_DEFINE
(
"TcpClassicRecoveryTestSuite"
);
22
23
/**
24
* @brief Classic Recovery algorithm test
25
*/
26
class
ClassicRecoveryTest
:
public
TestCase
27
{
28
public
:
29
/**
30
* @brief Constructor.
31
* @param cWnd Congestion window.
32
* @param segmentSize Segment size.
33
* @param ssThresh Slow Start Threshold.
34
* @param dupAckCount Duplicate acknowledgement Threshold.
35
* @param name Test description.
36
*/
37
ClassicRecoveryTest
(
uint32_t
cWnd,
38
uint32_t
segmentSize
,
39
uint32_t
ssThresh,
40
uint32_t
dupAckCount,
41
const
std::string& name);
42
43
private
:
44
void
DoRun
()
override
;
45
46
uint32_t
m_cWnd
;
//!< Congestion window.
47
uint32_t
m_segmentSize
;
//!< Segment size.
48
uint32_t
m_ssThresh
;
//!< Slow Start Threshold.
49
uint32_t
m_dupAckCount
;
//!< Duplicate acknowledgement Threshold.
50
51
Ptr<TcpSocketState>
m_state
;
//!< TCP socket state.
52
};
53
54
ClassicRecoveryTest::ClassicRecoveryTest
(
uint32_t
cWnd,
55
uint32_t
segmentSize
,
56
uint32_t
ssThresh,
57
uint32_t
dupAckCount,
58
const
std::string& name)
59
:
TestCase
(name),
60
m_cWnd(cWnd),
61
m_segmentSize(
segmentSize
),
62
m_ssThresh(ssThresh),
63
m_dupAckCount(dupAckCount)
64
{
65
}
66
67
void
68
ClassicRecoveryTest::DoRun
()
69
{
70
m_state
=
CreateObject<TcpSocketState>
();
71
72
m_state
->m_cWnd =
m_cWnd
;
73
m_state
->m_segmentSize =
m_segmentSize
;
74
m_state
->m_ssThresh =
m_ssThresh
;
75
76
Ptr<TcpClassicRecovery>
recovery =
CreateObject<TcpClassicRecovery>
();
77
78
NS_TEST_ASSERT_MSG_EQ
(recovery->GetName(),
79
"TcpClassicRecovery"
,
80
"The name of recovery used should be TcpClassicRecovery"
);
81
82
recovery->EnterRecovery(
m_state
,
m_dupAckCount
, 1000, 0);
83
NS_TEST_ASSERT_MSG_EQ
(
m_state
->m_cWnd,
84
m_state
->m_ssThresh,
85
"cWnd should be set to ssThresh on entering recovery"
);
86
NS_TEST_ASSERT_MSG_EQ
(
87
m_state
->m_cWndInfl,
88
(
m_state
->m_ssThresh + (
m_dupAckCount
*
m_state
->m_segmentSize)),
89
"cWndInfl should be set to (ssThresh + dupAckCount * segmentSize) on entering recovery"
);
90
91
uint32_t
cWndInflPrevious =
m_state
->m_cWndInfl;
92
uint32_t
cWndPrevious =
m_state
->m_cWnd;
93
recovery->DoRecovery(
m_state
, 500,
false
);
94
NS_TEST_ASSERT_MSG_EQ
(
95
m_state
->m_cWndInfl,
96
(cWndInflPrevious +
m_state
->m_segmentSize),
97
"m_cWndInfl should be increased by one segmentSize on calling DoRecovery"
);
98
NS_TEST_ASSERT_MSG_EQ
(
m_state
->m_cWnd, cWndPrevious,
"cWnd should not change in recovery"
);
99
100
recovery->ExitRecovery(
m_state
);
101
NS_TEST_ASSERT_MSG_EQ
(
m_state
->m_cWndInfl,
102
m_state
->m_ssThresh,
103
"cWndInfl should be set to ssThresh on exiting recovery"
);
104
NS_TEST_ASSERT_MSG_EQ
(
m_state
->m_cWnd,
105
m_state
->m_ssThresh,
106
"cWnd should be set to ssThresh on exiting recovery"
);
107
}
108
109
/**
110
* @ingroup internet-test
111
*
112
* @brief Classic Recovery TestSuite
113
*/
114
class
ClassicRecoveryTestSuite
:
public
TestSuite
115
{
116
public
:
117
ClassicRecoveryTestSuite
()
118
:
TestSuite
(
"tcp-classic-recovery-test"
,
Type
::
UNIT
)
119
{
120
AddTestCase
(
new
ClassicRecoveryTest
(3000,
121
500,
122
2500,
123
3,
124
"Classic recovery test with 500 bytes segmentSize"
),
125
TestCase::Duration::QUICK);
126
AddTestCase
(
new
ClassicRecoveryTest
(3000,
127
1000,
128
2500,
129
3,
130
"Classic recovery test with 1000 bytes segmentSize"
),
131
TestCase::Duration::QUICK);
132
AddTestCase
(
new
ClassicRecoveryTest
(3000,
133
500,
134
2500,
135
4,
136
"Classic recovery test with 4 DupAck threshold"
),
137
TestCase::Duration::QUICK);
138
AddTestCase
(
new
ClassicRecoveryTest
(3000,
139
500,
140
1000,
141
3,
142
"Classic recovery test with 1000 bytes ssThresh"
),
143
TestCase::Duration::QUICK);
144
AddTestCase
(
new
ClassicRecoveryTest
(2500,
145
500,
146
2500,
147
3,
148
"Classic recovery test with same cWnd and ssThresh"
),
149
TestCase::Duration::QUICK);
150
AddTestCase
(
new
ClassicRecoveryTest
(1000,
151
500,
152
2500,
153
3,
154
"Classic recovery test with cWnd lesser than ssThresh"
),
155
TestCase::Duration::QUICK);
156
}
157
};
158
159
static
ClassicRecoveryTestSuite
160
g_TcpClassicRecoveryTest
;
//!< Static variable for test initialization
ClassicRecoveryTest
Classic Recovery algorithm test.
Definition
tcp-classic-recovery-test.cc:27
ClassicRecoveryTest::ClassicRecoveryTest
ClassicRecoveryTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, uint32_t dupAckCount, const std::string &name)
Constructor.
Definition
tcp-classic-recovery-test.cc:54
ClassicRecoveryTest::m_cWnd
uint32_t m_cWnd
Congestion window.
Definition
tcp-classic-recovery-test.cc:46
ClassicRecoveryTest::m_state
Ptr< TcpSocketState > m_state
TCP socket state.
Definition
tcp-classic-recovery-test.cc:51
ClassicRecoveryTest::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
tcp-classic-recovery-test.cc:68
ClassicRecoveryTest::m_ssThresh
uint32_t m_ssThresh
Slow Start Threshold.
Definition
tcp-classic-recovery-test.cc:48
ClassicRecoveryTest::m_dupAckCount
uint32_t m_dupAckCount
Duplicate acknowledgement Threshold.
Definition
tcp-classic-recovery-test.cc:49
ClassicRecoveryTest::m_segmentSize
uint32_t m_segmentSize
Segment size.
Definition
tcp-classic-recovery-test.cc:47
ClassicRecoveryTestSuite
Classic Recovery TestSuite.
Definition
tcp-classic-recovery-test.cc:115
ClassicRecoveryTestSuite::ClassicRecoveryTestSuite
ClassicRecoveryTestSuite()
Definition
tcp-classic-recovery-test.cc:117
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
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::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
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::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
g_TcpClassicRecoveryTest
static ClassicRecoveryTestSuite g_TcpClassicRecoveryTest
Static variable for test initialization.
Definition
tcp-classic-recovery-test.cc:160
src
internet
test
tcp-classic-recovery-test.cc
Generated on Fri Dec 13 2024 09:20:41 for ns-3 by
1.11.0