This documentation is not the Latest Release.
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, packetSize, packets, Seconds (0.01), Seconds (0.5),
38  Seconds (10), initSsTh, 1, segmentSize, typeId, 1500),
39  m_ackedBytes (0),
40  m_sentBytes (0),
41  m_totalAckedBytes (0),
42  m_allowedIncrease (0),
43  m_initial (true)
44 {
45 }
46 
58 void
59 TcpSlowStartNormalTest::CWndTrace (uint32_t oldValue, uint32_t newValue)
60 {
61  uint32_t segSize = GetSegSize (TcpGeneralTest::SENDER);
62  uint32_t increase = newValue - oldValue;
63 
64  if (m_initial)
65  {
66  m_initial = false;
67  NS_LOG_INFO ("Ignored update to " << newValue <<
68  " with a segsize of " << segSize);
69  return;
70  }
71 
72  // The increase in RFC should be <= of segSize. In ns-3 we force = segSize
73  NS_TEST_ASSERT_MSG_EQ (increase, segSize, "Increase different than segsize");
74  NS_TEST_ASSERT_MSG_LT_OR_EQ (newValue, GetInitialSsThresh (), "cWnd increased over ssth");
75 
76  NS_LOG_INFO ("Incremented cWnd by " << segSize << " bytes in Slow Start " <<
77  "achieving a value of " << newValue);
78 
79  NS_TEST_ASSERT_MSG_GT_OR_EQ (m_allowedIncrease, 1, "Increase not allowed");
81 }
82 
83 void
85 {
86  NS_LOG_FUNCTION (this << p << h << who);
87 
88  if (who == SENDER && Simulator::Now ().GetSeconds () > 5.0)
89  {
91  }
92 }
93 
94 void
96 {
97  NS_LOG_FUNCTION (this << p << h << who);
98 
99  if (who == SENDER && Simulator::Now ().GetSeconds () > 5.0)
100  {
101  uint32_t acked = h.GetAckNumber().GetValue() - m_totalAckedBytes - 1;
102  m_totalAckedBytes += acked;
103  m_ackedBytes += acked;
104 
105  NS_LOG_INFO ("Ack of " << acked << " bytes, acked this round=" << m_ackedBytes);
106 
107  if (m_ackedBytes >= GetSegSize (SENDER))
108  {
109  NS_LOG_INFO ("FULL ACK achieved, bytes=" << m_ackedBytes);
110  m_allowedIncrease += 1;
112  }
113 
114  while (m_ackedBytes >= GetSegSize (SENDER))
115  {
117  }
118  }
119 }
120 
121 // TcpSlowStartAttackerTest
123  uint32_t packetSize,
124  uint32_t initSsTh,
125  uint32_t packets,
126  TypeId &typeId, const std::string &msg)
127  : TcpSlowStartNormalTest (segmentSize, packetSize, initSsTh, packets, typeId, msg)
128 {
129 
130 }
131 
134 {
135  Ptr<TcpSocketSmallAcks> socket = DynamicCast<TcpSocketSmallAcks> (
136  CreateSocket (node,
139  socket->SetBytesToAck (125);
140 
141  return socket;
142 }
143 
144 
145 //-----------------------------------------------------------------------------
146 
147 static class TcpSlowStartTestSuite : public TestSuite
148 {
149 public:
150  TcpSlowStartTestSuite () : TestSuite ("tcp-slow-start-test", UNIT)
151  {
152  // This test have less packets to transmit than SsTh
153  std::list<TypeId> types;
154  types.insert (types.begin (), TcpNewReno::GetTypeId ());
155  types.insert (types.begin (), TcpWestwood::GetTypeId ());
156 
157  for (std::list<TypeId>::iterator it = types.begin (); it != types.end (); ++it)
158  {
159  AddTestCase (new TcpSlowStartNormalTest (500, 500, 10000, 10, (*it),
160  "slow start 500 byte, " + (*it).GetName ()),
162  AddTestCase (new TcpSlowStartNormalTest (1000, 1000, 10000, 9, (*it),
163  "slow start 1000 byte, " + (*it).GetName ()),
165  AddTestCase (new TcpSlowStartNormalTest (500, 250, 10000, 10, (*it),
166  "slow start small packets, " + (*it).GetName ()),
168  AddTestCase (new TcpSlowStartAttackerTest (500, 500, 10000, 10, (*it),
169  "slow start ack attacker, 500 byte, " + (*it).GetName ()),
171  AddTestCase (new TcpSlowStartAttackerTest (1000, 1000, 10000, 9, (*it),
172  "slow start ack attacker, 1000 byte, " + (*it).GetName ()),
174  }
175  }
177 
178 } // namespace ns3
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
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
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:297
#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
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:223
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.
static TypeId GetTypeId(void)
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
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
uint32_t GetInitialSsThresh() const
Get the initial slow start threshold.
#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.
Test the normal behavior for slow start.
TypeId m_congControlTypeId
Congestion control.