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
* 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
26
using namespace
ns3
;
27
34
class
TcpSynConnectionFailedTest
:
public
TestCase
35
{
36
public
:
42
TcpSynConnectionFailedTest
(std::string desc,
bool
useEcn);
43
48
void
HandleConnectionFailed
(
Ptr<Socket>
socket);
49
void
DoRun
()
override
;
50
51
private
:
52
bool
m_connectionFailed
{
false
};
53
bool
m_useEcn
{
false
};
54
};
55
56
TcpSynConnectionFailedTest::TcpSynConnectionFailedTest
(std::string desc,
bool
useEcn)
57
:
TestCase
(desc),
58
m_useEcn(useEcn)
59
{
60
}
61
62
void
63
TcpSynConnectionFailedTest::HandleConnectionFailed
(
Ptr<Socket>
socket)
64
{
65
m_connectionFailed
=
true
;
66
}
67
68
void
69
TcpSynConnectionFailedTest::DoRun
()
70
{
71
Ptr<Node>
node = CreateObject<Node>();
72
73
InternetStackHelper
internet;
74
internet.Install(node);
75
76
TypeId
tid =
TcpSocketFactory::GetTypeId
();
77
78
Ptr<Socket>
socket =
Socket::CreateSocket
(node, tid);
79
if
(
m_useEcn
)
80
{
81
Ptr<TcpSocketBase>
tcpSocket = DynamicCast<TcpSocketBase>(socket);
82
tcpSocket->SetUseEcn(
TcpSocketState::On
);
83
}
84
socket->Bind();
85
socket->SetConnectCallback(
86
MakeNullCallback
<
void
,
Ptr<Socket>
>(),
87
MakeCallback
(&
TcpSynConnectionFailedTest::HandleConnectionFailed
,
this
));
88
socket->Connect(
InetSocketAddress
(
Ipv4Address::GetLoopback
(), 9));
89
90
Simulator::Run
();
91
Simulator::Destroy
();
92
93
NS_TEST_ASSERT_MSG_EQ
(
m_connectionFailed
,
true
,
"Connection failed callback was not called"
);
94
}
95
101
class
TcpSynConnectionFailedTestSuite
:
public
TestSuite
102
{
103
public
:
104
TcpSynConnectionFailedTestSuite
()
105
:
TestSuite
(
"tcp-syn-connection-failed-test"
,
UNIT
)
106
{
107
AddTestCase
(
new
TcpSynConnectionFailedTest
(
"TCP SYN connection failed test no ECN"
,
false
),
108
TestCase::QUICK
);
109
AddTestCase
(
new
TcpSynConnectionFailedTest
(
"TCP SYN connection failed test with ECN"
,
true
),
110
TestCase::QUICK
);
111
}
112
};
113
114
static
TcpSynConnectionFailedTestSuite
115
g_TcpSynConnectionFailedTestSuite
;
TcpSynConnectionFailedTest
Test that connection failed callback is called when SYN retransmission number is exceeded.
Definition:
tcp-syn-connection-failed-test.cc:35
TcpSynConnectionFailedTest::m_connectionFailed
bool m_connectionFailed
Connection failure indicator.
Definition:
tcp-syn-connection-failed-test.cc:52
TcpSynConnectionFailedTest::HandleConnectionFailed
void HandleConnectionFailed(Ptr< Socket > socket)
Handle a connection failure.
Definition:
tcp-syn-connection-failed-test.cc:63
TcpSynConnectionFailedTest::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
tcp-syn-connection-failed-test.cc:69
TcpSynConnectionFailedTest::m_useEcn
bool m_useEcn
Use ECN (true or false)
Definition:
tcp-syn-connection-failed-test.cc:53
TcpSynConnectionFailedTest::TcpSynConnectionFailedTest
TcpSynConnectionFailedTest(std::string desc, bool useEcn)
Constructor.
Definition:
tcp-syn-connection-failed-test.cc:56
TcpSynConnectionFailedTestSuite
TestSuite.
Definition:
tcp-syn-connection-failed-test.cc:102
TcpSynConnectionFailedTestSuite::TcpSynConnectionFailedTestSuite
TcpSynConnectionFailedTestSuite()
Definition:
tcp-syn-connection-failed-test.cc:104
ns3::InetSocketAddress
an Inet address class
Definition:
inet-socket-address.h:42
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition:
internet-stack-helper.h:92
ns3::Ipv4Address::GetLoopback
static Ipv4Address GetLoopback()
Definition:
ipv4-address.cc:394
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:78
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:140
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition:
simulator.cc:176
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:72
ns3::TcpSocketFactory::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition:
tcp-socket-factory.cc:30
ns3::TcpSocketState::On
@ On
Enable.
Definition:
tcp-socket-state.h:118
ns3::TestCase
encapsulates test code
Definition:
test.h:1060
ns3::TestCase::QUICK
@ QUICK
Fast test.
Definition:
test.h:1065
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:301
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1256
ns3::TestSuite::UNIT
@ UNIT
This test suite implements a Unit Test.
Definition:
test.h:1265
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::MakeNullCallback
Callback< R, Args... > MakeNullCallback()
Definition:
callback.h:745
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:144
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:702
g_TcpSynConnectionFailedTestSuite
static TcpSynConnectionFailedTestSuite g_TcpSynConnectionFailedTestSuite
Static variable for test initialization.
Definition:
tcp-syn-connection-failed-test.cc:115
src
internet
test
tcp-syn-connection-failed-test.cc
Generated on Sun Jul 2 2023 18:21:44 for ns-3 by
1.9.6