A Discrete-Event Network Simulator
API
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 * 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/simple-channel.h"
23#include "ns3/test.h"
24
25using namespace ns3;
26
27NS_LOG_COMPONENT_DEFINE("TcpNewRenoCongAvoidTest");
28
56{
57 public:
68 uint32_t packets,
69 const TypeId& congControl,
70 const std::string& desc);
71
72 protected:
73 void CWndTrace(uint32_t oldValue, uint32_t newValue) override;
74 void QueueDrop(SocketWho who) override;
75 void PhyDrop(SocketWho who) override;
76 void NormalClose(SocketWho who) override;
81 void Check();
82
83 void ConfigureEnvironment() override;
84 void ConfigureProperties() override;
85
86 private:
92 bool m_initial;
93};
94
97 uint32_t packets,
98 const TypeId& typeId,
99 const std::string& desc)
100 : TcpGeneralTest(desc),
101 m_segmentSize(segmentSize),
102 m_packetSize(packetSize),
103 m_packets(packets),
104 m_increment(0),
105 m_initial(true)
106{
107 m_congControlTypeId = typeId;
108}
109
110void
112{
113 TcpGeneralTest::ConfigureEnvironment();
116 SetMTU(1500);
117}
118
119void
121{
122 TcpGeneralTest::ConfigureProperties();
125}
126
127void
129{
130 if (m_initial)
131 {
132 m_initial = false;
133 return;
134 }
135
136 if (!m_event.IsRunning())
137 {
138 m_event = Simulator::Schedule(Seconds(1.0), &TcpNewRenoCongAvoidNormalTest::Check, this);
139 }
140
141 m_increment += newValue - oldValue;
142}
143
144void
146{
147 NS_FATAL_ERROR("Drop on the queue; cannot validate congestion avoidance");
148}
149
150void
152{
153 NS_FATAL_ERROR("Drop on the phy: cannot validate congestion avoidance");
154}
155
156void
158{
159 uint32_t segSize = GetSegSize(TcpGeneralTest::SENDER);
160
161 if (m_increment != 0)
162 {
164 segSize,
165 "Increment exceeded segment size in one RTT");
166 }
167
168 m_increment = 0;
169
170 m_event = Simulator::Schedule(Seconds(1.0), &TcpNewRenoCongAvoidNormalTest::Check, this);
171}
172
173void
175{
176 if (who == SENDER)
177 {
178 m_event.Cancel();
179 }
180}
181
189{
190 public:
192 : TestSuite("tcp-cong-avoid-test", UNIT)
193 {
194 std::list<TypeId> types = {
195 TcpNewReno::GetTypeId(),
196 };
197
198 for (const auto& t : types)
199 {
200 std::string typeName = t.GetName();
201
202 for (uint32_t i = 10; i <= 50; i += 10)
203 {
205 500,
206 i,
207 t,
208 "cong avoid MSS=500, pkt_size=500," +
209 typeName),
210 TestCase::QUICK);
212 1000,
213 i,
214 t,
215 "cong avoid MSS=500, pkt_size=1000," +
216 typeName),
217 TestCase::QUICK);
218 }
219 }
220 }
221};
222
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.
bool m_initial
True on first run.
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:55
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:76
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.
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.
void SetSegmentSize(SocketWho who, uint32_t segmentSize)
Forcefully set the segment size.
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_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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
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.