NS2 Wireless
description
Transcript of NS2 Wireless
NS2 - Wireless Network
Ming-Feng Yang
2
Outline
Basic wireless model Extensions wireless model Example - Ad hoc network Example – WLAN Example – Mobile IP
3
Basic wireless model
Creating wireless topologyset topo [new Topography]
$topo load_flatgrid $opt(x) $opt(y)
# where opt(x) and opt(y) are the boundaries used in simulation
4
Basic wireless model
Configure the node$ns_ node-config -adhocRouting DSDV or DSR or TORA or AODV \
-topoInstance $topo \-addressType flat or hierarchical or expanded\-wiredRouting ON \-mobileIP ON \-llType LL \-macType Mac/802_11 \-antType Antenna/OmniAntenna \-propType Propagation/TwoRayGround \-phyType Phy/WirelessPhy \-channelType Channel/WirelessChannel \-ifqType Queue/DropTail/PriQueue \-ifqLen <integer> \-agentTrace ON or OFF \-routerTrace ON or OFF \-macTrace ON or OFF \-movementTrace ON or OFF
MobileIPWired-cum-wireless
5
Basic wireless model
Node movement$node set X_ <x1>
$node set Y_ <y1>
$node set Z_ <z1>
# Start-position
$ns at $time $node setdest <x2> <y2> <speed>
# Future destinations
6
Basic wireless model
New traces format$ns use-newtrace
s -t 0.029290548 -Hs 1 -Hd -1 -Ni 1 -Nx 390.00 -Ny 385.00 -Nz 0.00
-Ne -1.000000 -Nl RTR -Nw --- -Ma 0 -Md 0 -Ms 0 -Mt 0 -Is 1.255
-Id -1.255 -It message -Il 32 -If 0 -Ii 0 -Iv 32
event s,r,d,f
time
id for next hop
next hopdestination
node id
node’s x-coordinate
node’s z-coordinate
node’s y-coordinate
nodeenergy level
trace level
reason for this event
duration
dest’s ethernet addr
source’s ethernet addr
ethernet type
source’s addr.port
dest’s addr.port
packet type
packet size
flow id
unique id
ttl value -H: next hop info
-N: node info-M: MAC level info-I: IP level info
7
Basic wireless model
Movement scenario generatorcd ns-allinone-2.27/ns-2.27/indep-utils/cmu-scen-gen/setdest
./setdest -n 3 -p 2.0 -s 20.0 -t 300 -x 600 -y 600 > pattern-fileNum-of-nodes Pause-time Max-speed Sim-time Topo-boundary
source pattern-file
set god_ [God instance]$ns_ at 50.000000000000 "$node_(2) setdest 369.463244915743 170.519203111152 3.371785899154”$ns_ at 51.000000000000 "$node_(1) setdest 221.826585497093 80.855495003839 14.909259208114”$ns_ at 33.000000000000 "$node_(0) setdest 89.663708107313 283.494644426442 19.153832288917”$god_ set-dist 1 2 2$god_ set-dist 0 2 3$god_ set-dist 0 1 1$node_(2) set Z_ 0.000000000000$node_(2) set Y_ 199.373306816804$node_(2) set X_ 591.256560093833$node_(1) set Z_ 0.000000000000$node_(1) set Y_ 345.357731779204$node_(1) set X_ 257.046298323157$node_(0) set Z_ 0.000000000000$node_(0) set Y_ 239.438009831261$node_(0) set X_ 83.364418416244 :
8
Basic wireless model
Traffic scenario generatorns cbrgen.tcl -type tcp -nn 25 -seed 0.0 -mc 8 > pattern-file
ns cbrgen.tcl -type cbr -nn 10 -seed 1.0 -mc 8 -rate 4.0 > pattern-fileCBR-or-TCP Num-of-nodes Random-seed Max-connection CBR-rate
source pattern-file
# nodes: 10, max conn: 8, send rate: 0.25, seed: 1.0# 1 connecting to 2 at time 2.5568388786897245set udp_(0) [new Agent/UDP]$ns_ attach-agent $node_(1) $udp_(0)set null_(0) [new Agent/Null]$ns_ attach-agent $node_(2) $null_(0)set cbr_(0) [new Application/Traffic/CBR]$cbr_(0) set packetSize_ 512$cbr_(0) set interval_ 0.25$cbr_(0) set random_ 1$cbr_(0) set maxpkts_ 10000$cbr_(0) attach-agent $udp_(0)$ns_ connect $udp_(0) $null_(0)$ns_ at 2.5568388786897245 "$cbr_(0) start“ :
9
Extensions wireless model
wired-cum-wireless$ns_ node-config -addressType hierarchicalAddrParams set domain_num_ 2lappend cluster_num 2 1AddrParams set cluster_num_ $cluster_numlappend eilastlevel 1 1 4AddrParams set nodes_num_ $eilastlevel
set temp {0.0.0 0.1.0}for {set i 0} {$i < $num_wired_nodes} {incr i} { set W($i) [$ns_ node [lindex $temp $i]] }
$ns_ node-config -wiredRouting ONset temp {1.0.0 1.0.1 1.0.2 1.0.3}set BS(0) [$ns_ node [lindex $temp 0]]$BS(0) random-motion 0
$ns_ node-config -wiredRouting OFFfor {set j 0} {$j < $opt(nn)} {incr j} { set node_($j) [ $ns_ node [lindex $temp [expr $j+1]] ] $node_($j) base-station [AddrParams addr2id [$BS(0) node-addr]] }
W(0)
W(1)
BS(0)
node_(1)node_(0)
node_(2)
domain 0
domain 1
cluster 0
cluster 1
cluster 0
0,0,0
0,1,0
1,0,0
1,0,1 1,0,2
1,0,3
10
Extensions wireless model
Mobile IP
$ns_ node-config -mobileIP ON
set HA [$ns_ node 1.0.0]set FA [$ns_ node 2.0.0]$HA random-motion 0$FA random-motion 0
set MH [$ns_ node 1.0.1]set node_(0) $MHset HAaddress [AddrParams addr2id [$HA node-addr]][$MH set regagent_] set home_agent_ $HAaddress
W(0)
W(1)
HA
MH
FA
11
Example - Ad hoc network
Traffic: node(0) to node(1)
12
Example - Ad hoc network
Traffic: node(0) to node(1)
13
Example - Ad hoc network
Traffic: node(0) to node(1)
14
Example - Ad hoc networkset val(chan) Channel/WirelessChannel ;# channel typeset val(prop) Propagation/TwoRayGround ;# radio-propagation modelset val(netif) Phy/WirelessPhy ;# network interface typeset val(mac) Mac/802_11 ;# MAC typeset val(ifq) Queue/DropTail/PriQueue ;# interface queue typeset val(ll) LL ;# link layer typeset val(ant) Antenna/OmniAntenna ;# antenna modelset val(ifqlen) 50 ;# max packet in ifqset val(nn) 3 ;# number of nodesset val(rp) DSDV ;# routing protocolset val(x) 500 ;# X dimension of topographyset val(y) 400 ;# Y dimension of topography set val(stop) 150 ;# time of simulation end# Define optionsset ns [new Simulator]set tracefd [open out.tr w]set namtrace [open out.nam w] $ns trace-all $tracefd$ns namtrace-all-wireless $namtrace $val(x) $val(y)
15
Example - Ad hoc networkset topo [new Topography]$topo load_flatgrid $val(x) $val(y)# Create a topology object that keeps track of movements of nodes within the topological boundarycreate-god $val(nn)# God object is used to store global information about the state of the environment, network or nodes$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) \-channelType $val(chan) \-topoInstance $topo \-agentTrace ON \-routerTrace ON \-macTrace OFF \-movementTrace ON
# Configure the nodes
16
Example - Ad hoc networkfor {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns node]$node_($i) random-motion 0 ;# disable random motion
}# Create the specified number of nodes [$val(nn)] and "attach" them to the channel$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# Provide initial location of nodes$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"$ns at 30.0 "$node_(1) setdest 45.0 285.0 5.0"$ns at 100.0 "$node_(0) setdest 480.0 300.0 5.0" # Generation of movements
17
Example - Ad hoc networkset tcp [new Agent/TCP]set sink [new Agent/TCPSink]$ns attach-agent $node_(0) $tcp$ns attach-agent $node_(1) $sink$ns connect $tcp $sinkset ftp [new Application/FTP]$ftp attach-agent $tcp$ns at 10.0 "$ftp start" # Set up a TCP connection between node_(0) and node_(1)for {set i 0} {$i < $val(nn)} { incr i } {
$ns initial_node_pos $node_($i) 40}# Define node initial position in NAM, 40 defines the node size for NAMfor {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "$node_($i) reset";}# Telling nodes when the simulation ends
18
Example - Ad hoc network$ns at $val(stop) "$ns nam-end-wireless $val(stop)"$ns at $val(stop) "stop"proc stop {} {
global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam out.nam & exit 0}# ending nam and the simulation $ns run
19
Example - WLAN
Traffic: node(3) to node(0), node(1) to node(5),
20
Example - WLAN
Traffic: node(3) to node(0), node(1) to node(5),
21
Example - WLAN
Traffic: node(3) to node(0), node(1) to node(5),
22
Example - WLAN
Traffic: node(3) to node(0), node(1) to node(5),
23
Example - WLANset opt(chan) Channel/WirelessChannel ;# channel typeset opt(prop) Propagation/TwoRayGround ;# radio-propagation modelset opt(netif) Phy/WirelessPhy ;# network interface typeset opt(mac) Mac/802_11 ;# MAC typeset opt(ifq) Queue/DropTail/PriQueue ;# interface queue typeset opt(ll) LL ;# link layer typeset opt(ant) Antenna/OmniAntenna ;# antenna modelset opt(ifqlen) 50 ;# max packet in ifqset opt(nn) 3 ;# number of mobilenodesset opt(rp) DSDV ;# routing protocolset opt(x) 300 ;# x coordinate of topologyset opt(y) 300 ;# y coordinate of topologyset opt(stop) 30 ;# time to stop simulationset opt(ftp1-start) 5.0set opt(ftp2-start) 5.0set num_wired_nodes 2set num_bs_nodes 1# Define options
24
Example - WLANset ns [new Simulator]set tracefd [open out.tr w]set namtrace [open out.nam w]$ns trace-all $tracefd$ns namtrace-all-wireless $namtrace $opt(x) $opt(y)
$ns node-config -addressType hierarchicalAddrParams set domain_num_ 2 ;# number of domainslappend cluster_num 2 1 ;# number of clusters in each domainAddrParams set cluster_num_ $cluster_numlappend eilastlevel 1 1 4 ;# number of nodes in each cluster of each domainAddrParams set nodes_num_ $eilastlevel # set up for hierarchical routingset topo [new Topography]$topo load_flatgrid $opt(x) $opt(y)# Create a topology object that keeps track of movements of nodes within the topological boundarycreate-god [expr $opt(nn) + $num_bs_nodes]# God object is used to store global information about the state of the environment, network or nodes
25
Example - WLANset temp {0.0.0 0.1.0} ;# hierarchical addresses for wired domainfor {set i 0} {$i < $num_wired_nodes} {incr i} { set W($i) [$ns node [lindex $temp $i]] }#Create wired nodes$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) \ -channelType $opt(chan) \
-topoInstance $topo \ -wiredRouting ON \
-agentTrace ON \ -routerTrace OFF \ -macTrace OFF # Configure for base-station node
26
Example - WLANset temp {1.0.0 1.0.1 1.0.2 1.0.3} ;# hierarchical addresses to be used for wireless domainset BS(0) [$ns node [lindex $temp 0]]$BS(0) random-motion 0 ;# disable random motion#create base-station node$BS(0) set X_ 150.0$BS(0) set Y_ 250.0$BS(0) set Z_ 0.0# provide some co-ord (fixed) to base-station node$ns node-config -wiredRouting OFFfor {set j 0} {$j < $opt(nn)} {incr j} {
set node_($j) [ $ns node [lindex $temp [expr $j+1]] ]$node_($j) base-station [AddrParams addr2id [$BS(0) node-addr]]
}# create mobilenodes in the same domain as BS(0) and configure for mobilenodes$ns duplex-link $W(0) $W(1) 5Mb 2ms DropTail$ns duplex-link $W(1) $BS(0) 5Mb 2ms DropTail#create links between wired and BS nodes$ns duplex-link-op $W(0) $W(1) orient down$ns duplex-link-op $W(1) $BS(0) orient left-down
27
Example - WLANset tcp1 [new Agent/TCP]set sink1 [new Agent/TCPSink]$ns attach-agent $node_(0) $tcp1$ns attach-agent $W(0) $sink1$ns connect $tcp1 $sink1$tcp1 set fid_ 1set ftp1 [new Application/FTP]$ftp1 attach-agent $tcp1$ns at $opt(ftp1-start) "$ftp1 start"# setup first TCP connectionset tcp2 [new Agent/TCP]$tcp2 set class_ 2set sink2 [new Agent/TCPSink]$ns attach-agent $W(1) $tcp2$ns attach-agent $node_(2) $sink2$ns connect $tcp2 $sink2$tcp2 set fid_ 2set ftp2 [new Application/FTP]$ftp2 attach-agent $tcp2$ns at $opt(ftp2-start) "$ftp2 start"# setup second TCP connection
28
Example - WLAN$node_(0) set X_ 120.0 $node_(0) set Y_ 220.0$node_(0) set Z_ 0.0$node_(1) set X_ 250.0$node_(1) set Y_ 250.0$node_(1) set Z_ 0.0$node_(2) set X_ 20.0$node_(2) set Y_ 20.0$node_(2) set Z_ 0.0# Provide initial location of nodes$ns at 10.0 "$node_(0) setdest 290.0 10.0 30.0"$ns at 15.0 "$node_(1) setdest 50.0 100.0 20.0"$ns at 5.0 "$node_(2) setdest 170.0 240.0 30.0"# Generation of movements
29
Example - WLANfor {set i } {$i < $opt(nn) } {incr i} { $ns at $opt(stop) "$node_($i) reset";}$ns at $opt(stop) "$BS(0) reset";# Tell all nodes when the simulation ends$ns at $opt(stop) "$ns nam-end-wireless $opt(stop)"$ns at $opt(stop) "stop"proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam out.nam & exit 0}# ending nam and the simulation $ns run
30
Example – Mobile IP
Traffic: node(0) to node(4)
31
Example – Mobile IP
Traffic: node(0) to node(4)
32
Example – Mobile IP
Traffic: node(0) to node(4)
33
Example – Mobile IP
Traffic: node(0) to node(4) Traffic: node(0) to node(4)
34
Example – Mobile IP
Traffic: node(0) to node(4)
35
Example – Mobile IPset opt(chan)Channel/WirelessChannel ;# channel typeset opt(prop) Propagation/TwoRayGround ;# radio-propagation modelset opt(netif) Phy/WirelessPhy ;# network interface typeset opt(mac) Mac/802_11 ;# MAC typeset opt(ifq) Queue/DropTail/PriQueue ;# interface queue typeset opt(ll) LL ;# link layer typeset opt(ant) Antenna/OmniAntenna ;# antenna modelset opt(ifqlen) 50 ;# max packet in ifqset opt(nn) 1 ;# number of mobilenodesset opt(rp) DSDV ;# routing protocolset opt(x) 500.0 ;# x coordinate of topologyset opt(y) 500.0 ;# y coordinate of topologyset opt(stop) 50.0 ;# time to stop simulationset opt(ftp1-start) 0.0set num_wired_nodes 2set num_bs_nodes 2# Define options
36
Example – Mobile IPset ns [new Simulator]set tracefd [open out.tr w]set namtrace [open out.nam w]$ns trace-all $tracefd$ns namtrace-all-wireless $namtrace $opt(x) $opt(y)$ns color 1 Red
$ns node-config -addressType hierarchicalAddrParams set domain_num_ 3 ;# number of domainslappend cluster_num 2 1 1 ;# number of clusters in each domainAddrParams set cluster_num_ $cluster_numlappend eilastlevel 1 1 2 1 ;# number of nodes in each cluster of each domai
nAddrParams set nodes_num_ $eilastlevel # set up for hierarchical routingset topo [new Topography]$topo load_flatgrid $opt(x) $opt(y)# Create a topology object that keeps track of movements of nodes within the topological boundary
37
Example – Mobile IPcreate-god [expr $opt(nn) + $num_bs_nodes]# God object is used to store global information about the state of the environment, network or nodesset temp {0.0.0 0.1.0} ;# hierarchical addresses for wired domainfor {set i 0} {$i < $num_wired_nodes} {incr i} { set W($i) [$ns node [lindex $temp $i]] }#Create wired nodes$ns node-config -mobileIP ON \
-adhocRouting $opt(rp) \ -llType $opt(ll) \ -macType $opt(mac) \ -ifqType $opt(ifq) \ -ifqLen $opt(ifqlen) \ -antType $opt(ant) \ -propType $opt(prop) \ -phyType $opt(netif) \ -channelType $opt(chan) \
-topoInstance $topo \ -wiredRouting ON \
-agentTrace ON \ -routerTrace OFF \ -macTrace OFF # Configure for ForeignAgent and HomeAgent nodes
38
Example – Mobile IPset HA_ [$ns node 1.0.0]set FA_ [$ns node 2.0.0]$HA_ random-motion 0$FA_ random-motion 0# Create HA and FA$HA_ set X_ 100.0$HA_ set Y_ 200.0$HA_ set Z_ 0.0$FA_ set X_ 400.0$FA_ set Y_ 200.0$FA_ set Z_ 0.0# Position (fixed) for base-station nodes (HA & FA).$ns node-config -wiredRouting OFFset MH_ [$ns node 1.0.1]set HAaddress [AddrParams addr2id [$HA_ node-addr]][$MH_ set regagent_] set home_agent_ $HAaddress# note address of MH indicates its in the same domain as HA.$ns duplex-link $W(0) $W(1) 5Mb 2ms DropTail$ns duplex-link $W(1) $HA_ 5Mb 2ms DropTail$ns duplex-link $W(1) $FA_ 5Mb 2ms DropTail# create links between wired and BaseStation nodes
39
Example – Mobile IPset tcp1 [new Agent/TCP]set sink1 [new Agent/TCPSink]$ns attach-agent $W(0) $tcp1$ns attach-agent $MH_ $sink1$ns connect $tcp1 $sink1$tcp1 set fid_ 1set ftp1 [new Application/FTP]$ftp1 attach-agent $tcp1$ns at $opt(ftp1-start) "$ftp1 start"# setup TCP connections between a wired node and the MobileHost$MH_ set X_ 100.0$MH_ set Y_ 170.0$MH_ set Z_ 0.0# Provide initial location of MH$ns at 5.0 "$MH_ setdest 400.0 170.0 20.0"# MH starts to move towards FA$ns at 25.0 "$MH_ setdest 100.0 170.0 20.0"# goes back to HA$ns initial_node_pos $MH_ 10# Define initial node position in NAM
40
Example – Mobile IP$ns at $opt(stop) "$MH_ reset";$ns at $opt(stop) "$HA_ reset";$ns at $opt(stop) "$FA_ reset";# Tell all nodes when the simulation ends$ns at $opt(stop) "$ns nam-end-wireless $opt(stop)"$ns at $opt(stop) "stop"proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam out.nam & exit 0}# ending nam and the simulation $ns run