Sketching a new promiscuous mode protocol handlers API; Netdevices implementation missing, though.
This commit is contained in:
@@ -96,6 +96,7 @@ Node::AddDevice (Ptr<NetDevice> device)
|
||||
device->SetNode (this);
|
||||
device->SetIfIndex(index);
|
||||
device->SetReceiveCallback (MakeCallback (&Node::ReceiveFromDevice, this));
|
||||
device->SetPromiscuousReceiveCallback (MakeCallback (&Node::PromiscuousReceiveFromDevice, this));
|
||||
NotifyDeviceAdded (device);
|
||||
return index;
|
||||
}
|
||||
@@ -181,6 +182,32 @@ Node::UnregisterProtocolHandler (ProtocolHandler handler)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Node::RegisterPromiscuousProtocolHandler (PromiscuousProtocolHandler handler,
|
||||
uint16_t protocolType,
|
||||
Ptr<NetDevice> device)
|
||||
{
|
||||
struct Node::PromiscuousProtocolHandlerEntry entry;
|
||||
entry.handler = handler;
|
||||
entry.protocol = protocolType;
|
||||
entry.device = device;
|
||||
m_promiscuousHandlers.push_back (entry);
|
||||
}
|
||||
|
||||
void
|
||||
Node::UnregisterPromiscuousProtocolHandler (PromiscuousProtocolHandler handler)
|
||||
{
|
||||
for (PromiscuousProtocolHandlerList::iterator i = m_promiscuousHandlers.begin ();
|
||||
i != m_promiscuousHandlers.end (); i++)
|
||||
{
|
||||
if (i->handler.IsEqual (handler))
|
||||
{
|
||||
m_promiscuousHandlers.erase (i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Node::ReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet,
|
||||
uint16_t protocol, const Address &from)
|
||||
@@ -208,4 +235,32 @@ Node::ReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet,
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Node::PromiscuousReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet,
|
||||
uint16_t protocol, const Address &from, const Address &to)
|
||||
{
|
||||
bool found = false;
|
||||
// if there are (potentially) multiple handlers, we need to copy the
|
||||
// packet before passing it to each handler, because handlers may
|
||||
// modify it.
|
||||
bool copyNeeded = (m_handlers.size () > 1);
|
||||
|
||||
for (PromiscuousProtocolHandlerList::iterator i = m_promiscuousHandlers.begin ();
|
||||
i != m_promiscuousHandlers.end (); i++)
|
||||
{
|
||||
if (i->device == 0 ||
|
||||
(i->device != 0 && i->device == device))
|
||||
{
|
||||
if (i->protocol == 0 ||
|
||||
i->protocol == protocol)
|
||||
{
|
||||
i->handler (device, (copyNeeded ? packet->Copy () : packet), protocol, from, to);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
Reference in New Issue
Block a user