A Discrete-Event Network Simulator
API
tcp-close-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 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 #include "ns3/config.h"
25 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("TcpCloseTestSuite");
29 
35 {
36 public:
41  TcpCloseWithLossTestCase (bool sackEnabled);
42 
43 protected:
45  virtual void ConfigureProperties ();
46  void Tx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
47  void Rx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
48  void FinalChecks ();
49 
50  virtual void NormalClose (SocketWho who)
51  {
52  if (who == SENDER)
53  m_sendClose = true;
54  else
55  m_recvClose = true;
56  }
57 
58  void PktDropped (const Ipv4Header &ipH, const TcpHeader& tcpH, Ptr<const Packet> pkt);
59 
60  virtual void BytesAvailable (uint32_t size, SocketWho who);
61 
62 private:
64  bool m_sendClose;
65  bool m_recvClose;
68 };
69 
71  : TcpGeneralTest ("Testing connection closing with retransmissions")
72 {
73  m_sendClose = false;
74  m_recvClose = false;
75  m_synReceived = false;
76  m_sackEnabled = sackEnabled;
77 }
78 
79 void
81 {
83  SetAppPktSize (1400);
84  SetAppPktCount (1);
87  SetMTU (1452);
88  SetSegmentSize (SENDER, 700);
89  GetSenderSocket ()->SetAttribute ("Timestamp", BooleanValue (false));
90  GetReceiverSocket ()->SetAttribute ("Timestamp", BooleanValue (false));
91  GetSenderSocket ()->SetAttribute("Sack", BooleanValue (m_sackEnabled));
92 }
93 
94 void
96 {
97  NS_TEST_ASSERT_MSG_EQ (m_sendClose, true, "Sender has not closed successfully the connection");
98  NS_TEST_ASSERT_MSG_EQ (m_recvClose, true, "Recv has not closed successfully the connection");
99 }
100 
103 {
104  m_errorModel = CreateObject<TcpSeqErrorModel> ();
106 
108 
109  return m_errorModel;
110 }
111 
113  {
114  if (m_synReceived && (who == SENDER))
115  {
116  this->GetSenderSocket()->Close();
117  }
118  else
119  {
120  m_synReceived = true;
121  }
122  }
123 
124 void
126 {
127  NS_LOG_INFO ("Dropped "<< tcpH);
128 }
129 
130 void
132 {
133  if (who == SENDER)
134  {
135  NS_LOG_INFO ("Sender TX: " << h << " size " << p->GetSize ());
136  }
137  else
138  {
139  NS_LOG_INFO ("Receiver TX: " << h << " size " << p->GetSize ());
140  }
141 }
142 
143 void
145 {
146  if (who == SENDER)
147  {
148  NS_LOG_INFO ("Sender RX: " << h << " size " << p->GetSize ());
149  }
150  else
151  {
152  NS_LOG_INFO ("Receiver RX: " << h << " size " << p->GetSize ());
153  }
154 }
155 
160 {
161 public:
163  : TestSuite ("tcp-close", UNIT)
164  {
167  }
168 
169 };
170 
172 
173 } // namespace ns3
TcpCloseWithLossTestCase(bool sackEnabled)
Constructor.
Ptr< ErrorModel > CreateReceiverErrorModel()
Create and return the error model to install in the receiver node.
bool m_sendClose
true when the sender has closed
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void SetSegmentSize(SocketWho who, uint32_t segmentSize)
Forcefully set the segment size.
AttributeValue implementation for Boolean.
Definition: boolean.h:36
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
Ptr< TcpSocketMsgBase > GetSenderSocket()
Get the pointer to a previously created sender socket.
static TcpTcpCloseTestSuite g_tcpTcpCloseTestSuite
Static variable for test initialization.
void SetDropCallback(Callback< void, const Ipv4Header &, const TcpHeader &, Ptr< const Packet > > cb)
Set the drop callback.
A suite of tests to run.
Definition: test.h:1343
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1286
void SetAppPktSize(uint32_t pktSize)
Set app packet size.
void PktDropped(const Ipv4Header &ipH, const TcpHeader &tcpH, Ptr< const Packet > pkt)
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
virtual void ConfigureProperties(void)
Change the configuration of the socket properties.
void FinalChecks()
Performs the (eventual) final checks through test asserts.
void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
Packet header for IPv4.
Definition: ipv4-header.h:33
Check if the TCP correctly close the connection after receiving previously lost data.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
#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:166
bool m_synReceived
true when the receiver gets SYN
Ptr< TcpSeqErrorModel > m_errorModel
The error model.
virtual void NormalClose(SocketWho who)
Socket closed normally.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
void AddSeqToKill(const SequenceNumber32 &seq)
Add the sequence number to the list of segments to be killed.
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
void SetAppPktInterval(Time pktInterval)
Interval between app-generated packet.
Check if the TCP is correctly closing its state.
virtual void BytesAvailable(uint32_t size, SocketWho who)
Fast test.
Definition: test.h:1159
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
General infrastructure for TCP testing.
Ptr< TcpSocketMsgBase > GetReceiverSocket()
Get the pointer to a previously created receiver socket.
void SetInitialCwnd(SocketWho who, uint32_t initialCwnd)
Forcefully set the initial cwnd.
virtual void ConfigureProperties()
Change the configuration of the socket properties.
This test suite implements a Unit Test.
Definition: test.h:1353
bool m_recvClose
true when the receiver has closed
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642
bool m_sackEnabled
true if sack should be enabled