socket update broke multicast
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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> ipv4 = m_node->QueryInterface<Ipv4> (Ipv4::iid);
|
||||
|
||||
if (ipv4->GetIfIndexForDestination (m_defaultAddress, localIfIndex))
|
||||
{
|
||||
uint32_t localIfIndex = routeToDest.GetInterface ();
|
||||
Ptr<Ipv4> ipv4 = m_node->QueryInterface<Ipv4> (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> ipv4 = m_node->QueryInterface<Ipv4> (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> ipv4 = m_node->QueryInterface<Ipv4> (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> ipv4 = m_node->QueryInterface<Ipv4> (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;
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ Ipv4::~Ipv4 ()
|
||||
{}
|
||||
|
||||
uint32_t
|
||||
GetIfIndexByIpv4Address (Ptr<Node> node, Ipv4Address a, Ipv4Mask amask)
|
||||
Ipv4::GetIfIndexByAddress (Ptr<Node> node, Ipv4Address a, Ipv4Mask amask)
|
||||
{
|
||||
Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (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> 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> node, Ipv4Route& route,
|
||||
Ipv4Address a, Ipv4Mask amask)
|
||||
Ipv4::GetRouteToDestination (
|
||||
Ptr<Node> node,
|
||||
Ipv4Route& route,
|
||||
Ipv4Address a,
|
||||
Ipv4Mask amask)
|
||||
{
|
||||
Ipv4Route tempRoute;
|
||||
Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (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> node, Ipv4Route& route,
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -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> node,
|
||||
Ipv4Address a,
|
||||
Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
|
||||
static uint32_t GetIfIndexByAddress (Ptr<Node> node, Ipv4Address a,
|
||||
Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
|
||||
|
||||
bool GetIpv4RouteToDestination (Ptr<Node> node, Ipv4Route& route,
|
||||
Ipv4Address a,
|
||||
Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
|
||||
static bool GetRouteToDestination (Ptr<Node> node, Ipv4Route& route,
|
||||
Ipv4Address a, Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
|
||||
@@ -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) );
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user