28 #define NS_LOG_APPEND_CONTEXT \
29 if (m_ipv4) { std::clog << "[node " << m_ipv4->GetObject<Node> ()->GetId () << "] "; }
33 #include "ns3/boolean.h"
34 #include "ns3/random-variable-stream.h"
35 #include "ns3/inet-socket-address.h"
36 #include "ns3/trace-source-accessor.h"
37 #include "ns3/udp-socket-factory.h"
38 #include "ns3/wifi-net-device.h"
39 #include "ns3/adhoc-wifi-mac.h"
40 #include "ns3/string.h"
41 #include "ns3/pointer.h"
91 return sizeof(int32_t);
106 os <<
"DeferredRouteOutputTag: output interface = " <<
m_oif;
122 ActiveRouteTimeout (Seconds (3)),
124 NodeTraversalTime (MilliSeconds (40)),
125 NetTraversalTime (
Time ((2 * NetDiameter) * NodeTraversalTime)),
126 PathDiscoveryTime (
Time (2 * NetTraversalTime)),
127 MyRouteTimeout (
Time (2 * std::max (PathDiscoveryTime, ActiveRouteTimeout))),
128 HelloInterval (Seconds (1)),
129 AllowedHelloLoss (2),
130 DeletePeriod (
Time (5 * std::max (ActiveRouteTimeout, HelloInterval))),
131 NextHopWait (NodeTraversalTime + MilliSeconds (10)),
133 BlackListTimeout (
Time (RreqRetries * NetTraversalTime)),
135 MaxQueueTime (Seconds (30)),
136 DestinationOnly (false),
137 GratuitousReply (true),
139 m_routingTable (DeletePeriod),
140 m_queue (MaxQueueLen, MaxQueueTime),
143 m_rreqIdCache (PathDiscoveryTime),
144 m_dpd (PathDiscoveryTime),
145 m_nb (HelloInterval),
148 m_htimer (
Timer::CANCEL_ON_DESTROY),
149 m_rreqRateLimitTimer (
Timer::CANCEL_ON_DESTROY),
150 m_rerrRateLimitTimer (
Timer::CANCEL_ON_DESTROY),
151 m_lastBcastTime (Seconds (0))
159 static TypeId tid =
TypeId (
"ns3::aodv::RoutingProtocol")
161 .AddConstructor<RoutingProtocol> ()
162 .AddAttribute (
"HelloInterval",
"HELLO messages emission interval.",
166 .AddAttribute (
"RreqRetries",
"Maximum number of retransmissions of RREQ to discover a route",
169 MakeUintegerChecker<uint32_t> ())
170 .AddAttribute (
"RreqRateLimit",
"Maximum number of RREQ per second.",
173 MakeUintegerChecker<uint32_t> ())
174 .AddAttribute (
"RerrRateLimit",
"Maximum number of RERR per second.",
177 MakeUintegerChecker<uint32_t> ())
178 .AddAttribute (
"NodeTraversalTime",
"Conservative estimate of the average one hop traversal time for packets and should include "
179 "queuing delays, interrupt processing times and transfer times.",
183 .AddAttribute (
"NextHopWait",
"Period of our waiting for the neighbour's RREP_ACK = 10 ms + NodeTraversalTime",
187 .AddAttribute (
"ActiveRouteTimeout",
"Period of time during which the route is considered to be valid",
191 .AddAttribute (
"MyRouteTimeout",
"Value of lifetime field in RREP generating by this node = 2 * max(ActiveRouteTimeout, PathDiscoveryTime)",
195 .AddAttribute (
"BlackListTimeout",
"Time for which the node is put into the blacklist = RreqRetries * NetTraversalTime",
199 .AddAttribute (
"DeletePeriod",
"DeletePeriod is intended to provide an upper bound on the time for which an upstream node A "
200 "can have a neighbor B as an active next hop for destination D, while B has invalidated the route to D."
201 " = 5 * max (HelloInterval, ActiveRouteTimeout)",
205 .AddAttribute (
"TimeoutBuffer",
"Its purpose is to provide a buffer for the timeout so that if the RREP is delayed"
206 " due to congestion, a timeout is less likely to occur while the RREP is still en route back to the source.",
209 MakeUintegerChecker<uint16_t> ())
210 .AddAttribute (
"NetDiameter",
"Net diameter measures the maximum possible number of hops between two nodes in the network",
213 MakeUintegerChecker<uint32_t> ())
214 .AddAttribute (
"NetTraversalTime",
"Estimate of the average net traversal time = 2 * NodeTraversalTime * NetDiameter",
218 .AddAttribute (
"PathDiscoveryTime",
"Estimate of maximum time needed to find route in network = 2 * NetTraversalTime",
222 .AddAttribute (
"MaxQueueLen",
"Maximum number of packets that we allow a routing protocol to buffer.",
226 MakeUintegerChecker<uint32_t> ())
227 .AddAttribute (
"MaxQueueTime",
"Maximum time packets can be queued (in seconds)",
232 .AddAttribute (
"AllowedHelloLoss",
"Number of hello messages which may be loss for valid link.",
235 MakeUintegerChecker<uint16_t> ())
236 .AddAttribute (
"GratuitousReply",
"Indicates whether a gratuitous RREP should be unicast to the node originated route discovery.",
240 MakeBooleanChecker ())
241 .AddAttribute (
"DestinationOnly",
"Indicates only the destination may respond to this RREQ.",
245 MakeBooleanChecker ())
246 .AddAttribute (
"EnableHello",
"Indicates whether a hello messages enable.",
250 MakeBooleanChecker ())
251 .AddAttribute (
"EnableBroadcast",
"Indicates whether a broadcast data packets forwarding enable.",
255 MakeBooleanChecker ())
256 .AddAttribute (
"UniformRv",
257 "Access to the underlying UniformRandomVariable",
260 MakePointerChecker<UniformRandomVariable> ())
289 iter->first->Close ();
392 if(!result || ((rt.GetFlag () !=
IN_SEARCH) && result))
451 NS_LOG_DEBUG (
"Duplicated packet " << p->
GetUid () <<
" from " << origin <<
". Drop.");
456 if (lcb.
IsNull () ==
false)
459 lcb (p, header, iif);
464 NS_LOG_ERROR (
"Unable to deliver packet locally due to null callback " << p->
GetUid () <<
" from " << origin);
478 ucb (route, packet, header);
503 if (lcb.
IsNull () ==
false)
506 lcb (p, header, iif);
510 NS_LOG_ERROR (
"Unable to deliver packet locally due to null callback " << p->
GetUid () <<
" from " << origin);
557 ucb (route, p, header);
570 NS_LOG_LOGIC (
"route not found to "<< dst <<
". Send RERR message.");
609 if (l3->GetNAddresses (i) > 1)
611 NS_LOG_WARN (
"AODV does not work with more then one address per each interface.");
685 NS_LOG_FUNCTION (
this <<
" interface " << i <<
" address " << address);
719 NS_LOG_LOGIC (
"AODV does not work with more then one address per each interface. Ignore added address");
763 NS_LOG_LOGIC (
"Remove address not participating in AODV operation");
813 int32_t
interface =
m_ipv4->GetInterfaceForAddress (addr);
947 NS_LOG_DEBUG (
"AODV node " <<
this <<
" received a AODV packet from " << sender <<
" to " << receiver);
954 NS_LOG_DEBUG (
"AODV message " << packet->
GetUid () <<
" with unknown type received: " << tHeader.
Get () <<
". Drop");
957 switch (tHeader.
Get ())
1004 NS_LOG_FUNCTION (
this <<
"sender " << sender <<
" receiver " << receiver);
1050 uint32_t
id = rreqHeader.
GetId ();
1110 NS_LOG_DEBUG (
"Neighbor:" << src <<
" not found in routing table. Creating an entry");
1130 <<
" ID " << rreqHeader.
GetId ()
1131 <<
" to destination " << rreqHeader.
GetDst ());
1138 NS_LOG_DEBUG (
"Send reply since I am the destination");
1218 packet->AddHeader (tHeader);
1233 if (toDst.
GetHop () == 1)
1264 packetToDst->AddHeader (type);
1328 if (!toDst.GetValidSeqNo ())
1333 else if ((int32_t (rrepHeader.
GetDstSeqno ()) - int32_t (toDst.GetSeqNo ())) > 0)
1340 if ((rrepHeader.
GetDstSeqno () == toDst.GetSeqNo ()) && (toDst.GetFlag () !=
VALID))
1345 else if ((rrepHeader.
GetDstSeqno () == toDst.GetSeqNo ()) && (hop < toDst.GetHop ()))
1388 toDst.InsertPrecursor (toOrigin.
GetNextHop ());
1449 toNeighbor.SetValidSeqNo (
true);
1450 toNeighbor.SetFlag (
VALID);
1467 std::map<Ipv4Address, uint32_t> dstWithNextHopSrc;
1468 std::map<Ipv4Address, uint32_t> unreachable;
1470 std::pair<Ipv4Address, uint32_t> un;
1473 for (std::map<Ipv4Address, uint32_t>::const_iterator i =
1474 dstWithNextHopSrc.begin (); i != dstWithNextHopSrc.end (); ++i)
1476 if (i->first == un.first)
1478 unreachable.insert (un);
1483 std::vector<Ipv4Address> precursors;
1484 for (std::map<Ipv4Address, uint32_t>::const_iterator i = unreachable.begin ();
1485 i != unreachable.end ();)
1494 rerrHeader.
Clear ();
1533 NS_LOG_LOGIC (
"route discovery to " << dst <<
" has been attempted RreqRetries (" <<
RreqRetries <<
") times");
1536 NS_LOG_DEBUG (
"Route not found. Drop all packets with dst " << dst);
1548 NS_LOG_DEBUG (
"Route down. Stop search. Drop packet with destination " << dst);
1617 packet->AddHeader (tHeader);
1646 NS_LOG_DEBUG (
"Output device doesn't match. Dropped.");
1653 ucb (route, p, header);
1662 std::vector<Ipv4Address> precursors;
1663 std::map<Ipv4Address, uint32_t> unreachable;
1671 for (std::map<Ipv4Address, uint32_t>::const_iterator i = unreachable.begin (); i
1672 != unreachable.end ();)
1682 rerrHeader.
Clear ();
1700 unreachable.insert (std::make_pair (nextHop, toNextHop.
GetSeqNo ()));
1717 <<
"; suppressing RERR");
1731 NS_LOG_LOGIC (
"Unicast RERR to the source of the data transmission");
1763 if (precursors.empty ())
1776 <<
"; suppressing RERR");
1780 if (precursors.size () == 1)
1795 std::vector<Ipv4InterfaceAddress> ifaces;
1797 for (std::vector<Ipv4Address>::const_iterator i = precursors.begin (); i != precursors.end (); ++i)
1800 std::find (ifaces.begin (), ifaces.end (), toPrecursor.
GetInterface ()) == ifaces.end ())
1806 for (std::vector<Ipv4InterfaceAddress>::const_iterator i = ifaces.begin (); i != ifaces.end (); ++i)
1810 NS_LOG_LOGIC (
"Broadcast RERR message from interface " << i->GetLocal ());
1819 destination = i->GetBroadcast ();