A Discrete-Event Network Simulator
API
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
52{
53 public:
59 TcpEndPointBug2211Test(std::string desc, bool ipVersion);
60
65 void Recv(Ptr<Socket> socket);
71 void HandleAccept(Ptr<Socket> s, const Address& from);
76 void HandleConnect(Ptr<Socket> socket);
77 void DoRun() override;
78
79 private:
80 bool m_v6;
81};
82
83void
85{
86 if (socket->GetRxAvailable() == 536 * 2)
87 {
88 socket->Close();
89 }
90}
91
92void
94{
96}
97
98void
100{
101 socket->Send(Create<Packet>(536));
102 socket->Send(Create<Packet>(536));
103 socket->Send(Create<Packet>(536));
104 socket->Close();
105}
106
107TcpEndPointBug2211Test::TcpEndPointBug2211Test(std::string desc, bool ipVersion)
108 : TestCase(desc)
109{
110 m_v6 = ipVersion;
111}
112
113void
115{
116 Ptr<Node> node = CreateObject<Node>();
117
118 InternetStackHelper internet;
119 internet.Install(node);
120
121 TypeId tid = TcpSocketFactory::GetTypeId();
122 Ptr<Socket> sink = Socket::CreateSocket(node, tid);
123 if (m_v6 == false)
124 {
125 sink->Bind(InetSocketAddress(Ipv4Address::GetAny(), 9));
126 }
127 else
128 {
129 sink->Bind(Inet6SocketAddress(Ipv6Address::GetAny(), 9));
130 }
131 sink->Listen();
132 sink->SetAcceptCallback(MakeNullCallback<bool, Ptr<Socket>, const Address&>(),
134
135 Ptr<Socket> source = Socket::CreateSocket(node, tid);
136 source->Bind();
139 if (m_v6 == false)
140 {
141 source->Connect(InetSocketAddress(Ipv4Address::GetLoopback(), 9));
142 }
143 else
144 {
145 source->Connect(Inet6SocketAddress(Ipv6Address::GetLoopback(), 9));
146 }
147
148 Simulator::Run();
149 Simulator::Destroy();
150}
151
159{
160 public:
162 : TestSuite("tcp-endpoint-bug2211-test", UNIT)
163 {
164 AddTestCase(new TcpEndPointBug2211Test("Bug 2211 testcase IPv4", false), TestCase::QUICK);
165 AddTestCase(new TcpEndPointBug2211Test("Bug 2211 testcase IPv6", true), TestCase::QUICK);
166 }
167};
168
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:92
An Inet6 address class.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
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:85
virtual uint32_t GetRxAvailable() const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Definition: socket.cc:126
virtual int Close()=0
Close a socket.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
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:60
Callback< R, Args... > MakeNullCallback()
Definition: callback.h:734
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:691
static TcpEndpointBug2211TestSuite g_TcpEndPoint2211TestSuite
Static variable for test initialization.
Ptr< PacketSink > sink
Pointer to the packet sink application.
Definition: wifi-tcp.cc:55