Fix logic error in sending RS and improved logging.

This commit is contained in:
Tommaso Pecorella
2020-05-27 03:12:04 +02:00
parent 54c5b1972c
commit ae554d95cd
3 changed files with 18 additions and 8 deletions

View File

@@ -1406,10 +1406,10 @@ bool Icmpv6L4Protocol::Lookup (Ptr<Packet> p, const Ipv6Header & ipHeader, Ipv6A
return false;
}
void Icmpv6L4Protocol::FunctionDadTimeout (Ptr<Icmpv6L4Protocol> icmpv6, Ipv6Interface* interface, Ipv6Address addr)
void Icmpv6L4Protocol::FunctionDadTimeout (Ipv6Interface* interface, Ipv6Address addr)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_LOGIC (interface << " " << addr);
NS_LOG_FUNCTION (this << interface << addr);
Ipv6InterfaceAddress ifaddr;
bool found = false;
uint32_t i = 0;
@@ -1426,6 +1426,11 @@ void Icmpv6L4Protocol::FunctionDadTimeout (Ptr<Icmpv6L4Protocol> icmpv6, Ipv6Int
}
}
if (!found)
{
NS_LOG_LOGIC ("Can not find the address in the interface.");
}
/* for the moment, this function is always called, if we was victim of a DAD the address is INVALID
* and we do not set it to PREFERRED
*/
@@ -1437,14 +1442,19 @@ void Icmpv6L4Protocol::FunctionDadTimeout (Ptr<Icmpv6L4Protocol> icmpv6, Ipv6Int
/* send an RS if our interface is not forwarding (router) and if address is a link-local ones
* (because we will send RS with it)
*/
Ptr<Ipv6> ipv6 = icmpv6->m_node->GetObject<Ipv6> ();
Ptr<Ipv6> ipv6 = m_node->GetObject<Ipv6> ();
if (!ipv6->IsForwarding (ipv6->GetInterfaceForDevice (interface->GetDevice ())) && addr.IsLinkLocal ())
{
/* \todo Add random delays before sending RS
* because all nodes start at the same time, there will be many of RS around 1 second of simulation time
*/
Simulator::Schedule (Seconds (0.0), &Icmpv6L4Protocol::SendRS, PeekPointer (icmpv6), ifaddr.GetAddress (), Ipv6Address::GetAllRoutersMulticast (), interface->GetDevice ()->GetAddress ());
NS_LOG_LOGIC ("Scheduled a Router Solicitation");
Simulator::Schedule (Seconds (0.0), &Icmpv6L4Protocol::SendRS, this, ifaddr.GetAddress (), Ipv6Address::GetAllRoutersMulticast (), interface->GetDevice ()->GetAddress ());
}
else
{
NS_LOG_LOGIC ("Did not schedule a Router Solicitation because the interface is in forwarding mode");
}
}
}

View File

@@ -320,7 +320,7 @@ public:
* \param interface the interface
* \param addr the IPv6 address
*/
static void FunctionDadTimeout (Ptr<Icmpv6L4Protocol> icmpv6, Ipv6Interface* interface, Ipv6Address addr);
void FunctionDadTimeout (Ipv6Interface* interface, Ipv6Address addr);
/**
* \brief Lookup in the ND cache for the IPv6 address

View File

@@ -219,7 +219,7 @@ void Ipv6Interface::SetForwarding (bool forwarding)
bool Ipv6Interface::AddAddress (Ipv6InterfaceAddress iface)
{
NS_LOG_FUNCTION (this);
NS_LOG_FUNCTION (this << iface);
Ipv6Address addr = iface.GetAddress ();
/* DAD handling */
@@ -243,7 +243,7 @@ bool Ipv6Interface::AddAddress (Ipv6InterfaceAddress iface)
int32_t interfaceId = m_node->GetObject<Ipv6> ()->GetInterfaceForDevice (m_device);
Ptr<Icmpv6L4Protocol> icmpv6 = DynamicCast<Icmpv6L4Protocol> (m_node->GetObject<Ipv6> ()->GetProtocol (Icmpv6L4Protocol::GetStaticProtocolNumber (), interfaceId));
if (icmpv6 && icmpv6->IsAlwaysDad ())
if (icmpv6)
{
if (icmpv6->IsAlwaysDad ())
{