📄 topo-gen.tcl
字号:
$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 the outfile name !!.. use "topology -h" for help}
return
}
$self create-topology
}
# XXX to be extended to include stubs... and other topo info
TG instproc setNodes { type num } {
$self instvar nodes
set nodes($type) $num # puts "nodes($type) = $nodes($type)" # now we stor nodes(all) x
# should be able to store nodes(stub1) x1-x2
# keep track of the num of stubs... etc
}
TG instproc getNodes { type } {
$self instvar nodes
if { ![info exists nodes($type)]} { puts "error: $type doesnot exist! Check srcstub/deststub arguments" exit } return $nodes($type)
}TG/itm instproc create-topology { } {
$self instvar opts
# initialize the seed if not given
if { $opts(seed) == -1 } { set opts(seed) [ns-random]
} puts "type $opts(type), seed $opts(seed)"
switch $opts(type) {
"random" {
# compose the filename
set i 0
while { 1 } {
# avoid clashing with prev files, incr i
set topo_filename rand-$opts(nodes)-$i
if ![file exists $topo_filename] {
break
}
incr i
}
set topo_file [open $topo_filename w]
# write to a file in GA tech format
# for now generate 1 graph,...
# check the scale, if not give, assign # of nodes
if { $opts(scale) == -1 } {
set opts(scale) $opts(nodes)
}
$self setNodes all $opts(nodes)
puts "nodes $opts(nodes), scale $opts(scale), \
method $opts(method)"
puts "conn prob $opts(connection_prob), beta \
$opts(beta), gamma $opts(gamma)"
puts $topo_file "geo $opts(number) $opts(seed)"
set str [$self rand-line $opts(nodes) $opts(scale) \
$opts(method) $opts(connection_prob) $opts(beta) \
$opts(gamma)]
puts $topo_file $str
}
"transit_stub" {
# filename
set i 0
while { 1 } {
# avoid clashing with prev files, incr i
set topo_filename ts-$opts(transit_domains)-$opts(transit_nodes)-$i
if ![file exists $topo_filename] {
break
}
incr i
}
set topo_file [open $topo_filename w]
# debugging stuff !!!
puts "stubs per transit $opts(stubs_per_transit), \
ts extra $opts(ts_extra_edges), ss extra $opts(ss_extra_edges)"
puts "transit domains $opts(transit_domains), \
domains_scale $opts(domains_scale), domains_method \
$opts(domains_method)"
puts "domains_conn $opts(domains_connection_prob), \
beta $opts(domains_beta), gamma $opts(domains_gamma)"
puts "transit_nodes $opts(transit_nodes), \
transit_scale $opts(transit_scale), \
transit_method $opts(transit_method)"
puts "transit prob $opts(transit_connection_prob) \
transit_beta $opts(transit_beta), \
transit_gamma $opts(transit_gamma)"
puts "stub_nodes $opts(stub_nodes), \
stub_method $opts(stub_method), \
stub_conn $opts(stub_connection_prob) \
stub_beta $opts(stub_beta) \
stub_gamma $opts(stub_gamma)"
set total_nodes [expr $opts(transit_domains) * \
$opts(transit_nodes) * [expr 1 + $opts(stubs_per_transit) \
* $opts(stub_nodes)]]
puts "Total nodes = $total_nodes\n"
#check if number of nodes specified is diff from # the total nodes after computation. if {$opts(nodes) != $total_nodes} { puts "\n ERROR: Nodes specified = $opts(nodes) \nActual number of total nodes = $total_nodes \nFor transit_stub type, specify value of \"transit_domains\", \"transit_nodes\", \"stubs_per_transit\" and \"stub_nodes\" to change the number of nodes in your topology\n" exit 1 } $self setNodes all $total_nodes
puts $topo_file "ts $opts(number) $opts(seed)"
puts $topo_file "$opts(stubs_per_transit) \
$opts(ts_extra_edges) $opts(ss_extra_edges)"
set str [$self rand-line $opts(transit_domains) \
$opts(domains_scale) $opts(domains_method) \
$opts(domains_connection_prob) $opts(domains_beta) \
$opts(domains_gamma)]
puts $topo_file $str
set str [$self rand-line $opts(transit_nodes) \
$opts(transit_scale) $opts(transit_method) \
$opts(transit_connection_prob) $opts(transit_beta) \
$opts(transit_gamma)]
puts $topo_file $str
set str [$self rand-line $opts(stub_nodes) \
$opts(stub_scale) $opts(stub_method) \
$opts(stub_connection_prob) $opts(stub_beta) \
$opts(stub_gamma)]
puts $topo_file $str
}
default {
puts "invalid type \"$opts(type)\"!! use \"topology -h\" for help"
return
}
}
flush $topo_file
close $topo_file
$self generate-topo-gatech $topo_filename
# cleanup if you want.. uncomment the next line !
# exec rm $topo_filename
# call the converter 'number' times
# no need for this loop if number is always 1 .. XXX
for { set i 0 } { $i < $opts(number) } { incr i } {
# output file is appended by -i.gb
$self convert-to-ns $topo_filename-$i.gb $opts(outfile) $opts(type) }
# clean up... not sure if the file is needed by hierarchical addressing
# exec rm $topo_filename-0.gb
}
TG/itm instproc rand-line { nodes scale method conn_prob beta gamma } {
lappend str $nodes $scale
switch $method {
"waxman1" {
# need alpha and beta
lappend str 1 $conn_prob $beta
}
"waxman2" {
lappend str 2 $conn_prob $beta
}
"pure-random" {
# needs only alpha
lappend str 3 $conn_prob
}
"doar-leslie" {
# alpha, beta and gamma... X seems to use only alpha !
lappend str 4 $conn_prob $beta $gamma
}
"exponential" {
# alpha .. XXX doesn't work now !!
lappend str 5 $conn_prob
}
"locality" {
# alpha , beta and gamma
lappend str 6 $conn_prob $beta $gamma
}
default {
puts "unidentified method $method .. aborting !!"
usage
return
}
}
# puts "str $str"
return $str
}
TG/itm instproc generate-topo-gatech { fn } { exec itm $fn}
TG/itm instproc convert-to-ns { fn outfile type} {
# to avoid generating false errors if sgb2ns is careless
# about its return/exit value # # topofile generated by sgb2hierns program; has topology info used by # topogen and agentgen # So If type permits, read in topofile and cleanup. # if {$type == "transit_stub"} { set topofile $outfile.topoinfo catch { exec sgb2hierns $fn $outfile $topofile } $self getTopoInfo $topofile #exec rm $topofile return } catch { exec sgb2ns $fn $outfile}}## Read in topology info from topo.$outfile#TG/itm instproc getTopoInfo topofile { set input [open $topofile r] foreach line [split [read $input] \n] { set stream [split $line] switch [lindex $stream 0] { "transits" {$self getLine $stream "transit"} "total-stubs" {$self setNodes "total-stubs" [lindex $stream 1]} "stubs" {$self getLine $line "stub"} "nodes/stub" {$self getLine $line "nodes/stub"} } } close $input}## Read each line and store away topoinfo#TG/itm instproc getLine {line type} { $self instvar nodes for {set i 1} {$i < [llength $line]} {incr i} { if {$type == "nodes/stub"} { set start $nodes(stub$i) set range [lindex $line $i] # puts "start=$start range=$range" $self setNodes stub$i $start:[expr $start + $range - 1] } else { $self setNodes $type$i [lindex $line $i] } }}proc comment { } {
puts {
* itm.c -- Driver to create graphs using geo(), geo_hier(), and transtub().
*
* Each argument is a file containing ONE set of specs for graph generation.
* Such a file has the following format:
* <method keyword> <number of graphs> [<initial seed>]
* <method-dependent parameter lines>
* Supported method names are "geo", "hier", and "ts".
* Method-dependent parameter lines are described by the following:
* <geo_parms> ::=
* <n> <scale> <edgeprobmethod> <alpha> [<beta>] [<gamma>]
* <"geo" parms> ::= <geo_parms>
* <"hier" parms> ::=
* <number of levels> <edgeconnmethod> <threshold>
* <geo_parms>+ {one per number of levels}
* <"ts" parms> ::=
* <# stubs/trans node> <#t-s edges> <#s-s edges>
* <geo_parms> {top-level parameters}
* <geo_parms> {transit domain parameters}
* <geo_parms> {stub domain parameters}
*
* Note that the stub domain "scale" parameter is ignored; a fraction
* of the transit scale range is used. This fraction is STUB_OFF_FACTOR,
* defined in ts.c.
*
* From the foregoing, it follows that best results will be obtained with
* -- a SMALL value for top-level scale parameter
* -- a LARGE value for transit-level scale parameter
* and then the value of stub-level scale parameter won't matter.
*
* The indicated number of graphs is produced using the given parameters.
* If the initial seed is present, it is used; otherwise, DFLTSEED is used.
*
* OUTPUT FILE NAMING CONVENTION:
* The i'th graph created with the parameters from file "arg" is placed
* in file "arg-i.gb", where the first value of i is zero.
}
}
###############################################################
### the scenario generator keeps track of topology generator ##
### and can be queried to get this info ##
###############################################################
Class ScenGen
ScenGen set TG ""
ScenGen proc setTG { tg } {
ScenGen set TG $tg
}
ScenGen proc getTG { } {
return [ScenGen set TG]
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -