merge
This commit is contained in:
113
src/node/application.cc
Normal file
113
src/node/application.cc
Normal file
@@ -0,0 +1,113 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2006 Georgia Tech Research Corporation
|
||||
*
|
||||
* 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: George F. Riley<riley@ece.gatech.edu>
|
||||
*/
|
||||
|
||||
// Implementation for ns3 Application base class.
|
||||
// George F. Riley, Georgia Tech, Fall 2006
|
||||
|
||||
#include "application.h"
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/random-variable.h"
|
||||
#include "ns3/simulator.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
// Application Methods
|
||||
|
||||
// \brief Application Constructor
|
||||
Application::Application(Ptr<Node> n)
|
||||
: m_node (n)
|
||||
{
|
||||
m_node->AddApplication (this);
|
||||
}
|
||||
|
||||
// \brief Application Destructor
|
||||
Application::~Application()
|
||||
{}
|
||||
|
||||
void
|
||||
Application::DoDispose (void)
|
||||
{
|
||||
m_node = 0;
|
||||
Simulator::Cancel(m_startEvent);
|
||||
Simulator::Cancel(m_stopEvent);
|
||||
}
|
||||
|
||||
void Application::Start(const Time& startTime)
|
||||
{
|
||||
ScheduleStart (startTime);
|
||||
}
|
||||
|
||||
void Application::Start(const RandomVariable& startVar)
|
||||
{
|
||||
RandomVariable *v = startVar.Copy ();
|
||||
ScheduleStart (Seconds (v->GetValue ()));
|
||||
delete v;
|
||||
}
|
||||
|
||||
|
||||
void Application::Stop(const Time& stopTime)
|
||||
{
|
||||
ScheduleStop (stopTime);
|
||||
}
|
||||
|
||||
void Application::Stop(const RandomVariable& stopVar)
|
||||
{
|
||||
RandomVariable *v = stopVar.Copy ();
|
||||
ScheduleStop (Seconds (v->GetValue ()));
|
||||
delete v;
|
||||
}
|
||||
|
||||
Ptr<Node> Application::GetNode() const
|
||||
{
|
||||
return m_node;
|
||||
}
|
||||
|
||||
// Protected methods
|
||||
// StartApp and StopApp will likely be overridden by application subclasses
|
||||
void Application::StartApplication()
|
||||
{ // Provide null functionality in case subclass is not interested
|
||||
}
|
||||
|
||||
void Application::StopApplication()
|
||||
{ // Provide null functionality in case subclass is not interested
|
||||
}
|
||||
|
||||
|
||||
// Private helpers
|
||||
void Application::ScheduleStart (const Time &startTime)
|
||||
{
|
||||
m_startEvent = Simulator::Schedule(startTime -
|
||||
Simulator::Now(),
|
||||
&Application::StartApplication, this);
|
||||
}
|
||||
|
||||
void Application::ScheduleStop (const Time &stopTime)
|
||||
{
|
||||
m_stopEvent = Simulator::Schedule(stopTime -
|
||||
Simulator::Now(),
|
||||
&Application::StopApplication, this);
|
||||
}
|
||||
|
||||
} //namespace ns3
|
||||
|
||||
|
||||
135
src/node/application.h
Normal file
135
src/node/application.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2006 Georgia Tech Research Corporation
|
||||
*
|
||||
* 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: George F. Riley<riley@ece.gatech.edu>
|
||||
*/
|
||||
|
||||
#ifndef __APPLICATION_H__
|
||||
#define __APPLICATION_H__
|
||||
|
||||
#include "ns3/event-id.h"
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/node.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Node;
|
||||
class RandomVariable;
|
||||
|
||||
/**
|
||||
* \brief The base class for all ns3 applicationes
|
||||
*
|
||||
* Class Application is the base class for all ns3 applications.
|
||||
* Applications are associated with individual nodes.
|
||||
*
|
||||
* Conceptually, an application has zero or more Socket
|
||||
* objects associated with it, that are created using the Socket
|
||||
* creation API of the Kernel capability. The Socket object
|
||||
* API is modeled after the
|
||||
* well-known BSD sockets interface, although it is somewhat
|
||||
* simplified for use with ns3. Further, any socket call that
|
||||
* would normally "block" in normal sockets will return immediately
|
||||
* in ns3. A set of "upcalls" are defined that will be called when
|
||||
* the previous blocking call would normally exit. THis is documented
|
||||
* in more detail Socket class in socket.h.
|
||||
*/
|
||||
class Application : public Object
|
||||
{
|
||||
public:
|
||||
Application(Ptr<Node>);
|
||||
virtual ~Application();
|
||||
|
||||
/**
|
||||
* \brief Specify application start time
|
||||
* \param startTime Start time for this application, absolute time,
|
||||
* relative to the start of the simulation.
|
||||
*
|
||||
* Applications start at various times in the simulation scenario.
|
||||
* The Start method specifies when the application should be
|
||||
* started. The application subclasses should override the
|
||||
* private "StartApplication" method defined below, which is called at the
|
||||
* time specified, to cause the application to begin.
|
||||
*/
|
||||
void Start(const Time& startTime);
|
||||
|
||||
/**
|
||||
* \brief Specify application start time.
|
||||
* \param startVariable the random variable to use to pick
|
||||
* the real start time as an absolute time, in units of
|
||||
* seconds, relative to the start of the simulation.
|
||||
*/
|
||||
void Start(const RandomVariable& startVariable);
|
||||
|
||||
/**
|
||||
* \brief Specify application stop time
|
||||
* \param stopTime Stop time for this application, relative to the
|
||||
* start of the simulation.
|
||||
*
|
||||
* Once an application has started, it is sometimes useful
|
||||
* to stop the application. The Stop method specifies when an
|
||||
* application is to stop. The application subclasses should override
|
||||
* the private StopApplication method, to be notified when that
|
||||
* time has come.
|
||||
*/
|
||||
void Stop(const Time& stopTime);
|
||||
|
||||
/**
|
||||
* \brief Specify application stop time
|
||||
* \param stopVariable the random variable to use to pick
|
||||
* the real stop time, in units of seconds,
|
||||
* relative to the start of the simulation.
|
||||
*/
|
||||
void Stop(const RandomVariable& stopVariable);
|
||||
|
||||
/**
|
||||
* \returns the Node to which this Application object is attached.
|
||||
*/
|
||||
Ptr<Node> GetNode() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* \brief Application specific startup code
|
||||
*
|
||||
* The StartApplication method is called at the start time specifed by Start
|
||||
* This method should be overridden by all or most application
|
||||
* subclasses.
|
||||
*/
|
||||
virtual void StartApplication (void);
|
||||
|
||||
/**
|
||||
* \brief Application specific shutdown code
|
||||
*
|
||||
* The StopApplication method is called at the stop time specifed by Stop
|
||||
* This method should be overridden by all or most application
|
||||
* subclasses.
|
||||
*/
|
||||
virtual void StopApplication (void);
|
||||
protected:
|
||||
virtual void DoDispose (void);
|
||||
private:
|
||||
void ScheduleStart (const Time &time);
|
||||
void ScheduleStop (const Time &time);
|
||||
|
||||
EventId m_startEvent;
|
||||
EventId m_stopEvent;
|
||||
Ptr<Node> m_node;
|
||||
};
|
||||
|
||||
} //namespace ns3
|
||||
#endif
|
||||
@@ -27,14 +27,18 @@ NS_DEBUG_COMPONENT_DEFINE ("Channel");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
const InterfaceId Channel::iid ("Channel");
|
||||
|
||||
Channel::Channel ()
|
||||
: m_name("Channel")
|
||||
: Interface (Channel::iid),
|
||||
m_name("Channel")
|
||||
{
|
||||
NS_DEBUG("Channel::Channel ()");
|
||||
}
|
||||
|
||||
Channel::Channel (std::string name)
|
||||
: m_name(name)
|
||||
: Interface (Channel::iid),
|
||||
m_name(name)
|
||||
{
|
||||
NS_DEBUG("Channel::Channel (" << name << ")");
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/interface.h"
|
||||
#include "ns3/ptr.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -36,9 +37,10 @@ class NetDevice;
|
||||
* A channel is a logical path over which information flows. The path can
|
||||
* be as simple as a short piece of wire, or as complicated as space-time.
|
||||
*/
|
||||
class Channel : public Object
|
||||
class Channel : public Interface
|
||||
{
|
||||
public:
|
||||
static const InterfaceId iid;
|
||||
Channel ();
|
||||
Channel (std::string name);
|
||||
|
||||
@@ -57,7 +59,7 @@ public:
|
||||
*
|
||||
* This method must be implemented by subclasses.
|
||||
*/
|
||||
virtual NetDevice *GetDevice (uint32_t i) const = 0;
|
||||
virtual Ptr<NetDevice> GetDevice (uint32_t i) const = 0;
|
||||
|
||||
protected:
|
||||
virtual ~Channel ();
|
||||
|
||||
@@ -27,12 +27,13 @@ namespace ns3 {
|
||||
static class QueueStackInitializationClass {
|
||||
public:
|
||||
QueueStackInitializationClass () {
|
||||
Queue::Default (DropTailQueue ());
|
||||
static DropTailQueue queue;
|
||||
Queue::AddDefault (queue, "DropTailQueue");
|
||||
Queue::AddDefault ("DropTailQueue");
|
||||
}
|
||||
} queue_stack_initialization_class;
|
||||
|
||||
const ClassId DropTailQueue::cid =
|
||||
ComponentManager::RegisterConstructor<DropTailQueue> ("DropTailQueue");
|
||||
|
||||
|
||||
DropTailQueue::DropTailQueue () :
|
||||
Queue (),
|
||||
@@ -47,11 +48,6 @@ DropTailQueue::~DropTailQueue ()
|
||||
NS_DEBUG("DropTailQueue::~DropTailQueue ()");
|
||||
}
|
||||
|
||||
DropTailQueue* DropTailQueue::Copy() const
|
||||
{
|
||||
return new DropTailQueue(*this);
|
||||
}
|
||||
|
||||
void
|
||||
DropTailQueue::SetMaxPackets (uint32_t npackets)
|
||||
{
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <queue>
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/queue.h"
|
||||
#include "ns3/component-manager.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -32,10 +33,10 @@ const int DTQ_NPACKETS_MAX_DEFAULT = 100;
|
||||
|
||||
class DropTailQueue : public Queue {
|
||||
public:
|
||||
static const ClassId cid;
|
||||
DropTailQueue ();
|
||||
|
||||
virtual ~DropTailQueue();
|
||||
virtual DropTailQueue* Copy() const;
|
||||
|
||||
void SetMaxPackets (uint32_t npackets);
|
||||
uint32_t GetMaxPackets (void);
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
const Iid IIpv4::iid ("IIpv4");
|
||||
const InterfaceId IIpv4::iid ("IIpv4");
|
||||
|
||||
IIpv4::IIpv4 ()
|
||||
: NsUnknown (IIpv4::iid)
|
||||
: Interface (IIpv4::iid)
|
||||
{}
|
||||
|
||||
IIpv4::~IIpv4 ()
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ns3/ipv4-address.h"
|
||||
#include "ns3/ns-unknown.h"
|
||||
#include "ns3/interface.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -31,10 +31,10 @@ class NetDevice;
|
||||
class Packet;
|
||||
class Ipv4Route;
|
||||
|
||||
class IIpv4 : public NsUnknown
|
||||
class IIpv4 : public Interface
|
||||
{
|
||||
public:
|
||||
static const Iid iid;
|
||||
static const InterfaceId iid;
|
||||
IIpv4 ();
|
||||
virtual ~IIpv4 ();
|
||||
|
||||
@@ -116,12 +116,18 @@ public:
|
||||
* to disable it, you can invoke Ipv4Interface::SetDown which will
|
||||
* make sure that it is never used during packet forwarding.
|
||||
*/
|
||||
virtual uint32_t AddInterface (NetDevice *device) = 0;
|
||||
virtual uint32_t AddInterface (Ptr<NetDevice> device) = 0;
|
||||
/**
|
||||
* \returns the number of interfaces added by the user.
|
||||
*/
|
||||
virtual uint32_t GetNInterfaces (void) = 0;
|
||||
|
||||
/**
|
||||
* \param index of interface
|
||||
* \returns address of the NetDevice associated with the ipv4 interface
|
||||
*/
|
||||
virtual Ptr<NetDevice> GetNetDevice (uint32_t i) = 0;
|
||||
|
||||
virtual void SetAddress (uint32_t i, Ipv4Address address) = 0;
|
||||
virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask) = 0;
|
||||
virtual Ipv4Mask GetNetworkMask (uint32_t t) const = 0;
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
const Iid IUdp::iid ("IUdp");
|
||||
const InterfaceId IUdp::iid ("IUdp");
|
||||
|
||||
IUdp::IUdp ()
|
||||
: NsUnknown (IUdp::iid)
|
||||
: Interface (IUdp::iid)
|
||||
{}
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -21,20 +21,21 @@
|
||||
#ifndef I_UDP_H
|
||||
#define I_UDP_H
|
||||
|
||||
#include "ns3/ns-unknown.h"
|
||||
#include "ns3/interface.h"
|
||||
#include "ns3/ptr.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Socket;
|
||||
|
||||
class IUdp : public NsUnknown
|
||||
class IUdp : public Interface
|
||||
{
|
||||
public:
|
||||
static const Iid iid;
|
||||
static const InterfaceId iid;
|
||||
|
||||
IUdp ();
|
||||
|
||||
virtual Socket *CreateSocket (void) = 0;
|
||||
virtual Ptr<Socket> CreateSocket (void) = 0;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -19,10 +19,6 @@
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
/*
|
||||
* This implementation borrowed from yans
|
||||
*/
|
||||
|
||||
#ifndef MAC_ADDRESS_H
|
||||
#define MAC_ADDRESS_H
|
||||
|
||||
|
||||
@@ -21,15 +21,19 @@
|
||||
|
||||
#include <iostream>
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/interface.h"
|
||||
|
||||
#include "channel.h"
|
||||
#include "net-device.h"
|
||||
#include "llc-snap-header.h"
|
||||
#include "node.h"
|
||||
#include "ns3/channel.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NetDevice::NetDevice(Node *node, const MacAddress& addr) :
|
||||
const InterfaceId NetDevice::iid ("NetDevice");
|
||||
|
||||
NetDevice::NetDevice(Ptr<Node> node, const MacAddress& addr) :
|
||||
Interface (NetDevice::iid),
|
||||
m_node (node),
|
||||
m_name(""),
|
||||
m_ifIndex (0),
|
||||
@@ -40,14 +44,11 @@ NetDevice::NetDevice(Node *node, const MacAddress& addr) :
|
||||
m_isMulticast (false),
|
||||
m_isPointToPoint (false)
|
||||
{
|
||||
m_node->Ref ();
|
||||
m_node->AddDevice (this);
|
||||
}
|
||||
|
||||
NetDevice::~NetDevice ()
|
||||
{
|
||||
m_node->Unref ();
|
||||
m_node = 0;
|
||||
}
|
||||
{}
|
||||
|
||||
MacAddress
|
||||
NetDevice::GetAddress (void) const
|
||||
@@ -188,7 +189,7 @@ NetDevice::CreateTraceResolver (TraceContext const &context)
|
||||
return DoCreateTraceResolver (context);
|
||||
}
|
||||
|
||||
Channel *
|
||||
Ptr<Channel>
|
||||
NetDevice::GetChannel (void) const
|
||||
{
|
||||
return DoGetChannel ();
|
||||
@@ -228,8 +229,8 @@ NetDevice::NotifyLinkDown (void)
|
||||
}
|
||||
}
|
||||
|
||||
Node *
|
||||
NetDevice::PeekNode (void) const
|
||||
Ptr<Node>
|
||||
NetDevice::GetNode (void) const
|
||||
{
|
||||
return m_node;
|
||||
}
|
||||
@@ -241,13 +242,15 @@ NetDevice::NeedsArp (void) const
|
||||
}
|
||||
|
||||
void
|
||||
NetDevice::SetReceiveCallback (Callback<bool,NetDevice *,const Packet &,uint16_t> cb)
|
||||
NetDevice::SetReceiveCallback (Callback<bool,Ptr<NetDevice>,const Packet &,uint16_t> cb)
|
||||
{
|
||||
m_receiveCallback = cb;
|
||||
}
|
||||
|
||||
void
|
||||
NetDevice::DoDispose()
|
||||
{}
|
||||
{
|
||||
m_node = 0;
|
||||
}
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
#include <stdint.h>
|
||||
#include "ns3/callback.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/interface.h"
|
||||
#include "ns3/ptr.h"
|
||||
#include "mac-address.h"
|
||||
|
||||
namespace ns3 {
|
||||
@@ -54,14 +55,10 @@ class Channel;
|
||||
* this base class and implement your own version of the
|
||||
* NetDevice::SendTo method.
|
||||
*/
|
||||
class NetDevice : public Object
|
||||
class NetDevice : public Interface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \param node base class node pointer of device's node
|
||||
* \param addr MAC address of this device.
|
||||
*/
|
||||
NetDevice(Node* node, const MacAddress& addr);
|
||||
static const InterfaceId iid;
|
||||
virtual ~NetDevice();
|
||||
|
||||
/**
|
||||
@@ -78,7 +75,7 @@ public:
|
||||
* returned can be zero if the NetDevice is not yet connected
|
||||
* to any channel.
|
||||
*/
|
||||
Channel *GetChannel (void) const;
|
||||
Ptr<Channel> GetChannel (void) const;
|
||||
|
||||
/**
|
||||
* \return the current MacAddress of this interface.
|
||||
@@ -109,7 +106,7 @@ public:
|
||||
/**
|
||||
* \param index ifIndex of the device
|
||||
*/
|
||||
void SetIfIndex(const uint32_t);
|
||||
void SetIfIndex(const uint32_t index);
|
||||
/**
|
||||
* \return index ifIndex of the device
|
||||
*/
|
||||
@@ -169,13 +166,28 @@ public:
|
||||
* base class to print the nodeid for example, it can invoke
|
||||
* this method.
|
||||
*/
|
||||
Node* PeekNode (void) const;
|
||||
Ptr<Node> GetNode (void) const;
|
||||
|
||||
/**
|
||||
* \returns true if ARP is needed, false otherwise.
|
||||
*
|
||||
* Called by higher-layers to check if this NetDevice requires
|
||||
* ARP to be used.
|
||||
*/
|
||||
bool NeedsArp (void) const;
|
||||
|
||||
void SetReceiveCallback (Callback<bool,NetDevice *,const Packet &,uint16_t> cb);
|
||||
/**
|
||||
* \param cb callback to invoke whenever a packet has been received and must
|
||||
* be forwarded to the higher layers.
|
||||
*/
|
||||
void SetReceiveCallback (Callback<bool,Ptr<NetDevice>,const Packet &,uint16_t> cb);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* \param node base class node pointer of device's node
|
||||
* \param addr MAC address of this device.
|
||||
*/
|
||||
NetDevice(Ptr<Node> node, const MacAddress& addr);
|
||||
/**
|
||||
* Enable broadcast support. This method should be
|
||||
* called by subclasses from their constructor
|
||||
@@ -224,6 +236,12 @@ public:
|
||||
*/
|
||||
bool ForwardUp (Packet& p);
|
||||
|
||||
/**
|
||||
* The dispose method for this NetDevice class.
|
||||
* Subclasses are expected to override this method _and_
|
||||
* to chain up to it by calling NetDevice::DoDispose
|
||||
* at the end of their own DoDispose method.
|
||||
*/
|
||||
virtual void DoDispose (void);
|
||||
|
||||
private:
|
||||
@@ -238,10 +256,30 @@ public:
|
||||
* subclasses to forward packets. Subclasses MUST override this method.
|
||||
*/
|
||||
virtual bool SendTo (Packet& p, const MacAddress& dest) = 0;
|
||||
/**
|
||||
* \returns true if this NetDevice needs the higher-layers
|
||||
* to perform ARP over it, false otherwise.
|
||||
*
|
||||
* Subclasses must implement this method.
|
||||
*/
|
||||
virtual bool DoNeedsArp (void) const = 0;
|
||||
/**
|
||||
* \param context the trace context to associated to the
|
||||
* trace resolver.
|
||||
* \returns a trace resolver associated to the input context.
|
||||
* the caller takes ownership of the pointer returned.
|
||||
*
|
||||
* Subclasses must implement this method.
|
||||
*/
|
||||
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0;
|
||||
virtual Channel *DoGetChannel (void) const = 0;
|
||||
Node* m_node;
|
||||
/**
|
||||
* \returns the channel associated to this NetDevice.
|
||||
*
|
||||
* Subclasses must implement this method.
|
||||
*/
|
||||
virtual Ptr<Channel> DoGetChannel (void) const = 0;
|
||||
|
||||
Ptr<Node> m_node;
|
||||
std::string m_name;
|
||||
uint16_t m_ifIndex;
|
||||
MacAddress m_address;
|
||||
@@ -252,7 +290,7 @@ public:
|
||||
bool m_isMulticast;
|
||||
bool m_isPointToPoint;
|
||||
Callback<void> m_linkChangeCallback;
|
||||
Callback<bool,NetDevice *,const Packet &,uint16_t> m_receiveCallback;
|
||||
Callback<bool,Ptr<NetDevice>,const Packet &,uint16_t> m_receiveCallback;
|
||||
};
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
@@ -49,37 +49,37 @@ public:
|
||||
NodeListPriv ();
|
||||
~NodeListPriv ();
|
||||
|
||||
uint32_t Add (Node *node);
|
||||
uint32_t Add (Ptr<Node> node);
|
||||
NodeList::Iterator Begin (void);
|
||||
NodeList::Iterator End (void);
|
||||
TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
Node *PeekNode (uint32_t n);
|
||||
Ptr<Node> GetNode (uint32_t n);
|
||||
uint32_t GetNNodes (void);
|
||||
|
||||
private:
|
||||
std::vector<Node *> m_nodes;
|
||||
std::vector<Ptr<Node> > m_nodes;
|
||||
};
|
||||
|
||||
NodeListPriv::NodeListPriv ()
|
||||
{}
|
||||
NodeListPriv::~NodeListPriv ()
|
||||
{
|
||||
for (std::vector<Node *>::iterator i = m_nodes.begin ();
|
||||
for (std::vector<Ptr<Node> >::iterator i = m_nodes.begin ();
|
||||
i != m_nodes.end (); i++)
|
||||
{
|
||||
Node *node = *i;
|
||||
Ptr<Node> node = *i;
|
||||
node->Dispose ();
|
||||
node->Unref ();
|
||||
*i = 0;
|
||||
}
|
||||
m_nodes.erase (m_nodes.begin (), m_nodes.end ());
|
||||
}
|
||||
|
||||
|
||||
uint32_t
|
||||
NodeListPriv::Add (Node *node)
|
||||
NodeListPriv::Add (Ptr<Node> node)
|
||||
{
|
||||
uint32_t index = m_nodes.size ();
|
||||
node->Ref ();
|
||||
m_nodes.push_back (node);
|
||||
return index;
|
||||
|
||||
@@ -101,10 +101,17 @@ NodeListPriv::GetNNodes (void)
|
||||
}
|
||||
Node *
|
||||
NodeListPriv::PeekNode (uint32_t n)
|
||||
{
|
||||
return PeekPointer (m_nodes[n]);
|
||||
}
|
||||
|
||||
Ptr<Node>
|
||||
NodeListPriv::GetNode (uint32_t n)
|
||||
{
|
||||
return m_nodes[n];
|
||||
}
|
||||
|
||||
|
||||
TraceResolver *
|
||||
NodeListPriv::CreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
@@ -126,7 +133,7 @@ NodeListPriv::CreateTraceResolver (TraceContext const &context)
|
||||
namespace ns3 {
|
||||
|
||||
uint32_t
|
||||
NodeList::Add (Node *node)
|
||||
NodeList::Add (Ptr<Node> node)
|
||||
{
|
||||
return SimulationSingleton<NodeListPriv>::Get ()->Add (node);
|
||||
}
|
||||
@@ -145,10 +152,10 @@ NodeList::CreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
return SimulationSingleton<NodeListPriv>::Get ()->CreateTraceResolver (context);
|
||||
}
|
||||
Node *
|
||||
NodeList::PeekNode (uint32_t n)
|
||||
Ptr<Node>
|
||||
NodeList::GetNode (uint32_t n)
|
||||
{
|
||||
return SimulationSingleton<NodeListPriv>::Get ()->PeekNode (n);
|
||||
return SimulationSingleton<NodeListPriv>::Get ()->GetNode (n);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include "ns3/array-trace-resolver.h"
|
||||
#include "ns3/ptr.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -31,18 +32,48 @@ class Node;
|
||||
class TraceResolver;
|
||||
class TraceContext;
|
||||
|
||||
/**
|
||||
* \brief the list of simulation nodes.
|
||||
*
|
||||
* Every Node created is automatically added to this list.
|
||||
*/
|
||||
class NodeList
|
||||
{
|
||||
public:
|
||||
typedef ArrayTraceResolver<Node>::Index NodeIndex;
|
||||
typedef std::vector<Node *>::iterator Iterator;
|
||||
typedef std::vector< Ptr<Node> >::iterator Iterator;
|
||||
|
||||
static uint32_t Add (Node *node);
|
||||
/**
|
||||
* \param node node to add
|
||||
* \returns index of node in list.
|
||||
*
|
||||
* This method is called automatically from Node::Node so
|
||||
* the user has little reason to call it himself.
|
||||
*/
|
||||
static uint32_t Add (Ptr<Node> node);
|
||||
/**
|
||||
* \returns a C++ iterator located at the beginning of this
|
||||
* list.
|
||||
*/
|
||||
static Iterator Begin (void);
|
||||
/**
|
||||
* \returns a C++ iterator located at the end of this
|
||||
* list.
|
||||
*/
|
||||
static Iterator End (void);
|
||||
/**
|
||||
* \param context trace context to use for trace resolver
|
||||
* to create.
|
||||
* \returns the requested trace resolver. The caller
|
||||
* takes ownership of the returned pointer.
|
||||
*/
|
||||
static TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
|
||||
static Node *PeekNode (uint32_t n);
|
||||
/**
|
||||
* \param n index of requested node.
|
||||
* \returns the Node associated to index n.
|
||||
*/
|
||||
static Ptr<Node> GetNode (uint32_t n);
|
||||
};
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
@@ -25,14 +25,15 @@
|
||||
#include "node.h"
|
||||
#include "node-list.h"
|
||||
#include "net-device.h"
|
||||
#include "application.h"
|
||||
#include "ns3/simulator.h"
|
||||
|
||||
namespace ns3{
|
||||
|
||||
const Iid Node::iid ("Node");
|
||||
const InterfaceId Node::iid ("Node");
|
||||
|
||||
Node::Node()
|
||||
: NsUnknown (Node::iid),
|
||||
: Interface (Node::iid),
|
||||
m_id(0),
|
||||
m_sid(0)
|
||||
{
|
||||
@@ -40,7 +41,7 @@ Node::Node()
|
||||
}
|
||||
|
||||
Node::Node(uint32_t sid)
|
||||
: NsUnknown (Node::iid),
|
||||
: Interface (Node::iid),
|
||||
m_id(0),
|
||||
m_sid(sid)
|
||||
{
|
||||
@@ -50,6 +51,12 @@ Node::Node(uint32_t sid)
|
||||
Node::~Node ()
|
||||
{}
|
||||
|
||||
TraceResolver *
|
||||
Node::CreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
return DoCreateTraceResolver (context);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Node::GetId (void) const
|
||||
{
|
||||
@@ -62,23 +69,16 @@ Node::GetSystemId (void) const
|
||||
return m_sid;
|
||||
}
|
||||
|
||||
void
|
||||
Node::SetSystemId(uint32_t s )
|
||||
{
|
||||
m_sid = s;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Node::AddDevice (NetDevice *device)
|
||||
Node::AddDevice (Ptr<NetDevice> device)
|
||||
{
|
||||
device->Ref ();
|
||||
uint32_t index = m_devices.size ();
|
||||
m_devices.push_back (device);
|
||||
DoAddDevice (device);
|
||||
device->SetIfIndex(index);
|
||||
return index;
|
||||
}
|
||||
NetDevice *
|
||||
Ptr<NetDevice>
|
||||
Node::GetDevice (uint32_t index) const
|
||||
{
|
||||
return m_devices[index];
|
||||
@@ -89,17 +89,44 @@ Node::GetNDevices (void) const
|
||||
return m_devices.size ();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Node::AddApplication (Ptr<Application> application)
|
||||
{
|
||||
uint32_t index = m_applications.size ();
|
||||
m_applications.push_back (application);
|
||||
return index;
|
||||
}
|
||||
Ptr<Application>
|
||||
Node::GetApplication (uint32_t index) const
|
||||
{
|
||||
return m_applications[index];
|
||||
}
|
||||
uint32_t
|
||||
Node::GetNApplications (void) const
|
||||
{
|
||||
return m_applications.size ();
|
||||
}
|
||||
|
||||
|
||||
void Node::DoDispose()
|
||||
{
|
||||
for (std::vector<NetDevice *>::iterator i = m_devices.begin ();
|
||||
for (std::vector<Ptr<NetDevice> >::iterator i = m_devices.begin ();
|
||||
i != m_devices.end (); i++)
|
||||
{
|
||||
NetDevice *device = *i;
|
||||
Ptr<NetDevice> device = *i;
|
||||
device->Dispose ();
|
||||
device->Unref ();
|
||||
*i = 0;
|
||||
}
|
||||
m_devices.clear ();
|
||||
NsUnknown::DoDispose ();
|
||||
for (std::vector<Ptr<Application> >::iterator i = m_applications.begin ();
|
||||
i != m_applications.end (); i++)
|
||||
{
|
||||
Ptr<Application> application = *i;
|
||||
application->Dispose ();
|
||||
*i = 0;
|
||||
}
|
||||
m_applications.clear ();
|
||||
Interface::DoDispose ();
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
128
src/node/node.h
128
src/node/node.h
@@ -27,41 +27,145 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "ns3/ns-unknown.h"
|
||||
#include "ns3/interface.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class TraceContext;
|
||||
class TraceResolver;
|
||||
class NetDevice;
|
||||
class Application;
|
||||
|
||||
class Node : public NsUnknown
|
||||
/**
|
||||
* \brief A network Node.
|
||||
*
|
||||
* This class holds together:
|
||||
* - a list of NetDevice objects which represent the network interfaces
|
||||
* of this node which are connected to other Node instances through
|
||||
* Channel instances.
|
||||
* - a list of Application objects which represent the userspace
|
||||
* traffic generation applications which interact with the Node
|
||||
* through the Socket API.
|
||||
* - a node Id: a unique per-node identifier.
|
||||
* - a system Id: a unique Id used for parallel simulations.
|
||||
* - a trace resolver which can be used to connect user trace sinks
|
||||
* to the node's trace sources.
|
||||
*
|
||||
* Every Node created is added to the NodeList automatically.
|
||||
*/
|
||||
class Node : public Interface
|
||||
{
|
||||
public:
|
||||
static const Iid iid;
|
||||
static const InterfaceId iid;
|
||||
|
||||
Node();
|
||||
Node(uint32_t); // Specify which system for a distributed simulation
|
||||
virtual ~Node();
|
||||
|
||||
virtual TraceResolver *CreateTraceResolver (TraceContext const &context) = 0;
|
||||
/**
|
||||
* \param context the trace context for the TraceResolver to create
|
||||
* \returns a newly-created TraceResolver. The caller takes
|
||||
* ownership of the returned pointer.
|
||||
*
|
||||
* Request the Node to create a trace resolver. This method
|
||||
* could be used directly by a user who needs access to very low-level
|
||||
* trace configuration.
|
||||
*/
|
||||
TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
|
||||
/**
|
||||
* \returns the unique id of this node.
|
||||
*
|
||||
* This unique id happens to be also the index of the Node into
|
||||
* the NodeList.
|
||||
*/
|
||||
uint32_t GetId (void) const;
|
||||
uint32_t GetSystemId (void) const;
|
||||
void SetSystemId(uint32_t s);
|
||||
|
||||
uint32_t AddDevice (NetDevice *device);
|
||||
NetDevice *GetDevice (uint32_t index) const;
|
||||
/**
|
||||
* \returns the system id for parallel simulations associated
|
||||
* to this node.
|
||||
*/
|
||||
uint32_t GetSystemId (void) const;
|
||||
|
||||
/**
|
||||
* \param device NetDevice to associate to this node.
|
||||
* \returns the index of the NetDevice into the Node's list of
|
||||
* NetDevice.
|
||||
*
|
||||
* Associate this device to this node.
|
||||
* This method is called automatically from NetDevice::NetDevice
|
||||
* so the user has little reason to call this method himself.
|
||||
*/
|
||||
uint32_t AddDevice (Ptr<NetDevice> device);
|
||||
/**
|
||||
* \param index the index of the requested NetDevice
|
||||
* \returns the requested NetDevice associated to this Node.
|
||||
*/
|
||||
Ptr<NetDevice> GetDevice (uint32_t index) const;
|
||||
/**
|
||||
* \returns the number of NetDevice instances associated
|
||||
* to this Node.
|
||||
*/
|
||||
uint32_t GetNDevices (void) const;
|
||||
|
||||
/**
|
||||
* \param application Application to associate to this node.
|
||||
* \returns the index of the Application within the Node's list
|
||||
* of Application.
|
||||
*
|
||||
* Associated this Application to this Node. This method is called
|
||||
* automatically from Application::Application so the user
|
||||
* has little reasons to call this method directly.
|
||||
*/
|
||||
uint32_t AddApplication (Ptr<Application> application);
|
||||
/**
|
||||
* \param index
|
||||
* \returns the application associated to this requested index
|
||||
* within this Node.
|
||||
*/
|
||||
Ptr<Application> GetApplication (uint32_t index) const;
|
||||
/**
|
||||
* \returns the number of applications associated to this Node.
|
||||
*/
|
||||
uint32_t GetNApplications (void) const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Must be invoked by subclasses only.
|
||||
*/
|
||||
Node();
|
||||
/**
|
||||
* \param systemId a unique integer used for parallel simulations.
|
||||
*
|
||||
* Must be invoked by subclasses only.
|
||||
*/
|
||||
Node(uint32_t systemId);
|
||||
/**
|
||||
* The dispose method. Subclasses must override this method
|
||||
* and must chain up to it by calling Node::DoDispose at the
|
||||
* end of their own DoDispose method.
|
||||
*/
|
||||
virtual void DoDispose (void);
|
||||
private:
|
||||
virtual void DoAddDevice (NetDevice *device) const = 0;
|
||||
/**
|
||||
* \param context the trace context
|
||||
* \returns a trace resolver to the user. The user must delete it.
|
||||
*
|
||||
* Subclasses must implement this method.
|
||||
*/
|
||||
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0;
|
||||
/**
|
||||
* \param device the device added to this Node.
|
||||
*
|
||||
* This method is invoked whenever a user calls Node::AddDevice.
|
||||
* Subclasses are expected to call NetDevice::SetReceiveCallback
|
||||
* at this point to setup the node's receive function for
|
||||
* the NetDevice packets.
|
||||
*/
|
||||
virtual void DoAddDevice (Ptr<NetDevice> device) const = 0;
|
||||
|
||||
uint32_t m_id; // Node id for this node
|
||||
uint32_t m_sid; // System id for this node
|
||||
std::vector<NetDevice *> m_devices;
|
||||
std::vector<Ptr<NetDevice> > m_devices;
|
||||
std::vector<Ptr<Application> > m_applications;
|
||||
};
|
||||
|
||||
} //namespace ns3
|
||||
|
||||
@@ -19,16 +19,18 @@
|
||||
|
||||
#include "ns3/debug.h"
|
||||
#include "ns3/composite-trace-resolver.h"
|
||||
#include "queue.h"
|
||||
#include "ns3/default-value.h"
|
||||
#include "ns3/component-manager.h"
|
||||
#include "queue.h"
|
||||
|
||||
NS_DEBUG_COMPONENT_DEFINE ("Queue");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
Queue* Queue::defaultQueue = 0;
|
||||
const InterfaceId Queue::iid ("Queue");
|
||||
|
||||
Queue::Queue() :
|
||||
Interface (Queue::iid),
|
||||
m_nBytes(0),
|
||||
m_nTotalReceivedBytes(0),
|
||||
m_nPackets(0),
|
||||
@@ -194,50 +196,23 @@ Queue::Drop (const Packet& p)
|
||||
m_traceDrop (p);
|
||||
}
|
||||
|
||||
// Static methods for managing default queue
|
||||
|
||||
// Set new default
|
||||
void Queue::Default(const Queue& q)
|
||||
{
|
||||
delete defaultQueue; // delete previous (if any)
|
||||
defaultQueue = q.Copy(); // set new default
|
||||
}
|
||||
|
||||
// Get current default
|
||||
Queue& Queue::Default()
|
||||
{
|
||||
// ! Need to schedule an "at end" event to delete the default
|
||||
return *defaultQueue;
|
||||
}
|
||||
|
||||
|
||||
Queue *
|
||||
Ptr<Queue>
|
||||
Queue::CreateDefault (void)
|
||||
{
|
||||
std::string defaultValue = GetDefault ()->GetValue ();
|
||||
for (List::iterator i = GetList ()->begin ();
|
||||
i != GetList ()->end (); i++)
|
||||
{
|
||||
if (i->second == defaultValue)
|
||||
{
|
||||
return i->first->Copy ();
|
||||
}
|
||||
}
|
||||
NS_ASSERT (false);
|
||||
// quiet compiler
|
||||
return 0;
|
||||
ClassId classId = ComponentManager::LookupByName (defaultValue);
|
||||
Ptr<Queue> queue = ComponentManager::Create<Queue> (classId, Queue::iid);
|
||||
return queue;
|
||||
}
|
||||
void
|
||||
Queue::Add (Queue &queue, const std::string &name)
|
||||
Queue::Add (const std::string &name)
|
||||
{
|
||||
GetDefault ()->AddPossibleValue (name);
|
||||
GetList ()->push_back (std::make_pair (&queue, name));
|
||||
}
|
||||
void
|
||||
Queue::AddDefault (Queue &queue, const std::string &name)
|
||||
Queue::AddDefault (const std::string &name)
|
||||
{
|
||||
GetDefault ()->AddDefaultValue (name);
|
||||
GetList ()->push_back (std::make_pair (&queue, name));
|
||||
}
|
||||
StringEnumDefaultValue *
|
||||
Queue::GetDefault (void)
|
||||
@@ -245,12 +220,6 @@ Queue::GetDefault (void)
|
||||
static StringEnumDefaultValue value ("Queue", "Packet Queue");
|
||||
return &value;
|
||||
}
|
||||
Queue::List *
|
||||
Queue::GetList (void)
|
||||
{
|
||||
static List list;
|
||||
return &list;
|
||||
}
|
||||
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/interface.h"
|
||||
#include "ns3/callback-trace-source.h"
|
||||
#include "ns3/trace-resolver.h"
|
||||
|
||||
@@ -35,9 +36,11 @@ namespace ns3 {
|
||||
|
||||
class StringEnumDefaultValue;
|
||||
|
||||
class Queue
|
||||
class Queue : public Interface
|
||||
{
|
||||
public:
|
||||
static const InterfaceId iid;
|
||||
|
||||
enum TraceType {
|
||||
ENQUEUE,
|
||||
DEQUEUE,
|
||||
@@ -46,8 +49,6 @@ public:
|
||||
Queue ();
|
||||
virtual ~Queue ();
|
||||
|
||||
virtual Queue* Copy() const = 0;
|
||||
|
||||
TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
|
||||
bool IsEmpty (void);
|
||||
@@ -112,22 +113,13 @@ private:
|
||||
uint32_t m_nTotalDroppedPackets;
|
||||
|
||||
public:
|
||||
static Queue *CreateDefault (void);
|
||||
static void Add (Queue &queue, const std::string &name);
|
||||
static void AddDefault (Queue &queue, const std::string &name);
|
||||
static Ptr<Queue> CreateDefault (void);
|
||||
static void Add (const std::string &name);
|
||||
static void AddDefault (const std::string &name);
|
||||
private:
|
||||
typedef std::list<std::pair<Queue *,std::string> > List;
|
||||
static StringEnumDefaultValue *GetDefault (void);
|
||||
static List *GetList (void);
|
||||
|
||||
public:
|
||||
// Static methods to manage queue default
|
||||
// Set desired queue default
|
||||
static void Default(const Queue& q);
|
||||
// Return reference to the current default queue type
|
||||
static Queue& Default();
|
||||
// Static variable pointing to current default queue
|
||||
static Queue* defaultQueue;
|
||||
};
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
@@ -6,7 +6,7 @@ Socket::~Socket ()
|
||||
{}
|
||||
|
||||
void
|
||||
Socket::Close(Callback<void, Socket*> closeCompleted)
|
||||
Socket::Close(Callback<void, Ptr<Socket> > closeCompleted)
|
||||
{
|
||||
DoClose (closeCompleted);
|
||||
}
|
||||
@@ -14,23 +14,23 @@ Socket::Close(Callback<void, Socket*> closeCompleted)
|
||||
void
|
||||
Socket::Connect(const Ipv4Address & address,
|
||||
uint16_t portNumber,
|
||||
Callback<void, Socket*> connectionSucceeded,
|
||||
Callback<void, Socket*> connectionFailed,
|
||||
Callback<void, Socket*> halfClose)
|
||||
Callback<void, Ptr<Socket> > connectionSucceeded,
|
||||
Callback<void, Ptr<Socket> > connectionFailed,
|
||||
Callback<void, Ptr<Socket> > halfClose)
|
||||
{
|
||||
DoConnect (address, portNumber, connectionSucceeded, connectionFailed, halfClose);
|
||||
}
|
||||
int
|
||||
Socket::Accept(Callback<bool, Socket*, const Ipv4Address&, uint16_t> connectionRequest,
|
||||
Callback<void, Socket*, const Ipv4Address&, uint16_t> newConnectionCreated,
|
||||
Callback<void, Socket*> closeRequested)
|
||||
Socket::Accept(Callback<bool, Ptr<Socket>, const Ipv4Address&, uint16_t> connectionRequest,
|
||||
Callback<void, Ptr<Socket>, const Ipv4Address&, uint16_t> newConnectionCreated,
|
||||
Callback<void, Ptr<Socket> > closeRequested)
|
||||
{
|
||||
return DoAccept (connectionRequest, newConnectionCreated, closeRequested);
|
||||
}
|
||||
int
|
||||
Socket::Send (const uint8_t* buffer,
|
||||
uint32_t size,
|
||||
Callback<void, Socket*, uint32_t> dataSent)
|
||||
Callback<void, Ptr<Socket>, uint32_t> dataSent)
|
||||
{
|
||||
return DoSend (buffer, size, dataSent);
|
||||
}
|
||||
@@ -39,42 +39,42 @@ Socket::SendTo(const Ipv4Address &address,
|
||||
uint16_t port,
|
||||
const uint8_t *buffer,
|
||||
uint32_t size,
|
||||
Callback<void, Socket*, uint32_t> dataSent)
|
||||
Callback<void, Ptr<Socket>, uint32_t> dataSent)
|
||||
{
|
||||
return DoSendTo (address, port, buffer, size, dataSent);
|
||||
}
|
||||
void
|
||||
Socket::Recv(Callback<void, Socket*, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> callback)
|
||||
Socket::Recv(Callback<void, Ptr<Socket>, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> callback)
|
||||
{
|
||||
DoRecv (callback);
|
||||
}
|
||||
void
|
||||
Socket::RecvDummy(Callback<void, Socket*, uint32_t,const Ipv4Address&, uint16_t> callback)
|
||||
Socket::RecvDummy(Callback<void, Ptr<Socket>, uint32_t,const Ipv4Address&, uint16_t> callback)
|
||||
{
|
||||
DoRecvDummy (callback);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Socket::RefuseAllConnections (Socket* socket, const Ipv4Address& address, uint16_t port)
|
||||
Socket::RefuseAllConnections (Ptr<Socket> socket, const Ipv4Address& address, uint16_t port)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
void
|
||||
Socket::DummyCallbackVoidSocket (Socket *socket)
|
||||
Socket::DummyCallbackVoidSocket (Ptr<Socket> socket)
|
||||
{}
|
||||
void
|
||||
Socket::DummyCallbackVoidSocketUi32 (Socket *socket, uint32_t)
|
||||
Socket::DummyCallbackVoidSocketUi32 (Ptr<Socket> socket, uint32_t)
|
||||
{}
|
||||
void
|
||||
Socket::DummyCallbackVoidSocketUi32Ipv4AddressUi16 (Socket *socket, uint32_t, const Ipv4Address &, uint16_t)
|
||||
Socket::DummyCallbackVoidSocketUi32Ipv4AddressUi16 (Ptr<Socket> socket, uint32_t, const Ipv4Address &, uint16_t)
|
||||
{}
|
||||
void
|
||||
Socket::DummyCallbackVoidSocketBufferUi32Ipv4AddressUi16 (Socket *socket, const uint8_t *, uint32_t,
|
||||
Socket::DummyCallbackVoidSocketBufferUi32Ipv4AddressUi16 (Ptr<Socket> socket, const uint8_t *, uint32_t,
|
||||
const Ipv4Address &, uint16_t)
|
||||
{}
|
||||
void
|
||||
Socket::DummyCallbackVoidSocketIpv4AddressUi16 (Socket *socket, const Ipv4Address &, uint16_t)
|
||||
Socket::DummyCallbackVoidSocketIpv4AddressUi16 (Ptr<Socket> socket, const Ipv4Address &, uint16_t)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#define __SOCKET_H__
|
||||
|
||||
#include "ns3/callback.h"
|
||||
#include "ns3/ptr.h"
|
||||
#include "ipv4-address.h"
|
||||
#include "ns3/object.h"
|
||||
#include <stdint.h>
|
||||
@@ -65,7 +66,7 @@ public:
|
||||
/**
|
||||
* \returns the node this socket is associated with.
|
||||
*/
|
||||
virtual Node *PeekNode (void) const = 0;
|
||||
virtual Ptr<Node> GetNode (void) const = 0;
|
||||
|
||||
/**
|
||||
* Allocate a free port number and
|
||||
@@ -113,7 +114,7 @@ public:
|
||||
* After the Close call, the socket is no longer valid, and cannot
|
||||
* safely be used for subsequent operations.
|
||||
*/
|
||||
void Close(Callback<void, Socket*> closeCompleted = MakeCallback (&Socket::DummyCallbackVoidSocket));
|
||||
void Close(Callback<void, Ptr<Socket> > closeCompleted = MakeCallback (&Socket::DummyCallbackVoidSocket));
|
||||
|
||||
/**
|
||||
* \returns zero on success, -1 on failure.
|
||||
@@ -146,9 +147,9 @@ public:
|
||||
*/
|
||||
void Connect(const Ipv4Address & address,
|
||||
uint16_t portNumber,
|
||||
Callback<void, Socket*> connectionSucceeded = MakeCallback(&Socket::DummyCallbackVoidSocket),
|
||||
Callback<void, Socket*> connectionFailed = MakeCallback(&Socket::DummyCallbackVoidSocket),
|
||||
Callback<void, Socket*> halfClose = MakeCallback(&Socket::DummyCallbackVoidSocket));
|
||||
Callback<void, Ptr<Socket> > connectionSucceeded = MakeCallback(&Socket::DummyCallbackVoidSocket),
|
||||
Callback<void, Ptr<Socket> > connectionFailed = MakeCallback(&Socket::DummyCallbackVoidSocket),
|
||||
Callback<void, Ptr<Socket> > halfClose = MakeCallback(&Socket::DummyCallbackVoidSocket));
|
||||
|
||||
/**
|
||||
* \brief Accept connection requests from remote hosts
|
||||
@@ -169,11 +170,11 @@ public:
|
||||
* \param closeRequested Callback for connection close request from peer.
|
||||
* XXX: when is this callback invoked ?
|
||||
*/
|
||||
int Accept(Callback<bool, Socket*, const Ipv4Address&, uint16_t> connectionRequest =
|
||||
int Accept(Callback<bool, Ptr<Socket>, const Ipv4Address&, uint16_t> connectionRequest =
|
||||
MakeCallback(&Socket::RefuseAllConnections),
|
||||
Callback<void, Socket*, const Ipv4Address&, uint16_t> newConnectionCreated =
|
||||
Callback<void, Ptr<Socket>, const Ipv4Address&, uint16_t> newConnectionCreated =
|
||||
MakeCallback (&Socket::DummyCallbackVoidSocketIpv4AddressUi16),
|
||||
Callback<void, Socket*> closeRequested = MakeCallback (&Socket::DummyCallbackVoidSocket));
|
||||
Callback<void, Ptr<Socket> > closeRequested = MakeCallback (&Socket::DummyCallbackVoidSocket));
|
||||
|
||||
/**
|
||||
* \brief Send data (or dummy data) to the remote host
|
||||
@@ -185,7 +186,7 @@ public:
|
||||
*/
|
||||
int Send (const uint8_t* buffer,
|
||||
uint32_t size,
|
||||
Callback<void, Socket*, uint32_t> dataSent = MakeCallback (&Socket::DummyCallbackVoidSocketUi32));
|
||||
Callback<void, Ptr<Socket>, uint32_t> dataSent = MakeCallback (&Socket::DummyCallbackVoidSocketUi32));
|
||||
|
||||
/**
|
||||
* \brief Send data to a specified peer.
|
||||
@@ -201,59 +202,59 @@ public:
|
||||
uint16_t port,
|
||||
const uint8_t *buffer,
|
||||
uint32_t size,
|
||||
Callback<void, Socket*, uint32_t> dataSent = MakeCallback (&Socket::DummyCallbackVoidSocketUi32));
|
||||
Callback<void, Ptr<Socket>, uint32_t> dataSent = MakeCallback (&Socket::DummyCallbackVoidSocketUi32));
|
||||
|
||||
/**
|
||||
* \brief Receive data
|
||||
* \param Received data callback. Invoked whenever new data is received.
|
||||
* \param receivedData Invoked whenever new data is received.
|
||||
*
|
||||
* If you wish to transport only dummy packets, this method is not a very
|
||||
* efficient way to receive these dummy packets: it will trigger a memory
|
||||
* allocation to hold the dummy memory into a buffer which can be passed
|
||||
* to the user. Instead, consider using the RecvDummy method.
|
||||
*/
|
||||
void Recv(Callback<void, Socket*, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> =
|
||||
void Recv(Callback<void, Ptr<Socket>, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> receivedData =
|
||||
MakeCallback (&Socket::DummyCallbackVoidSocketBufferUi32Ipv4AddressUi16));
|
||||
|
||||
/**
|
||||
* \brief Receive data
|
||||
* \param Received data callback. Invoked whenever new data is received.
|
||||
* \param receivedData Invoked whenever new data is received.
|
||||
*
|
||||
* This method is included because it is vastly more efficient than the
|
||||
* Recv method when you use dummy payload.
|
||||
*/
|
||||
void RecvDummy(Callback<void, Socket*, uint32_t,const Ipv4Address&, uint16_t> =
|
||||
void RecvDummy(Callback<void, Ptr<Socket>, uint32_t,const Ipv4Address&, uint16_t> receivedData =
|
||||
MakeCallback (&Socket::DummyCallbackVoidSocketUi32Ipv4AddressUi16));
|
||||
|
||||
private:
|
||||
virtual void DoClose(Callback<void, Socket*> closeCompleted) = 0;
|
||||
virtual void DoClose(Callback<void, Ptr<Socket> > closeCompleted) = 0;
|
||||
virtual void DoConnect(const Ipv4Address & address,
|
||||
uint16_t portNumber,
|
||||
Callback<void, Socket*> connectionSucceeded,
|
||||
Callback<void, Socket*> connectionFailed,
|
||||
Callback<void, Socket*> halfClose) = 0;
|
||||
virtual int DoAccept(Callback<bool, Socket*, const Ipv4Address&, uint16_t> connectionRequest,
|
||||
Callback<void, Socket*, const Ipv4Address&, uint16_t> newConnectionCreated,
|
||||
Callback<void, Socket*> closeRequested) = 0;
|
||||
Callback<void, Ptr<Socket> > connectionSucceeded,
|
||||
Callback<void, Ptr<Socket> > connectionFailed,
|
||||
Callback<void, Ptr<Socket> > halfClose) = 0;
|
||||
virtual int DoAccept(Callback<bool, Ptr<Socket>, const Ipv4Address&, uint16_t> connectionRequest,
|
||||
Callback<void, Ptr<Socket>, const Ipv4Address&, uint16_t> newConnectionCreated,
|
||||
Callback<void, Ptr<Socket> > closeRequested) = 0;
|
||||
virtual int DoSend (const uint8_t* buffer,
|
||||
uint32_t size,
|
||||
Callback<void, Socket*, uint32_t> dataSent) = 0;
|
||||
Callback<void, Ptr<Socket>, uint32_t> dataSent) = 0;
|
||||
virtual int DoSendTo(const Ipv4Address &address,
|
||||
uint16_t port,
|
||||
const uint8_t *buffer,
|
||||
uint32_t size,
|
||||
Callback<void, Socket*, uint32_t> dataSent) = 0;
|
||||
virtual void DoRecv(Callback<void, Socket*, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> receive) = 0;
|
||||
virtual void DoRecvDummy(Callback<void, Socket*, uint32_t,const Ipv4Address&, uint16_t>) = 0;
|
||||
Callback<void, Ptr<Socket>, uint32_t> dataSent) = 0;
|
||||
virtual void DoRecv(Callback<void, Ptr<Socket>, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> receive) = 0;
|
||||
virtual void DoRecvDummy(Callback<void, Ptr<Socket>, uint32_t,const Ipv4Address&, uint16_t>) = 0;
|
||||
|
||||
|
||||
static bool RefuseAllConnections (Socket* socket, const Ipv4Address& address, uint16_t port);
|
||||
static void DummyCallbackVoidSocket (Socket *socket);
|
||||
static void DummyCallbackVoidSocketUi32 (Socket *socket, uint32_t);
|
||||
static void DummyCallbackVoidSocketUi32Ipv4AddressUi16 (Socket *socket, uint32_t, const Ipv4Address &, uint16_t);
|
||||
static void DummyCallbackVoidSocketBufferUi32Ipv4AddressUi16 (Socket *socket, const uint8_t *, uint32_t,
|
||||
static bool RefuseAllConnections (Ptr<Socket> socket, const Ipv4Address& address, uint16_t port);
|
||||
static void DummyCallbackVoidSocket (Ptr<Socket> socket);
|
||||
static void DummyCallbackVoidSocketUi32 (Ptr<Socket> socket, uint32_t);
|
||||
static void DummyCallbackVoidSocketUi32Ipv4AddressUi16 (Ptr<Socket> socket, uint32_t, const Ipv4Address &, uint16_t);
|
||||
static void DummyCallbackVoidSocketBufferUi32Ipv4AddressUi16 (Ptr<Socket> socket, const uint8_t *, uint32_t,
|
||||
const Ipv4Address &, uint16_t);
|
||||
static void DummyCallbackVoidSocketIpv4AddressUi16 (Socket *socket, const Ipv4Address &, uint16_t);
|
||||
static void DummyCallbackVoidSocketIpv4AddressUi16 (Ptr<Socket> socket, const Ipv4Address &, uint16_t);
|
||||
};
|
||||
|
||||
} //namespace ns3
|
||||
|
||||
@@ -20,6 +20,7 @@ def build(bld):
|
||||
'socket.cc',
|
||||
'i-udp.cc',
|
||||
'i-ipv4.cc',
|
||||
'application.cc',
|
||||
]
|
||||
|
||||
headers = bld.create_obj('ns3header')
|
||||
@@ -37,4 +38,5 @@ def build(bld):
|
||||
'socket.h',
|
||||
'i-udp.h',
|
||||
'i-ipv4.h',
|
||||
'application.h',
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user