A Discrete-Event Network Simulator
API
tcp-lp-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 NITK Surathkal
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Charitha Sangaraju <charitha29193@gmail.com>
19  * Nandita G <gm.nandita@gmail.com>
20  * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
21  *
22  */
23 
24 #include "ns3/test.h"
25 #include "ns3/log.h"
26 #include "ns3/tcp-congestion-ops.h"
27 #include "ns3/tcp-socket-base.h"
28 #include "ns3/tcp-lp.h"
29 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("TcpLpTestSuite");
33 
37 class TcpLpToNewReno : public TestCase
38 {
39 public:
40  TcpLpToNewReno (uint32_t cWnd, uint32_t segmentSize,
41  uint32_t segmentsAcked,uint32_t ssThresh, Time rtt, const std::string &name);
42 
43 private:
44  virtual void DoRun (void);
45  void ExecuteTest (void);
46  uint32_t m_cWnd;
47  uint32_t m_segmentSize;
48  uint32_t m_ssThresh;
49  uint32_t m_segmentsAcked;
52 };
53 
54 TcpLpToNewReno::TcpLpToNewReno (uint32_t cWnd, uint32_t segmentSize,
55  uint32_t segmentsAcked, uint32_t ssThresh, Time rtt, const std::string &name)
56  : TestCase (name),
57  m_cWnd (cWnd),
58  m_segmentSize (segmentSize),
59  m_ssThresh (ssThresh),
60  m_segmentsAcked (segmentsAcked),
61  m_rtt (rtt)
62 {
63 }
64 
65 void
67 {
69  Simulator::Run ();
71 }
72 
73 void
75 {
76  m_state = CreateObject <TcpSocketState> ();
80 
81  Ptr<TcpSocketState> state = CreateObject <TcpSocketState> ();
82  state->m_cWnd = m_cWnd;
83  state->m_ssThresh = m_ssThresh;
85 
86  Ptr<TcpLp> cong = CreateObject <TcpLp> ();
87 
90 
91  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
92  cong->IncreaseWindow (m_state, m_segmentsAcked);
93 
94  Ptr<TcpNewReno> NewRenoCong = CreateObject <TcpNewReno> ();
95  NewRenoCong->IncreaseWindow (state, m_segmentsAcked);
96 
98  "cWnd has not updated correctly");
99 }
105 {
106 public:
107  TcpLpInferenceTest1 (uint32_t cWnd, uint32_t segmentSize,
108  uint32_t segmentsAcked, Time rtt, const std::string &name);
109 
110 private:
111  virtual void DoRun (void);
112  void ExecuteTest (void);
113 
114  uint32_t m_cWnd;
115  uint32_t m_segmentSize;
116  uint32_t m_segmentsAcked;
119 };
120 
121 TcpLpInferenceTest1::TcpLpInferenceTest1 (uint32_t cWnd, uint32_t segmentSize,
122  uint32_t segmentsAcked, Time rtt, const std::string &name)
123  : TestCase (name),
124  m_cWnd (cWnd),
125  m_segmentSize (segmentSize),
126  m_segmentsAcked (segmentsAcked),
127  m_rtt (rtt)
128 {
129 }
130 
131 void
133 {
135  Simulator::Run ();
137 }
138 
139 void
141 {
142  m_state = CreateObject <TcpSocketState> ();
143  m_state->m_cWnd = m_cWnd;
145 
146  Ptr<TcpLp> cong = CreateObject <TcpLp> ();
147 
150 
151  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
152 
155  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
156 
157  m_cWnd = m_cWnd / 2;
159  "cWnd has not updated correctly");
160 }
161 
166 {
167 public:
168  TcpLpInferenceTest2 (uint32_t cWnd, uint32_t segmentSize,
169  uint32_t segmentsAcked, Time rtt, const std::string &name);
170 
171 private:
172  virtual void DoRun (void);
173  void ExecuteTest (void);
174 
175  uint32_t m_cWnd;
176  uint32_t m_segmentSize;
177  uint32_t m_segmentsAcked;
180 };
181 
182 TcpLpInferenceTest2::TcpLpInferenceTest2 (uint32_t cWnd, uint32_t segmentSize,uint32_t segmentsAcked, Time rtt, const std::string &name)
183  : TestCase (name),
184  m_cWnd (cWnd),
185  m_segmentSize (segmentSize),
186  m_segmentsAcked (segmentsAcked),
187  m_rtt (rtt)
188 {
189 }
190 
191 void
193 {
195  Simulator::Run ();
197 }
198 
199 void
201 {
202  m_state = CreateObject <TcpSocketState> ();
203  m_state->m_cWnd = m_cWnd;
205 
206  Ptr<TcpLp> cong = CreateObject <TcpLp> ();
207 
210  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
211 
214  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
215 
218  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
219 
220  m_cWnd = 1U * m_segmentSize;
221 
223  "cWnd has not updated correctly");
224 }
225 
226 static class TcpLpTestSuite : public TestSuite
227 {
228 public:
229  TcpLpTestSuite () : TestSuite ("tcp-lp-test", UNIT)
230  {
231  AddTestCase (new TcpLpToNewReno (4 * 1446, 1446,2, 2 * 1446, MilliSeconds (100), "LP falls to New Reno if the owd is within threshold"), TestCase::QUICK);
232 
233  AddTestCase (new TcpLpInferenceTest1 (2 * 1446, 1446,2, MilliSeconds (100), "LP enters Inference phase when owd exceeds threshold for the first time"), TestCase::QUICK);
234 
235  AddTestCase (new TcpLpInferenceTest2 (2 * 1446, 1446,2, MilliSeconds (100), "LP reduces cWnd to 1 if owd exceeds threshold in inference phase"), TestCase::QUICK);
236  }
237 } g_tcplpTest;
238 
239 }
Testing the behaviour common to New Reno.
Definition: tcp-lp-test.cc:37
uint32_t m_rcvTimestampValue
Receiver Timestamp value.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Ptr< TcpSocketState > m_state
Definition: tcp-lp-test.cc:51
A suite of tests to run.
Definition: test.h:1342
uint32_t m_rcvTimestampEchoReply
Sender Timestamp echoed by the receiver.
static void Run(void)
Run the simulation.
Definition: simulator.cc:170
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1070
uint32_t m_segmentSize
Segment size.
uint32_t m_segmentsAcked
Definition: tcp-lp-test.cc:49
TcpLpToNewReno(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, uint32_t ssThresh, Time rtt, const std::string &name)
Definition: tcp-lp-test.cc:54
encapsulates test code
Definition: test.h:1155
TcpLpInferenceTest2(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, Time rtt, const std::string &name)
Definition: tcp-lp-test.cc:182
Ptr< TcpSocketState > m_state
Definition: tcp-lp-test.cc:118
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1389
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
#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:168
ns3::TcpLpTestSuite g_tcplpTest
void ExecuteTest(void)
Definition: tcp-lp-test.cc:74
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:134
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: tcp-lp-test.cc:192
Ptr< TcpSocketState > m_state
Definition: tcp-lp-test.cc:179
TracedValue< uint32_t > m_cWnd
Congestion window.
Fast test.
Definition: test.h:1160
Testing TcpLp when owd exceeds threshold.
Definition: tcp-lp-test.cc:104
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
TcpLpInferenceTest1(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, Time rtt, const std::string &name)
Definition: tcp-lp-test.cc:121
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: tcp-lp-test.cc:66
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: tcp-lp-test.cc:132
This test suite implements a Unit Test.
Definition: test.h:1352
Testing TcpLp when it is inference phase.
Definition: tcp-lp-test.cc:165
uint32_t m_segmentSize
Definition: tcp-lp-test.cc:47