1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
| #############################################
# Star over 802.15.4 #
# (beacon enabled) #
# Copyright (c) 2003 Samsung/CUNY #
# - - - - - - - - - - - - - - - - - - - - - #
# Prepared by Jianliang Zheng #
# (zheng@ee.ccny.cuny.edu) #
#############################################
# ======================================================================
# Define options
# ======================================================================
set val(chan) Channel/WirelessChannel ;# Channel Type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy/802_15_4
set val(mac) Mac/802_15_4
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) 150 ;# max packet in ifq
set val(nn) 7 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 50
set val(y) 50
set val(nam) wpan_demo2.nam
set val(traffic) cbr ;# cbr/poisson/ftp
set BO 3 ;# Non_Simulation time
set SO 3 ;# Non_Simulation time
#read command line arguments
proc getCmdArgu {argc argv} {
global val
for {set i 0} {$i < $argc} {incr i} {
set arg [lindex $argv $i]
if {[string range $arg 0 0] != "-"} continue
set name [string range $arg 1 end]
set val($name) [lindex $argv [expr $i+1]]
}
}
getCmdArgu $argc $argv
set appTime1 7.0 ;# in seconds
set appTime2 7.1 ;# in seconds
set appTime3 7.2 ;# in seconds
set appTime4 7.3 ;# in seconds
set appTime5 7.4 ;# in seconds
set appTime6 7.5 ;# in seconds
set stopTime 100 ;# in seconds
# Initialize Global Variables
set ns_ [new Simulator]
set tracefd [open ./wpan_demo2.tr w]
$ns_ trace-all $tracefd
if { "$val(nam)" == "wpan_demo2.nam" } {
set namtrace [open ./$val(nam) w]
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
}
$ns_ puts-nam-traceall {# nam4wpan #} ;# inform nam that this is a trace file for wpan (special handling needed)
Mac/802_15_4 wpanCmd verbose on
Mac/802_15_4 wpanNam namStatus on ;# default = off (should be turned on before other 'wpanNam' commands can work)
#Mac/802_15_4 wpanNam ColFlashClr gold ;# default = gold
# For model 'TwoRayGround'
set dist(5m) 7.69113e-06
set dist(9m) 2.37381e-06
set dist(10m) 1.92278e-06
set dist(11m) 1.58908e-06
set dist(12m) 1.33527e-06
set dist(13m) 1.13774e-06
set dist(14m) 9.81011e-07
set dist(15m) 8.54570e-07
set dist(16m) 7.51087e-07
set dist(20m) 4.80696e-07
set dist(25m) 3.07645e-07
set dist(30m) 2.13643e-07
set dist(35m) 1.56962e-07
set dist(40m) 1.20174e-07
Phy/WirelessPhy set CSThresh_ $dist(15m)
Phy/WirelessPhy set RXThresh_ $dist(15m)
# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
# Create God
set god_ [create-god $val(nn)]
set chan_1_ [new $val(chan)]
# configure node
$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) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON \
#-energyModel "EnergyModel" \
#-initialEnergy 1 \
#-rxPower 0.3 \
#-txPower 0.3 \
-channel $chan_1_
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0 ;# disable random motion
}
source ./wpan_demo2.scn
$ns_ at 0.0 "$node_(0) NodeLabel PAN Coor"
$ns_ at 0.0 "$node_(0) sscs startPANCoord 1" ;# startPANCoord <txBeacon=1> <BO=3> <SO=3>
# Start node 1 as a wpan device, beacon enabled
$ns_ at 0.5 "$node_(1) sscs startDevice 1 1 1 $BO $SO" ;# startDevice <isFFD=1> <assoPermit=1> <txBeacon=0> <BO=3> <SO=3>
$ns_ at 1.5 "$node_(2) sscs startDevice 1 0"
$ns_ at 2.5 "$node_(3) sscs startDevice 1 0"
$ns_ at 3.5 "$node_(4) sscs startDevice 1 0"
$ns_ at 4.5 "$node_(5) sscs startDevice 1 0"
$ns_ at 5.5 "$node_(6) sscs startDevice 1 0"
Mac/802_15_4 wpanNam PlaybackRate 3ms
$ns_ at $appTime1 "puts \"\nTransmitting data ...\n\""
# Setup traffic flow between nodes
proc cbrtraffic { src dst interval starttime } {
global ns_ node_
set udp_($src) [new Agent/UDP]
eval $ns_ attach-agent \$node_($src) \$udp_($src)
set null_($dst) [new Agent/Null]
eval $ns_ attach-agent \$node_($dst) \$null_($dst)
set cbr_($src) [new Application/Traffic/CBR]
eval \$cbr_($src) set packetSize_ 70
eval \$cbr_($src) set interval_ $interval
eval \$cbr_($src) set random_ 0
#eval \$cbr_($src) set maxpkts_ 10000
eval \$cbr_($src) attach-agent \$udp_($src)
eval $ns_ connect \$udp_($src) \$null_($dst)
$ns_ at $starttime "$cbr_($src) start"
}
if { ("$val(traffic)" == "cbr") } {
puts "\nTraffic: $val(traffic)"
#Mac/802_15_4 wpanCmd ack4data on
puts [format "Acknowledgement for data: %s" [Mac/802_15_4 wpanCmd ack4data]]
$ns_ at $appTime1 "Mac/802_15_4 wpanNam PlaybackRate 0.5ms"
$ns_ at [expr $appTime1 + 0.5] "Mac/802_15_4 wpanNam PlaybackRate 1.5ms"
$val(traffic)traffic 1 0 0.6 $appTime1
$val(traffic)traffic 3 0 0.6 $appTime3
$val(traffic)traffic 5 0 0.6 $appTime5
$ns_ at $appTime1 "$ns_ trace-annotate \"(at $appTime1) $val(traffic) traffic from node 1 to node 0\""
$ns_ at $appTime3 "$ns_ trace-annotate \"(at $appTime3) $val(traffic) traffic from node 3 to node 0\""
$ns_ at $appTime5 "$ns_ trace-annotate \"(at $appTime5) $val(traffic) traffic from node 5 to node 0\""
Mac/802_15_4 wpanNam FlowClr -p AODV -c tomato
Mac/802_15_4 wpanNam FlowClr -p ARP -c green
Mac/802_15_4 wpanNam FlowClr -p MAC -s 0 -d -1 -c navy
if { "$val(traffic)" == "cbr" } {
set pktType cbr
} else {
set pktType exp
}
Mac/802_15_4 wpanNam FlowClr -p $pktType -s 1 -d 0 -c blue
Mac/802_15_4 wpanNam FlowClr -p $pktType -s 3 -d 0 -c green4
Mac/802_15_4 wpanNam FlowClr -p $pktType -s 5 -d 0 -c cyan4
}
# defines the node size in nam
for {set i 0} {$i < $val(nn)} {incr i} {
$ns_ initial_node_pos $node_($i) 2
}
# Tell nodes when the simulation ends
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $stopTime "$node_($i) reset";
}
$ns_ at $stopTime "stop"
$ns_ at $stopTime "puts \"NS EXITING...\n\""
$ns_ at $stopTime "$ns_ halt"
proc stop {} {
global ns_ tracefd appTime1 val env
$ns_ flush-trace
close $tracefd
set hasDISPLAY 0
foreach index [array names env] {
#puts "$index: $env($index)"
if { ("$index" == "DISPLAY") && ("$env($index)" != "") } {
set hasDISPLAY 1
}
}
if { ("$val(nam)" == "wpan_demo2.nam") && ("$hasDISPLAY" == "1") } {
exec nam wpan_demo2.nam &
}
}
puts "\nStarting Simulation..."
$ns_ run |
Partager