test-suite-smac.tcl
来自「一款用来进行网络模拟的软件」· TCL 代码 · 共 1,635 行 · 第 1/3 页
TCL
1,635 行
# Copyright (c) 2000 by the University of Southern California# All rights reserved.## This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License,# version 2, as published by the Free Software Foundation.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License along# with this program; if not, write to the Free Software Foundation, Inc.,# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.## The copyright of this module includes the following# linking-with-specific-other-licenses addition:## In addition, as a special exception, the copyright holders of# this module give you permission to combine (via static or# dynamic linking) this module with free software programs or# libraries that are released under the GNU LGPL and with code# included in the standard release of ns-2 under the Apache 2.0# license or under otherwise-compatible licenses with advertising# requirements (or modified versions of such code, with unchanged# license). You may copy and distribute such a system following the# terms of the GNU GPL for this module and the licenses of the# other code concerned, provided that you include the source code of# that other code when and as the GNU GPL requires distribution of# source code.## Note that people who make modified versions of this module# are not obligated to grant this special exception for their# modified versions; it is their choice whether to do so. The GNU# General Public License gives permission to release a modified# version without this exception; this exception also makes it# possible to release a modified version which carries forward this# exception.# To view a list of available tests to run with this script:# ns test-suite-smac.tcl#remove-all-packet-headers ; # removes all except common#add-packet-header Flags IP TCP Diffusion ARP LL Mac # hdrs reqd for validation test# FOR UPDATING GLOBAL DEFAULTS:Agent/TCP set precisionReduce_ false ; # default changed on 2006/1/24.Agent/TCP set rtxcur_init_ 6.0 ; # Default changed on 2006/01/21Agent/TCP set updated_rttvar_ false ; # Variable added on 2006/1/21Agent/TCP set minrto_ 1# default changed on 10/14/2004.Class TestSuiteClass Test/brdcast1 -superclass TestSuite# 2 nodes brdcast ping req/replies to one anotherClass Test/brdcast1_sync -superclass TestSuiteClass Test/brdcast2 -superclass TestSuite# 3 node topology brdcasting ping req/rep that result in collisionClass Test/brdcast2_sync -superclass TestSuiteClass Test/unicast1 -superclass TestSuite# 2 node topology unicasting with RTS/CTS/DATA/ACK exchangeClass Test/unicast1_sync -superclass TestSuiteClass Test/unicast2 -superclass TestSuite# 3 node topology where node 0 & 1 unicast and node 2 brdcast.Class Test/unicast2_sync -superclass TestSuiteClass Test/unicast3 -superclass TestSuite#3 node topolofy where node 2 is neighbor to the sender node. can hear RTS/DATA, not CTSClass Test/unicast3_sync -superclass TestSuiteClass Test/unicast4 -superclass TestSuite#3 node topology where node 2 is neighbor to the recvr node. can hear CTS only.Class Test/unicast4_sync -superclass TestSuiteClass Test/unicast5 -superclass TestSuite# 4 node topology. 2 sender-recvr pairs (0->1 & 3->2)#3 cannot hear 0 & 1. 2 can hear only sender 0. Class Test/unicast5_sync -superclass TestSuiteClass Test/unicast6 -superclass TestSuite# 4 node topology. 2 sender-recvr pairs (0->1 & 3->2)#3 cannot hear 0 & 1. 2 can hear only recvr 1.Class Test/unicast6_sync -superclass TestSuiteClass Test/unicast7 -superclass TestSuite# 4 node topology. 2 sender-recvr pairs (0->1 & 2->3)#3 cannot hear 0 & 1. 2 can hear only sender 0. Class Test/unicast7_sync -superclass TestSuiteClass Test/unicast8 -superclass TestSuite# 4 node topology. 2 sender-recvr pairs (0->1 & 2->3)#3 cannot hear 0. 2 can hear only recvr 1.Class Test/unicast8_sync -superclass TestSuiteClass Test/unicast9 -superclass TestSuite# 4 node topology. 2 sender-recvr pairs (0->1 & 2->3)#2 & 3 can hear 0 & 1 but cannot recv pkts correctly. a lot of delayClass Test/unicast9_sync -superclass TestSuiteClass Test/unicast10 -superclass TestSuite# 4 node topology. 2 sender-recvr pairs (0->1 & 2->3)#2 & 3 cannot hear and recv from 0 & 1. can send simultaneously.Class Test/unicast10_sync -superclass TestSuiteClass Test/unicast11 -superclass TestSuite# 3 node triangle topology.1->2,2->3,3->1.Class Test/unicast11_sync -superclass TestSuiteClass Test/unicast12 -superclass TestSuite# 3 node triangle topology.1->2,2->3,3->1.with error model on every incoming interface# that randomly drops pktsClass Test/unicast12_sync -superclass TestSuiteproc usage {} { global argv0 puts stderr "usage: ns $argv0 <tests>" puts "Valid tests: brdcast1"}proc default_options {} { global opt set opt(chan) Channel/WirelessChannel ;# channel type set opt(prop) Propagation/TwoRayGround ;# radio-propagation model set opt(netif) Phy/WirelessPhy ;# network interface type set opt(mac) Mac/SMAC ;# MAC type #set opt(mac) Mac/802_11 ;# MAC type set opt(ifq) Queue/DropTail/PriQueue ;# interface queue type set opt(ll) LL ;# link layer type set opt(ant) Antenna/OmniAntenna ;# antenna model set opt(ifqlen) 50 ;# max packet in ifq set opt(x) 800 set opt(y) 800 set opt(rp) DumbAgent ;# routing protocol set opt(tr) temp.rands set opt(stop) 5.0 set opt(stop-sync) 100.0 ;# extended run time for sync simulations set opt(seed) 1}TestSuite instproc init {} { global opt node_ $self instvar ns_ topo_ tracefd_ testname_ set name [split $testname_ _] puts "$name" if { [lindex $name 1] == "sync" } { Mac/SMAC set syncFlag_ 1 } set ns_ [new Simulator] puts "Seeding Random number generator with $opt(seed)\n" ns-random $opt(seed) set tracefd_ [open $opt(tr) w] $ns_ trace-all $tracefd_ set topo_ [new Topography] $topo_ load_flatgrid $opt(x) $opt(y) create-god $opt(nn) $ns_ node-config -adhocRouting $opt(rp) \ -macType $opt(mac) \ -llType $opt(ll) \ -ifqType $opt(ifq) \ -ifqLen $opt(ifqlen) \ -antType $opt(ant) \ -propType $opt(prop) \ -phyType $opt(netif) \ -channelType $opt(chan) \ -topoInstance $topo_ \ -agentTrace ON \ -routerTrace ON \ -macTrace ON if {$testname_ == "unicast12" } { $ns_ node-config --IncomingErrProc $opt(err) } # if { [lindex $name 1] == "sync" } { #$ns_ node-config -macTrace OFF# } for {set i 0} {$i < $opt(nn) } {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 ;# disable random motion }}TestSuite instproc run {} { global opt node_ $self instvar ns_ testname_ set n [split $testname_ _] if { [lindex $n 1] == "sync" } { set opt(stop) $opt(stop-sync) } puts "$opt(stop)" # # Tell nodes when the simulation ends # for {set i 0} {$i < $opt(nn) } {incr i} { $ns_ at $opt(stop) "$node_($i) reset"; } $ns_ at $opt(stop) "$self finish" $ns_ at $opt(stop) "puts \"NS EXITING...\" ; $ns_ halt" puts "Starting Simulation..." $ns_ run}Test/brdcast1 instproc init {} { global opt node_ $self instvar ns_ testname_ set testname_ brdcast1 set opt(nn) 2 $self next $node_(0) set X_ 5.0 $node_(0) set Y_ 2.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 50.0 $node_(1) set Y_ 45.0 $node_(1) set Z_ 0.0 # all scheduled to brdcast at same time set ping0 [new Agent/Ping] $ns_ attach-agent $node_(0) $ping0 $ns_ at 1.0 "$ping0 start-WL-brdcast" set ping1 [new Agent/Ping] $ns_ attach-agent $node_(1) $ping1 $ns_ at 1.0 "$ping1 start-WL-brdcast" }Test/brdcast1 instproc run {} { $self instvar ns_ $self next} Test/brdcast1_sync instproc init {} { global opt node_ $self instvar testname_ ns_ set testname_ brdcast1_sync set opt(nn) 2 $self next $node_(0) set X_ 5.0 $node_(0) set Y_ 2.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 50.0 $node_(1) set Y_ 45.0 $node_(1) set Z_ 0.0 set ping0 [new Agent/Ping] $ns_ attach-agent $node_(0) $ping0 $ns_ at 40.0 "$ping0 start-WL-brdcast" set ping1 [new Agent/Ping] $ns_ attach-agent $node_(1) $ping1 $ns_ at 40.0 "$ping1 start-WL-brdcast"}Test/brdcast1_sync instproc run {} { $self instvar ns_ $self next}Test/brdcast2 instproc init {} { global opt node_ $self instvar ns_ net_ testname_ topo_ tracefd_ set testname_ brdcast2 set opt(nn) 3 $self next $node_(0) set X_ 5.0 $node_(0) set Y_ 2.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 50.0 $node_(1) set Y_ 45.0 $node_(1) set Z_ 0.0 $node_(2) set X_ 150.0 $node_(2) set Y_ 150.0 $node_(2) set Z_ 0.0 # all scheduled to brdcast at same time set ping0 [new Agent/Ping] $ns_ attach-agent $node_(0) $ping0 $ns_ at 1.0 "$ping0 start-WL-brdcast" set ping1 [new Agent/Ping] $ns_ attach-agent $node_(1) $ping1 $ns_ at 1.0 "$ping1 start-WL-brdcast" set ping2 [new Agent/Ping] $ns_ attach-agent $node_(2) $ping2 $ns_ at 1.0 "$ping2 start-WL-brdcast"}Test/brdcast2 instproc run {} { $self instvar ns_ $self next}Test/brdcast2_sync instproc init {} { global opt node_ $self instvar ns_ testname_ set testname_ brdcast2_sync set opt(nn) 3 $self next $node_(0) set X_ 5.0 $node_(0) set Y_ 2.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 50.0 $node_(1) set Y_ 45.0 $node_(1) set Z_ 0.0 $node_(2) set X_ 150.0 $node_(2) set Y_ 150.0 $node_(2) set Z_ 0.0 # all scheduled to brdcast at same time set ping0 [new Agent/Ping] $ns_ attach-agent $node_(0) $ping0 $ns_ at 40.0 "$ping0 start-WL-brdcast" set ping1 [new Agent/Ping] $ns_ attach-agent $node_(1) $ping1 $ns_ at 41.0 "$ping1 start-WL-brdcast" set ping2 [new Agent/Ping] $ns_ attach-agent $node_(2) $ping2 $ns_ at 42.0 "$ping2 start-WL-brdcast"}Test/brdcast2_sync instproc run {} { $self instvar ns_ $self next}Test/unicast1 instproc init {} { global opt node_ $self instvar ns_ net_ testname_ topo_ tracefd_ set testname_ unicast1 set opt(nn) 2 $self next $node_(0) set X_ 5.0 $node_(0) set Y_ 2.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 50.0 $node_(1) set Y_ 45.0 $node_(1) set Z_ 0.0 set ping0 [new Agent/Ping] $ns_ attach-agent $node_(0) $ping0 set ping1 [new Agent/Ping] $ns_ attach-agent $node_(1) $ping1 # connect two agents $ns_ connect $ping0 $ping1 $ns_ at 1.0 "$ping0 send"}Test/unicast1 instproc run {} { $self instvar ns_ $self next}Test/unicast1_sync instproc init {} { global opt node_ $self instvar ns_ net_ testname_ topo_ tracefd_ set testname_ unicast1_sync set opt(nn) 2 $self next $node_(0) set X_ 5.0 $node_(0) set Y_ 2.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 50.0 $node_(1) set Y_ 45.0 $node_(1) set Z_ 0.0 set ping0 [new Agent/Ping] $ns_ attach-agent $node_(0) $ping0 set ping1 [new Agent/Ping] $ns_ attach-agent $node_(1) $ping1 # connect two agents $ns_ connect $ping0 $ping1 $ns_ at 40.0 "$ping0 send"}Test/unicast1_sync instproc run {} { $self instvar ns_ $self next}Test/unicast2 instproc init {} { global opt node_ $self instvar ns_ net_ testname_ topo_ tracefd_ set testname_ unicast2 set opt(nn) 3 $self next $node_(0) set X_ 300.0 $node_(0) set Y_ 350.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 450.0 $node_(1) set Y_ 350.0 $node_(1) set Z_ 0.0 # 2 can hear and recv from nodes 0 & 1 (sender and recvr) $node_(2) set X_ 400.0 $node_(2) set Y_ 125.0 $node_(2) set Z_ 0.0 set ping0 [new Agent/Ping] $ns_ attach-agent $node_(0) $ping0 set ping1 [new Agent/Ping] $ns_ attach-agent $node_(1) $ping1 # connect two agents $ns_ connect $ping0 $ping1 set ping2 [new Agent/Ping] $ns_ attach-agent $node_(2) $ping2 # start times for connections $ns_ at 0.1 "$ping0 send" # ping2 sends brdcast overlapping with ping0 $ns_ at 0.2 "$ping2 start-WL-brdcast"}Test/unicast2 instproc run {} { $self instvar ns_ $self next}Test/unicast2_sync instproc init {} { global opt node_ $self instvar ns_ net_ testname_ topo_ tracefd_ set testname_ unicast2_sync set opt(nn) 3 $self next $node_(0) set X_ 300.0 $node_(0) set Y_ 350.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 450.0 $node_(1) set Y_ 350.0 $node_(1) set Z_ 0.0 # 2 can hear and recv from nodes 0 & 1 (sender and recvr) $node_(2) set X_ 400.0 $node_(2) set Y_ 125.0 $node_(2) set Z_ 0.0 set ping0 [new Agent/Ping] $ns_ attach-agent $node_(0) $ping0 set ping1 [new Agent/Ping] $ns_ attach-agent $node_(1) $ping1 # connect two agents $ns_ connect $ping0 $ping1 set ping2 [new Agent/Ping] $ns_ attach-agent $node_(2) $ping2 # start times for connections $ns_ at 40.1 "$ping0 send" # ping2 sends brdcast overlapping with ping0 $ns_ at 40.2 "$ping2 start-WL-brdcast"}Test/unicast2_sync instproc run {} { $self instvar ns_ $self next
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?