make OnOffApplication not depend on IUdp
parent
ec9215fbc1
commit
109139b07f
|
@ -207,6 +207,7 @@ node.add_sources ([
|
||||||
'channel.cc',
|
'channel.cc',
|
||||||
'node-list.cc',
|
'node-list.cc',
|
||||||
'socket.cc',
|
'socket.cc',
|
||||||
|
'i-socket-factory.cc',
|
||||||
'i-udp.cc',
|
'i-udp.cc',
|
||||||
'i-ipv4.cc',
|
'i-ipv4.cc',
|
||||||
'application.cc',
|
'application.cc',
|
||||||
|
@ -223,6 +224,7 @@ node.add_inst_headers ([
|
||||||
'channel.h',
|
'channel.h',
|
||||||
'node-list.h',
|
'node-list.h',
|
||||||
'socket.h',
|
'socket.h',
|
||||||
|
'i-socket-factory.h',
|
||||||
'i-udp.h',
|
'i-udp.h',
|
||||||
'i-ipv4.h',
|
'i-ipv4.h',
|
||||||
'application.h',
|
'application.h',
|
||||||
|
@ -263,7 +265,7 @@ inode.add_sources ([
|
||||||
'header-utils.cc',
|
'header-utils.cc',
|
||||||
'udp-socket.cc',
|
'udp-socket.cc',
|
||||||
'ipv4-end-point-demux.cc',
|
'ipv4-end-point-demux.cc',
|
||||||
'i-udp-impl.cc',
|
'i-udp-socket-factory-impl.cc',
|
||||||
'i-arp-private.cc',
|
'i-arp-private.cc',
|
||||||
'i-ipv4-impl.cc',
|
'i-ipv4-impl.cc',
|
||||||
'i-ipv4-private.cc',
|
'i-ipv4-private.cc',
|
||||||
|
@ -283,7 +285,7 @@ inode.add_headers ([
|
||||||
'queue.h',
|
'queue.h',
|
||||||
'arp-ipv4-interface.h',
|
'arp-ipv4-interface.h',
|
||||||
'udp-socket.h',
|
'udp-socket.h',
|
||||||
'i-udp-impl.h',
|
'i-udp-socket-factory-impl.h',
|
||||||
'udp.h',
|
'udp.h',
|
||||||
'i-arp-private.h',
|
'i-arp-private.h',
|
||||||
'i-ipv4-impl.h',
|
'i-ipv4-impl.h',
|
||||||
|
|
|
@ -149,6 +149,7 @@ int main (int argc, char *argv[])
|
||||||
n0,
|
n0,
|
||||||
Ipv4Address("10.1.3.2"),
|
Ipv4Address("10.1.3.2"),
|
||||||
80,
|
80,
|
||||||
|
"IUdp",
|
||||||
ConstantVariable(1),
|
ConstantVariable(1),
|
||||||
ConstantVariable(0));
|
ConstantVariable(0));
|
||||||
// Start the application
|
// Start the application
|
||||||
|
@ -160,6 +161,7 @@ int main (int argc, char *argv[])
|
||||||
n3,
|
n3,
|
||||||
Ipv4Address("10.1.2.1"),
|
Ipv4Address("10.1.2.1"),
|
||||||
80,
|
80,
|
||||||
|
"IUdp",
|
||||||
ConstantVariable(1),
|
ConstantVariable(1),
|
||||||
ConstantVariable(0));
|
ConstantVariable(0));
|
||||||
// Start the application
|
// Start the application
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "ns3/internet-node.h"
|
#include "ns3/internet-node.h"
|
||||||
#include "ns3/simulator.h"
|
#include "ns3/simulator.h"
|
||||||
#include "ns3/i-udp.h"
|
#include "ns3/i-socket-factory.h"
|
||||||
#include "ns3/socket.h"
|
#include "ns3/socket.h"
|
||||||
#include "ns3/nstime.h"
|
#include "ns3/nstime.h"
|
||||||
|
|
||||||
|
@ -40,12 +40,13 @@ RunSimulation (void)
|
||||||
{
|
{
|
||||||
Ptr<INode> a = MakeInternetNode ();
|
Ptr<INode> a = MakeInternetNode ();
|
||||||
|
|
||||||
Ptr<IUdp> udp = a->QueryInterface<IUdp> (IUdp::iid);
|
InterfaceId iid = InterfaceId::LookupByName ("IUdp");
|
||||||
|
Ptr<ISocketFactory> socketFactory = a->QueryInterface<ISocketFactory> (iid);
|
||||||
|
|
||||||
Ptr<Socket> sink = udp->CreateSocket ();
|
Ptr<Socket> sink = socketFactory->CreateSocket ();
|
||||||
sink->Bind (80);
|
sink->Bind (80);
|
||||||
|
|
||||||
Ptr<Socket> source = udp->CreateSocket ();
|
Ptr<Socket> source = socketFactory->CreateSocket ();
|
||||||
source->Connect (Ipv4Address::GetLoopback (), 80);
|
source->Connect (Ipv4Address::GetLoopback (), 80);
|
||||||
|
|
||||||
GenerateTraffic (source, 500);
|
GenerateTraffic (source, 500);
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include "ns3/random-variable.h"
|
#include "ns3/random-variable.h"
|
||||||
#include "ns3/socket.h"
|
#include "ns3/socket.h"
|
||||||
#include "ns3/simulator.h"
|
#include "ns3/simulator.h"
|
||||||
#include "ns3/i-udp.h"
|
#include "ns3/i-socket-factory.h"
|
||||||
#include "ns3/default-value.h"
|
#include "ns3/default-value.h"
|
||||||
#include "onoff-application.h"
|
#include "onoff-application.h"
|
||||||
|
|
||||||
|
@ -48,19 +48,22 @@ static IntegerDefaultValue<uint32_t> g_defaultSize ("OnOffApplicationPacketSize"
|
||||||
|
|
||||||
OnOffApplication::OnOffApplication(Ptr<INode> n,
|
OnOffApplication::OnOffApplication(Ptr<INode> n,
|
||||||
const Ipv4Address rip,
|
const Ipv4Address rip,
|
||||||
uint16_t rport,
|
uint16_t rport,
|
||||||
|
std::string iid,
|
||||||
const RandomVariable& ontime,
|
const RandomVariable& ontime,
|
||||||
const RandomVariable& offtime)
|
const RandomVariable& offtime)
|
||||||
: Application(n),
|
: Application(n),
|
||||||
m_cbrRate (g_defaultRate.GetValue ())
|
m_cbrRate (g_defaultRate.GetValue ())
|
||||||
{
|
{
|
||||||
Construct (n, rip, rport, ontime, offtime,
|
Construct (n, rip, rport, iid,
|
||||||
|
ontime, offtime,
|
||||||
g_defaultSize.GetValue ());
|
g_defaultSize.GetValue ());
|
||||||
}
|
}
|
||||||
|
|
||||||
OnOffApplication::OnOffApplication(Ptr<INode> n,
|
OnOffApplication::OnOffApplication(Ptr<INode> n,
|
||||||
const Ipv4Address rip,
|
const Ipv4Address rip,
|
||||||
uint16_t rport,
|
uint16_t rport,
|
||||||
|
std::string iid,
|
||||||
const RandomVariable& ontime,
|
const RandomVariable& ontime,
|
||||||
const RandomVariable& offtime,
|
const RandomVariable& offtime,
|
||||||
DataRate rate,
|
DataRate rate,
|
||||||
|
@ -68,13 +71,15 @@ OnOffApplication::OnOffApplication(Ptr<INode> n,
|
||||||
: Application(n),
|
: Application(n),
|
||||||
m_cbrRate (rate)
|
m_cbrRate (rate)
|
||||||
{
|
{
|
||||||
Construct (n, rip, rport, ontime, offtime, size);
|
Construct (n, rip, rport, iid,
|
||||||
|
ontime, offtime, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
OnOffApplication::Construct (Ptr<INode> n,
|
OnOffApplication::Construct (Ptr<INode> n,
|
||||||
const Ipv4Address rip,
|
const Ipv4Address rip,
|
||||||
uint16_t rport,
|
uint16_t rport,
|
||||||
|
std::string iid,
|
||||||
const RandomVariable& onTime,
|
const RandomVariable& onTime,
|
||||||
const RandomVariable& offTime,
|
const RandomVariable& offTime,
|
||||||
uint32_t size)
|
uint32_t size)
|
||||||
|
@ -90,6 +95,7 @@ OnOffApplication::Construct (Ptr<INode> n,
|
||||||
m_lastStartTime = Seconds (0);
|
m_lastStartTime = Seconds (0);
|
||||||
m_maxBytes = 0xffffffff;
|
m_maxBytes = 0xffffffff;
|
||||||
m_totBytes = 0;
|
m_totBytes = 0;
|
||||||
|
m_iid = iid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,8 +140,9 @@ void OnOffApplication::StartApplication() // Called at time specified by Star
|
||||||
// Create the socket if not already
|
// Create the socket if not already
|
||||||
if (!m_socket)
|
if (!m_socket)
|
||||||
{
|
{
|
||||||
Ptr<IUdp> udp = GetINode ()->QueryInterface<IUdp> (IUdp::iid);
|
InterfaceId iid = InterfaceId::LookupByName (m_iid);
|
||||||
m_socket = udp->CreateSocket ();
|
Ptr<ISocketFactory> socketFactory = GetINode ()->QueryInterface<ISocketFactory> (iid);
|
||||||
|
m_socket = socketFactory->CreateSocket ();
|
||||||
m_socket->Bind ();
|
m_socket->Bind ();
|
||||||
m_socket->Connect (m_peerIp, m_peerPort);
|
m_socket->Connect (m_peerIp, m_peerPort);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ public:
|
||||||
OnOffApplication(Ptr<INode> n,
|
OnOffApplication(Ptr<INode> n,
|
||||||
const Ipv4Address rip,
|
const Ipv4Address rip,
|
||||||
uint16_t rport,
|
uint16_t rport,
|
||||||
|
std::string iid,
|
||||||
const RandomVariable& ontime,
|
const RandomVariable& ontime,
|
||||||
const RandomVariable& offtime);
|
const RandomVariable& offtime);
|
||||||
|
|
||||||
|
@ -75,6 +76,7 @@ public:
|
||||||
OnOffApplication(Ptr<INode> n,
|
OnOffApplication(Ptr<INode> n,
|
||||||
const Ipv4Address rip,
|
const Ipv4Address rip,
|
||||||
uint16_t rport,
|
uint16_t rport,
|
||||||
|
std::string iid,
|
||||||
const RandomVariable& ontime,
|
const RandomVariable& ontime,
|
||||||
const RandomVariable& offtime,
|
const RandomVariable& offtime,
|
||||||
DataRate rate,
|
DataRate rate,
|
||||||
|
@ -110,6 +112,7 @@ private:
|
||||||
void Construct (Ptr<INode> n,
|
void Construct (Ptr<INode> n,
|
||||||
const Ipv4Address rip,
|
const Ipv4Address rip,
|
||||||
uint16_t rport,
|
uint16_t rport,
|
||||||
|
std::string iid,
|
||||||
const RandomVariable& ontime,
|
const RandomVariable& ontime,
|
||||||
const RandomVariable& offtime,
|
const RandomVariable& offtime,
|
||||||
uint32_t size);
|
uint32_t size);
|
||||||
|
@ -135,6 +138,7 @@ private:
|
||||||
EventId m_startStopEvent; // Event id for next start or stop event
|
EventId m_startStopEvent; // Event id for next start or stop event
|
||||||
EventId m_sendEvent; // Eventid of pending "send packet" event
|
EventId m_sendEvent; // Eventid of pending "send packet" event
|
||||||
bool m_sending; // True if currently in sending state
|
bool m_sending; // True if currently in sending state
|
||||||
|
std::string m_iid;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ScheduleNextTx();
|
void ScheduleNextTx();
|
||||||
|
|
|
@ -38,6 +38,16 @@ InterfaceId::InterfaceId (std::string name)
|
||||||
: m_iid (Singleton<IidManager>::Get ()->Allocate (name))
|
: m_iid (Singleton<IidManager>::Get ()->Allocate (name))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
InterfaceId::InterfaceId (uint32_t iid)
|
||||||
|
: m_iid (iid)
|
||||||
|
{}
|
||||||
|
|
||||||
|
InterfaceId
|
||||||
|
InterfaceId::LookupByName (std::string name)
|
||||||
|
{
|
||||||
|
return InterfaceId (Singleton<IidManager>::Get ()->LookupByName (name));
|
||||||
|
}
|
||||||
|
|
||||||
bool operator == (const InterfaceId &a, const InterfaceId &b)
|
bool operator == (const InterfaceId &a, const InterfaceId &b)
|
||||||
{
|
{
|
||||||
return a.m_iid == b.m_iid;
|
return a.m_iid == b.m_iid;
|
||||||
|
|
|
@ -32,7 +32,9 @@ class InterfaceId
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InterfaceId (std::string name);
|
InterfaceId (std::string name);
|
||||||
|
static InterfaceId LookupByName (std::string);
|
||||||
private:
|
private:
|
||||||
|
InterfaceId (uint32_t iid);
|
||||||
friend bool operator == (const InterfaceId &a, const InterfaceId &b);
|
friend bool operator == (const InterfaceId &a, const InterfaceId &b);
|
||||||
uint32_t m_iid;
|
uint32_t m_iid;
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 INRIA
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||||
|
*/
|
||||||
|
#include "i-socket-factory.h"
|
||||||
|
|
||||||
|
namespace ns3 {
|
||||||
|
|
||||||
|
const InterfaceId ISocketFactory::iid ("ISocketFactory");
|
||||||
|
|
||||||
|
ISocketFactory::ISocketFactory ()
|
||||||
|
: Interface (ISocketFactory::iid)
|
||||||
|
{}
|
||||||
|
|
||||||
|
} // namespace ns3
|
|
@ -0,0 +1,44 @@
|
||||||
|
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 INRIA
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||||
|
*/
|
||||||
|
#ifndef I_SOCKET_FACTORY_H
|
||||||
|
#define I_SOCKET_FACTORY_H
|
||||||
|
|
||||||
|
#include "ns3/interface.h"
|
||||||
|
#include "ns3/ptr.h"
|
||||||
|
|
||||||
|
namespace ns3 {
|
||||||
|
|
||||||
|
class Socket;
|
||||||
|
|
||||||
|
class ISocketFactory : public Interface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const InterfaceId iid;
|
||||||
|
|
||||||
|
ISocketFactory ();
|
||||||
|
|
||||||
|
virtual Ptr<Socket> CreateSocket (void) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace ns3
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* I_SOCKET_FACTORY_H */
|
|
@ -25,7 +25,8 @@ namespace ns3 {
|
||||||
const InterfaceId IUdp::iid ("IUdp");
|
const InterfaceId IUdp::iid ("IUdp");
|
||||||
|
|
||||||
IUdp::IUdp ()
|
IUdp::IUdp ()
|
||||||
: Interface (IUdp::iid)
|
{
|
||||||
{}
|
AddSelfInterface (IUdp::iid, this);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ns3
|
} // namespace ns3
|
||||||
|
|
|
@ -21,14 +21,13 @@
|
||||||
#ifndef I_UDP_H
|
#ifndef I_UDP_H
|
||||||
#define I_UDP_H
|
#define I_UDP_H
|
||||||
|
|
||||||
#include "ns3/interface.h"
|
#include "i-socket-factory.h"
|
||||||
#include "ns3/ptr.h"
|
|
||||||
|
|
||||||
namespace ns3 {
|
namespace ns3 {
|
||||||
|
|
||||||
class Socket;
|
class Socket;
|
||||||
|
|
||||||
class IUdp : public Interface
|
class IUdp : public ISocketFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static const InterfaceId iid;
|
static const InterfaceId iid;
|
||||||
|
|
Loading…
Reference in New Issue