A Discrete-Event Network Simulator
API
aodv-routing-protocol.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 IITP RAS
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Based on
19  * NS-2 AODV model developed by the CMU/MONARCH group and optimized and
20  * tuned by Samir Das and Mahesh Marina, University of Cincinnati;
21  *
22  * AODV-UU implementation by Erik Nordström of Uppsala University
23  * http://core.it.uu.se/core/index.php/AODV-UU
24  *
25  * Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
26  * Pavel Boyko <boyko@iitp.ru>
27  */
28 #ifndef AODVROUTINGPROTOCOL_H
29 #define AODVROUTINGPROTOCOL_H
30 
31 #include "aodv-rtable.h"
32 #include "aodv-rqueue.h"
33 #include "aodv-packet.h"
34 #include "aodv-neighbor.h"
35 #include "aodv-dpd.h"
36 #include "ns3/node.h"
37 #include "ns3/random-variable-stream.h"
38 #include "ns3/output-stream-wrapper.h"
39 #include "ns3/ipv4-routing-protocol.h"
40 #include "ns3/ipv4-interface.h"
41 #include "ns3/ipv4-l3-protocol.h"
42 #include <map>
43 
44 namespace ns3 {
45 namespace aodv {
52 {
53 public:
58  static TypeId GetTypeId (void);
59  static const uint32_t AODV_PORT;
60 
62  RoutingProtocol ();
63  virtual ~RoutingProtocol ();
64  virtual void DoDispose ();
65 
66  // Inherited from Ipv4RoutingProtocol
68  bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
71  virtual void NotifyInterfaceUp (uint32_t interface);
72  virtual void NotifyInterfaceDown (uint32_t interface);
73  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
74  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
75  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
76  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
77 
78  // Handle protocol parameters
84  {
85  return m_maxQueueTime;
86  }
91  void SetMaxQueueTime (Time t);
96  uint32_t GetMaxQueueLen () const
97  {
98  return m_maxQueueLen;
99  }
104  void SetMaxQueueLen (uint32_t len);
110  {
111  return m_destinationOnly;
112  }
118  {
120  }
126  {
127  return m_gratuitousReply;
128  }
134  {
136  }
141  void SetHelloEnable (bool f)
142  {
143  m_enableHello = f;
144  }
149  bool GetHelloEnable () const
150  {
151  return m_enableHello;
152  }
157  void SetBroadcastEnable (bool f)
158  {
160  }
165  bool GetBroadcastEnable () const
166  {
167  return m_enableBroadcast;
168  }
169 
178  int64_t AssignStreams (int64_t stream);
179 
180 protected:
181  virtual void DoInitialize (void);
182 private:
183  // Protocol parameters.
184  uint32_t m_rreqRetries;
185  uint16_t m_ttlStart;
186  uint16_t m_ttlIncrement;
187  uint16_t m_ttlThreshold;
188  uint16_t m_timeoutBuffer;
189  uint16_t m_rreqRateLimit;
190  uint16_t m_rerrRateLimit;
192  uint32_t m_netDiameter;
193 
201 
207 
214  uint32_t m_maxQueueLen;
220  //\}
221 
225  std::map< Ptr<Socket>, Ipv4InterfaceAddress > m_socketAddresses;
230 
236  uint32_t m_requestId;
238  uint32_t m_seqNo;
246  uint16_t m_rreqCount;
248  uint16_t m_rerrCount;
249 
250 private:
252  void Start ();
277  void ScheduleRreqRetry (Ipv4Address dst);
284  bool UpdateRouteLifeTime (Ipv4Address addr, Time lt);
290  void UpdateRouteToNeighbor (Ipv4Address sender, Ipv4Address receiver);
296  bool IsMyOwnAddress (Ipv4Address src);
317  void ProcessHello (RrepHeader const & rrepHeader, Ipv4Address receiverIfaceAddr);
325  Ptr<Ipv4Route> LoopbackRoute (const Ipv4Header & header, Ptr<NetDevice> oif) const;
326 
328  //\{
330  void RecvAodv (Ptr<Socket> socket);
332  void RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address src);
334  void RecvReply (Ptr<Packet> p, Ipv4Address my,Ipv4Address src);
336  void RecvReplyAck (Ipv4Address neighbor);
338  void RecvError (Ptr<Packet> p, Ipv4Address src);
339  //\}
340 
342  //\{
346  void SendHello ();
348  void SendRequest (Ipv4Address dst);
350  void SendReply (RreqHeader const & rreqHeader, RoutingTableEntry const & toOrigin);
356  void SendReplyByIntermediateNode (RoutingTableEntry & toDst, RoutingTableEntry & toOrigin, bool gratRep);
358  void SendReplyAck (Ipv4Address neighbor);
362  void SendRerrMessage (Ptr<Packet> packet, std::vector<Ipv4Address> precursors);
369  void SendRerrWhenNoRouteToForward (Ipv4Address dst, uint32_t dstSeqNo, Ipv4Address origin);
371 
378  void SendTo (Ptr<Socket> socket, Ptr<Packet> packet, Ipv4Address destination);
379 
383  void HelloTimerExpire ();
387  void RreqRateLimitTimerExpire ();
391  void RerrRateLimitTimerExpire ();
393  std::map<Ipv4Address, Timer> m_addressReqTimer;
405  void AckTimerExpire (Ipv4Address neighbor, Time blacklistTimeout);
406 
411 };
412 
413 } //namespace aodv
414 } //namespace ns3
415 
416 #endif /* AODVROUTINGPROTOCOL_H */
Time m_activeRouteTimeout
Period of time during which the route is considered to be valid.
maintain list of active neighbors
Definition: aodv-neighbor.h:51
void SendReplyAck(Ipv4Address neighbor)
Send RREP_ACK.
Time m_netTraversalTime
Estimate of the average net traversal time.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
bool GetGratuitousReplyFlag() const
Get gratuitous reply flag.
uint16_t m_rreqCount
Number of RREQs used for RREQ rate control.
Callback template class.
Definition: callback.h:1176
bool m_enableBroadcast
Indicates whether a a broadcast data packets forwarding enable.
AODV route request queue.
Definition: aodv-rqueue.h:180
void SendTo(Ptr< Socket > socket, Ptr< Packet > packet, Ipv4Address destination)
Send packet to destination scoket.
RoutingTable m_routingTable
Routing table.
A simple Timer class.
Definition: timer.h:73
uint32_t GetMaxQueueLen() const
Get the maximum queue length.
Time m_nodeTraversalTime
NodeTraversalTime is a conservative estimate of the average one hop traversal time for packets and sh...
Unique packets identification cache used for simple duplicate detection.
Definition: aodv-id-cache.h:43
Time m_deletePeriod
DeletePeriod is intended to provide an upper bound on the time for which an upstream node A can have ...
Routing table entry.
Definition: aodv-rtable.h:59
Ptr< Ipv4 > m_ipv4
IP protocol.
uint32_t m_maxQueueLen
The maximum number of packets that we allow a routing protocol to buffer.
bool Forwarding(Ptr< const Packet > p, const Ipv4Header &header, UnicastForwardCallback ucb, ErrorCallback ecb)
If route exists and is valid, forward packet.
bool GetBroadcastEnable() const
Get broadcast enable flag.
Time m_helloInterval
Every HelloInterval the node checks whether it has sent a broadcast within the last HelloInterval...
Time m_maxQueueTime
The maximum period of time that a routing protocol is allowed to buffer a packet for.
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
virtual void DoDispose()
Destructor implementation.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
void SetMaxQueueLen(uint32_t len)
Set the maximum queue length.
Timer m_rreqRateLimitTimer
RREQ rate limit timer.
uint16_t m_rreqRateLimit
Maximum number of RREQ per second.
uint16_t m_ttlThreshold
Maximum TTL value for expanding ring search, TTL = NetDiameter is used beyond this value...
Neighbors m_nb
Handle neighbors.
bool GetDestinationOnlyFlag() const
Get destination only flag.
void SetGratuitousReplyFlag(bool f)
Set gratuitous reply flag.
Ptr< Socket > FindSubnetBroadcastSocketWithInterfaceAddress(Ipv4InterfaceAddress iface) const
Find subnet directed broadcast socket with local interface address iface.
Time m_nextHopWait
Period of our waiting for the neighbour&#39;s RREP_ACK.
uint16_t m_rerrRateLimit
Maximum number of REER per second.
Route Request (RREQ) Message Format.
Definition: aodv-packet.h:131
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Time m_lastBcastTime
Keep track of the last bcast time.
bool m_destinationOnly
Indicates only the destination may respond to this RREQ.
uint32_t m_rreqRetries
Maximum number of retransmissions of RREQ with TTL = NetDiameter to discover a route.
RequestQueue m_queue
A "drop-front" queue used by the routing layer to buffer packets to which it does not have a route...
uint32_t m_seqNo
Request sequence number.
void ScheduleRreqRetry(Ipv4Address dst)
Repeated attempts by a source node at route discovery for a single destination use the expanding ring...
bool m_gratuitousReply
Indicates whether a gratuitous RREP should be unicast to the node originated route discovery...
void RecvAodv(Ptr< Socket > socket)
Receive and process control packet.
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
Packet header for IPv4.
Definition: ipv4-header.h:33
void RecvReplyAck(Ipv4Address neighbor)
Receive RREP_ACK.
void SendPacketFromQueue(Ipv4Address dst, Ptr< Ipv4Route > route)
Forward packet from route request queue.
void DeferredRouteOutput(Ptr< const Packet > p, const Ipv4Header &header, UnicastForwardCallback ucb, ErrorCallback ecb)
Queue packet and send route request.
bool IsMyOwnAddress(Ipv4Address src)
Test whether the provided address is assigned to an interface on this node.
uint16_t m_ttlIncrement
TTL increment for each attempt using the expanding ring search for RREQ dissemination.
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
void RecvReply(Ptr< Packet > p, Ipv4Address my, Ipv4Address src)
Receive RREP.
void HelloTimerExpire()
Schedule next send of hello message.
uint32_t m_allowedHelloLoss
Number of hello messages which may be loss for valid link.
bool UpdateRouteLifeTime(Ipv4Address addr, Time lt)
Set lifetime field in routing table entry to the maximum of existing lifetime and lt...
void UpdateRouteToNeighbor(Ipv4Address sender, Ipv4Address receiver)
Update neighbor record.
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:108
AODV routing protocol.
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
static TypeId GetTypeId(void)
Get the type ID.
virtual void DoInitialize(void)
Initialize() implementation.
void SendReplyByIntermediateNode(RoutingTableEntry &toDst, RoutingTableEntry &toOrigin, bool gratRep)
Send RREP by intermediate node.
Ptr< Socket > FindSocketWithInterfaceAddress(Ipv4InterfaceAddress iface) const
Find unicast socket with local interface address iface.
uint16_t m_rerrCount
Number of RERRs used for RERR rate control.
void SetMaxQueueTime(Time t)
Set the maximum queue time.
Route Reply (RREP) Message Format.
Definition: aodv-packet.h:335
bool GetHelloEnable() const
Get hello enable flag.
void SendRerrWhenNoRouteToForward(Ipv4Address dst, uint32_t dstSeqNo, Ipv4Address origin)
Send RERR message when no route to forward input packet.
double f(double x, void *params)
Definition: 80211b.c:70
void SendRerrWhenBreaksLinkToNextHop(Ipv4Address nextHop)
Initiate RERR.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::map< Ptr< Socket >, Ipv4InterfaceAddress > m_socketSubnetBroadcastAddresses
Raw subnet directed broadcast socket per each IP interface, map socket -> iface address (IP + mask) ...
address
Definition: first.py:37
void RecvRequest(Ptr< Packet > p, Ipv4Address receiver, Ipv4Address src)
Receive RREQ.
uint32_t m_netDiameter
Net diameter measures the maximum possible number of hops between two nodes in the network...
std::map< Ptr< Socket >, Ipv4InterfaceAddress > m_socketAddresses
Raw unicast socket per each IP interface, map socket -> iface address (IP + mask) ...
uint16_t m_ttlStart
Initial TTL value for RREQ.
void ProcessHello(RrepHeader const &rrepHeader, Ipv4Address receiverIfaceAddr)
Process hello message.
virtual void NotifyInterfaceUp(uint32_t interface)
bool m_enableHello
Indicates whether a hello messages enable.
The Routing table used by AODV protocol.
Definition: aodv-rtable.h:388
DuplicatePacketDetection m_dpd
Handle duplicated broadcast/multicast packets.
void RecvError(Ptr< Packet > p, Ipv4Address src)
Receive RERR from node with address src.
void RreqRateLimitTimerExpire()
Reset RREQ count and schedule RREQ rate limit timer with delay 1 sec.
void SetDestinationOnlyFlag(bool f)
Set destination only flag.
Time GetMaxQueueTime() const
Get maximum queue time.
Time m_myRouteTimeout
Value of lifetime field in RREP generating by this node.
Time m_pathDiscoveryTime
Estimate of maximum time needed to find route in network.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
virtual void NotifyInterfaceDown(uint32_t interface)
a class to store IPv4 address information on an interface
Time m_blackListTimeout
Time for which the node is put into the blacklist.
void SendRerrMessage(Ptr< Packet > packet, std::vector< Ipv4Address > precursors)
Forward RERR.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
void SendReply(RreqHeader const &rreqHeader, RoutingTableEntry const &toOrigin)
Send RREP.
Abstract base class for IPv4 routing protocols.
Helper class used to remember already seen packets and detect duplicates.
Definition: aodv-dpd.h:41
Ptr< Ipv4Route > LoopbackRoute(const Ipv4Header &header, Ptr< NetDevice > oif) const
Create loopback route for given header.
Timer m_rerrRateLimitTimer
RERR rate limit timer.
void AckTimerExpire(Ipv4Address neighbor, Time blacklistTimeout)
Mark link to neighbor node as unidirectional for blacklistTimeout.
std::map< Ipv4Address, Timer > m_addressReqTimer
Map IP address + RREQ timer.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
second
Definition: nstime.h:114
uint16_t m_timeoutBuffer
Provide a buffer for the timeout.
void SendRequest(Ipv4Address dst)
Send RREQ.
void RerrRateLimitTimerExpire()
Reset RERR count and schedule RERR rate limit timer with delay 1 sec.
IdCache m_rreqIdCache
Handle duplicated RREQ.
void RouteRequestTimerExpire(Ipv4Address dst)
Handle route discovery process.
void Start()
Start protocol operation.
void SetHelloEnable(bool f)
Set hello enable.
void SetBroadcastEnable(bool f)
Set broadcast enable flag.
a unique identifier for an interface.
Definition: type-id.h:58
Ptr< NetDevice > m_lo
Loopback device used to defer RREQ until packet will be fully formed.
uint32_t m_requestId
Broadcast ID.
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
static const uint32_t AODV_PORT
UDP Port for AODV control traffic.