A Discrete-Event Network Simulator
API
tcp-endpoint-bug2211.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 Alexander Krotov <ilabdsf@yandex.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 
53 {
54 public:
60  TcpEndPointBug2211Test (std::string desc, bool ipVersion);
61 
66  void Recv (Ptr<Socket> socket);
72  void HandleAccept (Ptr<Socket> s, const Address &from);
77  void HandleConnect (Ptr<Socket> socket);
78  virtual void DoRun ();
79 private:
80  bool m_v6;
81 };
82 
83 void
85 {
86  if (socket->GetRxAvailable() == 536 * 2)
87  {
88  socket->Close();
89  }
90 }
91 
92 void
94 {
96 }
97 
98 void
100 {
101  socket->Send (Create<Packet> (536));
102  socket->Send (Create<Packet> (536));
103  socket->Send (Create<Packet> (536));
104  socket->Close ();
105 }
106 
107 TcpEndPointBug2211Test::TcpEndPointBug2211Test (std::string desc, bool ipVersion) : TestCase (desc)
108 {
109  m_v6 = ipVersion;
110 }
111 
112 void
114 {
115  Ptr<Node> node = CreateObject<Node> ();
116 
117  InternetStackHelper internet;
118  internet.Install (node);
119 
120  TypeId tid = TcpSocketFactory::GetTypeId ();
121  Ptr<Socket> sink = Socket::CreateSocket (node, tid);
122  if (m_v6 == false)
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 == false)
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 
158 {
159 public:
160  TcpEndpointBug2211TestSuite () : 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 
168 
169 
170 
Ptr< PacketSink > sink
Definition: wifi-tcp.cc:56
an Inet address class
virtual void DoRun()
Implementation to actually run this TestCase.
void HandleConnect(Ptr< Socket > socket)
Handle a connection establishment.
bool m_v6
True to use IPv6.
A suite of tests to run.
Definition: test.h:1342
aggregate IP/TCP/UDP functionality to existing Nodes.
TestSuite for bug 2211 - It must be used with valgrind.
Callback< R > MakeNullCallback(void)
Definition: callback.h:1635
TcpEndPointBug2211Test(std::string desc, bool ipVersion)
Constructor.
encapsulates test code
Definition: test.h:1155
a polymophic address class
Definition: address.h:90
void HandleAccept(Ptr< Socket > s, const Address &from)
Handle an incoming connection.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
void Recv(Ptr< Socket > socket)
Receive a packet.
An Inet6 address class.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
Definition: socket.cc:128
static TcpEndpointBug2211TestSuite g_TcpEndPoint2211TestSuite
Static variable for test initialization.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
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
This test suite implements a Unit Test.
Definition: test.h:1351
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
virtual int Close(void)=0
Close a socket.
a unique identifier for an interface.
Definition: type-id.h:58
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.