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
44namespace ns3 {
45
46class WifiMacQueueItem;
47enum WifiMacDropReason : uint8_t; // opaque enum declaration
48
49namespace aodv {
56{
57public:
62 static TypeId GetTypeId (void);
63 static const uint32_t AODV_PORT;
64
67 virtual ~RoutingProtocol ();
68 virtual void DoDispose ();
69
70 // Inherited from Ipv4RoutingProtocol
75 virtual void NotifyInterfaceUp (uint32_t interface);
76 virtual void NotifyInterfaceDown (uint32_t interface);
77 virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
79 virtual void SetIpv4 (Ptr<Ipv4> ipv4);
80 virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
81
82 // Handle protocol parameters
88 {
89 return m_maxQueueTime;
90 }
95 void SetMaxQueueTime (Time t);
101 {
102 return m_maxQueueLen;
103 }
108 void SetMaxQueueLen (uint32_t len);
114 {
115 return m_destinationOnly;
116 }
122 {
124 }
130 {
131 return m_gratuitousReply;
132 }
138 {
140 }
145 void SetHelloEnable (bool f)
146 {
148 }
153 bool GetHelloEnable () const
154 {
155 return m_enableHello;
156 }
162 {
164 }
169 bool GetBroadcastEnable () const
170 {
171 return m_enableBroadcast;
172 }
173
182 int64_t AssignStreams (int64_t stream);
183
184protected:
185 virtual void DoInitialize (void);
186private:
194
195 // Protocol parameters.
197 uint16_t m_ttlStart;
198 uint16_t m_ttlIncrement;
199 uint16_t m_ttlThreshold;
232 //\}
233
237 std::map< Ptr<Socket>, Ipv4InterfaceAddress > m_socketAddresses;
242
258 uint16_t m_rreqCount;
260 uint16_t m_rerrCount;
261
262private:
264 void Start ();
296 bool UpdateRouteLifeTime (Ipv4Address addr, Time lt);
302 void UpdateRouteToNeighbor (Ipv4Address sender, Ipv4Address receiver);
308 bool IsMyOwnAddress (Ipv4Address src);
329 void ProcessHello (RrepHeader const & rrepHeader, Ipv4Address receiverIfaceAddr);
337 Ptr<Ipv4Route> LoopbackRoute (const Ipv4Header & header, Ptr<NetDevice> oif) const;
338
340 //\{
345 void RecvAodv (Ptr<Socket> socket);
352 void RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address src);
364 void RecvReplyAck (Ipv4Address neighbor);
371 void RecvError (Ptr<Packet> p, Ipv4Address src);
372 //\}
373
375 //\{
382 void SendHello ();
386 void SendRequest (Ipv4Address dst);
391 void SendReply (RreqHeader const & rreqHeader, RoutingTableEntry const & toOrigin);
397 void SendReplyByIntermediateNode (RoutingTableEntry & toDst, RoutingTableEntry & toOrigin, bool gratRep);
401 void SendReplyAck (Ipv4Address neighbor);
410 void SendRerrMessage (Ptr<Packet> packet, std::vector<Ipv4Address> precursors);
419
426 void SendTo (Ptr<Socket> socket, Ptr<Packet> packet, Ipv4Address destination);
427
431 void HelloTimerExpire ();
441 std::map<Ipv4Address, Timer> m_addressReqTimer;
453 void AckTimerExpire (Ipv4Address neighbor, Time blacklistTimeout);
454
459};
460
461} //namespace aodv
462} //namespace ns3
463
464#endif /* AODVROUTINGPROTOCOL_H */
double f(double x, void *params)
Definition: 80211b.c:70
Callback template class.
Definition: callback.h:1279
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Packet header for IPv4.
Definition: ipv4-header.h:34
a class to store IPv4 address information on an interface
Abstract base class for IPv4 routing protocols.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:109
@ S
second
Definition: nstime.h:114
A simple virtual Timer class.
Definition: timer.h:74
a unique identifier for an interface.
Definition: type-id.h:59
Helper class used to remember already seen packets and detect duplicates.
Definition: aodv-dpd.h:42
Unique packets identification cache used for simple duplicate detection.
Definition: aodv-id-cache.h:44
maintain list of active neighbors
Definition: aodv-neighbor.h:52
AODV route request queue.
Definition: aodv-rqueue.h:181
Ptr< Ipv4Route > LoopbackRoute(const Ipv4Header &header, Ptr< NetDevice > oif) const
Create loopback route for given header.
virtual void NotifyInterfaceUp(uint32_t interface)
uint32_t m_requestId
Broadcast ID.
void RecvAodv(Ptr< Socket > socket)
Receive and process control packet.
void UpdateRouteToNeighbor(Ipv4Address sender, Ipv4Address receiver)
Update neighbor record.
Timer m_rerrRateLimitTimer
RERR rate limit timer.
Time m_lastBcastTime
Keep track of the last bcast time.
void RecvReply(Ptr< Packet > p, Ipv4Address my, Ipv4Address src)
Receive RREP.
bool m_enableBroadcast
Indicates whether a a broadcast data packets forwarding enable.
bool GetBroadcastEnable() const
Get broadcast enable flag.
bool UpdateRouteLifeTime(Ipv4Address addr, Time lt)
Set lifetime field in routing table entry to the maximum of existing lifetime and lt,...
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 RerrRateLimitTimerExpire()
Reset RERR count and schedule RERR rate limit timer with delay 1 sec.
Time m_blackListTimeout
Time for which the node is put into the blacklist.
void RecvReplyAck(Ipv4Address neighbor)
Receive RREP_ACK.
virtual void NotifyInterfaceDown(uint32_t interface)
virtual void DoDispose()
Destructor implementation.
Time m_maxQueueTime
The maximum period of time that a routing protocol is allowed to buffer a packet for.
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
std::map< Ptr< Socket >, Ipv4InterfaceAddress > m_socketSubnetBroadcastAddresses
Raw subnet directed broadcast socket per each IP interface, map socket -> iface address (IP + mask)
Time m_activeRouteTimeout
Period of time during which the route is considered to be valid.
void SendReply(RreqHeader const &rreqHeader, RoutingTableEntry const &toOrigin)
Send RREP.
std::map< Ipv4Address, Timer > m_addressReqTimer
Map IP address + RREQ timer.
uint32_t GetMaxQueueLen() const
Get the maximum queue length.
void DeferredRouteOutput(Ptr< const Packet > p, const Ipv4Header &header, UnicastForwardCallback ucb, ErrorCallback ecb)
Queue packet and send route request.
void SendTo(Ptr< Socket > socket, Ptr< Packet > packet, Ipv4Address destination)
Send packet to destination scoket.
static TypeId GetTypeId(void)
Get the type ID.
DuplicatePacketDetection m_dpd
Handle duplicated broadcast/multicast packets.
Time m_netTraversalTime
Estimate of the average net traversal time.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
void SendRequest(Ipv4Address dst)
Send RREQ.
Time m_pathDiscoveryTime
Estimate of maximum time needed to find route in network.
bool m_gratuitousReply
Indicates whether a gratuitous RREP should be unicast to the node originated route discovery.
uint16_t m_rerrCount
Number of RERRs used for RERR rate control.
void HelloTimerExpire()
Schedule next send of hello message.
RoutingTable m_routingTable
Routing table.
uint16_t m_rreqRateLimit
Maximum number of RREQ per second.
void ProcessHello(RrepHeader const &rrepHeader, Ipv4Address receiverIfaceAddr)
Process hello message.
Ptr< NetDevice > m_lo
Loopback device used to defer RREQ until packet will be fully formed.
uint32_t m_netDiameter
Net diameter measures the maximum possible number of hops between two nodes in the network.
uint32_t m_maxQueueLen
The maximum number of packets that we allow a routing protocol to buffer.
uint16_t m_ttlThreshold
Maximum TTL value for expanding ring search, TTL = NetDiameter is used beyond this value.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
void SetMaxQueueTime(Time t)
Set the maximum queue time.
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.
uint16_t m_ttlIncrement
TTL increment for each attempt using the expanding ring search for RREQ dissemination.
Time m_myRouteTimeout
Value of lifetime field in RREP generating by this node.
uint16_t m_timeoutBuffer
Provide a buffer for the timeout.
Ptr< Socket > FindSocketWithInterfaceAddress(Ipv4InterfaceAddress iface) const
Find unicast socket with local interface address iface.
void SetBroadcastEnable(bool f)
Set broadcast enable flag.
void SendPacketFromQueue(Ipv4Address dst, Ptr< Ipv4Route > route)
Forward packet from route request queue.
uint32_t m_allowedHelloLoss
Number of hello messages which may be loss for valid link.
bool IsMyOwnAddress(Ipv4Address src)
Test whether the provided address is assigned to an interface on this node.
void SetMaxQueueLen(uint32_t len)
Set the maximum queue length.
void ScheduleRreqRetry(Ipv4Address dst)
Repeated attempts by a source node at route discovery for a single destination use the expanding ring...
void SendReplyByIntermediateNode(RoutingTableEntry &toDst, RoutingTableEntry &toOrigin, bool gratRep)
Send RREP by intermediate node.
void SetGratuitousReplyFlag(bool f)
Set gratuitous reply flag.
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
void Start()
Start protocol operation.
uint16_t m_rreqCount
Number of RREQs used for RREQ rate control.
IdCache m_rreqIdCache
Handle duplicated RREQ.
void NotifyTxError(WifiMacDropReason reason, Ptr< const WifiMacQueueItem > mpdu)
Notify that an MPDU was dropped.
std::map< Ptr< Socket >, Ipv4InterfaceAddress > m_socketAddresses
Raw unicast socket per each IP interface, map socket -> iface address (IP + mask)
Time m_deletePeriod
DeletePeriod is intended to provide an upper bound on the time for which an upstream node A can have ...
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
void SendRerrWhenNoRouteToForward(Ipv4Address dst, uint32_t dstSeqNo, Ipv4Address origin)
Send RERR message when no route to forward input packet.
Time m_helloInterval
Every HelloInterval the node checks whether it has sent a broadcast within the last HelloInterval.
void AckTimerExpire(Ipv4Address neighbor, Time blacklistTimeout)
Mark link to neighbor node as unidirectional for blacklistTimeout.
void SetHelloEnable(bool f)
Set hello enable.
bool m_destinationOnly
Indicates only the destination may respond to this RREQ.
void SetDestinationOnlyFlag(bool f)
Set destination only flag.
bool GetDestinationOnlyFlag() const
Get destination only flag.
void SendRerrMessage(Ptr< Packet > packet, std::vector< Ipv4Address > precursors)
Forward RERR.
uint16_t m_ttlStart
Initial TTL value for RREQ.
uint32_t m_rreqRetries
Maximum number of retransmissions of RREQ with TTL = NetDiameter to discover a route.
uint32_t m_seqNo
Request sequence number.
bool m_enableHello
Indicates whether a hello messages enable.
Neighbors m_nb
Handle neighbors.
bool Forwarding(Ptr< const Packet > p, const Ipv4Header &header, UnicastForwardCallback ucb, ErrorCallback ecb)
If route exists and is valid, forward packet.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
static const uint32_t AODV_PORT
UDP Port for AODV control traffic.
Timer m_rreqRateLimitTimer
RREQ rate limit timer.
Time GetMaxQueueTime() const
Get maximum queue time.
Time m_nodeTraversalTime
NodeTraversalTime is a conservative estimate of the average one hop traversal time for packets and sh...
uint16_t m_rerrRateLimit
Maximum number of REER per second.
void RecvRequest(Ptr< Packet > p, Ipv4Address receiver, Ipv4Address src)
Receive RREQ.
Ptr< Socket > FindSubnetBroadcastSocketWithInterfaceAddress(Ipv4InterfaceAddress iface) const
Find subnet directed broadcast socket with local interface address iface.
bool GetHelloEnable() const
Get hello enable flag.
void SendRerrWhenBreaksLinkToNextHop(Ipv4Address nextHop)
Initiate RERR.
void RouteRequestTimerExpire(Ipv4Address dst)
Handle route discovery process.
virtual void DoInitialize(void)
Initialize() implementation.
bool GetGratuitousReplyFlag() const
Get gratuitous reply flag.
void RecvError(Ptr< Packet > p, Ipv4Address src)
Receive RERR.
Time m_nextHopWait
Period of our waiting for the neighbour's RREP_ACK.
void SendReplyAck(Ipv4Address neighbor)
Send RREP_ACK.
Ptr< Ipv4 > m_ipv4
IP protocol.
void RreqRateLimitTimerExpire()
Reset RREQ count and schedule RREQ rate limit timer with delay 1 sec.
RequestQueue m_queue
A "drop-front" queue used by the routing layer to buffer packets to which it does not have a route.
Routing table entry.
Definition: aodv-rtable.h:60
The Routing table used by AODV protocol.
Definition: aodv-rtable.h:390
Route Reply (RREP) Message Format.
Definition: aodv-packet.h:336
Route Request (RREQ) Message Format.
Definition: aodv-packet.h:132
WifiMacDropReason
The reason why an MPDU was dropped.
Definition: wifi-mac.h:66
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.