src/node/node.cc
changeset 3435 1d704c128f1f
parent 3016 f77acbb9f7b4
child 3437 7cec39fe195c
equal deleted inserted replaced
3364:8e6ac6061680 3435:1d704c128f1f
    94   uint32_t index = m_devices.size ();
    94   uint32_t index = m_devices.size ();
    95   m_devices.push_back (device);
    95   m_devices.push_back (device);
    96   device->SetNode (this);
    96   device->SetNode (this);
    97   device->SetIfIndex(index);
    97   device->SetIfIndex(index);
    98   device->SetReceiveCallback (MakeCallback (&Node::ReceiveFromDevice, this));
    98   device->SetReceiveCallback (MakeCallback (&Node::ReceiveFromDevice, this));
       
    99   device->SetPromiscuousReceiveCallback (MakeCallback (&Node::PromiscuousReceiveFromDevice, this));
    99   NotifyDeviceAdded (device);
   100   NotifyDeviceAdded (device);
   100   return index;
   101   return index;
   101 }
   102 }
   102 Ptr<NetDevice>
   103 Ptr<NetDevice>
   103 Node::GetDevice (uint32_t index) const
   104 Node::GetDevice (uint32_t index) const
   174        i != m_handlers.end (); i++)
   175        i != m_handlers.end (); i++)
   175     {
   176     {
   176       if (i->handler.IsEqual (handler))
   177       if (i->handler.IsEqual (handler))
   177         {
   178         {
   178           m_handlers.erase (i);
   179           m_handlers.erase (i);
       
   180           break;
       
   181         }
       
   182     }
       
   183 }
       
   184 
       
   185 void
       
   186 Node::RegisterPromiscuousProtocolHandler (PromiscuousProtocolHandler handler, 
       
   187                                           uint16_t protocolType,
       
   188                                           Ptr<NetDevice> device)
       
   189 {
       
   190   struct Node::PromiscuousProtocolHandlerEntry entry;
       
   191   entry.handler = handler;
       
   192   entry.protocol = protocolType;
       
   193   entry.device = device;
       
   194   m_promiscuousHandlers.push_back (entry);
       
   195 }
       
   196 
       
   197 void
       
   198 Node::UnregisterPromiscuousProtocolHandler (PromiscuousProtocolHandler handler)
       
   199 {
       
   200   for (PromiscuousProtocolHandlerList::iterator i = m_promiscuousHandlers.begin ();
       
   201        i != m_promiscuousHandlers.end (); i++)
       
   202     {
       
   203       if (i->handler.IsEqual (handler))
       
   204         {
       
   205           m_promiscuousHandlers.erase (i);
   179           break;
   206           break;
   180         }
   207         }
   181     }
   208     }
   182 }
   209 }
   183 
   210 
   206         }
   233         }
   207     }
   234     }
   208   return found;
   235   return found;
   209 }
   236 }
   210 
   237 
       
   238 
       
   239 bool
       
   240 Node::PromiscuousReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet, 
       
   241                                     uint16_t protocol, const Address &from, const Address &to)
       
   242 {
       
   243   bool found = false;
       
   244   // if there are (potentially) multiple handlers, we need to copy the
       
   245   // packet before passing it to each handler, because handlers may
       
   246   // modify it.
       
   247   bool copyNeeded = (m_handlers.size () > 1);
       
   248 
       
   249   for (PromiscuousProtocolHandlerList::iterator i = m_promiscuousHandlers.begin ();
       
   250        i != m_promiscuousHandlers.end (); i++)
       
   251     {
       
   252       if (i->device == 0 ||
       
   253           (i->device != 0 && i->device == device))
       
   254         {
       
   255           if (i->protocol == 0 || 
       
   256               i->protocol == protocol)
       
   257             {
       
   258               i->handler (device, (copyNeeded ? packet->Copy () : packet), protocol, from, to);
       
   259               found = true;
       
   260             }
       
   261         }
       
   262     }
       
   263   return found;
       
   264 }
       
   265 
   211 }//namespace ns3
   266 }//namespace ns3