A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-htcp-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 ResiliNets, ITTC, University of Kansas
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Amir Modarresi <amodarresi@ittc.ku.edu>
18
19 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
20 * ResiliNets Research Group https://resilinets.org/
21 * Information and Telecommunication Technology Center (ITTC)
22 * and Department of Electrical Engineering and Computer Science
23 * The University of Kansas Lawrence, KS USA.
24 *
25 */
26
27#include "ns3/log.h"
28#include "ns3/tcp-congestion-ops.h"
29#include "ns3/tcp-htcp.h"
30#include "ns3/tcp-socket-base.h"
31#include "ns3/test.h"
32
33using namespace ns3;
34
35NS_LOG_COMPONENT_DEFINE("TcpHtcpTestSuite");
36
37/**
38 * \ingroup internet-test
39 *
40 * \brief Testing the congestion avoidance increment on TcpHtcp
41 */
43{
44 public:
45 /**
46 * \brief Constructor.
47 * \param cWnd Congestion window.
48 * \param segmentSize Segment size.
49 * \param segmentsAcked Segments already ACKed.
50 * \param lastCongestion Last congestion time.
51 * \param firstAck First ACK time.
52 * \param secondAck Second ACK time.
53 * \param expectedCwnd Expected cWnd.
54 * \param name Test description.
55 */
58 uint32_t segmentsAcked,
59 Time lastCongestion,
60 Time firstAck,
61 Time secondAck,
62 uint32_t expectedCwnd,
63 const std::string& name);
64
65 private:
66 void DoRun() override;
67
68 uint32_t m_cWnd; //!< Congestion window.
69 uint32_t m_segmentSize; //!< Segment size.
70 uint32_t m_segmentsAcked; //!< Segments already ACKed.
71 Time m_lastCongestion; //!< Last congestion time.
72 Time m_firstAck; //!< First ACK time.
73 Time m_secondAck; //!< Second ACK time.
74 uint32_t m_expectedCwnd; //!< Expected cWnd.
75 Ptr<TcpSocketState> m_state; //!< TCP socket state.
76};
77
80 uint32_t segmentsAcked,
81 Time lastCongestion,
82 Time firstAck,
83 Time secondAck,
84 uint32_t expectedCwnd,
85 const std::string& name)
86 : TestCase(name),
87 m_cWnd(cWnd),
88 m_segmentSize(segmentSize),
89 m_segmentsAcked(segmentsAcked),
90 m_lastCongestion(lastCongestion),
91 m_firstAck(firstAck),
92 m_secondAck(secondAck),
93 m_expectedCwnd(expectedCwnd)
94{
95}
96
97/**
98 * \brief Since the calculation depends on the throughput and its associated
99 * timing, we schedule a few exact events. We get the value from HTCP methods
100 * during the simulation and compare them with their associated expected
101 * values calculated from the algorithm by hand.
102 */
103void
105{
106 NS_LOG_FUNCTION(this);
107 m_state = CreateObject<TcpSocketState>();
108
111
112 Ptr<TcpHtcp> cong = CreateObject<TcpHtcp>();
113 Time lastCongestion;
114
115 NS_LOG_DEBUG("m_cWnd: " << m_cWnd << " m_segmentSize: " << m_segmentSize << " m_segmentsAcked: "
116 << m_segmentsAcked << " m_lastCongestion" << m_lastCongestion);
119 cong,
120 m_state,
121 m_state->m_cWnd);
122 lastCongestion = m_lastCongestion;
125 cong,
126 m_state,
131 cong,
132 m_state,
134 Time(ns3::MilliSeconds(100)));
135
137 NS_LOG_DEBUG("Simulation ran for the scheduled events");
138
139 cong->IncreaseWindow(m_state, m_segmentsAcked);
140 NS_LOG_DEBUG("m_cwnd from function: " << m_state->m_cWnd
141 << " expected cWnd calculated: " << m_expectedCwnd);
142
143 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(), m_expectedCwnd, "CWnd has not updated correctly");
144
146}
147
148/**
149 * \ingroup internet-test
150 *
151 * \brief TCP Htcp TestSuite.
152 *
153 * The following tests simulate conditions after a congestion event and
154 * return to 1/2 ssthresh. After that, two acks are scheduled and the
155 * value of the cWnd is compared at the end of the event.
156 * The values in each test have been chosen randomly. The first test
157 * simulates receiving acks for 38 packets with segmentSize=536,
158 * the second one receives ack for 100 packets with segmentSize=1 and
159 * the third one receives ack for 50 segment with segmentSize=1446.
160 * The cWnd values of 20383, 40 and 76671 have been
161 * calculated manually from the algorithm.
162 */
163
165{
166 public:
168 : TestSuite("tcp-htcp-test", Type::UNIT)
169 {
171 536,
172 38,
175 ns3::MilliSeconds(1000),
176 20383,
177 "TcpHtcp increment test on cWnd "),
178 TestCase::Duration::QUICK);
180 1,
181 100,
184 ns3::MilliSeconds(1100),
185 40,
186 "TcpHtcp increment test on cWnd "),
187 TestCase::Duration::QUICK);
188 AddTestCase(new TcpHtcpIncrementTest(53 * 1446,
189 1446,
190 50,
193 ns3::MilliSeconds(1500),
194 76671,
195 "TcpHtcp increment test on cWnd "),
196 TestCase::Duration::QUICK);
197 }
198};
199
200static TcpHtcpTestSuite g_TcpHtcpTest; //!< Static variable for test initialization
Testing the congestion avoidance increment on TcpHtcp.
void DoRun() override
Since the calculation depends on the throughput and its associated timing, we schedule a few exact ev...
Time m_secondAck
Second ACK time.
Time m_lastCongestion
Last congestion time.
uint32_t m_segmentsAcked
Segments already ACKed.
uint32_t m_cWnd
Congestion window.
uint32_t m_expectedCwnd
Expected cWnd.
Ptr< TcpSocketState > m_state
TCP socket state.
uint32_t m_segmentSize
Segment size.
TcpHtcpIncrementTest(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, Time lastCongestion, Time firstAck, Time secondAck, uint32_t expectedCwnd, const std::string &name)
Constructor.
Time m_firstAck
First ACK time.
TCP Htcp TestSuite.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight) override
Get the slow start threshold after a loss event.
Definition: tcp-htcp.cc:175
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition: tcp-htcp.cc:197
uint32_t m_segmentSize
Segment size.
TracedValue< uint32_t > m_cWnd
Congestion window.
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
T Get() const
Get the underlying value.
Definition: traced-value.h:249
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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:145
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1331
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpHtcpTestSuite g_TcpHtcpTest
Static variable for test initialization.