A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-cong-avoid-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/simple-channel.h"
12#include "ns3/test.h"
13
14using namespace ns3;
15
16NS_LOG_COMPONENT_DEFINE("TcpNewRenoCongAvoidTest");
17
18/**
19 * \ingroup internet-test
20 *
21 * \brief Test the behavior of RFC congestion avoidance
22 *
23 * From RFC 5681:\n
24 *
25 * cwnd += min (N, SMSS) (2)
26 *
27 * During congestion avoidance, cwnd is incremented by roughly 1 full-
28 * sized segment per round-trip time (RTT). Congestion avoidance
29 * continues until congestion is detected. The basic guidelines for
30 * incrementing cwnd during congestion avoidance are:
31 *
32 * * MAY increment cwnd by SMSS bytes
33 *
34 * * SHOULD increment cwnd per equation (2) once per RTT
35 *
36 * * MUST NOT increment cwnd by more than SMSS bytes
37 *
38 * To test this behavior and these points, a tracing callback is attached
39 * to the cWnd. Each time it increases, the increment is saved. Meanwhile, a
40 * timer checks if an amount of time equals to the RTT has passed, and if yes,
41 * it checks that the increment has not passed the 1 MSS limit.
42 */
44{
45 public:
46 /**
47 * \brief Constructor.
48 * \param segmentSize Segment size.
49 * \param packetSize Size of the packets.
50 * \param packets Number of packets.
51 * \param congControl Type of congestion control.
52 * \param desc The test description.
53 */
56 uint32_t packets,
57 const TypeId& congControl,
58 const std::string& desc);
59
60 protected:
61 void CWndTrace(uint32_t oldValue, uint32_t newValue) override;
62 void QueueDrop(SocketWho who) override;
63 void PhyDrop(SocketWho who) override;
64 void NormalClose(SocketWho who) override;
65 /**
66 * \brief Called each RTT (1.0 sec in the testing environment) and check
67 * that the overall increment in this RTT is less or equal than 1 MSS
68 */
69 void Check();
70
71 void ConfigureEnvironment() override;
72 void ConfigureProperties() override;
73
74 private:
75 uint32_t m_segmentSize; //!< Segment size.
76 uint32_t m_packetSize; //!< Size of the packets.
77 uint32_t m_packets; //!< Number of packets.
78 uint32_t m_increment; //!< Congestion window increment.
79 EventId m_event; //!< Check event.
80 bool m_initial; //!< True on first run.
81};
82
85 uint32_t packets,
86 const TypeId& typeId,
87 const std::string& desc)
88 : TcpGeneralTest(desc),
89 m_segmentSize(segmentSize),
90 m_packetSize(packetSize),
91 m_packets(packets),
92 m_increment(0),
93 m_initial(true)
94{
95 m_congControlTypeId = typeId;
96}
97
98void
106
107void
114
115void
117{
118 if (m_initial)
119 {
120 m_initial = false;
121 return;
122 }
123
124 if (!m_event.IsPending())
125 {
127 }
128
129 m_increment += newValue - oldValue;
130}
131
132void
134{
135 NS_FATAL_ERROR("Drop on the queue; cannot validate congestion avoidance");
136}
137
138void
140{
141 NS_FATAL_ERROR("Drop on the phy: cannot validate congestion avoidance");
142}
143
144void
146{
148
149 if (m_increment != 0)
150 {
152 segSize,
153 "Increment exceeded segment size in one RTT");
154 }
155
156 m_increment = 0;
157
159}
160
161void
163{
164 if (who == SENDER)
165 {
166 m_event.Cancel();
167 }
168}
169
170/**
171 * \ingroup internet-test
172 *
173 * \brief TestSuite for the behavior of RFC congestion avoidance
174 */
176{
177 public:
179 : TestSuite("tcp-cong-avoid-test", Type::UNIT)
180 {
181 std::list<TypeId> types = {
183 };
184
185 for (const auto& t : types)
186 {
187 std::string typeName = t.GetName();
188
189 for (uint32_t i = 10; i <= 50; i += 10)
190 {
192 500,
193 i,
194 t,
195 "cong avoid MSS=500, pkt_size=500," +
196 typeName),
197 TestCase::Duration::QUICK);
199 1000,
200 i,
201 t,
202 "cong avoid MSS=500, pkt_size=1000," +
203 typeName),
204 TestCase::Duration::QUICK);
205 }
206 }
207 }
208};
209
211 g_tcpCongAvoidNormalTest; //!< Static variable for test initialization
Test the behavior of RFC congestion avoidance.
void Check()
Called each RTT (1.0 sec in the testing environment) and check that the overall increment in this RTT...
uint32_t m_segmentSize
Segment size.
uint32_t m_packets
Number of packets.
void CWndTrace(uint32_t oldValue, uint32_t newValue) override
Tracks the congestion window changes.
void NormalClose(SocketWho who) override
Socket closed normally.
void PhyDrop(SocketWho who) override
Link drop.
TcpNewRenoCongAvoidNormalTest(uint32_t segmentSize, uint32_t packetSize, uint32_t packets, const TypeId &congControl, const std::string &desc)
Constructor.
void ConfigureEnvironment() override
Change the configuration of the environment.
uint32_t m_packetSize
Size of the packets.
void ConfigureProperties() override
Change the configuration of the socket properties.
void QueueDrop(SocketWho who) override
Drop on the queue.
uint32_t m_increment
Congestion window increment.
TestSuite for the behavior of RFC congestion avoidance.
An identifier for simulation events.
Definition event-id.h:45
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition event-id.cc:44
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Definition event-id.cc:65
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
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.
void SetAppPktSize(uint32_t pktSize)
Set app packet size.
virtual void ConfigureProperties()
Change the configuration of the socket properties.
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
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.
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_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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpRenoCongAvoidTestSuite g_tcpCongAvoidNormalTest
Static variable for test initialization.
static const uint32_t packetSize
Packet size generated at the AP.