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 * 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/config.h"
12#include "ns3/log.h"
13#include "ns3/node.h"
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("TcpCloseTestSuite");
19
20/**
21 * \brief Check if the TCP correctly close the connection after receiving
22 * previously lost data
23 */
25{
26 public:
27 /**
28 * \brief Constructor
29 * \param sackEnabled Enable or disable SACK
30 */
31 TcpCloseWithLossTestCase(bool sackEnabled);
32
33 protected:
35 void ConfigureProperties() override;
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;
38 void FinalChecks() override;
39
40 void NormalClose(SocketWho who) override
41 {
42 if (who == SENDER)
43 {
44 m_sendClose = true;
45 }
46 else
47 {
48 m_recvClose = true;
49 }
50 }
51
52 /**
53 * Called when a packet is dropped.
54 * \param ipH IP header
55 * \param tcpH TCP header
56 * \param pkt packet
57 */
58 void PktDropped(const Ipv4Header& ipH, const TcpHeader& tcpH, Ptr<const Packet> pkt);
59
60 private:
61 Ptr<TcpSeqErrorModel> m_errorModel; //!< The error model
62 bool m_sendClose; //!< true when the sender has closed
63 bool m_recvClose; //!< true when the receiver has closed
64 bool m_synReceived; //!< true when the receiver gets SYN
65 bool m_sackEnabled; //!< true if sack should be enabled
66};
67
69 : TcpGeneralTest("Testing connection closing with retransmissions")
70{
71 m_sendClose = false;
72 m_recvClose = false;
73 m_synReceived = false;
74 m_sackEnabled = sackEnabled;
75}
76
77void
79{
81 SetAppPktSize(1400);
85 SetMTU(1452);
87 GetSenderSocket()->SetAttribute("Timestamp", BooleanValue(false));
88 GetReceiverSocket()->SetAttribute("Timestamp", BooleanValue(false));
89 GetSenderSocket()->SetAttribute("Sack", BooleanValue(m_sackEnabled));
90}
91
92void
94{
95 NS_TEST_ASSERT_MSG_EQ(m_sendClose, true, "Sender has not closed successfully the connection");
96 NS_TEST_ASSERT_MSG_EQ(m_recvClose, true, "Recv has not closed successfully the connection");
97}
98
109
110void
112 const TcpHeader& tcpH,
114{
115 NS_LOG_INFO("Dropped " << tcpH);
116}
117
118void
120{
121 if (who == SENDER)
122 {
123 NS_LOG_INFO("Sender TX: " << h << " size " << p->GetSize());
124 }
125 else
126 {
127 NS_LOG_INFO("Receiver TX: " << h << " size " << p->GetSize());
128 }
129}
130
131void
133{
134 if (who == SENDER)
135 {
136 NS_LOG_INFO("Sender RX: " << h << " size " << p->GetSize());
137 }
138 else
139 {
140 NS_LOG_INFO("Receiver RX: " << h << " size " << p->GetSize());
141 }
142}
143
144/**
145 * Check if the TCP is correctly closing its state
146 */
157
158static TcpTcpCloseTestSuite g_tcpTcpCloseTestSuite; //!< Static variable for test initialization
159
160} // namespace ns3
Packet header for IPv4.
Definition ipv4-header.h:23
Smart pointer class similar to boost::intrusive_ptr.
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
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:36
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: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
#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
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
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:134
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
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:684