From b489a41127f7da46564615e62a6f3cf3de663449 Mon Sep 17 00:00:00 2001
From: Tommaso Pecorella
Date: Wed, 10 Sep 2014 06:09:45 +0200
Subject: [PATCH] Bug 1811 - Basic traffic generator for network module
---
CHANGES.html | 2 +
RELEASE_NOTES | 4 +-
src/network/examples/packet-socket-apps.cc | 98 +++++++++++
src/network/examples/wscript | 4 +
.../test/packet-socket-apps-test-suite.cc | 126 ++++++++++++++
src/network/utils/packet-socket-client.cc | 155 ++++++++++++++++++
src/network/utils/packet-socket-client.h | 100 +++++++++++
src/network/utils/packet-socket-server.cc | 129 +++++++++++++++
src/network/utils/packet-socket-server.h | 92 +++++++++++
src/network/wscript | 5 +
src/spectrum/test/spectrum-ideal-phy-test.cc | 17 +-
src/spectrum/wscript | 2 +-
src/wave/test/ocb-test-suite.cc | 19 ++-
src/wave/wscript | 2 +-
14 files changed, 738 insertions(+), 17 deletions(-)
create mode 100644 src/network/examples/packet-socket-apps.cc
create mode 100644 src/network/test/packet-socket-apps-test-suite.cc
create mode 100644 src/network/utils/packet-socket-client.cc
create mode 100644 src/network/utils/packet-socket-client.h
create mode 100644 src/network/utils/packet-socket-server.cc
create mode 100644 src/network/utils/packet-socket-server.h
diff --git a/CHANGES.html b/CHANGES.html
index afadf79a6..9a7d833c4 100644
--- a/CHANGES.html
+++ b/CHANGES.html
@@ -91,6 +91,8 @@ us a note on ns-developers mailing list.
A new SimpleNetDeviceHelper can now be used to install SimpleNetDevices.
+ New PacketSocketServer and PacketSocketClient apps, meant to be used in tests.
+
Changes to existing API:
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
index 4fab567a6..88b5906db 100644
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -44,11 +44,14 @@ New user-visible features
it can have a limited bandwidth and it uses an output queue.
- SimpleNetDevice and SimpleChannel can be installed in a node through
an helper: SimpleNetDeviceHelper.
+- Implemented new PacketSocketServer and PacketSocketClient applications.
+ The primary use is in tests, to avoid the ones from the application module.
Bugs fixed
----------
- Bug 1762 - UE stuck in IDLE_CONNECTING because RRC CONN REQ is not transmitted
+- Bug 1811 - basic traffic generator for network module
- Bug 1831 - TcpSocket SlowStartThreshold is not a TraceSource
- Bug 1854 - std::out_of_range Problem
- Bug 1893 - issue in DoSchedUlTriggerReq with harq
@@ -65,7 +68,6 @@ Bugs fixed
- Bug 1967 - LL Multicast is not compressed in the right way in IPHC
- Bug 1942 - refactoring of lte-sinr-chunk-processor -> lte-chunk-processor
-
Known issues
------------
diff --git a/src/network/examples/packet-socket-apps.cc b/src/network/examples/packet-socket-apps.cc
new file mode 100644
index 000000000..e6159af7e
--- /dev/null
+++ b/src/network/examples/packet-socket-apps.cc
@@ -0,0 +1,98 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014 Universita' di Firenze
+ *
+ * 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
+ *
+ * Author: Tommaso Pecorella
+ */
+
+// Network topology
+//
+// n0 n1
+// | |
+// =================
+// SimpleChannel
+//
+// - Packets flows from n0 to n1
+//
+// This example shows how to use the SimpleServer and SimpleClient
+// to send non-IP packets over a SimpleNetDevice
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+
+using namespace ns3;
+
+
+int main (int argc, char *argv[])
+{
+ bool verbose = false;
+
+ CommandLine cmd;
+ cmd.AddValue ("verbose", "turn on log components", verbose);
+ cmd.Parse(argc, argv);
+
+ if (verbose)
+ {
+ LogComponentEnable ("PacketSocketServer", LOG_LEVEL_ALL);
+ LogComponentEnable ("PacketSocketClient", LOG_LEVEL_ALL);
+ LogComponentEnable ("SimpleNetDevice", LOG_LEVEL_ALL);
+ }
+
+ NodeContainer nodes;
+ nodes.Create (2);
+
+ ns3::PacketMetadata::Enable();
+
+ PacketSocketHelper packetSocket;
+
+ // give packet socket powers to nodes.
+ packetSocket.Install (nodes);
+
+ Ptr txDev;
+ txDev = CreateObject ();
+ nodes.Get (0)->AddDevice (txDev);
+
+ Ptr rxDev;
+ rxDev = CreateObject ();
+ nodes.Get (1)->AddDevice (rxDev);
+
+ Ptr channel = CreateObject ();
+ txDev->SetChannel (channel);
+ rxDev->SetChannel (channel);
+ txDev->SetNode (nodes.Get (0));
+ rxDev->SetNode (nodes.Get (1));
+
+
+ PacketSocketAddress socketAddr;
+ socketAddr.SetSingleDevice (txDev->GetIfIndex ());
+ socketAddr.SetPhysicalAddress (rxDev->GetAddress ());
+ // Arbitrary protocol type.
+ // Note: PacketSocket doesn't have any L4 multiplexing or demultiplexing
+ // The only mux/demux is based on the protocol field
+ socketAddr.SetProtocol (1);
+
+ Ptr client = CreateObject ();
+ client->SetRemote (socketAddr);
+ nodes.Get (0)->AddApplication (client);
+
+ Ptr server = CreateObject ();
+ server->SetLocal (socketAddr);
+ nodes.Get (1)->AddApplication (server);
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+ return 0;
+}
diff --git a/src/network/examples/wscript b/src/network/examples/wscript
index 127b000ea..5c32710b8 100644
--- a/src/network/examples/wscript
+++ b/src/network/examples/wscript
@@ -15,3 +15,7 @@ def build(bld):
obj = bld.create_ns3_program('droptail_vs_red', ['point-to-point', 'point-to-point-layout', 'internet', 'applications'])
obj.source = 'droptail_vs_red.cc'
+
+ obj = bld.create_ns3_program('packet-socket-apps', ['core', 'network'])
+ obj.source = 'packet-socket-apps.cc'
+
\ No newline at end of file
diff --git a/src/network/test/packet-socket-apps-test-suite.cc b/src/network/test/packet-socket-apps-test-suite.cc
new file mode 100644
index 000000000..4e7275a40
--- /dev/null
+++ b/src/network/test/packet-socket-apps-test-suite.cc
@@ -0,0 +1,126 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014 Universita' di Firenze
+ *
+ * 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
+ *
+ * Author: Tommaso Pecorella
+ */
+
+#include "ns3/test.h"
+#include "ns3/simulator.h"
+#include "ns3/uinteger.h"
+#include "ns3/traced-callback.h"
+#include "ns3/packet.h"
+#include "ns3/packet-socket-helper.h"
+#include "ns3/packet-socket-client.h"
+#include "ns3/packet-socket-server.h"
+#include "ns3/simple-net-device.h"
+#include "ns3/simple-channel.h"
+
+using namespace ns3;
+
+
+class PacketSocketAppsTest : public TestCase
+{
+ uint32_t m_receivedPacketSize;
+ uint32_t m_receivedPacketNumber;
+
+public:
+ virtual void DoRun (void);
+ PacketSocketAppsTest ();
+
+ void ReceivePkt (Ptr packet, const Address &from);
+};
+
+PacketSocketAppsTest::PacketSocketAppsTest ()
+ : TestCase ("Packet Socket Apps test")
+{
+ m_receivedPacketSize = 0;
+ m_receivedPacketNumber = 0;
+}
+
+void PacketSocketAppsTest::ReceivePkt (Ptr packet, const Address &from)
+{
+ if (packet)
+ {
+ m_receivedPacketSize = packet->GetSize ();
+ m_receivedPacketNumber++;
+ }
+}
+
+
+void
+PacketSocketAppsTest::DoRun (void)
+{
+ // Create topology
+
+ NodeContainer nodes;
+ nodes.Create (2);
+
+ PacketSocketHelper packetSocket;
+
+ // give packet socket powers to nodes.
+ packetSocket.Install (nodes);
+
+ Ptr txDev;
+ txDev = CreateObject ();
+ nodes.Get (0)->AddDevice (txDev);
+
+ Ptr rxDev;
+ rxDev = CreateObject ();
+ nodes.Get (1)->AddDevice (rxDev);
+
+ Ptr channel = CreateObject ();
+ txDev->SetChannel (channel);
+ rxDev->SetChannel (channel);
+ txDev->SetNode (nodes.Get (0));
+ rxDev->SetNode (nodes.Get (1));
+
+
+ PacketSocketAddress socketAddr;
+ socketAddr.SetSingleDevice (txDev->GetIfIndex ());
+ socketAddr.SetPhysicalAddress (rxDev->GetAddress ());
+ socketAddr.SetProtocol (1);
+
+ Ptr client = CreateObject ();
+ client->SetRemote (socketAddr);
+ client->SetAttribute ("PacketSize", UintegerValue (1000));
+ client->SetAttribute ("MaxPackets", UintegerValue (3));
+ nodes.Get (0)->AddApplication (client);
+
+ Ptr server = CreateObject ();
+ server->TraceConnectWithoutContext ("Rx", MakeCallback (&PacketSocketAppsTest::ReceivePkt, this));
+ server->SetLocal (socketAddr);
+ nodes.Get (1)->AddApplication (server);
+
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ NS_TEST_EXPECT_MSG_EQ (m_receivedPacketNumber, 3, "Number of packet received");
+ NS_TEST_EXPECT_MSG_EQ (m_receivedPacketSize, 1000, "Size of packet received");
+}
+
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+class PacketSocketAppsTestSuite : public TestSuite
+{
+public:
+ PacketSocketAppsTestSuite () : TestSuite ("packet-socket-apps", UNIT)
+ {
+ AddTestCase (new PacketSocketAppsTest, TestCase::QUICK);
+ }
+} g_packetSocketAppsTestSuite;
diff --git a/src/network/utils/packet-socket-client.cc b/src/network/utils/packet-socket-client.cc
new file mode 100644
index 000000000..df06e54e4
--- /dev/null
+++ b/src/network/utils/packet-socket-client.cc
@@ -0,0 +1,155 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014 Universita' di Firenze
+ *
+ * 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
+ *
+ * Author: Tommaso Pecorella
+ */
+
+#include "ns3/log.h"
+#include "ns3/nstime.h"
+#include "ns3/packet-socket-address.h"
+#include "ns3/packet-socket.h"
+#include "ns3/packet-socket-factory.h"
+#include "ns3/socket.h"
+#include "ns3/simulator.h"
+#include "ns3/socket-factory.h"
+#include "ns3/packet.h"
+#include "ns3/uinteger.h"
+#include "ns3/abort.h"
+#include "packet-socket-client.h"
+#include
+#include
+
+namespace ns3 {
+
+NS_LOG_COMPONENT_DEFINE ("PacketSocketClient");
+NS_OBJECT_ENSURE_REGISTERED (PacketSocketClient);
+
+TypeId
+PacketSocketClient::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::PacketSocketClient")
+ .SetParent ()
+ .AddConstructor ()
+ .AddAttribute ("MaxPackets",
+ "The maximum number of packets the application will send (zero means infinite)",
+ UintegerValue (100),
+ MakeUintegerAccessor (&PacketSocketClient::m_maxPackets),
+ MakeUintegerChecker ())
+ .AddAttribute ("Interval",
+ "The time to wait between packets", TimeValue (Seconds (1.0)),
+ MakeTimeAccessor (&PacketSocketClient::m_interval),
+ MakeTimeChecker ())
+ .AddAttribute ("PacketSize",
+ "Size of packets generated (bytes).",
+ UintegerValue (1024),
+ MakeUintegerAccessor (&PacketSocketClient::m_size),
+ MakeUintegerChecker ())
+ .AddTraceSource ("Tx", "A packet has been sent",
+ MakeTraceSourceAccessor (&PacketSocketClient::m_txTrace))
+ ;
+ return tid;
+}
+
+PacketSocketClient::PacketSocketClient ()
+{
+ NS_LOG_FUNCTION (this);
+ m_sent = 0;
+ m_socket = 0;
+ m_sendEvent = EventId ();
+ m_peerAddressSet = false;
+}
+
+PacketSocketClient::~PacketSocketClient ()
+{
+ NS_LOG_FUNCTION (this);
+}
+
+void
+PacketSocketClient::SetRemote (PacketSocketAddress addr)
+{
+ NS_LOG_FUNCTION (this << addr);
+ m_peerAddress = addr;
+ m_peerAddressSet = true;
+}
+
+void
+PacketSocketClient::DoDispose (void)
+{
+ NS_LOG_FUNCTION (this);
+ Application::DoDispose ();
+}
+
+void
+PacketSocketClient::StartApplication (void)
+{
+ NS_LOG_FUNCTION (this);
+ NS_ASSERT_MSG (m_peerAddressSet, "Peer address not set");
+
+ if (m_socket == 0)
+ {
+ TypeId tid = TypeId::LookupByName ("ns3::PacketSocketFactory");
+ m_socket = Socket::CreateSocket (GetNode (), tid);
+
+ m_socket->Bind (m_peerAddress);
+ m_socket->Connect (m_peerAddress);
+ }
+
+ m_socket->SetRecvCallback (MakeNullCallback > ());
+ m_sendEvent = Simulator::ScheduleNow (&PacketSocketClient::Send, this);
+}
+
+void
+PacketSocketClient::StopApplication (void)
+{
+ NS_LOG_FUNCTION (this);
+ Simulator::Cancel (m_sendEvent);
+ m_socket->Close ();
+}
+
+void
+PacketSocketClient::Send (void)
+{
+ NS_LOG_FUNCTION (this);
+ NS_ASSERT (m_sendEvent.IsExpired ());
+
+ Ptr p = Create (m_size);
+
+ std::stringstream peerAddressStringStream;
+ peerAddressStringStream << PacketSocketAddress::ConvertFrom (m_peerAddress);
+
+ if ((m_socket->Send (p)) >= 0)
+ {
+ NS_LOG_INFO ("TraceDelay TX " << m_size << " bytes to "
+ << peerAddressStringStream.str () << " Uid: "
+ << p->GetUid () << " Time: "
+ << (Simulator::Now ()).GetSeconds ());
+ }
+ else
+ {
+ NS_LOG_INFO ("Error while sending " << m_size << " bytes to "
+ << peerAddressStringStream.str ());
+ }
+ m_sent++;
+
+ if ((m_sent < m_maxPackets) || (m_maxPackets == 0))
+ {
+ m_txTrace (p, m_peerAddress);
+ m_sendEvent = Simulator::Schedule (m_interval, &PacketSocketClient::Send, this);
+ }
+}
+
+} // Namespace ns3
diff --git a/src/network/utils/packet-socket-client.h b/src/network/utils/packet-socket-client.h
new file mode 100644
index 000000000..f4be95f43
--- /dev/null
+++ b/src/network/utils/packet-socket-client.h
@@ -0,0 +1,100 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014 Universita' di Firenze
+ *
+ * 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
+ *
+ * Author: Tommaso Pecorella
+ */
+
+#ifndef PACKET_SOCKET_CLIENT_H
+#define PACKET_SOCKET_CLIENT_H
+
+#include "ns3/application.h"
+#include "ns3/event-id.h"
+#include "ns3/ptr.h"
+#include "ns3/packet-socket-address.h"
+
+namespace ns3 {
+
+class Socket;
+class Packet;
+
+/**
+ * \ingroup socket
+ *
+ * \brief A simple client.
+ *
+ * Sends packets using PacketSocket. It does not require (or use) IP.
+ *
+ * Packets are sent as soon as PacketSocketClient::Start is called.
+ * The application has the same requirements as the PacketSocket for
+ * what concerns the underlying NetDevice and the Address scheme.
+ * It is meant to be used in ns-3 tests.
+ *
+ * The application will send `MaxPackets' packets, one every `Interval'
+ * time. Packet size (`PacketSize') can be configured.
+ * Provides a "Tx" Traced Callback (transmitted packets, source address).
+ *
+ * Note: packets larger than the NetDevice MTU will not be sent.
+ */
+class PacketSocketClient : public Application
+{
+public:
+ /**
+ * \brief Get the type ID.
+ * \return the object TypeId
+ */
+ static TypeId GetTypeId (void);
+
+ PacketSocketClient ();
+
+ virtual ~PacketSocketClient ();
+
+ /**
+ * \brief set the remote address and protocol to be used
+ * \param addr remote address
+ */
+ void SetRemote (PacketSocketAddress addr);
+
+protected:
+ virtual void DoDispose (void);
+
+private:
+
+ virtual void StartApplication (void);
+ virtual void StopApplication (void);
+
+ /**
+ * \brief Send a packet
+ */
+ void Send (void);
+
+ uint32_t m_maxPackets; //!< Maximum number of packets the application will send
+ Time m_interval; //!< Packet inter-send time
+ uint32_t m_size; //!< Size of the sent packet
+
+ uint32_t m_sent; //!< Counter for sent packets
+ Ptr m_socket; //!< Socket
+ PacketSocketAddress m_peerAddress; //!< Remote peer address
+ bool m_peerAddressSet; //!< Sanity check
+ EventId m_sendEvent; //!< Event to send the next packet
+
+ /// Traced Callback: sent packets, source address.
+ TracedCallback, const Address &> m_txTrace;
+};
+
+} // namespace ns3
+
+#endif /* PACKET_SOCKET_CLIENT_H */
diff --git a/src/network/utils/packet-socket-server.cc b/src/network/utils/packet-socket-server.cc
new file mode 100644
index 000000000..9127cf04b
--- /dev/null
+++ b/src/network/utils/packet-socket-server.cc
@@ -0,0 +1,129 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014 Universita' di Firenze
+ *
+ * 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
+ *
+ * Author: Tommaso Pecorella
+ */
+
+#include "ns3/log.h"
+#include "ns3/nstime.h"
+#include "ns3/packet-socket-address.h"
+#include "ns3/packet-socket.h"
+#include "ns3/packet-socket-factory.h"
+#include "ns3/socket.h"
+#include "ns3/simulator.h"
+#include "ns3/socket-factory.h"
+#include "ns3/packet.h"
+#include "ns3/uinteger.h"
+#include "ns3/abort.h"
+#include "packet-socket-server.h"
+#include
+#include
+
+namespace ns3 {
+
+NS_LOG_COMPONENT_DEFINE ("PacketSocketServer");
+NS_OBJECT_ENSURE_REGISTERED (PacketSocketServer);
+
+TypeId
+PacketSocketServer::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::PacketSocketServer")
+ .SetParent ()
+ .AddConstructor ()
+ .AddTraceSource ("Rx", "A packet has been received",
+ MakeTraceSourceAccessor (&PacketSocketServer::m_rxTrace))
+ ;
+ return tid;
+}
+
+PacketSocketServer::PacketSocketServer ()
+{
+ NS_LOG_FUNCTION (this);
+ m_pktRx = 0;
+ m_bytesRx = 0;
+ m_socket = 0;
+ m_localAddressSet = false;
+}
+
+PacketSocketServer::~PacketSocketServer ()
+{
+ NS_LOG_FUNCTION (this);
+}
+
+void
+PacketSocketServer::DoDispose (void)
+{
+ NS_LOG_FUNCTION (this);
+ Application::DoDispose ();
+}
+
+void
+PacketSocketServer::StartApplication (void)
+{
+ NS_LOG_FUNCTION (this);
+ NS_ASSERT_MSG (m_localAddressSet, "Local address not set");
+
+ if (m_socket == 0)
+ {
+ TypeId tid = TypeId::LookupByName ("ns3::PacketSocketFactory");
+ m_socket = Socket::CreateSocket (GetNode (), tid);
+ m_socket->Bind (m_localAddress);
+ }
+
+ m_socket->SetRecvCallback (MakeCallback (&PacketSocketServer::HandleRead, this));
+}
+
+void
+PacketSocketServer::StopApplication (void)
+{
+ NS_LOG_FUNCTION (this);
+ m_socket->SetRecvCallback (MakeNullCallback > ());
+ m_socket->Close ();
+}
+
+void
+PacketSocketServer::SetLocal (PacketSocketAddress addr)
+{
+ NS_LOG_FUNCTION (this << addr);
+ m_localAddress = addr;
+ m_localAddressSet = true;
+}
+
+void
+PacketSocketServer::HandleRead (Ptr socket)
+{
+ NS_LOG_FUNCTION (this << socket);
+ Ptr packet;
+ Address from;
+ while ((packet = socket->RecvFrom (from)))
+ {
+ if (PacketSocketAddress::IsMatchingType (from))
+ {
+ m_pktRx ++;
+ m_bytesRx += packet->GetSize ();
+ NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds ()
+ << "s packet sink received "
+ << packet->GetSize () << " bytes from "
+ << PacketSocketAddress::ConvertFrom (from)
+ << " total Rx " << m_pktRx << " packets"
+ << " and " << m_bytesRx << " bytes");
+ m_rxTrace (packet, from);
+ }
+ }
+}
+
+} // Namespace ns3
diff --git a/src/network/utils/packet-socket-server.h b/src/network/utils/packet-socket-server.h
new file mode 100644
index 000000000..691d83fb8
--- /dev/null
+++ b/src/network/utils/packet-socket-server.h
@@ -0,0 +1,92 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014 Universita' di Firenze
+ *
+ * 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
+ *
+ * Author: Tommaso Pecorella
+ */
+
+#ifndef PACKET_SOCKET_SERVER_H
+#define PACKET_SOCKET_SERVER_H
+
+#include "ns3/application.h"
+#include "ns3/event-id.h"
+#include "ns3/ptr.h"
+#include "ns3/packet-socket-address.h"
+
+namespace ns3 {
+
+class Socket;
+class Packet;
+
+/**
+ * \ingroup socket
+ *
+ * \brief A server using PacketSocket.
+ *
+ * Receives packets using PacketSocket. It does not require (or use) IP.
+ * The application has the same requirements as the PacketSocket for
+ * what concerns the underlying NetDevice and the Address scheme.
+ * It is meant to be used in ns-3 tests.
+ *
+ * Provides a "Rx" Traced Callback (received packets, source address)
+ */
+class PacketSocketServer : public Application
+{
+public:
+ /**
+ * \brief Get the type ID.
+ * \return the object TypeId
+ */
+ static TypeId GetTypeId (void);
+
+ PacketSocketServer ();
+
+ virtual ~PacketSocketServer ();
+
+ /**
+ * \brief set the local address and protocol to be used
+ * \param addr local address
+ */
+ void SetLocal (PacketSocketAddress addr);
+
+protected:
+ virtual void DoDispose (void);
+
+private:
+
+ virtual void StartApplication (void);
+ virtual void StopApplication (void);
+
+ /**
+ * \brief Handle a packet received by the application
+ * \param socket the receiving socket
+ */
+ void HandleRead (Ptr socket);
+
+ uint32_t m_pktRx; //!< The number of received packets
+ uint32_t m_bytesRx; //!< Total bytes received
+
+ Ptr m_socket; //!< Socket
+ PacketSocketAddress m_localAddress; //!< Local address
+ bool m_localAddressSet; //!< Sanity check
+
+ /// Traced Callback: received packets, source address.
+ TracedCallback, const Address &> m_rxTrace;
+};
+
+} // namespace ns3
+
+#endif /* PACKET_SOCKET_SERVER_H */
diff --git a/src/network/wscript b/src/network/wscript
index e406b266d..ebd9e8b2c 100644
--- a/src/network/wscript
+++ b/src/network/wscript
@@ -53,6 +53,8 @@ def build(bld):
'utils/red-queue.cc',
'utils/simple-channel.cc',
'utils/simple-net-device.cc',
+ 'utils/packet-socket-client.cc',
+ 'utils/packet-socket-server.cc',
'utils/packet-data-calculators.cc',
'utils/packet-probe.cc',
'helper/application-container.cc',
@@ -76,6 +78,7 @@ def build(bld):
'test/pcap-file-test-suite.cc',
'test/red-queue-test-suite.cc',
'test/sequence-number-test-suite.cc',
+ 'test/packet-socket-apps-test-suite.cc',
]
headers = bld(features='ns3header')
@@ -135,6 +138,8 @@ def build(bld):
'utils/sgi-hashmap.h',
'utils/simple-channel.h',
'utils/simple-net-device.h',
+ 'utils/packet-socket-client.h',
+ 'utils/packet-socket-server.h',
'utils/pcap-test.h',
'utils/packet-data-calculators.h',
'utils/packet-probe.h',
diff --git a/src/spectrum/test/spectrum-ideal-phy-test.cc b/src/spectrum/test/spectrum-ideal-phy-test.cc
index 04d0dacf2..e08aecf08 100644
--- a/src/spectrum/test/spectrum-ideal-phy-test.cc
+++ b/src/spectrum/test/spectrum-ideal-phy-test.cc
@@ -46,7 +46,7 @@
#include
#include
#include
-#include
+#include
#include
@@ -179,13 +179,14 @@ SpectrumIdealPhyTestCase::DoRun (void)
socket.SetPhysicalAddress (devices.Get (1)->GetAddress ());
socket.SetProtocol (1);
- OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
- onoff.SetConstantRate (DataRate (static_cast (1.2*phyRate)));
- onoff.SetAttribute ("PacketSize", UintegerValue (pktSize));
-
- ApplicationContainer apps = onoff.Install (c.Get (0));
- apps.Start (Seconds (0.0));
- apps.Stop (Seconds (testDuration));
+ Ptr client = CreateObject ();
+ client->SetRemote (socket);
+ client->SetAttribute ("Interval", TimeValue (Seconds (double (pktSize*8) / (1.2*double (phyRate)))));
+ client->SetAttribute ("PacketSize", UintegerValue (pktSize));
+ client->SetAttribute ("MaxPackets", UintegerValue (0));
+ client->SetStartTime(Seconds (0.0));
+ client->SetStopTime(Seconds (testDuration));
+ c.Get (0)->AddApplication (client);
Config::Connect ("/NodeList/*/DeviceList/*/Phy/RxEndOk", MakeCallback (&PhyRxEndOkTrace));
diff --git a/src/spectrum/wscript b/src/spectrum/wscript
index be7b5e322..211fdef3e 100644
--- a/src/spectrum/wscript
+++ b/src/spectrum/wscript
@@ -2,7 +2,7 @@
def build(bld):
- module = bld.create_ns3_module('spectrum', ['propagation', 'antenna', 'applications'])
+ module = bld.create_ns3_module('spectrum', ['propagation', 'antenna'])
module.source = [
'model/spectrum-model.cc',
'model/spectrum-value.cc',
diff --git a/src/wave/test/ocb-test-suite.cc b/src/wave/test/ocb-test-suite.cc
index 3a18ae847..4fd28c336 100644
--- a/src/wave/test/ocb-test-suite.cc
+++ b/src/wave/test/ocb-test-suite.cc
@@ -26,13 +26,14 @@
#include "ns3/ssid.h"
#include "ns3/packet-socket-address.h"
#include "ns3/mobility-model.h"
-#include "ns3/on-off-helper.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/position-allocator.h"
#include "ns3/packet-socket-helper.h"
#include "ns3/mobility-helper.h"
#include "ns3/nqos-wifi-mac-helper.h"
#include "ns3/wifi-net-device.h"
+#include "ns3/packet-socket-server.h"
+#include "ns3/packet-socket-client.h"
#include
#include "ns3/ocb-wifi-mac.h"
@@ -282,11 +283,17 @@ OcbWifiMacTestCase::PostDeviceConfiguration (Ptr static_node, Ptr mo
packetSocket.Install (static_node);
packetSocket.Install (mobile_node);
- OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
- onoff.SetConstantRate (DataRate ("500kb/s"));
- ApplicationContainer apps = onoff.Install (mobile_node);
- apps.Start (Seconds (0.5));
- apps.Stop (Seconds (70.0));
+ Ptr client = CreateObject ();
+ client->SetRemote (socket);
+ mobile_node->AddApplication (client);
+ client->SetStartTime (Seconds (0.5));
+ client->SetStopTime (Seconds (70.0));
+
+ Ptr server = CreateObject ();
+ server->SetLocal (socket);
+ static_node->AddApplication (server);
+ server->SetStartTime (Seconds (0.0));
+ server->SetStopTime (Seconds (70.5));
phytx_time = macassoc_time = phyrx_time = Time ();
phytx_pos = macassoc_pos = phyrx_pos = Vector ();
diff --git a/src/wave/wscript b/src/wave/wscript
index 17f1d4ae5..64718e18e 100644
--- a/src/wave/wscript
+++ b/src/wave/wscript
@@ -7,7 +7,7 @@
# conf.check_nonfatal(header_name='stdint.h', define_name='HAVE_STDINT_H')
def build(bld):
- module = bld.create_ns3_module('wave', ['core','wifi', 'applications'])
+ module = bld.create_ns3_module('wave', ['core', 'wifi'])
module.source = [
'model/wave-mac-low.cc',
'model/ocb-wifi-mac.cc',