A Discrete-Event Network Simulator
API
tcp-slow-start-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Natale Patriciello <natale.patriciello@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 */
18#include "tcp-general-test.h"
19
20#include "ns3/config.h"
21#include "ns3/log.h"
22#include "ns3/node.h"
23#include "ns3/simple-channel.h"
24#include "ns3/tcp-header.h"
25#include "ns3/test.h"
26
27using namespace ns3;
28
29NS_LOG_COMPONENT_DEFINE("TcpSlowStartTest");
30
47{
48 public:
60 uint32_t initSsTh,
61 uint32_t packets,
62 const TypeId& congControl,
63 const std::string& desc);
64
65 protected:
66 void CWndTrace(uint32_t oldValue, uint32_t newValue) override;
67 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
68 void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
69 void QueueDrop(SocketWho who) override;
70 void PhyDrop(SocketWho who) override;
71
72 void ConfigureEnvironment() override;
73 void ConfigureProperties() override;
74
79
80 bool m_initial;
81
82 private:
86};
87
90 uint32_t initSsTh,
91 uint32_t packets,
92 const TypeId& typeId,
93 const std::string& desc)
94 : TcpGeneralTest(desc),
95 m_ackedBytes(0),
96 m_sentBytes(0),
97 m_totalAckedBytes(0),
98 m_allowedIncrease(0),
99 m_initial(true),
100 m_segmentSize(segmentSize),
101 m_packetSize(packetSize),
102 m_packets(packets)
103{
104 m_congControlTypeId = typeId;
105}
106
107void
109{
110 TcpGeneralTest::ConfigureEnvironment();
113}
114
115void
117{
118 TcpGeneralTest::ConfigureProperties();
119 SetInitialSsThresh(SENDER, 400000);
122}
123
124void
126{
127 NS_FATAL_ERROR("Drop on the queue; cannot validate slow start");
128}
129
130void
132{
133 NS_FATAL_ERROR("Drop on the phy: cannot validate slow start");
134}
135
147void
149{
150 uint32_t segSize = GetSegSize(TcpGeneralTest::SENDER);
151 uint32_t increase = newValue - oldValue;
152
153 if (m_initial)
154 {
155 m_initial = false;
156 NS_LOG_INFO("Ignored update to " << newValue << " with a segsize of " << segSize);
157 return;
158 }
159
160 // The increase in RFC should be <= of segSize. In ns-3 we force = segSize
161 NS_TEST_ASSERT_MSG_EQ(increase, segSize, "Increase different than segsize");
162 NS_TEST_ASSERT_MSG_LT_OR_EQ(newValue, GetInitialSsThresh(SENDER), "cWnd increased over ssth");
163
164 NS_LOG_INFO("Incremented cWnd by " << segSize << " bytes in Slow Start "
165 << "achieving a value of " << newValue);
166
167 NS_TEST_ASSERT_MSG_GT_OR_EQ(m_allowedIncrease, 1, "Increase not allowed");
169}
170
171void
173{
174 NS_LOG_FUNCTION(this << p << h << who);
175
176 if (who == SENDER && Simulator::Now().GetSeconds() > 5.0)
177 {
178 m_sentBytes += GetSegSize(TcpGeneralTest::SENDER);
179 }
180}
181
182void
184{
185 NS_LOG_FUNCTION(this << p << h << who);
186
187 if (who == SENDER && Simulator::Now().GetSeconds() > 5.0)
188 {
190 m_totalAckedBytes += acked;
191 m_ackedBytes += acked;
192
193 NS_LOG_INFO("Ack of " << acked << " bytes, acked this round=" << m_ackedBytes);
194
196 {
197 NS_LOG_INFO("FULL ACK achieved, bytes=" << m_ackedBytes);
200 }
201
202 while (m_ackedBytes >= GetSegSize(SENDER))
203 {
205 }
206 }
207}
208
221{
222 public:
234 uint32_t initSsTh,
235 uint32_t packets,
236 const TypeId& congControl,
237 const std::string& desc);
238
239 protected:
241};
242
245 uint32_t initSsTh,
246 uint32_t packets,
247 const TypeId& typeId,
248 const std::string& msg)
249 : TcpSlowStartNormalTest(segmentSize, packetSize, initSsTh, packets, typeId, msg)
250{
251}
252
255{
256 Ptr<TcpSocketSmallAcks> socket = DynamicCast<TcpSocketSmallAcks>(
257 CreateSocket(node, TcpSocketSmallAcks::GetTypeId(), m_congControlTypeId));
258 socket->SetBytesToAck(125);
259
260 return socket;
261}
262
270{
271 public:
273 : TestSuite("tcp-slow-start-test", UNIT)
274 {
275 // This test have less packets to transmit than SsTh
276 std::list<TypeId> types = {
277 TcpNewReno::GetTypeId(),
278 };
279
280 for (const auto& t : types)
281 {
282 std::string typeName = t.GetName();
283
285 500,
286 10000,
287 10,
288 t,
289 "slow start 500 byte, " + typeName),
290 TestCase::QUICK);
292 1000,
293 10000,
294 9,
295 t,
296 "slow start 1000 byte, " + typeName),
297 TestCase::QUICK);
299 250,
300 10000,
301 10,
302 t,
303 "slow start small packets, " + typeName),
304 TestCase::QUICK);
307 500,
308 10000,
309 10,
310 t,
311 "slow start ack attacker, 500 byte, " + typeName),
312 TestCase::QUICK);
315 1000,
316 10000,
317 9,
318 t,
319 "slow start ack attacker, 1000 byte, " + typeName),
320 TestCase::QUICK);
321 }
322 }
323};
324
A slow start test using a socket which sends smaller ACKs.
TcpSlowStartAttackerTest(uint32_t segmentSize, uint32_t packetSize, uint32_t initSsTh, uint32_t packets, const TypeId &congControl, const std::string &desc)
Constructor.
Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node) override
Create and install the socket to install on the receiver.
Test the normal behavior for slow start.
bool m_initial
First cycle flag.
TcpSlowStartNormalTest(uint32_t segmentSize, uint32_t packetSize, uint32_t initSsTh, uint32_t packets, const TypeId &congControl, const std::string &desc)
Constructor.
void CWndTrace(uint32_t oldValue, uint32_t newValue) override
Trace the cWnd over the slow start.
void ConfigureEnvironment() override
Change the configuration of the environment.
uint32_t m_packetSize
Packet size.
void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet transmitted down to IP layer.
uint32_t m_packets
Packet counter.
uint32_t m_ackedBytes
ACKed bytes.
uint32_t m_segmentSize
Segment size.
void PhyDrop(SocketWho who) override
Link drop.
void QueueDrop(SocketWho who) override
Drop on the queue.
uint32_t m_sentBytes
Sent bytes.
uint32_t m_totalAckedBytes
Total ACKed bytes.
void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet received from IP layer.
void ConfigureProperties() override
Change the configuration of the socket properties.
uint32_t m_allowedIncrease
Allowed increase.
TCP Slow Start TestSuite.
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
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.
@ RECEIVER
Receiver node.
void SetAppPktSize(uint32_t pktSize)
Set app packet size.
uint32_t GetInitialSsThresh(SocketWho who)
Get the initial slow start threshold.
virtual Ptr< TcpSocketMsgBase > CreateSocket(Ptr< Node > node, TypeId socketType, TypeId congControl)
Create a socket.
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.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:46
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition: tcp-header.cc:143
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
std::string GetName() const
Definition: test.cc:377
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
a unique identifier for an interface.
Definition: type-id.h:60
uint32_t segmentSize
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:160
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:296
#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:144
#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:750
#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:915
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpSlowStartTestSuite g_tcpSlowStartTestSuite
Static variable for test initialization.
static const uint32_t packetSize
Packet size generated at the AP.