set source IP address in udp-socket packets
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
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 @@ UdpSocket::ForwardUp (const Packet &packet, Ipv4Address ipv4, uint16_t port)
|
||||
NotifyDataReceived (p, address);
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
} //namespace ns3
|
||||
|
||||
Reference in New Issue
Block a user