This documentation is not the Latest Release.
A Discrete-Event Network Simulator
API
tcp-zero-window-test.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 Natale Patriciello <natale.patriciello@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19 
20 #include "tcp-general-test.h"
21 #include "tcp-error-model.h"
22 #include "ns3/node.h"
23 #include "ns3/log.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("TcpZeroWindowTestSuite");
28 
30 {
31 public:
32  TcpZeroWindowTest (const std::string &desc);
33 
34 protected:
35  //virtual void ReceivePacket (Ptr<Socket> socket);
37 
38  virtual void Tx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
39  virtual void Rx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
40  virtual void ProcessedAck (const Ptr<const TcpSocketState> tcb,
41  const TcpHeader& h, SocketWho who);
42  void NormalClose (SocketWho who);
43  void FinalChecks ();
44 
45  void IncreaseBufSize ();
46 
47 protected:
53 };
54 
55 TcpZeroWindowTest::TcpZeroWindowTest (const std::string &desc)
56  : TcpGeneralTest (desc, 500, 20, Seconds (0.01), Seconds (0.05), Seconds (2.0),
57  0xffffffff, 10, 500),
58  m_zeroWindowProbe (false),
59  m_windowUpdated (false),
60  m_senderFinished (false),
61  m_receiverFinished (false)
62 {
63 }
64 
65 void
67 {
68  SetRcvBufSize (RECEIVER, 2500);
69 }
70 
73 {
75 
76  socket->SetAttribute ("RcvBufSize", UintegerValue (0));
79 
80  return socket;
81 }
82 
83 void
85 {
86  if (who == SENDER)
87  {
88  NS_LOG_INFO ("\tSENDER TX " << h << " size " << p->GetSize ());
89 
90  if (Simulator::Now ().GetSeconds () <= 6.0)
91  {
93  "Data packet sent anyway");
94  }
95  else if (Simulator::Now ().GetSeconds () > 6.0
96  && Simulator::Now ().GetSeconds () <= 7.0)
97  {
98  NS_TEST_ASSERT_MSG_EQ (m_zeroWindowProbe, false, "Sent another probe");
99 
100  if (!m_zeroWindowProbe)
101  {
103  "Data packet sent instead of window probe");
105  "Data packet sent instead of window probe");
106  m_zeroWindowProbe = true;
107  }
108  }
109  else if (Simulator::Now ().GetSeconds () > 7.0
110  && Simulator::Now ().GetSeconds () < 10.0)
111  {
112  NS_FATAL_ERROR ("No packets should be sent before the window update");
113  }
114  }
115  else if (who == RECEIVER)
116  {
117  NS_LOG_INFO ("\tRECEIVER TX " << h << " size " << p->GetSize ());
118 
119  if (h.GetFlags () & TcpHeader::SYN)
120  {
122  "RECEIVER window size is not 0 in the SYN-ACK");
123  }
124 
125  if (Simulator::Now ().GetSeconds () > 6.0
126  && Simulator::Now ().GetSeconds () <= 7.0)
127  {
129  "Data packet sent instead of window probe");
131  "No zero window advertised by RECEIVER");
132  }
133  else if (Simulator::Now ().GetSeconds () > 7.0
134  && Simulator::Now ().GetSeconds () < 10.0)
135  {
136  NS_FATAL_ERROR ("No packets should be sent before the window update");
137  }
138  else if (Simulator::Now ().GetSeconds () >= 10.0)
139  {
141  "Receiver window not updated");
142  }
143  }
144 
146  "Sender State is not OPEN");
148  "Receiver State is not OPEN");
149 }
150 
151 void
153 {
154  if (who == SENDER)
155  {
156  NS_LOG_INFO ("\tSENDER RX " << h << " size " << p->GetSize ());
157 
158  if (h.GetFlags () & TcpHeader::SYN)
159  {
161  "RECEIVER window size is not 0 in the SYN-ACK");
162  }
163 
164  if (Simulator::Now ().GetSeconds () >= 10.0)
165  {
167  "Receiver window not updated");
168  m_windowUpdated = true;
169  }
170  }
171  else if (who == RECEIVER)
172  {
173  NS_LOG_INFO ("\tRECEIVER RX " << h << " size " << p->GetSize ());
174  }
175 }
176 
177 void
179 {
180  if (who == SENDER)
181  {
182  m_senderFinished = true;
183  }
184  else if (who == RECEIVER)
185  {
186  m_receiverFinished = true;
187  }
188 }
189 
190 void
192 {
194  "Zero window probe not sent");
196  "Window has not updated during the connection");
198  "Connection not closed successfully (SENDER)");
200  "Connection not closed successfully (RECEIVER)");
201 }
202 
203 void
205  const TcpHeader& h, SocketWho who)
206 {
207  if (who == SENDER)
208  {
209  if (h.GetFlags () & TcpHeader::SYN)
210  {
211  EventId persistentEvent = GetPersistentEvent (SENDER);
212  NS_TEST_ASSERT_MSG_EQ (persistentEvent.IsRunning (), true,
213  "Persistent event not started");
214  }
215  }
216  else if (who == RECEIVER)
217  {
218 
219  }
220 }
221 
222 //-----------------------------------------------------------------------------
223 
224 static class TcpZeroWindowTestSuite : public TestSuite
225 {
226 public:
227  TcpZeroWindowTestSuite () : TestSuite ("tcp-zero-window-test", UNIT)
228  {
229  AddTestCase (new TcpZeroWindowTest ("zero window test"),
231  }
233 
234 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Normal state, no dubious events.
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
Definition: tcp-header.cc:143
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:161
Fast test.
Definition: test.h:1152
A suite of tests to run.
Definition: test.h:1333
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
TcpZeroWindowTest(const std::string &desc)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:786
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:145
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:65
This test suite implements a Unit Test.
Definition: test.h:1343
static TcpSocketState::TcpCongState_t GetCongStateFrom(Ptr< const TcpSocketState > tcb)
Convenience function to retrieve the ACK state from a TCB.
void NormalClose(SocketWho who)
Socket closed normally.
ns3::TcpZeroWindowTestSuite g_tcpZeroWindowTestSuite
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
void FinalChecks()
Performs the (eventual) final checks through test asserts.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1216
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:297
uint16_t GetWindowSize() const
Get the window size.
Definition: tcp-header.cc:167
virtual void ProcessedAck(const Ptr< const TcpSocketState > tcb, const TcpHeader &h, SocketWho who)
Processed ack.
Hold an unsigned integer type.
Definition: uinteger.h:44
#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:161
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:223
virtual uint32_t GetSerializedSize(void) const
Definition: tcp-header.cc:297
virtual void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
General infrastructure for TCP testing.
An identifier for simulation events.
Definition: event-id.h:53
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
Ptr< TcpSocketState > GetTcb(SocketWho who)
Get the TCB from selected socket.
EventId GetPersistentEvent(SocketWho who)
Get the persistent event of the selected socket.
void SetRcvBufSize(SocketWho who, uint32_t size)
Forcefully set a defined size for rx buffer.
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.