The document summarizes the use of the NS-2 network simulator to simulate mobile ad hoc network (MANET) routing algorithms. It describes creating scenarios of mobile nodes, generating network traffic between nodes, running simulations of different routing protocols, and analyzing the resulting trace files to calculate throughput. Key aspects covered include the NS-2 architecture, scenario and traffic generation procedures, simulation and analysis procedures, and options configured for the simulations.
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Use of NS-2 to Simulate MANET Routing Algorithms
1. Università degli Studi di Catania
Corso di Laurea Magistrale in Ingegneria Informatica
Use of NS-2 to simulate MANET routing algorithms
Architectures and tecnologies for telecommunications systems
Prof. Eng. Giacomo Morabito
Giancarlo Romeo
O55 000031
2. Ad hoc networks
“A mobile ad hoc network, is a self-configuring infrastructureless network of mobile devices
connected by wireless links”.
Route Discovery
Forward
Route Error
Broken Link
Source node
Destination node
Mobile Ad hoc NETwork
There is no static infrastructure such as base station. If two hosts are not
within radio range, all message communication between them must pass
through one or more intermediate hosts that double as routers.
3. Ad hoc routing protocols
Targets
Minimize number of exchanged messages to St
eve
Simplify processing and routing operations
Keeping updated the network scenario
Prevent loops inside the network
4. Ad hoc routing protocols: pro-active vs. reactive
Pro-active (table-driven)
Maintains fresh lists of destinations and their routes by periodically distributing routing tables
throughout the network. The main disadvantages of such algorithms are:
1. Respective amount of data for maintenance.
2. Slow reaction on restructuring and failures.
Reactive (on-demand)
Finds a route on demand by flooding the network with Route Request packets. The main disadvantages
of such algorithms are:
1. High latency time in route finding.
2. Excessive flooding can lead to network clogging.
5. DSDV (Destination-Sequenced Distance Vector)
DSDV is a table-driven routing scheme for ad hoc mobile networks
based on the Bellman-Ford algorithm.
Advantages
Guarantees for loop free paths (sequence numbers).
Since each node knows the complete topology, a node can immediately find the
best route to a destination.
Disadvantages
Requires a regular update of its routing tables, which uses up battery
power and a small amount of bandwidth even when the network is idle.
(full dumps and smaller incremental updates).
6. AODV (Ad hoc On-Demand Distance Vector)
AODV is a reactive routing protocol, meaning that it establishes a route
to a destination only on-demand.
Advantages
Guarantees for loop free paths (sequence numbers).
Low bandwidth utilization for path keeping.
Disadvantages
The connection setup delay is higher (route discovery).
7. Network Simulator 2 (ns-2)
NS-2 is a discrete event simulator targeted at networking research. Ns
provides substantial support for simulation of TCP, routing, and multicast
protocols over wired and wireless (local and satellite) networks.
Transmission ranges
Mobile node
Timeline
8. Scenarios
Parameters
v
Area v
Free space where mobile nodes move on. v
Nodes v
Number of mobile nodes in the area. Mobile node
v v
y
Speed
Min and max speed of nodes [in m/s]. v v
v
Simulation time
Duration of simulation [in s].
x
util/scenariogen
A program that creates TCL script for modeling mobile scenario.
$ util/scenariogen -v 2 -n $opt(nn) -s 1 -m $opt(minspeed) -M $opt(maxspeed) -t 300 -P 1 -p 2.0
-x $opt(x) -y $opt(y) > scenarios/scenario.tcl
9. Propagation model
Two-ray ground reflection model
direct ray Power received at distance d
Tx
Rx
ht
hr
ground
reflect ray
d
threshold.cc
A C++ program that calculates the thresholds for transmission receipt using the relation between various
physical parameters (distance, effect, propagation model etc.) related to transmissions in ns-2.
Distance in meters
$ ./util/threshold -m TwoRayGround 120
Propagation model
10. CS Threshold and RX Threshold
NS2 mainly uses thresholds to determine whether one frame
Physical transmission modeling
is received correctly by the receiver.
CSThresh_ MAC tags Good frame
corrupted frame
If signal strenght of the frame is less than CSThresh_,
the frame is discarded in PHY module and not will be
visible to MAC layer.
RXThresh_ RxThresh_
CSThresh_
If signal strenght of the frame is stronger than
RXThresh_, the frame is discarded in received
correctly. Otherwise, the frame is tagged as corrupted
and MAC layer will discard it. PHY module discards frame
11. Traffic
Communication model stack
Parameters Tx Rx
Protocol Application FTP FTP
Type of communication protocol. (e.g. TCP)
Nodes Agent TCP TCP Sink
Number of mobile nodes.
Connections create-connection
Number of connections between mobile nodes. MAC / PHY Layer
util/trafficgen.tcl
An OTCL script that creates traffic between nodes in ns-2.
$ util/trafficgen.tcl -nn $opt(nn) -cn $opt(cn) > traffic/traffic.tcl
12. util/trafficgen.tcl
Main Procedures/tcp-connect
while {$ftp_cnt < $opt(cn)} { proc tcp_connect {src dst} {
set src [expr int(rand() * $opt(nn))]
global ftp_cnt opt;
puts "n# Node $src connecting through TCP to Node $dst."
while 1 {
set dst [expr int(rand() * $opt(nn))]
# create TCP Agent and attach it to the source node
if {$src != $dst} {
puts "set tcp_($ftp_cnt) [new Agent/TCP]"
break
puts "$ns_ attach-agent $node_($src) $tcp_($ftp_cnt)"
}
}
puts "$tcp_($ftp_cnt) set window_ $opt(winsize)"
puts "$tcp_($ftp_cnt) set packetSize_ $opt(pktsize)"
Connects source and destination
tcp_connect $src $dst
}
# create TCPSink Agent and attach it to the destination node
puts "set sink_($ftp_cnt) [new Agent/TCPSink]"
puts "$ns_ attach-agent $node_($dst) $sink_($ftp_cnt)"
# create a connection between source and destination
Tx Rx
puts "$ns_ connect $tcp_($ftp_cnt) $sink_($ftp_cnt)"
Application FTP FTP
# create an FTP Application and attach it to the source node
puts "set ftp_($ftp_cnt) [new Application/FTP]"
puts "$ftp_($ftp_cnt) attach-agent $tcp_($ftp_cnt)"
puts "set ftp_($ftp_cnt) [$tcp_($ftp_cnt) attach-source FTP]"
Agent TCP TCP Sink
# starts the FTPs transmission
puts "$ns_ at 0 "$ftp_($ftp_cnt) start""
incr ftp_cnt
create-connection }
13. sim.tcl
Options
set opt(chan) Channel/WirelessChannel
;# channel type
set opt(prop) Propagation/TwoRayGround
;# radio-propagation model Physical configuration
set opt(ant) Antenna/OmniAntenna
;# antenna type
set opt(ll)
LL
;# link layer type
set opt(ifq)
set opt(ifqlen) Queue/DropTail/PriQueue
;# interface queue type
set opt(netif) 50
;# max packet in ifq
set opt(mac) Phy/WirelessPhy
;# network interface type
set opt(rp) Mac/802_11
;# MAC type
set opt(nn) DSDV
;# ad-hoc routing protocol
set opt(pktsize) 300
;# number of mobilenodes
Procedures
proc finish {} {...}
proc getargs {argc argv} {...}
proc usage {} {...}
14. sim.tcl
Main
getargs $argc $argv
set ns_ [new Simulator]
set tracef [open traces/$opt(sim)/[string tolower $opt(rp)]/trace_$opt(par).tr w] Open trace file
$ns_ trace-all $tracef
set topo [new Topography]
$topo load_flatgrid $opt(x) $opt(y)
set god_ [create-god $opt(nn)]
$ns_ node-config -adhocRouting $opt(rp)
-llType $opt(ll) Node configuration
-macType $opt(mac)
-ifqType $opt(ifq)
-ifqLen $opt(ifqlen)
-antType $opt(ant)
-propType $opt(prop)
-phyType $opt(netif)
-topoInstance $topo
-channel [new $opt(chan)]
15. sim.tcl
Main
for {set i 0} {$i < $opt(nn)} {incr i} {
set node_($i) [$ns_ node] Initialize nodes
$node_($i) random-motion 0
$ns_ initial_node_pos $node_($i) 10
}
source scenarios/$opt(sim)/scenario_$opt(par).tcl
source traffic/sim$sim/traffic.tcl
Import scenario and traffic files
$ns_ at $opt(duration) "finish"
$ns_ run
16. allsim.tcl
Architecture
allsim.tcl
util sim.tcl traces_analizer.awk
3. run-simulations 4. analize-traces
scenariogen trafficgen.tcl
1. create-scenarios 2. create-traffic
Options
set opt(nn) 100 ;# number of nodes
set opt(x) 500 ;# area width
set opt(y) 500 ;# area length
set opt(cn) 30 ;# number of connections
set opt(nsim) 5 ;# number of simulations
set opt(rp) {AODV DSDV} ;# routing protocols
set opt(minspeed) {0.1 5.1 10.1 15.1 20.1} ;# minimum speed
set opt(maxspeed) {5.0 10.0 15.0 20.0 25.0} ;# maximum speed
22. Simulations/Speed
Nodes: 100 Speed: {5.0 10.0 15.0 20.0 25.0} m/s
Connections: 30
Area: 500m x 500m
CSThreshold: 120m
RXThreshold: 80m
AODV DSDV
792K
800Kb 727K
640Kb high link failures
531K
Throughput
480Kb 406K
353K
321K
320Kb
208K
160Kb 91K 81K
56K
+overhead
0Kb
5 m/s 10 m/s 15 m/s 20 m/s 25 m/s
Nodes speed
23. Simulations/Nodes 10 m/s
Connections: 30 Nodes: {50 75 100 125 150}
Area: 500m x 500m
CSThreshold: 120m
RXThreshold: 80m
AODV DSDV
591K 580K high link failures
600Kb
482K
480Kb 458K
428K
Throughput
360Kb
226K 240K
240Kb 193K
146K
+overhead
134K
120Kb
0Kb
50 75 100 125 150
Number of nodes
24. Simulations/Nodes 20 m/s
Connections: 30 Nodes: {50 75 100 125 150}
Area: 500m x 500m
CSThreshold: 120m
RXThreshold: 80m
AODV DSDV
400Kb 364K 363K 362K
high link failures
332K 329K
320Kb
Throughput
240Kb
160Kb
68K
+overhead
80Kb 51K 47K
59K
35K
0Kb
50 75 100 125 150
Number of nodes
25. Simulations/Nodes 10-20 m/s
Connections: 30 Nodes: {50 75 100 125 150}
Area: 500m x 500m
CSThreshold: 120m
RXThreshold: 80m AODV 10 m/s
DSDV 10 m/s
AODV 20 m/s
DSDV 20 m/s
591K 580K
600Kb high link failures
482K
480Kb 458K
428K
364K 363K 362K
Throughput
360Kb 332K 329K
226K 240K
240Kb 193K
134K 146K
120Kb +overhead
68K 59K
51K 35K 47K
0Kb
50 75 100 125 150
Number of nodes
26. Simulations/Range
Nodes: 100 Range: {130 ... 120 100 80 60 40}
Connections: 30
Area: 500m x 500m
CSThreshold: 120m
RXThreshold: 80m
AODV DSDV
600K high link failures
tx range too small
480K
Throughput
360K
240K
120K +overhead
0K
130 125 124 123 122 121 120 115 110 100 80 60 40
Range
27. DSDV vs. AODV
DSDV AODV
Worst throughput: high Better throughput: low
bandwidth utilization for link bandwidth utilization for link
keeping. keeping.
Low latency: the connection setup High latency: the connection setup
delay is lower (update table). delay is higher (route discovery).