#! /bin/bash set opt(tr) "lan01.tr" set opt(namtr) "lan01.nam" set opt(seed) 0 set opt(stop) 1.2 set opt(node) 6 set opt(qsize) 100 set opt(bw) 10Mb set opt(delay) 1ms set opt(ll) LL set opt(ifq) Queue/DropTail set opt(mac) Mac/802_3 set opt(chan) Channel set opt(tcp) UDP set opt(sink) LossMonitor set opt(app) Traffic/Exponential proc finish {} { global env nshome pwd global ns opt trfd $ns flush-trace close $trfd # exec nam lan01.nam & exec x lan01.x & exec nam lan01.nam & exit 0 } proc interval {} { global ns opt src dst rng for {set i 0} {$i<$opt(node)} {incr i} { set intval [expr [$rng uniform 0.00001 0.0001]] $src($i) set interval_ $intval } set now [$ns now] $ns at [expr $now+$intval] "interval" } set xfd [open "lan01.x" w] global nlost nrecv set nlost 0 set nrecv 0 proc sample {} { global dst ns opt xfd nlost nrecv # set nlost 0 # set nrecv 0 for {set i 0} {$i<$opt(node)} {incr i} { set nlost [expr $nlost+[$dst($i) set nlost_]] set nrecv [expr $nrecv+[$dst($i) set npkts_]] # set now [$ns now] # puts $xfd "$now $nrecv" $dst($i) set nlost_ 0 $dst($i) set npkts_ 0 } set now [$ns now] set total [expr $nlost+$nrecv] if {$total!=0} { # set rate [expr 1.0*$nrecv/$total] # puts "$nlost" set rate [expr 1.0*$nrecv/$total] # puts $xfd "$now $nrecv" puts $xfd "$total $nrecv" } set time [expr $now+0.001] $ns at $time "sample" } proc create-trace {} { global ns opt if [file exists $opt(tr)] { catch "exec rm -f $opt(tr) $opt(tr)-bw [glob $opt(tr).*]" } set trfd [open $opt(tr) w] $ns trace-all $trfd if {$opt(namtr) != ""} { $ns namtrace-all [open $opt(namtr) w] } return $trfd } proc create-topology {} { global ns opt global lan node source node0 set num [expr $opt(node)*2] for {set i 0} {$i < $num} {incr i} { set node($i) [$ns node] lappend nodelist $node($i) } set lan [$ns newLan $nodelist $opt(bw) $opt(delay) \ -llType $opt(ll) -ifqType $opt(ifq) \ -macType $opt(mac) -chanType $opt(chan)] set node0 [$ns node] $ns duplex-link $node0 $node(0) 2Mb 2ms DropTail $ns duplex-link-op $node0 $node(0) orient right } ## MAIN ## set ns [new Simulator] set trfd [create-trace] create-topology for {set i 0} {$i<$opt(node)} {incr i} { set srcdst [$ns create-connection-list UDP $node([expr $i*2]) LossMonitor $node([expr $i*2+1]) 0] set src($i) [lindex $srcdst 0] set dst($i) [lindex $srcdst 1] set app($i) [$src($i) attach-app $opt(app)] $app($i) set burst_time_ 0.05ms $app($i) set idle_time_ 0.01ms $app($i) set rate_ 10Mb $ns at 0.01 "$app($i) start" $ns at 1.0 "$app($i) stop" } $ns at 0.01 "sample" $ns at $opt(stop) "finish" $ns run