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 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("TcpVegasTestSuite");
36 
40 class TcpVegasTest : public TestCase
41 {
42 public:
43  TcpVegasTest (uint32_t cWnd,
44  uint32_t segmentSize,
45  uint32_t ssThresh,
46  Time rtt,
47  uint32_t segmentsAcked,
48  SequenceNumber32 nextTxSeq,
49  SequenceNumber32 lastAckedSeq,
50  const std::string &name);
51 
52 private:
53  virtual void DoRun (void);
54  void IncreaseWindow (Ptr<TcpVegas> cong);
55  void GetSsThresh (Ptr<TcpVegas> cong);
56 
57  uint32_t m_cWnd;
58  uint32_t m_segmentSize;
59  uint32_t m_ssThresh;
61  uint32_t m_segmentsAcked;
65 };
66 
68  uint32_t segmentSize,
69  uint32_t ssThresh,
70  Time rtt,
71  uint32_t segmentsAcked,
72  SequenceNumber32 nextTxSeq,
73  SequenceNumber32 lastAckedSeq,
74  const std::string &name)
75  : TestCase (name),
76  m_cWnd (cWnd),
77  m_segmentSize (segmentSize),
78  m_ssThresh (ssThresh),
79  m_rtt (rtt),
80  m_segmentsAcked (segmentsAcked),
81  m_nextTxSeq (nextTxSeq),
82  m_lastAckedSeq (lastAckedSeq)
83 {
84 }
85 
86 void
88 {
89  m_state = CreateObject<TcpSocketState> ();
90 
91  m_state->m_cWnd = m_cWnd;
92  m_state->m_segmentSize = m_segmentSize;
93  m_state->m_ssThresh = m_ssThresh;
94  m_state->m_nextTxSequence = m_nextTxSeq;
95  m_state->m_lastAckedSeq = m_lastAckedSeq;
96 
97  Ptr<TcpVegas> cong = CreateObject <TcpVegas> ();
98 
99  // Set baseRtt to 100 ms
100  cong->PktsAcked (m_state, m_segmentsAcked, MilliSeconds (100));
101 
102  // Re-set Vegas to assign a new value of minRtt
103  cong->CongestionStateSet (m_state, TcpSocketState::CA_OPEN);
104  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
105 
106  // 2 more calls to PktsAcked to increment cntRtt beyond 2
107  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
108  cong->PktsAcked (m_state, m_segmentsAcked, m_rtt);
109 
110  // Update cwnd using Vegas algorithm
111  cong->IncreaseWindow (m_state, m_segmentsAcked);
112 
113  // Our calculation of cwnd
114  IncreaseWindow (cong);
115 
116  NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), m_cWnd,
117  "CWnd has not updated correctly");
118  NS_TEST_ASSERT_MSG_EQ (m_state->m_ssThresh.Get (), m_ssThresh,
119  "SsThresh has not updated correctly");
120 }
121 
122 void
124 {
125  Time baseRtt = MilliSeconds (100);
126  uint32_t segCwnd = m_cWnd / m_segmentSize;
127 
128  // Calculate expected throughput
129  uint64_t expectedCwnd;
130  expectedCwnd = (uint64_t) segCwnd * (double) baseRtt.GetMilliSeconds () / (double) m_rtt.GetMilliSeconds ();
131 
132  // Calculate the difference between actual and expected throughput
133  uint32_t diff;
134  diff = segCwnd - expectedCwnd;
135 
136  // Get the alpha,beta, and gamma attributes
137  UintegerValue alpha, beta, gamma;
138  cong->GetAttribute ("Alpha", alpha);
139  cong->GetAttribute ("Beta", beta);
140  cong->GetAttribute ("Gamma", gamma);
141 
142  if (diff > gamma.Get () && (m_cWnd < m_ssThresh))
143  { // Change from slow-start to linear increase/decrease mode
144  segCwnd = std::min (segCwnd, (uint32_t) expectedCwnd + 1);
145  m_cWnd = segCwnd * m_segmentSize;
146  GetSsThresh (cong);
147  }
148  else if (m_cWnd < m_ssThresh)
149  { // Execute Reno slow start
150  if (m_segmentsAcked >= 1)
151  {
153  m_segmentsAcked--;
154  }
155  }
156  else
157  { // Linear increase/decrease mode
158  if (diff > beta.Get ())
159  {
160  m_cWnd = (segCwnd - 1) * m_segmentSize;
161  GetSsThresh (cong);
162  }
163  else if (diff < alpha.Get ())
164  {
165  m_cWnd = (segCwnd + 1) * m_segmentSize;
166  }
167  else
168  {
169  }
170  }
171  m_ssThresh = std::max (m_ssThresh, 3 * m_cWnd / 4);
172 }
173 
174 void
176 {
178 }
179 
180 // -------------------------------------------------------------------
181 static class TcpVegasTestSuite : public TestSuite
182 {
183 public:
184  TcpVegasTestSuite () : TestSuite ("tcp-vegas-test", UNIT)
185  {
186  AddTestCase (new TcpVegasTest (38 * 1446, 1446, 40 * 1446, MilliSeconds (106), 1, SequenceNumber32 (2893), SequenceNumber32 (5785),
187  "Vegas test on cWnd and ssThresh when in slow start and diff > gamma"),
189  AddTestCase (new TcpVegasTest (5 * 536, 536, 10 * 536, MilliSeconds (118), 1, SequenceNumber32 (3216), SequenceNumber32 (3753),
190  "Vegas test on cWnd and ssThresh when in slow start and diff < gamma"),
192  AddTestCase (new TcpVegasTest (60 * 346, 346, 40 * 346, MilliSeconds (206), 1, SequenceNumber32 (20761), SequenceNumber32 (21107),
193  "Vegas test on cWnd and ssThresh when diff > beta"),
195  AddTestCase (new TcpVegasTest (15 * 1446, 1446, 10 * 1446, MilliSeconds (106), 1, SequenceNumber32 (21691), SequenceNumber32 (24583),
196  "Vegas test on cWnd and ssThresh when diff < alpha"),
198  AddTestCase (new TcpVegasTest (20 * 746, 746, 10 * 746, MilliSeconds (109), 1, SequenceNumber32 (14921), SequenceNumber32 (15667),
199  "Vegas test on cWnd and ssThresh when alpha <= diff <= beta"),
201  }
203 
204 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Normal state, no dubious events.
#define min(a, b)
Definition: 80211b.c:44
uint32_t m_segmentsAcked
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
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:903
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
SequenceNumber32 m_nextTxSeq
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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TcpVegasTestSuite g_tcpVegasTest
SequenceNumber32 m_lastAckedSeq
virtual void DoRun(void)
Implementation to actually run this TestCase.
TcpVegasTest(uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, Time rtt, uint32_t segmentsAcked, SequenceNumber32 nextTxSeq, SequenceNumber32 lastAckedSeq, const std::string &name)
void IncreaseWindow(Ptr< TcpVegas > cong)
Ptr< TcpSocketState > m_state
Testing TcpVegas congestion control algorithm.
void GetSsThresh(Ptr< TcpVegas > cong)
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:345