diff --git a/examples/aodv.cc b/examples/aodv.cc index 45e7d6ef3..43e9b7ecb 100644 --- a/examples/aodv.cc +++ b/examples/aodv.cc @@ -105,7 +105,7 @@ bool AodvExample::Configure (int argc, char **argv) { // Enable AODV logs by default. Comment this if too noisy - LogComponentEnable("AodvRoutingProtocol", LOG_LEVEL_ALL); + // LogComponentEnable("AodvRoutingProtocol", LOG_LEVEL_ALL); SeedManager::SetSeed(12345); CommandLine cmd; diff --git a/src/routing/aodv/aodv-routing-protocol.cc b/src/routing/aodv/aodv-routing-protocol.cc index 13b7413b9..794af5cb3 100644 --- a/src/routing/aodv/aodv-routing-protocol.cc +++ b/src/routing/aodv/aodv-routing-protocol.cc @@ -234,16 +234,13 @@ RoutingProtocol::RouteInput (Ptr p, const Ipv4Header &header, Ptr< // TODO: local delivery to non-AODV interfaces // Locally deliver all AODV control traffic - if (header.GetProtocol() == 17 /*UDP*/) + if (LooksLikeAodvControl (p, header)) { - UdpHeader uh; - if (p->PeekHeader(uh) && uh.GetDestinationPort() == AODV_PORT && uh.GetSourcePort() == AODV_PORT) - { - NS_LOG_LOGIC("Locally deliver AODV control traffic to " << m_ipv4->GetAddress(iif, 0).GetLocal() << " packet " << p->GetUid()); - Ipv4Header h = header; - h.SetDestination(m_ipv4->GetAddress(iif, 0).GetLocal()); // really want to receive it - lcb(p, h, iif); - } + NS_LOG_LOGIC("Locally deliver AODV control traffic to " << m_ipv4->GetAddress(iif, 0).GetLocal() << " packet " << p->GetUid()); + Ipv4Header h = header; + h.SetDestination(m_ipv4->GetAddress(iif, 0).GetLocal()); // really want to receive it + lcb(p, h, iif); + return true; } // Forwarding @@ -302,6 +299,17 @@ RoutingProtocol::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress a { } +bool +RoutingProtocol::LooksLikeAodvControl (Ptr p, Ipv4Header const & header) const +{ + if (header.GetProtocol() == 17 /*UDP*/) + { + UdpHeader uh; + return (p->PeekHeader(uh) && uh.GetDestinationPort() == AODV_PORT && uh.GetSourcePort() == AODV_PORT); + } + return false; +} + // TODO add use an expanding ring search technique void RoutingProtocol::SendRequest (Ipv4Address dst, bool G, bool D) @@ -444,9 +452,11 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s // silently discards the newly received RREQ. if (LookupBroadcastId (origin, id)) { - NS_LOG_DEBUG ("My interface" << receiver <<" RREQ duplicate from " << origin << " dropped by id " << id); + NS_LOG_DEBUG ("My interface " << receiver <<" RREQ duplicate from " << origin << " dropped by id " << id); return; } + InsertBroadcastId (origin, id); + // Increment RREQ hop count uint8_t hop = rreqHeader.GetHopCount() + 1; rreqHeader.SetHopCount (hop); @@ -531,10 +541,6 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s { Ptr socket = j->first; Ipv4InterfaceAddress iface = j->second; - - rreqHeader.SetOrigin (iface.GetLocal()); - InsertBroadcastId (iface.GetLocal(), bid); - socket->Send(packet); } @@ -639,7 +645,6 @@ RoutingProtocol::RecvReply (Ptr p, Ipv4Address receiverIfaceAddr ,Ipv4Ad } } } - rtable.Print(std::cout); if(receiverIfaceAddr == rrepHeader.GetOrigin()) { diff --git a/src/routing/aodv/aodv-routing-protocol.h b/src/routing/aodv/aodv-routing-protocol.h index b380cda03..22eebe527 100644 --- a/src/routing/aodv/aodv-routing-protocol.h +++ b/src/routing/aodv/aodv-routing-protocol.h @@ -159,6 +159,8 @@ private: void RtPurge (); /// Update neighbor record. \param receiver is supposed to be my interface void UpdateNeighbor (Ipv4Address sender, Ipv4Address receiver); + /// Check that packet is an AODV control message + bool LooksLikeAodvControl (Ptr p, Ipv4Header const & header) const; ///\name Recv //\{