A Discrete-Event Network Simulator
API
tcp-classic-recovery-test.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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: Viyom Mittal <viyommittal@gmail.com>
18  * Vivek Jain <jain.vivek.anand@gmail.com>
19  * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
20  *
21  */
22 
23 #include "ns3/log.h"
24 #include "ns3/string.h"
25 #include "ns3/tcp-congestion-ops.h"
26 #include "ns3/tcp-recovery-ops.h"
27 #include "ns3/tcp-socket-base.h"
28 #include "ns3/test.h"
29 
30 using namespace ns3;
31 
32 NS_LOG_COMPONENT_DEFINE("TcpClassicRecoveryTestSuite");
33 
38 {
39  public:
48  ClassicRecoveryTest(uint32_t cWnd,
49  uint32_t segmentSize,
50  uint32_t ssThresh,
51  uint32_t dupAckCount,
52  const std::string& name);
53 
54  private:
55  void DoRun() override;
56 
57  uint32_t m_cWnd;
58  uint32_t m_segmentSize;
59  uint32_t m_ssThresh;
60  uint32_t m_dupAckCount;
61 
63 };
64 
66  uint32_t segmentSize,
67  uint32_t ssThresh,
68  uint32_t dupAckCount,
69  const std::string& name)
70  : TestCase(name),
71  m_cWnd(cWnd),
72  m_segmentSize(segmentSize),
73  m_ssThresh(ssThresh),
74  m_dupAckCount(dupAckCount)
75 {
76 }
77 
78 void
80 {
81  m_state = CreateObject<TcpSocketState>();
82 
86 
87  Ptr<TcpClassicRecovery> recovery = CreateObject<TcpClassicRecovery>();
88 
89  NS_TEST_ASSERT_MSG_EQ(recovery->GetName(),
90  "TcpClassicRecovery",
91  "The name of recovery used should be TcpClassicRecovery");
92 
93  recovery->EnterRecovery(m_state, m_dupAckCount, 1000, 0);
96  "cWnd should be set to ssThresh on entering recovery");
100  "cWndInfl should be set to (ssThresh + dupAckCount * segmentSize) on entering recovery");
101 
102  uint32_t cWndInflPrevious = m_state->m_cWndInfl;
103  uint32_t cWndPrevious = m_state->m_cWnd;
104  recovery->DoRecovery(m_state, 500);
107  (cWndInflPrevious + m_state->m_segmentSize),
108  "m_cWndInfl should be increased by one segmentSize on calling DoRecovery");
109  NS_TEST_ASSERT_MSG_EQ(m_state->m_cWnd, cWndPrevious, "cWnd should not change in recovery");
110 
111  recovery->ExitRecovery(m_state);
114  "cWndInfl should be set to ssThresh on exiting recovery");
117  "cWnd should be set to ssThresh on exiting recovery");
118 }
119 
126 {
127  public:
129  : TestSuite("tcp-classic-recovery-test", UNIT)
130  {
132  500,
133  2500,
134  3,
135  "Classic recovery test with 500 bytes segmentSize"),
136  TestCase::QUICK);
138  1000,
139  2500,
140  3,
141  "Classic recovery test with 1000 bytes segmentSize"),
142  TestCase::QUICK);
144  500,
145  2500,
146  4,
147  "Classic recovery test with 4 DupAck threshold"),
148  TestCase::QUICK);
150  500,
151  1000,
152  3,
153  "Classic recovery test with 1000 bytes ssThresh"),
154  TestCase::QUICK);
156  500,
157  2500,
158  3,
159  "Classic recovery test with same cWnd and ssThresh"),
160  TestCase::QUICK);
162  500,
163  2500,
164  3,
165  "Classic recovery test with cWnd lesser than ssThresh"),
166  TestCase::QUICK);
167  }
168 };
169 
Classic Recovery algorithm test.
ClassicRecoveryTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, uint32_t dupAckCount, const std::string &name)
Constructor.
uint32_t m_cWnd
Congestion window.
Ptr< TcpSocketState > m_state
TCP socket state.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_ssThresh
Slow Start Threshold.
uint32_t m_dupAckCount
Duplicate acknowledgement Threshold.
uint32_t m_segmentSize
Segment size.
Classic Recovery TestSuite.
uint32_t m_segmentSize
Segment size.
TracedValue< uint32_t > m_cWnd
Congestion window.
TracedValue< uint32_t > m_cWndInfl
Inflated congestion window trace (used only for backward compatibility purpose)
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
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
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static ClassicRecoveryTestSuite g_TcpClassicRecoveryTest
Static variable for test initialization.