A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
15
using 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
*/
23
class
TcpSynConnectionFailedTest
:
public
TestCase
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
*/
37
void
HandleConnectionFailed
(
Ptr<Socket>
socket);
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
45
TcpSynConnectionFailedTest::TcpSynConnectionFailedTest
(std::string desc,
bool
useEcn)
46
:
TestCase
(desc),
47
m_useEcn(useEcn)
48
{
49
}
50
51
void
52
TcpSynConnectionFailedTest::HandleConnectionFailed
(
Ptr<Socket>
socket)
53
{
54
m_connectionFailed
=
true
;
55
}
56
57
void
58
TcpSynConnectionFailedTest::DoRun
()
59
{
60
Ptr<Node>
node =
CreateObject<Node>
();
61
62
InternetStackHelper
internet;
63
internet.Install(node);
64
65
TypeId
tid =
TcpSocketFactory::GetTypeId
();
66
67
Ptr<Socket>
socket =
Socket::CreateSocket
(node, tid);
68
if
(
m_useEcn
)
69
{
70
Ptr<TcpSocketBase>
tcpSocket =
DynamicCast<TcpSocketBase>
(socket);
71
tcpSocket->SetUseEcn(
TcpSocketState::On
);
72
}
73
socket->Bind();
74
socket->SetConnectCallback(
75
MakeNullCallback
<
void
,
Ptr<Socket>
>(),
76
MakeCallback
(&
TcpSynConnectionFailedTest::HandleConnectionFailed
,
this
));
77
socket->Connect(
InetSocketAddress
(
Ipv4Address::GetLoopback
(), 9));
78
79
Simulator::Run
();
80
Simulator::Destroy
();
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
*/
90
class
TcpSynConnectionFailedTestSuite
:
public
TestSuite
91
{
92
public
:
93
TcpSynConnectionFailedTestSuite
()
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
103
static
TcpSynConnectionFailedTestSuite
104
g_TcpSynConnectionFailedTestSuite
;
//!< Static variable for test initialization
TcpSynConnectionFailedTest
Test that connection failed callback is called when SYN retransmission number is exceeded.
Definition
tcp-syn-connection-failed-test.cc:24
TcpSynConnectionFailedTest::m_connectionFailed
bool m_connectionFailed
Connection failure indicator.
Definition
tcp-syn-connection-failed-test.cc:41
TcpSynConnectionFailedTest::HandleConnectionFailed
void HandleConnectionFailed(Ptr< Socket > socket)
Handle a connection failure.
Definition
tcp-syn-connection-failed-test.cc:52
TcpSynConnectionFailedTest::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
tcp-syn-connection-failed-test.cc:58
TcpSynConnectionFailedTest::m_useEcn
bool m_useEcn
Use ECN (true or false)
Definition
tcp-syn-connection-failed-test.cc:42
TcpSynConnectionFailedTest::TcpSynConnectionFailedTest
TcpSynConnectionFailedTest(std::string desc, bool useEcn)
Constructor.
Definition
tcp-syn-connection-failed-test.cc:45
TcpSynConnectionFailedTestSuite
TestSuite.
Definition
tcp-syn-connection-failed-test.cc:91
TcpSynConnectionFailedTestSuite::TcpSynConnectionFailedTestSuite
TcpSynConnectionFailedTestSuite()
Definition
tcp-syn-connection-failed-test.cc:93
ns3::InetSocketAddress
an Inet address class
Definition
inet-socket-address.h:31
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition
internet-stack-helper.h:81
ns3::Ipv4Address::GetLoopback
static Ipv4Address GetLoopback()
Definition
ipv4-address.cc:384
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::Socket::CreateSocket
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
ns3::TcpSocketFactory::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
tcp-socket-factory.cc:19
ns3::TcpSocketState::On
@ On
Enable.
Definition
tcp-socket-state.h:107
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::TestSuite::UNIT
static constexpr auto UNIT
Definition
test.h:1291
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
ns3::MakeNullCallback
Callback< R, Args... > MakeNullCallback()
Definition
callback.h:727
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
NS_TEST_ASSERT_MSG_EQ
#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
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::MakeCallback
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
ns3::DynamicCast
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition
ptr.h:580
g_TcpSynConnectionFailedTestSuite
static TcpSynConnectionFailedTestSuite g_TcpSynConnectionFailedTestSuite
Static variable for test initialization.
Definition
tcp-syn-connection-failed-test.cc:104
src
internet
test
tcp-syn-connection-failed-test.cc
Generated on Mon Oct 14 2024 18:20:42 for ns-3 by
1.11.0