make OnOffApplication not depend on IUdp

Mathieu Lacage 2007-05-14 12:59:44 +02:00
parent ec9215fbc1
commit 109139b07f
11 changed files with 122 additions and 19 deletions

View File

@ -207,6 +207,7 @@ node.add_sources ([
'channel.cc',
'node-list.cc',
'socket.cc',
'i-socket-factory.cc',
'i-udp.cc',
'i-ipv4.cc',
'application.cc',
@ -223,6 +224,7 @@ node.add_inst_headers ([
'channel.h',
'node-list.h',
'socket.h',
'i-socket-factory.h',
'i-udp.h',
'i-ipv4.h',
'application.h',
@ -263,7 +265,7 @@ inode.add_sources ([
'header-utils.cc',
'udp-socket.cc',
'ipv4-end-point-demux.cc',
'i-udp-impl.cc',
'i-udp-socket-factory-impl.cc',
'i-arp-private.cc',
'i-ipv4-impl.cc',
'i-ipv4-private.cc',
@ -283,7 +285,7 @@ inode.add_headers ([
'queue.h',
'arp-ipv4-interface.h',
'udp-socket.h',
'i-udp-impl.h',
'i-udp-socket-factory-impl.h',
'udp.h',
'i-arp-private.h',
'i-ipv4-impl.h',

View File

@ -149,6 +149,7 @@ int main (int argc, char *argv[])
n0,
Ipv4Address("10.1.3.2"),
80,
"IUdp",
ConstantVariable(1),
ConstantVariable(0));
// Start the application
@ -160,6 +161,7 @@ int main (int argc, char *argv[])
n3,
Ipv4Address("10.1.2.1"),
80,
"IUdp",
ConstantVariable(1),
ConstantVariable(0));
// Start the application

View File

@ -2,7 +2,7 @@
#include "ns3/internet-node.h"
#include "ns3/simulator.h"
#include "ns3/i-udp.h"
#include "ns3/i-socket-factory.h"
#include "ns3/socket.h"
#include "ns3/nstime.h"
@ -40,12 +40,13 @@ RunSimulation (void)
{
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);
Ptr<Socket> source = udp->CreateSocket ();
Ptr<Socket> source = socketFactory->CreateSocket ();
source->Connect (Ipv4Address::GetLoopback (), 80);
GenerateTraffic (source, 500);

View File

@ -29,7 +29,7 @@
#include "ns3/random-variable.h"
#include "ns3/socket.h"
#include "ns3/simulator.h"
#include "ns3/i-udp.h"
#include "ns3/i-socket-factory.h"
#include "ns3/default-value.h"
#include "onoff-application.h"
@ -48,19 +48,22 @@ static IntegerDefaultValue<uint32_t> g_defaultSize ("OnOffApplicationPacketSize"
OnOffApplication::OnOffApplication(Ptr<INode> n,
const Ipv4Address rip,
uint16_t rport,
uint16_t rport,
std::string iid,
const RandomVariable& ontime,
const RandomVariable& offtime)
: Application(n),
m_cbrRate (g_defaultRate.GetValue ())
{
Construct (n, rip, rport, ontime, offtime,
Construct (n, rip, rport, iid,
ontime, offtime,
g_defaultSize.GetValue ());
}
OnOffApplication::OnOffApplication(Ptr<INode> n,
const Ipv4Address rip,
uint16_t rport,
uint16_t rport,
std::string iid,
const RandomVariable& ontime,
const RandomVariable& offtime,
DataRate rate,
@ -68,13 +71,15 @@ OnOffApplication::OnOffApplication(Ptr<INode> n,
: Application(n),
m_cbrRate (rate)
{
Construct (n, rip, rport, ontime, offtime, size);
Construct (n, rip, rport, iid,
ontime, offtime, size);
}
void
OnOffApplication::Construct (Ptr<INode> n,
const Ipv4Address rip,
uint16_t rport,
uint16_t rport,
std::string iid,
const RandomVariable& onTime,
const RandomVariable& offTime,
uint32_t size)
@ -90,6 +95,7 @@ OnOffApplication::Construct (Ptr<INode> n,
m_lastStartTime = Seconds (0);
m_maxBytes = 0xffffffff;
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
if (!m_socket)
{
Ptr<IUdp> udp = GetINode ()->QueryInterface<IUdp> (IUdp::iid);
m_socket = udp->CreateSocket ();
InterfaceId iid = InterfaceId::LookupByName (m_iid);
Ptr<ISocketFactory> socketFactory = GetINode ()->QueryInterface<ISocketFactory> (iid);
m_socket = socketFactory->CreateSocket ();
m_socket->Bind ();
m_socket->Connect (m_peerIp, m_peerPort);
}

View File

@ -60,6 +60,7 @@ public:
OnOffApplication(Ptr<INode> n,
const Ipv4Address rip,
uint16_t rport,
std::string iid,
const RandomVariable& ontime,
const RandomVariable& offtime);
@ -75,6 +76,7 @@ public:
OnOffApplication(Ptr<INode> n,
const Ipv4Address rip,
uint16_t rport,
std::string iid,
const RandomVariable& ontime,
const RandomVariable& offtime,
DataRate rate,
@ -110,6 +112,7 @@ private:
void Construct (Ptr<INode> n,
const Ipv4Address rip,
uint16_t rport,
std::string iid,
const RandomVariable& ontime,
const RandomVariable& offtime,
uint32_t size);
@ -135,6 +138,7 @@ private:
EventId m_startStopEvent; // Event id for next start or stop event
EventId m_sendEvent; // Eventid of pending "send packet" event
bool m_sending; // True if currently in sending state
std::string m_iid;
private:
void ScheduleNextTx();

View File

@ -38,6 +38,16 @@ InterfaceId::InterfaceId (std::string 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)
{
return a.m_iid == b.m_iid;

View File

@ -32,7 +32,9 @@ class InterfaceId
{
public:
InterfaceId (std::string name);
static InterfaceId LookupByName (std::string);
private:
InterfaceId (uint32_t iid);
friend bool operator == (const InterfaceId &a, const InterfaceId &b);
uint32_t m_iid;
};

View File

@ -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

View File

@ -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 */

View File

@ -25,7 +25,8 @@ namespace ns3 {
const InterfaceId IUdp::iid ("IUdp");
IUdp::IUdp ()
: Interface (IUdp::iid)
{}
{
AddSelfInterface (IUdp::iid, this);
}
} // namespace ns3

View File

@ -21,14 +21,13 @@
#ifndef I_UDP_H
#define I_UDP_H
#include "ns3/interface.h"
#include "ns3/ptr.h"
#include "i-socket-factory.h"
namespace ns3 {
class Socket;
class IUdp : public Interface
class IUdp : public ISocketFactory
{
public:
static const InterfaceId iid;