?? example.tcl
字號:
### This simulation is an example of combination of wired and wireless ### topologies.#---------------------------------------------------------------------## Define Options ##---------------------------------------------------------------------#global optset opt(chan) Channel/WirelessChannel; # channel type set opt(prop) Propagation/TwoRayGround; # radio-propagation modelset opt(netif) Phy/WirelessPhy; # network interface type set opt(mac) Mac/802_16BS; # MAC typeset opt(ifq) Queue/DropTail/PriQueue; # Interface queue typeset opt(ll) LL; # Link layer type set opt(ant) Antenna/OmniAntenna; # Antenna typeset opt(x) 250; # X dimension of the topographyset opt(y) 250; # Y dimension ot the topography set opt(ifqlen) 50; # max packet in ifq set opt(tr) out.tr; # trace fileset opt(adhocRouting) NOAH; # non ad hoc routing set opt(stop) 200; # simulation time set opt(n-bs) 1; # number of bs nodesset opt(n-ugs) 1; # number of nodes with ugs connectionsset opt(n-rtps) 1; # number of nodes with rtps connections set opt(n-ertps) 1; # number of nodes with rtps connectionsset opt(n-nrtps) 1; # number of nodes with nrtps connectionsset opt(n-be) 1; # number of nodes with be connectionsset opt(n-nodes) [expr $opt(n-ugs)+$opt(n-rtps)+$opt(n-ertps)+$opt(n-nrtps)+$opt(n-be)]; set base_seed [lindex $argv 0];set BW 40000000; #channel bandwidth#window for the uplink scheduling mechanism #(see Globecom 2007 paper: Uplink Scheduling with Quality of Service in IEEE 802.16 Networks)Mac/802_16BS set window_ 0.05 set param(dir) "."global defaultRNG$defaultRNG seed predef [expr $base_seed*2]Phy/WirelessPhy set bandwidth_ $BW#QoS parameters#UGS set ugs_grant_interval 0.020; # data grants interval (seconds) set ugs_grant_size 66 #rtPSset rtps_grant_interval 0.020; # unicast request grant interval (seconds)set rtps_delay 0.100; # maximum delay request (seconds)set rtps_aggreq_interval 5; # aggregate request interval (in number of requests)set rtps_minBW 200000 ; # minimum bandwith request (bytes) - baseball video#ertPS set ertps_grant_interval 0.020; # data grants interval (seconds) set ertps_grant_size 200; # initial data grant interval (bytes)#nrtPSset nrtps_grant_interval 0.050; # unicast request grant interval (seconds)set nrtps_minBW 200000; # minimum bandwith request (bytes)set nrtps_aggreq_interval 10; # aggregate request interval (in number of requests)#BEset be_grant_interval 2.0; # unicast request grant interval (seconds)set be_aggreq_interval 10; # aggregate request interval (in number of requests)set ns_ [new Simulator]# set up for hierarchical routing$ns_ node-config -addressType hierarchicalAddrParams set domain_num_ 2 ;# number of domains - one for wired and one for wireless lappend cluster_num 1 1 ;# number of clusters in each domain AddrParams set cluster_num_ $cluster_num lappend eilastlevel 1 [expr $opt(n-nodes) + $opt(n-bs)] ;# number of nodes in each cluster AddrParams set nodes_num_ $eilastlevel # set trace filesset tracefd [open "out.tr" w]$ns_ trace-all $tracefd# create topography objectset topo [new Topography]$topo load_flatgrid $opt(x) $opt(y)# create Godcreate-god [expr $opt(n-nodes) + $opt(n-bs)]# create wired nodeset W [$ns_ node 0.0.0]$ns_ node-config -adhocRouting $opt(adhocRouting) \ -llType $opt(ll) \ -macType $opt(mac) \ -ifqType $opt(ifq) \ -ifqLen $opt(ifqlen) \ -antType $opt(ant) \ -propInstance [new $opt(prop)] \ -phyType $opt(netif) \ -channel [new $opt(chan)] \ -topoInstance $topo \ -wiredRouting ON \ -agentTrace ON \ -routerTrace OFF \ -macTrace ONset temp {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} #BS is the cmts nodeset BS [$ns_ node [lindex $temp 0]]$BS random-motion 0 #configure-channel "updatarate ticks-per-minislot maxburst upstream-overhead downdatarate downstream-overhead"$BS configure-channel $BW 8 1500 72 $BW 32#configure-mapparams time-covered map-interval num-contention-slots-permap#num-management-slots-permap bkoff-start bkoff-end proportion map_lookahead$BS configure-mapparams 0.005 0.005 1 1 3 8 0 0 #configure-mgmtparams sync-msg-interval rng-msg-interval ucd-msg-interval$BS configure-mgmtparams 2.0 1.0 3.0 #configure for mobilenodesset opt(mac) Mac/802_16SS$ns_ node-config -wiredRouting OFF \ -macType $opt(mac) #channel configuration for subscriber stations for {set j 0} {$j < $opt(n-nodes)} {incr j} { set node_($j) [ $ns_ node [lindex $temp [expr $j+1]] ] $node_($j) base-station [AddrParams addr2id [$BS node-addr]] # configure-ss priority rng_msg_interval ss_id debug on/off #Note: we will number the SS's from 1 on up ... $node_($j) configure-ss 1 1.0 $j 0 # configure-channel "updatarate ticks maxburst upstream-overhead downdatarate downstream-overhead" $node_($j) configure-channel $BW 8 1500 72 $BW 32}#---------------------------------------------------------------------## Configure the connections ##---------------------------------------------------------------------#set ugs_init 0set ugs_end $opt(n-ugs)#ugs connections configurationfor {set j $ugs_init} {$j < $ugs_end} {incr j} { #configure-upflows node "default schedtype dst-node pkt-type phs-type frag-enable concat-enable concat_thresh piggy # grant-size grant-interval queue_size latency minimum-bandwidth aggregate-request-interval debug rate_control rate" $node_($j) configure-upflows $node_($j) "0 0 $W 29 4 0 0 0 0 $ugs_grant_size $ugs_grant_interval 10000 0 0 0 0 0 0" $node_($j) configure-upflows $node_($j) "1 4 $W 54 4 0 1 1000 1 1500 0 10000 0 0 100 0 0 0" #configure-downflows node "default sched-type src-node pkt-type phs-type grant-size grant-interval #queue_size latency minimum-bandwidth " $node_($j) configure-downflows $node_($j) "1 4 $BS 54 4 0 0 10000 0 0" $node_($j) startsim}set rtps_init $ugs_endset rtps_end [expr $ugs_end+$opt(n-rtps)]#rtPS connections configurationfor {set j $rtps_init} {$j < $rtps_end} {incr j} { #configure-upflows node "default schedtype dst-node pkt-type phs-type frag-enable concat-enable concat_thresh piggy # grant-size grant-interval queue_size latency minimum-bandwidth aggregate-request-interval debug rate_control rate" $node_($j) configure-upflows $node_($j) "0 1 $W 1 4 1 1 20000 0 0 $rtps_grant_interval 10000 $rtps_delay $rtps_minBW $rtps_aggreq_interval 0 0 0" $node_($j) configure-upflows $node_($j) "1 4 $W 54 4 1 1 1000 1 0 0 10000 0 0 100 0 0 0" #configure-downflows node "default sched-type dst-node pkt-type phs-type grant-size grant-interval #queue_size latency minimum-bandwidth " $node_($j) configure-downflows $node_($j) "1 3 $BS 54 4 0 0 10000 0 0" $node_($j) startsim}set ertps_init $rtps_endset ertps_end [expr $rtps_end+$opt(n-ertps)]#ertPS connections configurationfor {set j $ertps_init} {$j < $ertps_end} {incr j} { #configure-upflows node "default schedtype dst-node pkt-type phs-type frag-enable concat-enable concat_thresh piggy # grant-size grant-interval queue_size latency minimum-bandwidth aggregate-request-interval debug rate_control rate" $node_($j) configure-upflows $node_($j) "0 2 $W 63 4 0 1 20000 0 $ertps_grant_size $ertps_grant_interval 10000 0 0 0 0 0 0" $node_($j) configure-upflows $node_($j) "1 4 $W 54 4 1 1 1000 1 0 0 10000 0 0 100 0 0 0" #configure-downflows node "default sched-type dst-node pkt-type phs-type grant-size grant-interval #queue_size latency minimum-bandwidth " $node_($j) configure-downflows $node_($j) "1 3 $BS 54 4 0 0 10000 0 0" $node_($j) startsim}set nrtps_init [expr $ertps_end]set nrtps_end [expr $ertps_end+$opt(n-nrtps)]#nrtPS connections configurationfor {set j $nrtps_init} {$j < $nrtps_end} {incr j} { #configure-upflows node "default schedtype dst-node pkt-type phs-type frag-enable concat-enable concat_thresh piggy # grant-size grant-interval queue_size latency minimum-bandwidth aggregate-request-interval debug rate_control rate" $node_($j) configure-upflows $node_($j) "0 3 $W 0 4 1 1 20000 1 0 $nrtps_grant_interval 10000 0 $nrtps_minBW $nrtps_aggreq_interval 0 0 0" $node_($j) configure-upflows $node_($j) "1 4 $BS 54 4 1 1 1000 1 0 0 10000 0 0 100 0 0 0" #configure-downflows node "default sched-type dst-node pkt-type phs-type grant-size grant-interval #queue_size latency minimum-bandwidth " $node_($j) configure-downflows $node_($j) "1 4 $BS 54 4 0 0 10000 0 0" $node_($j) startsim}set be_init [expr $nrtps_end]set be_end $opt(n-nodes)#BE connections configurationfor {set j $be_init} {$j < $be_end} {incr j} { #configure-upflows node "default schedtype dst-node pkt-type phs-type frag-enable concat-enable concat_thresh piggy # grant-size grant-interval queue_size latency minimum-bandwidth aggregate-request-interval debug rate_control rate" $node_($j) configure-upflows $node_($j) "0 4 $W 0 4 1 1 20000 1 0 $be_grant_interval 10000 0 0 $be_aggreq_interval 0 0 0" $node_($j) configure-upflows $node_($j) "1 4 $BS 54 4 1 1 1000 1 0 0 10000 0 0 100 0 0 0" #configure-downflows node "default sched-type dst-node pkt-type phs-type grant-size grant-interval #queue_size latency minimum-bandwidth " $node_($j) configure-downflows $node_($j) "1 4 $BS 54 4 0 0 10000 0 0" #configure-mapparams cmts-node time-covered map-interval num-contention-slots permap #num-sm-slots permap short-grant-limit long-grant-limit bkoff-start bkoff-end $node_($j) startsim}$BS startsim#create links between wired and BS nodes$ns_ duplex-link $W $BS 100Mb 2ms DropTail#---------------------------------------------------------------------## Configure the traffic flows ##---------------------------------------------------------------------##set up UGS uplink flowsset ugs_ul_sink [new Agent/LossMonitor]$ns_ attach-agent $W $ugs_ul_sinkfor {set j $ugs_init} {$j < $ugs_end} {incr j} { set udp_ul_($j) [new Agent/UDP] $udp_ul_($j) set packetSize_ 66 $udp_ul_($j) set class_ 0 $ns_ attach-agent $node_($j) $udp_ul_($j) $ns_ connect $udp_ul_($j) $ugs_ul_sink set voice_ul_($j) [new Application/Traffic/Exponential] $voice_ul_($j) set packetSize_ 66 #rate -> packets 66 bytes in length are generated at fixed intervals of 20ms $voice_ul_($j) set rate_ 26.4Kb $voice_ul_($j) set burst_time_ 1.2 $voice_ul_($j) set idle_time_ 1.8 $voice_ul_($j) attach-agent $udp_ul_($j) set rng_ul_($j) [new RNG] $rng_ul_($j) seed predef [expr $base_seed+$j] $voice_ul_($j) use-rng $rng_ul_($j)}# random number generatorset gna_ugs_ul [new RNG]$gna_ugs_ul seed predef [expr $base_seed + 1]for {set j $ugs_init} {$j < $ugs_end} {incr j} { set stime [expr 0.1 + [$gna_ugs_ul uniform 0 1]] $ns_ at $stime "$voice_ul_($j) start"}# set up rtPS uplink flowsset rtps_ul_sink [new Agent/LossMonitor]$ns_ attach-agent $W $rtps_ul_sinkset trace_file [new Tracefile]$trace_file filename nsvideo_baseball.datfor {set j $rtps_init} {$j < $rtps_end} {incr j} { set udp_ul_($j) [new Agent/UDP] #$udp_($j) set packetSize_ $packet_size $ns_ attach-agent $node_($j) $udp_ul_($j) $ns_ connect $udp_ul_($j) $rtps_ul_sink set video_ul_($j) [new Application/Traffic/Trace] $video_ul_($j) attach-tracefile $trace_file $video_ul_($j) attach-agent $udp_ul_($j)}# random number generatorset gna_rtps_ul [new RNG]$gna_rtps_ul seed predef [expr $base_seed + 2] for {set j $rtps_init} {$j < $rtps_end} {incr j} { set stime [expr 0.1 + [$gna_rtps_ul uniform 0 1]] $ns_ at $stime "$video_ul_($j) start"}#set up ertPS uplink flowsset ertps_ul_sink [new Agent/LossMonitor]$ns_ attach-agent $W $ertps_ul_sinkfor {set j $ertps_init} {$j < $ertps_end} {incr j} { set udp_ul_($j) [new Agent/UDP] $ns_ attach-agent $node_($j) $udp_ul_($j) $ns_ connect $udp_ul_($j) $ertps_ul_sink set voip_ul_($j) [new Application/Traffic/Exponential] $voip_ul_($j) set packetSize_ 66 #rate -> packets 66 bytes in length are generated at fixed intervals of 20ms $voip_ul_($j) set rate_ 26.4Kb $voip_ul_($j) set burst_time_ 1.2 $voip_ul_($j) set idle_time_ 1.8 $voip_ul_($j) attach-agent $udp_ul_($j) set rng_ul_($j) [new RNG] $rng_ul_($j) seed predef [expr $base_seed+$j] $voip_ul_($j) use-rng $rng_ul_($j)}# random number generatorset gna_ertps_ul [new RNG]$gna_ertps_ul seed predef [expr $base_seed + 3]for {set j $ertps_init} {$j < $ertps_end} {incr j} { set stime [expr 0.1 + [$gna_ertps_ul uniform 0 1]] $ns_ at $stime "$voip_ul_($j) start"}#set up nrtPS uplink flowsset nrtps_ul_sink [new Agent/LossMonitor]$ns_ attach-agent $W $nrtps_ul_sinkfor {set j $nrtps_init} {$j < $nrtps_end} {incr j} { set tcp_ul_($j) [new Agent/TCP] $ns_ attach-agent $node_($j) $tcp_ul_($j) $ns_ connect $tcp_ul_($j) $nrtps_ul_sink set ftp_ul_($j) [new Application/FTP] $ftp_ul_($j) attach-agent $tcp_ul_($j)}# random number generatorset gna_nrtps_ul [new RNG]$gna_nrtps_ul seed predef [expr $base_seed + 4]for {set j $nrtps_init} {$j < $nrtps_end} {incr j} { set stime [expr 0.1 + [$gna_nrtps_ul uniform 0 1]] $ns_ at $stime "$ftp_ul_($j) start"}#set up BE uplink flowsset be_ul_sink [new Agent/LossMonitor]$ns_ attach-agent $W $be_ul_sinkfor {set j $be_init} {$j < $be_end} {incr j} { set be_tcp_ul_($j) [new Agent/TCP] $ns_ attach-agent $node_($j) $be_tcp_ul_($j) $ns_ connect $be_tcp_ul_($j) $be_ul_sink set be_ftp_ul_($j) [new Application/FTP] $be_ftp_ul_($j) attach-agent $be_tcp_ul_($j) }# random number generatorset gna_be_ul [new RNG]$gna_be_ul seed predef [expr $base_seed + 5]for {set j $be_init} {$j < $be_end} {incr j} { set stime [expr 0.1 + [$gna_be_ul uniform 0 1]] $ns_ at $stime "$be_ftp_ul_($j) start"}for {set i 0} {$i < $opt(n-nodes) } {incr i} { $ns_ at $opt(stop).0000010 "$node_($i) reset";}$ns_ at $opt(stop).0000010 "$BS reset"; $ns_ at $opt(stop).0000011 "puts \"NS EXITING...\" ; $ns_ halt"puts "Starting Simulation..."$ns_ run
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -