--- a/examples/aodv-with-interface-down.cc Mon Aug 17 13:19:23 2009 +0400
+++ b/examples/aodv-with-interface-down.cc Mon Aug 17 15:37:17 2009 +0400
@@ -94,7 +94,7 @@
//-----------------------------------------------------------------------------
AodvExample::AodvExample () :
- size (4),
+ size (8),
step (120),
totalTime (10),
pcap (true)
@@ -206,8 +206,8 @@
p.Start (Seconds (0));
p.Stop (Seconds (totalTime));
- Ptr<Node> node = nodes.Get (size/2);
+ Ptr<Node> node = nodes.Get (2);
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
- Simulator::Schedule (Seconds (1), &Ipv4::SetDown, ipv4, 1);
+ Simulator::Schedule (Seconds (3), &Ipv4::SetDown, ipv4, 1);
}
--- a/src/routing/aodv/aodv-neighbor.cc Mon Aug 17 13:19:23 2009 +0400
+++ b/src/routing/aodv/aodv-neighbor.cc Mon Aug 17 15:37:17 2009 +0400
@@ -66,16 +66,16 @@
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 ();
+ i->m_expireTime = std::max(expire + Simulator::Now (), i->m_expireTime);
return;
}
struct Neighbor neighbor =
{ addr, expire + Simulator::Now () };
m_nb.push_back (neighbor);
+ Purge ();
}
void
--- a/src/routing/aodv/aodv-packet.cc Mon Aug 17 13:19:23 2009 +0400
+++ b/src/routing/aodv/aodv-packet.cc Mon Aug 17 15:37:17 2009 +0400
@@ -702,7 +702,7 @@
RerrHeader::AddUnDestination (Ipv4Address dst, uint32_t seqNo )
{
if (m_unreachableDstSeqNo.find (dst) != m_unreachableDstSeqNo.end ())
- return false;
+ return true;
NS_ASSERT (GetDestCount() < 255); // can't support more than 255 destinations in single RERR
m_unreachableDstSeqNo.insert (std::make_pair (dst, seqNo));
--- a/src/routing/aodv/aodv-routing-protocol.cc Mon Aug 17 13:19:23 2009 +0400
+++ b/src/routing/aodv/aodv-routing-protocol.cc Mon Aug 17 15:37:17 2009 +0400
@@ -345,7 +345,7 @@
RoutingTableEntry toDst;
if (m_routingTable.LookupRoute (dst, toDst))
{
- if (toDst.GetFlag () == INVALID && EnableLocalRepair && !lrtimer.IsRunning())
+ if (toDst.GetFlag () == REPAIRABLE && EnableLocalRepair && !lrtimer.IsRunning())
{
if (toDst.GetHop () > MaxRepairTtl)
return false;
@@ -392,8 +392,17 @@
ucb (route, p, header);
return true;
}
+ else
+ {
+ if (toDst.GetValidSeqNo ())
+ {
+ SendRerrWhenNoRouteToForward (dst, toDst.GetSeqNo (), origin);
+ return false;
+ }
+ }
}
- NS_LOG_LOGIC("route not found to "<< dst);
+ NS_LOG_LOGIC("route not found to "<< dst << ". Send RERR message.");
+ SendRerrWhenNoRouteToForward (dst, 0, origin);
return false;
}
@@ -410,7 +419,7 @@
if (EnableHello)
{
htimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this);
- htimer.Schedule(MilliSeconds(UniformVariable().GetValue (0.0, 10.0)));
+ htimer.Schedule(MilliSeconds(UniformVariable().GetValue (0.0, 100.0)));
}
m_ipv4 = ipv4;
@@ -1249,7 +1258,7 @@
SendHello ();
// TODO select random time for the next hello
htimer.Cancel ();
- Time t = Scalar(0.001)*MilliSeconds(UniformVariable().GetValue (0.0, 100.0));
+ Time t = Scalar(0.01)*MilliSeconds(UniformVariable().GetValue (0.0, 100.0));
NS_LOG_LOGIC ("delay = " << t.GetMicroSeconds ());
htimer.Schedule (HelloInterval - t);
}
@@ -1365,6 +1374,7 @@
{
if (!rerrHeader.AddUnDestination (i->first, i->second))
{
+ NS_LOG_LOGIC ("Send RERR message with maximum size.");
TypeHeader typeHeader (AODVTYPE_RERR);
Ptr<Packet> packet = Create<Packet> ();
packet->AddHeader (rerrHeader);
@@ -1397,6 +1407,43 @@
}
void
+RoutingProtocol::SendRerrWhenNoRouteToForward (Ipv4Address dst, uint32_t dstSeqNo, Ipv4Address origin)
+{
+ NS_LOG_FUNCTION (this);
+ RerrHeader rerrHeader;
+ rerrHeader.AddUnDestination(dst, dstSeqNo);
+ RoutingTableEntry toOrigin;
+ Ptr<Packet> packet = Create<Packet> ();
+ packet->AddHeader (rerrHeader);
+ packet->AddHeader (TypeHeader (AODVTYPE_RERR));
+ if (m_routingTable.LookupRoute(origin, toOrigin))
+ {
+ if (toOrigin.GetFlag () == VALID)
+ {
+ Ptr<Socket> socket = FindSocketWithInterfaceAddress (toOrigin.GetInterface ());
+ NS_ASSERT (socket);
+ NS_LOG_LOGIC ("unicast RERR to the source of the data transmission");
+ SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ std::make_pair(socket, toOrigin.GetInterface ()),
+ /*dst*/toOrigin.GetNextHop (), /*TTL*/ 1, /*id*/0);
+ }
+
+ }
+ else
+ {
+ for (std::map< Ptr<Socket>, Ipv4InterfaceAddress >::const_iterator i = m_socketAddresses.begin (); i != m_socketAddresses.end (); ++i)
+ {
+ Ptr<Socket> socket = i->first;
+ Ipv4InterfaceAddress iface = i->second;
+ NS_ASSERT (socket);
+ NS_LOG_LOGIC ("broadcast RERR meassage from interface " << iface.GetLocal());
+ SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ std::make_pair(socket, iface),
+ /*dst*/iface.GetBroadcast (), /*TTL*/1, /*id*/0);
+ }
+ }
+}
+
+
+void
RoutingProtocol::SendRerr (Ipv4Address dst, bool noDelete)
{
RerrHeader rerrHeader;
@@ -1459,7 +1506,7 @@
Ptr<Socket> socket = FindSocketWithInterfaceAddress (*i);
NS_ASSERT (socket);
NS_LOG_LOGIC ("broadcast RERR meassage from interface " << i->GetLocal());
- SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ std::make_pair(socket, toPrecursor.GetInterface ()),
+ SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ std::make_pair(socket, *i),
/*dst*/m_socketAddresses[socket].GetBroadcast (), /*TTL*/ 1, /*id*/0);
}
--- a/src/routing/aodv/aodv-routing-protocol.h Mon Aug 17 13:19:23 2009 +0400
+++ b/src/routing/aodv/aodv-routing-protocol.h Mon Aug 17 15:37:17 2009 +0400
@@ -235,6 +235,13 @@
/// Forward RERR
void SendRerrMessage(Ptr<Packet> packet, std::vector<Ipv4Address> precursors);
/**
+ * Send RERR message when no route to forward input packet. Unicast if there is reverse route to originating node, broadcast otherwise.
+ * \param dst - destination node IP address
+ * \param dstSeqNo - destination node sequence number
+ * \param origin - originating node IP address
+ */
+ void SendRerrWhenNoRouteToForward (Ipv4Address dst, uint32_t dstSeqNo, Ipv4Address origin);
+ /**
* Add UDP, IP headers to packet and send it via raw socket
*/
void SendPacketViaRawSocket (Ptr<Packet> packet, std::pair<Ptr<Socket> , Ipv4InterfaceAddress> socketAddress, Ipv4Address dst, uint16_t ttl, uint16_t id);