A Discrete-Event Network Simulator
API
tcp-ledbat-test.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 NITK Surathkal
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  * Author: Ankit Deepak <adadeepak8@gmail.com>
18  *
19  */
20 
21 #include "ns3/log.h"
22 #include "ns3/string.h"
23 #include "ns3/tcp-congestion-ops.h"
24 #include "ns3/tcp-ledbat.h"
25 #include "ns3/tcp-socket-base.h"
26 #include "ns3/test.h"
27 
28 using namespace ns3;
29 
30 NS_LOG_COMPONENT_DEFINE("TcpLedbatTestSuite");
31 
38 {
39  public:
52  TcpLedbatToNewReno(uint32_t cWnd,
53  uint32_t segmentSize,
54  uint32_t ssThresh,
55  uint32_t segmentsAcked,
56  SequenceNumber32 highTxMark,
57  SequenceNumber32 lastAckedSeq,
58  Time rtt,
59  const std::string& name);
60 
61  private:
62  void DoRun() override;
65  void ExecuteTest();
66 
67  uint32_t m_cWnd;
68  uint32_t m_segmentSize;
69  uint32_t m_segmentsAcked;
70  uint32_t m_ssThresh;
75 };
76 
78  uint32_t segmentSize,
79  uint32_t ssThresh,
80  uint32_t segmentsAcked,
81  SequenceNumber32 highTxMark,
82  SequenceNumber32 lastAckedSeq,
83  Time rtt,
84  const std::string& name)
85  : TestCase(name),
86  m_cWnd(cWnd),
87  m_segmentSize(segmentSize),
88  m_segmentsAcked(segmentsAcked),
89  m_ssThresh(ssThresh),
90  m_rtt(rtt),
91  m_highTxMark(highTxMark),
92  m_lastAckedSeq(lastAckedSeq)
93 {
94 }
95 
96 void
98 {
99  Simulator::Schedule(Seconds(0.0), &TcpLedbatToNewReno::ExecuteTest, this);
100  Simulator::Run();
101  Simulator::Destroy();
102 }
103 
104 void
106 {
107  m_state = CreateObject<TcpSocketState>();
108  m_state->m_cWnd = m_cWnd;
113 
114  Ptr<TcpSocketState> state = CreateObject<TcpSocketState>();
115  state->m_cWnd = m_cWnd;
116  state->m_ssThresh = m_ssThresh;
117  state->m_segmentSize = m_segmentSize;
118  state->m_highTxMark = m_highTxMark;
120 
121  Ptr<TcpLedbat> cong = CreateObject<TcpLedbat>();
122  cong->IncreaseWindow(m_state, m_segmentsAcked);
123 
124  Ptr<TcpNewReno> NewRenoCong = CreateObject<TcpNewReno>();
125  NewRenoCong->IncreaseWindow(state, m_segmentsAcked);
126 
128  state->m_cWnd.Get(),
129  "cWnd has not updated correctly");
130 }
131 
138 {
139  public:
152  TcpLedbatIncrementTest(uint32_t cWnd,
153  uint32_t segmentSize,
154  uint32_t ssThresh,
155  uint32_t segmentsAcked,
156  SequenceNumber32 highTxMark,
157  SequenceNumber32 lastAckedSeq,
158  Time rtt,
159  const std::string& name);
160 
161  private:
162  void DoRun() override;
165  void ExecuteTest();
166 
167  uint32_t m_cWnd;
168  uint32_t m_segmentSize;
169  uint32_t m_segmentsAcked;
170  uint32_t m_ssThresh;
175 };
176 
178  uint32_t segmentSize,
179  uint32_t ssThresh,
180  uint32_t segmentsAcked,
181  SequenceNumber32 highTxMark,
182  SequenceNumber32 lastAckedSeq,
183  Time rtt,
184  const std::string& name)
185  : TestCase(name),
186  m_cWnd(cWnd),
187  m_segmentSize(segmentSize),
188  m_segmentsAcked(segmentsAcked),
189  m_ssThresh(ssThresh),
190  m_rtt(rtt),
191  m_highTxMark(highTxMark),
192  m_lastAckedSeq(lastAckedSeq)
193 {
194 }
195 
196 void
198 {
199  Simulator::Schedule(Seconds(0.0), &TcpLedbatIncrementTest::ExecuteTest, this);
200  Simulator::Run();
201  Simulator::Destroy();
202 }
203 
204 void
206 {
207  m_state = CreateObject<TcpSocketState>();
208  m_state->m_cWnd = m_cWnd;
213 
214  Ptr<TcpLedbat> cong = CreateObject<TcpLedbat>();
215  cong->SetAttribute("SSParam", StringValue("no"));
216  cong->SetAttribute("NoiseFilterLen", UintegerValue(1));
217 
220  cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
221 
224  cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
225 
226  cong->IncreaseWindow(m_state, m_segmentsAcked);
227 
229 
230  NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(), m_cWnd, "cWnd has not updated correctly");
231 }
232 
239 {
240  public:
253  TcpLedbatDecrementTest(uint32_t cWnd,
254  uint32_t segmentSize,
255  uint32_t ssThresh,
256  uint32_t segmentsAcked,
257  SequenceNumber32 highTxMark,
258  SequenceNumber32 lastAckedSeq,
259  Time rtt,
260  const std::string& name);
261 
262  private:
263  void DoRun() override;
266  void ExecuteTest();
267 
268  uint32_t m_cWnd;
269  uint32_t m_segmentSize;
270  uint32_t m_segmentsAcked;
271  uint32_t m_ssThresh;
276 };
277 
279  uint32_t segmentSize,
280  uint32_t ssThresh,
281  uint32_t segmentsAcked,
282  SequenceNumber32 highTxMark,
283  SequenceNumber32 lastAckedSeq,
284  Time rtt,
285  const std::string& name)
286  : TestCase(name),
287  m_cWnd(cWnd),
288  m_segmentSize(segmentSize),
289  m_segmentsAcked(segmentsAcked),
290  m_ssThresh(ssThresh),
291  m_rtt(rtt),
292  m_highTxMark(highTxMark),
293  m_lastAckedSeq(lastAckedSeq)
294 {
295 }
296 
297 void
299 {
300  Simulator::Schedule(Seconds(0.0), &TcpLedbatDecrementTest::ExecuteTest, this);
301  Simulator::Run();
302  Simulator::Destroy();
303 }
304 
305 void
307 {
308  UintegerValue minCwnd;
309  m_state = CreateObject<TcpSocketState>();
310  m_state->m_cWnd = m_cWnd;
315 
316  Ptr<TcpLedbat> cong = CreateObject<TcpLedbat>();
317  cong->SetAttribute("SSParam", StringValue("no"));
318  cong->SetAttribute("NoiseFilterLen", UintegerValue(1));
319  cong->GetAttribute("MinCwnd", minCwnd);
320 
323  cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
324 
327  cong->PktsAcked(m_state, m_segmentsAcked, m_rtt);
328 
329  cong->IncreaseWindow(m_state, m_segmentsAcked);
330 
332  m_cWnd = std::max(m_cWnd, static_cast<uint32_t>(m_segmentSize * minCwnd.Get()));
333 
334  NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd.Get(), m_cWnd, "cWnd has not updated correctly");
335 }
336 
343 {
344  public:
346  : TestSuite("tcp-ledbat-test", UNIT)
347  {
348  AddTestCase(new TcpLedbatToNewReno(2 * 1446,
349  1446,
350  4 * 1446,
351  2,
352  SequenceNumber32(4753),
353  SequenceNumber32(3216),
354  MilliSeconds(100),
355  "LEDBAT falls to New Reno for slowstart"),
356  TestCase::QUICK);
357  AddTestCase(new TcpLedbatToNewReno(4 * 1446,
358  1446,
359  2 * 1446,
360  2,
361  SequenceNumber32(4753),
362  SequenceNumber32(3216),
363  MilliSeconds(100),
364  "LEDBAT falls to New Reno if timestamps are not found"),
365  TestCase::QUICK);
366  AddTestCase(new TcpLedbatIncrementTest(2 * 1446,
367  1446,
368  4 * 1446,
369  2,
370  SequenceNumber32(4753),
371  SequenceNumber32(3216),
372  MilliSeconds(100),
373  "LEDBAT increment test"),
374  TestCase::QUICK);
375  AddTestCase(new TcpLedbatDecrementTest(2 * 1446,
376  1446,
377  4 * 1446,
378  2,
379  SequenceNumber32(4753),
380  SequenceNumber32(3216),
381  MilliSeconds(100),
382  "LEDBAT decrement test"),
383  TestCase::QUICK);
384  }
385 };
386 
#define max(a, b)
Definition: 80211b.c:43
Test to validate cWnd decrement in LEDBAT.
TcpLedbatDecrementTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, uint32_t segmentsAcked, SequenceNumber32 highTxMark, SequenceNumber32 lastAckedSeq, Time rtt, const std::string &name)
Constructor.
SequenceNumber32 m_highTxMark
high tx mark
uint32_t m_segmentSize
segment size
uint32_t m_ssThresh
ss thresh
void ExecuteTest()
Execute the test.
uint32_t m_segmentsAcked
segments acked
SequenceNumber32 m_lastAckedSeq
last acked seq
void DoRun() override
Implementation to actually run this TestCase.
Ptr< TcpSocketState > m_state
state
Test to validate cWnd increment in LEDBAT.
SequenceNumber32 m_highTxMark
high tx mark
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_segmentsAcked
segments acked
void ExecuteTest()
Execute the test.
uint32_t m_segmentSize
segment size
TcpLedbatIncrementTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, uint32_t segmentsAcked, SequenceNumber32 highTxMark, SequenceNumber32 lastAckedSeq, Time rtt, const std::string &name)
Constructor.
uint32_t m_ssThresh
ss thresh
SequenceNumber32 m_lastAckedSeq
last acked seq
Ptr< TcpSocketState > m_state
state
TCP Ledbat TestSuite.
LEDBAT should be same as NewReno during slow start, and when timestamps are disabled.
uint32_t m_segmentsAcked
segments acked
TcpLedbatToNewReno(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, uint32_t segmentsAcked, SequenceNumber32 highTxMark, SequenceNumber32 lastAckedSeq, Time rtt, const std::string &name)
Constructor.
SequenceNumber32 m_highTxMark
high tx mark
Ptr< TcpSocketState > m_state
state
SequenceNumber32 m_lastAckedSeq
last acked seq
void DoRun() override
Implementation to actually run this TestCase.
void ExecuteTest()
Execute the test.
uint32_t m_segmentSize
segment size
uint32_t m_ssThresh
ss thresh
Hold variables of type string.
Definition: string.h:56
uint32_t m_segmentSize
Segment size.
TracedValue< SequenceNumber32 > m_highTxMark
Highest seqno ever sent, regardless of ReTx.
SequenceNumber32 m_lastAckedSeq
Last sequence ACKed.
TracedValue< uint32_t > m_cWnd
Congestion window.
uint32_t m_rcvTimestampEchoReply
Sender Timestamp echoed by the receiver.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
uint32_t m_rcvTimestampValue
Receiver Timestamp value.
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
Hold an unsigned integer type.
Definition: uinteger.h:45
uint64_t Get() const
Definition: uinteger.cc:37
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
#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 Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1348
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpLedbatTestSuite g_tcpledbatTest
static var for test initialization