A Discrete-Event Network Simulator
API
tcp-cong-avoid-test.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 Natale Patriciello <natale.patriciello@gmail.com>
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  */
19 #include "ns3/log.h"
20 #include "ns3/simple-channel.h"
21 #include "ns3/config.h"
22 #include "ns3/test.h"
23 #include "tcp-general-test.h"
24 
25 using namespace ns3;
26 
27 NS_LOG_COMPONENT_DEFINE ("TcpNewRenoCongAvoidTest");
28 
55 class
57 {
58 public:
68  uint32_t packets, const TypeId& congControl,
69  const std::string &desc);
70 protected:
71  virtual void CWndTrace (uint32_t oldValue, uint32_t newValue);
72  virtual void QueueDrop (SocketWho who);
73  virtual void PhyDrop (SocketWho who);
74  virtual void NormalClose (SocketWho who);
79  void Check ();
80 
81  virtual void ConfigureEnvironment ();
82  virtual void ConfigureProperties ();
83 
84 private:
85  uint32_t m_segmentSize;
86  uint32_t m_packetSize;
87  uint32_t m_packets;
88  uint32_t m_increment;
90  bool m_initial;
91 };
92 
93 
95  uint32_t packetSize,
96  uint32_t packets,
97  const TypeId &typeId,
98  const std::string &desc)
99  : TcpGeneralTest (desc),
100  m_segmentSize (segmentSize),
101  m_packetSize (packetSize),
102  m_packets (packets),
103  m_increment (0),
104  m_initial (true)
105 {
106  m_congControlTypeId = typeId;
107 }
108 
109 void
111 {
112  TcpGeneralTest::ConfigureEnvironment ();
115  SetMTU (1500);
116 }
117 
119 {
120  TcpGeneralTest::ConfigureProperties ();
123 }
124 
125 void
126 TcpNewRenoCongAvoidNormalTest::CWndTrace (uint32_t oldValue, uint32_t newValue)
127 {
128  if (m_initial)
129  {
130  m_initial = false;
131  return;
132  }
133 
134  if (!m_event.IsRunning ())
135  {
136  m_event = Simulator::Schedule (Seconds (1.0),
138  }
139 
140  m_increment += newValue - oldValue;
141 }
142 
143 void
145 {
146  NS_FATAL_ERROR ("Drop on the queue; cannot validate congestion avoidance");
147 }
148 
149 void
151 {
152  NS_FATAL_ERROR ("Drop on the phy: cannot validate congestion avoidance");
153 }
154 
155 void
157 {
158  uint32_t segSize = GetSegSize (TcpGeneralTest::SENDER);
159 
160  if (m_increment != 0)
161  {
163  "Increment exceeded segment size in one RTT");
164  }
165 
166  m_increment = 0;
167 
168  m_event = Simulator::Schedule (Seconds (1.0),
170 
171 }
172 
173 void
175 {
176  if (who == SENDER)
177  {
178  m_event.Cancel ();
179  }
180 }
181 
182 
183 
191 {
192 public:
193  TcpRenoCongAvoidTestSuite () : TestSuite ("tcp-cong-avoid-test", UNIT)
194  {
195  std::list<TypeId> types = {
196  TcpNewReno::GetTypeId (),
197  };
198 
199  for (const auto &t : types)
200  {
201  std::string typeName = t.GetName ();
202 
203  for (uint32_t i = 10; i <= 50; i += 10)
204  {
205  AddTestCase (new TcpNewRenoCongAvoidNormalTest (500, 500, i, t, "cong avoid MSS=500, pkt_size=500," + typeName),
206  TestCase::QUICK);
207  AddTestCase (new TcpNewRenoCongAvoidNormalTest (500, 1000, i, t, "cong avoid MSS=500, pkt_size=1000," + typeName),
208  TestCase::QUICK);
209  }
210  }
211  }
212 };
213 
Test the behavior of RFC congestion avoidance.
void Check()
Called each RTT (1.0 sec in the testing environment) and check that the overall increment in this RTT...
virtual void CWndTrace(uint32_t oldValue, uint32_t newValue)
uint32_t m_segmentSize
Segment size.
virtual void NormalClose(SocketWho who)
uint32_t m_packets
Number of packets.
virtual void PhyDrop(SocketWho who)
virtual void ConfigureProperties()
Change the configuration of the socket properties.
bool m_initial
True on first run.
TcpNewRenoCongAvoidNormalTest(uint32_t segmentSize, uint32_t packetSize, uint32_t packets, const TypeId &congControl, const std::string &desc)
Constructor.
virtual void QueueDrop(SocketWho who)
virtual void ConfigureEnvironment()
Change the configuration of the environment.
uint32_t m_packetSize
Size of the packets.
uint32_t m_increment
Congestion window increment.
TestSuite for the behavior of RFC congestion avoidance.
An identifier for simulation events.
Definition: event-id.h:54
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
General infrastructure for TCP testing.
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
void SetAppPktSize(uint32_t pktSize)
Set app packet size.
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
uint32_t GetSegSize(SocketWho who)
Get the segment size of the node specified.
TypeId m_congControlTypeId
Congestion control.
void SetInitialSsThresh(SocketWho who, uint32_t initialSsThresh)
Forcefully set the initial ssthresh.
void SetSegmentSize(SocketWho who, uint32_t segmentSize)
Forcefully set the segment size.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
std::string GetName(void) const
Definition: test.cc:370
A suite of tests to run.
Definition: test.h:1188
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1197
a unique identifier for an interface.
Definition: type-id.h:59
uint32_t segmentSize
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpRenoCongAvoidTestSuite g_tcpCongAvoidNormalTest
Static variable for test initialization.
static const uint32_t packetSize