From aecc283cb5044e95a548471f7720a066851f74eb Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Mon, 13 Aug 2007 19:54:47 -0700 Subject: [PATCH] set source IP address in udp-socket packets --- examples/csma-multicast.cc | 16 ++-------------- examples/csma-one-subnet.cc | 1 - src/internet-node/ipv4-impl.cc | 4 +++- src/internet-node/ipv4-l3-protocol.cc | 7 +++++-- src/internet-node/ipv4-static-routing.cc | 2 ++ src/internet-node/udp-socket.cc | 6 ++++-- 6 files changed, 16 insertions(+), 20 deletions(-) diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc index 5017805aa..9d7b5f8f6 100644 --- a/examples/csma-multicast.cc +++ b/examples/csma-multicast.cc @@ -71,11 +71,11 @@ main (int argc, char *argv[]) DebugComponentEnable("DropTailQueue"); DebugComponentEnable("Channel"); DebugComponentEnable("CsmaChannel"); + DebugComponentEnable("NetDevice"); DebugComponentEnable("CsmaNetDevice"); DebugComponentEnable("Ipv4L3Protocol"); - DebugComponentEnable("NetDevice"); - DebugComponentEnable("PacketSocket"); DebugComponentEnable("OnOffApplication"); + DebugComponentEnable("PacketSocket"); DebugComponentEnable("UdpSocket"); DebugComponentEnable("UdpL4Protocol"); DebugComponentEnable("Ipv4L3Protocol"); @@ -84,18 +84,6 @@ main (int argc, char *argv[]) DebugComponentEnable("ArpIpv4Interface"); DebugComponentEnable("Ipv4LoopbackInterface"); #endif - - DebugComponentEnable("UdpSocket"); - DebugComponentEnable("UdpL4Protocol"); - DebugComponentEnable("Ipv4L3Protocol"); - DebugComponentEnable("Ipv4StaticRouting"); - DebugComponentEnable("Ipv4Interface"); - DebugComponentEnable("ArpIpv4Interface"); - DebugComponentEnable("Ipv4LoopbackInterface"); - - DebugComponentEnable("CsmaMulticast"); - DebugComponentEnable("CsmaChannel"); - DebugComponentEnable("CsmaNetDevice"); // // 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/examples/csma-one-subnet.cc b/examples/csma-one-subnet.cc index b7926c0db..19d9200ff 100644 --- a/examples/csma-one-subnet.cc +++ b/examples/csma-one-subnet.cc @@ -80,7 +80,6 @@ main (int argc, char *argv[]) DebugComponentEnable("ArpIpv4Interface"); DebugComponentEnable("Ipv4LoopbackInterface"); #endif - // // 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 96f7af1e4..49a126547 100644 --- a/src/internet-node/ipv4-impl.cc +++ b/src/internet-node/ipv4-impl.cc @@ -184,8 +184,10 @@ Ipv4Impl::GetAddress (uint32_t i) const Ipv4Address Ipv4Impl::GetSourceAddress (Ipv4Address destination) const { - uint32_t ifIndex; + uint32_t ifIndex = 0xffffffff; + bool result = m_ipv4->GetIfIndexForDestination (destination, ifIndex); + if (result) { return m_ipv4->GetAddress (ifIndex); diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index 615985674..de1ca314b 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -703,10 +703,13 @@ Ipv4L3Protocol::GetIfIndexForDestination ( i++) { NS_DEBUG("Ipv4L3Protocol::Lookup (): Requesting Source Address"); - uint32_t ifIndex; + uint32_t ifIndexTmp; - if ((*i).second->RequestIfIndex (destination, ifIndex)) + if ((*i).second->RequestIfIndex (destination, ifIndexTmp)) { + NS_DEBUG("Ipv4L3Protocol::GetIfIndexForDestination (): " + "Found ifIndex " << ifIndexTmp); + ifIndex = ifIndexTmp; return true; } } diff --git a/src/internet-node/ipv4-static-routing.cc b/src/internet-node/ipv4-static-routing.cc index 3ead3fcec..9013769dd 100644 --- a/src/internet-node/ipv4-static-routing.cc +++ b/src/internet-node/ipv4-static-routing.cc @@ -406,6 +406,8 @@ Ipv4StaticRouting::RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex) } ifIndex = mRoute->GetOutputInterface(0); + NS_DEBUG ("Ipv4StaticRouting::RequestIfIndex (): " + "Found ifIndex " << ifIndex); return true; } return false; // Let other routing protocols try to handle this diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index bb3046c68..576239964 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -174,7 +174,7 @@ UdpSocket::Close(void) int UdpSocket::Connect(const Address & address) { - NS_DEBUG("UdpSocket::Connect (" << address << ")"); + NS_DEBUG ("UdpSocket::Connect (" << address << ")"); InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); m_defaultAddress = transport.GetIpv4 (); @@ -185,6 +185,8 @@ UdpSocket::Connect(const Address & address) Ptr ipv4; ipv4 = m_node->QueryInterface (Ipv4::iid); m_endPoint->SetLocalAddress (ipv4->GetSourceAddress(m_defaultAddress)); + NS_DEBUG ("UdpSocket::Connect (): Local address is" << + m_endPoint->GetLocalAddress()); return 0; } @@ -270,4 +272,4 @@ UdpSocket::ForwardUp (const Packet &packet, Ipv4Address ipv4, uint16_t port) NotifyDataReceived (p, address); } -}//namespace ns3 +} //namespace ns3