From dadcb2e987b82015d8e59843308120117a27936f Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Tue, 4 Aug 2009 17:50:00 +0400 Subject: [PATCH] logic checking in progress --- src/routing/aodv/aodv-routing-protocol.cc | 88 ++++++++++++++--------- src/routing/aodv/aodv-routing-protocol.h | 7 +- src/routing/aodv/aodv-rqueue.cc | 3 +- src/routing/aodv/aodv-rtable.cc | 10 ++- 4 files changed, 68 insertions(+), 40 deletions(-) diff --git a/src/routing/aodv/aodv-routing-protocol.cc b/src/routing/aodv/aodv-routing-protocol.cc index c70ce0c0d..99d04ff1d 100644 --- a/src/routing/aodv/aodv-routing-protocol.cc +++ b/src/routing/aodv/aodv-routing-protocol.cc @@ -122,12 +122,12 @@ RoutingProtocol::RoutingProtocol () : * This is to account for possible additional route discovery attempts. */ NextHopWait(NodeTraversalTime + MilliSeconds (10)), - TtlStart(1), TtlIncrement(2), TtlThreshold(7), MaxRepairTtl(0.3* NetDiameter), LOCAL_ADD_TTL(2), + TtlStart(2), TtlIncrement(2), TtlThreshold(7), MaxRepairTtl(0.3* NetDiameter), LOCAL_ADD_TTL(2), TIMEOUT_BUFFER (2), BLACKLIST_TIMEOUT( Scalar ( (((TtlThreshold - TtlStart)/TtlIncrement) + 1 + RreqRetries) )*NetTraversalTime ), MaxQueueLen (64), MaxQueueTime (Seconds(30)), DestinationOnly (false), GratuitousReply (true), m_routingTable (DeletePeriod), m_queue (MaxQueueLen, MaxQueueTime), - m_requestId (0), m_seqNo (0), btimer (Timer::CANCEL_ON_DESTROY), htimer (Timer::CANCEL_ON_DESTROY), ntimer (Timer::CANCEL_ON_DESTROY), + m_requestId (0), m_seqNo (0), htimer (Timer::CANCEL_ON_DESTROY), ntimer (Timer::CANCEL_ON_DESTROY), rtimer (Timer::CANCEL_ON_DESTROY), lrtimer (Timer::CANCEL_ON_DESTROY) @@ -161,10 +161,10 @@ RoutingProtocol::GetTypeId (void) .AddAttribute ("NetDiameter", "Net diameter measures the maximum possible number of hops between two nodes in the network", UintegerValue (35), MakeUintegerAccessor (&RoutingProtocol::NetDiameter), - MakeUintegerChecker ()) + MakeUintegerChecker ()) .AddAttribute ("TtlStart", "Initial value of TTL in RREQ when use an expanding ring search " "(should be set to at least 2 if Hello messages are used for local connectivity information.)", - UintegerValue (1), + UintegerValue (2), MakeUintegerAccessor (&RoutingProtocol::TtlStart), MakeUintegerChecker ()) .AddAttribute ("TtlIncrement", "Increment value of RREQ TTL when use an expanding ring search", @@ -253,7 +253,6 @@ RoutingProtocol::Start () m_scb = MakeCallback (&RoutingProtocol::Send, this); m_ecb = MakeCallback (&RoutingProtocol::Drop, this); - btimer.Schedule(); ntimer.Schedule(); rtimer.Schedule(); } @@ -262,6 +261,7 @@ Ptr RoutingProtocol::RouteOutput (Ptr p, const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr ) { NS_LOG_FUNCTION (this << p->GetUid() << header.GetDestination()); + sockerr = Socket::ERROR_NOTERROR; Ptr route; Ipv4Address dst = header.GetDestination (); RoutingTableEntry rt; @@ -271,24 +271,27 @@ RoutingProtocol::RouteOutput (Ptr p, const Ipv4Header &header, uint32_t { route = rt.GetRoute (); NS_ASSERT (route != 0); - sockerr = Socket::ERROR_NOTERROR; NS_LOG_LOGIC("exist route to " << route->GetDestination() << " from iface " << route->GetSource()); UpdateRouteLifeTime (dst, ActiveRouteTimeout); + UpdateRouteLifeTime (route->GetGateway(), ActiveRouteTimeout); + UpdateNeighbor (route->GetGateway(), ActiveRouteTimeout); } else { QueueEntry newEntry (p, header, m_scb, m_ecb); + m_queue.Enqueue (newEntry); - sockerr = Socket::ERROR_NOROUTETOHOST; if (rt.GetFlag () == RTF_DOWN) { - m_routingTable.SetEntryState (dst, RTF_IN_REPAIR); + m_routingTable.SetEntryState (dst, RTF_IN_SEARCH); SendRequest (dst, rt.GetHop () + TtlIncrement); } } } else { + QueueEntry newEntry (p, header, m_scb, m_ecb); + m_queue.Enqueue (newEntry); SendRequest (dst, TtlStart); } return route; @@ -324,6 +327,7 @@ RoutingProtocol::RouteInput (Ptr p, const Ipv4Header &header, Ptr< return true; } m_idCache.InsertId (origin, p->GetUid (), PathDiscoveryTime); + UpdateRouteLifeTime (origin, ActiveRouteTimeout); NS_LOG_LOGIC ("Broadcast local delivery to " << iface.GetLocal ()); lcb (p, header, iif); // TODO has TTL, forward @@ -335,6 +339,11 @@ RoutingProtocol::RouteInput (Ptr p, const Ipv4Header &header, Ptr< Ipv4InterfaceAddress iface = j->second; if (dst == iface.GetLocal ()) { + UpdateRouteLifeTime (origin, ActiveRouteTimeout); + RoutingTableEntry toOrigin; + m_routingTable.LookupRoute (origin, toOrigin); + UpdateRouteLifeTime (toOrigin.GetNextHop (), ActiveRouteTimeout); + UpdateNeighbor (toOrigin.GetNextHop (), ActiveRouteTimeout); NS_LOG_LOGIC ("Unicast local delivery to " << iface.GetLocal ()); lcb (p, header, iif); return true; @@ -397,14 +406,12 @@ RoutingProtocol::SetIpv4 (Ptr ipv4) NS_ASSERT (ipv4 != 0); NS_ASSERT (m_ipv4 == 0); - btimer.SetFunction (&RoutingProtocol::BroadcastTimerExpire, this); ntimer.SetFunction (&RoutingProtocol::NeighborTimerExpire, this); rtimer.SetFunction (&RoutingProtocol::RouteCacheTimerExpire, this); lrtimer.SetFunction (&RoutingProtocol::LocalRepairTimerExpire, this); htimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this); htimer.SetDelay (HelloInterval); - btimer.SetDelay (PathDiscoveryTime); rtimer.SetDelay (FREQUENCY); m_ipv4 = ipv4; @@ -482,7 +489,6 @@ RoutingProtocol::SendRequest (Ipv4Address dst, uint16_t ttl ) Ptr dev; rreqHeader.SetUnknownSeqno (true); RoutingTableEntry newEntry (dev, dst, false, 0, Ipv4InterfaceAddress (), 0, Ipv4Address (), Seconds (0)); - newEntry.IncrementRreqCnt (); newEntry.SetFlag (RTF_IN_SEARCH); m_routingTable.AddRoute (newEntry); } @@ -532,9 +538,9 @@ RoutingProtocol::SendRequest (Ipv4Address dst, uint16_t ttl ) m_routingTable.LookupRoute (dst, rt); if (ttl == NetDiameter) { - m_addressReqTimer[dst].Schedule (Scalar (rt.GetRreqCnt ()) * NetTraversalTime); rt.IncrementRreqCnt (); m_routingTable.Update (rt); + m_addressReqTimer[dst].Schedule (Scalar (rt.GetRreqCnt ()) * NetTraversalTime); } else m_addressReqTimer[dst].Schedule (Scalar (2) * NodeTraversalTime * Scalar (ttl + TIMEOUT_BUFFER)); @@ -634,7 +640,7 @@ RoutingProtocol::UpdateRouteToNeighbor (Ipv4Address sender, Ipv4Address receiver void RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address src, Ipv4Header ipv4Header ) { - NS_LOG_FUNCTION (this << receiver << src); + NS_LOG_FUNCTION (this); RreqHeader rreqHeader; p->RemoveHeader (rreqHeader); // TODO check that header correctly found @@ -655,7 +661,6 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s */ if (m_idCache.LookupId (origin, id)) { - NS_LOG_DEBUG ("My interface " << receiver <<" RREQ duplicate from " << origin << " dropped by id " << id); return; } m_idCache.InsertId (origin, id, PathDiscoveryTime); @@ -714,7 +719,7 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s */ RoutingTableEntry toDst; Ipv4Address dst = rreqHeader.GetDst (); - NS_LOG_LOGIC ("RREQ to destination " << dst); + NS_LOG_LOGIC (receiver << " recieve RREQ to destination " << dst << " with ttl " << (uint16_t) ipv4Header.GetTtl ()); if (m_routingTable.LookupRoute (dst, toDst)) { /* @@ -738,7 +743,7 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s * If a node does not generate a RREP the incoming IP header has TTL larger than 1, the node updates * and broadcasts the RREQ on each of its configured interfaces. */ - if (ipv4Header.GetTtl () < 2) + if (ipv4Header.GetTtl () < 1) return; for (std::map , Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j != m_socketAddresses.end (); ++j) @@ -784,7 +789,7 @@ RoutingProtocol::SendReply (RreqHeader const & rreqHeader, RoutingTableEntry con TypeHeader tHeader (AODVTYPE_RREP); packet->AddHeader (tHeader); BuildPacket (/*packet*/packet, /*source port*/AODV_PORT, /*destination port*/AODV_PORT, /*source address*/toOrigin.GetInterface ().GetLocal (), - /*destination address*/toOrigin.GetNextHop (), /*id*/0, /*TTL*//*toOrigin.GetHop()*/35); //TODO TTL + /*destination address*/toOrigin.GetNextHop (), /*id*/0, /*TTL*/1); //TODO TTL Ptr socket = FindSocketWithInterfaceAddress (toOrigin.GetInterface ().GetLocal ()); socket->SendTo (packet, 0, InetSocketAddress (toOrigin.GetNextHop (), AODV_PORT)); } @@ -1054,7 +1059,8 @@ RoutingProtocol::RouteRequestTimerExpire (Ipv4Address dst, uint16_t lastTtl ) m_routingTable.LookupRoute (dst, toDst); if (toDst.GetFlag () == RTF_UP) { - NS_LOG_LOGIC("route to " << dst << " found"); + SendPacketFromQueue (dst, toDst.GetRoute ()); + NS_LOG_LOGIC ("route to " << dst << " found"); return; } /** @@ -1065,25 +1071,33 @@ RoutingProtocol::RouteRequestTimerExpire (Ipv4Address dst, uint16_t lastTtl ) if (toDst.GetRreqCnt () == RreqRetries) { NS_LOG_LOGIC("route discovery to " << dst << " has been attempted RreqRetries times"); + m_addressReqTimer.erase(dst); + NS_LOG_UNCOND ("Route not found. Drop packet with dst " << dst); + DropFromQueue (dst); // TODO drop packet from queue and deliver Destination Unreachable message to the application. return; - } NS_LOG_LOGIC("Send new RREQ to " << dst); + } + if (toDst.GetFlag () == RTF_IN_SEARCH) { - if (lastTtl > TtlThreshold) - SendRequest (dst, NetDiameter); - else - SendRequest (dst, lastTtl + TtlIncrement); - } -} -void -RoutingProtocol::BroadcastTimerExpire () -{ - NS_LOG_FUNCTION(this); - m_idCache.Purge (); - btimer.Cancel (); - btimer.Schedule (); + if (lastTtl + TtlIncrement > TtlThreshold) + { + NS_LOG_LOGIC ("Send new RREQ to " << dst << " ttl " << NetDiameter); + SendRequest (dst, NetDiameter); + } + else + { + NS_LOG_LOGIC ("Send new RREQ to " << dst << " ttl " << lastTtl + TtlIncrement); + SendRequest (dst, lastTtl + TtlIncrement); + } + } + else + { + NS_LOG_UNCOND ("Route down. Stop search. Drop packet with destination " << dst); + m_addressReqTimer.erase(dst); + DropFromQueue (dst); + } } void @@ -1093,7 +1107,7 @@ RoutingProtocol::HelloTimerExpire () SendHello (); // TODO select random time for the next hello htimer.Cancel (); - htimer.Schedule (HelloInterval); + htimer.Schedule (HelloInterval + Seconds(UniformVariable().GetValue (0, 0.01)) ); } void @@ -1165,10 +1179,17 @@ RoutingProtocol::SendPacketFromQueue (Ipv4Address dst, Ptr route ) QueueEntry queueEntry; while (m_queue.Dequeue (dst, queueEntry)) { + NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << " SendPacketFromQueue"); UnicastForwardCallback ucb = queueEntry.GetUnicastForwardCallback (); ucb (route, queueEntry.GetPacket (), queueEntry.GetIpv4Header ()); } } +void +RoutingProtocol::DropFromQueue (Ipv4Address dst) +{ + NS_LOG_FUNCTION(this); + m_queue.DropPacketWithDst(dst); +} void RoutingProtocol::Send (Ptr route, Ptr packet, const Ipv4Header & header ) @@ -1179,7 +1200,6 @@ RoutingProtocol::Send (Ptr route, Ptr packet, const Ipv Ptr p = packet->Copy (); // TODO know protocol number l3->Send (p, route->GetSource (), header.GetDestination (), 1, route); - } void diff --git a/src/routing/aodv/aodv-routing-protocol.h b/src/routing/aodv/aodv-routing-protocol.h index c9381eed2..0c95829a5 100644 --- a/src/routing/aodv/aodv-routing-protocol.h +++ b/src/routing/aodv/aodv-routing-protocol.h @@ -85,10 +85,10 @@ public: private: ///\name Protocol parameters. TODO document //\{ - uint32_t RreqRetries; // 2 + uint32_t RreqRetries; ///< Maximum number of retransmissions of RREQ with TTL = NetDiameter to discover a route Time ActiveRouteTimeout; // 3 seconds Time MyRouteTimeout; // 2 * ActiveRouteTimeout - uint16_t NetDiameter; + uint32_t NetDiameter; Time NodeTraversalTime; // 40 milliseconds Time NetTraversalTime; // 2 * NodeTraversalTime * NetDiameter Time PathDiscoveryTime; @@ -235,11 +235,10 @@ private: /// Notify that packet is dropped for some reason void Drop(Ptr, const Ipv4Header &, Socket::SocketErrno) {} + void DropFromQueue (Ipv4Address dst); ///\name Timers. TODO comment each one //\{ - Timer btimer; - void BroadcastTimerExpire (); Timer htimer; // TODO independent hello timers for all interfaces void HelloTimerExpire (); Timer ntimer; diff --git a/src/routing/aodv/aodv-rqueue.cc b/src/routing/aodv/aodv-rqueue.cc index c7ebea62f..e22856943 100644 --- a/src/routing/aodv/aodv-rqueue.cc +++ b/src/routing/aodv/aodv-rqueue.cc @@ -178,7 +178,8 @@ RequestQueue::Purge () void RequestQueue::Drop (QueueEntry en, std::string reason ) { - NS_LOG_LOGIC (reason << en.GetPacket ()->GetUid () << " " << en.GetIpv4Header ().GetDestination ()); + NS_LOG_UNCOND (reason << en.GetPacket ()->GetUid () << " " << en.GetIpv4Header ().GetDestination ()); + en.GetErrorCallback() (en.GetPacket(), en.GetIpv4Header(), Socket::ERROR_NOROUTETOHOST); return; } diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc index b851b77fc..e3b8ef63e 100644 --- a/src/routing/aodv/aodv-rtable.cc +++ b/src/routing/aodv/aodv-rtable.cc @@ -124,6 +124,7 @@ RoutingTableEntry::Invalidate (Time badLinkLifetime ) if (m_flag == RTF_DOWN) return; m_flag = RTF_DOWN; + m_reqCount = 0; m_lifeTime = badLinkLifetime + Simulator::Now (); } @@ -303,6 +304,7 @@ RoutingTable::SetEntryState (Ipv4Address id, RouteFlags state ) if (i == m_ipv4AddressEntry.end ()) return false; i->second.SetFlag (state); + i->second.SetRreqCnt(0); return true; } @@ -324,7 +326,10 @@ RoutingTable::InvalidateRoutesWithDst (const std::map & u { for (std::map::const_iterator j = unreachable.begin (); j != unreachable.end (); ++j) if ((i->first == j->first) && (i->second.GetFlag () == RTF_UP)) - i->second.Invalidate (m_badLinkLifetime); + { + NS_LOG_UNCOND ("ivalidate route with dst " << i->first); + i->second.Invalidate (m_badLinkLifetime); + } } } @@ -348,6 +353,8 @@ RoutingTable::Purge () { NS_LOG_UNCOND ("ivalidate route with dst " << i->first ); i->second.Invalidate (m_badLinkLifetime); + NS_LOG_UNCOND (Simulator::Now().GetSeconds()); + Print(std::cout); ++i; } else @@ -365,6 +372,7 @@ RoutingTable::MarkLinkAsUinidirectional (Ipv4Address neighbor, Time blacklistTim return false; i->second.SetUnidirectional (true); i->second.SetBalcklistTimeout (blacklistTimeout); + i->second.SetRreqCnt(0); return true; }