move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
This commit is contained in:
1 parent
50c4686482
commit
b5d1d295d6
69 files changed
+3001
-982
No files matched your search
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/composite-trace-resolver.h"
|
||||
|
||||
#include "arp-ipv4-interface.h"
|
||||
#include "arp.h"
|
||||
@@ -37,6 +38,20 @@ ArpIpv4Interface::ArpIpv4Interface (Node *node, NetDevice *device)
|
||||
ArpIpv4Interface::~ArpIpv4Interface ()
|
||||
{}
|
||||
|
||||
TraceResolver *
|
||||
ArpIpv4Interface::DoCreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
|
||||
if (GetDevice () != 0)
|
||||
{
|
||||
resolver->Add ("netdevice",
|
||||
MakeCallback (&NetDevice::CreateTraceResolver, GetDevice ()),
|
||||
ArpIpv4Interface::NETDEVICE);
|
||||
}
|
||||
|
||||
return resolver;
|
||||
}
|
||||
|
||||
void
|
||||
ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest)
|
||||
{
|
||||
|
||||
@@ -31,11 +31,16 @@ class Node;
|
||||
class ArpIpv4Interface : public Ipv4Interface
|
||||
{
|
||||
public:
|
||||
enum TraceType {
|
||||
NETDEVICE,
|
||||
ARP,
|
||||
};
|
||||
ArpIpv4Interface (Node *node, NetDevice *device);
|
||||
virtual ~ArpIpv4Interface ();
|
||||
|
||||
private:
|
||||
virtual void SendTo (Packet p, Ipv4Address dest);
|
||||
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context);
|
||||
Node *m_node;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/debug.h"
|
||||
#include "ns3/empty-trace-resolver.h"
|
||||
#include "arp.h"
|
||||
#include "arp-header.h"
|
||||
#include "arp-cache.h"
|
||||
@@ -53,6 +54,12 @@ Arp::Copy (Node *node) const
|
||||
return new Arp (node);
|
||||
}
|
||||
|
||||
TraceResolver *
|
||||
Arp::CreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
return new EmptyTraceResolver (context);
|
||||
}
|
||||
|
||||
ArpCache *
|
||||
Arp::FindCache (NetDevice *device)
|
||||
{
|
||||
|
||||
@@ -32,6 +32,8 @@ class ArpCache;
|
||||
class NetDevice;
|
||||
class Node;
|
||||
class Packet;
|
||||
class TraceResolver;
|
||||
class TraceContext;
|
||||
|
||||
class Arp : public L3Protocol
|
||||
{
|
||||
@@ -42,6 +44,8 @@ public:
|
||||
~Arp ();
|
||||
virtual Arp *Copy (Node *node) const;
|
||||
|
||||
virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
|
||||
virtual void Receive(Packet& p, NetDevice &device);
|
||||
bool Lookup (Packet &p, Ipv4Address destination,
|
||||
NetDevice *device,
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 University of Washington
|
||||
*
|
||||
* 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: Craig Dowell <craigdo@ee.washingon.edu>
|
||||
*
|
||||
* Thu Feb 15 14:50:46 PST 2007 craigdo: Created.
|
||||
*/
|
||||
|
||||
#include "ns3/debug.h"
|
||||
#include "channel.h"
|
||||
|
||||
NS_DEBUG_COMPONENT_DEFINE ("Channel");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
Channel::Channel ()
|
||||
: m_name("Channel")
|
||||
{
|
||||
NS_DEBUG("Channel::Channel ()");
|
||||
}
|
||||
|
||||
Channel::Channel (std::string name)
|
||||
: m_name(name)
|
||||
{
|
||||
NS_DEBUG("Channel::Channel (" << name << ")");
|
||||
}
|
||||
|
||||
Channel::~Channel ()
|
||||
{
|
||||
NS_DEBUG("Channel::~Channel ()");
|
||||
}
|
||||
|
||||
void
|
||||
Channel::SetName(std::string name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
std::string
|
||||
Channel::GetName(void)
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
@@ -0,0 +1,59 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 University of Washington
|
||||
*
|
||||
* 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: Craig Dowell <craigdo@ee.washingon.edu>
|
||||
*
|
||||
* Wed Feb 14 16:05:46 PST 2007 craigdo: Created
|
||||
*/
|
||||
#ifndef CHANNEL_H
|
||||
#define CHANNEL_H
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class NetDevice;
|
||||
|
||||
/**
|
||||
* \brief Abstract Channel Base Class.
|
||||
*
|
||||
* 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:
|
||||
Channel ();
|
||||
Channel (std::string name);
|
||||
virtual ~Channel ();
|
||||
|
||||
void SetName(std::string);
|
||||
std::string GetName(void);
|
||||
|
||||
virtual uint32_t GetNDevices (void) const = 0;
|
||||
virtual NetDevice *GetDevice (uint32_t i) const = 0;
|
||||
|
||||
protected:
|
||||
std::string m_name;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
#endif /* CHANNEL_H */
|
||||
+5
-20
@@ -25,34 +25,19 @@ NS_DEBUG_COMPONENT_DEFINE ("DropTailQueue");
|
||||
namespace ns3 {
|
||||
|
||||
DropTailQueue::DropTailQueue () :
|
||||
Queue (""),
|
||||
Queue (),
|
||||
m_packets (),
|
||||
m_maxPackets(DTQ_NPACKETS_MAX_DEFAULT)
|
||||
{
|
||||
NS_DEBUG("DropTailQueue::DropTailQueue ()");
|
||||
}
|
||||
|
||||
|
||||
DropTailQueue::DropTailQueue (std::string const&name)
|
||||
: Queue (name),
|
||||
m_packets(),
|
||||
m_maxPackets(DTQ_NPACKETS_MAX_DEFAULT)
|
||||
{
|
||||
NS_DEBUG("DropTailQueue::DropTailQueue");
|
||||
}
|
||||
|
||||
DropTailQueue::~DropTailQueue ()
|
||||
{
|
||||
NS_DEBUG("DropTailQueue::~DropTailQueue ()");
|
||||
}
|
||||
|
||||
void
|
||||
DropTailQueue::RegisterTraces (TraceContainer &traceContainer)
|
||||
{
|
||||
Queue::QueueRegisterTraces (traceContainer);
|
||||
}
|
||||
|
||||
void
|
||||
DropTailQueue::SetMaxPackets (uint32_t npackets)
|
||||
{
|
||||
NS_DEBUG("DropTailQueue::SetMaxPackets (" << npackets << ")");
|
||||
@@ -60,7 +45,7 @@ DropTailQueue::SetMaxPackets (uint32_t npackets)
|
||||
m_maxPackets = npackets;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
uint32_t
|
||||
DropTailQueue::GetMaxPackets (void)
|
||||
{
|
||||
NS_DEBUG("DropTailQueue::GetMaxPackets () <= " << m_maxPackets);
|
||||
@@ -68,12 +53,12 @@ DropTailQueue::GetMaxPackets (void)
|
||||
return m_maxPackets;
|
||||
}
|
||||
|
||||
bool
|
||||
bool
|
||||
DropTailQueue::DoEnqueue (const Packet& p)
|
||||
{
|
||||
NS_DEBUG("DropTailQueue::DoEnqueue (" << &p << ")");
|
||||
|
||||
if (GetNPackets () >= m_maxPackets)
|
||||
if (m_packets.size () >= m_maxPackets)
|
||||
{
|
||||
NS_DEBUG("DropTailQueue::DoEnqueue (): Queue full -- droppping pkt");
|
||||
Drop (p);
|
||||
@@ -84,7 +69,7 @@ DropTailQueue::DoEnqueue (const Packet& p)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
bool
|
||||
DropTailQueue::DoDequeue (Packet& p)
|
||||
{
|
||||
NS_DEBUG("DropTailQueue::DoDequeue (" << &p << ")");
|
||||
|
||||
@@ -33,9 +33,6 @@ const int DTQ_NPACKETS_MAX_DEFAULT = 100;
|
||||
class DropTailQueue : public Queue {
|
||||
public:
|
||||
DropTailQueue ();
|
||||
DropTailQueue (std::string const &name);
|
||||
|
||||
void RegisterTraces (TraceContainer &traceContainer);
|
||||
|
||||
virtual ~DropTailQueue();
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
// Implementation of the InternetNode class for ns3.
|
||||
// George F. Riley, Georgia Tech, Fall 2006
|
||||
|
||||
#include "ns3/composite-trace-resolver.h"
|
||||
|
||||
#include "net-device-list.h"
|
||||
#include "l3-demux.h"
|
||||
#include "ipv4-l4-demux.h"
|
||||
@@ -96,6 +98,22 @@ InternetNode::Copy() const
|
||||
return copy;
|
||||
}
|
||||
|
||||
TraceResolver *
|
||||
InternetNode::CreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
|
||||
resolver->Add ("ipv4",
|
||||
MakeCallback (&Ipv4::CreateTraceResolver, GetIpv4 ()),
|
||||
InternetNode::IPV4);
|
||||
resolver->Add ("arp",
|
||||
MakeCallback (&Arp::CreateTraceResolver, GetArp ()),
|
||||
InternetNode::ARP);
|
||||
resolver->Add ("udp",
|
||||
MakeCallback (&Udp::CreateTraceResolver, GetUdp ()),
|
||||
InternetNode::UDP);
|
||||
return resolver;
|
||||
}
|
||||
|
||||
|
||||
NetDeviceList*
|
||||
InternetNode::GetNetDeviceList() const
|
||||
|
||||
@@ -35,11 +35,17 @@ namespace ns3 {
|
||||
class InternetNode : public Node
|
||||
{
|
||||
public:
|
||||
enum TraceType {
|
||||
IPV4,
|
||||
UDP,
|
||||
ARP,
|
||||
};
|
||||
InternetNode();
|
||||
InternetNode(const InternetNode&);
|
||||
InternetNode const &operator = (InternetNode const &o);
|
||||
virtual ~InternetNode ();
|
||||
virtual InternetNode* Copy() const;
|
||||
virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
// Capability access
|
||||
virtual NetDeviceList* GetNetDeviceList() const;
|
||||
virtual L3Demux* GetL3Demux() const;
|
||||
|
||||
@@ -45,6 +45,12 @@ Ipv4Interface::GetDevice (void) const
|
||||
return m_netdevice;
|
||||
}
|
||||
|
||||
TraceResolver *
|
||||
Ipv4Interface::CreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
return DoCreateTraceResolver (context);
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4Interface::SetAddress (Ipv4Address a)
|
||||
{
|
||||
|
||||
@@ -30,6 +30,8 @@ namespace ns3 {
|
||||
|
||||
class NetDevice;
|
||||
class Packet;
|
||||
class TraceResolver;
|
||||
class TraceContext;
|
||||
|
||||
/**
|
||||
* \brief The IPv4 representation of a network interface
|
||||
@@ -62,6 +64,7 @@ public:
|
||||
Ipv4Interface (NetDevice *nd);
|
||||
virtual ~Ipv4Interface();
|
||||
|
||||
TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
NetDevice *GetDevice (void) const;
|
||||
|
||||
void SetAddress (Ipv4Address a);
|
||||
@@ -96,6 +99,7 @@ public:
|
||||
|
||||
private:
|
||||
virtual void SendTo (Packet p, Ipv4Address dest) = 0;
|
||||
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0;
|
||||
NetDevice* m_netdevice;
|
||||
bool m_ifup;
|
||||
Ipv4Address m_address;
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
// Define the layer 4 demultiplexer object for ns3.
|
||||
// George F. Riley, Georgia Tech, Fall 2006
|
||||
|
||||
#include <sstream>
|
||||
#include "ns3/composite-trace-resolver.h"
|
||||
#include "ipv4-l4-demux.h"
|
||||
#include "ipv4-l4-protocol.h"
|
||||
|
||||
@@ -48,6 +50,23 @@ Ipv4L4Demux::Copy(Node *node) const
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
TraceResolver *
|
||||
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;
|
||||
std::string protValue;
|
||||
std::ostringstream oss (protValue);
|
||||
oss << (*i)->GetProtocolNumber ();
|
||||
Ipv4L4ProtocolTraceType protocolNumber = (*i)->GetProtocolNumber ();
|
||||
resolver->Add (protValue,
|
||||
MakeCallback (&Ipv4L4Protocol::CreateTraceResolver, protocol),
|
||||
protocolNumber);
|
||||
}
|
||||
return resolver;
|
||||
}
|
||||
Ipv4L4Protocol*
|
||||
Ipv4L4Demux::Insert(const Ipv4L4Protocol&protocol)
|
||||
{
|
||||
|
||||
@@ -32,12 +32,16 @@ namespace ns3 {
|
||||
|
||||
class Ipv4L4Protocol;
|
||||
class Node;
|
||||
class TraceResolver;
|
||||
class TraceContext;
|
||||
|
||||
class Ipv4L4Demux {
|
||||
public:
|
||||
typedef int Ipv4L4ProtocolTraceType;
|
||||
Ipv4L4Demux (Node *node);
|
||||
virtual ~Ipv4L4Demux();
|
||||
Ipv4L4Demux* Copy(Node *node) const;
|
||||
TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
Ipv4L4Protocol* Insert(const Ipv4L4Protocol&);
|
||||
Ipv4L4Protocol* Lookup(int protocolNumber);
|
||||
void Erase(Ipv4L4Protocol*);
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace ns3 {
|
||||
class Node;
|
||||
class Packet;
|
||||
class Ipv4Address;
|
||||
class TraceResolver;
|
||||
class TraceContext;
|
||||
|
||||
class Ipv4L4Protocol {
|
||||
public:
|
||||
@@ -41,6 +43,7 @@ public:
|
||||
int GetVersion() const;
|
||||
|
||||
virtual Ipv4L4Protocol* Copy(Node *node) const = 0;
|
||||
virtual TraceResolver *CreateTraceResolver (TraceContext const &context) = 0;
|
||||
/**
|
||||
* Called from lower-level layers to send the packet up
|
||||
* in the stack.
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
* Authors:
|
||||
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
|
||||
*/
|
||||
#include "ns3/empty-trace-resolver.h"
|
||||
#include "ipv4-loopback-interface.h"
|
||||
#include "net-device.h"
|
||||
#include "node.h"
|
||||
@@ -33,6 +34,7 @@ public:
|
||||
Node *PeekNode (void) const;
|
||||
private:
|
||||
virtual bool SendTo (Packet& p, const MacAddress& dest);
|
||||
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context);
|
||||
};
|
||||
|
||||
Ipv4DummyNetDevice::Ipv4DummyNetDevice (Node *node)
|
||||
@@ -50,6 +52,11 @@ Ipv4DummyNetDevice::SendTo (Packet& p, const MacAddress& dest)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
TraceResolver *
|
||||
Ipv4DummyNetDevice::DoCreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
return new EmptyTraceResolver (context);
|
||||
}
|
||||
|
||||
|
||||
Ipv4LoopbackInterface::Ipv4LoopbackInterface (Node *node)
|
||||
@@ -68,6 +75,12 @@ Ipv4LoopbackInterface::GetNode (void) const
|
||||
return m_node;
|
||||
}
|
||||
|
||||
TraceResolver *
|
||||
Ipv4LoopbackInterface::DoCreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
return new EmptyTraceResolver (context);
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest)
|
||||
{
|
||||
|
||||
@@ -36,6 +36,7 @@ class Ipv4LoopbackInterface : public Ipv4Interface
|
||||
|
||||
private:
|
||||
virtual void SendTo (Packet p, Ipv4Address dest);
|
||||
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context);
|
||||
Node *GetNode (void) const;
|
||||
|
||||
Node *m_node;
|
||||
|
||||
+35
-5
@@ -21,6 +21,9 @@
|
||||
|
||||
#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 "ipv4.h"
|
||||
#include "ipv4-l4-protocol.h"
|
||||
@@ -68,6 +71,30 @@ Ipv4::~Ipv4 ()
|
||||
delete m_defaultRoute;
|
||||
}
|
||||
|
||||
TraceResolver *
|
||||
Ipv4::CreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
|
||||
resolver->Add ("tx", m_txTrace, Ipv4::TX);
|
||||
resolver->Add ("rx", m_rxTrace, Ipv4::RX);
|
||||
resolver->Add ("drop", m_dropTrace, Ipv4::DROP);
|
||||
resolver->Add ("interfaces",
|
||||
MakeCallback (&Ipv4::InterfacesCreateTraceResolver, this),
|
||||
Ipv4::INTERFACES);
|
||||
return resolver;
|
||||
}
|
||||
|
||||
TraceResolver *
|
||||
Ipv4::InterfacesCreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
ArrayTraceResolver<Ipv4Interface> *resolver =
|
||||
new ArrayTraceResolver<Ipv4Interface>
|
||||
(context,
|
||||
MakeCallback (&Ipv4::GetNInterfaces, this),
|
||||
MakeCallback (&Ipv4::GetInterface, this));
|
||||
return resolver;
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4::SetDefaultTtl (uint8_t ttl)
|
||||
{
|
||||
@@ -77,8 +104,8 @@ Ipv4::SetDefaultTtl (uint8_t ttl)
|
||||
|
||||
void
|
||||
Ipv4::AddHostRouteTo (Ipv4Address dest,
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface)
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface)
|
||||
{
|
||||
Ipv4Route *route = new Ipv4Route ();
|
||||
*route = Ipv4Route::CreateHostRouteTo (dest, nextHop, interface);
|
||||
@@ -281,7 +308,7 @@ Ipv4::GetInterface (uint32_t index)
|
||||
return 0;
|
||||
}
|
||||
uint32_t
|
||||
Ipv4::GetNInterfaces (void) const
|
||||
Ipv4::GetNInterfaces (void)
|
||||
{
|
||||
return m_nInterfaces;
|
||||
}
|
||||
@@ -309,7 +336,7 @@ Ipv4::Copy(Node *node) const
|
||||
void
|
||||
Ipv4::Receive(Packet& packet, NetDevice &device)
|
||||
{
|
||||
// XXX trace here.
|
||||
m_rxTrace (packet);
|
||||
Ipv4Header ipHeader;
|
||||
packet.Peek (ipHeader);
|
||||
packet.Remove (ipHeader);
|
||||
@@ -357,6 +384,7 @@ Ipv4::Send (Packet const &packet,
|
||||
if (route == 0)
|
||||
{
|
||||
NS_DEBUG ("not for me -- forwarding but no route to host. drop.");
|
||||
m_dropTrace (packet);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -370,7 +398,7 @@ Ipv4::SendRealOut (Packet const &p, Ipv4Header const &ip, Ipv4Route const &route
|
||||
packet.Add (ip);
|
||||
Ipv4Interface *outInterface = GetInterface (route.GetInterface ());
|
||||
NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ());
|
||||
// XXX log trace here.
|
||||
m_txTrace (packet);
|
||||
if (route.IsGateway ())
|
||||
{
|
||||
outInterface->Send (packet, route.GetGateway ());
|
||||
@@ -425,6 +453,7 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice &device)
|
||||
// Should send ttl expired here
|
||||
// XXX
|
||||
NS_DEBUG ("not for me -- ttl expired. drop.");
|
||||
m_dropTrace (packet);
|
||||
return true;
|
||||
}
|
||||
ipHeader.SetTtl (ipHeader.GetTtl () - 1);
|
||||
@@ -432,6 +461,7 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice &device)
|
||||
if (route == 0)
|
||||
{
|
||||
NS_DEBUG ("not for me -- forwarding but no route to host. drop.");
|
||||
m_dropTrace (packet);
|
||||
return true;
|
||||
}
|
||||
NS_DEBUG ("not for me -- forwarding.");
|
||||
|
||||
+19
-1
@@ -24,6 +24,8 @@
|
||||
|
||||
#include <list>
|
||||
#include <stdint.h>
|
||||
#include "ns3/callback-trace-source.h"
|
||||
#include "ns3/array-trace-resolver.h"
|
||||
#include "ipv4-address.h"
|
||||
#include "l3-protocol.h"
|
||||
|
||||
@@ -36,6 +38,8 @@ class Ipv4Address;
|
||||
class Ipv4Header;
|
||||
class Ipv4Route;
|
||||
class Node;
|
||||
class TraceResolver;
|
||||
class TraceContext;
|
||||
|
||||
|
||||
/**
|
||||
@@ -46,9 +50,19 @@ class Ipv4 : public L3Protocol
|
||||
public:
|
||||
static const uint16_t PROT_NUMBER;
|
||||
|
||||
enum TraceType {
|
||||
TX,
|
||||
RX,
|
||||
DROP,
|
||||
INTERFACES,
|
||||
};
|
||||
typedef ArrayTraceResolver<Ipv4Interface>::Index InterfaceIndex;
|
||||
|
||||
Ipv4(Node *node);
|
||||
virtual ~Ipv4 ();
|
||||
|
||||
virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
|
||||
void SetDefaultTtl (uint8_t ttl);
|
||||
|
||||
/* add route to host dest through host nextHop
|
||||
@@ -88,7 +102,7 @@ public:
|
||||
|
||||
uint32_t AddInterface (Ipv4Interface *interface);
|
||||
Ipv4Interface * GetInterface (uint32_t i);
|
||||
uint32_t GetNInterfaces (void) const;
|
||||
uint32_t GetNInterfaces (void);
|
||||
Ipv4Interface *FindInterfaceForDevice (NetDevice const*device);
|
||||
|
||||
|
||||
@@ -109,6 +123,7 @@ public:
|
||||
void SendRealOut (Packet const &packet, Ipv4Header const &ip, Ipv4Route const &route);
|
||||
bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice &device);
|
||||
void ForwardUp (Packet p, Ipv4Header const&ip);
|
||||
TraceResolver *InterfacesCreateTraceResolver (TraceContext const &context);
|
||||
|
||||
typedef std::list<Ipv4Interface*> Ipv4InterfaceList;
|
||||
typedef std::list<Ipv4Route *> HostRoutes;
|
||||
@@ -126,6 +141,9 @@ public:
|
||||
NetworkRoutes m_networkRoutes;
|
||||
Ipv4Route *m_defaultRoute;
|
||||
Node *m_node;
|
||||
CallbackTraceSource<Packet const &> m_txTrace;
|
||||
CallbackTraceSource<Packet const &> m_rxTrace;
|
||||
CallbackTraceSource<Packet const &> m_dropTrace;
|
||||
};
|
||||
|
||||
} // Namespace ns3
|
||||
|
||||
+20
-1
@@ -20,7 +20,9 @@
|
||||
//
|
||||
// Implement the L3Protocols capability for ns3.
|
||||
// George F. Riley, Georgia Tech, Fall 2006
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "ns3/composite-trace-resolver.h"
|
||||
#include "l3-demux.h"
|
||||
#include "l3-protocol.h"
|
||||
|
||||
@@ -37,6 +39,23 @@ L3Demux::~L3Demux()
|
||||
delete i->second;
|
||||
}
|
||||
}
|
||||
|
||||
TraceResolver *
|
||||
L3Demux::CreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
|
||||
for (L3Map_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
|
||||
{
|
||||
std::string protValue;
|
||||
std::ostringstream oss (protValue);
|
||||
oss << (i->second)->GetProtocolNumber ();
|
||||
ProtocolTraceType context = (i->second)->GetProtocolNumber ();
|
||||
resolver->Add (protValue,
|
||||
MakeCallback (&L3Protocol::CreateTraceResolver, i->second),
|
||||
context);
|
||||
}
|
||||
return resolver;
|
||||
}
|
||||
|
||||
L3Demux* L3Demux::Copy(Node *node) const
|
||||
{
|
||||
|
||||
@@ -33,14 +33,19 @@ namespace ns3 {
|
||||
|
||||
class L3Protocol;
|
||||
class Node;
|
||||
class TraceResolver;
|
||||
class TraceContext;
|
||||
|
||||
class L3Demux
|
||||
{
|
||||
public:
|
||||
typedef int ProtocolTraceType;
|
||||
L3Demux(Node *node);
|
||||
virtual ~L3Demux();
|
||||
L3Demux* Copy(Node *node) const;
|
||||
|
||||
TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
|
||||
// Insert a new protocol
|
||||
ns3::L3Protocol* Insert(const ns3::L3Protocol&);
|
||||
// Look up a protocol by protocol number
|
||||
|
||||
@@ -33,7 +33,7 @@ L3Protocol::L3Protocol(int protocolNumber, int version)
|
||||
{}
|
||||
L3Protocol::~L3Protocol ()
|
||||
{}
|
||||
|
||||
|
||||
int
|
||||
L3Protocol::GetProtocolNumber (void) const
|
||||
{
|
||||
|
||||
@@ -30,7 +30,8 @@ namespace ns3 {
|
||||
class Packet;
|
||||
class NetDevice;
|
||||
class Node;
|
||||
|
||||
class TraceResolver;
|
||||
class TraceContext;
|
||||
|
||||
/**
|
||||
* ::Send is always defined in subclasses.
|
||||
@@ -44,6 +45,8 @@ public:
|
||||
int GetVersion() const;
|
||||
|
||||
virtual L3Protocol* Copy(Node *node) const = 0;
|
||||
|
||||
virtual TraceResolver *CreateTraceResolver (TraceContext const &context) = 0;
|
||||
/**
|
||||
* Lower layer calls this method after calling L3Demux::Lookup
|
||||
* The ARP subclass needs to know from which NetDevice this
|
||||
|
||||
@@ -163,6 +163,11 @@ NetDevice::Send(Packet& p, const MacAddress& dest, uint16_t protocolNumber)
|
||||
}
|
||||
}
|
||||
|
||||
TraceResolver *
|
||||
NetDevice::CreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
return DoCreateTraceResolver (context);
|
||||
}
|
||||
|
||||
// Receive packet from below
|
||||
bool
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace ns3 {
|
||||
|
||||
class Ipv4L4Demux;
|
||||
class Node;
|
||||
class TraceResolver;
|
||||
class TraceContext;
|
||||
|
||||
/**
|
||||
* \brief Network layer to device interface
|
||||
@@ -58,6 +60,9 @@ class NetDevice {
|
||||
*/
|
||||
NetDevice(Node* node, const MacAddress& addr);
|
||||
virtual ~NetDevice() {}
|
||||
|
||||
TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
|
||||
/**
|
||||
* \return the current MacAddress of this interface.
|
||||
*/
|
||||
@@ -204,6 +209,7 @@ class NetDevice {
|
||||
* MUST override this method.
|
||||
*/
|
||||
virtual bool SendTo (Packet& p, const MacAddress& dest) = 0;
|
||||
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0;
|
||||
Node* m_node;
|
||||
std::string m_name;
|
||||
uint16_t m_ifIndex;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 INRIA
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Authors:
|
||||
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
|
||||
*/
|
||||
|
||||
#include "ns3/array-trace-resolver.h"
|
||||
#include "ns3/trace-root.h"
|
||||
#include "node-list.h"
|
||||
#include "node.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
void
|
||||
NodeList::Add (Node *node)
|
||||
{
|
||||
GetNodes ()->push_back (node);
|
||||
}
|
||||
NodeList::Iterator
|
||||
NodeList::Begin (void)
|
||||
{
|
||||
return GetNodes ()->begin ();
|
||||
}
|
||||
NodeList::Iterator
|
||||
NodeList::End (void)
|
||||
{
|
||||
return GetNodes ()->end ();
|
||||
}
|
||||
|
||||
std::vector<Node *> *
|
||||
NodeList::GetNodes (void)
|
||||
{
|
||||
static bool firstTime = true;
|
||||
if (firstTime)
|
||||
{
|
||||
TraceRoot::Register ("nodes", MakeCallback (&NodeList::CreateTraceResolver));
|
||||
}
|
||||
static std::vector<Node *> nodes;
|
||||
return &nodes;
|
||||
}
|
||||
uint32_t
|
||||
NodeList::GetNNodes (void)
|
||||
{
|
||||
return GetNodes ()->size ();
|
||||
}
|
||||
Node *
|
||||
NodeList::GetNode (uint32_t n)
|
||||
{
|
||||
return (*GetNodes ())[n];
|
||||
}
|
||||
|
||||
TraceResolver *
|
||||
NodeList::CreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
ArrayTraceResolver<Node> *resolver =
|
||||
new ArrayTraceResolver<Node>
|
||||
(context,
|
||||
MakeCallback (&NodeList::GetNNodes),
|
||||
MakeCallback (&NodeList::GetNode));
|
||||
return resolver;
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
@@ -0,0 +1,58 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 INRIA
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Authors:
|
||||
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
|
||||
*/
|
||||
#ifndef NODE_LIST_H
|
||||
#define NODE_LIST_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "ns3/array-trace-resolver.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Node;
|
||||
class CallbackBase;
|
||||
class TraceResolver;
|
||||
class TraceContext;
|
||||
|
||||
class NodeList
|
||||
{
|
||||
public:
|
||||
typedef ArrayTraceResolver<Node>::Index NodeIndex;
|
||||
typedef std::vector<Node *>::iterator Iterator;
|
||||
|
||||
static void Add (Node *node);
|
||||
static Iterator Begin (void);
|
||||
static Iterator End (void);
|
||||
static TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
|
||||
static Node *GetNode (uint32_t n);
|
||||
|
||||
private:
|
||||
static std::vector<Node *> *GetNodes (void);
|
||||
static uint32_t GetNNodes (void);
|
||||
|
||||
};
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
|
||||
#endif /* NODE_LIST_H */
|
||||
@@ -99,6 +99,8 @@ class NetDeviceList;
|
||||
class Ipv4;
|
||||
class Udp;
|
||||
class Arp;
|
||||
class TraceContext;
|
||||
class TraceResolver;
|
||||
|
||||
class Node {
|
||||
public:
|
||||
@@ -107,6 +109,8 @@ public:
|
||||
virtual ~Node();
|
||||
virtual Node* Copy() const = 0;// Make a copy of this node
|
||||
|
||||
virtual TraceResolver *CreateTraceResolver (TraceContext const &context) = 0;
|
||||
|
||||
uint32_t GetId (void) const;
|
||||
uint32_t GetSystemId (void) const;
|
||||
void SetSystemId(uint32_t s);
|
||||
|
||||
+16
-19
@@ -18,20 +18,20 @@
|
||||
*/
|
||||
|
||||
#include "ns3/debug.h"
|
||||
#include "ns3/composite-trace-resolver.h"
|
||||
#include "queue.h"
|
||||
|
||||
NS_DEBUG_COMPONENT_DEFINE ("Queue");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
Queue::Queue(std::string const &name) :
|
||||
Queue::Queue() :
|
||||
m_nBytes(0),
|
||||
m_nTotalReceivedBytes(0),
|
||||
m_nPackets(0),
|
||||
m_nTotalReceivedPackets(0),
|
||||
m_nTotalDroppedBytes(0),
|
||||
m_nTotalDroppedPackets(0),
|
||||
m_name (name)
|
||||
m_nTotalDroppedPackets(0)
|
||||
{
|
||||
NS_DEBUG("Queue::Queue ()");
|
||||
}
|
||||
@@ -41,6 +41,16 @@ Queue::~Queue()
|
||||
NS_DEBUG("Queue::~Queue ()");
|
||||
}
|
||||
|
||||
TraceResolver *
|
||||
Queue::CreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
|
||||
resolver->Add ("enqueue", m_traceEnqueue, Queue::ENQUEUE);
|
||||
resolver->Add ("dequeue", m_traceDequeue, Queue::DEQUEUE);
|
||||
resolver->Add ("drop", m_traceDrop, Queue::DROP);
|
||||
return resolver;
|
||||
}
|
||||
|
||||
bool
|
||||
Queue::Enqueue (const Packet& p)
|
||||
{
|
||||
@@ -48,7 +58,7 @@ Queue::Enqueue (const Packet& p)
|
||||
|
||||
NS_DEBUG("Queue::Enqueue (): m_traceEnqueue (p)");
|
||||
|
||||
m_traceEnqueue (m_name, p);
|
||||
m_traceEnqueue (p);
|
||||
|
||||
bool retval = DoEnqueue (p);
|
||||
if (retval)
|
||||
@@ -77,7 +87,7 @@ Queue::Dequeue (Packet &p)
|
||||
NS_DEBUG("Queue::Dequeue (): m_traceDequeue (p)");
|
||||
|
||||
const Packet packet = p;
|
||||
m_traceDequeue (m_name, packet);
|
||||
m_traceDequeue (packet);
|
||||
}
|
||||
|
||||
return retval;
|
||||
@@ -115,19 +125,6 @@ Queue::IsEmpty (void)
|
||||
return m_nPackets == 0;
|
||||
}
|
||||
|
||||
void
|
||||
Queue::QueueRegisterTraces (TraceContainer &container)
|
||||
{
|
||||
NS_DEBUG("Queue::RegisterTraces (" << &container << ")");
|
||||
|
||||
container.RegisterCallback ("Queue::Enqueue",
|
||||
&m_traceEnqueue);
|
||||
container.RegisterCallback ("Queue::Dequeue",
|
||||
&m_traceDequeue);
|
||||
container.RegisterCallback ("Queue::Drop",
|
||||
&m_traceDrop);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Queue::GetTotalReceivedBytes (void)
|
||||
{
|
||||
@@ -182,7 +179,7 @@ Queue::Drop (const Packet& p)
|
||||
m_nTotalDroppedBytes += p.GetSize ();
|
||||
|
||||
NS_DEBUG("Queue::Drop (): m_traceDrop (p)");
|
||||
m_traceDrop (m_name, p);
|
||||
m_traceDrop (p);
|
||||
}
|
||||
|
||||
}; // namespace ns3
|
||||
+14
-12
@@ -27,17 +27,25 @@
|
||||
|
||||
#include <string>
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/callback-tracer.h"
|
||||
#include "ns3/trace-container.h"
|
||||
#include "ns3/callback-trace-source.h"
|
||||
#include "ns3/trace-resolver.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Queue
|
||||
{
|
||||
public:
|
||||
Queue (std::string const &name);
|
||||
enum TraceType {
|
||||
ENQUEUE,
|
||||
DEQUEUE,
|
||||
DROP,
|
||||
};
|
||||
Queue ();
|
||||
virtual ~Queue ();
|
||||
|
||||
TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
|
||||
bool IsEmpty (void);
|
||||
bool Enqueue (const Packet& p);
|
||||
bool Dequeue (Packet &p);
|
||||
|
||||
@@ -45,8 +53,6 @@ public:
|
||||
uint32_t GetNPackets (void);
|
||||
uint32_t GetNBytes (void);
|
||||
|
||||
bool IsEmpty (void);
|
||||
|
||||
uint32_t GetTotalReceivedBytes (void);
|
||||
uint32_t GetTotalReceivedPackets (void);
|
||||
uint32_t GetTotalDroppedBytes (void);
|
||||
@@ -85,12 +91,11 @@ private:
|
||||
protected:
|
||||
// called by subclasses to notify parent of packet drops.
|
||||
void Drop (const Packet& p);
|
||||
void QueueRegisterTraces (TraceContainer &container);
|
||||
|
||||
private:
|
||||
CallbackTracer<std::string const &, const Packet &> m_traceEnqueue;
|
||||
CallbackTracer<std::string const &, const Packet &> m_traceDequeue;
|
||||
CallbackTracer<std::string const &, const Packet &> m_traceDrop;
|
||||
CallbackTraceSource<const Packet &> m_traceEnqueue;
|
||||
CallbackTraceSource<const Packet &> m_traceDequeue;
|
||||
CallbackTraceSource<const Packet &> m_traceDrop;
|
||||
|
||||
uint32_t m_nBytes;
|
||||
uint32_t m_nTotalReceivedBytes;
|
||||
@@ -99,9 +104,6 @@ private:
|
||||
uint32_t m_nTotalDroppedBytes;
|
||||
uint32_t m_nTotalDroppedPackets;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
|
||||
#if 0
|
||||
// Static methods to manage queue default
|
||||
// Set desired queue default
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/empty-trace-resolver.h"
|
||||
|
||||
#include "udp.h"
|
||||
#include "udp-header.h"
|
||||
#include "ipv4-end-point-demux.h"
|
||||
@@ -46,6 +48,12 @@ Udp::~Udp ()
|
||||
delete m_endPoints;
|
||||
}
|
||||
|
||||
TraceResolver *
|
||||
Udp::CreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
return new EmptyTraceResolver (context);
|
||||
}
|
||||
|
||||
UdpEndPoint *
|
||||
Udp::Allocate (void)
|
||||
{
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
namespace ns3 {
|
||||
|
||||
class Node;
|
||||
class TraceResolver;
|
||||
class TraceContext;
|
||||
|
||||
class Udp : public Ipv4L4Protocol {
|
||||
public:
|
||||
@@ -41,6 +43,8 @@ public:
|
||||
Udp (Node *node);
|
||||
virtual ~Udp ();
|
||||
|
||||
virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
|
||||
|
||||
UdpEndPoint *Allocate (void);
|
||||
UdpEndPoint *Allocate (Ipv4Address address);
|
||||
UdpEndPoint *Allocate (uint16_t port);
|
||||
|
||||
Reference in new issue
Block a user