A Discrete-Event Network Simulator
API
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
44{
45 public:
59 uint32_t segmentsAcked,
60 Time lastCongestion,
61 Time firstAck,
62 Time secondAck,
63 uint32_t expectedCwnd,
64 const std::string& name);
65
66 private:
67 void DoRun() override;
68
77};
78
81 uint32_t segmentsAcked,
82 Time lastCongestion,
83 Time firstAck,
84 Time secondAck,
85 uint32_t expectedCwnd,
86 const std::string& name)
87 : TestCase(name),
88 m_cWnd(cWnd),
89 m_segmentSize(segmentSize),
90 m_segmentsAcked(segmentsAcked),
91 m_lastCongestion(lastCongestion),
92 m_firstAck(firstAck),
93 m_secondAck(secondAck),
94 m_expectedCwnd(expectedCwnd)
95{
96}
97
104void
106{
107 NS_LOG_FUNCTION(this);
108 m_state = CreateObject<TcpSocketState>();
109
112
113 Ptr<TcpHtcp> cong = CreateObject<TcpHtcp>();
114 Time lastCongestion;
115
116 NS_LOG_DEBUG("m_cWnd: " << m_cWnd << " m_segmentSize: " << m_segmentSize << " m_segmentsAcked: "
117 << m_segmentsAcked << " m_lastCongestion" << m_lastCongestion);
118 Simulator::Schedule(Time(m_lastCongestion),
119 &TcpHtcp::GetSsThresh,
120 cong,
121 m_state,
122 m_state->m_cWnd);
123 lastCongestion = m_lastCongestion;
124 Simulator::Schedule(Time(m_firstAck),
125 &TcpHtcp::PktsAcked,
126 cong,
127 m_state,
130 Simulator::Schedule(Time(m_secondAck),
131 &TcpHtcp::PktsAcked,
132 cong,
133 m_state,
135 Time(ns3::MilliSeconds(100)));
136
137 Simulator::Run();
138 NS_LOG_DEBUG("Simulation ran for the scheduled events");
139
140 cong->IncreaseWindow(m_state, m_segmentsAcked);
141 NS_LOG_DEBUG("m_cwnd from function: " << m_state->m_cWnd
142 << " expected cWnd calculated: " << m_expectedCwnd);
143
144 NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(), m_expectedCwnd, "CWnd has not updated correctly");
145
146 Simulator::Destroy();
147}
148
167{
168 public:
170 : TestSuite("tcp-htcp-test", UNIT)
171 {
173 536,
174 38,
177 ns3::MilliSeconds(1000),
178 20383,
179 "TcpHtcp increment test on cWnd "),
180 TestCase::QUICK);
182 1,
183 100,
186 ns3::MilliSeconds(1100),
187 40,
188 "TcpHtcp increment test on cWnd "),
189 TestCase::QUICK);
190 AddTestCase(new TcpHtcpIncrementTest(53 * 1446,
191 1446,
192 50,
195 ns3::MilliSeconds(1500),
196 76671,
197 "TcpHtcp increment test on cWnd "),
198 TestCase::QUICK);
199 }
200};
201
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.
uint32_t m_segmentSize
Segment size.
TracedValue< uint32_t > m_cWnd
Congestion window.
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
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:144
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:850
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpHtcpTestSuite g_TcpHtcpTest
Static variable for test initialization.