This commit is contained in:
Gustavo J. A. M. Carneiro
2007-05-13 12:52:38 +01:00
94 changed files with 1713 additions and 2089 deletions

View File

@@ -28,24 +28,21 @@
namespace ns3 {
ArpCache::ArpCache (NetDevice *device, Ipv4Interface *interface)
ArpCache::ArpCache (Ptr<NetDevice> device, Ipv4Interface *interface)
: m_device (device),
m_interface (interface),
m_aliveTimeout (Seconds (120)),
m_deadTimeout (Seconds (100)),
m_waitReplyTimeout (Seconds (1))
{
m_device->Ref ();
}
{}
ArpCache::~ArpCache ()
{
m_device->Unref ();
Flush ();
}
NetDevice *
ArpCache::PeekDevice (void) const
Ptr<NetDevice>
ArpCache::GetDevice (void) const
{
return m_device;
}

View File

@@ -27,6 +27,7 @@
#include "ns3/net-device.h"
#include "ns3/ipv4-address.h"
#include "ns3/mac-address.h"
#include "ns3/ptr.h"
#include "sgi-hashmap.h"
namespace ns3 {
@@ -38,10 +39,10 @@ class ArpCache {
public:
class Entry;
ArpCache (NetDevice *device, Ipv4Interface *interface);
ArpCache (Ptr<NetDevice> device, Ipv4Interface *interface);
~ArpCache ();
NetDevice *PeekDevice (void) const;
Ptr<NetDevice> GetDevice (void) const;
Ipv4Interface *GetInterface (void) const;
void SetAliveTimeout (Time aliveTimeout);
@@ -91,7 +92,7 @@ private:
typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash> Cache;
typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash>::iterator CacheI;
NetDevice *m_device;
Ptr<NetDevice> m_device;
Ipv4Interface *m_interface;
Time m_aliveTimeout;
Time m_deadTimeout;

View File

@@ -31,25 +31,21 @@
namespace ns3 {
ArpIpv4Interface::ArpIpv4Interface (Node *node, NetDevice *device)
ArpIpv4Interface::ArpIpv4Interface (Ptr<Node> node, Ptr<NetDevice> device)
: Ipv4Interface (device),
m_node (node)
{
m_node->Ref ();
}
{}
ArpIpv4Interface::~ArpIpv4Interface ()
{
m_node->Unref ();
}
{}
TraceResolver *
ArpIpv4Interface::DoCreateTraceResolver (TraceContext const &context)
{
CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
if (PeekDevice () != 0)
if (GetDevice () != 0)
{
resolver->Add ("netdevice",
MakeCallback (&NetDevice::CreateTraceResolver, PeekDevice ()),
MakeCallback (&NetDevice::CreateTraceResolver, PeekPointer (GetDevice ())),
ArpIpv4Interface::NETDEVICE);
}
@@ -59,21 +55,20 @@ ArpIpv4Interface::DoCreateTraceResolver (TraceContext const &context)
void
ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest)
{
NS_ASSERT (PeekDevice () != 0);
if (PeekDevice ()->NeedsArp ())
NS_ASSERT (GetDevice () != 0);
if (GetDevice ()->NeedsArp ())
{
IArpPrivate * arp = m_node->QueryInterface<IArpPrivate> (IArpPrivate::iid);
Ptr<IArpPrivate> arp = m_node->QueryInterface<IArpPrivate> (IArpPrivate::iid);
MacAddress hardwareDestination;
bool found = arp->Lookup (p, dest, PeekDevice (), &hardwareDestination);
bool found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination);
if (found)
{
PeekDevice ()->Send (p, hardwareDestination, Ipv4::PROT_NUMBER);
GetDevice ()->Send (p, hardwareDestination, Ipv4::PROT_NUMBER);
}
arp->Unref ();
}
else
{
PeekDevice ()->Send (p, PeekDevice ()->GetBroadcast (), Ipv4::PROT_NUMBER);
GetDevice ()->Send (p, GetDevice ()->GetBroadcast (), Ipv4::PROT_NUMBER);
}
}

View File

@@ -23,6 +23,7 @@
#define ARP_IPV4_INTERFACE_H
#include "ipv4-interface.h"
#include "ns3/ptr.h"
namespace ns3 {
@@ -42,13 +43,13 @@ class ArpIpv4Interface : public Ipv4Interface
NETDEVICE,
ARP,
};
ArpIpv4Interface (Node *node, NetDevice *device);
ArpIpv4Interface (Ptr<Node> node, Ptr<NetDevice> device);
virtual ~ArpIpv4Interface ();
private:
virtual void SendTo (Packet p, Ipv4Address dest);
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context);
Node *m_node;
Ptr<Node> m_node;
};
}//namespace ns3

View File

@@ -36,17 +36,13 @@ namespace ns3 {
const uint16_t Arp::PROT_NUMBER = 0x0806;
Arp::Arp (Node *node)
Arp::Arp (Ptr<Node> node)
: L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ),
m_node (node)
{
m_node->Ref ();
}
{}
Arp::~Arp ()
{
Dispose ();
}
{}
void
Arp::DoDispose (void)
@@ -56,11 +52,7 @@ Arp::DoDispose (void)
delete *i;
}
m_cacheList.clear ();
if (m_node != 0)
{
m_node->Unref ();
m_node = 0;
}
m_node = 0;
L3Protocol::DoDispose ();
}
@@ -71,18 +63,17 @@ Arp::CreateTraceResolver (TraceContext const &context)
}
ArpCache *
Arp::FindCache (NetDevice *device)
Arp::FindCache (Ptr<NetDevice> device)
{
for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++)
{
if ((*i)->PeekDevice () == device)
if ((*i)->GetDevice () == device)
{
return *i;
}
}
IIpv4Private *ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
Ptr<IIpv4Private> ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device);
ipv4->Unref ();
ArpCache * cache = new ArpCache (device, interface);
NS_ASSERT (device->IsBroadcast ());
device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
@@ -91,7 +82,7 @@ Arp::FindCache (NetDevice *device)
}
void
Arp::Receive(Packet& packet, NetDevice *device)
Arp::Receive(Packet& packet, Ptr<NetDevice> device)
{
ArpCache *cache = FindCache (device);
ArpHeader arp;
@@ -140,7 +131,7 @@ Arp::Receive(Packet& packet, NetDevice *device)
}
bool
Arp::Lookup (Packet &packet, Ipv4Address destination,
NetDevice *device,
Ptr<NetDevice> device,
MacAddress *hardwareDestination)
{
ArpCache *cache = FindCache (device);
@@ -212,25 +203,25 @@ void
Arp::SendArpRequest (ArpCache const *cache, Ipv4Address to)
{
ArpHeader arp;
arp.SetRequest (cache->PeekDevice ()->GetAddress (),
arp.SetRequest (cache->GetDevice ()->GetAddress (),
cache->GetInterface ()->GetAddress (),
cache->PeekDevice ()->GetBroadcast (),
cache->GetDevice ()->GetBroadcast (),
to);
Packet packet;
packet.AddHeader (arp);
cache->PeekDevice ()->Send (packet, cache->PeekDevice ()->GetBroadcast (), PROT_NUMBER);
cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), PROT_NUMBER);
}
void
Arp::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac)
{
ArpHeader arp;
arp.SetReply (cache->PeekDevice ()->GetAddress (),
arp.SetReply (cache->GetDevice ()->GetAddress (),
cache->GetInterface ()->GetAddress (),
toMac, toIp);
Packet packet;
packet.AddHeader (arp);
cache->PeekDevice ()->Send (packet, toMac, PROT_NUMBER);
cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER);
}
}//namespace ns3

View File

@@ -24,6 +24,7 @@
#include <list>
#include "ns3/ipv4-address.h"
#include "ns3/mac-address.h"
#include "ns3/ptr.h"
#include "l3-protocol.h"
namespace ns3 {
@@ -40,24 +41,24 @@ class Arp : public L3Protocol
public:
static const uint16_t PROT_NUMBER;
Arp (Node *node);
Arp (Ptr<Node> node);
~Arp ();
virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
virtual void Receive(Packet& p, NetDevice *device);
virtual void Receive(Packet& p, Ptr<NetDevice> device);
bool Lookup (Packet &p, Ipv4Address destination,
NetDevice *device,
Ptr<NetDevice> device,
MacAddress *hardwareDestination);
protected:
virtual void DoDispose (void);
private:
typedef std::list<ArpCache *> CacheList;
ArpCache *FindCache (NetDevice *device);
ArpCache *FindCache (Ptr<NetDevice> device);
void SendArpRequest (ArpCache const *cache, Ipv4Address to);
void SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac);
CacheList m_cacheList;
Node *m_node;
Ptr<Node> m_node;
};
}//namespace ns3

View File

@@ -110,7 +110,7 @@ AsciiTrace::LogDevQueue (TraceContext const &context, Packet const &packet)
m_os << Simulator::Now ().GetSeconds () << " ";
NodeList::NodeIndex nodeIndex;
context.Get (nodeIndex);
m_os << "node=" << NodeList::PeekNode (nodeIndex)->GetId () << " ";
m_os << "node=" << NodeList::GetNode (nodeIndex)->GetId () << " ";
Ipv4::InterfaceIndex interfaceIndex;
context.Get (interfaceIndex);
m_os << "interface=" << interfaceIndex << " ";
@@ -124,7 +124,7 @@ AsciiTrace::LogDevRx (TraceContext const &context, Packet &p)
m_os << "r " << Simulator::Now ().GetSeconds () << " ";
NodeList::NodeIndex nodeIndex;
context.Get (nodeIndex);
m_os << "node=" << NodeList::PeekNode (nodeIndex)->GetId () << " ";
m_os << "node=" << NodeList::GetNode (nodeIndex)->GetId () << " ";
Ipv4::InterfaceIndex interfaceIndex;
context.Get (interfaceIndex);
m_os << "interface=" << interfaceIndex << " ";

View File

@@ -21,17 +21,16 @@
#include "i-arp-private.h"
#include "arp.h"
#include "ns3/assert.h"
#include "ns3/net-device.h"
namespace ns3 {
const Iid IArpPrivate::iid ("IArpPrivate");
const InterfaceId IArpPrivate::iid ("IArpPrivate");
IArpPrivate::IArpPrivate (Arp *arp)
: NsUnknown (IArpPrivate::iid),
IArpPrivate::IArpPrivate (Ptr<Arp> arp)
: Interface (IArpPrivate::iid),
m_arp (arp)
{
m_arp->Ref ();
}
{}
IArpPrivate::~IArpPrivate ()
{
NS_ASSERT (m_arp == 0);
@@ -39,7 +38,7 @@ IArpPrivate::~IArpPrivate ()
bool
IArpPrivate::Lookup (Packet &p, Ipv4Address destination,
NetDevice *device,
Ptr<NetDevice> device,
MacAddress *hardwareDestination)
{
return m_arp->Lookup (p, destination, device, hardwareDestination);
@@ -48,9 +47,8 @@ IArpPrivate::Lookup (Packet &p, Ipv4Address destination,
void
IArpPrivate::DoDispose (void)
{
m_arp->Unref ();
m_arp = 0;
NsUnknown::DoDispose ();
Interface::DoDispose ();
}

View File

@@ -21,7 +21,7 @@
#ifndef I_ARP_PRIVATE_H
#define I_ARP_PRIVATE_H
#include "ns3/ns-unknown.h"
#include "ns3/interface.h"
#include "ns3/ipv4-address.h"
namespace ns3 {
@@ -31,19 +31,19 @@ class MacAddress;
class Packet;
class Arp;
class IArpPrivate : public NsUnknown
class IArpPrivate : public Interface
{
public:
static const Iid iid;
IArpPrivate (Arp *arp);
static const InterfaceId iid;
IArpPrivate (Ptr<Arp> arp);
virtual ~IArpPrivate ();
bool Lookup (Packet &p, Ipv4Address destination,
NetDevice *device,
Ptr<NetDevice> device,
MacAddress *hardwareDestination);
protected:
virtual void DoDispose (void);
private:
Arp *m_arp;
Ptr<Arp> m_arp;
};
} // namespace ns3

View File

@@ -20,15 +20,15 @@
*/
#include "i-ipv4-impl.h"
#include "ipv4.h"
#include "ipv4-interface.h"
#include "ns3/assert.h"
#include "ns3/net-device.h"
namespace ns3 {
IIpv4Impl::IIpv4Impl (Ipv4 *ipv4)
IIpv4Impl::IIpv4Impl (Ptr<Ipv4> ipv4)
: m_ipv4 (ipv4)
{
m_ipv4->Ref ();
}
{}
IIpv4Impl::~IIpv4Impl ()
{
NS_ASSERT (m_ipv4 == 0);
@@ -36,7 +36,6 @@ IIpv4Impl::~IIpv4Impl ()
void
IIpv4Impl::DoDispose (void)
{
m_ipv4->Unref ();
m_ipv4 = 0;
}
@@ -90,7 +89,7 @@ IIpv4Impl::RemoveRoute (uint32_t i)
return m_ipv4->RemoveRoute (i);
}
uint32_t
IIpv4Impl::AddInterface (NetDevice *device)
IIpv4Impl::AddInterface (Ptr<NetDevice> device)
{
return m_ipv4->AddInterface (device);
}
@@ -99,6 +98,11 @@ IIpv4Impl::GetNInterfaces (void)
{
return m_ipv4->GetNInterfaces ();
}
Ptr<NetDevice>
IIpv4Impl::GetNetDevice (uint32_t i)
{
return m_ipv4->GetInterface (i)-> GetDevice ();
}
void
IIpv4Impl::SetAddress (uint32_t i, Ipv4Address address)

View File

@@ -22,6 +22,7 @@
#define I_IPV4_IMPL_H
#include "ns3/i-ipv4.h"
#include "ns3/ptr.h"
namespace ns3 {
@@ -30,7 +31,7 @@ class Ipv4;
class IIpv4Impl : public IIpv4
{
public:
IIpv4Impl (Ipv4 *ipv4);
IIpv4Impl (Ptr<Ipv4> ipv4);
virtual ~IIpv4Impl ();
@@ -51,8 +52,9 @@ public:
virtual uint32_t GetNRoutes (void);
virtual Ipv4Route *GetRoute (uint32_t i);
virtual void RemoveRoute (uint32_t i);
virtual uint32_t AddInterface (NetDevice *device);
virtual uint32_t AddInterface (Ptr<NetDevice> device);
virtual uint32_t GetNInterfaces (void);
virtual Ptr<NetDevice> GetNetDevice(uint32_t i);
virtual void SetAddress (uint32_t i, Ipv4Address address);
virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask);
@@ -65,7 +67,7 @@ public:
protected:
virtual void DoDispose (void);
private:
Ipv4 *m_ipv4;
Ptr<Ipv4> m_ipv4;
};
} // namespace ns3

View File

@@ -21,17 +21,16 @@
#include "i-ipv4-private.h"
#include "ipv4.h"
#include "ns3/assert.h"
#include "ns3/net-device.h"
namespace ns3 {
const Iid IIpv4Private::iid ("IIpv4Private");
const InterfaceId IIpv4Private::iid ("IIpv4Private");
IIpv4Private::IIpv4Private (Ipv4 *ipv4)
: NsUnknown (IIpv4Private::iid),
IIpv4Private::IIpv4Private (Ptr<Ipv4> ipv4)
: Interface (IIpv4Private::iid),
m_ipv4 (ipv4)
{
m_ipv4->Ref ();
}
{}
IIpv4Private::~IIpv4Private ()
{
NS_ASSERT (m_ipv4 == 0);
@@ -48,21 +47,20 @@ IIpv4Private::Send (Packet const &packet, Ipv4Address source,
m_ipv4->Send (packet, source, destination, protocol);
}
Ipv4Interface *
IIpv4Private::FindInterfaceForDevice (NetDevice const*device)
IIpv4Private::FindInterfaceForDevice (Ptr<const NetDevice>device)
{
return m_ipv4->FindInterfaceForDevice (device);
}
void
IIpv4Private::Receive(Packet& p, NetDevice *device)
IIpv4Private::Receive(Packet& p, Ptr<NetDevice> device)
{
m_ipv4->Receive (p, device);
}
void
IIpv4Private::DoDispose (void)
{
m_ipv4->Unref ();
m_ipv4 = 0;
NsUnknown::DoDispose ();
Interface::DoDispose ();
}
} // namespace ns3

View File

@@ -21,8 +21,9 @@
#ifndef I_IPV4_PRIVATE_H
#define I_IPV4_PRIVATE_H
#include "ns3/ns-unknown.h"
#include "ns3/interface.h"
#include "ns3/ipv4-address.h"
#include "ns3/ptr.h"
#include <stdint.h>
namespace ns3 {
@@ -34,22 +35,22 @@ class TraceResolver;
class Ipv4Interface;
class NetDevice;
class IIpv4Private : public NsUnknown
class IIpv4Private : public Interface
{
public:
static const Iid iid;
IIpv4Private (Ipv4 *ipv4);
static const InterfaceId iid;
IIpv4Private (Ptr<Ipv4> ipv4);
virtual ~IIpv4Private ();
TraceResolver *CreateTraceResolver (TraceContext const &context);
void Send (Packet const &packet, Ipv4Address source,
Ipv4Address destination, uint8_t protocol);
Ipv4Interface *FindInterfaceForDevice (NetDevice const*device);
void Receive(Packet& p, NetDevice *device);
Ipv4Interface *FindInterfaceForDevice (Ptr<const NetDevice>device);
void Receive(Packet& p, Ptr<NetDevice> device);
protected:
virtual void DoDispose (void);
private:
Ipv4 *m_ipv4;
Ptr<Ipv4> m_ipv4;
};
} // namespace ns3

View File

@@ -20,21 +20,20 @@
*/
#include "i-udp-impl.h"
#include "udp.h"
#include "ns3/socket.h"
#include "ns3/assert.h"
namespace ns3 {
IUdpImpl::IUdpImpl (Udp *udp)
IUdpImpl::IUdpImpl (Ptr<Udp> udp)
: m_udp (udp)
{
m_udp->Ref ();
}
{}
IUdpImpl::~IUdpImpl ()
{
NS_ASSERT (m_udp == 0);
}
Socket *
Ptr<Socket>
IUdpImpl::CreateSocket (void)
{
return m_udp->CreateSocket ();
@@ -43,11 +42,7 @@ IUdpImpl::CreateSocket (void)
void
IUdpImpl::DoDispose (void)
{
if (m_udp != 0)
{
m_udp->Unref ();
m_udp = 0;
}
m_udp = 0;
IUdp::DoDispose ();
}

View File

@@ -22,6 +22,7 @@
#define I_UDP_IMPL_H
#include "ns3/i-udp.h"
#include "ns3/ptr.h"
namespace ns3 {
@@ -30,15 +31,15 @@ class Udp;
class IUdpImpl : public IUdp
{
public:
IUdpImpl (Udp *udp);
IUdpImpl (Ptr<Udp> udp);
virtual ~IUdpImpl ();
virtual Socket *CreateSocket (void);
virtual Ptr<Socket> CreateSocket (void);
protected:
virtual void DoDispose (void);
private:
Udp *m_udp;
Ptr<Udp> m_udp;
};
} // namespace ns3

View File

@@ -22,7 +22,6 @@
// George F. Riley, Georgia Tech, Fall 2006
#include "ns3/composite-trace-resolver.h"
#include "ns3/application-list.h"
#include "ns3/net-device.h"
#include "l3-demux.h"
@@ -41,42 +40,28 @@ namespace ns3 {
InternetNode::InternetNode()
{
Ipv4 *ipv4 = new Ipv4 (this);
Arp *arp = new Arp (this);
Udp *udp = new Udp (this);
Ptr<Ipv4> ipv4 = MakeNewObject<Ipv4> (this);
Ptr<Arp> arp = MakeNewObject<Arp> (this);
Ptr<Udp> udp = MakeNewObject<Udp> (this);
ApplicationList *applicationList = new ApplicationList(this);
L3Demux *l3Demux = new L3Demux(this);
Ipv4L4Demux *ipv4L4Demux = new Ipv4L4Demux(this);
Ptr<L3Demux> l3Demux = MakeNewObject<L3Demux> (this);
Ptr<Ipv4L4Demux> ipv4L4Demux = MakeNewObject<Ipv4L4Demux> (this);
l3Demux->Insert (ipv4);
l3Demux->Insert (arp);
ipv4L4Demux->Insert (udp);
IUdpImpl *udpImpl = new IUdpImpl (udp);
IArpPrivate *arpPrivate = new IArpPrivate (arp);
IIpv4Impl *ipv4Impl = new IIpv4Impl (ipv4);
IIpv4Private *ipv4Private = new IIpv4Private (ipv4);
Ptr<IUdpImpl> udpImpl = MakeNewObject<IUdpImpl> (udp);
Ptr<IArpPrivate> arpPrivate = MakeNewObject<IArpPrivate> (arp);
Ptr<IIpv4Impl> ipv4Impl = MakeNewObject<IIpv4Impl> (ipv4);
Ptr<IIpv4Private> ipv4Private = MakeNewObject<IIpv4Private> (ipv4);
NsUnknown::AddInterface (ipv4Private);
NsUnknown::AddInterface (ipv4Impl);
NsUnknown::AddInterface (arpPrivate);
NsUnknown::AddInterface (udpImpl);
NsUnknown::AddInterface (applicationList);
NsUnknown::AddInterface (l3Demux);
NsUnknown::AddInterface (ipv4L4Demux);
applicationList->Unref ();
l3Demux->Unref ();
ipv4L4Demux->Unref ();
arp->Unref ();
ipv4->Unref ();
udp->Unref ();
udpImpl->Unref ();
arpPrivate->Unref ();
ipv4Impl->Unref ();
ipv4Private->Unref ();
Interface::AddInterface (ipv4Private);
Interface::AddInterface (ipv4Impl);
Interface::AddInterface (arpPrivate);
Interface::AddInterface (udpImpl);
Interface::AddInterface (l3Demux);
Interface::AddInterface (ipv4L4Demux);
}
InternetNode::~InternetNode ()
@@ -89,14 +74,13 @@ InternetNode::SetName (std::string name)
}
TraceResolver *
InternetNode::CreateTraceResolver (TraceContext const &context)
InternetNode::DoCreateTraceResolver (TraceContext const &context)
{
CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
IIpv4Private *ipv4 = QueryInterface<IIpv4Private> (IIpv4Private::iid);
Ptr<IIpv4Private> ipv4 = QueryInterface<IIpv4Private> (IIpv4Private::iid);
resolver->Add ("ipv4",
MakeCallback (&IIpv4Private::CreateTraceResolver, ipv4),
MakeCallback (&IIpv4Private::CreateTraceResolver, PeekPointer (ipv4)),
InternetNode::IPV4);
ipv4->Unref ();
return resolver;
}
@@ -108,17 +92,16 @@ InternetNode::DoDispose()
}
void
InternetNode::DoAddDevice (NetDevice *device) const
InternetNode::DoAddDevice (Ptr<NetDevice> device) const
{
device->SetReceiveCallback (MakeCallback (&InternetNode::ReceiveFromDevice, this));
}
bool
InternetNode::ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const
InternetNode::ReceiveFromDevice (Ptr<NetDevice> device, const Packet &p, uint16_t protocolNumber) const
{
L3Demux *demux = QueryInterface<L3Demux> (L3Demux::iid);
L3Protocol *target = demux->PeekProtocol (protocolNumber);
demux->Unref ();
Ptr<L3Demux> demux = QueryInterface<L3Demux> (L3Demux::iid);
Ptr<L3Protocol> target = demux->GetProtocol (protocolNumber);
if (target != 0)
{
Packet packet = p;

View File

@@ -41,14 +41,14 @@ public:
};
InternetNode();
virtual ~InternetNode ();
virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
void SetName(std::string name);
protected:
virtual void DoDispose(void);
private:
virtual void DoAddDevice (NetDevice *device) const;
bool ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const;
virtual void DoAddDevice (Ptr<NetDevice> device) const;
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context);
bool ReceiveFromDevice (Ptr<NetDevice> device, const Packet &p, uint16_t protocolNumber) const;
std::string m_name;
};

View File

@@ -31,26 +31,16 @@ namespace ns3 {
* becoming useable, the user must invoke SetUp on them
* once the final Ipv4 address and mask has been set.
*/
Ipv4Interface::Ipv4Interface (NetDevice *nd)
Ipv4Interface::Ipv4Interface (Ptr<NetDevice> nd)
: m_netdevice (nd),
m_ifup(false)
{
if (m_netdevice != 0)
{
m_netdevice->Ref ();
}
}
{}
Ipv4Interface::~Ipv4Interface ()
{
if (m_netdevice != 0)
{
m_netdevice->Unref ();
}
}
{}
NetDevice*
Ipv4Interface::PeekDevice (void) const
Ptr<NetDevice>
Ipv4Interface::GetDevice (void) const
{
return m_netdevice;
}

View File

@@ -25,6 +25,7 @@
#include <list>
#include "ns3/ipv4-address.h"
#include "ns3/ptr.h"
namespace ns3 {
@@ -69,7 +70,7 @@ public:
* This value can be zero in which case the MTU
* of this interface will be 2^(16-1).
*/
Ipv4Interface (NetDevice *nd);
Ipv4Interface (Ptr<NetDevice> nd);
virtual ~Ipv4Interface();
/**
@@ -87,7 +88,7 @@ public:
* \returns the underlying NetDevice. This method can return
* zero if this interface has no associated NetDevice.
*/
NetDevice *PeekDevice (void) const;
Ptr<NetDevice> GetDevice (void) const;
/**
* \param a set the ipv4 address of this interface.
@@ -153,7 +154,7 @@ public:
private:
virtual void SendTo (Packet p, Ipv4Address dest) = 0;
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0;
NetDevice* m_netdevice;
Ptr<NetDevice> m_netdevice;
bool m_ifup;
Ipv4Address m_address;
Ipv4Mask m_netmask;

View File

@@ -30,14 +30,12 @@
namespace ns3 {
const Iid Ipv4L4Demux::iid ("Ipv4L4Demux");
const InterfaceId Ipv4L4Demux::iid ("Ipv4L4Demux");
Ipv4L4Demux::Ipv4L4Demux (Node *node)
: NsUnknown (Ipv4L4Demux::iid),
Ipv4L4Demux::Ipv4L4Demux (Ptr<Node> node)
: Interface (Ipv4L4Demux::iid),
m_node (node)
{
m_node->Ref ();
}
{}
Ipv4L4Demux::~Ipv4L4Demux()
{}
@@ -45,18 +43,14 @@ Ipv4L4Demux::~Ipv4L4Demux()
void
Ipv4L4Demux::DoDispose (void)
{
for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
for (L4List_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
{
(*i)->Dispose ();
(*i)->Unref ();
*i = 0;
}
m_protocols.clear ();
if (m_node != 0)
{
m_node->Unref ();
m_node = 0;
}
NsUnknown::DoDispose ();
m_node = 0;
Interface::DoDispose ();
}
TraceResolver *
@@ -65,25 +59,24 @@ Ipv4L4Demux::CreateTraceResolver (TraceContext const &context)
CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
{
Ipv4L4Protocol *protocol = *i;
Ptr<Ipv4L4Protocol> protocol = *i;
std::string protValue;
std::ostringstream oss (protValue);
oss << (*i)->GetProtocolNumber ();
Ipv4L4ProtocolTraceType protocolNumber = (*i)->GetProtocolNumber ();
resolver->Add (protValue,
MakeCallback (&Ipv4L4Protocol::CreateTraceResolver, protocol),
MakeCallback (&Ipv4L4Protocol::CreateTraceResolver, PeekPointer (protocol)),
protocolNumber);
}
return resolver;
}
void
Ipv4L4Demux::Insert(Ipv4L4Protocol *protocol)
Ipv4L4Demux::Insert(Ptr<Ipv4L4Protocol> protocol)
{
protocol->Ref ();
m_protocols.push_back (protocol);
}
Ipv4L4Protocol*
Ipv4L4Demux::PeekProtocol(int protocolNumber)
Ptr<Ipv4L4Protocol>
Ipv4L4Demux::GetProtocol(int protocolNumber)
{
for (L4List_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
{
@@ -95,7 +88,7 @@ Ipv4L4Demux::PeekProtocol(int protocolNumber)
return 0;
}
void
Ipv4L4Demux::Erase(Ipv4L4Protocol*protocol)
Ipv4L4Demux::Remove (Ptr<Ipv4L4Protocol> protocol)
{
m_protocols.remove (protocol);
}

View File

@@ -26,7 +26,8 @@
#define IPV4_L4_DEMUX_H
#include <list>
#include "ns3/ns-unknown.h"
#include "ns3/interface.h"
#include "ns3/ptr.h"
namespace ns3 {
@@ -38,12 +39,12 @@ class TraceContext;
/**
* \brief L4 Ipv4 Demux
*/
class Ipv4L4Demux : public NsUnknown
class Ipv4L4Demux : public Interface
{
public:
static const Iid iid;
static const InterfaceId iid;
typedef int Ipv4L4ProtocolTraceType;
Ipv4L4Demux (Node *node);
Ipv4L4Demux (Ptr<Node> node);
virtual ~Ipv4L4Demux();
/**
@@ -64,7 +65,7 @@ public:
* a working L4 Protocol and returned from this method.
* The caller does not get ownership of the returned pointer.
*/
void Insert(Ipv4L4Protocol *protocol);
void Insert(Ptr<Ipv4L4Protocol> protocol);
/**
* \param protocolNumber number of protocol to lookup
* in this L4 Demux
@@ -74,19 +75,19 @@ public:
* to forward packets up the stack to the right protocol.
* It is also called from InternetNode::GetUdp for example.
*/
Ipv4L4Protocol* PeekProtocol(int protocolNumber);
Ptr<Ipv4L4Protocol> GetProtocol(int protocolNumber);
/**
* \param protocol protocol to remove from this demux.
*
* The input value to this method should be the value
* returned from the Ipv4L4Protocol::Insert method.
*/
void Erase(Ipv4L4Protocol*protocol);
void Remove (Ptr<Ipv4L4Protocol> protocol);
private:
virtual void DoDispose (void);
typedef std::list<Ipv4L4Protocol*> L4List_t;
typedef std::list<Ptr<Ipv4L4Protocol> > L4List_t;
L4List_t m_protocols;
Node *m_node;
Ptr<Node> m_node;
};
} //namespace ns3

View File

@@ -29,7 +29,6 @@
namespace ns3 {
class Node;
class Packet;
class Ipv4Address;
class TraceResolver;

View File

@@ -27,16 +27,12 @@
namespace ns3 {
Ipv4LoopbackInterface::Ipv4LoopbackInterface (Node *node)
Ipv4LoopbackInterface::Ipv4LoopbackInterface (Ptr<Node> node)
: Ipv4Interface (0),
m_node (node)
{
m_node->Ref ();
}
{}
Ipv4LoopbackInterface::~Ipv4LoopbackInterface ()
{
m_node->Unref ();
}
{}
TraceResolver *
Ipv4LoopbackInterface::DoCreateTraceResolver (TraceContext const &context)
@@ -47,9 +43,8 @@ Ipv4LoopbackInterface::DoCreateTraceResolver (TraceContext const &context)
void
Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest)
{
IIpv4Private *ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
ipv4->Receive (packet, PeekDevice ());
ipv4->Unref ();
Ptr<IIpv4Private> ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
ipv4->Receive (packet, GetDevice ());
}
}//namespace ns3

View File

@@ -23,6 +23,7 @@
#define IPV4_LOOPBACK_INTERFACE_H
#include "ipv4-interface.h"
#include "ns3/ptr.h"
namespace ns3 {
@@ -31,14 +32,14 @@ class Node;
class Ipv4LoopbackInterface : public Ipv4Interface
{
public:
Ipv4LoopbackInterface (Node *node);
Ipv4LoopbackInterface (Ptr<Node> node);
virtual ~Ipv4LoopbackInterface ();
private:
virtual void SendTo (Packet p, Ipv4Address dest);
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context);
Node *m_node;
Ptr<Node> m_node;
};
}//namespace ns3

View File

@@ -27,6 +27,7 @@
#include "ns3/ipv4-address.h"
#include "ns3/ipv4-route.h"
#include "ns3/node.h"
#include "ns3/net-device.h"
#include "ipv4.h"
#include "ipv4-l4-protocol.h"
@@ -42,7 +43,7 @@ namespace ns3 {
const uint16_t Ipv4::PROT_NUMBER = 0x0800;
Ipv4::Ipv4(Node *node)
Ipv4::Ipv4(Ptr<Node> node)
: L3Protocol (PROT_NUMBER, 4),
m_nInterfaces (0),
m_defaultTtl (64),
@@ -51,12 +52,9 @@ Ipv4::Ipv4(Node *node)
m_node (node)
{
SetupLoopback ();
m_node->Ref ();
}
Ipv4::~Ipv4 ()
{
DoDispose ();
}
{}
void
Ipv4::DoDispose (void)
@@ -83,11 +81,7 @@ Ipv4::DoDispose (void)
delete m_defaultRoute;
m_defaultRoute = 0;
}
if (m_node != 0)
{
m_node->Unref ();
m_node = 0;
}
m_node = 0;
L3Protocol::DoDispose ();
}
@@ -317,7 +311,7 @@ Ipv4::RemoveRoute (uint32_t index)
uint32_t
Ipv4::AddInterface (NetDevice *device)
Ipv4::AddInterface (Ptr<NetDevice> device)
{
Ipv4Interface *interface = new ArpIpv4Interface (m_node, device);
return AddIpv4Interface (interface);
@@ -351,11 +345,11 @@ Ipv4::GetNInterfaces (void) const
}
Ipv4Interface *
Ipv4::FindInterfaceForDevice (NetDevice const*device)
Ipv4::FindInterfaceForDevice (Ptr<const NetDevice> device)
{
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
{
if ((*i)->PeekDevice () == device)
if ((*i)->GetDevice () == device)
{
return *i;
}
@@ -364,12 +358,12 @@ Ipv4::FindInterfaceForDevice (NetDevice const*device)
}
void
Ipv4::Receive(Packet& packet, NetDevice *device)
Ipv4::Receive(Packet& packet, Ptr<NetDevice> device)
{
uint32_t index = 0;
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
{
if ((*i)->PeekDevice () == device)
if ((*i)->GetDevice () == device)
{
m_rxTrace (packet, index);
break;
@@ -449,7 +443,7 @@ Ipv4::SendRealOut (Packet const &p, Ipv4Header const &ip, Ipv4Route const &route
bool
Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device)
Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr<NetDevice> device)
{
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
i != m_interfaces.end (); i++)
@@ -465,7 +459,7 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device)
i != m_interfaces.end (); i++)
{
Ipv4Interface *interface = *i;
if (interface->PeekDevice () == device)
if (interface->GetDevice () == device)
{
if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ()))
{
@@ -511,9 +505,8 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device)
void
Ipv4::ForwardUp (Packet p, Ipv4Header const&ip)
{
Ipv4L4Demux *demux = m_node->QueryInterface<Ipv4L4Demux> (Ipv4L4Demux::iid);
Ipv4L4Protocol *protocol = demux->PeekProtocol (ip.GetProtocol ());
demux->Unref ();
Ptr<Ipv4L4Demux> demux = m_node->QueryInterface<Ipv4L4Demux> (Ipv4L4Demux::iid);
Ptr<Ipv4L4Protocol> protocol = demux->GetProtocol (ip.GetProtocol ());
protocol->Receive (p, ip.GetSource (), ip.GetDestination ());
}

View File

@@ -27,6 +27,7 @@
#include "ns3/callback-trace-source.h"
#include "ns3/array-trace-resolver.h"
#include "ns3/ipv4-address.h"
#include "ns3/ptr.h"
#include "l3-protocol.h"
namespace ns3 {
@@ -58,7 +59,7 @@ public:
};
typedef ArrayTraceResolver<Ipv4Interface>::Index InterfaceIndex;
Ipv4(Node *node);
Ipv4(Ptr<Node> node);
virtual ~Ipv4 ();
/**
@@ -164,7 +165,7 @@ public:
* to disable it, you can invoke Ipv4Interface::SetDown which will
* make sure that it is never used during packet forwarding.
*/
uint32_t AddInterface (NetDevice *device);
uint32_t AddInterface (Ptr<NetDevice> device);
/**
* \param i index of interface to return
* \returns the requested interface
@@ -181,7 +182,7 @@ public:
* Try to find an Ipv4Interface whose NetDevice is equal to
* the input NetDevice.
*/
Ipv4Interface *FindInterfaceForDevice (NetDevice const*device);
Ipv4Interface *FindInterfaceForDevice (Ptr<const NetDevice> device);
/**
@@ -191,7 +192,7 @@ public:
* - implement a per-NetDevice ARP cache
* - send back arp replies on the right device
*/
virtual void Receive(Packet& p, NetDevice *device);
virtual void Receive(Packet& p, Ptr<NetDevice> device);
/**
* \param packet packet to send
@@ -219,7 +220,7 @@ protected:
virtual void DoDispose (void);
private:
void SendRealOut (Packet const &packet, Ipv4Header const &ip, Ipv4Route const &route);
bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device);
bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr<NetDevice> device);
void ForwardUp (Packet p, Ipv4Header const&ip);
uint32_t AddIpv4Interface (Ipv4Interface *interface);
void SetupLoopback (void);
@@ -240,7 +241,7 @@ private:
HostRoutes m_hostRoutes;
NetworkRoutes m_networkRoutes;
Ipv4Route *m_defaultRoute;
Node *m_node;
Ptr<Node> m_node;
CallbackTraceSource<Packet const &, uint32_t> m_txTrace;
CallbackTraceSource<Packet const &, uint32_t> m_rxTrace;
CallbackTraceSource<Packet const &> m_dropTrace;

View File

@@ -29,14 +29,12 @@
namespace ns3 {
const Iid L3Demux::iid ("L3Demux");
const InterfaceId L3Demux::iid ("L3Demux");
L3Demux::L3Demux (Node *node)
: NsUnknown (L3Demux::iid),
L3Demux::L3Demux (Ptr<Node> node)
: Interface (L3Demux::iid),
m_node (node)
{
m_node->Ref ();
}
{}
L3Demux::~L3Demux()
{}
@@ -47,15 +45,11 @@ L3Demux::DoDispose (void)
for (L3Map_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
{
i->second->Dispose ();
i->second->Unref ();
i->second = 0;
}
m_protocols.clear ();
if (m_node != 0)
{
m_node->Unref ();
m_node = 0;
}
NsUnknown::DoDispose ();
m_node = 0;
Interface::DoDispose ();
}
TraceResolver *
@@ -69,23 +63,25 @@ L3Demux::CreateTraceResolver (TraceContext const &context) const
oss << i->second->GetProtocolNumber ();
ProtocolTraceType context = i->second->GetProtocolNumber ();
resolver->Add (protValue,
MakeCallback (&L3Protocol::CreateTraceResolver, i->second),
MakeCallback (&L3Protocol::CreateTraceResolver, PeekPointer (i->second)),
context);
}
return resolver;
}
void L3Demux::Insert(L3Protocol *p)
void L3Demux::Insert(Ptr<L3Protocol> p)
{
p->Ref ();
m_protocols.insert(L3Map_t::value_type(p->GetProtocolNumber (), p));
}
L3Protocol*
L3Demux::PeekProtocol (int p)
Ptr<L3Protocol>
L3Demux::GetProtocol (int p)
{ // Look up a protocol by protocol number
L3Map_t::iterator i = m_protocols.find(p);
if (i == m_protocols.end()) return 0; // Not found
if (i == m_protocols.end())
{
return 0;
}
return i->second; // Return the protocol
}

View File

@@ -28,7 +28,8 @@
#define L3_DEMUX_H
#include <map>
#include "ns3/ns-unknown.h"
#include "ns3/interface.h"
#include "ns3/ptr.h"
namespace ns3 {
@@ -40,12 +41,12 @@ class TraceContext;
/**
* \brief L3 Demux
*/
class L3Demux : public NsUnknown
class L3Demux : public Interface
{
public:
static const Iid iid;
static const InterfaceId iid;
typedef int ProtocolTraceType;
L3Demux(Node *node);
L3Demux(Ptr<Node> node);
virtual ~L3Demux();
/**
@@ -67,7 +68,7 @@ public:
* a working L3 Protocol and returned from this method.
* The caller does not get ownership of the returned pointer.
*/
void Insert(ns3::L3Protocol * protocol);
void Insert(Ptr<L3Protocol> protocol);
/**
* \param protocolNumber number of protocol to lookup
* in this L4 Demux
@@ -77,20 +78,13 @@ public:
* to forward packets up the stack to the right protocol.
* It is also called from InternetNode::GetIpv4 for example.
*/
ns3::L3Protocol* PeekProtocol (int protocolNumber);
/**
* \param protocol protocol to remove from this demux.
*
* The input value to this method should be the value
* returned from the L3Protocol::Insert method.
*/
void Erase(ns3::L3Protocol*protocol);
Ptr<L3Protocol> GetProtocol (int protocolNumber);
protected:
virtual void DoDispose (void);
private:
typedef std::map<int, ns3::L3Protocol*> L3Map_t;
typedef std::map<int, Ptr<ns3::L3Protocol> > L3Map_t;
Node *m_node;
Ptr<Node> m_node;
L3Map_t m_protocols;
};

View File

@@ -26,12 +26,12 @@
#define L3_PROTOCOL_H
#include "ns3/object.h"
#include "ns3/ptr.h"
namespace ns3 {
class Packet;
class NetDevice;
class Node;
class TraceResolver;
class TraceContext;
@@ -54,7 +54,7 @@ public:
* - implement a per-NetDevice ARP cache
* - send back arp replies on the right device
*/
virtual void Receive(Packet& p, NetDevice *device) = 0;
virtual void Receive(Packet& p, Ptr<NetDevice> device) = 0;
protected:
virtual void DoDispose (void);

View File

@@ -84,7 +84,7 @@ PcapTrace::LogIp (TraceContext const &context, Packet const &p, uint32_t interfa
{
NodeList::NodeIndex nodeIndex;
context.Get (nodeIndex);
uint32_t nodeId = NodeList::PeekNode (nodeIndex)->GetId ();
uint32_t nodeId = NodeList::GetNode (nodeIndex)->GetId ();
PcapWriter *writer = GetStream (nodeId, interfaceIndex);
writer->WritePacket (p);
}

View File

@@ -26,7 +26,7 @@
namespace ns3 {
UdpSocket::UdpSocket (Node *node, Udp *udp)
UdpSocket::UdpSocket (Ptr<Node> node, Ptr<Udp> udp)
: m_endPoint (0),
m_node (node),
m_udp (udp),
@@ -34,17 +34,10 @@ UdpSocket::UdpSocket (Node *node, Udp *udp)
m_shutdownSend (false),
m_shutdownRecv (false),
m_connected (false)
{
m_udp->Ref ();
m_node->Ref ();
}
{}
UdpSocket::~UdpSocket ()
{
if (m_node != 0)
{
m_node->Unref ();
m_node = 0;
}
m_node = 0;
if (m_endPoint != 0)
{
NS_ASSERT (m_udp != 0);
@@ -60,15 +53,11 @@ UdpSocket::~UdpSocket ()
m_udp->DeAllocate (m_endPoint);
NS_ASSERT (m_endPoint == 0);
}
if (m_udp != 0)
{
m_udp->Unref ();
m_udp = 0;
}
m_udp = 0;
}
Node *
UdpSocket::PeekNode (void) const
Ptr<Node>
UdpSocket::GetNode (void) const
{
return m_node;
}
@@ -76,17 +65,9 @@ UdpSocket::PeekNode (void) const
void
UdpSocket::Destroy (void)
{
if (m_node != 0)
{
m_node->Unref ();
m_node = 0;
}
m_node = 0;
m_endPoint = 0;
if (m_udp != 0)
{
m_udp->Unref ();
m_udp = 0;
}
m_udp = 0;
}
int
UdpSocket::FinishBind (void)
@@ -144,7 +125,7 @@ UdpSocket::ShutdownRecv (void)
}
void
UdpSocket::DoClose(ns3::Callback<void, Socket*> closeCompleted)
UdpSocket::DoClose(ns3::Callback<void, Ptr<Socket> > closeCompleted)
{
// XXX: we should set the close state and check it in all API methods.
if (!closeCompleted.IsNull ())
@@ -155,9 +136,9 @@ UdpSocket::DoClose(ns3::Callback<void, Socket*> closeCompleted)
void
UdpSocket::DoConnect(const Ipv4Address & address,
uint16_t portNumber,
ns3::Callback<void, Socket*> connectionSucceeded,
ns3::Callback<void, Socket*> connectionFailed,
ns3::Callback<void, Socket*> halfClose)
ns3::Callback<void, Ptr<Socket> > connectionSucceeded,
ns3::Callback<void, Ptr<Socket> > connectionFailed,
ns3::Callback<void, Ptr<Socket> > halfClose)
{
m_defaultAddress = address;
m_defaultPort = portNumber;
@@ -168,9 +149,9 @@ UdpSocket::DoConnect(const Ipv4Address & address,
m_connected = true;
}
int
UdpSocket::DoAccept(ns3::Callback<bool, Socket*, const Ipv4Address&, uint16_t> connectionRequest,
ns3::Callback<void, Socket*, const Ipv4Address&, uint16_t> newConnectionCreated,
ns3::Callback<void, Socket*> closeRequested)
UdpSocket::DoAccept(ns3::Callback<bool, Ptr<Socket>, const Ipv4Address&, uint16_t> connectionRequest,
ns3::Callback<void, Ptr<Socket>, const Ipv4Address&, uint16_t> newConnectionCreated,
ns3::Callback<void, Ptr<Socket> > closeRequested)
{
// calling accept on a udp socket is a programming error.
m_errno = EOPNOTSUPP;
@@ -179,7 +160,7 @@ UdpSocket::DoAccept(ns3::Callback<bool, Socket*, const Ipv4Address&, uint16_t> c
int
UdpSocket::DoSend (const uint8_t* buffer,
uint32_t size,
ns3::Callback<void, Socket*, uint32_t> dataSent)
ns3::Callback<void, Ptr<Socket>, uint32_t> dataSent)
{
if (!m_connected)
{
@@ -199,7 +180,7 @@ UdpSocket::DoSend (const uint8_t* buffer,
}
int
UdpSocket::DoSendPacketTo (const Packet &p, Ipv4Address daddr, uint16_t dport,
ns3::Callback<void, Socket*, uint32_t> dataSent)
ns3::Callback<void, Ptr<Socket>, uint32_t> dataSent)
{
if (m_endPoint == 0)
{
@@ -228,7 +209,7 @@ UdpSocket::DoSendTo(const Ipv4Address &address,
uint16_t port,
const uint8_t *buffer,
uint32_t size,
ns3::Callback<void, Socket*, uint32_t> dataSent)
ns3::Callback<void, Ptr<Socket>, uint32_t> dataSent)
{
if (m_connected)
{
@@ -247,12 +228,12 @@ UdpSocket::DoSendTo(const Ipv4Address &address,
return DoSendPacketTo (p, address, port, dataSent);
}
void
UdpSocket::DoRecv(ns3::Callback<void, Socket*, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> callback)
UdpSocket::DoRecv(ns3::Callback<void, Ptr<Socket>, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> callback)
{
m_rxCallback = callback;
}
void
UdpSocket::DoRecvDummy(ns3::Callback<void, Socket*, uint32_t,const Ipv4Address&, uint16_t> callback)
UdpSocket::DoRecvDummy(ns3::Callback<void, Ptr<Socket>, uint32_t,const Ipv4Address&, uint16_t> callback)
{
m_dummyRxCallback = callback;
}

View File

@@ -24,6 +24,7 @@
#include <stdint.h>
#include "ns3/callback.h"
#include "ns3/socket.h"
#include "ns3/ptr.h"
namespace ns3 {
@@ -38,11 +39,11 @@ public:
/**
* Create an unbound udp socket.
*/
UdpSocket (Node *node, Udp *udp);
UdpSocket (Ptr<Node> node, Ptr<Udp> udp);
virtual ~UdpSocket ();
virtual enum SocketErrno GetErrno (void) const;
virtual Node *PeekNode (void) const;
virtual Ptr<Node> GetNode (void) const;
virtual int Bind (void);
virtual int Bind (Ipv4Address address);
virtual int Bind (uint16_t port);
@@ -51,25 +52,25 @@ public:
virtual int ShutdownRecv (void);
private:
virtual void DoClose(ns3::Callback<void, Socket*> closeCompleted);
virtual void DoClose(ns3::Callback<void, Ptr<Socket> > closeCompleted);
virtual void DoConnect(const Ipv4Address & address,
uint16_t portNumber,
ns3::Callback<void, Socket*> connectionSucceeded,
ns3::Callback<void, Socket*> connectionFailed,
ns3::Callback<void, Socket*> halfClose);
virtual int DoAccept(ns3::Callback<bool, Socket*, const Ipv4Address&, uint16_t> connectionRequest,
ns3::Callback<void, Socket*, const Ipv4Address&, uint16_t> newConnectionCreated,
ns3::Callback<void, Socket*> closeRequested);
ns3::Callback<void, Ptr<Socket> > connectionSucceeded,
ns3::Callback<void, Ptr<Socket> > connectionFailed,
ns3::Callback<void, Ptr<Socket> > halfClose);
virtual int DoAccept(ns3::Callback<bool, Ptr<Socket>, const Ipv4Address&, uint16_t> connectionRequest,
ns3::Callback<void, Ptr<Socket>, const Ipv4Address&, uint16_t> newConnectionCreated,
ns3::Callback<void, Ptr<Socket> > closeRequested);
virtual int DoSend (const uint8_t* buffer,
uint32_t size,
ns3::Callback<void, Socket*, uint32_t> dataSent);
ns3::Callback<void, Ptr<Socket>, uint32_t> dataSent);
virtual int DoSendTo(const Ipv4Address &address,
uint16_t port,
const uint8_t *buffer,
uint32_t size,
ns3::Callback<void, Socket*, uint32_t> dataSent);
virtual void DoRecv(ns3::Callback<void, Socket*, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t>);
virtual void DoRecvDummy(ns3::Callback<void, Socket*, uint32_t,const Ipv4Address&, uint16_t>);
ns3::Callback<void, Ptr<Socket>, uint32_t> dataSent);
virtual void DoRecv(ns3::Callback<void, Ptr<Socket>, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t>);
virtual void DoRecvDummy(ns3::Callback<void, Ptr<Socket>, uint32_t,const Ipv4Address&, uint16_t>);
private:
friend class Udp;
@@ -78,15 +79,15 @@ private:
void ForwardUp (const Packet &p, Ipv4Address saddr, uint16_t sport);
void Destroy (void);
int DoSendPacketTo (const Packet &p, Ipv4Address daddr, uint16_t dport,
ns3::Callback<void, Socket*, uint32_t> dataSent);
ns3::Callback<void, Ptr<Socket>, uint32_t> dataSent);
Ipv4EndPoint *m_endPoint;
Node *m_node;
Udp *m_udp;
Ptr<Node> m_node;
Ptr<Udp> m_udp;
Ipv4Address m_defaultAddress;
uint16_t m_defaultPort;
Callback<void,Socket*,uint32_t,const Ipv4Address &,uint16_t> m_dummyRxCallback;
Callback<void,Socket*,uint8_t const*,uint32_t,const Ipv4Address &,uint16_t> m_rxCallback;
Callback<void,Ptr<Socket>,uint32_t,const Ipv4Address &,uint16_t> m_dummyRxCallback;
Callback<void,Ptr<Socket>,uint8_t const*,uint32_t,const Ipv4Address &,uint16_t> m_rxCallback;
enum SocketErrno m_errno;
bool m_shutdownSend;
bool m_shutdownRecv;

View File

@@ -38,13 +38,11 @@ namespace ns3 {
/* see http://www.iana.org/assignments/protocol-numbers */
const uint8_t Udp::PROT_NUMBER = 17;
Udp::Udp (Node *node)
Udp::Udp (Ptr<Node> node)
: Ipv4L4Protocol (PROT_NUMBER, 2),
m_node (node),
m_endPoints (new Ipv4EndPointDemux ())
{
m_node->Ref ();
}
{}
Udp::~Udp ()
{}
@@ -63,18 +61,15 @@ Udp::DoDispose (void)
delete m_endPoints;
m_endPoints = 0;
}
if (m_node != 0)
{
m_node->Unref ();
m_node = 0;
}
m_node = 0;
Ipv4L4Protocol::DoDispose ();
}
Socket *
Ptr<Socket>
Udp::CreateSocket (void)
{
return new UdpSocket (m_node, this);
Ptr<Socket> socket = MakeNewObject<UdpSocket> (m_node, this);
return socket;
}
Ipv4EndPoint *
@@ -142,11 +137,10 @@ Udp::Send (Packet packet,
packet.AddHeader (udpHeader);
IIpv4Private *ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
Ptr<IIpv4Private> ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
if (ipv4 != 0)
{
ipv4->Send (packet, saddr, daddr, PROT_NUMBER);
ipv4->Unref ();
}
}

View File

@@ -26,6 +26,7 @@
#include "ns3/packet.h"
#include "ns3/ipv4-address.h"
#include "ns3/ptr.h"
#include "ipv4-end-point-demux.h"
#include "ipv4-l4-protocol.h"
@@ -40,12 +41,12 @@ class Udp : public Ipv4L4Protocol {
public:
static const uint8_t PROT_NUMBER;
Udp (Node *node);
Udp (Ptr<Node> node);
virtual ~Udp ();
virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
Socket *CreateSocket (void);
Ptr<Socket> CreateSocket (void);
Ipv4EndPoint *Allocate (void);
Ipv4EndPoint *Allocate (Ipv4Address address);
@@ -67,7 +68,7 @@ public:
protected:
virtual void DoDispose (void);
private:
Node *m_node;
Ptr<Node> m_node;
Ipv4EndPointDemux *m_endPoints;
};