diff --git a/src/internet/model/icmpv6-l4-protocol.cc b/src/internet/model/icmpv6-l4-protocol.cc index 5eb4edb59..5bac99d92 100644 --- a/src/internet/model/icmpv6-l4-protocol.cc +++ b/src/internet/model/icmpv6-l4-protocol.cc @@ -1288,7 +1288,7 @@ Ptr Icmpv6L4Protocol::CreateCache (Ptr device, Ptr cache = CreateObject (); - cache->SetDevice (device, interface); + cache->SetDevice (device, interface, this); device->AddLinkChangeCallback (MakeCallback (&NdiscCache::Flush, cache)); m_cacheList.push_back (cache); return cache; diff --git a/src/internet/model/ndisc-cache.cc b/src/internet/model/ndisc-cache.cc index e41c7e87e..efff7c16f 100644 --- a/src/internet/model/ndisc-cache.cc +++ b/src/internet/model/ndisc-cache.cc @@ -66,14 +66,16 @@ void NdiscCache::DoDispose () Flush (); m_device = 0; m_interface = 0; + m_icmpv6 = 0; Object::DoDispose (); } -void NdiscCache::SetDevice (Ptr device, Ptr interface) +void NdiscCache::SetDevice (Ptr device, Ptr interface, Ptr icmpv6) { NS_LOG_FUNCTION (this << device << interface); m_device = device; m_interface = interface; + m_icmpv6 = icmpv6; } Ptr NdiscCache::GetInterface () const @@ -271,7 +273,6 @@ void NdiscCache::Entry::FunctionReachableTimeout () void NdiscCache::Entry::FunctionRetransmitTimeout () { NS_LOG_FUNCTION_NOARGS (); - Ptr icmpv6 = m_ndCache->GetDevice ()->GetNode ()->GetObject (); Ipv6Address addr; /* determine source address */ @@ -291,11 +292,11 @@ void NdiscCache::Entry::FunctionRetransmitTimeout () } } - if (m_nsRetransmit < icmpv6->GetMaxMulticastSolicit ()) + if (m_nsRetransmit < m_ndCache->m_icmpv6->GetMaxMulticastSolicit ()) { m_nsRetransmit++; - icmpv6->SendNS (addr, Ipv6Address::MakeSolicitedAddress (m_ipv6Address), m_ipv6Address, m_ndCache->GetDevice ()->GetAddress ()); + m_ndCache->m_icmpv6->SendNS (addr, Ipv6Address::MakeSolicitedAddress (m_ipv6Address), m_ipv6Address, m_ndCache->GetDevice ()->GetAddress ()); /* arm the timer again */ StartRetransmitTimer (); } @@ -311,7 +312,7 @@ void NdiscCache::Entry::FunctionRetransmitTimeout () malformedPacket.first->AddHeader (malformedPacket.second); } - icmpv6->SendErrorDestinationUnreachable (malformedPacket.first, addr, Icmpv6Header::ICMPV6_ADDR_UNREACHABLE); + m_ndCache->m_icmpv6->SendErrorDestinationUnreachable (malformedPacket.first, addr, Icmpv6Header::ICMPV6_ADDR_UNREACHABLE); /* delete the entry */ m_ndCache->Remove (this); @@ -321,8 +322,6 @@ void NdiscCache::Entry::FunctionRetransmitTimeout () void NdiscCache::Entry::FunctionDelayTimeout () { NS_LOG_FUNCTION_NOARGS (); - Ptr ipv6 = m_ndCache->GetDevice ()->GetNode ()->GetObject (); - Ptr icmpv6 = ipv6->GetIcmpv6 (); Ipv6Address addr; this->MarkProbe (); @@ -347,7 +346,7 @@ void NdiscCache::Entry::FunctionDelayTimeout () return; } - Ipv6PayloadHeaderPair p = icmpv6->ForgeNS (addr, m_ipv6Address, m_ipv6Address, m_ndCache->GetDevice ()->GetAddress ()); + Ipv6PayloadHeaderPair p = m_ndCache->m_icmpv6->ForgeNS (addr, m_ipv6Address, m_ipv6Address, m_ndCache->GetDevice ()->GetAddress ()); p.first->AddHeader (p.second); m_ndCache->GetDevice ()->Send (p.first, this->GetMacAddress (), Ipv6L3Protocol::PROT_NUMBER); @@ -359,9 +358,7 @@ void NdiscCache::Entry::FunctionProbeTimeout () { NS_LOG_FUNCTION_NOARGS (); - Ptr icmpv6 = m_ndCache->GetDevice ()->GetNode ()->GetObject (); - - if (m_nsRetransmit < icmpv6->GetMaxUnicastSolicit ()) + if (m_nsRetransmit < m_ndCache->m_icmpv6->GetMaxUnicastSolicit ()) { m_nsRetransmit++; @@ -388,7 +385,7 @@ void NdiscCache::Entry::FunctionProbeTimeout () } /* icmpv6->SendNS (m_ndCache->GetInterface ()->GetLinkLocalAddress (), m_ipv6Address, m_ipv6Address, m_ndCache->GetDevice ()->GetAddress ()); */ - Ipv6PayloadHeaderPair p = icmpv6->ForgeNS (addr, m_ipv6Address, m_ipv6Address, m_ndCache->GetDevice ()->GetAddress ()); + Ipv6PayloadHeaderPair p = m_ndCache->m_icmpv6->ForgeNS (addr, m_ipv6Address, m_ipv6Address, m_ndCache->GetDevice ()->GetAddress ()); p.first->AddHeader (p.second); m_ndCache->GetDevice ()->Send (p.first, this->GetMacAddress (), Ipv6L3Protocol::PROT_NUMBER); @@ -422,11 +419,9 @@ void NdiscCache::Entry::StartReachableTimer () m_nudTimer.Cancel (); } - Ptr icmpv6 = m_ndCache->GetDevice ()->GetNode ()->GetObject (); - m_lastReachabilityConfirmation = Simulator::Now (); m_nudTimer.SetFunction (&NdiscCache::Entry::FunctionReachableTimeout, this); - m_nudTimer.SetDelay (icmpv6->GetReachableTime ()); + m_nudTimer.SetDelay (m_ndCache->m_icmpv6->GetReachableTime ()); m_nudTimer.Schedule (); } @@ -453,10 +448,8 @@ void NdiscCache::Entry::StartProbeTimer () m_nudTimer.Cancel (); } - Ptr icmpv6 = m_ndCache->GetDevice ()->GetNode ()->GetObject (); - m_nudTimer.SetFunction (&NdiscCache::Entry::FunctionProbeTimeout, this); - m_nudTimer.SetDelay (icmpv6->GetRetransmissionTime ()); + m_nudTimer.SetDelay (m_ndCache->m_icmpv6->GetRetransmissionTime ()); m_nudTimer.Schedule (); } @@ -468,10 +461,8 @@ void NdiscCache::Entry::StartDelayTimer () m_nudTimer.Cancel (); } - Ptr icmpv6 = m_ndCache->GetDevice ()->GetNode ()->GetObject (); - m_nudTimer.SetFunction (&NdiscCache::Entry::FunctionDelayTimeout, this); - m_nudTimer.SetDelay (icmpv6->GetDelayFirstProbe ()); + m_nudTimer.SetDelay (m_ndCache->m_icmpv6->GetDelayFirstProbe ()); m_nudTimer.Schedule (); } @@ -483,10 +474,8 @@ void NdiscCache::Entry::StartRetransmitTimer () m_nudTimer.Cancel (); } - Ptr icmpv6 = m_ndCache->GetDevice ()->GetNode ()->GetObject (); - m_nudTimer.SetFunction (&NdiscCache::Entry::FunctionRetransmitTimeout, this); - m_nudTimer.SetDelay (icmpv6->GetRetransmissionTime ()); + m_nudTimer.SetDelay (m_ndCache->m_icmpv6->GetRetransmissionTime ()); m_nudTimer.Schedule (); } diff --git a/src/internet/model/ndisc-cache.h b/src/internet/model/ndisc-cache.h index 52d40357f..8fef87382 100644 --- a/src/internet/model/ndisc-cache.h +++ b/src/internet/model/ndisc-cache.h @@ -39,6 +39,7 @@ namespace ns3 class NetDevice; class Ipv6Interface; class Ipv6Header; +class Icmpv6L4Protocol; /** * \ingroup ipv6 @@ -132,7 +133,7 @@ public: * \param device the device * \param interface the IPv6 interface */ - void SetDevice (Ptr device, Ptr interface); + void SetDevice (Ptr device, Ptr interface, Ptr icmpv6); /** * \brief Print the NDISC cache entries @@ -440,6 +441,11 @@ private: */ Ptr m_interface; + /** + * \brief the icmpv6 L4 protocol for this cache. + */ + Ptr m_icmpv6; + /** * \brief A list of Entry. */