A Discrete-Event Network Simulator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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
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  */
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 "ns3/repository.h"
43 #include <map>
45 namespace ns3
46 {
47 namespace aodv
48 {
55 {
56 public:
57  static TypeId GetTypeId (void);
58  static const uint32_t AODV_PORT;
61  RoutingProtocol ();
62  virtual ~RoutingProtocol();
63  virtual void DoDispose ();
66  //\{
67  Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
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) const;
77  void SetRepository(Ptr<Repository> repo);
79  void SendHello ();
80  //\}
83  //\{
84  Time GetMaxQueueTime () const { return MaxQueueTime; }
85  void SetMaxQueueTime (Time t);
86  uint32_t GetMaxQueueLen () const { return MaxQueueLen; }
87  void SetMaxQueueLen (uint32_t len);
88  bool GetDesinationOnlyFlag () const { return DestinationOnly; }
89  void SetDesinationOnlyFlag (bool f) { DestinationOnly = f; }
90  bool GetGratuitousReplyFlag () const { return GratuitousReply; }
91  void SetGratuitousReplyFlag (bool f) { GratuitousReply = f; }
92  void SetHelloEnable (bool f) { EnableHello = f; }
93  bool GetHelloEnable () const { return EnableHello; }
94  void SetBroadcastEnable (bool f) { EnableBroadcast = f; }
95  bool GetBroadcastEnable () const { return EnableBroadcast; }
96  //\}
106  int64_t AssignStreams (int64_t stream);
108 private:
110  //\{
111  uint32_t RreqRetries;
112  uint16_t RreqRateLimit;
113  uint16_t RerrRateLimit;
115  uint32_t NetDiameter;
129  uint32_t AllowedHelloLoss;
140  uint16_t TimeoutBuffer;
142  uint32_t MaxQueueLen;
146  bool EnableHello;
148  //\}
153  std::map< Ptr<Socket>, Ipv4InterfaceAddress > m_socketAddresses;
164  uint32_t m_requestId;
166  uint32_t m_seqNo;
174  uint16_t m_rreqCount;
176  uint16_t m_rerrCount;
178 private:
180  void Start ();
189  void ScheduleRreqRetry (Ipv4Address dst);
196  bool UpdateRouteLifeTime (Ipv4Address addr, Time lt);
202  void UpdateRouteToNeighbor (Ipv4Address sender, Ipv4Address receiver);
204  bool IsMyOwnAddress (Ipv4Address src);
208  void ProcessHello (RrepHeader const & rrepHeader, Ipv4Address receiverIfaceAddr);
210  Ptr<Ipv4Route> LoopbackRoute (const Ipv4Header & header, Ptr<NetDevice> oif) const;
213  //\{
215  void RecvAodv (Ptr<Socket> socket);
217  void RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address src);
219  void RecvReply (Ptr<Packet> p, Ipv4Address my,Ipv4Address src);
221  void RecvReplyAck (Ipv4Address neighbor);
223  void RecvError (Ptr<Packet> p, Ipv4Address src);
224  //\}
227  //\{
229  void SendPacketFromQueue (Ipv4Address dst, Ptr<Ipv4Route> route, uint16_t channel);
231  void SendRequest (Ipv4Address dst);
233  void SendReply (RreqHeader const & rreqHeader, RoutingTableEntry const & toOrigin);
239  void SendReplyByIntermediateNode (RoutingTableEntry & toDst, RoutingTableEntry & toOrigin, bool gratRep);
241  void SendReplyAck (Ipv4Address neighbor);
245  void SendRerrMessage (Ptr<Packet> packet, std::vector<Ipv4Address> precursors);
252  void SendRerrWhenNoRouteToForward (Ipv4Address dst, uint32_t dstSeqNo, Ipv4Address origin);
253  //\}
258  void HelloTimerExpire ();
262  void RreqRateLimitTimerExpire ();
266  void RerrRateLimitTimerExpire ();
268  std::map<Ipv4Address, Timer> m_addressReqTimer;
272  void AckTimerExpire (Ipv4Address neighbor, Time blacklistTimeout);
276 };
278 }
279 }
maintain list of active neighbors
Definition: aodv-neighbor.h:49
void SendReplyAck(Ipv4Address neighbor)
keep track of time unit.
Definition: nstime.h:149
uint16_t m_rreqCount
Number of RREQs used for RREQ rate control.
Callback template class.
Definition: callback.h:369
Time MaxQueueTime
The maximum period of time that a routing protocol is allowed to buffer a packet for.
AODV route request queue.
Definition: aodv-rqueue.h:95
RoutingTable m_routingTable
Routing table.
a simple Timer class
Definition: timer.h:45
Unique packets identification cache used for simple duplicate detection.
Definition: aodv-id-cache.h:45
Routing table entry.
Definition: aodv-rtable.h:59
uint32_t MaxQueueLen
The maximum number of packets that we allow a routing protocol to buffer.
Ptr< Ipv4 > m_ipv4
IP protocol.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
Ptr< Repository > m_crRepository
Pointer to cognitive radio repository.
bool Forwarding(Ptr< const Packet > p, const Ipv4Header &header, UnicastForwardCallback ucb, ErrorCallback ecb)
If route exists and valid, forward packet.
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
int64_t AssignStreams(int64_t stream)
Timer m_rreqRateLimitTimer
RREQ rate limit timer.
Time NetTraversalTime
Estimate of the average net traversal time.
Neighbors m_nb
Handle neighbors.
uint32_t RreqRetries
Maximum number of retransmissions of RREQ with TTL = NetDiameter to discover a route.
Route Request (RREQ) Message Format.
Definition: aodv-packet.h:102
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)
Ptr< Socket > FindSocketWithInterfaceAddress(Ipv4InterfaceAddress iface) const
Find socket with local interface address iface.
Ptr< Ipv4Route > LoopbackRoute(const Ipv4Header &header, Ptr< NetDevice > oif) const
Create loopback route for given header.
void RecvAodv(Ptr< Socket > socket)
Receive and process control packet.
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
Packet header for IPv4.
Definition: ipv4-header.h:31
bool DestinationOnly
Indicates only the destination may respond to this RREQ.
void RecvReplyAck(Ipv4Address neighbor)
Receive RREP_ACK.
void DeferredRouteOutput(Ptr< const Packet > p, const Ipv4Header &header, UnicastForwardCallback ucb, ErrorCallback ecb)
Queue packet and send route request.
bool IsMyOwnAddress(Ipv4Address src)
Check that packet is send from own interface.
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.
bool UpdateRouteLifeTime(Ipv4Address addr, Time lt)
void UpdateRouteToNeighbor(Ipv4Address sender, Ipv4Address receiver)
AODV routing protocol.
uint16_t RreqRateLimit
Maximum number of RREQ per second.
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
void SendReplyByIntermediateNode(RoutingTableEntry &toDst, RoutingTableEntry &toOrigin, bool gratRep)
uint16_t m_rerrCount
Number of RERRs used for RERR rate control.
Route Reply (RREP) Message Format.
Definition: aodv-packet.h:183
void SendRerrWhenNoRouteToForward(Ipv4Address dst, uint32_t dstSeqNo, Ipv4Address origin)
void SendRerrWhenBreaksLinkToNextHop(Ipv4Address nextHop)
Initiate RERR.
void SendPacketFromQueue(Ipv4Address dst, Ptr< Ipv4Route > route, uint16_t channel)
Forward packet from route request queue.
Time ActiveRouteTimeout
Period of time during which the route is considered to be valid.
void RecvRequest(Ptr< Packet > p, Ipv4Address receiver, Ipv4Address src)
Receive RREQ.
std::map< Ptr< Socket >, Ipv4InterfaceAddress > m_socketAddresses
Raw socket per each IP interface, map socket -> iface address (IP + mask)
void ProcessHello(RrepHeader const &rrepHeader, Ipv4Address receiverIfaceAddr)
Process hello message.
virtual void NotifyInterfaceUp(uint32_t interface)
The Routing table used by AODV protocol.
Definition: aodv-rtable.h:193
DuplicatePacketDetection m_dpd
Handle duplicated broadcast/multicast packets.
bool EnableBroadcast
Indicates whether a a broadcast data packets forwarding enable.
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.
Time PathDiscoveryTime
Estimate of maximum time needed to find route in network.
Time BlackListTimeout
Time for which the node is put into the blacklist.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
Time NextHopWait
Period of our waiting for the neighbour's RREP_ACK.
virtual void NotifyInterfaceDown(uint32_t interface)
void SetRepository(Ptr< Repository > repo)
Set cognitive radio repository.
Time MyRouteTimeout
Value of lifetime field in RREP generating by this node.
a class to store IPv4 address information on an interface
uint32_t AllowedHelloLoss
Number of hello messages which may be loss for valid link.
void SendRerrMessage(Ptr< Packet > packet, std::vector< Ipv4Address > precursors)
Forward RERR.
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:43
uint32_t NetDiameter
Net diameter measures the maximum possible number of hops between two nodes in the network...
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.
bool GratuitousReply
Indicates whether a gratuitous RREP should be unicast to the node originated route discovery...
uint16_t RerrRateLimit
Maximum number of REER per second.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
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.
a unique identifier for an interface.
Definition: type-id.h:44
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.
bool EnableHello
Indicates whether a hello messages enable.