use the Object::GetTraceResolver tracing support rather than the old adhoc tracing code

This commit is contained in:
Mathieu Lacage committed 2007-08-12 16:28:29 +02:00
1 parent 2df1260c87
commit ec4d9bbcb9
31 files changed
+109 -238

No files matched your search

+3 -3
View File
@@ -19,16 +19,16 @@
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "ns3/assert.h"
#include "ns3/packet.h"
#include "ns3/simulator.h"
#include "arp-cache.h"
#include "arp-header.h"
#include "ipv4-interface.h"
namespace ns3 {
ArpCache::ArpCache (Ptr<NetDevice> device, Ipv4Interface *interface)
ArpCache::ArpCache (Ptr<NetDevice> device, Ptr<Ipv4Interface> interface)
: m_device (device),
m_interface (interface),
m_aliveTimeout (Seconds (120)),
@@ -47,7 +47,7 @@ ArpCache::GetDevice (void) const
return m_device;
}
Ipv4Interface *
Ptr<Ipv4Interface>
ArpCache::GetInterface (void) const
{
return m_interface;
+3 -3
View File
@@ -48,7 +48,7 @@ public:
* \param device The hardware NetDevice associated with this ARP chache
* \param interface the Ipv4Interface associated with this ARP chache
*/
ArpCache (Ptr<NetDevice> device, Ipv4Interface *interface);
ArpCache (Ptr<NetDevice> device, Ptr<Ipv4Interface> interface);
~ArpCache ();
/**
* \return The NetDevice that this ARP cache is associated with
@@ -57,7 +57,7 @@ public:
/**
* \return the Ipv4Interface that this ARP cache is associated with
*/
Ipv4Interface *GetInterface (void) const;
Ptr<Ipv4Interface> GetInterface (void) const;
void SetAliveTimeout (Time aliveTimeout);
void SetDeadTimeout (Time deadTimeout);
@@ -152,7 +152,7 @@ private:
typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash>::iterator CacheI;
Ptr<NetDevice> m_device;
Ipv4Interface *m_interface;
Ptr<Ipv4Interface> m_interface;
Time m_aliveTimeout;
Time m_deadTimeout;
Time m_waitReplyTimeout;
+3 -4
View File
@@ -41,15 +41,14 @@ ArpIpv4Interface::~ArpIpv4Interface ()
{}
Ptr<TraceResolver>
ArpIpv4Interface::DoCreateTraceResolver (void)
ArpIpv4Interface::GetTraceResolver (void)
{
Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
if (GetDevice () != 0)
{
resolver->Add ("netdevice",
MakeCallback (&NetDevice::CreateTraceResolver, PeekPointer (GetDevice ())));
resolver->AddChild ("netdevice", GetDevice ());
}
resolver->SetParent (Ipv4Interface::GetTraceResolver ());
return resolver;
}
+3 -2
View File
@@ -42,9 +42,10 @@ class ArpIpv4Interface : public Ipv4Interface
ArpIpv4Interface (Ptr<Node> node, Ptr<NetDevice> device);
virtual ~ArpIpv4Interface ();
private:
protected:
virtual Ptr<TraceResolver> GetTraceResolver (void);
private:
virtual void SendTo (Packet p, Ipv4Address dest);
virtual Ptr<TraceResolver> DoCreateTraceResolver (void);
Ptr<Node> m_node;
};
+1 -7
View File
@@ -58,12 +58,6 @@ ArpL3Protocol::DoDispose (void)
Object::DoDispose ();
}
Ptr<TraceResolver>
ArpL3Protocol::CreateTraceResolver (void)
{
return Create<EmptyTraceResolver> ();
}
ArpCache *
ArpL3Protocol::FindCache (Ptr<NetDevice> device)
{
@@ -75,7 +69,7 @@ ArpL3Protocol::FindCache (Ptr<NetDevice> device)
}
}
Ptr<Ipv4L3Protocol> ipv4 = m_node->QueryInterface<Ipv4L3Protocol> (Ipv4L3Protocol::iid);
Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device);
Ptr<Ipv4Interface> interface = ipv4->FindInterfaceForDevice (device);
ArpCache * cache = new ArpCache (device, interface);
NS_ASSERT (device->IsBroadcast ());
device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
-2
View File
@@ -48,8 +48,6 @@ public:
*/
ArpL3Protocol (Ptr<Node> node);
virtual ~ArpL3Protocol ();
virtual Ptr<TraceResolver> CreateTraceResolver (void);
/**
* \brief Recieve a packet
*/
+6 -5
View File
@@ -74,13 +74,14 @@ InternetNode::Construct (void)
Object::AddInterface (ipv4L4Demux);
}
void
InternetNode::DoFillTraceResolver (CompositeTraceResolver &resolver)
Ptr<TraceResolver>
InternetNode::GetTraceResolver ()
{
Node::DoFillTraceResolver (resolver);
Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
Ptr<Ipv4L3Protocol> ipv4 = QueryInterface<Ipv4L3Protocol> (Ipv4L3Protocol::iid);
resolver.Add ("ipv4",
MakeCallback (&Ipv4L3Protocol::CreateTraceResolver, PeekPointer (ipv4)));
resolver->AddChild ("ipv4", ipv4);
resolver->SetParent (Node::GetTraceResolver ());
return resolver;
}
void
+1 -1
View File
@@ -42,8 +42,8 @@ public:
protected:
virtual void DoDispose(void);
virtual Ptr<TraceResolver> GetTraceResolver (void);
private:
virtual void DoFillTraceResolver (CompositeTraceResolver &resolver);
bool ReceiveFromDevice (Ptr<NetDevice> device, const Packet &p, uint16_t protocolNumber) const;
void Construct (void);
};
+7 -6
View File
@@ -40,18 +40,19 @@ Ipv4Interface::Ipv4Interface (Ptr<NetDevice> nd)
Ipv4Interface::~Ipv4Interface ()
{}
void
Ipv4Interface::DoDispose (void)
{
m_netdevice = 0;
Object::DoDispose ();
}
Ptr<NetDevice>
Ipv4Interface::GetDevice (void) const
{
return m_netdevice;
}
Ptr<TraceResolver>
Ipv4Interface::CreateTraceResolver (void)
{
return DoCreateTraceResolver ();
}
void
Ipv4Interface::SetAddress (Ipv4Address a)
{
+5 -16
View File
@@ -26,6 +26,7 @@
#include <list>
#include "ns3/ipv4-address.h"
#include "ns3/ptr.h"
#include "ns3/object.h"
namespace ns3 {
@@ -60,9 +61,8 @@ class TraceContext;
*
* Subclasses must implement the two methods:
* - Ipv4Interface::SendTo
* - Ipv4Interface::DoCreateTraceResolver
*/
class Ipv4Interface
class Ipv4Interface : public Object
{
public:
/**
@@ -73,17 +73,6 @@ public:
Ipv4Interface (Ptr<NetDevice> nd);
virtual ~Ipv4Interface();
/**
* \param context the trace context to use to construct the
* TraceResolver to return
* \returns a TraceResolver which can resolve all traces
* performed in this object. The caller must
* delete the returned object.
*
* This method will delegate the work to the private DoCreateTraceResolver
* method which is supposed to be implemented by subclasses.
*/
Ptr<TraceResolver> CreateTraceResolver (void);
/**
* \returns the underlying NetDevice. This method can return
* zero if this interface has no associated NetDevice.
@@ -150,10 +139,10 @@ public:
*/
void Send(Packet p, Ipv4Address dest);
private:
protected:
virtual void DoDispose (void);
private:
virtual void SendTo (Packet p, Ipv4Address dest) = 0;
virtual Ptr<TraceResolver> DoCreateTraceResolver (void) = 0;
Ptr<NetDevice> m_netdevice;
bool m_ifup;
Ipv4Address m_address;
+26 -40
View File
@@ -22,7 +22,6 @@
#include "ns3/packet.h"
#include "ns3/debug.h"
#include "ns3/composite-trace-resolver.h"
#include "ns3/array-trace-resolver.h"
#include "ns3/callback.h"
#include "ns3/ipv4-address.h"
#include "ns3/ipv4-route.h"
@@ -90,26 +89,26 @@ Ipv4L3ProtocolTraceContextElement::GetUid (void)
}
Ipv4l3ProtocolInterfaceIndex::Ipv4l3ProtocolInterfaceIndex ()
Ipv4L3ProtocolInterfaceIndex::Ipv4L3ProtocolInterfaceIndex ()
: m_index (0)
{}
Ipv4l3ProtocolInterfaceIndex::Ipv4l3ProtocolInterfaceIndex (uint32_t index)
Ipv4L3ProtocolInterfaceIndex::Ipv4L3ProtocolInterfaceIndex (uint32_t index)
: m_index (index)
{}
uint32_t
Ipv4l3ProtocolInterfaceIndex::Get (void) const
Ipv4L3ProtocolInterfaceIndex::Get (void) const
{
return m_index;
}
void
Ipv4l3ProtocolInterfaceIndex::Print (std::ostream &os) const
Ipv4L3ProtocolInterfaceIndex::Print (std::ostream &os) const
{
os << "ipv4-interface=" << m_index;
}
uint16_t
Ipv4l3ProtocolInterfaceIndex::GetUid (void)
Ipv4L3ProtocolInterfaceIndex::GetUid (void)
{
static uint16_t uid = AllocateUid<Ipv4l3ProtocolInterfaceIndex> ("Ipv4l3ProtocolInterfaceIndex");
static uint16_t uid = AllocateUid<Ipv4L3ProtocolInterfaceIndex> ("Ipv4L3ProtocolInterfaceIndex");
return uid;
}
@@ -131,10 +130,6 @@ Ipv4L3Protocol::~Ipv4L3Protocol ()
void
Ipv4L3Protocol::DoDispose (void)
{
for (Ipv4InterfaceList::iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
{
delete (*i);
}
m_interfaces.clear ();
m_node = 0;
m_staticRouting->Dispose ();
@@ -145,7 +140,7 @@ Ipv4L3Protocol::DoDispose (void)
void
Ipv4L3Protocol::SetupLoopback (void)
{
Ipv4LoopbackInterface * interface = new Ipv4LoopbackInterface (m_node);
Ptr<Ipv4LoopbackInterface> interface = Create<Ipv4LoopbackInterface> (m_node);
interface->SetAddress (Ipv4Address::GetLoopback ());
interface->SetNetworkMask (Ipv4Mask::GetLoopback ());
uint32_t index = AddIpv4Interface (interface);
@@ -154,24 +149,15 @@ Ipv4L3Protocol::SetupLoopback (void)
}
Ptr<TraceResolver>
Ipv4L3Protocol::CreateTraceResolver (void)
Ipv4L3Protocol::GetTraceResolver (void)
{
Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
resolver->Add ("tx", m_txTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::TX));
resolver->Add ("rx", m_rxTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::RX));
resolver->Add ("drop", m_dropTrace, Ipv4L3ProtocolTraceContextElement (Ipv4L3ProtocolTraceContextElement::DROP));
resolver->Add ("interfaces",
MakeCallback (&Ipv4L3Protocol::InterfacesCreateTraceResolver, this));
return resolver;
}
Ptr<TraceResolver>
Ipv4L3Protocol::InterfacesCreateTraceResolver (void) const
{
Ptr<ArrayTraceResolver<Ipv4Interface *, Ipv4l3ProtocolInterfaceIndex> >resolver =
Create<ArrayTraceResolver<Ipv4Interface *,Ipv4l3ProtocolInterfaceIndex> >
(MakeCallback (&Ipv4L3Protocol::GetNInterfaces, this),
MakeCallback (&Ipv4L3Protocol::GetInterface, this));
resolver->AddArray ("interfaces",
m_interfaces.begin (), m_interfaces.end (),
Ipv4L3ProtocolInterfaceIndex ());
return resolver;
}
@@ -264,18 +250,18 @@ Ipv4L3Protocol::RemoveRoute (uint32_t index)
uint32_t
Ipv4L3Protocol::AddInterface (Ptr<NetDevice> device)
{
Ipv4Interface *interface = new ArpIpv4Interface (m_node, device);
Ptr<Ipv4Interface> interface = Create<ArpIpv4Interface> (m_node, device);
return AddIpv4Interface (interface);
}
uint32_t
Ipv4L3Protocol::AddIpv4Interface (Ipv4Interface *interface)
Ipv4L3Protocol::AddIpv4Interface (Ptr<Ipv4Interface>interface)
{
uint32_t index = m_nInterfaces;
m_interfaces.push_back (interface);
m_nInterfaces++;
return index;
}
Ipv4Interface *
Ptr<Ipv4Interface>
Ipv4L3Protocol::GetInterface (uint32_t index) const
{
uint32_t tmp = 0;
@@ -295,7 +281,7 @@ Ipv4L3Protocol::GetNInterfaces (void) const
return m_nInterfaces;
}
Ipv4Interface *
Ptr<Ipv4Interface>
Ipv4L3Protocol::FindInterfaceForDevice (Ptr<const NetDevice> device)
{
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
@@ -363,7 +349,7 @@ Ipv4L3Protocol::Send (Packet const &packet,
for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin ();
ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
{
Ipv4Interface *outInterface = *ifaceIter;
Ptr<Ipv4Interface> outInterface = *ifaceIter;
Packet packetCopy = packet;
NS_ASSERT (packetCopy.GetSize () <= outInterface->GetMtu ());
@@ -400,7 +386,7 @@ Ipv4L3Protocol::SendRealOut (bool found,
return;
}
packet.AddHeader (ipHeader);
Ipv4Interface *outInterface = GetInterface (route.GetInterface ());
Ptr<Ipv4Interface> outInterface = GetInterface (route.GetInterface ());
NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ());
m_txTrace (packet, route.GetInterface ());
if (route.IsGateway ())
@@ -430,7 +416,7 @@ Ipv4L3Protocol::Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr<NetD
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
i != m_interfaces.end (); i++)
{
Ipv4Interface *interface = *i;
Ptr<Ipv4Interface> interface = *i;
if (interface->GetDevice () == device)
{
if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ()))
@@ -480,43 +466,43 @@ Ipv4L3Protocol::ForwardUp (Packet p, Ipv4Header const&ip)
void
Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address)
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
interface->SetAddress (address);
}
void
Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask)
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
interface->SetNetworkMask (mask);
}
Ipv4Mask
Ipv4L3Protocol::GetNetworkMask (uint32_t i) const
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
return interface->GetNetworkMask ();
}
Ipv4Address
Ipv4L3Protocol::GetAddress (uint32_t i) const
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
return interface->GetAddress ();
}
uint16_t
Ipv4L3Protocol::GetMtu (uint32_t i) const
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
return interface->GetMtu ();
}
bool
Ipv4L3Protocol::IsUp (uint32_t i) const
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
return interface->IsUp ();
}
void
Ipv4L3Protocol::SetUp (uint32_t i)
{
Ipv4Interface *interface = GetInterface (i);
Ptr<Ipv4Interface> interface = GetInterface (i);
interface->SetUp ();
// If interface address and network mask have been set, add a route
@@ -532,7 +518,7 @@ Ipv4L3Protocol::SetUp (uint32_t i)
void
Ipv4L3Protocol::SetDown (uint32_t ifaceIndex)
{
Ipv4Interface *interface = GetInterface (ifaceIndex);
Ptr<Ipv4Interface> interface = GetInterface (ifaceIndex);
interface->SetDown ();
// Remove all routes that are going through this interface
+8 -17
View File
@@ -63,11 +63,11 @@ private:
enum Type m_type;
};
class Ipv4l3ProtocolInterfaceIndex : public TraceContextElement
class Ipv4L3ProtocolInterfaceIndex : public TraceContextElement
{
public:
Ipv4l3ProtocolInterfaceIndex ();
Ipv4l3ProtocolInterfaceIndex (uint32_t index);
Ipv4L3ProtocolInterfaceIndex ();
Ipv4L3ProtocolInterfaceIndex (uint32_t index);
uint32_t Get (void) const;
void Print (std::ostream &os) const;
static uint16_t GetUid (void);
@@ -85,15 +85,6 @@ public:
Ipv4L3Protocol(Ptr<Node> node);
virtual ~Ipv4L3Protocol ();
/**
* \param context the trace context to use to construct the
* TraceResolver to return
* \returns a TraceResolver which can resolve all traces
* performed in this object. The caller must
* delete the returned object.
*/
virtual Ptr<TraceResolver> CreateTraceResolver (void);
/**
* \param ttl default ttl to use
*
@@ -109,7 +100,7 @@ public:
* Try to find an Ipv4Interface whose NetDevice is equal to
* the input NetDevice.
*/
Ipv4Interface *FindInterfaceForDevice (Ptr<const NetDevice> device);
Ptr<Ipv4Interface> FindInterfaceForDevice (Ptr<const NetDevice> device);
/**
* Lower layer calls this method after calling L3Demux::Lookup
@@ -159,7 +150,7 @@ public:
void RemoveRoute (uint32_t i);
uint32_t AddInterface (Ptr<NetDevice> device);
Ipv4Interface * GetInterface (uint32_t i) const;
Ptr<Ipv4Interface> GetInterface (uint32_t i) const;
uint32_t GetNInterfaces (void) const;
@@ -178,6 +169,7 @@ public:
protected:
virtual void DoDispose (void);
virtual Ptr<TraceResolver> GetTraceResolver (void);
private:
@@ -187,11 +179,10 @@ private:
Ipv4Header const &ipHeader);
bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr<NetDevice> device);
void ForwardUp (Packet p, Ipv4Header const&ip);
uint32_t AddIpv4Interface (Ipv4Interface *interface);
uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface);
void SetupLoopback (void);
Ptr<TraceResolver> InterfacesCreateTraceResolver (void) const;
typedef std::list<Ipv4Interface*> Ipv4InterfaceList;
typedef std::list<Ptr<Ipv4Interface> > Ipv4InterfaceList;
typedef std::list< std::pair< int, Ptr<Ipv4RoutingProtocol> > > Ipv4RoutingProtocolList;
Ipv4InterfaceList m_interfaces;
+3 -4
View File
@@ -79,7 +79,7 @@ Ipv4L4Demux::DoDispose (void)
}
Ptr<TraceResolver>
Ipv4L4Demux::CreateTraceResolver (void)
Ipv4L4Demux::GetTraceResolver (void)
{
Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
@@ -89,10 +89,9 @@ Ipv4L4Demux::CreateTraceResolver (void)
std::ostringstream oss (protValue);
oss << (*i)->GetProtocolNumber ();
Ipv4L4ProtocolTraceContextElement protocolNumber = (*i)->GetProtocolNumber ();
resolver->Add (protValue,
MakeCallback (&Ipv4L4Protocol::CreateTraceResolver, PeekPointer (protocol)),
protocolNumber);
resolver->AddChild (protValue, protocol, protocolNumber);
}
resolver->SetParent (Object::GetTraceResolver ());
return resolver;
}
void
+3 -9
View File
@@ -59,14 +59,6 @@ public:
Ipv4L4Demux (Ptr<Node> node);
virtual ~Ipv4L4Demux();
/**
* \param context the trace context to use to construct the
* TraceResolver to return
* \returns a TraceResolver which can resolve all traces
* performed in this object. The caller must
* delete the returned object.
*/
Ptr<TraceResolver> CreateTraceResolver (void);
/**
* \param protocol a template for the protocol to add to this L4 Demux.
* \returns the L4Protocol effectively added.
@@ -95,8 +87,10 @@ public:
* returned from the Ipv4L4Protocol::Insert method.
*/
void Remove (Ptr<Ipv4L4Protocol> protocol);
private:
protected:
Ptr<TraceResolver> GetTraceResolver (void);
virtual void DoDispose (void);
private:
typedef std::list<Ptr<Ipv4L4Protocol> > L4List_t;
L4List_t m_protocols;
Ptr<Node> m_node;
-6
View File
@@ -37,10 +37,6 @@ class TraceContext;
/**
* \brief L4 Protocol base class
*
* All subclasses must implement:
* - Ipv4L4Protocol::Copy
* - Ipv4L4Protocol::CreateTraceResolver
*
* If you want to implement a new L4 protocol, all you have to do is
* implement a subclass of this base class and add it to an L4Demux.
*/
@@ -59,8 +55,6 @@ public:
*/
int GetVersion() const;
virtual Ptr<TraceResolver> CreateTraceResolver () = 0;
/**
* \param p packet to forward up
* \param source source address of packet received
@@ -33,13 +33,6 @@ Ipv4LoopbackInterface::Ipv4LoopbackInterface (Ptr<Node> node)
{}
Ipv4LoopbackInterface::~Ipv4LoopbackInterface ()
{}
Ptr<TraceResolver>
Ipv4LoopbackInterface::DoCreateTraceResolver (void)
{
return Create<EmptyTraceResolver> ();
}
void
Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest)
{
@@ -43,7 +43,6 @@ class Ipv4LoopbackInterface : public Ipv4Interface
private:
virtual void SendTo (Packet p, Ipv4Address dest);
virtual Ptr<TraceResolver> DoCreateTraceResolver (void);
Ptr<Node> m_node;
};
-6
View File
@@ -45,12 +45,6 @@ UdpL4Protocol::UdpL4Protocol (Ptr<Node> node)
UdpL4Protocol::~UdpL4Protocol ()
{}
Ptr<TraceResolver>
UdpL4Protocol::CreateTraceResolver (void)
{
return Create<EmptyTraceResolver> ();
}
void
UdpL4Protocol::DoDispose (void)
{
-1
View File
@@ -49,7 +49,6 @@ public:
UdpL4Protocol (Ptr<Node> node);
virtual ~UdpL4Protocol ();
virtual Ptr<TraceResolver> CreateTraceResolver (void);
/**
* \return A smart Socket pointer to a UdpSocket, allocated by this instance
* of the UDP protocol