A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-close-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 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/config.h"
23#include "ns3/log.h"
24#include "ns3/node.h"
25
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE("TcpCloseTestSuite");
30
31/**
32 * \brief Check if the TCP correctly close the connection after receiving
33 * previously lost data
34 */
36{
37 public:
38 /**
39 * \brief Constructor
40 * \param sackEnabled Enable or disable SACK
41 */
42 TcpCloseWithLossTestCase(bool sackEnabled);
43
44 protected:
46 void ConfigureProperties() override;
47 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
48 void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
49 void FinalChecks() override;
50
51 void NormalClose(SocketWho who) override
52 {
53 if (who == SENDER)
54 {
55 m_sendClose = true;
56 }
57 else
58 {
59 m_recvClose = true;
60 }
61 }
62
63 /**
64 * Called when a packet is dropped.
65 * \param ipH IP header
66 * \param tcpH TCP header
67 * \param pkt packet
68 */
69 void PktDropped(const Ipv4Header& ipH, const TcpHeader& tcpH, Ptr<const Packet> pkt);
70
71 private:
72 Ptr<TcpSeqErrorModel> m_errorModel; //!< The error model
73 bool m_sendClose; //!< true when the sender has closed
74 bool m_recvClose; //!< true when the receiver has closed
75 bool m_synReceived; //!< true when the receiver gets SYN
76 bool m_sackEnabled; //!< true if sack should be enabled
77};
78
80 : TcpGeneralTest("Testing connection closing with retransmissions")
81{
82 m_sendClose = false;
83 m_recvClose = false;
84 m_synReceived = false;
85 m_sackEnabled = sackEnabled;
86}
87
88void
90{
92 SetAppPktSize(1400);
96 SetMTU(1452);
98 GetSenderSocket()->SetAttribute("Timestamp", BooleanValue(false));
99 GetReceiverSocket()->SetAttribute("Timestamp", BooleanValue(false));
100 GetSenderSocket()->SetAttribute("Sack", BooleanValue(m_sackEnabled));
101}
102
103void
105{
106 NS_TEST_ASSERT_MSG_EQ(m_sendClose, true, "Sender has not closed successfully the connection");
107 NS_TEST_ASSERT_MSG_EQ(m_recvClose, true, "Recv has not closed successfully the connection");
108}
109
112{
113 m_errorModel = CreateObject<TcpSeqErrorModel>();
115
117
118 return m_errorModel;
119}
120
121void
123 const TcpHeader& tcpH,
125{
126 NS_LOG_INFO("Dropped " << tcpH);
127}
128
129void
131{
132 if (who == SENDER)
133 {
134 NS_LOG_INFO("Sender TX: " << h << " size " << p->GetSize());
135 }
136 else
137 {
138 NS_LOG_INFO("Receiver TX: " << h << " size " << p->GetSize());
139 }
140}
141
142void
144{
145 if (who == SENDER)
146 {
147 NS_LOG_INFO("Sender RX: " << h << " size " << p->GetSize());
148 }
149 else
150 {
151 NS_LOG_INFO("Receiver RX: " << h << " size " << p->GetSize());
152 }
153}
154
155/**
156 * Check if the TCP is correctly closing its state
157 */
159{
160 public:
162 : TestSuite("tcp-close", Type::UNIT)
163 {
166 }
167};
168
169static TcpTcpCloseTestSuite g_tcpTcpCloseTestSuite; //!< Static variable for test initialization
170
171} // namespace ns3
AttributeValue implementation for Boolean.
Definition: boolean.h:37
Packet header for IPv4.
Definition: ipv4-header.h:34
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Check if the TCP correctly close the connection after receiving previously lost data.
void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet received from IP layer.
Ptr< TcpSeqErrorModel > m_errorModel
The error model.
bool m_sackEnabled
true if sack should be enabled
Ptr< ErrorModel > CreateReceiverErrorModel() override
Create and return the error model to install in the receiver node.
void FinalChecks() override
Performs the (eventual) final checks through test asserts.
void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet transmitted down to IP layer.
void ConfigureProperties() override
Change the configuration of the socket properties.
bool m_recvClose
true when the receiver has closed
bool m_sendClose
true when the sender has closed
void PktDropped(const Ipv4Header &ipH, const TcpHeader &tcpH, Ptr< const Packet > pkt)
Called when a packet is dropped.
TcpCloseWithLossTestCase(bool sackEnabled)
Constructor.
void NormalClose(SocketWho who) override
Socket closed normally.
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.
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.
void SetInitialCwnd(SocketWho who, uint32_t initialCwnd)
Forcefully set the initial cwnd.
virtual void ConfigureProperties()
Change the configuration of the socket properties.
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.
Ptr< TcpSocketMsgBase > GetReceiverSocket()
Get the pointer to a previously created receiver socket.
void SetSegmentSize(SocketWho who, uint32_t segmentSize)
Forcefully set the segment size.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:47
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.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
#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
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
#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:145
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1331
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpTcpCloseTestSuite g_tcpTcpCloseTestSuite
Static variable for test initialization.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:706