set source IP address in udp-socket packets
authorCraig Dowell <craigdo@ee.washington.edu>
Mon, 13 Aug 2007 19:54:47 -0700
changeset 1435 a70de165a25a
parent 1434 2b63aafb050b
child 1436 9f9fe7919c89
set source IP address in udp-socket packets
examples/csma-multicast.cc
examples/csma-one-subnet.cc
src/internet-node/ipv4-impl.cc
src/internet-node/ipv4-l3-protocol.cc
src/internet-node/ipv4-static-routing.cc
src/internet-node/udp-socket.cc
--- a/examples/csma-multicast.cc	Mon Aug 13 16:21:39 2007 -0700
+++ b/examples/csma-multicast.cc	Mon Aug 13 19:54:47 2007 -0700
@@ -71,11 +71,11 @@
   DebugComponentEnable("DropTailQueue");
   DebugComponentEnable("Channel");
   DebugComponentEnable("CsmaChannel");
+  DebugComponentEnable("NetDevice");
   DebugComponentEnable("CsmaNetDevice");
   DebugComponentEnable("Ipv4L3Protocol");
-  DebugComponentEnable("NetDevice");
+  DebugComponentEnable("OnOffApplication");
   DebugComponentEnable("PacketSocket");
-  DebugComponentEnable("OnOffApplication");
   DebugComponentEnable("UdpSocket");
   DebugComponentEnable("UdpL4Protocol");
   DebugComponentEnable("Ipv4L3Protocol");
@@ -84,18 +84,6 @@
   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
--- a/examples/csma-one-subnet.cc	Mon Aug 13 16:21:39 2007 -0700
+++ b/examples/csma-one-subnet.cc	Mon Aug 13 19:54:47 2007 -0700
@@ -80,7 +80,6 @@
   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
--- a/src/internet-node/ipv4-impl.cc	Mon Aug 13 16:21:39 2007 -0700
+++ b/src/internet-node/ipv4-impl.cc	Mon Aug 13 19:54:47 2007 -0700
@@ -184,8 +184,10 @@
 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);
--- a/src/internet-node/ipv4-l3-protocol.cc	Mon Aug 13 16:21:39 2007 -0700
+++ b/src/internet-node/ipv4-l3-protocol.cc	Mon Aug 13 19:54:47 2007 -0700
@@ -703,10 +703,13 @@
        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;
         }
     }
--- a/src/internet-node/ipv4-static-routing.cc	Mon Aug 13 16:21:39 2007 -0700
+++ b/src/internet-node/ipv4-static-routing.cc	Mon Aug 13 19:54:47 2007 -0700
@@ -406,6 +406,8 @@
             }
 
           ifIndex = mRoute->GetOutputInterface(0);
+          NS_DEBUG ("Ipv4StaticRouting::RequestIfIndex (): "
+            "Found ifIndex " << ifIndex);
           return true;
         }
       return false; // Let other routing protocols try to handle this
--- a/src/internet-node/udp-socket.cc	Mon Aug 13 16:21:39 2007 -0700
+++ b/src/internet-node/udp-socket.cc	Mon Aug 13 19:54:47 2007 -0700
@@ -174,7 +174,7 @@
 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 @@
   Ptr<Ipv4> ipv4;
   ipv4 = m_node->QueryInterface<Ipv4> (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 @@
   NotifyDataReceived (p, address);
 }
 
-}//namespace ns3
+} //namespace ns3