📄 pcftest.tcl
字号:
# Script testing PCF functionality by dugdale# Command line optionsset clo_nodes [lindex $argv 0]set clo_prionodes [lindex $argv 1]set clo_cbr_interval [lindex $argv 2]set clo_cbr_packetsize [lindex $argv 3]set clo_outfile [lindex $argv 4]set clo_superframe [lindex $argv 5]# Optionsset 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) [expr $clo_nodes + 1] ;# number of mobilenodesset opt(adhocRouting) DSDV ;# routing protocolset opt(cp) "" ;# connection pattern fileset opt(sc) "" ;# node movement file. set opt(x) 500 ;# x coordinate of topologyset opt(y) 500 ;# y coordinate of topologyset opt(stop) 20 ;# time to stop simulationset num_wired_nodes 1set num_bs_nodes 1set num_cbr $clo_nodes# Seed the random generatorns-random 54.33# create simulator instanceset ns_ [new Simulator]# set up for hierarchical routing$ns_ node-config -addressType hierarchicalAddrParams set domain_num_ 2 ;# number of domainslappend cluster_num 1 1 ;# number of clusters in each domainAddrParams set cluster_num_ $cluster_numlappend eilastlevel $opt(nn) 1 ;# number of nodes in each cluster AddrParams set nodes_num_ $eilastlevel ;# of each domain# Use the new trace file format$ns_ use-newtrace# More trace stuffset tracefd [open "| gzip >$clo_outfile" w]#set namtrace [open dug2.nam w]#set tracefd [open "/dev/null" w]$ns_ trace-all $tracefd# Create topography objectset topo [new Topography]# define topology$topo load_flatgrid $opt(x) $opt(y)create-god $opt(nn)# Create the wired nodeset W(0) [$ns_ node 0.0.0]# configure for base-station node$ns_ node-config -adhocRouting $opt(adhocRouting) \ -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 OFF \ -routerTrace OFF \ -macTrace ON# Addresses for the wireless domain...set waddr {1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.47 1.0.48 1.0.49 1.0.50 1.0.51 1.0.52}# Create the base stationset BS(0) [$ns_ node [lindex $waddr 0]]$BS(0) random-motion 0# Coordinates for the base station$BS(0) set X_ 250.0$BS(0) set Y_ 250.0$BS(0) set Z_ 0.0# Create wireless nodes$ns_ node-config -wiredRouting OFFfor {set j 0} {$j < $opt(nn)} {incr j} { set node_($j) [ $ns_ node [lindex $waddr \ [expr $j+1]] ] $node_($j) base-station [AddrParams addr2id \ [$BS(0) node-addr]]}# This turns $BS(0) into a Point Coordinator[$BS(0) set mac_(0)] make-pc# And here we set how long the time between beacons should be[$BS(0) set mac_(0)] beaconperiod $clo_superframefor {set k 0} {$k<$clo_prionodes} {incr k} { # Adding stations to the polling list of the PC [$BS(0) set mac_(0)] addSTA [expr $k+1] 1 0}#[$node_(2) set mac_(0)] set weight_ 1.4# Create a link between the wired node and the base station$ns_ duplex-link $W(0) $BS(0) 10Mb 2ms DropTail$ns_ duplex-link-op $W(0) $BS(0) orient down# CBR flowsfor {set i 0} {$i < $num_cbr} {incr i} { set udp_($i) [new Agent/UDP] $ns_ attach-agent $node_([expr $i]) $udp_($i) set cbr_($i) [new Application/Traffic/CBR] $cbr_($i) attach-agent $udp_($i) $cbr_($i) set packetSize_ $clo_cbr_packetsize $udp_($i) set packetSize_ 2500 $cbr_($i) set interval_ $clo_cbr_interval set null_($i) [new Agent/Null] $ns_ attach-agent $W(0) $null_($i) $ns_ connect $udp_($i) $null_($i) $ns_ at [expr 7.0+0.0210003*$i] "$cbr_($i) start"}# Initial node positionsfor {set i 0} {$i < $num_cbr} {incr i} { $ns_ initial_node_pos $node_($i) [expr 20 + 0.12*$i] $node_($i) set X_ [expr 100 - 4*$i] $node_($i) set Y_ [expr 100 + 4*$i]}$W(0) set X_ 50$W(0) set Y_ 70# Tell all nodes when the simulation endsfor {set i 0} {$i < $opt(nn) } {incr i} { $ns_ at $opt(stop).0 "$node_($i) reset";}$ns_ at $opt(stop).0 "$BS(0) reset";$ns_ at $opt(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"$ns_ at $opt(stop).0001 "stop"for {set i 0} {$i<[expr $opt(nn)-1]} {incr i} {$ns_ at $opt(stop).0 "$node_($i) reset";}proc stop {} { global ns_ tracefd namtrace $ns_ flush-trace close $tracefd# close $namtrace}puts "Starting Simulation..."$ns_ run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -