src/internet-node/ipv4-static-routing.cc
changeset 1440 c77745b2731c
parent 1435 a70de165a25a
child 1442 bb5cf98c0c64
equal deleted inserted replaced
1439:4743aef86605 1440:c77745b2731c
   228     }
   228     }
   229   n += m_hostRoutes.size ();
   229   n += m_hostRoutes.size ();
   230   n += m_networkRoutes.size ();
   230   n += m_networkRoutes.size ();
   231   return n;
   231   return n;
   232 }
   232 }
       
   233 
       
   234 Ipv4Route *
       
   235 Ipv4StaticRouting::GetDefaultRoute ()
       
   236 {
       
   237   if (m_defaultRoute != 0)
       
   238     {
       
   239       return m_defaultRoute;
       
   240     }
       
   241   else
       
   242     {
       
   243       return 0;
       
   244     }
       
   245 }
       
   246 
   233 Ipv4Route *
   247 Ipv4Route *
   234 Ipv4StaticRouting::GetRoute (uint32_t index)
   248 Ipv4StaticRouting::GetRoute (uint32_t index)
   235 {
   249 {
   236   if (index == 0 && m_defaultRoute != 0)
   250   if (index == 0 && m_defaultRoute != 0)
   237     {
   251     {
   329   NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): source = " << 
   343   NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): source = " << 
   330     ipHeader.GetSource ());
   344     ipHeader.GetSource ());
   331 
   345 
   332   NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): destination = " << 
   346   NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): destination = " << 
   333     ipHeader.GetDestination ());
   347     ipHeader.GetDestination ());
   334 //
   348 
   335 // First, see if this is a multicast packet we have a route for.  If we
       
   336 // have a route, then send the packet down each of the specified interfaces.
       
   337 //
       
   338   if (ipHeader.GetDestination ().IsMulticast ())
   349   if (ipHeader.GetDestination ().IsMulticast ())
   339     {
   350     {
   340       NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): Multicast destination");
   351       NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): Multicast destination");
   341 
   352 //
       
   353 // We have a multicast packet we're going to send.  There are two distinct
       
   354 // cases we need to support.  The first is if the current node is the source
       
   355 // of the packet.  In that case, we don't want to have to consult multicast
       
   356 // routing tables (nor build them) in order to send multicasts.  The interface
       
   357 // index (ifIndex) is Ipv4RoutingProtocol::IF_INDEX_ANY if we're the source.
       
   358 //
       
   359 // The second case is if the current packet has gotten to us by being
       
   360 // received over one of our interfaces.  In this case, ifIndex is set to the
       
   361 // index over which we received the packet.  For these packets, we need to
       
   362 // consult the multicast routing table for a disposition.
       
   363 //
       
   364 // So, first let's see if we're the source.  In this case, we don't consult
       
   365 // the routing tables, but just return false and let the caller (up in 
       
   366 // ipv4-l3-protocol) flood the multicast packet out of all of its interfaces.
       
   367 // We can't really do it here even if we wanted to since we have no easy way
       
   368 // to get to the Ipv4 interface which we would need.
       
   369 //
       
   370       if (ifIndex == Ipv4RoutingProtocol::IF_INDEX_ANY)
       
   371         {
       
   372           return false;
       
   373         }
       
   374 //
       
   375 // If we fall through to this point, we have a multicast packet that has
       
   376 // not originated at this node.  We need to deal with forwarding.  Let's
       
   377 // see if we have a route, and if so go ahead and forward this puppy.
       
   378 //
   342       Ipv4MulticastRoute *mRoute = LookupStatic(ipHeader.GetSource (),
   379       Ipv4MulticastRoute *mRoute = LookupStatic(ipHeader.GetSource (),
   343         ipHeader.GetDestination (), ifIndex);
   380         ipHeader.GetDestination (), ifIndex);
   344 
   381 
   345       if (mRoute)
   382       if (mRoute)
   346         {
   383         {
   347           NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): "
   384           NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): "
   348             "Multicast route found");
   385             "Multicast route found");
   349           for (uint32_t i = 0; i < mRoute->GetNOutputInterfaces (); ++i)
   386           for (uint32_t i = 0; i < mRoute->GetNOutputInterfaces (); ++i)
   350             {
   387             {
   351               Packet p = packet;
   388               Packet p = packet;
       
   389               Ipv4Header h = ipHeader;
   352               Ipv4Route route = 
   390               Ipv4Route route = 
   353                 Ipv4Route::CreateHostRouteTo(ipHeader.GetDestination (), 
   391                 Ipv4Route::CreateHostRouteTo(h.GetDestination (), 
   354                   mRoute->GetOutputInterface(i));
   392                   mRoute->GetOutputInterface(i));
   355               NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): "
   393               NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): "
   356                 "Send via interface " << mRoute->GetOutputInterface(i));
   394                 "Send via interface " << mRoute->GetOutputInterface(i));
   357               routeReply (true, route, p, ipHeader);
   395               routeReply (true, route, p, h);
   358               return true;
       
   359             }
   396             }
       
   397           return true;
   360         }
   398         }
   361       return false; // Let other routing protocols try to handle this
   399       return false; // Let other routing protocols try to handle this
   362     }
   400     }
   363 //
   401 //
   364 // See if this is a unicast packet we have a route for.
   402 // See if this is a unicast packet we have a route for.