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)),
125 NetTraversalTime (
Time ((2 * NetDiameter) * NodeTraversalTime)),
126 PathDiscoveryTime (
Time (2 * NetTraversalTime)),
127 MyRouteTimeout (
Time (2 * std::max (PathDiscoveryTime, ActiveRouteTimeout))),
129 AllowedHelloLoss (2),
130 DeletePeriod (
Time (5 * std::max (ActiveRouteTimeout, HelloInterval))),
133 BlackListTimeout (
Time (RreqRetries * NetTraversalTime)),
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)
161 static TypeId tid =
TypeId (
"ns3::aodv::RoutingProtocol")
163 .AddConstructor<RoutingProtocol> ()
164 .AddAttribute (
"HelloInterval",
"HELLO messages emission interval.",
168 .AddAttribute (
"RreqRetries",
"Maximum number of retransmissions of RREQ to discover a route",
171 MakeUintegerChecker<uint32_t> ())
172 .AddAttribute (
"RreqRateLimit",
"Maximum number of RREQ per second.",
175 MakeUintegerChecker<uint32_t> ())
176 .AddAttribute (
"RerrRateLimit",
"Maximum number of RERR per second.",
179 MakeUintegerChecker<uint32_t> ())
180 .AddAttribute (
"NodeTraversalTime",
"Conservative estimate of the average one hop traversal time for packets and should include "
181 "queuing delays, interrupt processing times and transfer times.",
185 .AddAttribute (
"NextHopWait",
"Period of our waiting for the neighbour's RREP_ACK = 10 ms + NodeTraversalTime",
189 .AddAttribute (
"ActiveRouteTimeout",
"Period of time during which the route is considered to be valid",
193 .AddAttribute (
"MyRouteTimeout",
"Value of lifetime field in RREP generating by this node = 2 * max(ActiveRouteTimeout, PathDiscoveryTime)",
197 .AddAttribute (
"BlackListTimeout",
"Time for which the node is put into the blacklist = RreqRetries * NetTraversalTime",
201 .AddAttribute (
"DeletePeriod",
"DeletePeriod is intended to provide an upper bound on the time for which an upstream node A "
202 "can have a neighbor B as an active next hop for destination D, while B has invalidated the route to D."
203 " = 5 * max (HelloInterval, ActiveRouteTimeout)",
207 .AddAttribute (
"TimeoutBuffer",
"Its purpose is to provide a buffer for the timeout so that if the RREP is delayed"
208 " due to congestion, a timeout is less likely to occur while the RREP is still en route back to the source.",
211 MakeUintegerChecker<uint16_t> ())
212 .AddAttribute (
"NetDiameter",
"Net diameter measures the maximum possible number of hops between two nodes in the network",
215 MakeUintegerChecker<uint32_t> ())
216 .AddAttribute (
"NetTraversalTime",
"Estimate of the average net traversal time = 2 * NodeTraversalTime * NetDiameter",
220 .AddAttribute (
"PathDiscoveryTime",
"Estimate of maximum time needed to find route in network = 2 * NetTraversalTime",
224 .AddAttribute (
"MaxQueueLen",
"Maximum number of packets that we allow a routing protocol to buffer.",
228 MakeUintegerChecker<uint32_t> ())
229 .AddAttribute (
"MaxQueueTime",
"Maximum time packets can be queued (in seconds)",
234 .AddAttribute (
"AllowedHelloLoss",
"Number of hello messages which may be loss for valid link.",
237 MakeUintegerChecker<uint16_t> ())
238 .AddAttribute (
"GratuitousReply",
"Indicates whether a gratuitous RREP should be unicast to the node originated route discovery.",
242 MakeBooleanChecker ())
243 .AddAttribute (
"DestinationOnly",
"Indicates only the destination may respond to this RREQ.",
247 MakeBooleanChecker ())
248 .AddAttribute (
"EnableHello",
"Indicates whether a hello messages enable.",
252 MakeBooleanChecker ())
253 .AddAttribute (
"EnableBroadcast",
"Indicates whether a broadcast data packets forwarding enable.",
257 MakeBooleanChecker ())
258 .AddAttribute (
"UniformRv",
259 "Access to the underlying UniformRandomVariable",
262 MakePointerChecker<UniformRandomVariable> ())
291 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);
948 NS_LOG_DEBUG (
"AODV node " <<
this <<
" received a AODV packet from " << sender <<
" to " << receiver);
955 NS_LOG_DEBUG (
"AODV message " << packet->
GetUid () <<
" with unknown type received: " << tHeader.
Get () <<
". Drop");
958 switch (tHeader.
Get ())
1005 NS_LOG_FUNCTION (
this <<
"sender " << sender <<
" receiver " << receiver);
1051 uint32_t
id = rreqHeader.
GetId ();
1106 <<
" ID " << rreqHeader.
GetId ()
1107 <<
" to destination " << rreqHeader.
GetDst ());
1114 NS_LOG_DEBUG (
"Send reply since I am the destination");
1201 packet->AddHeader (tHeader);
1216 if (toDst.
GetHop () == 1)
1247 packetToDst->AddHeader (type);
1311 if (!toDst.GetValidSeqNo ())
1316 else if ((int32_t (rrepHeader.
GetDstSeqno ()) - int32_t (toDst.GetSeqNo ())) > 0)
1323 if ((rrepHeader.
GetDstSeqno () == toDst.GetSeqNo ()) && (toDst.GetFlag () !=
VALID))
1328 else if ((rrepHeader.
GetDstSeqno () == toDst.GetSeqNo ()) && (hop < toDst.GetHop ()))
1371 toDst.InsertPrecursor (toOrigin.
GetNextHop ());
1432 toNeighbor.SetValidSeqNo (
true);
1433 toNeighbor.SetFlag (
VALID);
1450 std::map<Ipv4Address, uint32_t> dstWithNextHopSrc;
1451 std::map<Ipv4Address, uint32_t> unreachable;
1453 std::pair<Ipv4Address, uint32_t> un;
1456 for (std::map<Ipv4Address, uint32_t>::const_iterator i =
1457 dstWithNextHopSrc.begin (); i != dstWithNextHopSrc.end (); ++i)
1459 if (i->first == un.first)
1461 unreachable.insert (un);
1466 std::vector<Ipv4Address> precursors;
1467 for (std::map<Ipv4Address, uint32_t>::const_iterator i = unreachable.begin ();
1468 i != unreachable.end ();)
1477 rerrHeader.
Clear ();
1516 NS_LOG_LOGIC (
"route discovery to " << dst <<
" has been attempted RreqRetries (" <<
RreqRetries <<
") times");
1519 NS_LOG_DEBUG (
"Route not found. Drop all packets with dst " << dst);
1531 NS_LOG_DEBUG (
"Route down. Stop search. Drop packet with destination " << dst);
1590 packet->AddHeader (tHeader);
1618 NS_LOG_DEBUG (
"Output device doesn't match. Dropped.");
1625 ucb (route, p, header);
1634 std::vector<Ipv4Address> precursors;
1635 std::map<Ipv4Address, uint32_t> unreachable;
1643 for (std::map<Ipv4Address, uint32_t>::const_iterator i = unreachable.begin (); i
1644 != unreachable.end ();)
1654 rerrHeader.
Clear ();
1672 unreachable.insert (std::make_pair (nextHop, toNextHop.
GetSeqNo ()));
1689 <<
"; suppressing RERR");
1703 NS_LOG_LOGIC (
"Unicast RERR to the source of the data transmission");
1735 if (precursors.empty ())
1748 <<
"; suppressing RERR");
1752 if (precursors.size () == 1)
1767 std::vector<Ipv4InterfaceAddress> ifaces;
1769 for (std::vector<Ipv4Address>::const_iterator i = precursors.begin (); i != precursors.end (); ++i)
1772 std::find (ifaces.begin (), ifaces.end (), toPrecursor.
GetInterface ()) == ifaces.end ())
1778 for (std::vector<Ipv4InterfaceAddress>::const_iterator i = ifaces.begin (); i != ifaces.end (); ++i)
1782 NS_LOG_LOGIC (
"Broadcast RERR message from interface " << i->GetLocal ());
1791 destination = i->GetBroadcast ();