⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 802_11.tcl

📁 在网络仿真模拟工具下实现支持QoS的MAC层EDCF协议
💻 TCL
字号:
# globals and flagsset ns [new Simulator]#number of nodesset num_wired_nodes  1set num_mobile_nodes 1set num_bs_nodes     1 ;# number of base stationsset num_nodes [expr $num_wired_nodes + $num_mobile_nodes + $num_bs_nodes]set bs_id $num_wired_nodes# Parameter for wireless nodesset 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(ifqlen)         50set opt(ll)             LL                         ;# link layer typeset opt(ant)            Antenna/OmniAntenna        ;# antenna modelset opt(ifqlen)         50                        ;# max packet in ifqset opt(adhocRouting)   NOAH                       ;# routing protocolset opt(x)		500      	;# X dimension of the topographyset opt(y)		500		;# Y dimension of the topographyMac/802_11e set dataRate_  11MbMac/802_11e set basicRate_ 1Mb #set up for hierarchical routing#(needed for routing over a basestation)$ns node-config -addressType hierarchicalAddrParams set domain_num_ 2          ;# domain numberlappend cluster_num 1 1               ;# cluster number for each domain AddrParams set cluster_num_ $cluster_numlappend eilastlevel $num_wired_nodes [expr $num_mobile_nodes + $num_bs_nodes] ;# number of nodes for each cluster             AddrParams set nodes_num_ $eilastlevel#Open the nam trace fileset nf [open out.nam w]$ns namtrace-all-wireless $nf $opt(x) $opt(y)set ntr [open out.tr w]$ns trace-all $ntrset chan	[new $opt(chan)]set topo	[new Topography]$topo load_flatgrid $opt(x) $opt(y)# Create Godcreate-god [expr $num_mobile_nodes + $num_bs_nodes]# creating wired nodesfor {set i 0} {$i < $num_wired_nodes} {incr i} {	set W($i) [$ns node 0.0.$i]    puts "wired node $i created"}# creating base station$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) \                 -channel $chan      \                 -topoInstance $topo \                 -wiredRouting ON \                 -agentTrace OFF \                 -routerTrace OFF \                 -macTrace OFF    \                 -movementTrace OFFset BS(0) [$ns node 1.0.0]$BS(0) random-motion 0puts "Base-Station node $bs_id created"#provide some co-ord (fixed) to base station node$BS(0) set X_ 250.0$BS(0) set Y_ 250.0$BS(0) set Z_ 0.0set  rng  [new RNG]$rng seed 1set  rand1  [new RandomVariable/Uniform]$rand1  use-rng $rng$rand1  set  min_ -100.0$rand1  set  max_ 100.0# creating mobile nodes$ns node-config -wiredRouting OFFfor {set i 0} {$i < $num_mobile_nodes} {incr i} {    set wl_node_($i) [$ns node 1.0.[expr $i + 1]]	    $wl_node_($i) random-motion 0		;# disable random motion    puts "wireless node $i created ..."    $wl_node_($i) base-station [AddrParams addr2id [$BS(0) node-addr]]    set x [expr 250+[$rand1 value]]    set y [expr 250+[$rand1 value]]    $wl_node_($i) set X_ $x    $wl_node_($i) set Y_ $y    $wl_node_($i) set Z_ 0.0    puts "X_:$x Y_:$y"}# linking of root to base-station node$ns duplex-link $W(0) $BS(0) 100Mb 2ms myfifoset q1	[[$ns link $W(0) $BS(0)] queue]set  rng  [new RNG]$rng  seed 1set  rand2  [new RandomVariable/Uniform]$rand2  use-rng $rng$rand2  set  min_ 0.0$rand2  set  max_ 3.0for {set i 0} {$i < $num_mobile_nodes} {incr i} {  set udp0 [new Agent/mUDP]  set p [expr $i*3]  $udp0 set class_ $p  $udp0 set_filename sd_$p  $udp0 set packetSize_ 1500  set sink0 [new Agent/mUdpSink]  $sink0 set_filename rd_$p  $ns attach-agent $W(0) $udp0  $ns attach-agent $wl_node_($i) $sink0  $ns connect $udp0 $sink0  set app0 [new Application/Traffic/CBR]  $app0 set packetSize_ 160  $app0 set interval_ 20ms  $app0 set random_ 0  $app0 attach-agent $udp0  set app0_start_time [$rand2 value]  puts "app0_start_time:$app0_start_time"  $ns at $app0_start_time "$app0 start"    set udp1 [new Agent/mUDP]  set j [expr $i*3+1]  $udp1 set class_ $j  $udp1 set_filename sd_$j  $udp1 set packetSize_ 1500  set sink1 [new Agent/mUdpSink]  $sink1 set_filename rd_$j  $ns attach-agent $W(0) $udp1  $ns attach-agent $wl_node_($i) $sink1  $ns connect $udp1 $sink1  set app1 [new Application/Traffic/CBR]  $app1 set packetSize_ 1280  $app1 set rate_ 64Kb  $app1 set random_ 0  $app1 attach-agent $udp1  set app1_start_time [$rand2 value]  puts "app1_start_time:$app1_start_time"  $ns at $app1_start_time "$app1 start"    set udp2 [new Agent/mUDP]  set k [expr $i*3+2]  $udp2 set class_ $k  $udp2 set_filename sd_$k  $udp2 set packetSize_ 1500  set sink2 [new Agent/mUdpSink]  $sink2 set_filename rd_$k  $ns attach-agent $W(0) $udp2  $ns attach-agent $wl_node_($i) $sink2  $ns connect $udp2 $sink2  set app2 [new Application/Traffic/CBR]  $app2 set packetSize_ 1000  $app2 set rate_ 128Kb  $app2 set random_ 0    $app2 attach-agent $udp2  set app2_start_time [$rand2 value]  puts "app2_start_time:$app2_start_time"  $ns at $app2_start_time "$app2 start"}# Define node initial position in namfor {set i 0} {$i < $num_mobile_nodes} {incr i} {    $ns initial_node_pos $wl_node_($i) 20   }# Tell nodes when the simulation endsfor {set i 0} {$i < $num_mobile_nodes } {incr i} {    $ns at 105.0 "$wl_node_($i) reset";}$ns at 100.0 "$BS(0) reset";$ns at 100.0 "$app0 stop"$ns at 100.0 "$app1 stop"$ns at 100.0 "$app2 stop"$ns at 110.0 "puts \"NS EXITING...\" ; $ns halt"proc stop {} {    global ns ntr nf    close $ntr    close $nf}# run the simulation$ns run

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -