A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7#include "tcp-general-test.h"
8
9#include "ns3/config.h"
10#include "ns3/log.h"
11#include "ns3/node.h"
12#include "ns3/simple-channel.h"
13#include "ns3/tcp-header.h"
14#include "ns3/test.h"
15
16using namespace ns3;
17
18NS_LOG_COMPONENT_DEFINE("TcpSlowStartTest");
19
20/**
21 * \ingroup internet-test
22 *
23 * \brief Test the normal behavior for slow start
24 *
25 * As method for checking the slow start, a callback is attached to the
26 * congestion window. With the knowledge of the number of segments, we can calculate
27 * if the value of the cWnd is right. Also, with a fixed delay for each packet,
28 * we can know if the timing is correct.
29 *
30 * Check what is done inside CWndTrace.
31 *
32 * \see CWndTrace
33 */
35{
36 public:
37 /**
38 * \brief Constructor.
39 * \param segmentSize Segment size.
40 * \param packetSize Packet size.
41 * \param initSsTh Initial SlowStart threshold.
42 * \param packets Packet counter.
43 * \param congControl Congestion control.
44 * \param desc Test description.
45 */
48 uint32_t initSsTh,
49 uint32_t packets,
50 const TypeId& congControl,
51 const std::string& desc);
52
53 protected:
54 void CWndTrace(uint32_t oldValue, uint32_t newValue) override;
55 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
56 void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
57 void QueueDrop(SocketWho who) override;
58 void PhyDrop(SocketWho who) override;
59
60 void ConfigureEnvironment() override;
61 void ConfigureProperties() override;
62
63 uint32_t m_ackedBytes; //!< ACKed bytes.
64 uint32_t m_sentBytes; //!< Sent bytes.
65 uint32_t m_totalAckedBytes; //!< Total ACKed bytes.
66 uint32_t m_allowedIncrease; //!< Allowed increase.
67
68 bool m_initial; //!< First cycle flag.
69
70 private:
71 uint32_t m_segmentSize; //!< Segment size.
72 uint32_t m_packetSize; //!< Packet size.
73 uint32_t m_packets; //!< Packet counter.
74};
75
78 uint32_t initSsTh,
79 uint32_t packets,
80 const TypeId& typeId,
81 const std::string& desc)
82 : TcpGeneralTest(desc),
83 m_ackedBytes(0),
84 m_sentBytes(0),
85 m_totalAckedBytes(0),
86 m_allowedIncrease(0),
87 m_initial(true),
88 m_segmentSize(segmentSize),
89 m_packetSize(packetSize),
90 m_packets(packets)
91{
92 m_congControlTypeId = typeId;
93}
94
95void
102
103void
111
112void
114{
115 NS_FATAL_ERROR("Drop on the queue; cannot validate slow start");
116}
117
118void
120{
121 NS_FATAL_ERROR("Drop on the phy: cannot validate slow start");
122}
123
124/**
125 * \brief Trace the cWnd over the slow start
126 *
127 * This method is called each time the cWnd changes. It should be updated only
128 * by MSS bytes at time. Since the size doubles each RTT, a timing test is also
129 * performed: the doubling should be made in 0.5s from the first (0.5s is
130 * the delay of the SimpleChannel which connect the two socket).
131 *
132 * \param oldValue old value of cWnd
133 * \param newValue new value of cWnd
134 */
135void
137{
139 uint32_t increase = newValue - oldValue;
140
141 if (m_initial)
142 {
143 m_initial = false;
144 NS_LOG_INFO("Ignored update to " << newValue << " with a segsize of " << segSize);
145 return;
146 }
147
148 // The increase in RFC should be <= of segSize. In ns-3 we force = segSize
149 NS_TEST_ASSERT_MSG_EQ(increase, segSize, "Increase different than segsize");
150 NS_TEST_ASSERT_MSG_LT_OR_EQ(newValue, GetInitialSsThresh(SENDER), "cWnd increased over ssth");
151
152 NS_LOG_INFO("Incremented cWnd by " << segSize << " bytes in Slow Start "
153 << "achieving a value of " << newValue);
154
155 NS_TEST_ASSERT_MSG_GT_OR_EQ(m_allowedIncrease, 1, "Increase not allowed");
157}
158
159void
161{
162 NS_LOG_FUNCTION(this << p << h << who);
163
164 if (who == SENDER && Simulator::Now().GetSeconds() > 5.0)
165 {
167 }
168}
169
170void
172{
173 NS_LOG_FUNCTION(this << p << h << who);
174
175 if (who == SENDER && Simulator::Now().GetSeconds() > 5.0)
176 {
178 m_totalAckedBytes += acked;
179 m_ackedBytes += acked;
180
181 NS_LOG_INFO("Ack of " << acked << " bytes, acked this round=" << m_ackedBytes);
182
184 {
185 NS_LOG_INFO("FULL ACK achieved, bytes=" << m_ackedBytes);
188 }
189
190 while (m_ackedBytes >= GetSegSize(SENDER))
191 {
193 }
194 }
195}
196
197/**
198 * \ingroup internet-test
199 *
200 * \brief A slow start test using a socket which sends smaller ACKs
201 *
202 * The same test are performed over a connection where, on one side, there is
203 * a malicious socket which sends smaller ACKs than the segment received.
204 *
205 * Slow start behavior should not change.
206 */
208{
209 public:
210 /**
211 * \brief Constructor.
212 * \param segmentSize Segment size.
213 * \param packetSize Packet size.
214 * \param initSsTh Initial SlowStart threshold.
215 * \param packets Packet counter.
216 * \param congControl Congestion control.
217 * \param desc Test description.
218 */
221 uint32_t initSsTh,
222 uint32_t packets,
223 const TypeId& congControl,
224 const std::string& desc);
225
226 protected:
228};
229
232 uint32_t initSsTh,
233 uint32_t packets,
234 const TypeId& typeId,
235 const std::string& msg)
236 : TcpSlowStartNormalTest(segmentSize, packetSize, initSsTh, packets, typeId, msg)
237{
238}
239
249
250/**
251 * \ingroup internet-test
252 *
253 * \brief TCP Slow Start TestSuite.
254 */
256{
257 public:
259 : TestSuite("tcp-slow-start-test", Type::UNIT)
260 {
261 // This test have less packets to transmit than SsTh
262 std::list<TypeId> types = {
264 };
265
266 for (const auto& t : types)
267 {
268 std::string typeName = t.GetName();
269
271 500,
272 10000,
273 10,
274 t,
275 "slow start 500 byte, " + typeName),
276 TestCase::Duration::QUICK);
278 1000,
279 10000,
280 9,
281 t,
282 "slow start 1000 byte, " + typeName),
283 TestCase::Duration::QUICK);
285 250,
286 10000,
287 10,
288 t,
289 "slow start small packets, " + typeName),
290 TestCase::Duration::QUICK);
293 500,
294 10000,
295 10,
296 t,
297 "slow start ack attacker, 500 byte, " + typeName),
298 TestCase::Duration::QUICK);
301 1000,
302 10000,
303 9,
304 t,
305 "slow start ack attacker, 1000 byte, " + typeName),
306 TestCase::Duration::QUICK);
307 }
308 }
309};
310
311static TcpSlowStartTestSuite g_tcpSlowStartTestSuite; //!< Static variable for test initialization
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.
Smart pointer class similar to boost::intrusive_ptr.
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
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.
virtual void ConfigureProperties()
Change the configuration of the socket properties.
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.
virtual void ConfigureEnvironment()
Change the configuration of the environment.
void SetSegmentSize(SocketWho who, uint32_t segmentSize)
Forcefully set the segment size.
Header for the Transmission Control Protocol.
Definition tcp-header.h:36
SequenceNumber32 GetAckNumber() const
Get the ACK number.
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Get the type ID.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
a unique identifier for an interface.
Definition type-id.h:48
std::string GetName() const
Get the name.
Definition type-id.cc:1061
uint32_t segmentSize
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:264
#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:134
#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:740
#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:905
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
static TcpSlowStartTestSuite g_tcpSlowStartTestSuite
Static variable for test initialization.
static const uint32_t packetSize
Packet size generated at the AP.