A Discrete-Event Network Simulator
API
tcp-zero-window-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
19#include "tcp-error-model.h"
20#include "tcp-general-test.h"
21
22#include "ns3/log.h"
23#include "ns3/node.h"
24
25using namespace ns3;
26
27NS_LOG_COMPONENT_DEFINE("TcpZeroWindowTestSuite");
28
36{
37 public:
42 TcpZeroWindowTest(const std::string& desc);
43
44 protected:
45 // virtual void ReceivePacket (Ptr<Socket> socket);
47
48 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
49 void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
51 const TcpHeader& h,
52 SocketWho who) override;
53 void NormalClose(SocketWho who) override;
54 void FinalChecks() override;
55
56 void ConfigureEnvironment() override;
57 void ConfigureProperties() override;
58
62 void IncreaseBufSize();
63
64 protected:
70};
71
73 : TcpGeneralTest(desc),
74 m_zeroWindowProbe(false),
75 m_windowUpdated(false),
76 m_senderFinished(false),
77 m_receiverFinished(false)
78{
79}
80
81void
83{
84 TcpGeneralTest::ConfigureEnvironment();
86 SetMTU(500);
89}
90
91void
93{
94 TcpGeneralTest::ConfigureProperties();
96}
97
98void
100{
101 SetRcvBufSize(RECEIVER, 2500);
102}
103
106{
107 Ptr<TcpSocketMsgBase> socket = TcpGeneralTest::CreateReceiverSocket(node);
108
109 socket->SetAttribute("RcvBufSize", UintegerValue(0));
110 Simulator::Schedule(Seconds(10.0), &TcpZeroWindowTest::IncreaseBufSize, this);
111
112 return socket;
113}
114
115void
117{
118 if (who == SENDER)
119 {
120 NS_LOG_INFO("\tSENDER TX " << h << " size " << p->GetSize());
121
122 if (Simulator::Now().GetSeconds() <= 6.0)
123 {
124 NS_TEST_ASSERT_MSG_EQ(p->GetSize(), 0, "Data packet sent anyway");
125 }
126 else if (Simulator::Now().GetSeconds() > 6.0 && Simulator::Now().GetSeconds() <= 7.0)
127 {
128 NS_TEST_ASSERT_MSG_EQ(m_zeroWindowProbe, false, "Sent another probe");
129
131 {
132 NS_TEST_ASSERT_MSG_EQ(p->GetSize(), 1, "Data packet sent instead of window probe");
135 "Data packet sent instead of window probe");
136 m_zeroWindowProbe = true;
137 }
138 }
139 else if (Simulator::Now().GetSeconds() > 7.0 && Simulator::Now().GetSeconds() < 10.0)
140 {
141 NS_FATAL_ERROR("No packets should be sent before the window update");
142 }
143 }
144 else if (who == RECEIVER)
145 {
146 NS_LOG_INFO("\tRECEIVER TX " << h << " size " << p->GetSize());
147
148 if (h.GetFlags() & TcpHeader::SYN)
149 {
151 0,
152 "RECEIVER window size is not 0 in the SYN-ACK");
153 }
154
155 if (Simulator::Now().GetSeconds() > 6.0 && Simulator::Now().GetSeconds() <= 7.0)
156 {
159 "Data packet sent instead of window probe");
160 NS_TEST_ASSERT_MSG_EQ(h.GetWindowSize(), 0, "No zero window advertised by RECEIVER");
161 }
162 else if (Simulator::Now().GetSeconds() > 7.0 && Simulator::Now().GetSeconds() < 10.0)
163 {
164 NS_FATAL_ERROR("No packets should be sent before the window update");
165 }
166 else if (Simulator::Now().GetSeconds() >= 10.0)
167 {
168 NS_TEST_ASSERT_MSG_EQ(h.GetWindowSize(), 2500, "Receiver window not updated");
169 }
170 }
171
173 TcpSocketState::CA_OPEN,
174 "Sender State is not OPEN");
176 TcpSocketState::CA_OPEN,
177 "Receiver State is not OPEN");
178}
179
180void
182{
183 if (who == SENDER)
184 {
185 NS_LOG_INFO("\tSENDER RX " << h << " size " << p->GetSize());
186
187 if (h.GetFlags() & TcpHeader::SYN)
188 {
190 0,
191 "RECEIVER window size is not 0 in the SYN-ACK");
192 }
193
194 if (Simulator::Now().GetSeconds() >= 10.0)
195 {
196 NS_TEST_ASSERT_MSG_EQ(h.GetWindowSize(), 2500, "Receiver window not updated");
197 m_windowUpdated = true;
198 }
199 }
200 else if (who == RECEIVER)
201 {
202 NS_LOG_INFO("\tRECEIVER RX " << h << " size " << p->GetSize());
203 }
204}
205
206void
208{
209 if (who == SENDER)
210 {
211 m_senderFinished = true;
212 }
213 else if (who == RECEIVER)
214 {
215 m_receiverFinished = true;
216 }
217}
218
219void
221{
222 NS_TEST_ASSERT_MSG_EQ(m_zeroWindowProbe, true, "Zero window probe not sent");
223 NS_TEST_ASSERT_MSG_EQ(m_windowUpdated, true, "Window has not updated during the connection");
224 NS_TEST_ASSERT_MSG_EQ(m_senderFinished, true, "Connection not closed successfully (SENDER)");
226 true,
227 "Connection not closed successfully (RECEIVER)");
228}
229
230void
232 const TcpHeader& h,
233 SocketWho who)
234{
235 if (who == SENDER)
236 {
237 if (h.GetFlags() & TcpHeader::SYN)
238 {
239 EventId persistentEvent = GetPersistentEvent(SENDER);
240 NS_TEST_ASSERT_MSG_EQ(persistentEvent.IsRunning(),
241 true,
242 "Persistent event not started");
243 }
244 }
245 else if (who == RECEIVER)
246 {
247 }
248}
249
257{
258 public:
260 : TestSuite("tcp-zero-window-test", UNIT)
261 {
262 AddTestCase(new TcpZeroWindowTest("zero window test"), TestCase::QUICK);
263 }
264};
265
Testing the congestion avoidance increment on TCP ZeroWindow.
void ConfigureEnvironment() override
Change the configuration of the environment.
void FinalChecks() override
Performs the (eventual) final checks through test asserts.
void NormalClose(SocketWho who) override
Socket closed normally.
bool m_windowUpdated
Window updated.
void ProcessedAck(const Ptr< const TcpSocketState > tcb, const TcpHeader &h, SocketWho who) override
Processed ack.
bool m_senderFinished
Send finished.
bool m_receiverFinished
Receiver finished.
Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node) override
Create and install the socket to install on the receiver.
void IncreaseBufSize()
Increase the receiver buffer size.
void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet received from IP layer.
void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet transmitted down to IP layer.
bool m_zeroWindowProbe
ZeroWindow probe.
TcpZeroWindowTest(const std::string &desc)
Constructor.
EventId m_receivePktEvent
Receive packet event.
void ConfigureProperties() override
Change the configuration of the socket properties.
TCP ZeroWindow TestSuite.
An identifier for simulation events.
Definition: event-id.h:55
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:76
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:863
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
General infrastructure for TCP testing.
void SetPropagationDelay(Time propDelay)
Propagation delay of the bottleneck link.
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.
Ptr< TcpSocketState > GetTcb(SocketWho who)
Get the TCB from selected socket.
void SetRcvBufSize(SocketWho who, uint32_t size)
Forcefully set a defined size for rx buffer.
EventId GetPersistentEvent(SocketWho who)
Get the persistent event of the selected socket.
void SetInitialCwnd(SocketWho who, uint32_t initialCwnd)
Forcefully set the initial cwnd.
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
void SetTransmitStart(Time startTime)
Set the initial time at which the application sends the first data packet.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:46
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
Definition: tcp-header.cc:137
uint16_t GetWindowSize() const
Get the window size.
Definition: tcp-header.cc:173
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:167
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
Hold an unsigned integer type.
Definition: uinteger.h:45
#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_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
static TcpSocketState::TcpCongState_t GetCongStateFrom(Ptr< const TcpSocketState > tcb)
Convenience function to retrieve the ACK state from a TCB.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpZeroWindowTestSuite g_tcpZeroWindowTestSuite
Static variable for test initialization.