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 
64  void PktDropped (const Ipv4Header &ipH, const TcpHeader& tcpH, Ptr<const Packet> pkt);
65 
66 private:
68  bool m_sendClose;
69  bool m_recvClose;
72 };
73 
75  : TcpGeneralTest ("Testing connection closing with retransmissions")
76 {
77  m_sendClose = false;
78  m_recvClose = false;
79  m_synReceived = false;
80  m_sackEnabled = sackEnabled;
81 }
82 
83 void
85 {
87  SetAppPktSize (1400);
88  SetAppPktCount (1);
91  SetMTU (1452);
92  SetSegmentSize (SENDER, 700);
93  GetSenderSocket ()->SetAttribute ("Timestamp", BooleanValue (false));
94  GetReceiverSocket ()->SetAttribute ("Timestamp", BooleanValue (false));
95  GetSenderSocket ()->SetAttribute("Sack", BooleanValue (m_sackEnabled));
96 }
97 
98 void
100 {
101  NS_TEST_ASSERT_MSG_EQ (m_sendClose, true, "Sender has not closed successfully the connection");
102  NS_TEST_ASSERT_MSG_EQ (m_recvClose, true, "Recv has not closed successfully the connection");
103 }
104 
107 {
108  m_errorModel = CreateObject<TcpSeqErrorModel> ();
110 
112 
113  return m_errorModel;
114 }
115 
116 void
118 {
119  NS_LOG_INFO ("Dropped "<< tcpH);
120 }
121 
122 void
124 {
125  if (who == SENDER)
126  {
127  NS_LOG_INFO ("Sender TX: " << h << " size " << p->GetSize ());
128  }
129  else
130  {
131  NS_LOG_INFO ("Receiver TX: " << h << " size " << p->GetSize ());
132  }
133 }
134 
135 void
137 {
138  if (who == SENDER)
139  {
140  NS_LOG_INFO ("Sender RX: " << h << " size " << p->GetSize ());
141  }
142  else
143  {
144  NS_LOG_INFO ("Receiver RX: " << h << " size " << p->GetSize ());
145  }
146 }
147 
152 {
153 public:
155  : TestSuite ("tcp-close", UNIT)
156  {
159  }
160 
161 };
162 
164 
165 } // namespace ns3
AttributeValue implementation for Boolean.
Definition: boolean.h:37
Packet header for IPv4.
Definition: ipv4-header.h:34
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Check if the TCP correctly close the connection after receiving previously lost data.
Ptr< TcpSeqErrorModel > m_errorModel
The error model.
virtual void NormalClose(SocketWho who)
bool m_sackEnabled
true if sack should be enabled
void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
virtual void ConfigureProperties()
Change the configuration of the socket properties.
void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
bool m_recvClose
true when the receiver has closed
bool m_sendClose
true when the sender has closed
Ptr< ErrorModel > CreateReceiverErrorModel()
Create and return the error model to install in the receiver node.
void FinalChecks()
Performs the (eventual) final checks through test asserts.
void PktDropped(const Ipv4Header &ipH, const TcpHeader &tcpH, Ptr< const Packet > pkt)
Called when a packet is dropped.
TcpCloseWithLossTestCase(bool sackEnabled)
Constructor.
bool m_synReceived
true when the receiver gets SYN
void SetDropCallback(Callback< void, const Ipv4Header &, const TcpHeader &, Ptr< const Packet > > cb)
Set the drop callback.
General infrastructure for TCP testing.
Ptr< TcpSocketMsgBase > GetReceiverSocket()
Get the pointer to a previously created receiver socket.
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.
virtual void ConfigureProperties(void)
Change the configuration of the socket properties.
void SetInitialCwnd(SocketWho who, uint32_t initialCwnd)
Forcefully set the initial cwnd.
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
void SetAppPktInterval(Time pktInterval)
Interval between app-generated packet.
Ptr< TcpSocketMsgBase > GetSenderSocket()
Get the pointer to a previously created sender socket.
void SetSegmentSize(SocketWho who, uint32_t segmentSize)
Forcefully set the segment size.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:45
void AddSeqToKill(const SequenceNumber32 &seq)
Add the sequence number to the list of segments to be killed.
Check if the TCP is correctly closing its state.
@ QUICK
Fast test.
Definition: test.h:999
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1197
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#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:141
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpTcpCloseTestSuite g_tcpTcpCloseTestSuite
Static variable for test initialization.
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:1648