add NetDevice::SetReceiveCallback and use it
parent
52646de997
commit
4873ff5f39
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue