📄 rsvp_large.tcl
字号:
## Copyright (c) 1998 The University of Bonn# All rights reserved.# # Permission to use and copy this software in source and binary forms# is hereby granted, provided that the above copyright notice, this# paragraph and the following disclaimer are retained in any copies# of any part of this software and that the University of Bonn is# acknowledged in all documentation pertaining to any such copy# or derivative work. The name of the University of Bonn may not# be used to endorse or promote products derived from this software# without specific prior written permission.## THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL # THE UNIVERSITY OF BONN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE.## An RSVP simulation scenario with 80 nodes and up to 1140 flows. See# 'http://titan.cs.uni-bonn.de/~greis/rsvpns/rsvpns.ps' for a detailed# description.set ns [new Simulator]# Open four log filesset f0 [open out0.tr w]set f1 [open out1.tr w]set f2 [open out2.tr w]set f3 [open out3.tr w]Agent/RSVP set noisy_ 0# Redefine the Path upcall to automatically perform a reservationAgent/RSVP instproc upcall-path { sid rate bucket sender } { $self reserve $sid FF $rate $bucket $sender}# Redefine the Resv upcall to start sending a flow for this session# as soon as a reservation is establishedAgent/RSVP instproc upcall-resv { sid rate bucket sender } { global [$self get-handle $sid] [$self get-handle $sid] start}# The average packet sizeset psize 500# The average flow length in secondsset flength 200# The number of best-effort flows for every end nodeset flownum 15# The number of RSVP flows for every end nodeset rsvpnum 4# The first flow idset fid 1000set rng [new RNG]$rng seed 0set packetrv [new RandomVariable/Exponential]$packetrv set avg_ $psizeset timerv [new RandomVariable/Exponential]$timerv set avg_ $flength# The class 'Flow' creates a best-effort flow with an expoo # distribution and a peak rate of 64kb/s.Class Flow# The init procedure creates the traffic source for the flow and # schedules the stop time.Flow instproc init {n1 n2} { eval $self next $self instvar source_ traffic_ node_ global packetrv timerv null set ns [Simulator instance] set node_ $n1 set source_ [new Agent/CBR/UDP] $ns attach-agent $node_ $source_ set traffic_ [new Traffic/Expoo] set size [expr int([$packetrv value]) + 1] $traffic_ set packet-size $size $traffic_ set burst-time 1s $traffic_ set idle-time 0.5s $traffic_ set rate 64k $source_ attach-traffic $traffic_ $ns connect $source_ $null([$n2 id]) $source_ start $ns at [expr [$ns now] + [$timerv value]] "$self stop"}# The stop procedure stops the flow, schedules the next flow and# deletes the Flow object.Flow instproc stop {} { $self instvar source_ traffic_ node_ global timerv rng n set ns [Simulator instance] $source_ stop $ns detach-agent $node_ $source_ delete $traffic_ delete $source_ set next_time [expr [$ns now] + ([$timerv value] / 2)] set tonode [$rng integer 60] while {$tonode == $node_} { set tonode [$rng integer 60] } $ns at $next_time "new Flow $node_ $n($tonode)" delete $self}# The class RSVPFlow creates a flow with similar characteristics# as the best-effort flows, but with a reservation for its rate.# RSVPFlows are sent with a constant bit rate of 64kbit/s.Class RSVPFlow# The init procedure creates an RSVP session for this flow and# sends path messagesRSVPFlow instproc init {n1 n2} { eval $self next $self instvar node_ session_ fid_ dest_ set ns [Simulator instance] global fid r set fid_ $fid set node_ $n1 set dest_ [$n2 id] incr fid set id [$n1 id] set session_ [$r($id) session $n2 $fid_] $r($id) sender $session_ 64000 5000 10 $r($id) set-handle $session_ $self}# The start procedure is called by the Resv upcall when a reservation# for this flow is in place. It creates a CBR agent and schedules# its stop time.RSVPFlow instproc start {} { $self instvar node_ source_ fid_ dest_ global null timerv set ns [Simulator instance] set source_ [new Agent/CBR] $ns attach-agent $node_ $source_ $source_ set packetSize_ 500 $source_ set interval_ 0.0625 $source_ set fid_ $fid_ $ns connect $source_ $null($dest_) $source_ start $ns at [expr [$ns now] + [$timerv value]] "$self stop"} # The stop procedure deletes the traffic source and releases the# RSVP session, then it schedules the start of the next session before# it deletes the RSVPFlow object.RSVPFlow instproc stop {} { $self instvar session_ source_ node_ global timerv r rng n $source_ stop set ns [Simulator instance] $ns detach-agent $node_ $source_ delete $source_ $r([$node_ id]) release $session_ set next_time [expr [$ns now] + ([$timerv value] / 2)] set tonode [$rng integer 60] while {$tonode == $node_} { set tonode [$rng integer 60] } $ns at $next_time "new RSVPFlow $node_ $n($tonode)" delete $self}# The class MonFlow does not actually create a flow, it only performs# a reservation for the flow sent by the cbr0 agent.Class MonFlow# The init procedure creates a session for the flow and starts sending# path messages, then schedules the stop procedure after 100 seconds.MonFlow instproc init {} { $self instvar sid_ global r n set sid_ [$r(0) session $n(30) 10] $r(0) set-handle $sid_ $self $r(0) sender $sid_ 64000 5000 10 set ns [Simulator instance] $ns at [expr [$ns now] + 100] "$self stop"}# This is more or less a dummy procedure that is needed since # the resv upcall calls a 'start' function. It is useful to see# that the reservation actually succeeded though.MonFlow instproc start {} { puts "Reservation accepted at [[Simulator instance] now]"}# The stop procedure releases the session and deletes the object.MonFlow instproc stop {} { global r $self instvar sid_ $r(0) release $sid_ puts "Reservation cancelled at [[Simulator instance] now]" delete $self}# Set up the topology:puts "Creating 80 nodes with RSVP agents and traffic sinks"for {set i 0} {$i < 80} {incr i} { set n($i) [$ns node] set r($i) [$n($i) add-rsvp-agent] if {$i < 60} { $r($i) set noisy_ 3 } set null($i) [new Agent/Null] $ns attach-agent $n($i) $null($i)}puts "Connecting the \"backbone\""for {set i 0} {$i < 5} {incr i} { $ns duplex-rsvp-link $n([expr $i + 75]) \ $n([expr (($i + 1) % 5) + 75]) 3Mb 10ms 0.99 5000 1000 Param Null}puts "Connecting the \"access nodes\" with the \"backbone\""for {set i 0} {$i < 15} {incr i} { $ns duplex-rsvp-link $n([expr $i + 60]) $n([expr ($i / 3) + 75]) \ 2Mb 10ms 0.99 5000 1000 Param Null}puts "Connecting the \"end nodes\" with the \"access nodes\""for {set i 0} {$i < 60} {incr i} { $ns duplex-rsvp-link $n($i) $n([expr ($i / 4) + 60]) \ 1Mb 10ms 0.99 5000 10000 Param Null}puts "Initializing $flownum flows per end node"for {set i 0} {$i < 60} {incr i} { for {set j 0} {$j < $flownum} {incr j} { set tonode [$rng integer 60] while {$tonode == $i} { set tonode [$rng integer 60] } new Flow $n($i) $n($tonode) }}puts "Initializing $rsvpnum RSVP flows per end node"for {set i 0} {$i < 60} {incr i} { for {set j 0} {$j < $rsvpnum} {incr j} { set tonode [$rng integer 60] while {$tonode == $i} { set tonode [$rng integer 60] } $ns at [$rng uniform 1 50] \ "set ne \[new RSVPFlow $n($i) $n($tonode)\]" }}# A simple procedure to log some interesting data. The procedure# writes the data into the corresponding files, then schedules itself# a second later.proc record {} { global ns counter sink0 f0 f1 f2 f3 r monqueue set time 1.0 set now [$ns now] set bw [$sink0 set bytes_] # The bandwidth for the 'main flow' puts $f0 "$now [expr $bw/$time*8/1000]" # The number of flows in an arbitrarily chosen backbone node puts $f1 "$now [$r(79) set num_flows_]" # The number of flows in an arbitrarily chosen backbone link puts $f2 "$now [$monqueue set num_flows_]" # The number of dropped packets for reserved flows in that link puts $f3 "$now [$monqueue set num_drops_]" $monqueue clear-stats $sink0 set bytes_ 0 $ns at [expr $now+$time] "record" puts "Time: $now" incr counter}proc finish {} { puts "Done." exit 0}set cbr0 [new Agent/CBR]$ns attach-agent $n(0) $cbr0$cbr0 set packetSize_ 100$cbr0 set interval_ 0.0125$cbr0 set fid_ 10set sink0 [new Agent/LossMonitor]$ns attach-agent $n(30) $sink0$ns connect $cbr0 $sink0set monqueue [[$ns link $n(78) $n(79)] queue]set counter 0$ns at 0.0 "record"$ns at 0.0 "$cbr0 start"$ns at 300 "new MonFlow"$ns at 500 "new MonFlow"$ns at 700 "new MonFlow"$ns at 820.0 "finish"$ns run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -