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/tcp-westwood.h"
22 #include "ns3/config.h"
23 #include "ns3/test.h"
24 #include "tcp-general-test.h"
25 
26 using namespace ns3;
27 
28 NS_LOG_COMPONENT_DEFINE ("TcpNewRenoCongAvoidTest");
29 
56 class
58 {
59 public:
69  uint32_t packets, TypeId& congControl,
70  const std::string &desc);
71 protected:
72  virtual void CWndTrace (uint32_t oldValue, uint32_t newValue);
73  virtual void QueueDrop (SocketWho who);
74  virtual void PhyDrop (SocketWho who);
75  virtual void NormalClose (SocketWho who);
80  void Check ();
81 
82  virtual void ConfigureEnvironment ();
83  virtual void ConfigureProperties ();
84 
85 private:
86  uint32_t m_segmentSize;
87  uint32_t m_packetSize;
88  uint32_t m_packets;
89  uint32_t m_increment;
91  bool m_initial;
92 };
93 
94 
96  uint32_t packetSize,
97  uint32_t packets,
98  TypeId &typeId,
99  const std::string &desc)
100  : TcpGeneralTest (desc),
101  m_segmentSize (segmentSize),
102  m_packetSize (packetSize),
103  m_packets (packets),
104  m_increment (0),
105  m_initial (true)
106 {
107  m_congControlTypeId = typeId;
108 }
109 
110 void
112 {
113  TcpGeneralTest::ConfigureEnvironment ();
116  SetMTU (1500);
117 }
118 
120 {
121  TcpGeneralTest::ConfigureProperties ();
124 }
125 
126 void
127 TcpNewRenoCongAvoidNormalTest::CWndTrace (uint32_t oldValue, uint32_t newValue)
128 {
129  if (m_initial)
130  {
131  m_initial = false;
132  return;
133  }
134 
135  if (!m_event.IsRunning ())
136  {
137  m_event = Simulator::Schedule (Seconds (1.0),
139  }
140 
141  m_increment += newValue - oldValue;
142 }
143 
144 void
146 {
147  NS_FATAL_ERROR ("Drop on the queue; cannot validate congestion avoidance");
148 }
149 
150 void
152 {
153  NS_FATAL_ERROR ("Drop on the phy: cannot validate congestion avoidance");
154 }
155 
156 void
158 {
159  uint32_t segSize = GetSegSize (TcpGeneralTest::SENDER);
160 
161  if (m_increment != 0)
162  {
164  "Increment exceeded segment size in one RTT");
165  }
166 
167  m_increment = 0;
168 
169  m_event = Simulator::Schedule (Seconds (1.0),
171 
172 }
173 
174 void
176 {
177  if (who == SENDER)
178  {
179  m_event.Cancel ();
180  }
181 }
182 
183 
184 
192 {
193 public:
194  TcpRenoCongAvoidTestSuite () : TestSuite ("tcp-cong-avoid-test", UNIT)
195  {
196  std::list<TypeId> types;
197  types.insert (types.begin (), TcpWestwood::GetTypeId ());
198  types.insert (types.begin (), TcpNewReno::GetTypeId ());
199 
200  for (std::list<TypeId>::iterator it = types.begin (); it != types.end (); ++it)
201  {
202  for (uint32_t i = 10; i <= 50; i += 10)
203  {
204  AddTestCase (new TcpNewRenoCongAvoidNormalTest (500, 500, i, (*it),
205  "cong avoid MSS=500, pkt_size=500," + (*it).GetName ()),
206  TestCase::QUICK);
207  AddTestCase (new TcpNewRenoCongAvoidNormalTest (500, 1000, i, (*it),
208  "cong avoid MSS=500, pkt_size=1000," + (*it).GetName ()),
209  TestCase::QUICK);
210  }
211  }
212  }
213 };
214 
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_TEST_ASSERT_MSG_LT_OR_EQ
#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:830
ns3::TcpGeneralTest::SocketWho
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
Definition: tcp-general-test.h:275
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
TcpNewRenoCongAvoidNormalTest::m_packets
uint32_t m_packets
Number of packets.
Definition: tcp-cong-avoid-test.cc:88
ns3::EventId
An identifier for simulation events.
Definition: event-id.h:54
TcpNewRenoCongAvoidNormalTest::QueueDrop
virtual void QueueDrop(SocketWho who)
Drop on the queue.
Definition: tcp-cong-avoid-test.cc:145
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TcpGeneralTest::SENDER
@ SENDER
Sender node.
Definition: tcp-general-test.h:276
TcpNewRenoCongAvoidNormalTest::ConfigureEnvironment
virtual void ConfigureEnvironment()
Change the configuration of the environment.
Definition: tcp-cong-avoid-test.cc:111
ns3::TcpGeneralTest::SetAppPktCount
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
Definition: tcp-general-test.h:650
TcpNewRenoCongAvoidNormalTest::m_segmentSize
uint32_t m_segmentSize
Segment size.
Definition: tcp-cong-avoid-test.cc:86
TcpNewRenoCongAvoidNormalTest::ConfigureProperties
virtual void ConfigureProperties()
Change the configuration of the socket properties.
Definition: tcp-cong-avoid-test.cc:119
ns3::TcpGeneralTest::GetSegSize
uint32_t GetSegSize(SocketWho who)
Get the segment size of the node specified.
Definition: tcp-general-test.cc:637
ns3::TcpGeneralTest::SetMTU
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
Definition: tcp-general-test.h:692
TcpNewRenoCongAvoidNormalTest::CWndTrace
virtual void CWndTrace(uint32_t oldValue, uint32_t newValue)
Tracks the congestion window changes.
Definition: tcp-cong-avoid-test.cc:127
TcpNewRenoCongAvoidNormalTest::NormalClose
virtual void NormalClose(SocketWho who)
Socket closed normally.
Definition: tcp-cong-avoid-test.cc:175
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
ns3::EventId::IsRunning
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
TcpNewRenoCongAvoidNormalTest::m_packetSize
uint32_t m_packetSize
Size of the packets.
Definition: tcp-cong-avoid-test.cc:87
ns3::EventId::Cancel
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
TcpNewRenoCongAvoidNormalTest
Test the behavior of RFC congestion avoidance.
Definition: tcp-cong-avoid-test.cc:58
TcpRenoCongAvoidTestSuite::TcpRenoCongAvoidTestSuite
TcpRenoCongAvoidTestSuite()
Definition: tcp-cong-avoid-test.cc:194
g_tcpCongAvoidNormalTest
static TcpRenoCongAvoidTestSuite g_tcpCongAvoidNormalTest
Static variable for test initialization.
Definition: tcp-cong-avoid-test.cc:215
tcp-general-test.h
ns3::TcpGeneralTest
General infrastructure for TCP testing.
Definition: tcp-general-test.h:257
ns3::TestSuite
A suite of tests to run.
Definition: test.h:1344
TcpRenoCongAvoidTestSuite
TestSuite for the behavior of RFC congestion avoidance.
Definition: tcp-cong-avoid-test.cc:192
packetSize
static const uint32_t packetSize
Definition: wifi-power-adaptation-distance.cc:113
ns3::TestSuite::UNIT
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1353
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::TcpGeneralTest::m_congControlTypeId
TypeId m_congControlTypeId
Congestion control.
Definition: tcp-general-test.h:1036
segmentSize
uint32_t segmentSize
Definition: tcp-linux-reno.cc:53
TcpNewRenoCongAvoidNormalTest::TcpNewRenoCongAvoidNormalTest
TcpNewRenoCongAvoidNormalTest(uint32_t segmentSize, uint32_t packetSize, uint32_t packets, TypeId &congControl, const std::string &desc)
Constructor.
Definition: tcp-cong-avoid-test.cc:95
TcpNewRenoCongAvoidNormalTest::PhyDrop
virtual void PhyDrop(SocketWho who)
Link drop.
Definition: tcp-cong-avoid-test.cc:151
ns3::TcpGeneralTest::SetAppPktSize
void SetAppPktSize(uint32_t pktSize)
Set app packet size.
Definition: tcp-general-test.h:641
TcpNewRenoCongAvoidNormalTest::m_event
EventId m_event
Check event.
Definition: tcp-cong-avoid-test.cc:90
ns3::TcpGeneralTest::SetInitialSsThresh
void SetInitialSsThresh(SocketWho who, uint32_t initialSsThresh)
Forcefully set the initial ssthresh.
Definition: tcp-general-test.cc:1022
TcpNewRenoCongAvoidNormalTest::Check
void Check()
Called each RTT (1.0 sec in the testing environment) and check that the overall increment in this RTT...
Definition: tcp-cong-avoid-test.cc:157
TcpNewRenoCongAvoidNormalTest::m_initial
bool m_initial
True on first run.
Definition: tcp-cong-avoid-test.cc:91
TcpNewRenoCongAvoidNormalTest::m_increment
uint32_t m_increment
Congestion window increment.
Definition: tcp-cong-avoid-test.cc:89
ns3::TcpGeneralTest::SetSegmentSize
void SetSegmentSize(SocketWho who, uint32_t segmentSize)
Forcefully set the segment size.
Definition: tcp-general-test.cc:922