📄 mmac-test.tcl
字号:
# mmac-36.tcl# common network environment & topology file# 36 nodes in 6*6 grid form, WLAN (single hop)# ======================================================================# Define options# ======================================================================set 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) 36 ;# number of mobilenodesset opt(flow) 3set opt(row) 6 set opt(column) 6 set opt(adhocRouting) DSDV ;# routing protocolset opt(cp) "" ;# connection pattern fileset opt(sc) "" ;# node movement file. set opt(x) 400 ;# x coordinate of topologyset opt(y) 400 ;# y coordinate of topologyset opt(seed) 0 ;# seed for random number gen.set opt(stop) 50 ;# time to stop simulation# ============================================================================# check for boundary parameters and random seedif { $opt(x) == 0 || $opt(y) == 0 } { puts "No X-Y boundary values given for wireless topology\n"}if {$opt(seed) > 0} { puts "Seeding Random number generator with $opt(seed)\n" ns-random $opt(seed)}# create simulator instanceset ns_ [new Simulator]set tracefd [open out.tr w]$ns_ trace-all $tracefd# Create topography objectset topo [new Topography]# define topology$topo load_flatgrid $opt(x) $opt(y)# create Godcreate-god [expr $opt(nn)]# 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 \ -agentTrace ON \ -routerTrace OFF \ -macTrace ON \ -movementTrace OFF # create mobilenodes in the same domain as BS(0) # note the position and movement of mobilenodes is as defined# in $opt(sc)#configure for mobilenodesfor {set j 0} {$j < $opt(nn)} {incr j} { set node_($j) [$ns_ node]}for {set j 0} {$j < $opt(row)} {incr j} { for {set i 0} {$i < $opt(column)} {incr i} { $node_([expr $j * $opt(column) + $i]) set X_ [expr $i * 10] $node_([expr $j * $opt(column) + $i]) set Y_ [expr $j * 10] $node_([expr $j * $opt(column) + $i]) set Z_ 0 }} #mmacfor {set j 0} {$j < $opt(nn)} {incr j} { [$node_($j) set mac_(0)] make-pc [$node_($j) set mac_(0)] beaconperiod 100 [$node_($j) set mac_(0)] atimwindowsize 20}#load traffic file#source $opt(traffic)###########################################################set udp_(1) [new Agent/UDP]$ns_ attach-agent $node_(0) $udp_(1)set null_(1) [new Agent/Null]$ns_ attach-agent $node_(1) $null_(1)set cbr_(1) [new Application/Traffic/CBR]$cbr_(1) set packetSize_ 512 $cbr_(1) set interval_ 0.025 $cbr_(1) set random_ 1$cbr_(1) attach-agent $udp_(1)$ns_ connect $udp_(1) $null_(1)$ns_ at 9.8 "$cbr_(1) start"$ns_ at 30.0 "$cbr_(1) stop"set udp_(2) [new Agent/UDP]$ns_ attach-agent $node_(2) $udp_(2)set null_(2) [new Agent/Null]$ns_ attach-agent $node_(3) $null_(2)set cbr_(2) [new Application/Traffic/CBR]$cbr_(2) set packetSize_ 512 $cbr_(2) set interval_ 0.025 $cbr_(2) set random_ 1$cbr_(2) attach-agent $udp_(2)$ns_ connect $udp_(2) $null_(2)$ns_ at 9.9 "$cbr_(2) start"$ns_ at 30.0 "$cbr_(2) stop"set udp_(3) [new Agent/UDP]$ns_ attach-agent $node_(4) $udp_(3)set null_(3) [new Agent/Null]$ns_ attach-agent $node_(5) $null_(3)set cbr_(3) [new Application/Traffic/CBR]$cbr_(3) set packetSize_ 512 $cbr_(3) set interval_ 0.025 $cbr_(3) set random_ 1$cbr_(3) attach-agent $udp_(3)$ns_ connect $udp_(3) $null_(3)$ns_ at 10.0 "$cbr_(3) start"$ns_ at 30.0 "$cbr_(3) stop"############################################################ source connection-pattern and node-movement scriptsif { $opt(cp) == "" } { puts "*** NOTE: no connection pattern specified." set opt(cp) "none"} else { puts "Loading connection pattern..." source $opt(cp)}if { $opt(sc) == "" } { puts "*** NOTE: no scenario file specified." set opt(sc) "none"} else { puts "Loading scenario file..." source $opt(sc) puts "Load complete..."}puts " "puts "MMAC Flow:3 Rate:0.025 P-Size:512 A-Size:20"puts " "# 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).0004 "stop"$ns_ at $opt(stop).0005 "puts \"NS EXITING...\" ; $ns_ halt"proc stop {} { global ns_ tracefd $ns_ flush-trace close $tracefd}# informative headers for CMUTracefile#puts $tracefd "M 0.0 nn $opt(nn) x $opt(x) y $opt(y) rp \# $opt(adhocRouting)"#puts $tracefd "M 0.0 sc $opt(sc) cp $opt(cp) seed $opt(seed)"#puts $tracefd "M 0.0 prop $opt(prop) ant $opt(ant)"puts "Starting Simulation..."$ns_ run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -