A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
tcp-syn-connection-failed-test.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2019 Alexander Krotov <krotov@iitp.ru>
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
*/
19
20
#include <iostream>
21
22
#include "ns3/test.h"
23
#include "ns3/core-module.h"
24
#include "ns3/network-module.h"
25
#include "ns3/internet-module.h"
26
27
using namespace
ns3
;
28
36
class
TcpSynConnectionFailedTest
:
public
TestCase
37
{
38
public
:
44
TcpSynConnectionFailedTest
(std::string desc,
bool
useEcn);
45
50
void
HandleConnectionFailed (
Ptr<Socket>
socket);
51
virtual
void
DoRun ();
52
53
private
:
54
bool
m_connectionFailed{
false
};
55
bool
m_useEcn {
false
};
56
};
57
58
TcpSynConnectionFailedTest::TcpSynConnectionFailedTest
(std::string desc,
bool
useEcn) :
TestCase
(desc), 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
(
MakeNullCallback
<
void
,
Ptr<Socket>
>(),
86
MakeCallback
(&
TcpSynConnectionFailedTest::HandleConnectionFailed
,
this
));
87
socket->
Connect
(
InetSocketAddress
(Ipv4Address::GetLoopback (), 9));
88
89
Simulator::Run ();
90
Simulator::Destroy ();
91
92
NS_TEST_ASSERT_MSG_EQ
(
m_connectionFailed
,
true
,
"Connection failed callback was not called"
);
93
}
94
101
class
TcpSynConnectionFailedTestSuite
:
public
TestSuite
102
{
103
public
:
104
TcpSynConnectionFailedTestSuite
() :
TestSuite
(
"tcp-syn-connection-failed-test"
,
UNIT
)
105
{
106
AddTestCase
(
new
TcpSynConnectionFailedTest
(
"TCP SYN connection failed test no ECN"
,
false
), TestCase::QUICK);
107
AddTestCase
(
new
TcpSynConnectionFailedTest
(
"TCP SYN connection failed test with ECN"
,
true
), TestCase::QUICK);
108
}
109
};
110
111
static
TcpSynConnectionFailedTestSuite
g_TcpSynConnectionFailedTestSuite
;
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::InetSocketAddress
an Inet address class
Definition:
inet-socket-address.h:41
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
ns3::Socket::Bind
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
TcpSynConnectionFailedTest::m_useEcn
bool m_useEcn
Use ECN (true or false)
Definition:
tcp-syn-connection-failed-test.cc:55
TcpSynConnectionFailedTest::TcpSynConnectionFailedTest
TcpSynConnectionFailedTest(std::string desc, bool useEcn)
Constructor.
Definition:
tcp-syn-connection-failed-test.cc:58
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Socket::SetConnectCallback
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:84
TcpSynConnectionFailedTest::DoRun
virtual void DoRun()
Implementation to actually run this TestCase.
Definition:
tcp-syn-connection-failed-test.cc:69
ns3::MakeNullCallback
Callback< R, Ts... > MakeNullCallback(void)
Definition:
callback.h:1682
ns3::TestCase
encapsulates test code
Definition:
test.h:1154
ns3::Ptr< Socket >
g_TcpSynConnectionFailedTestSuite
static TcpSynConnectionFailedTestSuite g_TcpSynConnectionFailedTestSuite
Static variable for test initialization.
Definition:
tcp-syn-connection-failed-test.cc:111
ns3::InternetStackHelper::Install
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Definition:
internet-stack-helper.cc:366
TcpSynConnectionFailedTestSuite
TestSuite.
Definition:
tcp-syn-connection-failed-test.cc:102
ns3::MakeCallback
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition:
callback.h:1642
TcpSynConnectionFailedTestSuite::TcpSynConnectionFailedTestSuite
TcpSynConnectionFailedTestSuite()
Definition:
tcp-syn-connection-failed-test.cc:104
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1344
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:166
TcpSynConnectionFailedTest::m_connectionFailed
bool m_connectionFailed
Connection failure indicator.
Definition:
tcp-syn-connection-failed-test.cc:54
ns3::Socket::Connect
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
ns3::TestSuite::UNIT
@ UNIT
This test suite implements a Unit Test.
Definition:
test.h:1353
ns3::TcpSocketBase::SetUseEcn
void SetUseEcn(TcpSocketState::UseEcn_t useEcn)
Set ECN mode of use on the socket.
Definition:
tcp-socket-base.cc:4540
TcpSynConnectionFailedTest::HandleConnectionFailed
void HandleConnectionFailed(Ptr< Socket > socket)
Handle a connection failure.
Definition:
tcp-syn-connection-failed-test.cc:63
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition:
internet-stack-helper.h:88
TcpSynConnectionFailedTest
Test that connection failed callback is called when SYN retransmission number is exceeded.
Definition:
tcp-syn-connection-failed-test.cc:37
src
internet
test
tcp-syn-connection-failed-test.cc
Generated on Fri Oct 1 2021 17:03:13 for ns-3 by
1.8.20