Bug 1811 - Basic traffic generator for network module
This commit is contained in:
@@ -91,6 +91,8 @@ us a note on ns-developers mailing list.</p>
|
||||
</li>
|
||||
<li> A new SimpleNetDeviceHelper can now be used to install SimpleNetDevices.
|
||||
</li>
|
||||
<li> New PacketSocketServer and PacketSocketClient apps, meant to be used in tests.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>Changes to existing API:</h2>
|
||||
|
||||
@@ -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
|
||||
------------
|
||||
|
||||
|
||||
98
src/network/examples/packet-socket-apps.cc
Normal file
98
src/network/examples/packet-socket-apps.cc
Normal file
@@ -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 <tommaso.pecorella@unifi.it>
|
||||
*/
|
||||
|
||||
// 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<SimpleNetDevice> txDev;
|
||||
txDev = CreateObject<SimpleNetDevice> ();
|
||||
nodes.Get (0)->AddDevice (txDev);
|
||||
|
||||
Ptr<SimpleNetDevice> rxDev;
|
||||
rxDev = CreateObject<SimpleNetDevice> ();
|
||||
nodes.Get (1)->AddDevice (rxDev);
|
||||
|
||||
Ptr<SimpleChannel> channel = CreateObject<SimpleChannel> ();
|
||||
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<PacketSocketClient> client = CreateObject<PacketSocketClient> ();
|
||||
client->SetRemote (socketAddr);
|
||||
nodes.Get (0)->AddApplication (client);
|
||||
|
||||
Ptr<PacketSocketServer> server = CreateObject<PacketSocketServer> ();
|
||||
server->SetLocal (socketAddr);
|
||||
nodes.Get (1)->AddApplication (server);
|
||||
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
return 0;
|
||||
}
|
||||
@@ -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'
|
||||
|
||||
126
src/network/test/packet-socket-apps-test-suite.cc
Normal file
126
src/network/test/packet-socket-apps-test-suite.cc
Normal file
@@ -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 <tommaso.pecorella@unifi.it>
|
||||
*/
|
||||
|
||||
#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<const Packet> packet, const Address &from);
|
||||
};
|
||||
|
||||
PacketSocketAppsTest::PacketSocketAppsTest ()
|
||||
: TestCase ("Packet Socket Apps test")
|
||||
{
|
||||
m_receivedPacketSize = 0;
|
||||
m_receivedPacketNumber = 0;
|
||||
}
|
||||
|
||||
void PacketSocketAppsTest::ReceivePkt (Ptr<const Packet> 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<SimpleNetDevice> txDev;
|
||||
txDev = CreateObject<SimpleNetDevice> ();
|
||||
nodes.Get (0)->AddDevice (txDev);
|
||||
|
||||
Ptr<SimpleNetDevice> rxDev;
|
||||
rxDev = CreateObject<SimpleNetDevice> ();
|
||||
nodes.Get (1)->AddDevice (rxDev);
|
||||
|
||||
Ptr<SimpleChannel> channel = CreateObject<SimpleChannel> ();
|
||||
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<PacketSocketClient> client = CreateObject<PacketSocketClient> ();
|
||||
client->SetRemote (socketAddr);
|
||||
client->SetAttribute ("PacketSize", UintegerValue (1000));
|
||||
client->SetAttribute ("MaxPackets", UintegerValue (3));
|
||||
nodes.Get (0)->AddApplication (client);
|
||||
|
||||
Ptr<PacketSocketServer> server = CreateObject<PacketSocketServer> ();
|
||||
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;
|
||||
155
src/network/utils/packet-socket-client.cc
Normal file
155
src/network/utils/packet-socket-client.cc
Normal file
@@ -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 <tommaso.pecorella@unifi.it>
|
||||
*/
|
||||
|
||||
#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 <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("PacketSocketClient");
|
||||
NS_OBJECT_ENSURE_REGISTERED (PacketSocketClient);
|
||||
|
||||
TypeId
|
||||
PacketSocketClient::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::PacketSocketClient")
|
||||
.SetParent<Application> ()
|
||||
.AddConstructor<PacketSocketClient> ()
|
||||
.AddAttribute ("MaxPackets",
|
||||
"The maximum number of packets the application will send (zero means infinite)",
|
||||
UintegerValue (100),
|
||||
MakeUintegerAccessor (&PacketSocketClient::m_maxPackets),
|
||||
MakeUintegerChecker<uint32_t> ())
|
||||
.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<uint32_t> ())
|
||||
.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<void, Ptr<Socket> > ());
|
||||
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<Packet> p = Create<Packet> (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
|
||||
100
src/network/utils/packet-socket-client.h
Normal file
100
src/network/utils/packet-socket-client.h
Normal file
@@ -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 <tommaso.pecorella@unifi.it>
|
||||
*/
|
||||
|
||||
#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<Socket> 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<Ptr<const Packet>, const Address &> m_txTrace;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* PACKET_SOCKET_CLIENT_H */
|
||||
129
src/network/utils/packet-socket-server.cc
Normal file
129
src/network/utils/packet-socket-server.cc
Normal file
@@ -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 <tommaso.pecorella@unifi.it>
|
||||
*/
|
||||
|
||||
#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 <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("PacketSocketServer");
|
||||
NS_OBJECT_ENSURE_REGISTERED (PacketSocketServer);
|
||||
|
||||
TypeId
|
||||
PacketSocketServer::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::PacketSocketServer")
|
||||
.SetParent<Application> ()
|
||||
.AddConstructor<PacketSocketServer> ()
|
||||
.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<void, Ptr<Socket> > ());
|
||||
m_socket->Close ();
|
||||
}
|
||||
|
||||
void
|
||||
PacketSocketServer::SetLocal (PacketSocketAddress addr)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << addr);
|
||||
m_localAddress = addr;
|
||||
m_localAddressSet = true;
|
||||
}
|
||||
|
||||
void
|
||||
PacketSocketServer::HandleRead (Ptr<Socket> socket)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << socket);
|
||||
Ptr<Packet> 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
|
||||
92
src/network/utils/packet-socket-server.h
Normal file
92
src/network/utils/packet-socket-server.h
Normal file
@@ -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 <tommaso.pecorella@unifi.it>
|
||||
*/
|
||||
|
||||
#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> socket);
|
||||
|
||||
uint32_t m_pktRx; //!< The number of received packets
|
||||
uint32_t m_bytesRx; //!< Total bytes received
|
||||
|
||||
Ptr<Socket> m_socket; //!< Socket
|
||||
PacketSocketAddress m_localAddress; //!< Local address
|
||||
bool m_localAddressSet; //!< Sanity check
|
||||
|
||||
/// Traced Callback: received packets, source address.
|
||||
TracedCallback<Ptr<const Packet>, const Address &> m_rxTrace;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* PACKET_SOCKET_SERVER_H */
|
||||
@@ -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',
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include <ns3/uinteger.h>
|
||||
#include <ns3/packet-socket-helper.h>
|
||||
#include <ns3/packet-socket-address.h>
|
||||
#include <ns3/on-off-helper.h>
|
||||
#include <ns3/packet-socket-client.h>
|
||||
#include <ns3/config.h>
|
||||
|
||||
|
||||
@@ -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<uint64_t> (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<PacketSocketClient> client = CreateObject<PacketSocketClient> ();
|
||||
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));
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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 <iostream>
|
||||
|
||||
#include "ns3/ocb-wifi-mac.h"
|
||||
@@ -282,11 +283,17 @@ OcbWifiMacTestCase::PostDeviceConfiguration (Ptr<Node> static_node, Ptr<Node> 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<PacketSocketClient> client = CreateObject<PacketSocketClient> ();
|
||||
client->SetRemote (socket);
|
||||
mobile_node->AddApplication (client);
|
||||
client->SetStartTime (Seconds (0.5));
|
||||
client->SetStopTime (Seconds (70.0));
|
||||
|
||||
Ptr<PacketSocketServer> server = CreateObject<PacketSocketServer> ();
|
||||
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 ();
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user