Upload
giancarlo-romeo
View
10.005
Download
5
Tags:
Embed Size (px)
Citation preview
Università degli Studi di CataniaCorso di Laurea Magistrale in Ingegneria Informatica
Giancarlo RomeoO55 000031
Use of NS-2 to simulate MANET routing algorithms
Architectures and tecnologies for telecommunications systemsProf. Eng. Giacomo Morabito
Ad hoc networks
“A mobile ad hoc network, is a self-configuring infrastructureless network of mobile devices connected by wireless links”.
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.
Source node
Destination node
Mobile Ad hoc NETwork
Route DiscoveryForward
Route Error
Broken Link
Ad hoc routing protocols
Minimize number of exchanged messages
Simplify processing and routing operations
Keeping updated the network scenario
Prevent loops inside the network
Targets
to Steve
Ad hoc routing protocols: pro-active vs. reactive
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.
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.
Pro-active (table-driven)
Reactive (on-demand)
DSDV (Destination-Sequenced Distance Vector)
DSDV is a table-driven routing scheme for ad hoc mobile networks based on the Bellman-Ford algorithm.
Guarantees for loop free paths (sequence numbers).
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).
Advantages
Disadvantages
Since each node knows the complete topology, a node can immediately find the best route to a destination.
AODV (Ad hoc On-Demand Distance Vector)
Guarantees for loop free paths (sequence numbers).
AODV is a reactive routing protocol, meaning that it establishes a route to a destination only on-demand.
Low bandwidth utilization for path keeping.
The connection setup delay is higher (route discovery).
Advantages
Disadvantages
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
Scenarios
Nodes
Area
Speed
Simulation time
$ 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
Parameters
Free space where mobile nodes move on.
Number of mobile nodes in the area.
Min and max speed of nodes [in m/s].
Duration of simulation [in s].
util/scenariogen
x
yv
v
v
v
v
v
v
v
v
Mobile node
A program that creates TCL script for modeling mobile scenario.
Propagation model
Two-ray ground reflection model
ht hr
d
direct ray
reflect ray
threshold.cc
$ ./util/threshold -m TwoRayGround 120
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.
Propagation model
Distance in meters
Power received at distance d
ground
Tx
Rx
CS Threshold and RX Threshold
RxThresh_CSThresh_
PHY module discards frame
Physical transmission modeling
CSThresh_
RXThresh_
NS2 mainly uses thresholds to determine whether one frame is received correctly by the receiver.
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.
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.
MAC tags corrupted frame
Good frame
Traffic
Nodes
Protocol
Connections
$ util/trafficgen.tcl -nn $opt(nn) -cn $opt(cn) > traffic/traffic.tcl
Type of communication protocol. (e.g. TCP)
Number of mobile nodes.
Number of connections between mobile nodes.
Parameters
util/trafficgen.tcl
FTPFTPApplication
Agent
Tx Rx
create-connection
TCP SinkTCP
Communication model stack
An OTCL script that creates traffic between nodes in ns-2.
MAC / PHY Layer
util/trafficgen.tcl
proc tcp_connect {src dst} { global ftp_cnt opt; puts "\n# Node $src connecting through TCP to Node $dst." # create TCP Agent and attach it to the source node puts "set tcp_($ftp_cnt) \[new Agent/TCP\]" 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)" # 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 puts "\$ns_ connect \$tcp_($ftp_cnt) \$sink_($ftp_cnt)" # 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\]" # starts the FTPs transmission puts "\$ns_ at 0 \"\$ftp_($ftp_cnt) start\"" incr ftp_cnt}
Procedures/tcp-connectwhile {$ftp_cnt < $opt(cn)} { set src [expr int(rand() * $opt(nn))] while 1 { set dst [expr int(rand() * $opt(nn))] if {$src != $dst} { break } } tcp_connect $src $dst}
Main
FTPFTPApplication
Agent
Tx Rx
create-connection
TCP SinkTCP
Connects source and destination
sim.tcl
Options
set opt(chan)set opt(prop)set opt(ant)set opt(ll)set opt(ifq)set opt(ifqlen)set opt(netif)set opt(mac)set opt(rp) set opt(nn)set opt(pktsize)
Channel/WirelessChannel ;# channel typePropagation/TwoRayGround ;# radio-propagation modelAntenna/OmniAntenna ;# antenna typeLL ;# link layer typeQueue/DropTail/PriQueue ;# interface queue type50 ;# max packet in ifqPhy/WirelessPhy ;# network interface typeMac/802_11 ;# MAC typeDSDV ;# ad-hoc routing protocol 300 ;# number of mobilenodes
Procedures
proc finish {} {...}proc getargs {argc argv} {...}proc usage {} {...}
Physical configuration
sim.tclMain
getargs $argc $argvset ns_ [new Simulator]
set tracef [open traces/$opt(sim)/[string tolower $opt(rp)]/trace_$opt(par).tr w]$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) \ -macType $opt(mac) \ -ifqType $opt(ifq) \ -ifqLen $opt(ifqlen) \ -antType $opt(ant) \ -propType $opt(prop) \ -phyType $opt(netif) \ -topoInstance $topo \ -channel [new $opt(chan)]
Node configuration
Open trace file
sim.tclMain
for {set i 0} {$i < $opt(nn)} {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 $ns_ initial_node_pos $node_($i) 10}
source scenarios/$opt(sim)/scenario_$opt(par).tclsource traffic/sim$sim/traffic.tcl
$ns_ at $opt(duration) "finish"$ns_ run
Import scenario and traffic files
Initialize nodes
Optionsset opt(nn)set opt(x)set opt(y)set opt(cn)
set opt(nsim)set opt(rp)
set opt(minspeed)set opt(maxspeed)
10050050030
5{AODV DSDV}
{0.1 5.1 10.1 15.1 20.1}{5.0 10.0 15.0 20.0 25.0}
;# number of nodes;# area width;# area length;# number of connections
;# number of simulations;# routing protocols
;# minimum speed;# maximum speed
allsim.tcl
4. analize-traces3. run-simulations
1. create-scenarios 2. create-traffic
allsim.tcl
sim.tclutil traces_analizer.awk
trafficgen.tclscenariogen
Architecture
Procedures: create-scenarios
proc create-scenarios {} {global opt
file mkdir scenariosfor {set sim 1} {$sim <= $opt(nsim)} {incr sim} {
puts "Creating simulation n.$sim"
file mkdir scenarios/sim$simfor {set j 0} {$j < 5} {incr j} {
puts " Creating scenario (m=[lindex $opt(minspeed) $j] m/s, M=[lindex $opt(maxspeed) $j] m/s)"puts " => Writing \"scenarios/sim$sim/scenario_[expr $j+1].tcl\""
exec util/scenariogen -v 2 -n $opt(nn) -s 1 -m [lindex $opt(minspeed) $j] -M [lindex $opt(maxspeed) $j] \-t 300 -P 1 -p 2.0 -x $opt(x) -y $opt(y) > scenarios/$sim/scenario_[expr $j+1].tcl
} } puts "Scenarios have been successfully created!\n" puts "Press any key to continue..." gets stdin -}
allsim.tcl
Creates scenarios
Number of simulations
Procedures: create-traffic
proc create-traffic {} { global opt file mkdir traffic for {set sim 1} {$sim <= $opt(nsim)} {incr sim} {
puts "Creating simulation n.$sim"
file mkdir traffic/sim$sim puts " Creating traffic (nn=$opt(nn), cn=$opt(cn))"
puts " => writing \"traffic/sim$sim/traffic.tcl\"\n" exec ns util/trafficgen.tcl -nn $opt(nn) -cn $opt(cn) > traffic/sim$sim/traffic.tcl
}
puts "Traffic has been successfully created!" puts "\nPress any key to continue..." gets stdin -}
Creates traffic
allsim.tcl
Number of simulations
allsim.tclProcedures: run-simulations
proc run-simulations {} {global opt
for {set sim 1} {$sim <= $opt(nsim)} {incr sim} {puts "Running simulation n.$sim"
foreach rp $opt(rp) {puts " Simulating $rp algorithm"
for {set j 0} {$j < 5} {incr j} {puts " Running simulation (speed=[lindex $opt(minspeed) $j]-[lindex $opt(maxspeed) $j])"puts " => writing \"traces/sim$sim/$rp/trace_[expr $j+1].tr\""catch {exec ns sim.tcl -nn $opt(nn) -rp $rp -x $opt(x) -y $opt(y) -sim $sim -par [expr $j+1]}
} } } puts "Simulations have been successfully executed!" puts "\nPress any key to continue..." gets stdin -}
Runs simulation on NS2
Number of simulations
Procedures: analize-traces
proc analize-traces {} {global optputs "Analyzing traces"
file mkdir resultsforeach rp $opt(rp) {
puts " Analyzing $rp algorithm"file mkdir results/[string tolower $rp]for {set j 0} {$j < 5} {incr j} {
set resultsf [open results/[string tolower $rp]/results_[expr $j+1].txt w]puts " => writing \"results/[string tolower $rp]/results_[expr $j+1].txt\""
for {set sim 1} {$sim <= $opt(nsim)} {incr sim} {puts $resultsf [exec awk -f util/traces_analizer.awk traces/$sim/[string tolower $rp]/trace_[expr $j+1].tr]
} close $resultsf } } puts "Calculating throughput has been successfully executed!" puts "\nPress any key to continue..." gets stdin -}
allsim.tcl
Filters trace files with awk and computes throughput
Main
while 1 {exec clear >@ stdout
puts "Welcome to NS2 Ad-hoc Network Simulator"puts "-- Speed ------------------------------\n"puts "Simulation info:"puts " Nodes: \t\t $opt(nn)"puts " Grid: \t\t $opt(x) m x $opt(y) m"puts " Connections: \t\t $opt(cn)"puts " Algorithms: \t\t $opt(rp)"
puts "\nCommand menu:"puts " 1. Create scenarios (varying max speed 5-25 m/s)"puts " 2. Create traffic"puts " 3. Run simulation on NS2"puts " 4. Analize traces"puts "\n 0. Exit"puts "\nWhat dou you choose?"gets stdin i
switch $i {1 {create-scenarios}2 {create-traffic}3 {run-simulations}4 {analize-traces}0 {exit 0}
}}
allsim.tcl
Running allsim.tcl script screenshot
$ tclsh allsim.tcl
Usage
Interactive menu
Simulations/Speed
Connections: 30
Nodes: 100
Area: 500m x 500m
Speed: {5.0 10.0 15.0 20.0 25.0} m/s
CSThreshold: 120m
RXThreshold: 80m
0Kb
160Kb
320Kb
480Kb
640Kb
800Kb
5 m/s 10 m/s 15 m/s 20 m/s 25 m/s
727K
208K
91K 81K 56K
792K
531K
406K353K 321K
Thr
ough
put
Nodes speed
AODV DSDV
+overhead
high link failures
Simulations/Nodes
Connections: 30
Area: 500m x 500m
Nodes: {50 75 100 125 150}
CSThreshold: 120m
RXThreshold: 80m
10 m/s
0Kb
120Kb
240Kb
360Kb
480Kb
600Kb
50 75 100 125 150
226K 240K
134K
193K146K
591K 580K
428K482K
458K
Thr
ough
put
Number of nodes
AODV DSDV
+overhead
high link failures
Simulations/Nodes
Connections: 30
Area: 500m x 500m
Nodes: {50 75 100 125 150}
CSThreshold: 120m
RXThreshold: 80m
20 m/s
0Kb
80Kb
160Kb
240Kb
320Kb
400Kb
50 75 100 125 150
51K35K
68K47K 59K
364K 363K 362K332K 329K
Thr
ough
put
Number of nodes
AODV DSDV
+overhead
high link failures
Simulations/Nodes
Connections: 30
Area: 500m x 500m
Nodes: {50 75 100 125 150}
CSThreshold: 120m
RXThreshold: 80m
10-20 m/s
0Kb
120Kb
240Kb
360Kb
480Kb
600Kb
50 75 100 125 150
226K 240K
134K
193K146K
591K 580K
428K482K
458K
51K 35K68K 47K 59K
364K 363K 362K332K 329K
Thr
ough
put
Number of nodes
AODV 10 m/sDSDV 10 m/sAODV 20 m/sDSDV 20 m/s
+overhead
high link failures
Simulations/Range
Connections: 30
Nodes: 100
Area: 500m x 500m
CSThreshold: 120m
RXThreshold: 80m
0K
120K
240K
360K
480K
600K
130 125 124 123 122 121 120 115 110 100 80 60 40
Thr
ough
put
Range
AODV DSDV
Range: {130 ... 120 100 80 60 40}
+overhead
high link failures
tx range too small
DSDV vs. AODV
Better throughput: low bandwidth utilization for link
keeping.
High latency: the connection setup delay is higher (route discovery).
Worst throughput: high bandwidth utilization for link
keeping.
Low latency: the connection setup delay is lower (update table).
DSDV AODV