diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc index 9b964abec..801e8ea51 100644 --- a/examples/csma-multicast.cc +++ b/examples/csma-multicast.cc @@ -85,19 +85,6 @@ main (int argc, char *argv[]) DebugComponentEnable("Ipv4LoopbackInterface"); #endif - DebugComponentEnable("Channel"); - DebugComponentEnable("CsmaChannel"); - DebugComponentEnable("CsmaMulticast"); - DebugComponentEnable("CsmaNetDevice"); - DebugComponentEnable("OnOffApplication"); - DebugComponentEnable("PacketSocket"); - DebugComponentEnable("UdpSocket"); - DebugComponentEnable("UdpL4Protocol"); - DebugComponentEnable("Ipv4L3Protocol"); - DebugComponentEnable("Ipv4StaticRouting"); - DebugComponentEnable("Ipv4Interface"); - DebugComponentEnable("ArpIpv4Interface"); - DebugComponentEnable("Ipv4LoopbackInterface"); // // Set up default values for the simulation. Use the DefaultValue::Bind() // technique to tell the system what subclass of Queue to use. The Bind diff --git a/src/internet-node/ipv4-impl.cc b/src/internet-node/ipv4-impl.cc index b105d5a41..a67c6a4e8 100644 --- a/src/internet-node/ipv4-impl.cc +++ b/src/internet-node/ipv4-impl.cc @@ -201,6 +201,12 @@ Ipv4Impl::GetAddress (uint32_t i) const return m_ipv4->GetAddress (i); } +bool +Ipv4Impl::GetIfIndexForDestination (Ipv4Address dest, uint32_t &ifIndex) const +{ + return m_ipv4->GetIfIndexForDestination (dest, ifIndex); +} + Ipv4Address Ipv4Impl::GetSourceAddress (Ipv4Address destination) const { diff --git a/src/internet-node/ipv4-impl.h b/src/internet-node/ipv4-impl.h index ab17c16f4..1f4a79f5c 100644 --- a/src/internet-node/ipv4-impl.h +++ b/src/internet-node/ipv4-impl.h @@ -89,6 +89,8 @@ public: virtual Ipv4Mask GetNetworkMask (uint32_t t) const; virtual Ipv4Address GetAddress (uint32_t i) const; virtual Ipv4Address GetSourceAddress (Ipv4Address destination) const; + virtual bool GetIfIndexForDestination (Ipv4Address dest, + uint32_t &ifIndex) const; virtual uint16_t GetMtu (uint32_t i) const; virtual bool IsUp (uint32_t i) const; diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 1183ce7d9..6f123bed5 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -186,11 +186,13 @@ UdpSocket::Connect(const Address & address) NS_DEBUG ("UdpSocket::Connect (): Updating local address"); - if (GetIpv4RouteToDestination (m_node, routeToDest, m_defaultAddress) ) + uint32_t localIfIndex; + + Ptr ipv4 = m_node->QueryInterface (Ipv4::iid); + + if (ipv4->GetIfIndexForDestination (m_defaultAddress, localIfIndex)) { - uint32_t localIfIndex = routeToDest.GetInterface (); - Ptr ipv4 = m_node->QueryInterface (Ipv4::iid); - m_endPoint->SetLocalAddress (ipv4->GetAddress(localIfIndex) ); + m_endPoint->SetLocalAddress (ipv4->GetAddress(localIfIndex)); } NS_DEBUG ("UdpSocket::Connect (): Local address is " << @@ -240,6 +242,7 @@ UdpSocket::DoSendTo (const Packet &p, const Address &address) if (!m_connected) { + NS_DEBUG("UdpSocket::DoSendTo (): Not connected"); InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); Ipv4Address ipv4 = transport.GetIpv4 (); uint16_t port = transport.GetPort (); @@ -248,6 +251,7 @@ UdpSocket::DoSendTo (const Packet &p, const Address &address) else { // connected UDP socket must use default addresses + NS_DEBUG("UdpSocket::DoSendTo (): Connected"); return DoSendTo (p, m_defaultAddress, m_defaultPort); } } @@ -274,13 +278,17 @@ UdpSocket::DoSendTo (const Packet &p, Ipv4Address dest, uint16_t port) m_errno = ERROR_SHUTDOWN; return -1; } + + uint32_t localIfIndex; + Ptr ipv4 = m_node->QueryInterface (Ipv4::iid); + // // If dest is sent to the limited broadcast address (all ones), // convert it to send a copy of the packet out of every interface // if (dest.IsBroadcast ()) { - Ptr ipv4 = m_node->QueryInterface (Ipv4::iid); + NS_DEBUG("UdpSocket::DoSendTo (): Limited broadcast"); for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++ ) { Ipv4Address addri = ipv4->GetAddress (i); @@ -290,10 +298,9 @@ UdpSocket::DoSendTo (const Packet &p, Ipv4Address dest, uint16_t port) NotifyDataSent (p.GetSize ()); } } - else if (GetIpv4RouteToDestination (m_node, routeToDest, dest) ) + else if (ipv4->GetIfIndexForDestination(dest, localIfIndex)) { - uint32_t localIfIndex = routeToDest.GetInterface (); - Ptr ipv4 = m_node->QueryInterface (Ipv4::iid); + NS_DEBUG("UdpSocket::DoSendTo (): Route exists"); m_udp->Send (p, ipv4->GetAddress (localIfIndex), dest, m_endPoint->GetLocalPort (), port); NotifyDataSent (p.GetSize ()); @@ -301,6 +308,7 @@ UdpSocket::DoSendTo (const Packet &p, Ipv4Address dest, uint16_t port) } else { + NS_DEBUG("UdpSocket::DoSendTo (): ERROR_NOROUTETOHOST"); m_errno = ERROR_NOROUTETOHOST; return -1; } diff --git a/src/node/ipv4.cc b/src/node/ipv4.cc index d7c83d42a..f8a852149 100644 --- a/src/node/ipv4.cc +++ b/src/node/ipv4.cc @@ -36,10 +36,10 @@ Ipv4::~Ipv4 () {} uint32_t -GetIfIndexByIpv4Address (Ptr node, Ipv4Address a, Ipv4Mask amask) +Ipv4::GetIfIndexByAddress (Ptr node, Ipv4Address a, Ipv4Mask amask) { Ptr ipv4 = node->QueryInterface (Ipv4::iid); - NS_ASSERT_MSG (ipv4, "GetIfIndexByIpv4Address: No Ipv4 interface"); + NS_ASSERT_MSG (ipv4, "Ipv4::GetIfIndexByAddress: No Ipv4 interface"); for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++) { if (ipv4->GetAddress (i).CombineMask(amask) == a.CombineMask(amask) ) @@ -48,17 +48,26 @@ GetIfIndexByIpv4Address (Ptr node, Ipv4Address a, Ipv4Mask amask) } } // Mapping not found - NS_ASSERT_MSG (false, "GetIfIndexByIpv4Address failed"); + NS_ASSERT_MSG (false, "Ipv4::GetIfIndexByAddress failed"); return 0; } +// +// XXX BUGBUG I don't think this is really the right approach here. The call +// to GetRoute () filters down into Ipv4L3Protocol where it translates into +// a call into the Ipv4 static routing package. This bypasses any other +// routing packages. At a minimum, the name is misleading. +// bool -GetIpv4RouteToDestination (Ptr node, Ipv4Route& route, - Ipv4Address a, Ipv4Mask amask) +Ipv4::GetRouteToDestination ( + Ptr node, + Ipv4Route& route, + Ipv4Address a, + Ipv4Mask amask) { Ipv4Route tempRoute; Ptr ipv4 = node->QueryInterface (Ipv4::iid); - NS_ASSERT_MSG (ipv4, "GetIpv4RouteToDestination: No Ipv4 interface"); + NS_ASSERT_MSG (ipv4, "Ipv4::GetRouteToDestination: No Ipv4 interface"); for (uint32_t i = 0; i < ipv4->GetNRoutes (); i++) { tempRoute = ipv4->GetRoute (i); @@ -83,5 +92,4 @@ GetIpv4RouteToDestination (Ptr node, Ipv4Route& route, return false; } - } // namespace ns3 diff --git a/src/node/ipv4.h b/src/node/ipv4.h index 1cdc08d6f..ba4868a4a 100644 --- a/src/node/ipv4.h +++ b/src/node/ipv4.h @@ -105,6 +105,7 @@ public: const Ipv4Header &ipHeader, Packet packet, RouteReplyCallback routeReply) = 0; + /** * \brief Synchronously check to see if we can determine the interface index * that will be used if a packet is sent to this destination. @@ -395,6 +396,15 @@ public: */ virtual Ipv4Address GetSourceAddress (Ipv4Address destination) const = 0; + /** + * \param destination The IP address of a hypothetical destination. + * \param ifIndex filled in with the interface index that will be used to + * send a packet to the hypothetical destination. + * \returns True if a single interface can be identified, false otherwise. + */ + virtual bool GetIfIndexForDestination (Ipv4Address dest, + uint32_t &ifIndex) const = 0; + /** * \param i index of ipv4 interface * \returns the Maximum Transmission Unit (in bytes) associated @@ -424,20 +434,18 @@ public: * ignored during ipv4 forwarding. */ virtual void SetDown (uint32_t i) = 0; -}; /** * Convenience functions (Doxygen still needed) * * Return the ifIndex corresponding to the Ipv4Address provided. */ -uint32_t GetIfIndexByIpv4Address (Ptr node, - Ipv4Address a, - Ipv4Mask amask = Ipv4Mask("255.255.255.255")); + static uint32_t GetIfIndexByAddress (Ptr node, Ipv4Address a, + Ipv4Mask amask = Ipv4Mask("255.255.255.255")); -bool GetIpv4RouteToDestination (Ptr node, Ipv4Route& route, - Ipv4Address a, - Ipv4Mask amask = Ipv4Mask("255.255.255.255")); + static bool GetRouteToDestination (Ptr node, Ipv4Route& route, + Ipv4Address a, Ipv4Mask amask = Ipv4Mask("255.255.255.255")); +}; } // namespace ns3 diff --git a/src/routing/global-routing/global-route-manager-impl.cc b/src/routing/global-routing/global-route-manager-impl.cc index 10f07ca85..4e8f19f51 100644 --- a/src/routing/global-routing/global-route-manager-impl.cc +++ b/src/routing/global-routing/global-route-manager-impl.cc @@ -1143,7 +1143,7 @@ GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask) // we're looking for. If we find one, return the corresponding interface // index. // - return (GetIfIndexByIpv4Address (node, a, amask) ); + return (Ipv4::GetIfIndexByAddress (node, a, amask) ); } } //