A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
33 using namespace ns3;
34 
35 NS_LOG_COMPONENT_DEFINE("TcpHtcpTestSuite");
36 
43 {
44  public:
56  TcpHtcpIncrementTest(uint32_t cWnd,
57  uint32_t segmentSize,
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;
69  uint32_t m_segmentSize;
70  uint32_t m_segmentsAcked;
74  uint32_t m_expectedCwnd;
76 };
77 
79  uint32_t segmentSize,
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 
103 void
105 {
106  NS_LOG_FUNCTION(this);
107  m_state = CreateObject<TcpSocketState>();
108 
109  m_state->m_cWnd = m_cWnd;
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);
117  Simulator::Schedule(Time(m_lastCongestion),
118  &TcpHtcp::GetSsThresh,
119  cong,
120  m_state,
121  m_state->m_cWnd);
122  lastCongestion = m_lastCongestion;
123  Simulator::Schedule(Time(m_firstAck),
124  &TcpHtcp::PktsAcked,
125  cong,
126  m_state,
128  Time(ns3::MilliSeconds(80)));
129  Simulator::Schedule(Time(m_secondAck),
130  &TcpHtcp::PktsAcked,
131  cong,
132  m_state,
134  Time(ns3::MilliSeconds(100)));
135 
136  Simulator::Run();
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 
145  Simulator::Destroy();
146 }
147 
165 {
166  public:
168  : TestSuite("tcp-htcp-test", UNIT)
169  {
170  AddTestCase(new TcpHtcpIncrementTest(38 * 536,
171  536,
172  38,
174  ns3::MilliSeconds(900),
175  ns3::MilliSeconds(1000),
176  20383,
177  "TcpHtcp increment test on cWnd "),
178  TestCase::QUICK);
180  1,
181  100,
183  ns3::MilliSeconds(900),
184  ns3::MilliSeconds(1100),
185  40,
186  "TcpHtcp increment test on cWnd "),
187  TestCase::QUICK);
188  AddTestCase(new TcpHtcpIncrementTest(53 * 1446,
189  1446,
190  50,
192  ns3::MilliSeconds(900),
193  ns3::MilliSeconds(1500),
194  76671,
195  "TcpHtcp increment test on cWnd "),
196  TestCase::QUICK);
197  }
198 };
199 
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:301
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:1338
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:839
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpHtcpTestSuite g_TcpHtcpTest
Static variable for test initialization.