--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/routing/aodv/aodv-neighbor.cc Tue Aug 04 23:01:35 2009 +0400
@@ -0,0 +1,87 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Based on
+ * NS-2 AODV model developed by the CMU/MONARCH group and optimized and
+ * tuned by Samir Das and Mahesh Marina, University of Cincinnati;
+ *
+ * AODV-UU implementation by Erik Nordström of Uppsala University
+ * http://core.it.uu.se/core/index.php/AODV-UU
+ *
+ * Authors: Elena Borovkova <borovkovaes@iitp.ru>
+ * Pavel Boyko <boyko@iitp.ru>
+ */
+
+#include "aodv-neighbor.h"
+
+namespace ns3
+{
+namespace aodv
+{
+
+bool
+Neighbors::Lookup (Ipv4Address addr, Neighbor & n )
+{
+ Purge ();
+ for (std::vector<Neighbor>::const_iterator i = m_nb.begin (); i != m_nb.end (); ++i)
+ if (i->m_neighborAddress == addr)
+ {
+ n = *i;
+ return true;
+ }
+ return false;
+}
+bool
+Neighbors::IsNeighbor (Ipv4Address addr )
+{
+ for (std::vector<Neighbor>::const_iterator i = m_nb.begin (); i != m_nb.end (); ++i)
+ if (i->m_neighborAddress == addr)
+ return true;
+ return false;
+}
+
+void
+Neighbors::Update (Ipv4Address addr, Time expire )
+{
+ Purge ();
+ for (std::vector<Neighbor>::iterator i = m_nb.begin (); i != m_nb.end (); ++i)
+ if (i->m_neighborAddress == addr)
+ {
+ i->m_expireTime = expire + Simulator::Now ();
+ return;
+ }
+ struct Neighbor neighbor =
+ { addr, expire + Simulator::Now () };
+ m_nb.push_back (neighbor);
+}
+void
+Neighbors::Purge ()
+{
+ for (std::vector<Neighbor>::const_iterator i = m_nb.begin (); i != m_nb.end (); ++i)
+ if (i->m_expireTime < Simulator::Now ())
+ {
+ m_handleLinleFailure (i->m_neighborAddress);
+ }
+ std::vector<Neighbor>::iterator i = remove_if (m_nb.begin (), m_nb.end (), IsExpired ());
+ m_nb.erase (i, m_nb.end ());
+
+}
+
+
+}
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/routing/aodv/aodv-neighbor.h Tue Aug 04 23:01:35 2009 +0400
@@ -0,0 +1,78 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Based on
+ * NS-2 AODV model developed by the CMU/MONARCH group and optimized and
+ * tuned by Samir Das and Mahesh Marina, University of Cincinnati;
+ *
+ * AODV-UU implementation by Erik Nordström of Uppsala University
+ * http://core.it.uu.se/core/index.php/AODV-UU
+ *
+ * Authors: Elena Borovkova <borovkovaes@iitp.ru>
+ * Pavel Boyko <boyko@iitp.ru>
+ */
+
+#ifndef AODVNEIGHBOR_H_
+#define AODVNEIGHBOR_H_
+
+#include "ns3/simulator.h"
+#include "ns3/nstime.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/callback.h"
+#include <vector>
+
+
+namespace ns3
+{
+namespace aodv
+{
+class Neighbors
+{
+public:
+ Neighbors (Callback<void, Ipv4Address> cb) : m_handleLinleFailure (cb) {}
+ struct Neighbor
+ {
+ Ipv4Address m_neighborAddress;
+ Time m_expireTime;
+ };
+ /**
+ * Lookup neighbor with address addr
+ * @param addr - neighbor's IP address
+ * @return true on success
+ */
+ bool Lookup (Ipv4Address addr, Neighbor & n);
+ /// Check that node with address addr is neighbor
+ bool IsNeighbor (Ipv4Address addr);
+ void Update (Ipv4Address addr, Time expire);
+ void Purge ();
+private:
+ struct IsExpired
+ {
+ bool operator()(const struct Neighbor & nb) const
+ {
+ return (nb.m_expireTime < Simulator::Now());
+ }
+ };
+
+ Callback<void, Ipv4Address> m_handleLinleFailure;
+ std::vector<Neighbor> m_nb;
+};
+
+}
+}
+
+#endif /* AODVNEIGHBOR_H_ */
--- a/src/routing/aodv/aodv-routing-protocol.cc Tue Aug 04 19:26:50 2009 +0400
+++ b/src/routing/aodv/aodv-routing-protocol.cc Tue Aug 04 23:01:35 2009 +0400
@@ -59,50 +59,6 @@
{
NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol);
-bool
-RoutingProtocol::LookupNeighbor (Ipv4Address addr, Neighbor & n)
-{
- PurgeNeighbor ();
- for (std::vector<Neighbor>::const_iterator i = m_nb.begin (); i != m_nb.end (); ++i)
- if (i->m_neighborAddress == addr)
- {
- n = *i;
- return true;
- }
- return false;
-}
-bool
-RoutingProtocol::IsNeighbor(Ipv4Address addr)
-{
- for (std::vector<Neighbor>::const_iterator i = m_nb.begin (); i != m_nb.end (); ++i)
- if (i->m_neighborAddress == addr) return true;
- return false;
-}
-
-void
-RoutingProtocol::UpdateNeighbor(Ipv4Address addr, Time expire)
-{
- NS_LOG_FUNCTION(this);
- for (std::vector<Neighbor>::iterator i = m_nb.begin (); i != m_nb.end (); ++i)
- if (i->m_neighborAddress == addr)
- {
- i->m_expireTime = expire + Simulator::Now();
- return;
- }
- struct Neighbor neighbor = { addr, expire + Simulator::Now () };
- m_nb.push_back (neighbor);
- PurgeNeighbor ();
-}
-void
-RoutingProtocol::PurgeNeighbor ()
-{
- NS_LOG_FUNCTION(this);
- for(std::vector<Neighbor>::const_iterator i = m_nb.begin(); i != m_nb.end(); ++i)
- if(i->m_expireTime < Simulator::Now()) HandleLinkFailure(i->m_neighborAddress);
- std::vector<Neighbor>::iterator i = remove_if (m_nb.begin (), m_nb.end (), IsExpiredForNeighbor ());
- m_nb.erase (i, m_nb.end ());
-
-}
RoutingProtocol::RoutingProtocol () :
RreqRetries (2),
@@ -127,12 +83,11 @@
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), htimer (Timer::CANCEL_ON_DESTROY), ntimer (Timer::CANCEL_ON_DESTROY),
+ m_requestId (0), m_seqNo (0), m_nb(MakeCallback(&RoutingProtocol::HandleLinkFailure, this)),
+ htimer (Timer::CANCEL_ON_DESTROY), ntimer (Timer::CANCEL_ON_DESTROY),
rtimer (Timer::CANCEL_ON_DESTROY), lrtimer (Timer::CANCEL_ON_DESTROY)
-
{
-
}
TypeId
@@ -274,7 +229,7 @@
NS_LOG_LOGIC("exist route to " << route->GetDestination() << " from iface " << route->GetSource());
UpdateRouteLifeTime (dst, ActiveRouteTimeout);
UpdateRouteLifeTime (route->GetGateway(), ActiveRouteTimeout);
- UpdateNeighbor (route->GetGateway(), ActiveRouteTimeout);
+ m_nb.Update (route->GetGateway(), ActiveRouteTimeout);
}
else
{
@@ -343,7 +298,7 @@
RoutingTableEntry toOrigin;
m_routingTable.LookupRoute (origin, toOrigin);
UpdateRouteLifeTime (toOrigin.GetNextHop (), ActiveRouteTimeout);
- UpdateNeighbor (toOrigin.GetNextHop (), ActiveRouteTimeout);
+ m_nb.Update (toOrigin.GetNextHop (), ActiveRouteTimeout);
NS_LOG_LOGIC ("Unicast local delivery to " << iface.GetLocal ());
lcb (p, header, iif);
return true;
@@ -388,8 +343,8 @@
m_routingTable.LookupRoute (origin, toOrigin);
UpdateRouteLifeTime (toOrigin.GetNextHop (), ActiveRouteTimeout);
- UpdateNeighbor (route->GetGateway (), ActiveRouteTimeout); //?
- UpdateNeighbor (toOrigin.GetNextHop (), ActiveRouteTimeout);
+ m_nb.Update (route->GetGateway (), ActiveRouteTimeout); //?
+ m_nb.Update (toOrigin.GetNextHop (), ActiveRouteTimeout);
ucb (route, p, header);
return true;
@@ -1003,7 +958,7 @@
toNeighbor.SetInterface (m_ipv4->GetAddress (m_ipv4->GetInterfaceForAddress (receiver), 0));
m_routingTable.Update (toNeighbor);
}
- UpdateNeighbor (rrepHeader.GetDst (), Scalar (AllowedHelloLoss) * HelloInterval);
+ m_nb.Update (rrepHeader.GetDst (), Scalar (AllowedHelloLoss) * HelloInterval);
}
// TODO process RERR with 'N' flag
@@ -1018,7 +973,7 @@
std::pair<Ipv4Address, uint32_t> un;
while (rerrHeader.RemoveUnDestination (un))
{
- if (IsNeighbor (un.first))
+ if (m_nb.IsNeighbor (un.first))
SendRerrWhenBreaksLinkToNextHop (un.first);
else
{
@@ -1114,7 +1069,7 @@
RoutingProtocol::NeighborTimerExpire ()
{
NS_LOG_FUNCTION(this);
- PurgeNeighbor ();
+ m_nb.Purge ();
ntimer.Cancel ();
ntimer.Schedule (HelloInterval);
}
--- a/src/routing/aodv/aodv-routing-protocol.h Tue Aug 04 19:26:50 2009 +0400
+++ b/src/routing/aodv/aodv-routing-protocol.h Tue Aug 04 23:01:35 2009 +0400
@@ -32,6 +32,7 @@
#include "aodv-rqueue.h"
#include "aodv-packet.h"
#include "id-cache.h"
+#include "aodv-neighbor.h"
#include "src/internet-stack/ipv4-l3-protocol.h"
@@ -116,31 +117,6 @@
bool GratuitousReply;
//\}
- /**\name Handle neighbors
- * - from which node has received a Hello message, or
- * - which are active next hops, or
- * - which are active precursors
- */
- //\{
- struct Neighbor
- {
- Ipv4Address m_neighborAddress;
- Time m_expireTime;
- };
- struct IsExpiredForNeighbor
- {
- bool operator()(const struct Neighbor & nb) const
- {
- return (nb.m_expireTime < Simulator::Now());
- }
- };
- bool LookupNeighbor (Ipv4Address addr, Neighbor & n);
- bool IsNeighbor (Ipv4Address addr);
- void UpdateNeighbor (Ipv4Address addr, Time expire);
- void PurgeNeighbor ();
- std::vector<Neighbor> m_nb;
- //\}
-
/// IP protocol
Ptr<Ipv4> m_ipv4;
/// Raw socket per each IP interface, map socket -> iface address (IP + mask)
@@ -156,6 +132,8 @@
uint32_t m_seqNo;
/// Handle duplicated packets
IdCache m_idCache;
+ /// Handle neighbors
+ Neighbors m_nb;
UnicastForwardCallback m_scb;
ErrorCallback m_ecb;
--- a/src/routing/aodv/wscript Tue Aug 04 19:26:50 2009 +0400
+++ b/src/routing/aodv/wscript Tue Aug 04 23:01:35 2009 +0400
@@ -8,6 +8,7 @@
'aodv-rqueue.cc',
'aodv-packet.cc',
'id-cache.cc',
+ 'aodv-neighbor.cc',
'aodv-routing-protocol.cc',
]
@@ -18,6 +19,7 @@
'aodv-rqueue.h',
'aodv-packet.h',
'id-cache.h',
+ 'aodv-neighbor.h',
'aodv-routing-protocol.h',
]