Professional Documents
Culture Documents
Design and Analysis of Modified AODV
Design and Analysis of Modified AODV
BACHELOR OF TECHNOLOGY
degree
In
Computer Science & Engineering
By
Ragini Tiwari(1235210083)
Shubhanshi Sharma(1235210096)
Surabhi Sharma(1235210102)
Name of Guide
Mr. Prashant Kumar Mishra
Date:
i
DECLARATION
Shubhanshi Sharma(1235210096)
ii
ACKNOWLEDGEMENT
In the end we would like to thank our friends, family for bearing
with us, supporting us emotionally thereby helping us to finish the
project.
Ragini Tiwari
Shubhanshi Sharma
Surabhi Sharma
iii
ABSTRACT
iv
TABLE OF CONTENTS
CERTIFICATE i
DECLARATION ii
ACKNOWLEDGEMENT iii
ABSTRACT iv
LIST OF TABLES vii
LIST OF FIGURE vii
LIST OF ABBREVIATIONS viii
1. INTRODUCTION 1
3. Methodology 27
4. Result 28
4.1 Parameters 28
4.2 Performance of AODV 29
4.3 Performance of Modified AODV 29
5. Analysis of Results 30
5.1 Graphical comparison of AODV & Modified AODV 30
5.1.1 Packet Delivery Ratio in AODV&Modified AODV 30
5.1.2 End to End Delay in AODV & Modified AODV 31
5.1.3 Generated Packets in AODV & Modified AODV 32
6. Conclusion & Future Works 34
6.1 Summary of Work done 34
6.2 Conclusion 34
6.3 Future Works 35
6. Appendix-1: Code Snippet 36
8. Appendix-2: User Interface Design 65
9. References 67
vi
LIST OF TABLES
LIST OF FIGURES
vii
LIST OF ABBREVIATIONS
viii
CHAPTER-1
INTRODUCTION
1
Fig1.1 Overview of Ad-hoc Networks
2
Load Balancing-Operating in a single channel might yield various
problems like delay and hidden node problems. Load balancing by making
use of all available channels would optimize channel utilization which would
help reduce delay and hidden terminal problem.
3
1.3 Problem Identification
All the above mentioned concerns call for an efficient protocol that
would make efficient routing decisions. Once the aforementioned parameters are
taken into account, reliable and efficient packet delivery to the end nodes is
ensured.
4
1.4 Proposed Solution
Considering the need for the messages to reach the intended recipient
within the stipulated time, the existing routing metric (AODV) is modified to
make use of all the available channels. Based on the composite metric (modified
AODV), the source node selects the best possible route through which it
forwards the packet. These metrics are considered important in ad hoc
environment.
5
CHAPTER-2
6
Routing tables are updated by all the nodes in order to maintain a consistent
and up to date view of the network. In table driven routing protocol, continuous
broadcasting of messages is done in order to establish routes and maintain them. For
example: DSDV etc.
In Reactive (on demand) routing protocol, creation of routes is done when it
is required. When some packets are to be send from source to destination, it may
invoke the route discovery mechanism to find the path to the destination. The route
is valid, till the destination is reached or it is no longer be required in the future. For
example: AODV, DSR etc. In hybrid protocol routing, we combine the benefits of
both the reactive as well as proactive. Hybrid protocols are basically dependent on
the network size for their functionality.
MANETs are very much different from the wireless network infrastructures.
MANETs has to face various challenges in order to achieve best Quality of Service
for the underlying network.
Some of these challenges are as follows:
1. Unicast and multicast routing.
2. Topology changes dynamically.
3. Speed and network overhead.
4. Limited power supply and bandwidth.
5. Quality of service and secure routing.
6. Scalable and energy efficient routing.
These challenges are faced at the different layers of MANETs shown in the
figure 1.2. It represents the layered architecture of the OSI model and entitled the
challenges of MANETs regarding these layers.
8
Application Layer 6 Security
DSDV
WRP
AODV DSR LMR ABR
CGSR
TORA SSR
9
2.4 Ad hoc On Demand Distance Vector (AODV)
The main aim of AODV routing algorithm is to provide reliable and secure
data transmission over the MANETs. In this routing protocol route maintenance
from one node to every other node is not considered in the network. Whereas in
AODV, route are discovered only when they are needed as well as they are
maintained only as long as they are required.
10
Figure 2.3 Route discovery in AODV
1. Route creation-
Route creation process is initiated when the node wants to send the data
packet to the destination node but does not find the valid route to send the packet.
This process is initiated as such: when a particular node want to send the data packet
to the destination node then, the routing table entries are checked in order to verify
whether there exists a route between the source and destination or not. If the route
exists, then the packet is forwarded to the next hop towards the destination.
When the route does not exists, and then the route discovery process is
initiated. AODV starts the route discovery process using the route request (RREQ)
and route reply (RREP).
11
The source node will create the route request packet(RREQ) containing its
sequence number, its IP address , destination node sequence number, destination IP
address and broadcasting ID. Whenever the source node initiates the RREQ, the
broadcast ID is incremented each time. As the sequence number is used to identify
the timeliness of each data packet and broadcast ID and the IP address identify the
unique identifier for route request so that they can uniquely identify each of the
request. The data packet sends the request using the RREQ message and gets back
the reply in the form of RREP message if the route is discovered between the nodes.
The source node sends the RREQ packet to its neighbors as well as set the timer in
order to wait for the RREP message.
In order to describe RREQ, reverse route entry is set up by the node in its
routing table. This enables us to know how we can forward the route reply (RREP)
to the source. Moreover, a time period is associated with the reverse route entry and
if this route entry is not used within the given time period then only the route
information is deleted. If in any case RREQ is lost during the transfer of packet then
the source node again initiates route discovery mechanism.
2. Route maintenance-
Route that has been created by the source node and destination node is being
maintained as long as it is needed by the source node. Since nodes in the MANETs
are mobile and if the source node is in the mobile state during the active session, it
again restarts the route discovery mechanism in order to establish new routes from
source to destination. Otherwise, if some of the intermediate node or the destination
node is in the mobile state during the active session, then the nodes initiates the
RERR message that affects the above neighbors and the nodes.
12
As a result of which these nodes forward the RERR message to the
predecessor nodes and can be continued until the source node is reached. When
RERR is received by the source node, then the node stop sending the data or it can
again start the route discovery mechanism by sending the RREQ message.
The AODV Routing Protocol uses an on-demand approach for finding routes,
that is, a route is established only when it is required by a source node for
transmitting data packets. It employs destination sequence numbers to identify
the most recent path. The major difference between AODV and Dynamic Source
Routing (DSR) stems out from the fact that DSR uses source routing in which a
data packet carries the complete path to be traversed.
13
However, in AODV, the source node and the intermediate nodes store the next-
hop information corresponding to each flow for data packet transmission. In an
on-demand routing protocol, the source node floods the RouteRequest packet in
the network when a route is not available for the desired destination. It may
obtain multiple routes to different destinations from a single RouteRequest.
14
When a node receives a RouteReply packet, information about the previous node
from which the packet was received is also stored in order to forward the data
packet to this next node as the next hop toward the destination.
Advantages-
Disadvantages-
• Bi-directional connection needed in order to detect a unidirectional link.
• Delay caused by the route discovery process.
15
Mobile nodes cause broken links when they move from place to place. When a link
to the next hop is broken, any route through that next hop is immediately assigned
infinity metric and an updated sequence number. This is the only situation when any
mobile node other than the destination node assigns the sequence number. Sequence
numbers assigned by the origination nodes are even numbers, and sequence numbers
assigned to indicate infinity metrics are odd numbers. When a node receives infinity
metric, and it has an equal or later sequence number with a finite metric, it triggers a
route update broadcast, and the route with infinity metric will be quickly replaced by
the new route. When a mobile node receives a new route update packet; it compares
it to the information already available in the table and the table is updated based on
the following criteria:
If the received sequence number is greater, then the information in the table
is replaced with the information in the update packet.
Otherwise, the table is updated if the sequence numbers are the same and the
metric in the update packet is better.
DSDV introduces the large amount of overhead to the network due to the
requirement of periodic update messages. Hence, this protocol is not suitable for the
large network because large portion of the network bandwidth is used for the
updating of messages.
Advantages-
• Guarantees loop free path.
• Count to infinity problem is reduced in DSDV.
• With incremental updates, we can avoid extra traffic.
• DSDV maintains the best possible path instead of maintaining the multiple paths
to the destination this reduces the amount of space in the routing table.
16
Disadvantages-
• It does not support the multipath routing.
• Difficult to determine the delay for the advertisement of routes.
• Unnecessary advertising of routing information can result in the
wastage of bandwidth.
17
A route reply is generated by the destination, then it places the route record
from the route request packet into the route reply packet.
On the other hand, if the node generating the route reply is an intermediate node,
then it appends its cached route to the destination to the route record of the route
request packet and puts that into the route reply packet being sent by the destination
itself.
To send the route reply packet, the responding node must have a route to the
source. If it has a route to the source in its route cache, it can use that route.The
reverse of route record can be used if symmetric links are supported. In case
symmetric links are not supported, the node can initiate route discovery to the source
and piggyback the route reply on this new route request.
DSR uses two types of packets for route maintenance: Route Error packet
and acknowledgements.
When a node encounters a fatal transmission problem at its data link layer, it
generates a route error packet. When a node receives a node error packet, it removes
the hop in error from its route cache.
All routes that contain the hop in error are truncated at that point. Acknowledgement
packets are used to verify the correct operation of the route links. This also includes
passive acknowledgements in which a node hears the next hop forwarding the
packet along the route.
The proposed protocol has all the characteristics of the original AODV
routing protocol since it follows all the steps of the route discovery and route
maintenance mechanism of the original AODV routing protocol. The modified
AODV is different from the original AODV protocol, in that it modifies the original
AODV to reduce the length of the path of routing messages (RERR and RREQ)
when link breakage occurs. The modification of AODV reduces the protocol
overhead, packet losses and packet transmission time delays.
18
2.7.1 Algorithm of the Modified AODV
2. Any intermediate node which receives the RERR message, then checks its
state flag; if the node is mobile, it then forwards the RERR message to the
next hop towards the source.
4. In the case that the intermediate node is a part of the old route (and has an
entry for a path to the unreachable destination in its routing table), it must
perform the steps below:
Discard the RERR message.
Stop sending the data to the next node.
Save the received packets from the source node.
Increment the destination’s sequence number.
Initiate an RREQ message and broadcast it to all neighbors.
Wait to receive the RREP from the destination.
5. When the initiator of the RREQ has received the RREP from the destination
or from any node which has a route to the destination, it must perform the
steps below:
19
Modify the routing table’s entry for the path to the destination according to
the new route.
Start sending the saved data.
6. MAODV continues to work the same as the original AODV from this step
onwards.
All the rules of the original AODV apply to the MAODV since the MAODV just
decreases the path of the RERR.
If calculated power is greater than threshold power then link will be available
till that time otherwise, link may break before time t. Bisection method is used to
calculate the link breakage time (assuming free space propagation model).
20
2.8.2 Link Breakage Time Evaluation
1. Check how many packets are in signal info array to predict link breakage time
2. If p(tprev)>pthreshold and p(tnext)<pthreshold then the link breakage time will lie
between tprev and tnext and we have apply bisection method consecutively to
find accurate time.
a. tbr=(tprev+tnext)/2;
b. if p(tprev)>pthreshold and p(tbr)<pthreshold then set
tnext=tbr
c. otherwise set tprev=tbr
d. If tbr-(tprev+tnext)/2 <= correctness then the link breakage
time will be
tbr=(tprev+tnext)/2 otherwise, set tbr=(tprev+tnext)/2 and goto
step b.
21
3. Otherwise set tprev=tnext and tnext=tnext+1. If tnext=t[3]<=limit then goto step2
otherwise allot tbr a high value because the link will not break before time
(t[3]+limit).
We consider atleast three data packet that are stored in the signal info array
to predict link breakage time (tbr). Every mobile node maintain signal info array that
holds received power and reception time from its neighbouring mobile node.The
powers and time are updated in following order-
P[3]<p[2]<p[1]<p[0] and t[3]>t[2]>t[1]>t[0]
If only three packets are in signal info then the link breakage time is
calculated using these only three packets. If mobile node are moving closer then the
received power will be greater and in this case no link prediction is necessary.
2.9 Simulator
22
Creating a working implementation of an ad hoc routing protocol is non-
trivial and more difficult than developing a simulation. In simulation, the developer
controls the whole system, which is in effect only a single component, an
implementation, on the other hand, needs to interoperate with a large, complex
system. Some components of this system are the operating system, sockets, and
network interfaces.
Additional implementation problems surface because current operating
systems are not built to support ad hoc routing protocols. A number of required
events are unsupported; support for these events must be added. Because these
events encompass many systems components, the components and their interactions
must also be explored. For these reasons it takes significantly more effort to create
an ad hoc routing protocol implementation than a simulation.
23
NS-2 fully simulates a layered network from the physical radio transmission
channel to high-level applications. The simulator supports a class hierarchy in C++
and a similar class hierarchy within the OTcl interpreter. There is a one-to-one
correspondence between a class in the interpreted hierarchy and one in the compile
hierarchy. The reason to use two different programming languages is that OTcl is
suitable for the programs and configurations that demand frequent and fast change
while C++ is suitable for the programs that have high demand in speed. NS2 is
highly extensible. It not only supports most commonly used IP protocols but also
allows the users to extend or implement their own protocols. The simulator is
composed of two parts:
The TCL code: It is used to communicate with the simulator, and permits to
define different simulation parameters.
The C++ code: It is the main part of the project, because it defines how the
simulator has to behave.
24
2.9.2 TCL: The Scenario Interface
The main reason for using a TCL language in ns2 is because it is not useful
to use only C++ code. In fact, by this mean, the user does not need to compile the
simulator every time he wants to do a new simulation. The TCL language is
interpreted by the C++ code in ns2, without being compiled. To use a network
simulator, you have to define two things:
How does the protocol behave? It is done by the C++ code, because it does
not change for every simulation.
What are the simulation parameters? It is done by the TCL code, because
every simulation is different (number of nodes, positions, speeds, protocol
used).
The TCL code allows the user to choose between fix or wireless network,
and among the different implemented protocols: TORA, AODV, DSR (for wireless
networks). It also contains information about nodes like position and speed, or
information about source and destination, the transmission rate, and a lot of other
parameters. Some tools have been developed to build these scenarios.
25
2.9.3 Implementation in NS2 :
All simulations have been carried out using the NS simulator program
version 2.34 under Linux platform. NS2 is an open source simulator software and
used by a lot of institutes and researchers.
The main goal of the NS2 simulator is to provide support to education and research
in networking. It is one of the best programs in terms of comparing different routing
protocols and designing new ones.
NS2 has been written in two languages: Object oriented variant of Tool
Command Language (OTCL) and object oriented language C++. Here we are using
the OTCL implementation.
26
CHAPTER-3
METHODOLOGY
The methodology of this work entitled has always been a tedious task as it
requires a lot of analysis work and drawing inferences from the same.
The following shows up the detailed algorithm and methodology of the work
that has been done by us in the due course of this work:
1. Install NS2 2.35 package on any Linux platform (Here we have used Ubuntu
14.04).
2. Design the .tcl files with specifications like number of nodes, node types, the
link specification between the nodes, and design with proper variations.
(refer to the Code Snippet Section of this work).
3. Use it with the ns nam animator to present and gain inferences on the
terminal window. Ex: ns filename.tcl
4. Implement the protocols AODV and DSDV using the packages available
within NS2, run it with the animator of NS and generate the trace file. Ex:
set tracefd [open filename.tr w]
5. Use the awk tool utility to generate the exact statistics of the protocol run
depending upon the various parameters specified.
6. Analyse the various observations and the do the analysis required and give
results.
27
CHAPTER-4
RESULTS
4.1 Parameters
Packet Delivery Ratio (PDR): It is the ratio of total data bits received
to total data bits sent from source to destination.
Generated Packets: It is the total number of data bits send from source
to destination.
Dropped Packets: It is the total number of data bits dropped in the path.
28
4.2 Performance of AODV
29
CHAPTER-5
ANALYSIS OF RESULTS
Packet Delivery Ratio is basically ratio of received packets and sent packets
in any network.
This graph shows the packet delivery ratios of AODV & DSDV by taking
packet delivery ratio on y-axis and number of mobile nodes on x-axis.
30
This graph shows us that on varying the no. of nodes in the network, the
packet delivery ratio of AODV is quite the same but in DSDV it is decreasing with
the increase of no. of mobile node.
Initially when the no of mobile nodes were only 5, they both have almost the
same ratio but gradually the ratio for the DSDV decreases but for AODV there is no
such effect on that. So we can say that the Packet delivery ratio for DSDV depends
on the no of mobile nodes in the network but AODV’s ratio is independent of that.
End-to-end delay is the time gap (in ms) taken by the protocol to successfully send
any packet from one node to another. This graph shows the end-to-end delay in
AODV & Modified AODV by taking end-to-end delay on y-axis and number of
mobile nodes on x-axis.
This graph shows us that on varying the no. of nodes in the network, the end-
to-end delay of AODV is always higher than that of Modified AODV.
Initially when the no of mobile nodes were only 3, the delay in AODV is less
as we compare it with Modified AODV and that ratio remains the almost same for
increase in nodes as well.
31
5.1.4 Generated Packets in AODV & Modified AODV
This graph shows us that on varying the no. of nodes in the network, the
packets generated in Modified AODV are higher than in AODV. Also we have
observed that the packets generated in AODV are nearly constant while in other it is
not so.
32
CHAPTER-6
1. Study and analysis of the protocol i.e. AODV and Modified AODV.
6.2 Conclusion:
33
The conclusions can be stated as:
If we are Using the Modified AODV and AODV routing Protocol with 30 nodes,
pause time 10 s, varying node speed (20-100 m/s by interval of 20 m/s) then
overall result say that packet delivery fraction and normalized routing load in
1000 m. x 1000 m. of AODV is more optimal than 1000 m. x 1000 m. of
Modified AODV.
The Packet Delivery Fraction is always low in AODV on varying node speed.
The Average Throughput is greater in AODV on varying node speed.
There were some anomalies observed due to the increased loss of packets when
the number of nodes increases from 35 to 40. In this, the throughput was
decreased considerably and that results due to the overhead generated at each
node regarding the updation of the table.
34
6.3 Future Works
In our study, we have tried to carry out all the variations we could do in
order to cover every aspect of the analysis. But as there is always a scope for
betterment, the project offers the following future works to be done.
The number of nodes and velocity might be changed and varied to improve
the charges.
The anomalies that were observed could have been be dealt with more
intense work and study so as to reduce them to a considerable extent.
35
APPENDIX-1
CODE SNIPPET
1. AODV Implementation:
# Define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 3 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 500 ;# X dimension of topography
set val(y) 400 ;# Y dimension of topography
set val(stop) 150 ;# time of simulation end
set ns [new Simulator]
set namtrace [open simwrls.nam w]
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
36
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns node] }
# Provide initial location of mobilenodes
$node_(0) set X_ 5.0
$node_(0) set Y_ 5.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 490.0
$node_(1) set Y_ 285.0
$node_(1) set Z_ 0.0
$node_(2) set X_ 150.0
$node_(2) set Y_ 240.0
$node_(2) set Z_ 0.0
# Generation of movements
$ns at 1.0 "$node_(0) setdest 250.0 250.0 3.0"
$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
$ns at 10.0 "$node_(0) setdest 480.0 300.0 5.0"
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp
37
$ns attach-agent $node_(1) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"
proc plotWindow {tcpSource file} {
global ns
set time 0.01
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 10.1 "plotWindow $tcp $windowVsTime2"
for {set i 0} {$i < $val(nn)} { incr i } {
$ns initial_node_pos $node_($i) 30}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "$node_($i) reset";}
# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
proc stop {} {
global ns tracefd namtrace
}
$ns run
38
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 30 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 500 ;# X dimension of topography
set val(y) 400 ;# Y dimension of topography
set val(stop) 150 ;# time of simulation end
set ns [new Simulator]
set tracefd [open simple5.tr w]
set windowVsTime2 [open win5.tr w]
set namtrace [open simwrls5.nam w]
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
39
-macTrace OFF \
-movementTrace ON
for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns node]
}
$node_(0) set X_ 5.0
$node_(0) set Y_ 5.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 490.0
$node_(1) set Y_ 285.0
$node_(1) set Z_ 0.0
$node_(2) set X_ 150.0
$node_(2) set Y_ 240.0
$node_(2) set Z_ 0.0
$node_(3) set X_ 250.0
$node_(3) set Y_ 240.0
$node_(3) set Z_ 0.0
$node_(4) set X_ 100.0
$node_(4) set Y_ 70.0
$node_(4) set Z_ 0.0
# Generation of movements
$ns at 10.0 "$node_(0) setdest 250.0 250.0 10.0"
$ns at 15.0 "$node_(1) setdest 45.0 285.0 10.0"
$ns at 110.0 "$node_(0) setdest 480.0 300.0 10.0"
$ns at 70.0 "$node_(3) setdest 180.0 30.0 10.0"
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
40
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp
$ns attach-agent $node_(1) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"
proc plotWindow {tcpSource file} {
global ns
set time 0.01
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 10.1 "plotWindow $tcp $windowVsTime2"
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } {
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30
}
# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "$node_($i) reset";
}
# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 150.01 "puts \"end simulation\" ; $ns halt"
proc stop {} {
41
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
#Execute nam on the trace file
exec nam simwrls4.nam &
exit 0
}
$ns run
42
//return (new AODV((nsaddr_t) atoi(argv[4])));
return (new AODV((nsaddr_t) Address::instance().str2addr(argv[4])));
}
} class_rtProtoAODV;
int
AODV::command(int argc, const char*const* argv) {
if(argc == 2) {
Tcl& tcl = Tcl::instance();
if(strncasecmp(argv[1], "id", 2) == 0) {
tcl.resultf("%d", index);
return TCL_OK;
}
if(strncasecmp(argv[1], "start", 2) == 0) {
btimer.handle((Event*) 0);
#ifndef AODV_LINK_LAYER_DETECTION
htimer.handle((Event*) 0);
ntimer.handle((Event*) 0);
#endif // LINK LAYER DETECTION
rtimer.handle((Event*) 0);
return TCL_OK;
} }
else if(argc == 3) {
if(strcmp(argv[1], "index") == 0) {
index = atoi(argv[2]);
return TCL_OK; }
else if(strcmp(argv[1], "log-target") == 0 || strcmp(argv[1], "tracetarget") == 0) {
logtarget = (Trace*) TclObject::lookup(argv[2]);
if(logtarget == 0)
43
return TCL_ERROR;
return TCL_OK; }
else if(strcmp(argv[1], "drop-target") == 0) {
int stat = rqueue.command(argc,argv);
if (stat != TCL_OK) return stat;
return Agent::command(argc, argv); }
else if(strcmp(argv[1], "if-queue") == 0) {
ifqueue = (PriQueue*) TclObject::lookup(argv[2]);
if (dmux_ == 0) {
fprintf (stderr, "%s: %s lookup of %s failed\n", __FILE__,
argv[1], argv[2]);
return TCL_ERROR; }
return TCL_OK; } }
return Agent::command(argc, argv);
}
AODV::AODV(nsaddr_t id) : Agent(PT_AODV),
btimer(this), htimer(this), ntimer(this),
rtimer(this), lrtimer(this), rqueue() {
index = id;
seqno = 2;
bid = 1;
LIST_INIT(&nbhead);
LIST_INIT(&bihead);
//rt->rt_seqno++;
agent->rt_down(rt);
#ifdef DEBUG
fprintf(stderr,"Dst - %d, failed local repair\n", rt->rt_dst);
#endif
44
}
Packet::free((Packet *)p);
}
void AODV::id_insert(nsaddr_t id, u_int32_t bid) {
BroadcastID *b = new BroadcastID(id, bid);
assert(b);
b->expire = CURRENT_TIME + BCAST_ID_SAVE;
LIST_INSERT_HEAD(&bihead, b, link);
}
bool AODV::id_lookup(nsaddr_t id, u_int32_t bid) {
BroadcastID *b = bihead.lh_first;
for( ; b; b = b->link.le_next) {
if ((b->src == id) && (b->id == bid))
return true; }
return false; }
void AODV::id_purge() {
BroadcastID *b = bihead.lh_first;
BroadcastID *bn;
double now = CURRENT_TIME;
for(; b; b = bn) {
bn = b->link.le_next;
if(b->expire <= now) {
LIST_REMOVE(b,link);
delete b;
void AODV::sendP_Error(Packet *p)
{
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_aodv_p_error *re = HDR_AODV_P_ERROR(p);
45
re->re_type=AODVTYPE_P_RERR;
ch->ptype() = PT_AODV;
ch->size() = IP_HDR_LEN + re->size();
ch->iface() = -2;
ch->error() = 0;
ch->addr_type() = NS_AF_NONE;
ch->next_hop_ = 0;
ch->prev_hop_ = index; // AODV hack
ch->direction() = hdr_cmn::DOWN; //important: change the packet's direction
ih->saddr() = index;
ih->daddr() = IP_BROADCAST;
ih->sport() = RT_PORT;
ih->dport() = RT_PORT;
ih->ttl_ = 1;
// Do we need any jitter? Yes
//printf("Sceduling at sendperror at %d",index);
Scheduler::instance().schedule(target_, p, 0.0);
}
void AODV::recvP_Error(Packet *p)
{
struct hdr_ip *ih = HDR_IP(p);
struct hdr_aodv_p_error *re=HDR_AODV_P_ERROR(p);
aodv_rt_entry *rt;
u_int8_t i;
Packet *prerr= Packet::alloc();
struct hdr_aodv_p_error *nre=HDR_AODV_P_ERROR(prerr);
nre->DestCount=0;
for(i=0; i<re->DestCount; i++){
46
rt=rtable.rt_lookup(re->linkbreakable_dst[i]);
if(rt &&(rt->rt_hops!=INFINITY2)&&
(rt->rt_nexthop==ih->saddr()))
{
assert(rt->rt_flags==RTF_UP);
rt->rt_flags=P_RTF_UP;
rt->rt_expire=CURRENT_TIME+re->predTime-PerHopTime(rt);
if(!rt->pc_empty()) {
AODV_Precursor *pc=rt->rt_pclist.lh_first;
nre->linkbreakable_dst[nre->DestCount]=re->linkbreakable_dst[i];
nre->DestCount++; }
if(rt->rt_src==index) {
sendAREQ(re->linkbreakable_dst[i]); }}}
nre->predTime=re->predTime-PerHopTime(rt);
Packet::free(p);
if(nre->DestCount>0)
{
sendP_Error(prerr);
}
else
{
Packet::free(prerr);
}}
void AODV::sendAREQ(nsaddr_t id)
{
aodv_rt_entry *rt;
rt=rtable.rt_lookup(id,true);
if(rt==0)
{
47
rt=rtable.rt_add(id,true);
}
rt->rt_src=index;
sendRequest(rt->rt_dst,true);
}
node.cc
#include "parentnode.h"
#define NO_OF_PACKET_FOR_PREDICTION 4
#define PREDICTION_TIME_INFINITY 2000.0
#define HANDOFF_THRESHOLD 4.0e-09
#define SETUP_TIME 1.0
#define TIME 2.000000
#define RThres_3.067e-09
#define CORRECTNESS 0.001
#define VALUE 100
#define DECREMENT 1.0
class SignalPower;
class SignalPower
public:
int No_of_Packets;
int nodeID;
double predictTime;
double receivingTime[NO_OF_PACKET_FOR_PREDICTION];
double receivingPower[NO_OF_PACKET_FOR_PREDICTION];
public:
48
LIST_ENTRY(SignalPower) SignalPower_entry;
//member functions
inline int getNodeid() {return nodeID;}
inline double getPredict() {return predictTime;}
//initial instance variables
SignalPower(int nID) {
nodeID=nID;
No_of_Packets=0;
predictTime=PREDICTION_TIME_INFINITY;
for(int i=0;i<NO_OF_PACKET_FOR_PREDICTION;i++) {
receivingTime[i]=0.0;
receivingPower[i]=-1.0;
}//printf("no of packets=%d id=d......\n",No_of_Packets,nodeID);
}
double getLastpktPower(void)
{
if(No_of_Packets>0)
return receivingPower[No_of_Packets-1];
}
//add the time and power parameters
void addParameter(double aPower,double aTime);
double predTime(void);
double getPower_pkt4(double);
double getPower_pkt3(double);
};
class Node : public ParentNode {
//added for receiving power and time list public:
SignalPower* getSignalPowerObject(int NodeId1);
double predtm(int NodeId1);
};
49
ll.cc
#ifndef lint
static const char rcsid[] =
#endif
#include <errmodel.h>
#include <mac.h>
#include <ll.h>
#include <address.h>
#include <dsr/hdr_sr.h>
int hdr_ll::offset_;
static class LLHeaderClass : public PacketHeaderClass {
public:
LLHeaderClass() : PacketHeaderClass("PacketHeader/LL",
sizeof(hdr_ll)) {
bind_offset(&hdr_ll::offset_); }
}
class_hdr_ll;
static class LLClass : public TclClass {
public:
LLClass() : TclClass("LL") {}
TclObject* create(int, const char*const*) {
return (new LL);
}
} class_ll;
LL::LL() : LinkDelay(), seqno_(0), ackno_(0), macDA_(0), ifq_(0),
mac_(0), lanrouter_(0), arptable_(0), varp_(0),
downtarget_(0), uptarget_(0) {
bind("macDA_", &macDA_); }
50
int LL::command(int argc, const char*const* argv)
{
Tcl& tcl = Tcl::instance();
if (argc == 3) {
if (strcmp(argv[1], "ifq") == 0) {
ifq_ = (Queue*) TclObject::lookup(argv[2]);
return (TCL_OK);
}
if(strcmp(argv[1], "arptable") == 0) {
arptable_ = (ARPTable*)TclObject::lookup(argv[2]);
assert(arptable_);
return TCL_OK; }
if(strcmp(argv[1], "varp") == 0) {
varp_ = (VARPTable*)TclObject::lookup(argv[2]);
assert(varp_);
return TCL_OK;
}
if (strcmp(argv[1], "mac") == 0) {
mac_ = (Mac*) TclObject::lookup(argv[2]);
assert(mac_);
return (TCL_OK); }
if (strcmp(argv[1], "down-target") == 0) {
downtarget_ = (NsObject*) TclObject::lookup(argv[2]);
return (TCL_OK); }
if (strcmp(argv[1], "up-target") == 0) {
uptarget_ = (NsObject*) TclObject::lookup(argv[2]);
return (TCL_OK);
}
51
if (strcmp(argv[1], "lanrouter") == 0) {
lanrouter_ = (LanRouter*) TclObject::lookup(argv[2]);
return (TCL_OK);
}
}
else if (argc == 2) {
if (strcmp(argv[1], "ifq") == 0) {
tcl.resultf("%s", ifq_->name());
return (TCL_OK); }
if (strcmp(argv[1], "mac") == 0) {
tcl.resultf("%s", mac_->name());
return (TCL_OK); }
if (strcmp(argv[1], "down-target") == 0) {
tcl.resultf("%s", downtarget_->name());
return (TCL_OK); }
if (strcmp(argv[1], "up-target") == 0) {
tcl.resultf("%s", uptarget_->name());
return (TCL_OK); } }
return LinkDelay::command(argc, argv); }
void LL::recv(Packet* p, Handler* /*h*/)
{
hdr_cmn *ch = HDR_CMN(p);
assert(initialized());
}
if(ch->direction() == hdr_cmn::UP) {
//if(mac_->hdr_type(mh) == ETHERTYPE_ARP)
if(ch->ptype_ == PT_ARP)
arptable_->arpinput(p, this);
52
else
uptarget_ ? sendUp(p) : drop(p);
return; }
ch->direction() = hdr_cmn::DOWN;
sendDown(p);
}
void LL::sendDown(Packet* p)
{ hdr_cmn *ch = HDR_CMN(p);
hdr_ip *ih = HDR_IP(p);
nsaddr_t dst = (nsaddr_t)Address::instance().get_nodeaddr(ih->daddr());
//nsaddr_t dst = ih->dst();
hdr_ll *llh = HDR_LL(p);
char *mh = (char*)p->access(hdr_mac::offset_);
if (tx == 0) {
Scheduler& s = Scheduler::instance();
// let mac decide when to take a new packet from the queue.
s.schedule(downtarget_, p, delay_);
}
}
void LL::sendUp(Packet* p)
{
Scheduler& s = Scheduler::instance();
if (hdr_cmn::access(p)->error() > 0)
drop(p);
else
s.schedule(uptarget_, p, delay_);
}
53
node.cc
54
#ifdef DEBUG
printf("N (%.6f): sink node is set to %d, start beaconing \n",
CURRENT_TIME, index);
#endif
return TCL_OK; } }
else if(argc == 3) {
if(strcmp(argv[1], "index") == 0) {
index = atoi(argv[2]);
return TCL_OK; }
else if(strcmp(argv[1], "log-target") == 0 || strcmp(argv[1],
"tracetarget") == 0) {
logtarget = (Trace*) TclObject::lookup(argv[2]);
if(logtarget == 0)
return TCL_ERROR;
return TCL_OK; }
else if(strcmp(argv[1], "drop-target") == 0) {
/* int stat = rqueue.command(argc,argv);
if (stat != TCL_OK)
return stat;
return Agent::command(argc, argv);*/
return TCL_OK; }
else if(strcmp(argv[1], "if-queue") == 0) {
ifqueue = (PriQueue*) TclObject::lookup(argv[2]);
if(ifqueue == 0)
return TCL_ERROR;
return TCL_OK;
}
else if (strcmp(argv[1], "port-dmux") == 0) {
55
dmux_ = (PortClassifier *)TclObject::lookup(argv[2]);
if (dmux_ == 0) {
fprintf (stderr, "%s: %s lookup of %s failed\n",
__FILE__,
argv[1], argv[2]);
return TCL_ERROR; }
return TCL_OK; } }
return Agent::command(argc, argv);}
#ifdef DEBUG
printf("N (%.6f): Routing agent is initialized for node %d \n",
CURRENT_TIME, id);
#endif
index = id;
seqno = 1;
LIST_INIT(&rthead);
posx = 0;
posy = 0;
logtarget = 0;
ifqueue = 0; }
void wfrpRouteCacheTimer::handle(Event*) {
agent->rt_purge();
Scheduler::instance().schedule(this, &intr,
ROUTE_PURGE_FREQUENCY); }
void wfrpBeaconTimer::handle(Event*) {
agent->send_beacon();
Scheduler::instance().schedule(this, &intr,
DEFAULT_BEACON_INTERVAL);
}
56
Void WFRP::send_beacon() {
Packet *p = Packet::alloc();
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_wfrp_beacon *bcn = HDR_WFRP_BEACON(p);
ch->ptype() = PT_WFRP;
ch->size() = IP_HDR_LEN + bcn->size();
ch->addr_type() = NS_AF_NONE;
ch->prev_hop_ = index;
ih->saddr() = index;
ih->daddr() = IP_BROADCAST;
ih->sport() = RT_PORT;
ih->dport() = RT_PORT;
ih->ttl_ = NETWORK_DIAMETER;
RouteCache *rt = rt_lookup(bcn->beacon_src);
if (rt == NULL) {
rt_insert(bcn->beacon_src,bcn->beacon_id, ih->saddr(), bcn-
>beacon_posx, bcn->beacon_posy, bcn->beacon_hops);
ih->saddr() = index;
bcn->beacon_hops +=1; // increase hop count
double delay = 0.1 + Random::uniform();
forward(p, IP_BROADCAST, delay); }
else if (bcn->beacon_id > rt->rt_seqno) {
rt->rt_state = ROUTE_FRESH;
rt->rt_hopcount = bcn->beacon_hops;
rt->rt_expire = CURRENT_TIME + DEFAULT_ROUTE_EXPIRE;
ih->saddr() = index;
bcn->beacon_hops +=1; // increase hop count
double delay = 0.1 + Random::uniform();
57
#ifdef DEBUG
printf("F (%.6f): UPDATE ROUTE, forward beacon by %d \n",
CURRENT_TIME, index);
#endif
forward(p, IP_BROADCAST, delay); }
else if ((bcn->beacon_id == rt->rt_seqno) && (bcn->beacon_hops <
rt->rt_hopcount )) {
rt->rt_seqno = bcn->beacon_id;
rt->rt_hopcount = bcn->beacon_hops;
rt->rt_expire = CURRENT_TIME + DEFAULT_ROUTE_EXPIRE;
} }
void WFRP::rt_insert(nsaddr_t src, u_int32_t id, nsaddr_t nexthop, u_int32_t xpos,
u_int32_t ypos, u_int8_t hopcount) {
RouteCache *rt = new RouteCache(src, id);
rt->rt_nexthop = nexthop;
rt->rt_expire = CURRENT_TIME + DEFAULT_ROUTE_EXPIRE;
LIST_INSERT_HEAD(&rthead, rt, rt_link); }
RouteCache*
WFRP::rt_lookup(nsaddr_t dst) {
RouteCache *r = rthead.lh_first;
for( ; r; r = r->rt_link.le_next) {
if (r->rt_dst == dst)
return r; }
return NULL; }
void WFRP::rt_purge() {
RouteCache *rt= rthead.lh_first;
double now = CURRENT_TIME;
for(; rt; rt = rt->rt_link.le_next) {
if(rt->rt_expire <= now)
58
rt->rt_state = ROUTE_EXPIRED; }}
void WFRP::rt_remove(RouteCache *rt) {
LIST_REMOVE(rt,rt_link);
}
aodv_packet.h
#ifndef __aodv_packet_h__
#include <classifier/classifier-port.h>
#define NETWORK_DIAMETER 64
#define DEFAULT_BEACON_INTERVAL 10 // seconds;
#define DEFAULT_ROUTE_EXPIRE
2*DEFAULT_BEACON_INTERVAL // seconds;
#define ROUTE_PURGE_FREQUENCY 2 // seconds
#define ROUTE_FRESH 0x01
#define ROUTE_EXPIRED 0x02
#define ROUTE_FAILED 0x03
class WFRP;
class wfrpBeaconTimer : public Handler {
public:
wfrpBeaconTimer(WFRP* a) : agent(a) {}
void handle(Event*);
private:
WFRP *agent;
Event intr;
};
class wfrpRouteCacheTimer : public Handler {
public:
59
wfrpRouteCacheTimer(WFRP* a) : agent(a) {}
void handle(Event*);
private:
WFRP *agent;
Event intr; };
class RouteCache {
friend class WFRP;
public:
RouteCache(nsaddr_t bsrc, u_int32_t bid) { rt_dst = bsrc; rt_seqno = bid; }
protected:
LIST_ENTRY(RouteCache) rt_link;
u_int32_t rt_xpos; // x position of destination;
u_int32_t rt_ypos; // y position of destination;
u_int8_t rt_state; // state of the route: FRESH, EXPIRED,
FAILED (BROKEN)
u_int8_t rt_hopcount; // number of hops up to the destination (sink)
double rt_expire; // when route expires };
LIST_HEAD(wfrp_rtcache, RouteCache);
class WFRP : public Agent {
friend class RouteCacheTimer;
public:
WFRP(nsaddr_t id);
void recv(Packet *p, Handler *);
int command(int, const char *const *);
void rt_insert(nsaddr_t src, u_int32_t id, nsaddr_t nexthop,
u_int32_t xpos, u_int32_t ypos, u_int8_t hopcount);
wfrpBeaconTimer bcnTimer;
wfrpRouteCacheTimer rtcTimer;
void send_beacon();
60
void forward(Packet *p, nsaddr_t nexthop, double delay);
void recv_beacon(Packet *p);
void recv_error(Packet *p);
};
node.h
#ifndef __wfrp_packet_h__
#define __wrfp_packet_h__
#define WFRP_BEACON 0x01
#define WFRP_ERROR 0x02
#define HDR_WFRP(p) ((struct hdr_wfrp*)hdr_wfrp::access(p))
#define HDR_WFRP_BEACON(p) ((struct
hdr_wfrp_beacon*)hdr_wfrp::access(p))
#define HDR_WFRP_ERROR(p) ((struct hdr_wfrp_error*)hdr_wfrp::access(p))
struct hdr_wfrp {
u_int8_t pkt_type;
static int offset_;
inline static int& offset() { return offset_;}
inline static hdr_wfrp* access(const Packet *p) {
return (hdr_wfrp*) p->access(offset_);
} };
struct hdr_wfrp_beacon {
u_int8_t pkt_type; // type of packet : Beacon or Error
u_int8_t beacon_hops; // hop count, increadecreases as beacon is
forwarded
u_int32_t beacon_id; // unique identifier for the beacon
nsaddr_t beacon_src; // source address of beacon, this is sink address
u_int32_t beacon_posx; // x position of beacon source, if available
61
u_int32_t beacon_posy; // y position of beacon source, if available
double timestamp; // emission time of beacon message
inline int size() {
int sz = 0;
sz = sizeof(struct hdr_wfrp_beacon);
assert(sz>=0);
return sz;
}};
struct hdr_wfrp_error {
u_int8_t pkt_type; // type of packet : Beacon or Error
u_int8_t reserved; // reserved for future use
nsaddr_t error_src; // error packet source node;
nsaddr_t urch_dst; // unreachable destination
double timestamp; // emission time
inline int size() {
int sz = 0;
sz = sizeof(struct hdr_wfrp_error);
assert(sz>=0);
return sz;
}};
// For size calculation of header-space reservation
union hdr_all_wfrp {
hdr_wfrp wfrp;
hdr_wfrp_beacon beacon;
hdr_wfrp_error error;
};
62
3. AWK Files for calculating the parameters:
63
delay[i] = end_time[i] - start_time[i]
count++ }
else {
delay[i] = -1 } }
for(i=0; i<count; i++) {
if(delay[i] > 0) {
n_to_n_delay = n_to_n_delay + delay[i] } }
n_to_n_delay = n_to_n_delay/count
print "\n"
print "GeneratedPackets = " seqno+1
print "ReceivedPackets = " receivedPackets
print "Packet Delivery Ratio = "receivedPackets/(seqno+1)*100 "%"
print "Total Dropped Packets = " droppedPackets
print "Average End-to-End Delay = " n_to_n_delay * 1000 " ms"
print "\n"
}
64
APPENDIX-2
Fig 7.2:- Parameters generated for tcl code for three nodes
65
Fig 7.3:- Modified AODV Parameters
66
REFRENCES
67