22 #include "ns3/uinteger.h"
25 #include "ipv6-l3-protocol.h"
26 #include "icmpv6-l4-protocol.h"
27 #include "ndisc-cache.h"
28 #include "ipv6-interface.h"
35 NS_OBJECT_ENSURE_REGISTERED (NdiscCache);
41 .AddAttribute (
"UnresolvedQueueSize",
42 "Size of the queue for packets pending an NA reply.",
45 MakeUintegerChecker<uint32_t> ())
107 entry->SetIpv6Address (to);
118 if ((*i).second == entry)
156 m_reachableTimer (
Timer::CANCEL_ON_DESTROY),
157 m_retransTimer (
Timer::CANCEL_ON_DESTROY),
158 m_probeTimer (
Timer::CANCEL_ON_DESTROY),
159 m_delayTimer (
Timer::CANCEL_ON_DESTROY),
160 m_lastReachabilityConfirmation (
Seconds (0.0)),
182 if (m_waiting.size () >=
m_ndCache->GetUnresQlen ())
186 m_waiting.remove (0);
188 m_waiting.push_back (p);
211 if (m_ipv6Address.IsLinkLocal ())
213 addr =
m_ndCache->GetInterface ()->GetLinkLocalAddress ().GetAddress ();;
215 else if (!m_ipv6Address.IsAny ())
217 addr =
m_ndCache->GetInterface ()->GetAddressMatchingDestination (m_ipv6Address).GetAddress ();
227 if (GetNSRetransmit () < icmpv6->MAX_MULTICAST_SOLICIT)
233 StartRetransmitTimer ();
238 if (malformedPacket == 0)
240 malformedPacket = Create<Packet> ();
243 icmpv6->SendErrorDestinationUnreachable (malformedPacket, addr, Icmpv6Header::ICMPV6_ADDR_UNREACHABLE);
259 if (m_ipv6Address.IsLinkLocal ())
261 addr =
m_ndCache->GetInterface ()->GetLinkLocalAddress ().GetAddress ();
263 else if (!m_ipv6Address.IsAny ())
265 addr =
m_ndCache->GetInterface ()->GetAddressMatchingDestination (m_ipv6Address).GetAddress ();
279 Ptr<Packet> p = icmpv6->ForgeNS (addr, m_ipv6Address, m_ipv6Address,
m_ndCache->GetDevice ()->GetAddress ());
282 ResetNSRetransmit ();
293 if (GetNSRetransmit () < icmpv6->MAX_UNICAST_SOLICIT)
297 if (m_ipv6Address.IsLinkLocal ())
299 addr =
m_ndCache->GetInterface ()->GetLinkLocalAddress ().GetAddress ();
301 else if (!m_ipv6Address.IsAny ())
303 addr =
m_ndCache->GetInterface ()->GetAddressMatchingDestination (m_ipv6Address).GetAddress ();
319 Ptr<Packet> p = icmpv6->ForgeNS (addr, m_ipv6Address, m_ipv6Address,
m_ndCache->GetDevice ()->GetAddress ());
335 m_ipv6Address = ipv6Address;
341 return m_nsRetransmit;
359 return m_lastReachabilityConfirmation;
372 m_reachableTimer.Schedule ();
378 m_reachableTimer.Cancel ();
386 m_probeTimer.Schedule ();
392 m_probeTimer.Cancel ();
393 ResetNSRetransmit ();
402 m_delayTimer.Schedule ();
408 m_delayTimer.Cancel ();
409 ResetNSRetransmit ();
417 m_retransTimer.Schedule ();
423 m_retransTimer.Cancel ();
424 ResetNSRetransmit ();
430 m_state = INCOMPLETE;
434 m_waiting.push_back (p);
481 return (m_state == STALE);
487 return (m_state == REACHABLE);
493 return (m_state == DELAY);
499 return (m_state == INCOMPLETE);
505 return (m_state == PROBE);
bool IsAny() const
If the IPv6 address is the "Any" address.
void FunctionDelayTimeout()
Function called when delay timer timeout.
static TypeId GetTypeId()
Get the type ID.
Time GetLastReachabilityConfirmation() const
Get the time of last reachability confirmation.
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
void MarkIncomplete(Ptr< Packet > p)
Changes the state to this entry to INCOMPLETE.
Address GetMacAddress() const
Get the MAC address of this entry.
NdiscCache::Entry * Add(Ipv6Address to)
Add an entry.
void SetUnresQlen(uint32_t unresQlen)
Set the max number of waiting packet.
IPv6 layer implementation.
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
void StopReachableTimer()
Stop the reachable timer.
virtual void DoDispose(void)
#define NS_LOG_FUNCTION_NOARGS()
a polymophic address class
uint32_t GetUnresQlen()
Get the max number of waiting packet.
Ptr< Ipv6Interface > GetInterface() const
Get the Ipv6Interface associated with this cache.
bool IsDelay() const
Is the entry DELAY.
Ptr< Ipv6Interface > m_interface
the interface.
void FunctionRetransmitTimeout()
Function called when retransmit timer timeout. It verify that the NS retransmit has reached the max s...
void MarkReachable()
Changes the state to this entry to REACHABLE.
void Flush()
Flush the cache.
Hold an unsigned integer type.
IPv6 Neighbor Discovery cache.
static const uint32_t REACHABLE_TIME
Neighbor Discovery node constants : reachable time.
void StopProbeTimer()
Stop probe timer.
void StartRetransmitTimer()
Start retransmit timer.
void ClearWaitingPacket()
Clear the waiting packet list.
Entry(NdiscCache *nd)
Constructor.
bool IsProbe() const
Is the entry PROBE.
void AddWaitingPacket(Ptr< Packet > p)
Add a packet (or replace old value) in the queue.
void StartDelayTimer()
Start delay timer.
void StartReachableTimer()
Start the reachable timer.
bool IsIncomplete() const
Is the entry INCOMPLETE.
void FunctionReachableTimeout()
Function called when reachable timer timeout.
void StartProbeTimer()
Start probe timer.
static const uint32_t DEFAULT_UNRES_QLEN
Default value for unres qlen.
void Remove(NdiscCache::Entry *entry)
Delete an entry.
void FunctionProbeTimeout()
Function called when probe timer timeout.
uint32_t m_unresQlen
Max number of packet stored in m_waiting.
void SetMacAddress(Address mac)
Set the MAC address of this entry.
Describes an IPv6 address.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
NdiscCache::Entry * Lookup(Ipv6Address dst)
Lookup in the cache.
void MarkStale()
Changes the state to this entry to STALE.
void IncNSRetransmit()
Increment NS retransmit.
void DoDispose()
Dispose this object.
void SetIpv6Address(Ipv6Address ipv6Address)
Set the IPv6 address.
void MarkDelay()
Change the state to this entry to DELAY.
static const uint32_t RETRANS_TIMER
Neighbor Discovery node constants : retransmission timer.
void StopRetransmitTimer()
Stop retransmit timer.
void UpdateLastReachabilityconfirmation()
Update the time of last reachability confirmation.
void StopDelayTimer()
Stop delay timer.
bool IsRouter() const
If the entry is a host or a router.
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv6Interface > interface)
Set the device and interface.
Cache m_ndCache
A list of Entry.
A record that holds information about an NdiscCache entry.
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.
void SetRouter(bool router)
Set the node type.
static const uint8_t DELAY_FIRST_PROBE_TIME
Neighbor Discovery node constants : delay for the first probe.
a base class which provides memory management and object aggregation
bool IsReachable() const
Is the entry REACHABLE.
a unique identifier for an interface.
void ResetNSRetransmit()
Reset NS retransmit (=0).
Ptr< NetDevice > GetDevice() const
Get the NetDevice associated with this cache.
TypeId SetParent(TypeId tid)
void MarkProbe()
Changes the state to this entry to PROBE.
static const uint16_t PROT_NUMBER
The protocol number for IPv6 (0x86DD).
bool IsStale() const
Is the entry STALE.
static Ipv6Address MakeSolicitedAddress(Ipv6Address addr)
Make the solicited IPv6 address.
Ptr< NetDevice > m_device
The NetDevice.
uint8_t GetNSRetransmit() const
Get the number of NS retransmit.