--- a/examples/csma-cd-packet-socket.cc Wed Aug 01 12:33:44 2007 +0200
+++ b/examples/csma-cd-packet-socket.cc Wed Aug 01 13:53:48 2007 +0200
@@ -90,13 +90,13 @@
// 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);
--- a/src/internet-node/ascii-trace.cc Wed Aug 01 12:33:44 2007 +0200
+++ b/src/internet-node/ascii-trace.cc Wed Aug 01 13:53:48 2007 +0200
@@ -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 @@
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 @@
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 @@
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;
--- a/src/internet-node/ascii-trace.h Wed Aug 01 12:33:44 2007 +0200
+++ b/src/internet-node/ascii-trace.h Wed Aug 01 13:53:48 2007 +0200
@@ -37,7 +37,6 @@
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;
--- a/src/internet-node/ipv4-l3-protocol.h Wed Aug 01 12:33:44 2007 +0200
+++ b/src/internet-node/ipv4-l3-protocol.h Wed Aug 01 13:53:48 2007 +0200
@@ -57,7 +57,7 @@
DROP,
INTERFACES,
};
- typedef ArrayTraceResolver<Ipv4Interface>::Index InterfaceIndex;
+ typedef ArrayTraceResolver<Ipv4Interface *>::Index InterfaceIndex;
Ipv4L3Protocol(Ptr<Node> node);
virtual ~Ipv4L3Protocol ();
--- a/src/node/node-list.h Wed Aug 01 12:33:44 2007 +0200
+++ b/src/node/node-list.h Wed Aug 01 13:53:48 2007 +0200
@@ -40,7 +40,7 @@
class NodeList
{
public:
- typedef ArrayTraceResolver<Node>::Index NodeIndex;
+ typedef ArrayTraceResolver<Ptr<Node> >::Index NodeIndex;
typedef std::vector< Ptr<Node> >::iterator Iterator;
/**
--- a/src/node/node.cc Wed Aug 01 12:33:44 2007 +0200
+++ b/src/node/node.cc Wed Aug 01 13:53:48 2007 +0200
@@ -79,8 +79,8 @@
uint32_t
Node::AddDevice (Ptr<NetDevice> device)
{
+ uint32_t index = m_devices.size ();
m_devices.push_back (device);
- uint32_t index = m_devices.size ();
device->SetIfIndex(index);
device->SetReceiveCallback (MakeCallback (&Node::ReceiveFromDevice, this));
NotifyDeviceAdded (device);
@@ -89,14 +89,7 @@
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
--- a/src/node/node.h Wed Aug 01 12:33:44 2007 +0200
+++ b/src/node/node.h Wed Aug 01 13:53:48 2007 +0200
@@ -25,6 +25,7 @@
#include "ns3/object.h"
#include "ns3/callback.h"
+#include "ns3/array-trace-resolver.h"
namespace ns3 {
@@ -57,6 +58,7 @@
{
public:
static const InterfaceId iid;
+ typedef ArrayTraceResolver<Ptr<NetDevice> >::Index NetDeviceIndex;
/**
* Must be invoked by subclasses only.
--- a/src/node/packet-socket-address.cc Wed Aug 01 12:33:44 2007 +0200
+++ b/src/node/packet-socket-address.cc Wed Aug 01 13:53:48 2007 +0200
@@ -29,22 +29,17 @@
{
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 @@
{
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 @@
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 @@
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;
}
--- a/src/node/packet-socket-address.h Wed Aug 01 12:33:44 2007 +0200
+++ b/src/node/packet-socket-address.h Wed Aug 01 13:53:48 2007 +0200
@@ -35,18 +35,14 @@
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 @@
private:
static uint8_t GetType (void);
uint16_t m_protocol;
+ bool m_isSingleDevice;
uint32_t m_device;
Address m_address;
};
--- a/src/node/packet-socket.cc Wed Aug 01 12:33:44 2007 +0200
+++ b/src/node/packet-socket.cc Wed Aug 01 13:53:48 2007 +0200
@@ -64,7 +64,7 @@
{
PacketSocketAddress address;
address.SetProtocol (0);
- address.SetDevice (0);
+ address.SetAllDevices ();
return DoBind (address);
}
int
@@ -93,12 +93,21 @@
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 @@
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 @@
}
}
}
- 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 @@
PacketSocketAddress address;
address.SetPhysicalAddress (from);
- address.SetDevice (device->GetIfIndex ());
+ address.SetSingleDevice (device->GetIfIndex ());
address.SetProtocol (protocol);
NS_DEBUG ("PacketSocket::ForwardUp: UID is " << packet.GetUid()
--- a/src/node/packet-socket.h Wed Aug 01 12:33:44 2007 +0200
+++ b/src/node/packet-socket.h Wed Aug 01 13:53:48 2007 +0200
@@ -121,6 +121,7 @@
bool m_shutdownRecv;
enum State m_state;
uint16_t m_protocol;
+ bool m_isSingleDevice;
uint32_t m_device;
Address m_destAddr; /// Default destination address
};