📄 ns-trafficgen.tcl
字号:
} if {![info exists opts_(client-nodes-r:$node)]} { set cs_r_($node) [$ns_ node] } else { set cs_r_($node) $opts(client-nodes-r:$node) } # Set delay. set delay $opts_(client-delay) if {$delay == "random"} { set delay [$rng_ exponential [$ns_ delay_parse $opts_(client-delay-range)]] } # Now divide the delay into the two haves and set up the network. set ldelay [$rng_ uniform 0 $delay] set rdelay [expr $delay - $ldelay] my-duplex-link $ns_ $cs_l_($node) $bottle_l_ $opts_(client-bw) $ldelay $opts_(client-queue-method) $opts_(client-queue-length) my-duplex-link $ns_ $cs_r_($node) $bottle_r_ $opts_(client-bw) $rdelay $opts_(client-queue-method) $opts_(client-queue-length) # Add routing in all directions $cs_l_($node) add-route-to-adj-node -default $bottle_l_ $cs_r_($node) add-route-to-adj-node -default $bottle_r_ $bottle_l_ add-route-to-adj-node $cs_l_($node) $bottle_r_ add-route-to-adj-node $cs_r_($node) if {$opts_(debug)} { # puts "t=[format %.3f $now]: node pair $node created" # puts "delay $delay ldelay $ldelay" }}# Get the number of the node pairTrafficGen/ManyTCP instproc get_node_number { client_number } { $self instvar opts_ if {$opts_(node-number) > 0} { set node [expr $client_number % $opts_(node-number)] } else { set node $client_number } return $node}# return the client indexTrafficGen/ManyTCP instproc create_a_client {} { $self instvar opts_ cs_l_ cs_r_ sources_ cs_count_ ns_ rng_ # Get the client number for the new client. set now [$ns_ now] set i $cs_count_ incr cs_count_ set node $i if {[expr $i % 100] == 0} { puts "t=[format %.3f $now]: client $i created" } # Get the source and sink nodes. if {$opts_(node-number) > 0} { if {$node < $opts_(node-number) } { $self create_client_nodes $node } else { set node [$self get_node_number $i] } } else { $self create_client_nodes $node } if {$opts_(debug)} { # puts "t=[format %.3f $now]: client $i uses node pair $node" } # create sources and sinks in both directions # (actually, only one source per connection, for now) if {[$rng_ integer 100] < $opts_(client-reverse-chance)} { set sources_($i) [$ns_ create-connection-list $opts_(source-tcp-method) $cs_r_($node) $opts_(sink-ack-method) $cs_l_($node) $i] } else { set sources_($i) [$ns_ create-connection-list $opts_(source-tcp-method) $cs_l_($node) $opts_(sink-ack-method) $cs_r_($node) $i] } [lindex $sources_($i) 0] set maxpkts_ 0 [lindex $sources_($i) 0] set packetSize_ $opts_(client-pkt-size) # Set up a callback when this client ends. [lindex $sources_($i) 0] proc done {} "$self finish_a_client $i" if {$opts_(debug)} { # puts "t=[$ns_ now]: client $i created" } return $i}## Make a batch of clients to amortize the cost of routing recomputation# (actually no longer improtant).#TrafficGen/ManyTCP instproc create_some_clients {} { $self instvar opts_ idle_clients_ ns_ cs_count_ set now [$ns_ now] set step 16 if {$opts_(debug)} { puts "t=[format %.3f $now]: creating clients $cs_count_ to [expr $cs_count_ + $step - 1]" } for {set i 0} {$i < $step} {incr i} { lappend idle_clients_ [$self create_a_client] } # debugging: # puts "after client_create:" # $ns_ gen-map # $self instvar bottle_l_ bottle_r_ # puts "bottle_l_ classifier_:" # [$bottle_l_ set classifier_] dump # puts "bottle_r_ classifier_:" # [$bottle_r_ set classifier_] dump}TrafficGen/ManyTCP instproc start_a_client {} { $self instvar opts_ idle_clients_ ns_ sources_ rng_ \ source_start_ source_size_ clients_started_ set i "" set now [$ns_ now] # can we reuse a dead client? if {![info exists idle_clients_]} { set idle_clients_ "" } while {$idle_clients_ == ""} { $self create_some_clients } set i [lindex $idle_clients_ 0] set idle_clients_ [lrange $idle_clients_ 1 end] # Reset the connection. [lindex $sources_($i) 0] reset [lindex $sources_($i) 1] reset # Start traffic for that client. if {[$rng_ integer 100] < $opts_(client-mouse-chance)} { set len $opts_(client-mouse-packets) } else { set len $opts_(client-elephant-packets) } [lindex $sources_($i) 0] advanceby $len set source_start_($i) $now set source_size_($i) $len if {$opts_(debug)} { # puts "t=[$ns_ now]: client $i started, ldelay=[format %.6f $ldelay], rdelay=[format %.6f $rdelay]" puts "t=[format %.3f $now]: client $i started" } incr clients_started_}TrafficGen/ManyTCP instproc finish_a_client {i} { $self instvar opts_ ns_ idle_clients_ source_start_ source_size_ \ clients_finished_ set now [$ns_ now] if {$opts_(debug)} { set delta [expr $now - $source_start_($i)] puts "t=[format %.3f $now]: client $i finished ($source_size_($i) pkts, $delta s)" } lappend idle_clients_ $i incr clients_finished_}TrafficGen/ManyTCP instproc schedule_continuing_traffic {} { $self instvar opts_ ns_ rng_ $self start_a_client # schedule the next one set next [expr [$ns_ now]+([$rng_ exponential]/$opts_(client-arrival-rate))] if {$opts_(debug)} { # puts "t=[$ns_ now]: next continuing traffic at $next" } $ns_ at $next "$self schedule_continuing_traffic"}TrafficGen/ManyTCP instproc schedule_initial_traffic {} { $self instvar opts_ idle_clients_ # Start with no pending clients. # Start initial clients. for {set i 0} {$i < $opts_(initial-client-count)} {incr i} { $self start_a_client }}TrafficGen/ManyTCP instproc open_trace { stop_time } { $self instvar opts_ ns_ trace_file_ nam_trace_file_ \ trace_filename_ set trace_filename_ $opts_(trace-filename) exec rm -f "$trace_filename_.tr" set trace_file_ [open "$trace_filename_.tr" w] set stop_actions "close $trace_file_" if {$opts_(namtrace-some) || $opts_(namtrace-all)} { exec rm -f "$trace_filename_.nam" set nam_trace_file_ [open "$trace_filename_.nam" w] set $stop_actions "$stop_actions; close $nam_trace_file_" } else { set nam_trace_file_ "" } $ns_ at $stop_time "$stop_actions; $self finish" return "$trace_file_ $nam_trace_file_"}# There seems to be a problem with the foll function, so quit plotting # with -a -q, use just -a.TrafficGen/ManyTCP instproc finish {} { $self instvar opts_ fmon_ trace_filename_ ns_ cs_count_ \ clients_started_ clients_finished_ puts "total clients started: $clients_started_" puts "total clients finished: $clients_finished_" if {$opts_(print-drop-rate)} { set drops [$fmon_ set pdrops_] set pkts [$fmon_ set parrivals_] puts "total_drops $drops total_packets $pkts" set droprate [expr 100.0*$drops / $pkts ] puts [format "drop_percentage %7.4f" $droprate] } if {$opts_(trace-filename) != "none"} { set title $opts_(title) set flow_factor 1 if {$opts_(graph-scale) == "2"} { set flow_factor 100 } # Make sure that we run in place even without raw2xg in our path # (for the test suites). set raw2xg raw2xg if [file exists ../../bin/raw2xg] { set raw2xg ../../bin/raw2xg } set raw2xg_opts "" if {$opts_(graph-join-queueing)} { set raw2xg_opts "$raw2xg_opts -q" } # always run raw2xg because maybe we need the output set cmd "$raw2xg -a $raw2xg_opts -n $flow_factor < $trace_filename_.tr >$trace_filename_.xg" eval "exec $cmd" if {$opts_(graph-results)} { if {$opts_(graph-join-queueing)} { exec xgraph -t $title < $trace_filename_.xg & } else { exec xgraph -tk -nl -m -bb -t $title < $trace_filename_.xg & } } if {$opts_(test-suite)} { exec cp $trace_filename_.xg $opts_(test-suite-file) } # exec raw2xg -a < out.tr | xgraph -t "$opts_(server-tcp-method)" & } if {$opts_(mem-trace)} { $ns_ clearMemTrace } exit 0}TrafficGen/ManyTCP instproc trace_stuff {} { $self instvar opts_ bottle_l_ bottle_r_ ns_ trace_file_ \ nam_trace_file_ $self open_trace $opts_(duration) if {$opts_(trace-all)} { $ns_ trace-all $trace_file_ } if {$opts_(namtrace-all)} { $ns_ namtrace-all $nam_trace_file_ } elseif {$opts_(namtrace-some)} {# xxx $bottle_l_ dump-namconfig $bottle_r_ dump-namconfig [$ns_ link $bottle_l_ $bottle_r_] dump-namconfig $ns_ namtrace-queue $bottle_l_ $bottle_r_ $nam_trace_file_ $ns_ namtrace-queue $bottle_r_ $bottle_l_ $nam_trace_file_ } # regular tracing. # trace left-to-right only $ns_ trace-queue $bottle_l_ $bottle_r_ $trace_file_ $ns_ trace-queue $bottle_r_ $bottle_l_ $trace_file_ # Currently tracing is somewhat broken because # of how the plumbing happens.}TrafficGen/ManyTCP instproc start {} { $self instvar ns_ opts_ if {$opts_(trace-filename) == "none"} { $ns_ at $opts_(duration) "$self finish" } else { $self trace_stuff } if {$opts_(gen-map)} { $ns_ gen-map } $self schedule_initial_traffic if {$opts_(client-arrival-rate) != 0} { $self schedule_continuing_traffic } if {$opts_(gen-map)} { $ns_ gen-map } Agent/TCP set syn_ true Agent/TCP set delay_growth_ true Agent/TCP set windowInit_ 1 Agent/TCP set windowInitOption_ 1 if {$opts_(init-win) == "0"} { Agent/TCP set windowInitOption_ 2 } elseif {$opts_(init-win) == "10"} { Agent/TCP set windowInitOption_ 1 Agent/TCP set windowInit_ 10 } elseif {$opts_(init-win) == "20"} { Agent/TCP set windowInitOption_ 1 Agent/TCP set windowInit_ 20 puts "init-win 20" }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -