A Discrete-Event Network Simulator
API
tcp-scalable-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 ResiliNets, ITTC, University of Kansas
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: Truc Anh N. Nguyen <annguyen@ittc.ku.edu>
19 
20  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22  * Information and Telecommunication Technology Center (ITTC)
23  * and Department of Electrical Engineering and Computer Science
24  * The University of Kansas Lawrence, KS USA.
25  *
26  */
27 
28 #include "ns3/test.h"
29 #include "ns3/log.h"
30 #include "ns3/tcp-congestion-ops.h"
31 #include "ns3/tcp-socket-base.h"
32 #include "ns3/tcp-scalable.h"
33 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("TcpScalableTestSuite");
37 
42 {
43 public:
44  TcpScalableIncrementTest (uint32_t cWnd, uint32_t segmentSize,
45  uint32_t segmentsAcked,
46  const std::string &name);
47 
48 private:
49  virtual void DoRun (void);
50 
51  uint32_t m_cWnd;
52  uint32_t m_segmentSize;
53  uint32_t m_segmentsAcked;
55 };
56 
58  uint32_t segmentSize,
59  uint32_t segmentsAcked,
60  const std::string &name)
61  : TestCase (name),
62  m_cWnd (cWnd),
63  m_segmentSize (segmentSize),
64  m_segmentsAcked (segmentsAcked)
65 {
66 }
67 
68 void
70 {
71  m_state = CreateObject<TcpSocketState> ();
72 
73  m_state->m_cWnd = m_cWnd;
74  m_state->m_segmentSize = m_segmentSize;
75 
76  Ptr<TcpScalable> cong = CreateObject <TcpScalable> ();
77 
78  uint32_t segCwnd = m_cWnd / m_segmentSize;
79 
80  // Get default value of additive increase factor
81  UintegerValue aiFactor;
82  cong->GetAttribute ("AIFactor", aiFactor);
83 
84  // To see an increase of 1 MSS, the number of segments ACKed has to be at least
85  // min (segCwnd, aiFactor).
86 
87  uint32_t w = std::min (segCwnd, (uint32_t) aiFactor.Get ());
88  uint32_t delta = m_segmentsAcked / w;
89 
90  cong->IncreaseWindow (m_state, m_segmentsAcked);
91 
92  NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), m_cWnd + delta * m_segmentSize,
93  "CWnd has not increased");
94 }
95 
100 {
101 public:
102  TcpScalableDecrementTest (uint32_t ssThresh, uint32_t segmentSize,
103  const std::string &name);
104 
105 private:
106  virtual void DoRun (void);
107 
108  uint32_t m_cWnd;
109  uint32_t m_segmentSize;
111 };
112 
114  uint32_t segmentSize,
115  const std::string &name)
116  : TestCase (name),
117  m_cWnd (cWnd),
118  m_segmentSize (segmentSize)
119 {
120 }
121 
122 void
124 {
125  m_state = CreateObject<TcpSocketState> ();
126 
127  m_state->m_cWnd = m_cWnd;
128  m_state->m_segmentSize = m_segmentSize;
129 
130  Ptr<TcpScalable> cong = CreateObject <TcpScalable> ();
131 
132  uint32_t segCwnd = m_cWnd / m_segmentSize;
133 
134  // Get default value of multiplicative decrease factor
135  DoubleValue mdFactor;
136  cong->GetAttribute ("MDFactor", mdFactor);
137 
138  double b = 1.0 - mdFactor.Get ();
139 
140  uint32_t ssThresh = std::max (2.0, segCwnd * b);
141 
142  uint32_t ssThreshInSegments = cong->GetSsThresh (m_state, m_state->m_cWnd) / m_segmentSize;
143 
144  NS_TEST_ASSERT_MSG_EQ (ssThreshInSegments, ssThresh,
145  "Scalable decrement fn not used");
146 }
147 
148 
149 // -------------------------------------------------------------------
150 
151 static class TcpScalableTestSuite : public TestSuite
152 {
153 public:
154  TcpScalableTestSuite () : TestSuite ("tcp-scalable-test", UNIT)
155  {
156  AddTestCase (new TcpScalableIncrementTest (38 * 536, 536, 38,
157  "Scalable increment test on cWnd = 38 segments and segmentSize = 536 bytes"),
159  AddTestCase (new TcpScalableIncrementTest (38, 1, 100,
160  "Scalable increment test on cWnd = 38 segments and segmentSize = 1 byte"),
162  AddTestCase (new TcpScalableIncrementTest (53 * 1446, 1446, 50,
163  "Scalable increment test on cWnd = 53 segments and segmentSize = 1446 bytes"),
165 
167  "Scalable decrement test on cWnd = 38 segments and segmentSize = 1 byte"),
169  AddTestCase (new TcpScalableDecrementTest (100 * 536, 536,
170  "Scalable decrement test on cWnd = 100 segments and segmentSize = 536 bytes"),
172  AddTestCase (new TcpScalableDecrementTest (40 * 1446, 1446,
173  "Scalable decrement test on cWnd = 40 segments and segmentSize = 1446 bytes"),
175 
176  }
178 
179 } // namespace ns3
TcpScalableIncrementTest(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, const std::string &name)
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Testing the congestion avoidance increment on TcpScalable.
#define min(a, b)
Definition: 80211b.c:44
Fast test.
Definition: test.h:1152
A suite of tests to run.
Definition: test.h:1333
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Ptr< TcpSocketState > m_state
encapsulates test code
Definition: test.h:1147
This test suite implements a Unit Test.
Definition: test.h:1343
uint64_t Get(void) const
Definition: uinteger.cc:35
#define max(a, b)
Definition: 80211b.c:45
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
Hold an unsigned integer type.
Definition: uinteger.h:44
#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:161
double Get(void) const
Definition: double.cc:35
Testing the multiplicative decrease on TcpScalable.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void DoRun(void)
Implementation to actually run this TestCase.
TcpScalableDecrementTest(uint32_t ssThresh, uint32_t segmentSize, const std::string &name)
virtual void DoRun(void)
Implementation to actually run this TestCase.
ns3::TcpScalableTestSuite g_tcpScalableTest
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41