diff --git a/src/internet-stack/icmpv6-l4-protocol.cc b/src/internet-stack/icmpv6-l4-protocol.cc index b783c6a93..8ea3ee0f6 100644 --- a/src/internet-stack/icmpv6-l4-protocol.cc +++ b/src/internet-stack/icmpv6-l4-protocol.cc @@ -69,6 +69,10 @@ TypeId Icmpv6L4Protocol::GetTypeId () static TypeId tid = TypeId ("ns3::Icmpv6L4Protocol") .SetParent () .AddConstructor () + .AddAttribute ("DAD", "Always do DAD check.", + BooleanValue (true), + MakeBooleanAccessor (&Icmpv6L4Protocol::m_alwaysDad), + MakeBooleanChecker ()) ; return tid; } @@ -144,14 +148,24 @@ int Icmpv6L4Protocol::GetVersion () const return 1; } +bool Icmpv6L4Protocol::IsAlwaysDad () const +{ + return m_alwaysDad; +} + void Icmpv6L4Protocol::DoDAD (Ipv6Address target, Ptr interface) { NS_LOG_FUNCTION (this << target << interface); Ipv6Address addr; - Ptr ipv6 = m_node->GetObject (); + NS_ASSERT (ipv6); + if(!m_alwaysDad) + { + return; + } + /* TODO : disable multicast loopback to prevent NS probing to be received by the sender */ Ptr p = ForgeNS ("::" ,Ipv6Address::MakeSolicitedAddress (target), target, interface->GetDevice ()->GetAddress ()); diff --git a/src/internet-stack/icmpv6-l4-protocol.h b/src/internet-stack/icmpv6-l4-protocol.h index 4fecb747d..d7a13b1a5 100644 --- a/src/internet-stack/icmpv6-l4-protocol.h +++ b/src/internet-stack/icmpv6-l4-protocol.h @@ -28,6 +28,7 @@ #include "ns3/ptr.h" #include "ns3/socket.h" #include "ns3/buffer.h" +#include "ns3/boolean.h" #include "icmpv6-header.h" #include "ipv6-l4-protocol.h" #include "ndisc-cache.h" @@ -387,6 +388,12 @@ class Icmpv6L4Protocol : public Ipv6L4Protocol */ Ptr CreateCache (Ptr device, Ptr interface); + /** + * \brief Is the node must do DAD. + * \return true if node has to do DAD. + */ + bool IsAlwaysDad () const; + protected: /** * \brief Dispose this object. @@ -407,6 +414,11 @@ class Icmpv6L4Protocol : public Ipv6L4Protocol */ CacheList m_cacheList; + /** + * \brief Always do DAD ? + */ + bool m_alwaysDad; + /** * \brief Receive Neighbor Solicitation method. * \param p the packet diff --git a/src/internet-stack/ipv6-interface.cc b/src/internet-stack/ipv6-interface.cc index 9c07ec984..34d0cb82e 100644 --- a/src/internet-stack/ipv6-interface.cc +++ b/src/internet-stack/ipv6-interface.cc @@ -196,7 +196,7 @@ bool Ipv6Interface::AddAddress (Ipv6InterfaceAddress iface) /* DAD handling */ Ptr icmpv6 = m_node->GetObject ()->GetIcmpv6 (); - if (icmpv6) + if (icmpv6 && icmpv6->IsAlwaysDad ()) { Simulator::Schedule (Seconds (0.), &Icmpv6L4Protocol::DoDAD, icmpv6, addr, this); Simulator::Schedule (Seconds (1.), &Icmpv6L4Protocol::FunctionDadTimeout, icmpv6, this, addr); diff --git a/src/internet-stack/ipv6-test.cc b/src/internet-stack/ipv6-test.cc index 4f3de3892..55e320ca6 100644 --- a/src/internet-stack/ipv6-test.cc +++ b/src/internet-stack/ipv6-test.cc @@ -78,6 +78,7 @@ bool Ipv6L3ProtocolTest::RunTests () uint32_t index = 0; /* init */ + icmpv6->SetAttribute ("DAD", BooleanValue (false)); node->AggregateObject (ipv6); node->AggregateObject (icmpv6); ipv6->Insert (icmpv6);