src/internet-node/ipv4-l3-protocol.cc
changeset 1432 3aef7d7a71c2
parent 1430 25fa26a6533e
child 1434 2b63aafb050b
equal deleted inserted replaced
1431:3760d52ef5d1 1432:3aef7d7a71c2
   244     interface << ")");
   244     interface << ")");
   245   m_staticRouting->SetDefaultRoute (nextHop, interface);
   245   m_staticRouting->SetDefaultRoute (nextHop, interface);
   246 }
   246 }
   247 
   247 
   248 void
   248 void
   249 Ipv4L3Protocol::Lookup (Ipv4Header const &ipHeader,
   249 Ipv4L3Protocol::Lookup (
   250                         Packet packet,
   250   Ipv4Header const &ipHeader,
   251                         Ipv4RoutingProtocol::RouteReplyCallback routeReply)
   251   Packet packet,
   252 {
   252   Ipv4RoutingProtocol::RouteReplyCallback routeReply)
   253   NS_DEBUG("Ipv4L3Protocol::Lookup (" << &ipHeader << ", " << &packet <<
   253 {
   254     &routeReply << ")");
   254   NS_DEBUG("Ipv4L3Protocol::Lookup (" << &ipHeader << 
       
   255     ", " << &packet << &routeReply << ")");
       
   256 
       
   257   Lookup (Ipv4RoutingProtocol::IF_INDEX_ANY, ipHeader, packet, routeReply);
       
   258 }
       
   259 
       
   260 void
       
   261 Ipv4L3Protocol::Lookup (
       
   262   uint32_t ifIndex,
       
   263   Ipv4Header const &ipHeader,
       
   264   Packet packet,
       
   265   Ipv4RoutingProtocol::RouteReplyCallback routeReply)
       
   266 {
       
   267   NS_DEBUG("Ipv4L3Protocol::Lookup (" << ifIndex << ", " << &ipHeader << 
       
   268     ", " << &packet << &routeReply << ")");
   255 
   269 
   256   for (Ipv4RoutingProtocolList::const_iterator rprotoIter = 
   270   for (Ipv4RoutingProtocolList::const_iterator rprotoIter = 
   257          m_routingProtocols.begin ();
   271          m_routingProtocols.begin ();
   258        rprotoIter != m_routingProtocols.end (); 
   272        rprotoIter != m_routingProtocols.end (); 
   259        rprotoIter++)
   273        rprotoIter++)
   260     {
   274     {
   261       NS_DEBUG("Ipv4L3Protocol::Lookup (): Requesting route");
   275       NS_DEBUG("Ipv4L3Protocol::Lookup (): Requesting route");
   262       if ((*rprotoIter).second->RequestRoute (ipHeader, packet, routeReply))
   276       if ((*rprotoIter).second->RequestRoute (ifIndex, ipHeader, packet, 
       
   277                                               routeReply))
   263         return;
   278         return;
   264     }
   279     }
   265 
   280 
   266   // No route found
   281   // No route found
   267   routeReply (false, Ipv4Route (), packet, ipHeader);
   282   routeReply (false, Ipv4Route (), packet, ipHeader);
   403 {
   418 {
   404   NS_DEBUG("Ipv4L3Protocol::Receive (" << &device << ", " << &p << ", " <<
   419   NS_DEBUG("Ipv4L3Protocol::Receive (" << &device << ", " << &p << ", " <<
   405     protocol << ", " << from << ")");
   420     protocol << ", " << from << ")");
   406 
   421 
   407   uint32_t index = 0;
   422   uint32_t index = 0;
   408   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
   423   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
       
   424        i != m_interfaces.end (); 
       
   425        i++)
   409     {
   426     {
   410       if ((*i)->GetDevice () == device)
   427       if ((*i)->GetDevice () == device)
   411         {
   428         {
   412           m_rxTrace (p, index);
   429           m_rxTrace (p, index);
   413           break;
   430           break;
   421   if (!ipHeader.IsChecksumOk ()) 
   438   if (!ipHeader.IsChecksumOk ()) 
   422     {
   439     {
   423       return;
   440       return;
   424     }
   441     }
   425 
   442 
   426   if (Forwarding (packet, ipHeader, device)) 
   443   if (Forwarding (index, packet, ipHeader, device)) 
   427     {
   444     {
   428       return;
   445       return;
   429     }
   446     }
   430 
   447 
   431   ForwardUp (packet, ipHeader);
   448   ForwardUp (packet, ipHeader);
   519       outInterface->Send (packet, ipHeader.GetDestination ());
   536       outInterface->Send (packet, ipHeader.GetDestination ());
   520     }
   537     }
   521 }
   538 }
   522 
   539 
   523 bool
   540 bool
   524 Ipv4L3Protocol::Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr<NetDevice> device)
   541 Ipv4L3Protocol::Forwarding (
   525 {
   542   uint32_t ifIndex, 
   526   NS_DEBUG("Ipv4L3Protocol::Forwarding (" << &packet << ", " << &ipHeader << 
   543   Packet const &packet, 
   527     ", " << device << ")");
   544   Ipv4Header &ipHeader, 
       
   545   Ptr<NetDevice> device)
       
   546 {
       
   547   NS_DEBUG("Ipv4L3Protocol::Forwarding (" << ifIndex << ", " << &packet << 
       
   548     ", " << &ipHeader << ", " << device << ")");
   528 
   549 
   529   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
   550   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
   530        i != m_interfaces.end (); i++) 
   551        i != m_interfaces.end (); i++) 
   531     {
   552     {
   532       if ((*i)->GetAddress ().IsEqual (ipHeader.GetDestination ())) 
   553       if ((*i)->GetAddress ().IsEqual (ipHeader.GetDestination ())) 
   577       return true;
   598       return true;
   578     }
   599     }
   579   ipHeader.SetTtl (ipHeader.GetTtl () - 1);
   600   ipHeader.SetTtl (ipHeader.GetTtl () - 1);
   580 
   601 
   581   NS_DEBUG("Ipv4L3Protocol::Forwarding (): Forwarding packet.");
   602   NS_DEBUG("Ipv4L3Protocol::Forwarding (): Forwarding packet.");
   582   Lookup (ipHeader, packet,
   603   Lookup (ifIndex, ipHeader, packet,
   583           MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
   604           MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
   584 //
   605 //
   585 // If this is a to a multicast address and this node is a member of the 
   606 // If this is a to a multicast address and this node is a member of the 
   586 // indicated group we need to return false so the multicast is forwarded up.
   607 // indicated group we need to return false so the multicast is forwarded up.
   587 // Note that we may have just forwarded this packet too.
   608 // Note that we may have just forwarded this packet too.