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;
116 
117  Ptr<TcpVegas> cong = CreateObject <TcpVegas> ();
118 
119  // Set baseRtt to 100 ms
121 
122  // Re-set Vegas to assign a new value of minRtt
123  cong->CongestionStateSet (m_state, TcpSocketState::CA_OPEN);
125 
126  // 2 more calls to PktsAcked to increment cntRtt beyond 2
129 
130  // Update cwnd using Vegas algorithm
132 
133  // Our calculation of cwnd
134  IncreaseWindow (cong);
135 
137  "CWnd has not updated correctly");
139  "SsThresh has not updated correctly");
140 }
141 
142 void
144 {
145  Time baseRtt = MilliSeconds (100);
146  uint32_t segCwnd = m_cWnd / m_segmentSize;
147 
148  // Calculate expected throughput
149  uint64_t expectedCwnd;
150  expectedCwnd = (uint64_t) segCwnd * (double) baseRtt.GetMilliSeconds () / (double) m_rtt.GetMilliSeconds ();
151 
152  // Calculate the difference between actual and expected throughput
153  uint32_t diff;
154  diff = segCwnd - expectedCwnd;
155 
156  // Get the alpha,beta, and gamma attributes
157  UintegerValue alpha, beta, gamma;
158  cong->GetAttribute ("Alpha", alpha);
159  cong->GetAttribute ("Beta", beta);
160  cong->GetAttribute ("Gamma", gamma);
161 
162  if (diff > gamma.Get () && (m_cWnd < m_ssThresh))
163  { // Change from slow-start to linear increase/decrease mode
164  segCwnd = std::min (segCwnd, (uint32_t) expectedCwnd + 1);
165  m_cWnd = segCwnd * m_segmentSize;
166  GetSsThresh (cong);
167  }
168  else if (m_cWnd < m_ssThresh)
169  { // Execute Reno slow start
170  if (m_segmentsAcked >= 1)
171  {
173  m_segmentsAcked--;
174  }
175  }
176  else
177  { // Linear increase/decrease mode
178  if (diff > beta.Get ())
179  {
180  m_cWnd = (segCwnd - 1) * m_segmentSize;
181  GetSsThresh (cong);
182  }
183  else if (diff < alpha.Get ())
184  {
185  m_cWnd = (segCwnd + 1) * m_segmentSize;
186  }
187  else
188  {
189  }
190  }
191  m_ssThresh = std::max (m_ssThresh, 3 * m_cWnd / 4);
192 }
193 
194 void
196 {
198 }
199 
200 
208 {
209 public:
210  TcpVegasTestSuite () : TestSuite ("tcp-vegas-test", UNIT)
211  {
212  AddTestCase (new TcpVegasTest (38 * 1446, 1446, 40 * 1446, MilliSeconds (106), 1, SequenceNumber32 (2893), SequenceNumber32 (5785),
213  "Vegas test on cWnd and ssThresh when in slow start and diff > gamma"),
214  TestCase::QUICK);
215  AddTestCase (new TcpVegasTest (5 * 536, 536, 10 * 536, MilliSeconds (118), 1, SequenceNumber32 (3216), SequenceNumber32 (3753),
216  "Vegas test on cWnd and ssThresh when in slow start and diff < gamma"),
217  TestCase::QUICK);
218  AddTestCase (new TcpVegasTest (60 * 346, 346, 40 * 346, MilliSeconds (206), 1, SequenceNumber32 (20761), SequenceNumber32 (21107),
219  "Vegas test on cWnd and ssThresh when diff > beta"),
220  TestCase::QUICK);
221  AddTestCase (new TcpVegasTest (15 * 1446, 1446, 10 * 1446, MilliSeconds (106), 1, SequenceNumber32 (21691), SequenceNumber32 (24583),
222  "Vegas test on cWnd and ssThresh when diff < alpha"),
223  TestCase::QUICK);
224  AddTestCase (new TcpVegasTest (20 * 746, 746, 10 * 746, MilliSeconds (109), 1, SequenceNumber32 (14921), SequenceNumber32 (15667),
225  "Vegas test on cWnd and ssThresh when alpha <= diff <= beta"),
226  TestCase::QUICK);
227  }
228 };
229 
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:44
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:201
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1001
uint32_t m_segmentSize
Segment size.
encapsulates test code
Definition: test.h:1155
This test suite implements a Unit Test.
Definition: test.h:1352
void IncreaseWindow(Ptr< TcpVegas > cong)
Increases the TCP window.
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
uint32_t m_ssThresh
Slow Start Threshold.
uint64_t Get(void) const
Definition: uinteger.cc:35
#define max(a, b)
Definition: 80211b.c:45
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.
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Adjust cwnd following Vegas linear increase/decrease algorithm.
Definition: tcp-vegas.cc:155
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:140
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:99
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:223
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.
Ptr< TcpSocketState > m_state
TCP socket state.
uint32_t m_segmentsAcked
Number of segments ACKed.
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:345
TracedValue< SequenceNumber32 > m_nextTxSequence
Next seqnum to be sent (SND.NXT), ReTx pushes it back.
TcpVegas congestion control algorithm test.