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. |