A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "tcp-error-model.h"
9#include "tcp-general-test.h"
10
11#include "ns3/log.h"
12#include "ns3/node.h"
13
14using namespace ns3;
15
16NS_LOG_COMPONENT_DEFINE("TcpZeroWindowTestSuite");
17
18/**
19 * @ingroup internet-test
20 *
21 * @brief Testing the congestion avoidance increment on TCP ZeroWindow
22 */
24{
25 public:
26 /**
27 * @brief Constructor.
28 * @param desc Test description.
29 */
30 TcpZeroWindowTest(const std::string& desc);
31
32 protected:
33 // virtual void ReceivePacket (Ptr<Socket> socket);
35
36 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
37 void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
39 const TcpHeader& h,
40 SocketWho who) override;
41 void NormalClose(SocketWho who) override;
42 void FinalChecks() override;
43
44 void ConfigureEnvironment() override;
45 void ConfigureProperties() override;
46
47 /**
48 * @brief Increase the receiver buffer size.
49 */
50 void IncreaseBufSize();
51
52 protected:
53 EventId m_receivePktEvent; //!< Receive packet event.
54 bool m_zeroWindowProbe; //!< ZeroWindow probe.
55 bool m_windowUpdated; //!< Window updated.
56 bool m_senderFinished; //!< Send finished.
57 bool m_receiverFinished; //!< Receiver finished.
58};
59
61 : TcpGeneralTest(desc),
62 m_zeroWindowProbe(false),
63 m_windowUpdated(false),
64 m_senderFinished(false),
65 m_receiverFinished(false)
66{
67}
68
69void
78
79void
85
86void
91
94{
96
97 socket->SetAttribute("RcvBufSize", UintegerValue(0));
99
100 return socket;
101}
102
103void
105{
106 if (who == SENDER)
107 {
108 NS_LOG_INFO("\tSENDER TX " << h << " size " << p->GetSize());
109
110 if (Simulator::Now().GetSeconds() <= 6.0)
111 {
112 NS_TEST_ASSERT_MSG_EQ(p->GetSize(), 0, "Data packet sent anyway");
113 }
114 else if (Simulator::Now().GetSeconds() > 6.0 && Simulator::Now().GetSeconds() <= 7.0)
115 {
116 NS_TEST_ASSERT_MSG_EQ(m_zeroWindowProbe, false, "Sent another probe");
117
119 {
120 NS_TEST_ASSERT_MSG_EQ(p->GetSize(), 1, "Data packet sent instead of window probe");
123 "Data packet sent instead of window probe");
124 m_zeroWindowProbe = true;
125 }
126 }
127 else if (Simulator::Now().GetSeconds() > 7.0 && Simulator::Now().GetSeconds() < 10.0)
128 {
129 NS_FATAL_ERROR("No packets should be sent before the window update");
130 }
131 }
132 else if (who == RECEIVER)
133 {
134 NS_LOG_INFO("\tRECEIVER TX " << h << " size " << p->GetSize());
135
136 if (h.GetFlags() & TcpHeader::SYN)
137 {
139 0,
140 "RECEIVER window size is not 0 in the SYN-ACK");
141 }
142
143 if (Simulator::Now().GetSeconds() > 6.0 && Simulator::Now().GetSeconds() <= 7.0)
144 {
147 "Data packet sent instead of window probe");
148 NS_TEST_ASSERT_MSG_EQ(h.GetWindowSize(), 0, "No zero window advertised by RECEIVER");
149 }
150 else if (Simulator::Now().GetSeconds() > 7.0 && Simulator::Now().GetSeconds() < 10.0)
151 {
152 NS_FATAL_ERROR("No packets should be sent before the window update");
153 }
154 else if (Simulator::Now().GetSeconds() >= 10.0)
155 {
156 NS_TEST_ASSERT_MSG_EQ(h.GetWindowSize(), 2500, "Receiver window not updated");
157 }
158 }
159
160 NS_TEST_ASSERT_MSG_EQ(GetTcb(SENDER)->m_congState.Get(),
162 "Sender State is not OPEN");
163 NS_TEST_ASSERT_MSG_EQ(GetTcb(RECEIVER)->m_congState.Get(),
165 "Receiver State is not OPEN");
166}
167
168void
170{
171 if (who == SENDER)
172 {
173 NS_LOG_INFO("\tSENDER RX " << h << " size " << p->GetSize());
174
175 if (h.GetFlags() & TcpHeader::SYN)
176 {
178 0,
179 "RECEIVER window size is not 0 in the SYN-ACK");
180 }
181
182 if (Simulator::Now().GetSeconds() >= 10.0)
183 {
184 NS_TEST_ASSERT_MSG_EQ(h.GetWindowSize(), 2500, "Receiver window not updated");
185 m_windowUpdated = true;
186 }
187 }
188 else if (who == RECEIVER)
189 {
190 NS_LOG_INFO("\tRECEIVER RX " << h << " size " << p->GetSize());
191 }
192}
193
194void
196{
197 if (who == SENDER)
198 {
199 m_senderFinished = true;
200 }
201 else if (who == RECEIVER)
202 {
203 m_receiverFinished = true;
204 }
205}
206
207void
209{
210 NS_TEST_ASSERT_MSG_EQ(m_zeroWindowProbe, true, "Zero window probe not sent");
211 NS_TEST_ASSERT_MSG_EQ(m_windowUpdated, true, "Window has not updated during the connection");
212 NS_TEST_ASSERT_MSG_EQ(m_senderFinished, true, "Connection not closed successfully (SENDER)");
214 true,
215 "Connection not closed successfully (RECEIVER)");
216}
217
218void
220 const TcpHeader& h,
221 SocketWho who)
222{
223 if (who == SENDER)
224 {
225 if (h.GetFlags() & TcpHeader::SYN)
226 {
227 EventId persistentEvent = GetPersistentEvent(SENDER);
228 NS_TEST_ASSERT_MSG_EQ(persistentEvent.IsPending(),
229 true,
230 "Persistent event not started");
231 }
232 }
233 else if (who == RECEIVER)
234 {
235 }
236}
237
238/**
239 * @ingroup internet-test
240 *
241 * @brief TCP ZeroWindow TestSuite
242 */
244{
245 public:
247 : TestSuite("tcp-zero-window-test", Type::UNIT)
248 {
249 AddTestCase(new TcpZeroWindowTest("zero window test"), TestCase::Duration::QUICK);
250 }
251};
252
253static TcpZeroWindowTestSuite g_tcpZeroWindowTestSuite; //!< Static variable for test initialization
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:45
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Definition event-id.cc:65
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
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.
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
virtual void ConfigureProperties()
Change the configuration of the socket properties.
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
virtual void ConfigureEnvironment()
Change the configuration of the environment.
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:36
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
uint16_t GetWindowSize() const
Get the window size.
uint8_t GetFlags() const
Get the flags.
@ CA_OPEN
Normal state, no dubious events.
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
Hold an unsigned integer type.
Definition uinteger.h:34
#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_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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1356
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpZeroWindowTestSuite g_tcpZeroWindowTestSuite
Static variable for test initialization.