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

📄 twoflows-1channel.tcl

📁 NS中如何添加MANUAL路由协议
💻 TCL
字号:
# VARIABLE PARTset val(chan)           Channel/WirelessChannel    ;# channel typeset val(prop)           Propagation/TwoRayGround   ;# radio-propagation modelset val(netif)          Phy/WirelessPhy            ;# network interface typeset val(mac)            Mac/802_11                 ;# MAC typeset val(ifq)            Queue/DropTail/PriQueue    ;# interface queue typeset val(ll)             LL                         ;# link layer typeset val(ant)            Antenna/OmniAntenna        ;# antenna modelset val(ifqlen)         50                         ;# max packet in ifqset val(nn)             4                          ;# number of mobilenodesset val(rp)             MANUAL                     ;# routing protocolset val(x)      100set val(y)      200set filename       twoflows-1channel# TRACE PARTset ns_     [new Simulator]set tracefd     [open $filename.tr w]$ns_ use-newtrace$ns_ trace-all $tracefdset namtrace [open $filename.nam w]$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)set topo       [new Topography]$topo load_flatgrid $val(x) $val(y)create-god $val(nn)set chan_0_ [new $val(chan)]set chan_1_ [new $val(chan)]set chan_2_ [new $val(chan)]set chan_3_ [new $val(chan)]set chan_4_ [new $val(chan)]set chan_5_ [new $val(chan)]set chan_6_ [new $val(chan)]set chan_7_ [new $val(chan)]set chan_8_ [new $val(chan)]set chan_9_ [new $val(chan)]set chan_10_ [new $val(chan)]set chan_11_ [new $val(chan)]# NODE CONFIG PART$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 OFF$ns_ node-config -channel $chan_6_\	 -channel2 $chan_1_\	 -channel3 $chan_11_\	 -channel4 $chan_4_\	 -channel5 $chan_5_\set node_(0) [$ns_ node]$node_(0) random-motion 0set node_(1) [$ns_ node]$node_(1) random-motion 0set node_(2) [$ns_ node]$node_(2) random-motion 0set node_(3) [$ns_ node]$node_(3) random-motion 0# Add routing tag$node_(0) add-route-tag 1 999$node_(2) add-route-tag 3 8# Add next hop$node_(0) add-next-hop 1 999 1 2$node_(2) add-next-hop 3 8 3 2# GRAPH PART$node_(0) set X_ 11$node_(0) set Y_ 11$node_(0) set Z_ 0.0$node_(1) set X_ 11$node_(1) set Y_ 111 $node_(1) set Z_ 0.0$node_(2) set X_ 61$node_(2) set Y_ 11$node_(2) set Z_ 0.0$node_(3) set X_ 61$node_(3) set Y_ 111$node_(3) set Z_ 0.0for {set i 0} {$i < $val(nn) } {incr i} {    $ns_ initial_node_pos $node_($i) 10}# Trafficproc attach-cbr-traffic { node sink size interval } {	global ns_	set source [new Agent/UDP]	$source set class_ 2	$ns_ attach-agent $node $source	set traffic [new Application/Traffic/CBR]	$traffic set packetSize_ $size	$traffic set interval_ $interval	$traffic attach-agent $source	$ns_ connect $source $sink	return $traffic}set null0 [new Agent/Null]$ns_ attach-agent $node_(1) $null0set cbr0 [attach-cbr-traffic $node_(0) $null0 1000 0.008]$ns_ at 0.001 "$cbr0 start"$ns_ at 4.9 "$cbr0 stop"set null1 [new Agent/Null]$ns_ attach-agent $node_(3) $null1set cbr1 [attach-cbr-traffic $node_(2) $null1 1000 0.008]$ns_ at 0.001 "$cbr1 start"$ns_ at 4.9 "$cbr1 stop"for {set i 0} {$i < $val(nn) } {incr i} {    $ns_ at 5.0 "$node_($i) reset";}puts "Starting Simulation..."$ns_ run

⌨️ 快捷键说明

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