add NetDevice::SetReceiveCallback and use it

Mathieu Lacage 2007-04-30 10:37:22 +02:00
parent 52646de997
commit 4873ff5f39
4 changed files with 30 additions and 9 deletions

View File

@ -30,6 +30,7 @@
#include "udp.h"
#include "ipv4.h"
#include "arp.h"
#include "net-device.h"
namespace ns3 {
@ -144,7 +145,20 @@ InternetNode::GetArp (void) const
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;
}

View File

@ -31,6 +31,7 @@
namespace ns3 {
class Packet;
class InternetNode : public Node
{
@ -57,6 +58,7 @@ public:
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;

View File

@ -179,19 +179,15 @@ NetDevice::GetChannel (void) const
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 @@ NetDevice::NeedsArp (void) const
return DoNeedsArp ();
}
void
NetDevice::SetReceiveCallback (Callback<bool,NetDevice *,const Packet &,uint16_t> cb)
{
m_receiveCallback = cb;
}
}; // namespace ns3

View File

@ -154,6 +154,8 @@ class NetDevice {
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 @@ class NetDevice {
bool m_isMulticast;
bool m_isPointToPoint;
Callback<void> m_linkChangeCallback;
Callback<bool,NetDevice *,const Packet &,uint16_t> m_receiveCallback;
};
}; // namespace ns3