diff --git a/src/aodv/model/aodv-routing-protocol.cc b/src/aodv/model/aodv-routing-protocol.cc index 5b24341c1..d4683fb48 100644 --- a/src/aodv/model/aodv-routing-protocol.cc +++ b/src/aodv/model/aodv-routing-protocol.cc @@ -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 @@ -334,6 +332,7 @@ RoutingProtocol::RouteOutput (Ptr 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 ()) @@ -368,6 +367,7 @@ RoutingProtocol::RouteOutput (Ptr 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); @@ -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, Ptr packet, Ipv4Address destination) +{ + socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT)); + +} void RoutingProtocol::ScheduleRreqRetry (Ipv4Address dst) { @@ -1101,7 +1100,32 @@ RoutingProtocol::RecvRequest (Ptr 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 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(rreqHeader.GetHopCount ()) << " ID " << rreqHeader.GetId () << " to destination " << rreqHeader.GetDst ()); @@ -1170,16 +1194,9 @@ RoutingProtocol::RecvRequest (Ptr 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)))); - } } } @@ -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 @@ -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); } } @@ -1757,7 +1785,7 @@ RoutingProtocol::SendRerrMessage (Ptr packet, std::vector p Ptr 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; @@ -1790,8 +1818,7 @@ RoutingProtocol::SendRerrMessage (Ptr packet, std::vector 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); } } diff --git a/src/aodv/model/aodv-routing-protocol.h b/src/aodv/model/aodv-routing-protocol.h index c56237f79..fac4ba2b1 100644 --- a/src/aodv/model/aodv-routing-protocol.h +++ b/src/aodv/model/aodv-routing-protocol.h @@ -248,6 +248,8 @@ private: void SendRerrWhenNoRouteToForward (Ipv4Address dst, uint32_t dstSeqNo, Ipv4Address origin); //\} + void SendTo (Ptr socket, Ptr packet, Ipv4Address destination); + /// Hello timer Timer m_htimer; /// Schedule next send of hello message @@ -269,6 +271,8 @@ private: /// Provides uniform random variables. Ptr m_uniformRandomVariable; + /// Keep track of the last bcast time + Time m_lastBcastTime; }; } diff --git a/src/aodv/test/aodv-chain-regression-test-0-0.pcap b/src/aodv/test/aodv-chain-regression-test-0-0.pcap index 4b41d0aa3..c5edd7e39 100644 Binary files a/src/aodv/test/aodv-chain-regression-test-0-0.pcap and b/src/aodv/test/aodv-chain-regression-test-0-0.pcap differ diff --git a/src/aodv/test/aodv-chain-regression-test-1-0.pcap b/src/aodv/test/aodv-chain-regression-test-1-0.pcap index 80a643ce5..7f42fb015 100644 Binary files a/src/aodv/test/aodv-chain-regression-test-1-0.pcap and b/src/aodv/test/aodv-chain-regression-test-1-0.pcap differ diff --git a/src/aodv/test/aodv-chain-regression-test-2-0.pcap b/src/aodv/test/aodv-chain-regression-test-2-0.pcap index daf3dc307..673bfc071 100644 Binary files a/src/aodv/test/aodv-chain-regression-test-2-0.pcap and b/src/aodv/test/aodv-chain-regression-test-2-0.pcap differ diff --git a/src/aodv/test/aodv-chain-regression-test-3-0.pcap b/src/aodv/test/aodv-chain-regression-test-3-0.pcap index d2400c9f0..c582f750e 100644 Binary files a/src/aodv/test/aodv-chain-regression-test-3-0.pcap and b/src/aodv/test/aodv-chain-regression-test-3-0.pcap differ diff --git a/src/aodv/test/aodv-chain-regression-test-4-0.pcap b/src/aodv/test/aodv-chain-regression-test-4-0.pcap index 6133c2525..2298c3ea6 100644 Binary files a/src/aodv/test/aodv-chain-regression-test-4-0.pcap and b/src/aodv/test/aodv-chain-regression-test-4-0.pcap differ diff --git a/src/aodv/test/aodv-regression.cc b/src/aodv/test/aodv-regression.cc index 149e8b6c4..f68f13725 100644 --- a/src/aodv/test/aodv-regression.cc +++ b/src/aodv/test/aodv-regression.cc @@ -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"); diff --git a/src/aodv/test/bug-606-test-0-0.pcap b/src/aodv/test/bug-606-test-0-0.pcap index 881801b99..6f4d627a4 100644 Binary files a/src/aodv/test/bug-606-test-0-0.pcap and b/src/aodv/test/bug-606-test-0-0.pcap differ diff --git a/src/aodv/test/bug-606-test-1-0.pcap b/src/aodv/test/bug-606-test-1-0.pcap index fe8aee8aa..c977009b1 100644 Binary files a/src/aodv/test/bug-606-test-1-0.pcap and b/src/aodv/test/bug-606-test-1-0.pcap differ diff --git a/src/aodv/test/bug-606-test-2-0.pcap b/src/aodv/test/bug-606-test-2-0.pcap index 4be2d5bda..c12506513 100644 Binary files a/src/aodv/test/bug-606-test-2-0.pcap and b/src/aodv/test/bug-606-test-2-0.pcap differ diff --git a/src/aodv/test/udp-chain-test-0-0.pcap b/src/aodv/test/udp-chain-test-0-0.pcap index 92c778557..5f427df00 100644 Binary files a/src/aodv/test/udp-chain-test-0-0.pcap and b/src/aodv/test/udp-chain-test-0-0.pcap differ diff --git a/src/aodv/test/udp-chain-test-9-0.pcap b/src/aodv/test/udp-chain-test-9-0.pcap index fea37c4c2..31435245c 100644 Binary files a/src/aodv/test/udp-chain-test-9-0.pcap and b/src/aodv/test/udp-chain-test-9-0.pcap differ