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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Amir Modarresi <amodarresi@ittc.ku.edu>
7
8 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
9 * ResiliNets Research Group https://resilinets.org/
10 * Information and Telecommunication Technology Center (ITTC)
11 * and Department of Electrical Engineering and Computer Science
12 * The University of Kansas Lawrence, KS USA.
13 *
14 */
15
16#include "ns3/log.h"
17#include "ns3/tcp-congestion-ops.h"
18#include "ns3/tcp-htcp.h"
19#include "ns3/tcp-socket-base.h"
20#include "ns3/test.h"
21
22using namespace ns3;
23
24NS_LOG_COMPONENT_DEFINE("TcpHtcpTestSuite");
25
26/**
27 * \ingroup internet-test
28 *
29 * \brief Testing the congestion avoidance increment on TcpHtcp
30 */
32{
33 public:
34 /**
35 * \brief Constructor.
36 * \param cWnd Congestion window.
37 * \param segmentSize Segment size.
38 * \param segmentsAcked Segments already ACKed.
39 * \param lastCongestion Last congestion time.
40 * \param firstAck First ACK time.
41 * \param secondAck Second ACK time.
42 * \param expectedCwnd Expected cWnd.
43 * \param name Test description.
44 */
47 uint32_t segmentsAcked,
48 Time lastCongestion,
49 Time firstAck,
50 Time secondAck,
51 uint32_t expectedCwnd,
52 const std::string& name);
53
54 private:
55 void DoRun() override;
56
57 uint32_t m_cWnd; //!< Congestion window.
58 uint32_t m_segmentSize; //!< Segment size.
59 uint32_t m_segmentsAcked; //!< Segments already ACKed.
60 Time m_lastCongestion; //!< Last congestion time.
61 Time m_firstAck; //!< First ACK time.
62 Time m_secondAck; //!< Second ACK time.
63 uint32_t m_expectedCwnd; //!< Expected cWnd.
64 Ptr<TcpSocketState> m_state; //!< TCP socket state.
65};
66
69 uint32_t segmentsAcked,
70 Time lastCongestion,
71 Time firstAck,
72 Time secondAck,
73 uint32_t expectedCwnd,
74 const std::string& name)
75 : TestCase(name),
76 m_cWnd(cWnd),
77 m_segmentSize(segmentSize),
78 m_segmentsAcked(segmentsAcked),
79 m_lastCongestion(lastCongestion),
80 m_firstAck(firstAck),
81 m_secondAck(secondAck),
82 m_expectedCwnd(expectedCwnd)
83{
84}
85
86/**
87 * \brief Since the calculation depends on the throughput and its associated
88 * timing, we schedule a few exact events. We get the value from HTCP methods
89 * during the simulation and compare them with their associated expected
90 * values calculated from the algorithm by hand.
91 */
92void
94{
95 NS_LOG_FUNCTION(this);
97
98 m_state->m_cWnd = m_cWnd;
99 m_state->m_segmentSize = m_segmentSize;
100
102 Time lastCongestion;
103
104 NS_LOG_DEBUG("m_cWnd: " << m_cWnd << " m_segmentSize: " << m_segmentSize << " m_segmentsAcked: "
105 << m_segmentsAcked << " m_lastCongestion" << m_lastCongestion);
108 cong,
109 m_state,
110 m_state->m_cWnd);
111 lastCongestion = m_lastCongestion;
114 cong,
115 m_state,
120 cong,
121 m_state,
123 Time(ns3::MilliSeconds(100)));
124
126 NS_LOG_DEBUG("Simulation ran for the scheduled events");
127
128 cong->IncreaseWindow(m_state, m_segmentsAcked);
129 NS_LOG_DEBUG("m_cwnd from function: " << m_state->m_cWnd
130 << " expected cWnd calculated: " << m_expectedCwnd);
131
132 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(), m_expectedCwnd, "CWnd has not updated correctly");
133
135}
136
137/**
138 * \ingroup internet-test
139 *
140 * \brief TCP Htcp TestSuite.
141 *
142 * The following tests simulate conditions after a congestion event and
143 * return to 1/2 ssthresh. After that, two acks are scheduled and the
144 * value of the cWnd is compared at the end of the event.
145 * The values in each test have been chosen randomly. The first test
146 * simulates receiving acks for 38 packets with segmentSize=536,
147 * the second one receives ack for 100 packets with segmentSize=1 and
148 * the third one receives ack for 50 segment with segmentSize=1446.
149 * The cWnd values of 20383, 40 and 76671 have been
150 * calculated manually from the algorithm.
151 */
152
154{
155 public:
157 : TestSuite("tcp-htcp-test", Type::UNIT)
158 {
160 536,
161 38,
164 ns3::MilliSeconds(1000),
165 20383,
166 "TcpHtcp increment test on cWnd "),
167 TestCase::Duration::QUICK);
169 1,
170 100,
173 ns3::MilliSeconds(1100),
174 40,
175 "TcpHtcp increment test on cWnd "),
176 TestCase::Duration::QUICK);
177 AddTestCase(new TcpHtcpIncrementTest(53 * 1446,
178 1446,
179 50,
182 ns3::MilliSeconds(1500),
183 76671,
184 "TcpHtcp increment test on cWnd "),
185 TestCase::Duration::QUICK);
186 }
187};
188
189static 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.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight) override
Get the slow start threshold after a loss event.
Definition tcp-htcp.cc:164
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition tcp-htcp.cc:186
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
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
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:1320
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpHtcpTestSuite g_TcpHtcpTest
Static variable for test initialization.