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 
26 using 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 
82 void
84 {
85  if (socket->GetRxAvailable() == 536 * 2)
86  {
87  socket->Close();
88  }
89 }
90 
91 void
93 {
95 }
96 
97 void
99 {
100  socket->Send(Create<Packet>(536));
101  socket->Send(Create<Packet>(536));
102  socket->Send(Create<Packet>(536));
103  socket->Close();
104 }
105 
106 TcpEndPointBug2211Test::TcpEndPointBug2211Test(std::string desc, bool ipVersion)
107  : TestCase(desc)
108 {
109  m_v6 = ipVersion;
110 }
111 
112 void
114 {
115  Ptr<Node> node = CreateObject<Node>();
116 
118  internet.Install(node);
119 
120  TypeId tid = TcpSocketFactory::GetTypeId();
121  Ptr<Socket> sink = Socket::CreateSocket(node, tid);
122  if (!m_v6)
123  {
124  sink->Bind(InetSocketAddress(Ipv4Address::GetAny(), 9));
125  }
126  else
127  {
128  sink->Bind(Inet6SocketAddress(Ipv6Address::GetAny(), 9));
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();
137  MakeNullCallback<void, Ptr<Socket>>());
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 
147  Simulator::Run();
148  Simulator::Destroy();
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:101
An Inet6 address class.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
virtual uint32_t GetRxAvailable() const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
void SetRecvCallback(Callback< void, Ptr< Socket >> receivedData)
Notify application when new data is available to be read.
Definition: socket.cc:128
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
virtual int Close()=0
Close a socket.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
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:87
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: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:747
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:704
static TcpEndpointBug2211TestSuite g_TcpEndPoint2211TestSuite
Static variable for test initialization.
Ptr< PacketSink > sink
Pointer to the packet sink application.
Definition: wifi-tcp.cc:55