A Discrete-Event Network Simulator
API
tcp-prr-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/tcp-prr-recovery.h"
30 #include "ns3/string.h"
31 
32 using namespace ns3;
33 
34 NS_LOG_COMPONENT_DEFINE ("TcpPrrRecoveryTestSuite");
35 
39 class PrrRecoveryTest : public TestCase
40 {
41 public:
54  PrrRecoveryTest (uint32_t cWnd,
55  uint32_t segmentSize,
56  uint32_t ssThresh,
57  uint32_t unAckDataCount,
58  uint32_t bytesInFlight,
59  uint32_t m_deliveredBytes,
60  uint32_t bytesSent,
61  const std::string &reductionBound,
62  const std::string &name);
63 
64 private:
65  virtual void DoRun (void);
66 
67  uint32_t m_cWnd;
68  uint32_t m_segmentSize;
69  uint32_t m_ssThresh;
70  uint32_t m_unAckDataCount;
71  uint32_t m_bytesInFlight;
72  uint32_t m_deliveredBytes;
73  uint32_t m_bytesSent;
74  const std::string m_reductionBound;
75 
77 };
78 
80  uint32_t segmentSize,
81  uint32_t ssThresh,
82  uint32_t unAckDataCount,
83  uint32_t bytesInFlight,
84  uint32_t deliveredBytes,
85  uint32_t bytesSent,
86  const std::string &reductionBound,
87  const std::string &name)
88  : TestCase (name),
89  m_cWnd (cWnd),
90  m_segmentSize (segmentSize),
91  m_ssThresh (ssThresh),
92  m_unAckDataCount (unAckDataCount),
93  m_bytesInFlight (bytesInFlight),
94  m_deliveredBytes (deliveredBytes),
95  m_bytesSent (bytesSent),
96  m_reductionBound (reductionBound)
97 {
98 }
99 
100 void
102 {
103  m_state = CreateObject<TcpSocketState> ();
104 
105  m_state->m_cWnd = m_cWnd;
110 
111  Ptr<TcpPrrRecovery> recovery = CreateObject <TcpPrrRecovery> ();
112  recovery->SetAttribute ("ReductionBound", StringValue (m_reductionBound));
113 
114  recovery->EnterRecovery (m_state, 3, m_unAckDataCount, 0);
115 
117  "There should be at least one transmission on entering recovery");
118 
119  for (uint32_t iterator = 0; iterator < m_bytesSent; )
120  {
121  recovery->UpdateBytesSent (m_segmentSize);
122  iterator += m_segmentSize;
123  }
124 
127  m_cWnd = m_state->m_cWnd.Get ();
128  recovery->DoRecovery (m_state, m_deliveredBytes);
129 
131  {
133  "Updated cwnd should be less than or equal to the existing cwnd");
134  }
135  else
136  {
138  "Updated cwnd should be greater than or equal to the existing cwnd");
139  }
140 }
141 
149 {
150 public:
151  PrrRecoveryTestSuite () : TestSuite ("tcp-prr-recovery-test", UNIT)
152  {
153  AddTestCase (new PrrRecoveryTest (3000, 500, 2500, 3000, 3000, 500, 1000, "SSRB",
154  "Prr test on cWnd when bytesInFlight is greater than ssThresh with SSRB"),
155  TestCase::QUICK);
156  AddTestCase (new PrrRecoveryTest (1000, 500, 2500, 3000, 1000, 500, 1000, "SSRB",
157  "Prr test on cWnd when bytesInFlight is lower than ssThresh with SSRB"),
158  TestCase::QUICK);
159  AddTestCase (new PrrRecoveryTest (3000, 500, 2500, 3000, 3000, 500, 1000, "CRB",
160  "Prr test on cWnd when bytesInFlight is greater than ssThresh with CRB"),
161  TestCase::QUICK);
162  AddTestCase (new PrrRecoveryTest (1000, 500, 2500, 3000, 1000, 500, 1000, "CRB",
163  "Prr test on cWnd when bytesInFlight is lower than ssThresh with CRB"),
164  TestCase::QUICK);
165  }
166 };
167 
PRR Recovery algorithm test.
uint32_t m_bytesInFlight
Current bytes in flight.
uint32_t m_bytesSent
Bytes sent while in recovery phase.
PrrRecoveryTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, uint32_t unAckDataCount, uint32_t bytesInFlight, uint32_t m_deliveredBytes, uint32_t bytesSent, const std::string &reductionBound, const std::string &name)
Constructor.
uint32_t m_segmentSize
Segment size.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ptr< TcpSocketState > m_state
TCP socket state.
uint32_t m_ssThresh
Slow Start Threshold.
uint32_t m_deliveredBytes
Bytes SACKed on last acknowledgment.
uint32_t m_cWnd
Congestion window.
const std::string m_reductionBound
Type of reduction bound to be used.
uint32_t m_unAckDataCount
Unacknowledged data at the start of recovery.
PRR Recovery TestSuite.
Hold variables of type string.
Definition: string.h:41
uint32_t m_segmentSize
Segment size.
TracedValue< uint32_t > m_cWnd
Congestion window.
TracedValue< uint32_t > m_bytesInFlight
Bytes in flight.
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:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1197
T Get(void) const
Get the underlying value.
Definition: traced-value.h:232
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg)
Test that an actual value is less than or equal to a limit and report and abort if not.
Definition: test.h:712
#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg)
Test that an actual value is greater than or equal to a limit and report and abort if not.
Definition: test.h:862
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static PrrRecoveryTestSuite g_TcpPrrRecoveryTest
Static variable for test initialization.