Skip to content

Commit

Permalink
Bug 1190 - Suppress hello if bcast was sent within the last hello int…
Browse files Browse the repository at this point in the history
…erval
  • Loading branch information
johnabraham2017 committed Aug 15, 2013
1 parent 9c172a5 commit 08e8705
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 32 deletions.
87 changes: 57 additions & 30 deletions src/aodv/model/aodv-routing-protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,10 @@ RoutingProtocol::RoutingProtocol () :
m_rerrCount (0),
m_htimer (Timer::CANCEL_ON_DESTROY),
m_rreqRateLimitTimer (Timer::CANCEL_ON_DESTROY),
m_rerrRateLimitTimer (Timer::CANCEL_ON_DESTROY)
m_rerrRateLimitTimer (Timer::CANCEL_ON_DESTROY),
m_lastBcastTime (Seconds (0))
{
if (EnableHello)
{
m_nb.SetCallback (MakeCallback (&RoutingProtocol::SendRerrWhenBreaksLinkToNextHop, this));
}
m_nb.SetCallback (MakeCallback (&RoutingProtocol::SendRerrWhenBreaksLinkToNextHop, this));
}

TypeId
Expand Down Expand Up @@ -334,6 +332,7 @@ RoutingProtocol::RouteOutput (Ptr<Packet> p, const Ipv4Header &header,
NS_LOG_FUNCTION (this << header << (oif ? oif->GetIfIndex () : 0));
if (!p)
{
NS_LOG_DEBUG("Packet is == 0");
return LoopbackRoute (header, oif); // later
}
if (m_socketAddresses.empty ())
Expand Down Expand Up @@ -368,6 +367,7 @@ RoutingProtocol::RouteOutput (Ptr<Packet> p, const Ipv4Header &header,
// routed to loopback, received from loopback and passed to RouteInput (see below)
uint32_t iif = (oif ? m_ipv4->GetInterfaceForDevice (oif) : -1);
DeferredRouteOutputTag tag (iif);
NS_LOG_DEBUG ("Valid Route not found");
if (!p->PeekPacketTag (tag))
{
p->AddPacketTag (tag);
Expand Down Expand Up @@ -903,19 +903,18 @@ RoutingProtocol::SendRequest (Ipv4Address dst)
destination = iface.GetBroadcast ();
}
NS_LOG_DEBUG ("Send RREQ with id " << rreqHeader.GetId () << " to socket");
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT));
m_lastBcastTime = Simulator::Now ();
Simulator::Schedule (Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))), &RoutingProtocol::SendTo, this, socket, packet, destination);
}
ScheduleRreqRetry (dst);
if (EnableHello)
{
if (!m_htimer.IsRunning ())
{
m_htimer.Cancel ();
m_htimer.Schedule (HelloInterval - Time (0.01 * MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))));
}
}
}

void
RoutingProtocol::SendTo (Ptr<Socket> socket, Ptr<Packet> packet, Ipv4Address destination)
{
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT));

}
void
RoutingProtocol::ScheduleRreqRetry (Ipv4Address dst)
{
Expand Down Expand Up @@ -1101,7 +1100,32 @@ RoutingProtocol::RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address s
toOrigin.SetLifeTime (std::max (Time (2 * NetTraversalTime - 2 * hop * NodeTraversalTime),
toOrigin.GetLifeTime ()));
m_routingTable.Update (toOrigin);
//m_nb.Update (src, Time (AllowedHelloLoss * HelloInterval));
}


RoutingTableEntry toNeighbor;
if (!m_routingTable.LookupRoute (src, toNeighbor))
{
NS_LOG_DEBUG ("Neighbor:" << src << " not found in routing table. Creating an entry");
Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (receiver));
RoutingTableEntry newEntry (dev, src, false, rreqHeader.GetOriginSeqno (),
m_ipv4->GetAddress (m_ipv4->GetInterfaceForAddress (receiver), 0),
1, src, ActiveRouteTimeout);
m_routingTable.AddRoute (newEntry);
}
else
{
toNeighbor.SetLifeTime (ActiveRouteTimeout);
toNeighbor.SetValidSeqNo (false);
toNeighbor.SetSeqNo (rreqHeader.GetOriginSeqno ());
toNeighbor.SetFlag (VALID);
toNeighbor.SetOutputDevice (m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (receiver)));
toNeighbor.SetInterface (m_ipv4->GetAddress (m_ipv4->GetInterfaceForAddress (receiver), 0));
m_routingTable.Update (toNeighbor);
}
m_nb.Update (src, Time (AllowedHelloLoss * HelloInterval));

NS_LOG_LOGIC (receiver << " receive RREQ with hop count " << static_cast<uint32_t>(rreqHeader.GetHopCount ())
<< " ID " << rreqHeader.GetId ()
<< " to destination " << rreqHeader.GetDst ());
Expand Down Expand Up @@ -1170,16 +1194,9 @@ RoutingProtocol::RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address s
{
destination = iface.GetBroadcast ();
}
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT));
}
m_lastBcastTime = Simulator::Now ();
Simulator::Schedule (Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))), &RoutingProtocol::SendTo, this, socket, packet, destination);

if (EnableHello)
{
if (!m_htimer.IsRunning ())
{
m_htimer.Cancel ();
m_htimer.Schedule (HelloInterval - Time (0.1 * MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))));
}
}
}

Expand Down Expand Up @@ -1539,10 +1556,20 @@ void
RoutingProtocol::HelloTimerExpire ()
{
NS_LOG_FUNCTION (this);
SendHello ();
Time offset = Time (Seconds (0));
if (m_lastBcastTime > Time (Seconds (0)))
{
offset = Simulator::Now () - m_lastBcastTime;
NS_LOG_DEBUG ("Hello deferred due to last bcast at:" << m_lastBcastTime);
}
else
{
SendHello ();
}
m_htimer.Cancel ();
Time t = Time (0.01 * MilliSeconds (m_uniformRandomVariable->GetInteger (0, 100)));
m_htimer.Schedule (HelloInterval - t);
Time diff = HelloInterval - offset;
m_htimer.Schedule (std::max (Time (Seconds (0)), diff));
m_lastBcastTime = Time (Seconds (0));
}

void
Expand Down Expand Up @@ -1598,7 +1625,8 @@ RoutingProtocol::SendHello ()
{
destination = iface.GetBroadcast ();
}
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT));
Time jitter = Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10)));
Simulator::Schedule (jitter, &RoutingProtocol::SendTo, this , socket, packet, destination);
}
}

Expand Down Expand Up @@ -1757,7 +1785,7 @@ RoutingProtocol::SendRerrMessage (Ptr<Packet> packet, std::vector<Ipv4Address> p
Ptr<Socket> socket = FindSocketWithInterfaceAddress (toPrecursor.GetInterface ());
NS_ASSERT (socket);
NS_LOG_LOGIC ("one precursor => unicast RERR to " << toPrecursor.GetDestination () << " from " << toPrecursor.GetInterface ().GetLocal ());
socket->SendTo (packet, 0, InetSocketAddress (precursors.front (), AODV_PORT));
Simulator::Schedule (Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))), &RoutingProtocol::SendTo, this, socket, packet, precursors.front ());
m_rerrCount++;
}
return;
Expand Down Expand Up @@ -1790,8 +1818,7 @@ RoutingProtocol::SendRerrMessage (Ptr<Packet> packet, std::vector<Ipv4Address> p
{
destination = i->GetBroadcast ();
}
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT));
m_rerrCount++;
Simulator::Schedule (Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))), &RoutingProtocol::SendTo, this, socket, packet, destination);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/aodv/model/aodv-routing-protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ class RoutingProtocol : public Ipv4RoutingProtocol
void SendRerrWhenNoRouteToForward (Ipv4Address dst, uint32_t dstSeqNo, Ipv4Address origin);
//\}

void SendTo (Ptr<Socket> socket, Ptr<Packet> packet, Ipv4Address destination);

/// Hello timer
Timer m_htimer;
/// Schedule next send of hello message
Expand All @@ -269,6 +271,8 @@ class RoutingProtocol : public Ipv4RoutingProtocol

/// Provides uniform random variables.
Ptr<UniformRandomVariable> m_uniformRandomVariable;
/// Keep track of the last bcast time
Time m_lastBcastTime;
};

}
Expand Down
Binary file modified src/aodv/test/aodv-chain-regression-test-0-0.pcap
Binary file not shown.
Binary file modified src/aodv/test/aodv-chain-regression-test-1-0.pcap
Binary file not shown.
Binary file modified src/aodv/test/aodv-chain-regression-test-2-0.pcap
Binary file not shown.
Binary file modified src/aodv/test/aodv-chain-regression-test-3-0.pcap
Binary file not shown.
Binary file modified src/aodv/test/aodv-chain-regression-test-4-0.pcap
Binary file not shown.
4 changes: 2 additions & 2 deletions src/aodv/test/aodv-regression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ ChainRegressionTest::CreateDevices ()
internetStack.Install (*m_nodes);
streamsUsed += internetStack.AssignStreams (*m_nodes, streamsUsed);
// InternetStack uses m_size more streams
NS_TEST_ASSERT_MSG_EQ (streamsUsed, (devices.GetN () * 6) + m_size, "Stream assignment mismatch");
NS_TEST_ASSERT_MSG_EQ (streamsUsed, (devices.GetN () * 8) + m_size, "Stream assignment mismatch");
streamsUsed += aodv.AssignStreams (*m_nodes, streamsUsed);
// AODV uses m_size more streams
NS_TEST_ASSERT_MSG_EQ (streamsUsed, ((devices.GetN () * 6) + (2*m_size)), "Stream assignment mismatch");
NS_TEST_ASSERT_MSG_EQ (streamsUsed, ((devices.GetN () * 8) + (2*m_size)), "Stream assignment mismatch");

Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Expand Down
Binary file modified src/aodv/test/bug-606-test-0-0.pcap
Binary file not shown.
Binary file modified src/aodv/test/bug-606-test-1-0.pcap
Binary file not shown.
Binary file modified src/aodv/test/bug-606-test-2-0.pcap
Binary file not shown.
Binary file modified src/aodv/test/udp-chain-test-0-0.pcap
Binary file not shown.
Binary file modified src/aodv/test/udp-chain-test-9-0.pcap
Binary file not shown.

0 comments on commit 08e8705

Please sign in to comment.