Skip to content

Commit

Permalink
Bug 1522 - Hidden node scenario leads to ARP failure
Browse files Browse the repository at this point in the history
  • Loading branch information
johnabraham2017 committed Aug 15, 2013
1 parent 490bd45 commit 5adb032
Show file tree
Hide file tree
Showing 28 changed files with 115 additions and 6 deletions.
19 changes: 19 additions & 0 deletions src/internet/helper/internet-stack-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
#include "ns3/ipv6-extension.h"
#include "ns3/ipv6-extension-demux.h"
#include "ns3/ipv6-extension-header.h"
#include "ns3/icmpv6-l4-protocol.h"
#include "ns3/global-router-interface.h"
#include <limits>
#include <map>
Expand Down Expand Up @@ -342,6 +343,24 @@ InternetStackHelper::AssignStreams (NodeContainer c, int64_t stream)
NS_ASSERT (fe); // should always exist in the demux
currentStream += fe->AssignStreams (currentStream);
}
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
if (ipv4 != 0)
{
Ptr<ArpL3Protocol> arpL3Protocol = ipv4->GetObject<ArpL3Protocol> ();
if (arpL3Protocol != 0)
{
currentStream += arpL3Protocol->AssignStreams (currentStream);
}
}
Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
if (ipv6 != 0)
{
Ptr<Icmpv6L4Protocol> icmpv6L4Protocol = ipv6->GetObject<Icmpv6L4Protocol> ();
if (icmpv6L4Protocol != 0)
{
currentStream += icmpv6L4Protocol->AssignStreams (currentStream);
}
}
}
return (currentStream - stream);
}
Expand Down
20 changes: 17 additions & 3 deletions src/internet/model/arp-l3-protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "ns3/net-device.h"
#include "ns3/object-vector.h"
#include "ns3/trace-source-accessor.h"
#include "ns3/pointer.h"
#include "ns3/string.h"

#include "ipv4-l3-protocol.h"
#include "arp-l3-protocol.h"
Expand All @@ -49,6 +51,10 @@ ArpL3Protocol::GetTypeId (void)
ObjectVectorValue (),
MakeObjectVectorAccessor (&ArpL3Protocol::m_cacheList),
MakeObjectVectorChecker<ArpCache> ())
.AddAttribute ("RequestJitter", "The jitter in ms a node is allowed to wait before sending an ARP request. Some jitter aims to prevent collisions. By default, the model will wait for a duration in ms defined by a uniform random-variable between 0 and RequestJitter",
StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=10.0]"),
MakePointerAccessor (&ArpL3Protocol::m_requestJitter),
MakePointerChecker<RandomVariableStream> ())
.AddTraceSource ("Drop",
"Packet dropped because not enough room in pending queue for a specific cache entry.",
MakeTraceSourceAccessor (&ArpL3Protocol::m_dropTrace))
Expand All @@ -66,6 +72,14 @@ ArpL3Protocol::~ArpL3Protocol ()
NS_LOG_FUNCTION (this);
}

int64_t
ArpL3Protocol::AssignStreams (int64_t stream)
{
NS_LOG_FUNCTION (this << stream);
m_requestJitter->SetStream (stream);
return 1;
}

void
ArpL3Protocol::SetNode (Ptr<Node> node)
{
Expand Down Expand Up @@ -257,14 +271,14 @@ ArpL3Protocol::Lookup (Ptr<Packet> packet, Ipv4Address destination,
NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
", dead entry for " << destination << " expired -- send arp request");
entry->MarkWaitReply (packet);
SendArpRequest (cache, destination);
Simulator::Schedule (Time (MilliSeconds (m_requestJitter->GetValue ())), &ArpL3Protocol::SendArpRequest, this, cache, destination);
}
else if (entry->IsAlive ())
{
NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
", alive entry for " << destination << " expired -- send arp request");
entry->MarkWaitReply (packet);
SendArpRequest (cache, destination);
Simulator::Schedule (Time (MilliSeconds (m_requestJitter->GetValue ())), &ArpL3Protocol::SendArpRequest, this, cache, destination);
}
else if (entry->IsWaitReply ())
{
Expand Down Expand Up @@ -304,7 +318,7 @@ ArpL3Protocol::Lookup (Ptr<Packet> packet, Ipv4Address destination,
", no entry for " << destination << " -- send arp request");
entry = cache->Add (destination);
entry->MarkWaitReply (packet);
SendArpRequest (cache, destination);
Simulator::Schedule (Time (MilliSeconds (m_requestJitter->GetValue ())), &ArpL3Protocol::SendArpRequest, this, cache, destination);
}
return false;
}
Expand Down
14 changes: 14 additions & 0 deletions src/internet/model/arp-l3-protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ns3/address.h"
#include "ns3/ptr.h"
#include "ns3/traced-callback.h"
#include "ns3/random-variable-stream.h"

namespace ns3 {

Expand Down Expand Up @@ -76,6 +77,17 @@ class ArpL3Protocol : public Object
Ptr<NetDevice> device,
Ptr<ArpCache> cache,
Address *hardwareDestination);

/**
* Assign a fixed random variable stream number to the random variables
* used by this model. Return the number of streams (possibly zero) that
* have been assigned.
*
* \param stream first stream index to use
* \return the number of stream indices assigned by this model
*/
int64_t AssignStreams (int64_t stream);

protected:
virtual void DoDispose (void);
/*
Expand All @@ -93,6 +105,8 @@ class ArpL3Protocol : public Object
CacheList m_cacheList;
Ptr<Node> m_node;
TracedCallback<Ptr<const Packet> > m_dropTrace;
Ptr<RandomVariableStream> m_requestJitter;

};

} // namespace ns3
Expand Down
42 changes: 39 additions & 3 deletions src/internet/model/icmpv6-l4-protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "ns3/boolean.h"
#include "ns3/ipv6-routing-protocol.h"
#include "ns3/ipv6-route.h"
#include "ns3/pointer.h"
#include "ns3/string.h"

#include "ipv6-raw-socket-factory-impl.h"
#include "ipv6-l3-protocol.h"
Expand Down Expand Up @@ -72,6 +74,11 @@ TypeId Icmpv6L4Protocol::GetTypeId ()
BooleanValue (true),
MakeBooleanAccessor (&Icmpv6L4Protocol::m_alwaysDad),
MakeBooleanChecker ())
.AddAttribute ("SolicitationJitter", "The jitter in ms a node is allowed to wait before sending any solicitation . Some jitter aims to prevent collisions. By default, the model will wait for a duration in ms defined by a uniform random-variable between 0 and SolicitationJitter",
StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=10.0]"),
MakePointerAccessor (&Icmpv6L4Protocol::m_solicitationJitter),
MakePointerChecker<RandomVariableStream> ())

;
return tid;
}
Expand Down Expand Up @@ -103,6 +110,13 @@ void Icmpv6L4Protocol::DoDispose ()
IpL4Protocol::DoDispose ();
}

int64_t Icmpv6L4Protocol::AssignStreams (int64_t stream)
{
NS_LOG_FUNCTION (this << stream);
m_solicitationJitter->SetStream (stream);
return 1;
}

void Icmpv6L4Protocol::NotifyNewAggregate ()
{
NS_LOG_FUNCTION (this);
Expand Down Expand Up @@ -174,7 +188,7 @@ void Icmpv6L4Protocol::DoDAD (Ipv6Address target, Ptr<Ipv6Interface> interface)

/* update last packet UID */
interface->SetNsDadUid (target, p->GetUid ());
interface->Send (p, Ipv6Address::MakeSolicitedAddress (target));
Simulator::Schedule (Time (MilliSeconds (m_solicitationJitter->GetValue ())), &Ipv6Interface::Send, interface, p, Ipv6Address::MakeSolicitedAddress (target));
}

enum IpL4Protocol::RxStatus Icmpv6L4Protocol::Receive (Ptr<Packet> packet, Ipv4Header const &header, Ptr<Ipv4Interface> interface)
Expand Down Expand Up @@ -870,6 +884,12 @@ void Icmpv6L4Protocol::SendMessage (Ptr<Packet> packet, Ipv6Address src, Ipv6Add
m_downTarget (packet, src, dst, PROT_NUMBER, 0);
}

void Icmpv6L4Protocol::DelayedSendMessage (Ptr<Packet> packet, Ipv6Address src, Ipv6Address dst, uint8_t ttl)
{
NS_LOG_FUNCTION (this << packet << src << dst << (uint32_t)ttl);
SendMessage (packet, src, dst, ttl);
}

void Icmpv6L4Protocol::SendMessage (Ptr<Packet> packet, Ipv6Address dst, Icmpv6Header& icmpv6Hdr, uint8_t ttl)
{
NS_LOG_FUNCTION (this << packet << dst << icmpv6Hdr << (uint32_t)ttl);
Expand Down Expand Up @@ -964,7 +984,15 @@ void Icmpv6L4Protocol::SendNS (Ipv6Address src, Ipv6Address dst, Ipv6Address tar
p->AddHeader (llOption);
ns.CalculatePseudoHeaderChecksum (src, dst, p->GetSize () + ns.GetSerializedSize (), PROT_NUMBER);
p->AddHeader (ns);
SendMessage (p, src, dst, 255);
if (!dst.IsMulticast ())
{
SendMessage (p, src, dst, 255);
}
else
{
NS_LOG_LOGIC ("Destination is Multicast, using DelayedSendMessage");
Simulator::Schedule (Time (MilliSeconds (m_solicitationJitter->GetValue ())), &Icmpv6L4Protocol::DelayedSendMessage, this, p, src, dst, 255);
}
}

void Icmpv6L4Protocol::SendRS (Ipv6Address src, Ipv6Address dst, Address hardwareAddress)
Expand All @@ -984,7 +1012,15 @@ void Icmpv6L4Protocol::SendRS (Ipv6Address src, Ipv6Address dst, Address hardwa

rs.CalculatePseudoHeaderChecksum (src, dst, p->GetSize () + rs.GetSerializedSize (), PROT_NUMBER);
p->AddHeader (rs);
SendMessage (p, src, dst, 255);
if (!dst.IsMulticast ())
{
SendMessage (p, src, dst, 255);
}
else
{
NS_LOG_LOGIC ("Destination is Multicast, using DelayedSendMessage");
Simulator::Schedule (Time (MilliSeconds (m_solicitationJitter->GetValue ())), &Icmpv6L4Protocol::DelayedSendMessage, this, p, src, dst, 255);
}
}

void Icmpv6L4Protocol::SendErrorDestinationUnreachable (Ptr<Packet> malformedPacket, Ipv6Address dst, uint8_t code)
Expand Down
26 changes: 26 additions & 0 deletions src/internet/model/icmpv6-l4-protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <list>

#include "ns3/ipv6-address.h"
#include "ns3/random-variable-stream.h"

#include "icmpv6-header.h"
#include "ip-l4-protocol.h"

Expand Down Expand Up @@ -189,6 +191,15 @@ class Icmpv6L4Protocol : public IpL4Protocol
*/
void SendMessage (Ptr<Packet> packet, Ipv6Address src, Ipv6Address dst, uint8_t ttl);

/**
* \brief Helper function used during delayed solicitation. Calls SendMessage internally
* \param packet the packet to send which contains ICMPv6 header
* \param src source address
* \param dst destination address
* \param ttl next hop limit
*/
void DelayedSendMessage (Ptr<Packet> packet, Ipv6Address src, Ipv6Address dst, uint8_t ttl);

/**
* \brief Send a packet via ICMPv6.
* \param packet the packet to send
Expand Down Expand Up @@ -396,6 +407,16 @@ class Icmpv6L4Protocol : public IpL4Protocol
*/
bool IsAlwaysDad () const;

/**
* Assign a fixed random variable stream number to the random variables
* used by this model. Return the number of streams (possibly zero) that
* have been assigned.
*
* \param stream first stream index to use
* \return the number of stream indices assigned by this model
*/
int64_t AssignStreams (int64_t stream);

protected:
/**
* \brief Dispose this object.
Expand All @@ -420,6 +441,11 @@ class Icmpv6L4Protocol : public IpL4Protocol
*/
bool m_alwaysDad;

/**
* \brief Random jitter before sending solicitations
*/
Ptr<RandomVariableStream> m_solicitationJitter;

/**
* \brief Notify an ICMPv6 reception to upper layers (if requested).
* \param source the ICMP source
Expand Down
Binary file modified src/mesh/test/dot11s/hwmp-proactive-regression-test-0-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-proactive-regression-test-1-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-proactive-regression-test-2-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-proactive-regression-test-3-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-proactive-regression-test-4-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-reactive-regression-test-0-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-reactive-regression-test-1-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-reactive-regression-test-2-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-reactive-regression-test-3-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-reactive-regression-test-4-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-reactive-regression-test-5-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-simplest-regression-test-0-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-simplest-regression-test-1-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-target-flags-regression-test-0-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-target-flags-regression-test-1-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-target-flags-regression-test-2-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/dot11s/hwmp-target-flags-regression-test-3-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/flame/flame-regression-test-0-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/flame/flame-regression-test-1-1.pcap
Binary file not shown.
Binary file modified src/mesh/test/flame/flame-regression-test-2-1.pcap
Binary file not shown.
Binary file modified src/olsr/test/bug780-0-0.pcap
Binary file not shown.
Binary file modified src/olsr/test/bug780-1-0.pcap
Binary file not shown.
Binary file modified src/olsr/test/bug780-2-0.pcap
Binary file not shown.

0 comments on commit 5adb032

Please sign in to comment.