diff --git a/src/test/ns3tcp/ns3tcp-socket-test-suite.cc b/src/test/ns3tcp/ns3tcp-socket-test-suite.cc index d42e039d0..b9e2d514a 100644 --- a/src/test/ns3tcp/ns3tcp-socket-test-suite.cc +++ b/src/test/ns3tcp/ns3tcp-socket-test-suite.cc @@ -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, Address peer); - void Connect (); - void Write (uint32_t numBytes); - void Close (); - -private: - virtual void StartApplication (void); - virtual void StopApplication (void); - Address m_peer; - Ptr m_node; - Ptr 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, 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 = Create (numBytes); - m_socket->Send (packet); -} - -void -SocketWriter::Close () -{ - m_socket->Close (); -} - class Ns3TcpSocketTestCase1 : public TestCase { public: diff --git a/src/test/ns3tcp/ns3tcp-socket-writer.cc b/src/test/ns3tcp/ns3tcp-socket-writer.cc new file mode 100644 index 000000000..b835a467b --- /dev/null +++ b/src/test/ns3tcp/ns3tcp-socket-writer.cc @@ -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, 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 = Create (numBytes); + m_socket->Send (packet); +} + +void +SocketWriter::Close () +{ + m_socket->Close (); +} +} diff --git a/src/test/ns3tcp/ns3tcp-socket-writer.h b/src/test/ns3tcp/ns3tcp-socket-writer.h new file mode 100644 index 000000000..9c3083461 --- /dev/null +++ b/src/test/ns3tcp/ns3tcp-socket-writer.h @@ -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, Address peer); + void Connect (); + void Write (uint32_t numBytes); + void Close (); + +private: + virtual void StartApplication (void); + virtual void StopApplication (void); + Address m_peer; + Ptr m_node; + Ptr m_socket; + bool m_isSetup; + bool m_isConnected; +}; +} diff --git a/src/test/ns3tcp/ns3tcp.h b/src/test/ns3tcp/ns3tcp.h index 30189c605..effaef699 100644 --- a/src/test/ns3tcp/ns3tcp.h +++ b/src/test/ns3tcp/ns3tcp.h @@ -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. */ diff --git a/src/test/ns3tcp/wscript b/src/test/ns3tcp/wscript index 661cb3233..6f5eea428 100644 --- a/src/test/ns3tcp/wscript +++ b/src/test/ns3tcp/wscript @@ -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')