A Discrete-Event Network Simulator
API
tcp-syn-connection-failed-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Alexander Krotov <krotov@iitp.ru>
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 "ns3/core-module.h"
20#include "ns3/internet-module.h"
21#include "ns3/network-module.h"
22#include "ns3/test.h"
23
24#include <iostream>
25
26using namespace ns3;
27
36{
37 public:
43 TcpSynConnectionFailedTest(std::string desc, bool useEcn);
44
50 void DoRun() override;
51
52 private:
53 bool m_connectionFailed{false};
54 bool m_useEcn{false};
55};
56
58 : TestCase(desc),
59 m_useEcn(useEcn)
60{
61}
62
63void
65{
66 m_connectionFailed = true;
67}
68
69void
71{
72 Ptr<Node> node = CreateObject<Node>();
73
74 InternetStackHelper internet;
75 internet.Install(node);
76
77 TypeId tid = TcpSocketFactory::GetTypeId();
78
79 Ptr<Socket> socket = Socket::CreateSocket(node, tid);
80 if (m_useEcn)
81 {
82 Ptr<TcpSocketBase> tcpSocket = DynamicCast<TcpSocketBase>(socket);
83 tcpSocket->SetUseEcn(TcpSocketState::On);
84 }
85 socket->Bind();
86 socket->SetConnectCallback(
89 socket->Connect(InetSocketAddress(Ipv4Address::GetLoopback(), 9));
90
91 Simulator::Run();
92 Simulator::Destroy();
93
94 NS_TEST_ASSERT_MSG_EQ(m_connectionFailed, true, "Connection failed callback was not called");
95}
96
104{
105 public:
107 : TestSuite("tcp-syn-connection-failed-test", UNIT)
108 {
109 AddTestCase(new TcpSynConnectionFailedTest("TCP SYN connection failed test no ECN", false),
110 TestCase::QUICK);
111 AddTestCase(new TcpSynConnectionFailedTest("TCP SYN connection failed test with ECN", true),
112 TestCase::QUICK);
113 }
114};
115
Test that connection failed callback is called when SYN retransmission number is exceeded.
bool m_connectionFailed
Connection failure indicator.
void HandleConnectionFailed(Ptr< Socket > socket)
Handle a connection failure.
void DoRun() override
Implementation to actually run this TestCase.
bool m_useEcn
Use ECN (true or false)
TcpSynConnectionFailedTest(std::string desc, bool useEcn)
Constructor.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SetConnectCallback(Callback< void, Ptr< Socket > > connectionSucceeded, Callback< void, Ptr< Socket > > connectionFailed)
Specify callbacks to allow the caller to determine if the connection succeeds of fails.
Definition: socket.cc:85
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
a unique identifier for an interface.
Definition: type-id.h:60
Callback< R, Args... > MakeNullCallback()
Definition: callback.h:734
#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:144
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:691
static TcpSynConnectionFailedTestSuite g_TcpSynConnectionFailedTestSuite
Static variable for test initialization.