A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "ns3/core-module.h"
9#include "ns3/internet-module.h"
10#include "ns3/network-module.h"
11#include "ns3/test.h"
12
13#include <iostream>
14
15using namespace ns3;
16
17/**
18 * \ingroup internet-test
19 *
20 * \brief Test that connection failed callback is called when
21 * SYN retransmission number is exceeded.
22 */
24{
25 public:
26 /**
27 * Constructor.
28 * \param desc Test description.
29 * \param useEcn Whether to enable ECN.
30 */
31 TcpSynConnectionFailedTest(std::string desc, bool useEcn);
32
33 /**
34 * \brief Handle a connection failure.
35 * \param socket The receiving socket.
36 */
38 void DoRun() override;
39
40 private:
41 bool m_connectionFailed{false}; //!< Connection failure indicator
42 bool m_useEcn{false}; //!< Use ECN (true or false)
43};
44
46 : TestCase(desc),
47 m_useEcn(useEcn)
48{
49}
50
51void
56
57void
59{
61
62 InternetStackHelper internet;
63 internet.Install(node);
64
66
67 Ptr<Socket> socket = Socket::CreateSocket(node, tid);
68 if (m_useEcn)
69 {
71 tcpSocket->SetUseEcn(TcpSocketState::On);
72 }
73 socket->Bind();
74 socket->SetConnectCallback(
77 socket->Connect(InetSocketAddress(Ipv4Address::GetLoopback(), 9));
78
81
82 NS_TEST_ASSERT_MSG_EQ(m_connectionFailed, true, "Connection failed callback was not called");
83}
84
85/**
86 * \ingroup internet-test
87 *
88 * \brief TestSuite
89 */
91{
92 public:
94 : TestSuite("tcp-syn-connection-failed-test", Type::UNIT)
95 {
96 AddTestCase(new TcpSynConnectionFailedTest("TCP SYN connection failed test no ECN", false),
97 TestCase::Duration::QUICK);
98 AddTestCase(new TcpSynConnectionFailedTest("TCP SYN connection failed test with ECN", true),
99 TestCase::Duration::QUICK);
100 }
101};
102
104 g_TcpSynConnectionFailedTestSuite; //!< Static variable for test initialization
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.
TcpSynConnectionFailedTest(std::string desc, bool useEcn)
Constructor.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
static Ipv4Address GetLoopback()
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition socket.cc:61
static TypeId GetTypeId()
Get the type ID.
encapsulates test code
Definition test.h:1050
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
a unique identifier for an interface.
Definition type-id.h:48
Callback< R, Args... > MakeNullCallback()
Definition callback.h:727
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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
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:684
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
static TcpSynConnectionFailedTestSuite g_TcpSynConnectionFailedTestSuite
Static variable for test initialization.