fix tracing

This commit is contained in:
Mathieu Lacage
2007-08-01 13:53:48 +02:00
parent dd3ca3aa63
commit 707b722c36
11 changed files with 70 additions and 100 deletions

View File

@@ -90,13 +90,13 @@ int main (int argc, char *argv[])
// create the address which identifies n1 from n0
PacketSocketAddress n0ToN1;
n0ToN1.SetDevice (n0If->GetIfIndex ()); // set outgoing interface for outgoing packets
n0ToN1.SetSingleDevice (n0If->GetIfIndex ()); // set outgoing interface for outgoing packets
n0ToN1.SetPhysicalAddress (n1If->GetAddress ()); // set destination address for outgoing packets
n0ToN1.SetProtocol (2); // set arbitrary protocol for outgoing packets
// create the address which identifies n0 from n3
PacketSocketAddress n3ToN0;
n3ToN0.SetDevice (n3If->GetIfIndex ());
n3ToN0.SetSingleDevice (n3If->GetIfIndex ());
n3ToN0.SetPhysicalAddress (n0If->GetAddress ());
n3ToN0.SetProtocol (3);

View File

@@ -26,12 +26,6 @@
#include "ns3/node.h"
#include "ns3/queue.h"
#include "ns3/node-list.h"
#include "ns3/llc-snap-header.h"
#include "ipv4-l3-protocol.h"
#include "arp-header.h"
#include "udp-header.h"
#include "ipv4-header.h"
namespace ns3 {
@@ -58,40 +52,6 @@ AsciiTrace::TraceAllNetDeviceRx (void)
MakeCallback (&AsciiTrace::LogDevRx, this));
}
void
AsciiTrace::PrintType (Packet const &packet)
{
Packet p = packet;
LlcSnapHeader llc;
p.RemoveHeader (llc);
switch (llc.GetType ())
{
case 0x0800: {
Ipv4Header ipv4;
p.RemoveHeader (ipv4);
if (ipv4.GetProtocol () == 17)
{
UdpHeader udp;
p.RemoveHeader (udp);
m_os << "udp size=" << p.GetSize ();
}
} break;
case 0x0806: {
ArpHeader arp;
p.RemoveHeader (arp);
m_os << "arp ";
if (arp.IsRequest ())
{
m_os << "request";
}
else
{
m_os << "reply ";
}
} break;
}
}
void
AsciiTrace::LogDevQueue (TraceContext const &context, Packet const &packet)
{
@@ -113,9 +73,9 @@ AsciiTrace::LogDevQueue (TraceContext const &context, Packet const &packet)
NodeList::NodeIndex nodeIndex;
context.Get (nodeIndex);
m_os << "node=" << NodeList::GetNode (nodeIndex)->GetId () << " ";
Ipv4L3Protocol::InterfaceIndex interfaceIndex;
context.Get (interfaceIndex);
m_os << "interface=" << interfaceIndex << " ";
Node::NetDeviceIndex deviceIndex;
context.Get (deviceIndex);
m_os << "device=" << deviceIndex << " ";
m_os << "pkt-uid=" << packet.GetUid () << " ";
packet.Print (m_os);
m_os << std::endl;
@@ -127,9 +87,9 @@ AsciiTrace::LogDevRx (TraceContext const &context, Packet &p)
NodeList::NodeIndex nodeIndex;
context.Get (nodeIndex);
m_os << "node=" << NodeList::GetNode (nodeIndex)->GetId () << " ";
Ipv4L3Protocol::InterfaceIndex interfaceIndex;
context.Get (interfaceIndex);
m_os << "interface=" << interfaceIndex << " ";
Node::NetDeviceIndex deviceIndex;
context.Get (deviceIndex);
m_os << "device=" << deviceIndex << " ";
m_os << "pkt-uid=" << p.GetUid () << " ";
p.Print (m_os);
m_os << std::endl;

View File

@@ -37,7 +37,6 @@ public:
void TraceAllQueues (void);
void TraceAllNetDeviceRx (void);
private:
void PrintType (Packet const &p);
void LogDevQueue (TraceContext const &context, const Packet &p);
void LogDevRx (TraceContext const &context, Packet &p);
std::ofstream m_os;

View File

@@ -57,7 +57,7 @@ public:
DROP,
INTERFACES,
};
typedef ArrayTraceResolver<Ipv4Interface>::Index InterfaceIndex;
typedef ArrayTraceResolver<Ipv4Interface *>::Index InterfaceIndex;
Ipv4L3Protocol(Ptr<Node> node);
virtual ~Ipv4L3Protocol ();

View File

@@ -40,7 +40,7 @@ class TraceContext;
class NodeList
{
public:
typedef ArrayTraceResolver<Node>::Index NodeIndex;
typedef ArrayTraceResolver<Ptr<Node> >::Index NodeIndex;
typedef std::vector< Ptr<Node> >::iterator Iterator;
/**

View File

@@ -79,8 +79,8 @@ Node::GetSystemId (void) const
uint32_t
Node::AddDevice (Ptr<NetDevice> device)
{
m_devices.push_back (device);
uint32_t index = m_devices.size ();
m_devices.push_back (device);
device->SetIfIndex(index);
device->SetReceiveCallback (MakeCallback (&Node::ReceiveFromDevice, this));
NotifyDeviceAdded (device);
@@ -89,14 +89,7 @@ Node::AddDevice (Ptr<NetDevice> device)
Ptr<NetDevice>
Node::GetDevice (uint32_t index) const
{
if (index == 0)
{
return 0;
}
else
{
return m_devices[index - 1];
}
return m_devices[index];
}
uint32_t
Node::GetNDevices (void) const

View File

@@ -25,6 +25,7 @@
#include "ns3/object.h"
#include "ns3/callback.h"
#include "ns3/array-trace-resolver.h"
namespace ns3 {
@@ -57,6 +58,7 @@ class Node : public Object
{
public:
static const InterfaceId iid;
typedef ArrayTraceResolver<Ptr<NetDevice> >::Index NetDeviceIndex;
/**
* Must be invoked by subclasses only.

View File

@@ -29,22 +29,17 @@ PacketSocketAddress::SetProtocol (uint16_t protocol)
{
m_protocol = protocol;
}
void
PacketSocketAddress::SetDevice (uint32_t index)
void
PacketSocketAddress::SetAllDevices (void)
{
m_device = index;
m_isSingleDevice = false;
m_device = 0;
}
void
PacketSocketAddress::SetDevice (Ptr<NetDevice> device)
PacketSocketAddress::SetSingleDevice (uint32_t index)
{
if (device == 0)
{
m_device = 0;
}
else
{
m_device = device->GetIfIndex ();
}
m_isSingleDevice = true;
m_device = index;
}
void
PacketSocketAddress::SetPhysicalAddress (const Address address)
@@ -57,8 +52,13 @@ PacketSocketAddress::GetProtocol (void) const
{
return m_protocol;
}
bool
PacketSocketAddress::IsSingleDevice (void) const
{
return m_isSingleDevice;
}
uint32_t
PacketSocketAddress::GetDevice (void) const
PacketSocketAddress::GetSingleDevice (void) const
{
return m_device;
}
@@ -79,8 +79,9 @@ PacketSocketAddress::ConvertTo (void) const
buffer[3] = (m_device >> 16) & 0xff;
buffer[4] = (m_device >> 8) & 0xff;
buffer[5] = (m_device >> 0) & 0xff;
uint32_t copied = m_address.CopyAllTo (buffer + 6, Address::MAX_SIZE - 6);
return Address (GetType (), buffer, 6 + copied);
buffer[6] = m_isSingleDevice?1:0;
uint32_t copied = m_address.CopyAllTo (buffer + 7, Address::MAX_SIZE - 7);
return Address (GetType (), buffer, 7 + copied);
}
PacketSocketAddress
PacketSocketAddress::ConvertFrom (const Address &address)
@@ -97,11 +98,19 @@ PacketSocketAddress::ConvertFrom (const Address &address)
device |= buffer[4];
device <<= 8;
device |= buffer[5];
bool isSingleDevice = (buffer[6] == 1)?true:false;
Address physical;
physical.CopyAllFrom (buffer + 6, Address::MAX_SIZE - 6);
physical.CopyAllFrom (buffer + 7, Address::MAX_SIZE - 7);
PacketSocketAddress ad;
ad.SetProtocol (protocol);
ad.SetDevice (device);
if (isSingleDevice)
{
ad.SetSingleDevice (device);
}
else
{
ad.SetAllDevices ();
}
ad.SetPhysicalAddress (physical);
return ad;
}

View File

@@ -35,18 +35,14 @@ class PacketSocketAddress
public:
PacketSocketAddress ();
void SetProtocol (uint16_t protocol);
/**
* \param index of NetDevice.
*
* index zero is reserved to identify _all_
* Netdevices.
*/
void SetDevice (uint32_t index);
void SetDevice (Ptr<NetDevice> device);
void SetAllDevices (void);
void SetSingleDevice (uint32_t device);
void SetPhysicalAddress (const Address address);
uint16_t GetProtocol (void) const;
uint32_t GetDevice (void) const;
uint32_t GetSingleDevice (void) const;
bool IsSingleDevice (void) const;
Address GetPhysicalAddress (void) const;
/**
@@ -69,6 +65,7 @@ class PacketSocketAddress
private:
static uint8_t GetType (void);
uint16_t m_protocol;
bool m_isSingleDevice;
uint32_t m_device;
Address m_address;
};

View File

@@ -64,7 +64,7 @@ PacketSocket::Bind (void)
{
PacketSocketAddress address;
address.SetProtocol (0);
address.SetDevice (0);
address.SetAllDevices ();
return DoBind (address);
}
int
@@ -93,12 +93,21 @@ PacketSocket::DoBind (const PacketSocketAddress &address)
m_errno = ERROR_BADF;
return -1;
}
Ptr<NetDevice> dev = m_node->GetDevice (address.GetDevice ());
Ptr<NetDevice> dev ;
if (address.IsSingleDevice ())
{
dev = 0;
}
else
{
m_node->GetDevice (address.GetSingleDevice ());
}
m_node->RegisterProtocolHandler (MakeCallback (&PacketSocket::ForwardUp, this),
address.GetProtocol (), dev);
m_state = STATE_BOUND;
m_protocol = address.GetProtocol ();
m_device = address.GetDevice ();
m_isSingleDevice = address.IsSingleDevice ();
m_device = address.GetSingleDevice ();
return 0;
}
@@ -254,9 +263,17 @@ PacketSocket::DoSendTo(const Address &address,
bool error = false;
Address dest = ad.GetPhysicalAddress ();
if (ad.GetDevice () == 0)
if (ad.IsSingleDevice ())
{
for (uint32_t i = 1; i <= m_node->GetNDevices (); i++)
Ptr<NetDevice> device = m_node->GetDevice (ad.GetSingleDevice ());
if (!device->Send (p, dest, ad.GetProtocol ()))
{
error = true;
}
}
else
{
for (uint32_t i = 0; i < m_node->GetNDevices (); i++)
{
Ptr<NetDevice> device = m_node->GetDevice (i);
if (!device->Send (p, dest, ad.GetProtocol ()))
@@ -265,14 +282,6 @@ PacketSocket::DoSendTo(const Address &address,
}
}
}
else
{
Ptr<NetDevice> device = m_node->GetDevice (ad.GetDevice ());
if (!device->Send (p, dest, ad.GetProtocol ()))
{
error = true;
}
}
if (!error && !dataSent.IsNull ())
{
dataSent (this, p.GetSize ());
@@ -314,7 +323,7 @@ PacketSocket::ForwardUp (Ptr<NetDevice> device, const Packet &packet,
PacketSocketAddress address;
address.SetPhysicalAddress (from);
address.SetDevice (device->GetIfIndex ());
address.SetSingleDevice (device->GetIfIndex ());
address.SetProtocol (protocol);
NS_DEBUG ("PacketSocket::ForwardUp: UID is " << packet.GetUid()

View File

@@ -121,6 +121,7 @@ private:
bool m_shutdownRecv;
enum State m_state;
uint16_t m_protocol;
bool m_isSingleDevice;
uint32_t m_device;
Address m_destAddr; /// Default destination address
};