Factor out socket writer application from tcp test suites

This commit is contained in:
Tom Henderson
2010-04-11 23:12:42 -07:00
parent b3a1b16240
commit ab6e1c3d0a
5 changed files with 139 additions and 85 deletions

View File

@@ -34,6 +34,7 @@
#include "ns3/tcp-socket-factory.h"
#include "ns3/node-container.h"
#include "ns3/simulator.h"
#include "ns3tcp-socket-writer.h"
using namespace ns3;
@@ -44,85 +45,6 @@ NS_LOG_COMPONENT_DEFINE ("Ns3SocketTest");
// ===========================================================================
//
//
// Simple class to write data to sockets
class SocketWriter : public Application
{
public:
SocketWriter ();
virtual ~SocketWriter ();
void Setup (Ptr<Node> node, Address peer);
void Connect ();
void Write (uint32_t numBytes);
void Close ();
private:
virtual void StartApplication (void);
virtual void StopApplication (void);
Address m_peer;
Ptr<Node> m_node;
Ptr<Socket> m_socket;
bool m_isSetup;
bool m_isConnected;
};
SocketWriter::SocketWriter () : m_node (0), m_socket (0), m_isSetup (false), m_isConnected (false)
{
}
SocketWriter::~SocketWriter ()
{
m_socket = 0;
m_node = 0;
}
void
SocketWriter::StartApplication ()
{
m_socket = Socket::CreateSocket (m_node, TcpSocketFactory::GetTypeId ());
m_socket->Bind ();
}
void
SocketWriter::StopApplication ()
{
}
void
SocketWriter::Setup (Ptr<Node> node, Address peer)
{
m_peer = peer;
m_node = node;
m_isSetup = true;
}
void
SocketWriter::Connect ()
{
if (!m_isSetup)
{
NS_FATAL_ERROR ("Forgot to call Setup() first");
}
m_socket->Connect (m_peer);
m_isConnected = true;
}
void
SocketWriter::Write (uint32_t numBytes)
{
if (!m_isConnected)
{
Connect ();
}
Ptr<Packet> packet = Create<Packet> (numBytes);
m_socket->Send (packet);
}
void
SocketWriter::Close ()
{
m_socket->Close ();
}
class Ns3TcpSocketTestCase1 : public TestCase
{
public:

View File

@@ -0,0 +1,83 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2010 University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ns3tcp-socket-writer.h"
#include "ns3/tcp-socket-factory.h"
#include "ns3/packet.h"
namespace ns3
{
SocketWriter::SocketWriter () : m_node (0), m_socket (0), m_isSetup (false), m_isConnected (false)
{
}
SocketWriter::~SocketWriter ()
{
m_socket = 0;
m_node = 0;
}
void
SocketWriter::StartApplication ()
{
m_socket = Socket::CreateSocket (m_node, TcpSocketFactory::GetTypeId ());
m_socket->Bind ();
}
void
SocketWriter::StopApplication ()
{
}
void
SocketWriter::Setup (Ptr<Node> node, Address peer)
{
m_peer = peer;
m_node = node;
m_isSetup = true;
}
void
SocketWriter::Connect ()
{
if (!m_isSetup)
{
NS_FATAL_ERROR ("Forgot to call Setup() first");
}
m_socket->Connect (m_peer);
m_isConnected = true;
}
void
SocketWriter::Write (uint32_t numBytes)
{
if (!m_isConnected)
{
Connect ();
}
Ptr<Packet> packet = Create<Packet> (numBytes);
m_socket->Send (packet);
}
void
SocketWriter::Close ()
{
m_socket->Close ();
}
}

View File

@@ -0,0 +1,47 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2010 University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ns3/application.h"
#include "ns3/node.h"
#include "ns3/ptr.h"
#include "ns3/socket.h"
#include "ns3/address.h"
namespace ns3
{
// Simple class to write data to sockets
class SocketWriter : public Application
{
public:
SocketWriter ();
virtual ~SocketWriter ();
void Setup (Ptr<Node> node, Address peer);
void Connect ();
void Write (uint32_t numBytes);
void Close ();
private:
virtual void StartApplication (void);
virtual void StopApplication (void);
Address m_peer;
Ptr<Node> m_node;
Ptr<Socket> m_socket;
bool m_isSetup;
bool m_isConnected;
};
}

View File

@@ -4,5 +4,6 @@
*
* \section Ns3TcpTestsOverview ns-3 Tcp Implementation Tests Overview
*
* ns-3 has a TCP implemtation and we test it a litte.
* Includes tests of ns-3 TCP as well as tests involving the mix
* of ns-3 and Network Simulation Cradle (nsc) TCP models.
*/

View File

@@ -10,9 +10,10 @@ def build(bld):
headers.source = [
'ns3tcp.h',
]
ns3tcp.source = [
'ns3tcp-socket-writer.cc',
]
if bld.env['NSC_ENABLED']:
ns3tcp.source = [
'ns3tcp-interop-test-suite.cc',
'ns3tcp-cwnd-test-suite.cc',
'ns3tcp-socket-test-suite.cc'
]
ns3tcp.source.append ('ns3tcp-interop-test-suite.cc')
ns3tcp.source.append ('ns3tcp-cwnd-test-suite.cc')
ns3tcp.source.append ('ns3tcp-socket-test-suite.cc')