A Discrete-Event Network Simulator
API
tcp-slow-start-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 "tcp-slow-start-test.h"
20 #include "ns3/log.h"
21 #include "ns3/simple-channel.h"
22 #include "ns3/internet-module.h"
23 #include "ns3/config.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("TcpSlowStartTest");
28 
29 // TcpSlowStartNormalTest
30 
32  uint32_t packetSize,
33  uint32_t initSsTh,
34  uint32_t packets,
35  TypeId &typeId,
36  const std::string &desc)
37  : TcpGeneralTest (desc),
38  m_ackedBytes (0),
39  m_sentBytes (0),
40  m_totalAckedBytes (0),
41  m_allowedIncrease (0),
42  m_initial (true),
43  m_segmentSize (segmentSize),
44  m_packetSize (packetSize),
45  m_packets (packets)
46 {
47  m_congControlTypeId = typeId;
48 }
49 
50 void
52 {
56 }
57 
58 void
60 {
62  SetInitialSsThresh (SENDER, 400000);
65 }
66 
67 void
69 {
70  NS_FATAL_ERROR ("Drop on the queue; cannot validate slow start");
71 }
72 
73 void
75 {
76  NS_FATAL_ERROR ("Drop on the phy: cannot validate slow start");
77 }
78 
90 void
91 TcpSlowStartNormalTest::CWndTrace (uint32_t oldValue, uint32_t newValue)
92 {
93  uint32_t segSize = GetSegSize (TcpGeneralTest::SENDER);
94  uint32_t increase = newValue - oldValue;
95 
96  if (m_initial)
97  {
98  m_initial = false;
99  NS_LOG_INFO ("Ignored update to " << newValue <<
100  " with a segsize of " << segSize);
101  return;
102  }
103 
104  // The increase in RFC should be <= of segSize. In ns-3 we force = segSize
105  NS_TEST_ASSERT_MSG_EQ (increase, segSize, "Increase different than segsize");
106  NS_TEST_ASSERT_MSG_LT_OR_EQ (newValue, GetInitialSsThresh (SENDER), "cWnd increased over ssth");
107 
108  NS_LOG_INFO ("Incremented cWnd by " << segSize << " bytes in Slow Start " <<
109  "achieving a value of " << newValue);
110 
111  NS_TEST_ASSERT_MSG_GT_OR_EQ (m_allowedIncrease, 1, "Increase not allowed");
113 }
114 
115 void
117 {
118  NS_LOG_FUNCTION (this << p << h << who);
119 
120  if (who == SENDER && Simulator::Now ().GetSeconds () > 5.0)
121  {
123  }
124 }
125 
126 void
128 {
129  NS_LOG_FUNCTION (this << p << h << who);
130 
131  if (who == SENDER && Simulator::Now ().GetSeconds () > 5.0)
132  {
133  uint32_t acked = h.GetAckNumber ().GetValue () - m_totalAckedBytes - 1;
134  m_totalAckedBytes += acked;
135  m_ackedBytes += acked;
136 
137  NS_LOG_INFO ("Ack of " << acked << " bytes, acked this round=" << m_ackedBytes);
138 
139  if (m_ackedBytes >= GetSegSize (SENDER))
140  {
141  NS_LOG_INFO ("FULL ACK achieved, bytes=" << m_ackedBytes);
142  m_allowedIncrease += 1;
144  }
145 
146  while (m_ackedBytes >= GetSegSize (SENDER))
147  {
149  }
150  }
151 }
152 
153 // TcpSlowStartAttackerTest
155  uint32_t packetSize,
156  uint32_t initSsTh,
157  uint32_t packets,
158  TypeId &typeId, const std::string &msg)
159  : TcpSlowStartNormalTest (segmentSize, packetSize, initSsTh, packets, typeId, msg)
160 {
161 
162 }
163 
166 {
167  Ptr<TcpSocketSmallAcks> socket = DynamicCast<TcpSocketSmallAcks> (
168  CreateSocket (node,
171  socket->SetBytesToAck (125);
172 
173  return socket;
174 }
175 
176 
177 //-----------------------------------------------------------------------------
178 
179 static class TcpSlowStartTestSuite : public TestSuite
180 {
181 public:
182  TcpSlowStartTestSuite () : TestSuite ("tcp-slow-start-test", UNIT)
183  {
184  // This test have less packets to transmit than SsTh
185  std::list<TypeId> types;
186  types.insert (types.begin (), TcpNewReno::GetTypeId ());
187  types.insert (types.begin (), TcpWestwood::GetTypeId ());
188 
189  for (std::list<TypeId>::iterator it = types.begin (); it != types.end (); ++it)
190  {
191  AddTestCase (new TcpSlowStartNormalTest (500, 500, 10000, 10, (*it),
192  "slow start 500 byte, " + (*it).GetName ()),
194  AddTestCase (new TcpSlowStartNormalTest (1000, 1000, 10000, 9, (*it),
195  "slow start 1000 byte, " + (*it).GetName ()),
197  AddTestCase (new TcpSlowStartNormalTest (500, 250, 10000, 10, (*it),
198  "slow start small packets, " + (*it).GetName ()),
200  AddTestCase (new TcpSlowStartAttackerTest (500, 500, 10000, 10, (*it),
201  "slow start ack attacker, 500 byte, " + (*it).GetName ()),
203  AddTestCase (new TcpSlowStartAttackerTest (1000, 1000, 10000, 9, (*it),
204  "slow start ack attacker, 1000 byte, " + (*it).GetName ()),
206  }
207  }
209 
210 } // namespace ns3
void PhyDrop(SocketWho who)
Link drop.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint32_t GetSegSize(SocketWho who)
Get the segment size of the node specified.
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
Fast test.
Definition: test.h:1152
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
A suite of tests to run.
Definition: test.h:1333
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition: tcp-header.cc:149
void QueueDrop(SocketWho who)
Drop on the queue.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void SetAppPktSize(uint32_t pktSize)
Set app packet size.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
virtual void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
This test suite implements a Unit Test.
Definition: test.h:1343
virtual void ConfigureEnvironment()
Change the configuration of the evironment.
static TypeId GetTypeId(void)
Get the type ID.
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
virtual void ConfigureProperties(void)
Change the configuration of the socket properties.
void SetSegmentSize(SocketWho who, uint32_t segmentSize)
Forcefully set the segment size.
#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
TcpSlowStartAttackerTest(uint32_t segmentSize, uint32_t packetSize, uint32_t initSsTh, uint32_t packets, TypeId &congControl, const std::string &desc)
TcpSlowStartNormalTest(uint32_t segmentSize, uint32_t packetSize, uint32_t initSsTh, uint32_t packets, TypeId &congControl, const std::string &desc)
virtual Ptr< TcpSocketMsgBase > CreateSocket(Ptr< Node > node, TypeId socketType, TypeId congControl)
Create a socket.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
uint32_t GetInitialSsThresh(SocketWho who)
Get the initial slow start threshold.
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-westwood.cc:47
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
void SetInitialSsThresh(SocketWho who, uint32_t initialSsThresh)
Forcefully set the initial ssth.
ns3::TcpSlowStartTestSuite g_tcpSlowStartTestSuite
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
General infrastructure for TCP testing.
virtual void ConfigureEnvironment(void)
Change the configuration of the evironment.
static TypeId GetTypeId(void)
A slow start test using a socket which sends smaller ACKs.
#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:825
static const uint32_t packetSize
#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg)
Test that an actual value is greater than or equal to a limit and report and abort if not...
Definition: test.h:1011
a unique identifier for an interface.
Definition: type-id.h:58
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
virtual void CWndTrace(uint32_t oldValue, uint32_t newValue)
Trace the cWnd over the slow start.
virtual void ConfigureProperties()
Change the configuration of the socket properties.
Test the normal behavior for slow start.
TypeId m_congControlTypeId
Congestion control.