📄 test-suite-greis.tcl
字号:
# FOR UPDATING GLOBAL DEFAULTS:Agent/TCP set windowInit_ 1# The default is being changed to 2.Agent/TCP set singledup_ 0# The default is being changed to 1## Copyright (c) 1998 University of Southern California.# All rights reserved. # # Redistribution and use in source and binary forms are permitted# provided that the above copyright notice and this paragraph are# duplicated in all such forms and that any documentation, advertising# materials, and other materials related to such distribution and use# acknowledge that the software was developed by the University of# Southern California, Information Sciences Institute. The name of the# University may not be used to endorse or promote products derived from# this software without specific prior written permission.# # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.# ## ****** Note: please keep this test-suite sync'ed with the example scripts # provided in the tutorial. Thanks.## This test suite is for validating all the examples in Marc Greis tutorial# that's now on the ns web pages at http://www.isi.edu/nsnam/ns/tutorial/index.html## To run all tests: test-all-greis# to run individual test:# ns test-suite-greis.tcl example1# ns test-suite-greis.tcl example1a# ....## To view a list of available test to run with this script:# ns test-suite-greis.tcl#Agent/TCP set syn_ falseAgent/TCP set delay_growth_ false# In preparation for changing the default values for syn_ and delay_growth_.Class TestSuiteClass Test/example1 -superclass TestSuiteClass Test/example1a -superclass TestSuiteClass Test/example1b -superclass TestSuiteClass Test/example2 -superclass TestSuiteClass Test/example3 -superclass TestSuiteClass Test/example4 -superclass TestSuiteClass Test/ping -superclass TestSuite proc usage {} { global argv0 puts stderr "usage: ns $argv0 <tests> " puts "Valid Tests: example1 example1a example1b example2 \ example3 example4" exit 1}#example1.tclTest/example1 instproc init {} { $self instvar ns testName nf set testName example1 #create a simulator object set ns [new Simulator] #open a file for writing that is used for nam trace data set nf [open temp.rands w] $ns namtrace-all $nf}#finish procedure that closes the trace file and starts namTest/example1 instproc finish {} { global quiet $self instvar ns nf $ns flush-trace close $nf if {$quiet == "false"} { puts "finishing.." } exit 0}Test/example1 instproc run {} { $self instvar ns #execute the "finish" procedure after 5.0 seconds of simulation time $ns at 5.0 "$self finish" #start the simulation $ns run}#example1a.tclTest/example1a instproc init {} { $self instvar ns testName nf set testName example1a #Create a simulator object set ns [new Simulator] #Open the nam trace file set nf [open temp.rands w] $ns namtrace-all $nf}#Define a 'finish' procedureTest/example1a instproc finish {} { global quiet $self instvar ns nf $ns flush-trace #Close the trace file close $nf #Execute nam on the trace file if {$quiet == "false"} { puts "finishing.." } exit 0}Test/example1a instproc run {} { $self instvar ns # Insert your own code for topology creation # and agent definitions, etc. here set n0 [$ns node] set n1 [$ns node] $ns duplex-link $n0 $n1 1Mb 10ms DropTail #Call the finish procedure after 5 seconds simulation time $ns at 5.0 "$self finish" #Run the simulation $ns run}#example1b.tclTest/example1b instproc init {} { $self instvar ns testName nf set testName example1b #Create a simulator object set ns [new Simulator] #Open the nam trace file set nf [open temp.rands w] $ns namtrace-all $nf}#Define a 'finish' procedureTest/example1b instproc finish {} { global quiet $self instvar ns nf $ns flush-trace #Close the trace file close $nf #Execute nam on the trace file if {$quiet == "false"} { puts "finishing.." } exit 0}Test/example1b instproc run {} { $self instvar ns #Create two nodes set n0 [$ns node] set n1 [$ns node] #Create a duplex link between the nodes $ns duplex-link $n0 $n1 1Mb 10ms DropTail #Create a CBR agent and attach it to node n0 set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0 #Create a Null agent (a traffic sink) and attach it to node n1 set null0 [new Agent/Null] $ns attach-agent $n1 $null0 #Connect the traffic source with the traffic sink $ns connect $udp0 $null0 #Schedule events for the CBR traffic generator $ns at 0.5 "$cbr0 start" $ns at 4.5 "$cbr0 stop" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "$self finish" #Run the simulation $ns run}#example2.tclTest/example2 instproc init {} { $self instvar ns testName nf set testName example2 #Create a simulator object set ns [new Simulator] #Define different colors for data flows $ns color 1 Blue $ns color 2 Red #Open the nam trace file set nf [open temp.rands w] $ns namtrace-all $nf}#Define a 'finish' procedureTest/example2 instproc finish {} { global quiet $self instvar ns nf $ns flush-trace #Close the trace file close $nf #Execute nam on the trace file if {$quiet == "false"} { puts "finishing.." } exit 0}Test/example2 instproc run {} { $self instvar ns #Create four nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] #Create links between the nodes $ns duplex-link $n0 $n2 1Mb 10ms DropTail $ns duplex-link $n1 $n2 1Mb 10ms DropTail $ns duplex-link $n3 $n2 1Mb 10ms SFQ $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link-op $n2 $n3 orient right #Monitor the queue for the link between node 2 and node 3 $ns duplex-link-op $n2 $n3 queuePos 0.5 #Create a UDP agent with CBR traffic and attach it to node n0 set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 set fid_ 0 $cbr0 attach-agent $udp0 #Create a UDP agent with CBR traffic and attach it to node n1 set udp1 [new Agent/UDP] $ns attach-agent $n1 $udp1 set cbr1 [new Application/Traffic/CBR] $cbr1 set packetSize_ 500 $cbr1 set interval_ 0.005 $cbr1 set fid_ 2 $cbr1 attach-agent $udp1 #Create a Null agent (a traffic sink) and attach it to node n3 set null0 [new Agent/Null] $ns attach-agent $n3 $null0 #Connect the traffic sources with the traffic sink $ns connect $udp0 $null0 $ns connect $udp1 $null0 #Schedule events for the CBR traffic generators $ns at 0.5 "$cbr0 start" $ns at 1.0 "$cbr1 start" $ns at 4.0 "$cbr1 stop" $ns at 4.5 "$cbr0 stop" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "$self finish" #Run the simulation $ns run}#example3.tclTest/example3 instproc init {} { $self instvar ns testName nf set testName example3 #Create a simulator object set ns [new Simulator] #Tell the simulator to use dynamic routing $ns rtproto DV
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -