A Discrete-Event Network Simulator
API
tcp-vegas-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  * Author: 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 #include "ns3/test.h"
28 #include "ns3/log.h"
29 #include "ns3/tcp-congestion-ops.h"
30 #include "ns3/tcp-socket-base.h"
31 #include "ns3/tcp-vegas.h"
32 
33 using namespace ns3;
34 
35 NS_LOG_COMPONENT_DEFINE ("TcpVegasTestSuite");
36 
40 class TcpVegasTest : public TestCase
41 {
42 public:
54  TcpVegasTest (uint32_t cWnd,
55  uint32_t segmentSize,
56  uint32_t ssThresh,
57  Time rtt,
58  uint32_t segmentsAcked,
59  SequenceNumber32 nextTxSeq,
60  SequenceNumber32 lastAckedSeq,
61  const std::string &name);
62 
63 private:
64  virtual void DoRun (void);
69  void IncreaseWindow (Ptr<TcpVegas> cong);
74  void GetSsThresh (Ptr<TcpVegas> cong);
75 
76  uint32_t m_cWnd;
77  uint32_t m_segmentSize;
78  uint32_t m_ssThresh;
80  uint32_t m_segmentsAcked;
83 
85 };
86 
88  uint32_t segmentSize,
89  uint32_t ssThresh,
90  Time rtt,
91  uint32_t segmentsAcked,
92  SequenceNumber32 nextTxSeq,
93  SequenceNumber32 lastAckedSeq,
94  const std::string &name)
95  : TestCase (name),
96  m_cWnd (cWnd),
97  m_segmentSize (segmentSize),
98  m_ssThresh (ssThresh),
99  m_rtt (rtt),
100  m_segmentsAcked (segmentsAcked),
101  m_nextTxSeq (nextTxSeq),
102  m_lastAckedSeq (lastAckedSeq)
103 {
104 }
105 
106 void
108 {
109  m_state = CreateObject<TcpSocketState> ();
110 
111  m_state->m_cWnd = m_cWnd;
117 
118  Ptr<TcpVegas> cong = CreateObject <TcpVegas> ();
119 
120  // Set baseRtt to 100 ms
122 
123  // Re-set Vegas to assign a new value of minRtt
124  cong->CongestionStateSet (m_state, TcpSocketState::CA_OPEN);
126 
127  // 2 more calls to PktsAcked to increment cntRtt beyond 2
130 
131  // Update cwnd using Vegas algorithm
133 
134  // Our calculation of cwnd
135  IncreaseWindow (cong);
136 
138  "CWnd has not updated correctly");
140  "SsThresh has not updated correctly");
141 }
142 
143 void
145 {
146  Time baseRtt = MilliSeconds (100);
147  uint32_t segCwnd = m_cWnd / m_segmentSize;
148 
149  // Calculate expected throughput
150  uint64_t expectedCwnd;
151  expectedCwnd = (uint64_t) segCwnd * (double) baseRtt.GetMilliSeconds () / (double) m_rtt.GetMilliSeconds ();
152 
153  // Calculate the difference between actual and expected throughput
154  uint32_t diff;
155  diff = segCwnd - expectedCwnd;
156 
157  // Get the alpha,beta, and gamma attributes
158  UintegerValue alpha, beta, gamma;
159  cong->GetAttribute ("Alpha", alpha);
160  cong->GetAttribute ("Beta", beta);
161  cong->GetAttribute ("Gamma", gamma);
162 
163  if (diff > gamma.Get () && (m_cWnd < m_ssThresh))
164  { // Change from slow-start to linear increase/decrease mode
165  segCwnd = std::min (segCwnd, (uint32_t) expectedCwnd + 1);
166  m_cWnd = segCwnd * m_segmentSize;
167  GetSsThresh (cong);
168  }
169  else if (m_cWnd < m_ssThresh)
170  { // Execute Reno slow start
171  if (m_segmentsAcked >= 1)
172  {
174  m_segmentsAcked--;
175  }
176  }
177  else
178  { // Linear increase/decrease mode
179  if (diff > beta.Get ())
180  {
181  m_cWnd = (segCwnd - 1) * m_segmentSize;
182  GetSsThresh (cong);
183  }
184  else if (diff < alpha.Get ())
185  {
186  m_cWnd = (segCwnd + 1) * m_segmentSize;
187  }
188  else
189  {
190  }
191  }
192  m_ssThresh = std::max (m_ssThresh, 3 * m_cWnd / 4);
193 }
194 
195 void
197 {
199 }
200 
201 
209 {
210 public:
211  TcpVegasTestSuite () : TestSuite ("tcp-vegas-test", UNIT)
212  {
213  AddTestCase (new TcpVegasTest (38 * 1446, 1446, 40 * 1446, MilliSeconds (106), 1, SequenceNumber32 (2893), SequenceNumber32 (5785),
214  "Vegas test on cWnd and ssThresh when in slow start and diff > gamma"),
215  TestCase::QUICK);
216  AddTestCase (new TcpVegasTest (5 * 536, 536, 10 * 536, MilliSeconds (118), 1, SequenceNumber32 (3216), SequenceNumber32 (3753),
217  "Vegas test on cWnd and ssThresh when in slow start and diff < gamma"),
218  TestCase::QUICK);
219  AddTestCase (new TcpVegasTest (60 * 346, 346, 40 * 346, MilliSeconds (206), 1, SequenceNumber32 (20761), SequenceNumber32 (21107),
220  "Vegas test on cWnd and ssThresh when diff > beta"),
221  TestCase::QUICK);
222  AddTestCase (new TcpVegasTest (15 * 1446, 1446, 10 * 1446, MilliSeconds (106), 1, SequenceNumber32 (21691), SequenceNumber32 (24583),
223  "Vegas test on cWnd and ssThresh when diff < alpha"),
224  TestCase::QUICK);
225  AddTestCase (new TcpVegasTest (20 * 746, 746, 10 * 746, MilliSeconds (109), 1, SequenceNumber32 (14921), SequenceNumber32 (15667),
226  "Vegas test on cWnd and ssThresh when alpha <= diff <= beta"),
227  TestCase::QUICK);
228  }
229 };
230 
TcpVegasTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, Time rtt, uint32_t segmentsAcked, SequenceNumber32 nextTxSeq, SequenceNumber32 lastAckedSeq, const std::string &name)
Constructor.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define min(a, b)
Definition: 80211b.c:42
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:202
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1022
uint32_t m_segmentSize
Segment size.
encapsulates test code
Definition: test.h:1155
void IncreaseWindow(Ptr< TcpVegas > cong)
Increases the TCP window.
uint32_t m_ssThresh
Slow Start Threshold.
#define max(a, b)
Definition: 80211b.c:43
SequenceNumber32 m_lastAckedSeq
Last ACKed sequence number.
uint32_t m_cWnd
Congestion window.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
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:168
SequenceNumber32 m_lastAckedSeq
Last sequence ACKed.
virtual void DoRun(void)
Implementation to actually run this TestCase.
uint32_t m_segmentSize
Segment size.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
uint64_t Get(void) const
Definition: uinteger.cc:35
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Adjust cwnd following Vegas linear increase/decrease algorithm.
Definition: tcp-vegas.cc:154
Every class exported by the ns3 library is enclosed in the ns3 namespace.
SequenceNumber32 m_nextTxSeq
Next Tx sequence number.
virtual void CongestionStateSet(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCongState_t newState)
Enable/disable Vegas algorithm depending on the congestion state.
Definition: tcp-vegas.cc:139
Generic "sequence number" class.
Time m_rtt
RTT.
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Compute RTTs needed to execute Vegas algorithm.
Definition: tcp-vegas.cc:98
static TcpVegasTestSuite g_tcpVegasTest
Static variable for test initialization.
TCP Vegas TestSuite.
TracedValue< uint32_t > m_cWnd
Congestion window.
void GetSsThresh(Ptr< TcpVegas > cong)
brief Get and check the SSH threshold.
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:359
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
Time m_minRtt
Minimum RTT observed throughout the connection.
Ptr< TcpSocketState > m_state
TCP socket state.
This test suite implements a Unit Test.
Definition: test.h:1352
uint32_t m_segmentsAcked
Number of segments ACKed.
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:223
TracedValue< SequenceNumber32 > m_nextTxSequence
Next seqnum to be sent (SND.NXT), ReTx pushes it back.
TcpVegas congestion control algorithm test.