--- a/src/node/internet-node.cc Mon Apr 30 10:24:43 2007 +0200
+++ b/src/node/internet-node.cc Mon Apr 30 10:37:22 2007 +0200
@@ -30,6 +30,7 @@
#include "udp.h"
#include "ipv4.h"
#include "arp.h"
+#include "net-device.h"
namespace ns3 {
@@ -144,7 +145,20 @@
void
InternetNode::DoAddDevice (NetDevice *device) const
{
- //XXX
+ device->SetReceiveCallback (MakeCallback (&InternetNode::ReceiveFromDevice, this));
+}
+
+bool
+InternetNode::ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const
+{
+ L3Protocol *target = GetL3Demux()->Lookup(protocolNumber);
+ if (target != 0)
+ {
+ Packet packet = p;
+ target->Receive(packet, *device);
+ return true;
+ }
+ return false;
}
--- a/src/node/internet-node.h Mon Apr 30 10:24:43 2007 +0200
+++ b/src/node/internet-node.h Mon Apr 30 10:37:22 2007 +0200
@@ -31,6 +31,7 @@
namespace ns3 {
+class Packet;
class InternetNode : public Node
{
@@ -57,6 +58,7 @@
void SetName(std::string name);
private:
virtual void DoAddDevice (NetDevice *device) const;
+ bool ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const;
// Capabilities
ApplicationList* m_applicationList;
L3Demux* m_l3Demux;
--- a/src/node/net-device.cc Mon Apr 30 10:24:43 2007 +0200
+++ b/src/node/net-device.cc Mon Apr 30 10:37:22 2007 +0200
@@ -179,19 +179,15 @@
bool
NetDevice::ForwardUp (Packet& packet)
{
+ bool retval = false;
LlcSnapHeader llc;
packet.Peek (llc);
packet.Remove (llc);
- if (GetNode()->GetL3Demux() != 0)
+ if (!m_receiveCallback.IsNull ())
{
- L3Protocol *target = GetNode()->GetL3Demux()->Lookup(llc.GetType ());
- if (target != 0)
- {
- target->Receive(packet, *this);
- return true;
- }
+ retval = m_receiveCallback (this, packet, llc.GetType ());
}
- return false;
+ return retval;
}
void
@@ -226,4 +222,10 @@
return DoNeedsArp ();
}
+void
+NetDevice::SetReceiveCallback (Callback<bool,NetDevice *,const Packet &,uint16_t> cb)
+{
+ m_receiveCallback = cb;
+}
+
}; // namespace ns3
--- a/src/node/net-device.h Mon Apr 30 10:24:43 2007 +0200
+++ b/src/node/net-device.h Mon Apr 30 10:37:22 2007 +0200
@@ -154,6 +154,8 @@
bool NeedsArp (void) const;
+ void SetReceiveCallback (Callback<bool,NetDevice *,const Packet &,uint16_t> cb);
+
protected:
/**
* Enable broadcast support. This method should be
@@ -238,6 +240,7 @@
bool m_isMulticast;
bool m_isPointToPoint;
Callback<void> m_linkChangeCallback;
+ Callback<bool,NetDevice *,const Packet &,uint16_t> m_receiveCallback;
};
}; // namespace ns3