A Discrete-Event Network Simulator
API
tcp-classic-recovery-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 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  * Author: Viyom Mittal <viyommittal@gmail.com>
19  * Vivek Jain <jain.vivek.anand@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-recovery-ops.h"
28 #include "ns3/tcp-socket-base.h"
29 #include "ns3/string.h"
30 
31 using namespace ns3;
32 
33 NS_LOG_COMPONENT_DEFINE ("TcpClassicRecoveryTestSuite");
34 
39 {
40 public:
49  ClassicRecoveryTest (uint32_t cWnd,
50  uint32_t segmentSize,
51  uint32_t ssThresh,
52  uint32_t dupAckCount,
53  const std::string &name);
54 
55 private:
56  virtual void DoRun (void);
57 
58  uint32_t m_cWnd;
59  uint32_t m_segmentSize;
60  uint32_t m_ssThresh;
61  uint32_t m_dupAckCount;
62 
64 };
65 
67  uint32_t segmentSize,
68  uint32_t ssThresh,
69  uint32_t dupAckCount,
70  const std::string &name)
71  : TestCase (name),
72  m_cWnd (cWnd),
73  m_segmentSize (segmentSize),
74  m_ssThresh (ssThresh),
75  m_dupAckCount (dupAckCount)
76 {
77 }
78 
79 void
81 {
82  m_state = CreateObject<TcpSocketState> ();
83 
87 
88  Ptr<TcpClassicRecovery> recovery = CreateObject <TcpClassicRecovery> ();
89 
90  NS_TEST_ASSERT_MSG_EQ (recovery->GetName (), "TcpClassicRecovery",
91  "The name of recovery used should be TcpClassicRecovery");
92 
93  recovery->EnterRecovery (m_state, m_dupAckCount, 1000, 0);
95  "cWnd should be set to ssThresh on entering recovery");
97  "cWndInfl should be set to (ssThresh + dupAckCount * segmentSize) on entering recovery");
98 
99  uint32_t cWndInflPrevious = m_state->m_cWndInfl;
100  uint32_t cWndPrevious = m_state->m_cWnd;
101  recovery->DoRecovery (m_state, 500);
103  "m_cWndInfl should be incresed by one segmentSize on calling DoRecovery");
104  NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd, cWndPrevious,
105  "cWnd should not change in recovery");
106 
107  recovery->ExitRecovery (m_state);
109  "cWndInfl should be set to ssThresh on exiting recovery");
111  "cWnd should be set to ssThresh on exiting recovery");
112 }
113 
121 {
122 public:
123  ClassicRecoveryTestSuite () : TestSuite ("tcp-classic-recovery-test", UNIT)
124  {
125  AddTestCase (new ClassicRecoveryTest (3000, 500, 2500, 3, "Classic recovery test with 500 bytes segmentSize"),
126  TestCase::QUICK);
127  AddTestCase (new ClassicRecoveryTest (3000, 1000, 2500, 3, "Classic recovery test with 1000 bytes segmentSize"),
128  TestCase::QUICK);
129  AddTestCase (new ClassicRecoveryTest (3000, 500, 2500, 4, "Classic recovery test with 4 DupAck threshold"),
130  TestCase::QUICK);
131  AddTestCase (new ClassicRecoveryTest (3000, 500, 1000, 3, "Classic recovery test with 1000 bytes ssThresh"),
132  TestCase::QUICK);
133  AddTestCase (new ClassicRecoveryTest (2500, 500, 2500, 3, "Classic recovery test with same cWnd and ssThresh"),
134  TestCase::QUICK);
135  AddTestCase (new ClassicRecoveryTest (1000, 500, 2500, 3, "Classic recovery test with cWnd lesser than ssThresh"),
136  TestCase::QUICK);
137  }
138 };
139 
static ClassicRecoveryTestSuite g_TcpClassicRecoveryTest
Static variable for test initialization.
A suite of tests to run.
Definition: test.h:1342
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
uint32_t m_ssThresh
Slow Start Threshold.
uint32_t m_segmentSize
Segment size.
encapsulates test code
Definition: test.h:1155
Classic Recovery algorithm test.
Classic Recovery TestSuite.
TracedValue< uint32_t > m_cWndInfl
Inflated congestion window trace (used only for backward compatibility purpose)
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
virtual void ExitRecovery(Ptr< TcpSocketState > tcb) override
Performs cwnd adjustments at the end of recovery.
#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
uint32_t m_segmentSize
Segment size.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
virtual void DoRecovery(Ptr< TcpSocketState > tcb, uint32_t deliveredBytes) override
Performs recovery based on the recovery algorithm.
uint32_t m_dupAckCount
Duplicate acknowledgement Threshold.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ClassicRecoveryTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, uint32_t dupAckCount, const std::string &name)
Constructor.
virtual void EnterRecovery(Ptr< TcpSocketState > tcb, uint32_t dupAckCount, uint32_t unAckDataCount, uint32_t deliveredBytes) override
Performs variable initialization at the start of recovery.
TracedValue< uint32_t > m_cWnd
Congestion window.
uint32_t m_cWnd
Congestion window.
Ptr< TcpSocketState > m_state
TCP socket state.
This test suite implements a Unit Test.
Definition: test.h:1351
virtual std::string GetName() const override
Get the name of the recovery algorithm.