A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-endpoint-bug2211.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Alexander Krotov <ilabdsf@yandex.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
51{
52 public:
58 TcpEndPointBug2211Test(std::string desc, bool ipVersion);
59
64 void Recv(Ptr<Socket> socket);
70 void HandleAccept(Ptr<Socket> s, const Address& from);
75 void HandleConnect(Ptr<Socket> socket);
76 void DoRun() override;
77
78 private:
79 bool m_v6;
80};
81
82void
84{
85 if (socket->GetRxAvailable() == 536 * 2)
86 {
87 socket->Close();
88 }
89}
90
91void
93{
94 s->SetRecvCallback(MakeCallback(&TcpEndPointBug2211Test::Recv, this));
95}
96
97void
99{
100 socket->Send(Create<Packet>(536));
101 socket->Send(Create<Packet>(536));
102 socket->Send(Create<Packet>(536));
103 socket->Close();
104}
105
106TcpEndPointBug2211Test::TcpEndPointBug2211Test(std::string desc, bool ipVersion)
107 : TestCase(desc)
108{
109 m_v6 = ipVersion;
110}
111
112void
114{
115 Ptr<Node> node = CreateObject<Node>();
116
117 InternetStackHelper internet;
118 internet.Install(node);
119
122 if (!m_v6)
123 {
125 }
126 else
127 {
129 }
130 sink->Listen();
131 sink->SetAcceptCallback(MakeNullCallback<bool, Ptr<Socket>, const Address&>(),
133
134 Ptr<Socket> source = Socket::CreateSocket(node, tid);
135 source->Bind();
136 source->SetConnectCallback(MakeCallback(&TcpEndPointBug2211Test::HandleConnect, this),
138 if (!m_v6)
139 {
140 source->Connect(InetSocketAddress(Ipv4Address::GetLoopback(), 9));
141 }
142 else
143 {
144 source->Connect(Inet6SocketAddress(Ipv6Address::GetLoopback(), 9));
145 }
146
149}
150
157{
158 public:
160 : TestSuite("tcp-endpoint-bug2211-test", UNIT)
161 {
162 AddTestCase(new TcpEndPointBug2211Test("Bug 2211 testcase IPv4", false), TestCase::QUICK);
163 AddTestCase(new TcpEndPointBug2211Test("Bug 2211 testcase IPv6", true), TestCase::QUICK);
164 }
165};
166
bool m_v6
True to use IPv6.
void DoRun() override
Implementation to actually run this TestCase.
void Recv(Ptr< Socket > socket)
Receive a packet.
void HandleAccept(Ptr< Socket > s, const Address &from)
Handle an incoming connection.
void HandleConnect(Ptr< Socket > socket)
Handle a connection establishment.
TcpEndPointBug2211Test(std::string desc, bool ipVersion)
Constructor.
TestSuite for bug 2211 - It must be used with valgrind.
a polymophic address class
Definition: address.h:100
An Inet6 address class.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
static Ipv4Address GetLoopback()
static Ipv4Address GetAny()
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
static Ipv6Address GetLoopback()
Get the loopback address.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static void Run()
Run the simulation.
Definition: simulator.cc:176
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
static TypeId GetTypeId()
Get the type ID.
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
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:59
Callback< R, Args... > MakeNullCallback()
Definition: callback.h:745
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:702
static TcpEndpointBug2211TestSuite g_TcpEndPoint2211TestSuite
Static variable for test initialization.
Ptr< PacketSink > sink
Pointer to the packet sink application.
Definition: wifi-tcp.cc:55