📄 agent-gen.tcl
字号:
## Copyright (c) 1996-1997 Regents of the University of California.# All rights reserved.# # Redistribution and use in source and binary forms, with or without# modification, are permitted provided that the following conditions# are met:# 1. Redistributions of source code must retain the above copyright# notice, this list of conditions and the following disclaimer.# 2. Redistributions in binary form must reproduce the above copyright# notice, this list of conditions and the following disclaimer in the# documentation and/or other materials provided with the distribution.# 3. All advertising materials mentioning features or use of this software# must display the following acknowledgement:# This product includes software developed by the MASH Research# Group at the University of California Berkeley.# 4. Neither the name of the University nor of the Research Group may be# used to endorse or promote products derived from this software without# specific prior written permission.# # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF# SUCH DAMAGE.# Created May 98 by Ahmed Helmy; updated June 98# agent generator classClass AgentGenproc agent-usage { } { puts stderr {usage: agents [options]where options are given as: -key valueexample options:-outfile f -transport TCP/Reno -num 20 -src FTP -sink TCPSink -start 1-3 -stop 6-8 "agents -h" for help} return}proc detailed-usage { } {puts {usage: agents [-<key 1> <value 1> -<key n> <value n>]example1:agents -outfile f -transport TCP -num 20 -src FTP -sink TCPSink -srcstub 4-7,12 -deststub 8-11,15 example2:agents -outfile f -transport SRM -num 50 -src Telnet -srcstub 1,3 -deststub 2,4-20 -srcnum 10%Keys:-outfile: the filename to which the generated script will be written.-transport: [now supports only TCP and SRM and their variants] values: tcp types: TCP [TCP Tahoe], TCP/Reno, TCP/NewReno, TCP/Sack1, TCP/Vegas, TCP/Fack srm types: SRM, SRM/Deterministic , SRM/Probabilistic, SRM/Adaptive details: SRM: C1 = C2 = 2 (request param), D1 = D2 = 1 (repair param) Deterministic: C2 = 0, D2 = 0 Probabilistic: C1 = D1 = 0-src: FTP [default with TCPs], Telnet, CBR, CBR/UDP. CBR is a constant bit rate source, CBR/UDP same as CBR but with ability to use traffic models [such as pareto and exponential, described next]-traffic: [the traffic model, may be used with CBR/UDP] Expoo: Exponential on/off model Pareto: Pareto on/off model-sink: [now used for sinks of tcp connections] values: TCPSink,TCPSink/DelAck,TCPSink/Sack1,TCPSink/Sack1/DelAck,FullTcp details: one way rxvg agents: TCPSink (1 ack per packet) , TCPSink/DelAck (w/ delay per ack), TCPSink/Sack1 (selective ack sink rcf2018), TCPSink/Sack1/DelAck (sack1 with DelAck) 2 way "FullTcp": Reno sender-num: number of tcp connections or total srm agents. Given as either absolute value indicating number of nodes, or as percentage of the total number of nodes in the topology (e.g. 60%). [for srm the default is all nodes are agents]-srcstub: the stubs from the sources are going to originate. stubs can be defined as a number, percentage or as a range. Nodes in the stub are selected randomly. e.g -srcstub <10> (indicates simply stub 10) or -srcstub <1-6,8,10-15> (meaning all stubs between 1 to 6 and 10 to 15 and stub 8 shall have n (as defined) number of source nodes or -srcstub <1-6> , includes all stubs only from 1 to 6. Stubs are used to determine membership/flow distribution for a given topology and can be used to control dense or sparse mode simulation. Defaults to all stubs in topology.-deststub: Stubs from which the destination nodes are going to originate. deststubs are also defined as absolute numbers, percentages or as range. e.g -deststub <10> or -deststub <1-5,8-10> or -destnode <1-6>. Defaults to all stubs in topology.-srcnum: the number of srm agents that are also sources [defaults to 10% of total nodes]-start: starting time of the tcp connections, or srm sources. May be given as a range x1-x2, in which different random starting times from the range will be assigned to different agents, or may be given as value x at which all agents start (default is 0)-stop: (format similar to start) stop the sources-join: (format similar to start) when srm agents join the group-leave: (format similar to start) when srm agents leave [not support by srm yet!]-totalnodes: the number of nodes to be used by the agent generator as the total # nodes in the topology. [if left out, the agent generator asks the topology generator for this info.] }}proc agents { args } { set len [llength $args] if { $len } { set key [lindex $args 0] if {$key == "-?" || $key == "--help" || $key == "-help" \ || $key == "-h" } { detailed-usage return } } if { !$len || [expr $len % 2] } { # if number is odd => error ! puts "fewer number of arguments than needed in \"$args\"" agent-usage return } if { [catch {set ag [AgentGen info instances]}] } { puts "can't create AgentGen ..!!" agent-usage return } if { $ag == "" } { set ag [new AgentGen] } $ag create $args}AgentGen instproc init { } { $self next}AgentGen instproc default_options { } { $self instvar opt_info set opt_info { # init file to -1, must be supplied by input outfile -1 transport -1 src -1 sink -1 num -1 srcstub -1 deststub -1 # may add location same_stub/other_stub later # start range either a number x or range x1-x2 start 0 stop 0 # srm srcnum srcnum 10% traffic -1 join 0 leave 0 totalnodes 0 } $self parse_opts} AgentGen instproc parse_opts { } { $self instvar opts opt_info while { $opt_info != ""} { # parse line by line if {![regexp "^\[^\n\]*\n" $opt_info line]} { break } # remove the parsed line regsub "^\[^\n\]*\n" $opt_info {} opt_info # remove leading spaces and tabs using trim set line [string trim $line] # skip comment lines beginning with # if {[regexp "^\[ \t\]*#" $line]} { continue } # skip empty lines if {$line == ""} { continue } elseif {[regexp {^([^ ]+)[ ]+([^ ]+)$} $line dummy key value]} { set opts($key) $value } }}AgentGen instproc parse_input { args } { # remove the list brackets from the args list set args [lindex $args 0] set len [llength $args] $self instvar opts for { set i 0 } { $i < $len } { incr i } { set key [lindex $args $i] regsub {^-} $key {} key if {![info exists opts($key)]} { puts stderr "unrecognized option $key" agent-usage return -1 } incr i puts "changing $key from $opts($key) to [lindex $args $i]" set opts($key) [lindex $args $i] } # puts "end of parsing... " return 0}AgentGen instproc create { args } { # remove the list brackets from the args list set args [lindex $args 0] set len [llength $args] # puts "calling create with args $args, len $len" $self default_options if { $len } { if { [$self parse_input $args] == -1 } { return } } # check that the filename is provided $self instvar opts if { $opts(outfile) == -1 } { puts {you must provide outfile. Use "agents -h" for help} return } $self save-command $opts(outfile) $args $self create-agents}# we save the commands to append them to the end of the fileAgentGen instproc save-command { file command } { global AllCommandLines # XXX clear the commands if this is a new file if { ![file exists $file] } { set f [open $file w] # XXX complete # puts $f "header info... "puts $f "\n proc generate-agents \{ sim nodes \} \{ \n"puts $f "\t upvar \$nodes n; upvar \$sim ns \n" # initialize the fid to 0 puts $f "\t set fid 0\n\n" flush $f; close $f set AllCommandLines "" } $self instvar commandLine set commandLine "agents $command" lappend AllCommandLines $commandLine}AgentGen instproc create-agents { } { $self instvar opts # puts "transport $opts(transport)" set transport -1 regexp {^([a-zA-Z]+)} $opts(transport) all transport switch $transport { "TCP" { if { [$self check-tcp $opts(transport)] == -1 || \ [$self check-tcp-sink $opts(sink)] == -1 } { puts "invalid or unsupported tcp or sink option" return -1 } set tcp $opts(transport) set sink $opts(sink) set src $opts(src) if { $src == -1 } { puts "you left out the source..!! using FTP" set src FTP } # check location of stubs (src and dest) $self check-TCP-location set num [$self calc-num $opts(num)] # we open the file in append mode since we allow # multiple agents commands in one script... set f [open $opts(outfile) a] set str [$self preamble-tcp] puts $f "$str" # may add topological semantics for src,dst # placemnt .. later.. for now use all (i.e. # randomize over all nodes) # set str [$self generate-tcp-agents $tcp $src \ # $sink $num all] set str [$self generate-tcp-agents $tcp $src $sink $num] puts $f "$str" set start $opts(start) set stop $opts(stop) set str [$self generate-src-start $start $stop $num] puts $f "$str" flush $f close $f } # can merge the checks in check-$type proc..later "SRM" { # may want to add a check on multicast and # either assign default mrouting, or flag an # error if mrouting is not enabled # if left out, use SRM default if { [$self check-srm $opts(transport)] == -1 } { puts "invalid or unsupported srm option" return -1 } set srm $opts(transport) set num [$self calc-num $opts(num)] set srcnum [$self calc-num $opts(srcnum)] $self check-SRM-location set f [open $opts(outfile) a] set str [$self preamble-srm] puts $f "$str" set src $opts(src) set traffic $opts(traffic) #set str [$self generate-srm-agents $srm $num $srcnum $src $traffic all] set str [$self generate-srm-agents $srm $num \ $srcnum $src $traffic] puts $f "$str" # may want to check on these values.. later X set join $opts(join) set leave $opts(leave) set start $opts(start) set stop $opts(stop) set str [$self generate-srm-patterns $join \ $leave $num $start $stop $srcnum] puts $f "$str" flush $f close $f } "-1" { puts "transport was not specified !!" # should we return for now return -1 } default { puts "unknown or unsupported transport \"$opts(transport)\"" return -1 } } }AgentGen instproc check-tcp { type } { set tcps { "" /Reno /NewReno /Sack1 /Vegas /Fack /FullTcp } foreach tcp $tcps { if { $type == "TCP$tcp" } { return 1 } } return -1}AgentGen instproc check-tcp-sink { sink } { set sinks { TCPSink TCPSink/DelAck TCPSink/Sack1 \ TCP/Sink/Sack1/DelAck FullTcp } foreach snk $sinks { if { $snk == $sink } { return 1 } } return -1}AgentGen instproc create-stub-location { type } { $self instvar opts set loc $opts($type) if {$loc == -1} { puts "\nLocation not specified: using randomized distribution for $type\n" } else { foreach L [split $loc ,] { set S [split $L -] if {[llength $S] == 2} { for {set x [lindex $S 0]} {$x <= [lindex $S 1]} {incr x} { lappend opts($type-list) $x } } else { lappend opts($type-list) [lindex $S 0] } } #puts "list of $type - [list $opts($type-list)]" } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -