#Create a simulator object set ns [new Simulator] #Define different colors for data flows $ns color 1 Blue $ns color 2 Red #Open the nam trace file set nf [open out.nam w] set ng1 [open fq_test1.tr w] set ng2 [open fq_test2.tr w] set ng3 [open fq_test3.tr w] set tr [open out.tr w] $ns trace-all $tr $ns namtrace-all $nf proc record {} { global sink0 sink1 sink2 ng1 ng2 ng3 set ns [Simulator instance] set time 0.05 set bw0 [$sink0 set bytes_] set bw1 [$sink1 set bytes_] set bw2 [$sink2 set bytes_] set now [$ns now] puts $ng1 "$now [expr $bw0/$time*8/1000000]" puts $ng2 "$now [expr $bw1/$time*8/1000000]" puts $ng3 "$now [expr $bw2/$time*8/1000000]" $sink0 set bytes_ 0 $sink1 set bytes_ 0 $sink2 set bytes_ 0 $ns at [expr $now+$time] "record" } #Define a 'finish' procedure proc finish {} { global ns nf ng $ns flush-trace #Close the trace file close $nf #close $tr #close $ng1 #close $ng2 #close $ng3 #Execute nam on the trace file exec nam out.nam & set f [open temp1.rands w] puts $f "TitleText: Output" puts $f "Device: Postscript" exec rm -f temp1.p temp1.d temp1.p1 sort.tr sortd.tr final.tr \ final1.tr final2.tr result.tr result1.tr result2.tr exec touch temp1.d temp1.p temp1.p1 sort.tr sortd.tr final.tr \ final1.tr final2.tr result.tr result1.tr result2.tr exec awk { { if (($1 == "+" || $1 == "-") && \ ($5 == "cbr"))\ print $2, $8+($11 % 90) * 0.01 } } out.tr >temp1.p exec awk { { if (($1 == "+" || $1 == "-") && \ ($5 == "cbr"))\ print $2, $8, $11 } } out.tr >temp1.p1 exec awk { { if ($1 == "d") print $2, $8 +($11 % 90) * 0.01 } } out.tr >temp1.d exec awk { { if ($1 == "+" || $1 == "-") { if ($3 == "2" && $4 == "3") { #print $1, $2, $3, $4, $5, $6, $7, \ #$8, $9, $10, $11, $12 \ #print $2 print $1, $2, $9, $11, $12 } } } } out.tr >sort.tr #exec sort -t ' ' -k 11,11n -k 12,12n sort.tr > sortd.tr puts $f \"packets flush $f exec cat temp1.p >@ $f flush $f puts $f [format "\n\"skip-1\n0 1\n\n\"skip-2\n0 1\n\n"] puts $f \"drops flush $f exec head -1 temp1.d >@ $f exec cat temp1.d >@ $f close $f #exec sort -t ' ' -k 11,11n -k 12,12n sort.tr -o sortd.tr exec xgraph -bb -tk -nl -m -x time -y packet temp1.rands & exec xgraph fq_test1.tr fq_test2.tr fq_test3.tr -geometry 800x400 & exit 0 } source utils.tcl #Create four nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set sink0 [new Agent/LossMonitor] set sink1 [new Agent/LossMonitor] set sink2 [new Agent/LossMonitor] $ns attach-agent $n3 $sink0 $ns attach-agent $n3 $sink1 $ns attach-agent $n3 $sink2 #Create links between the nodes $ns duplex-link $n0 $n2 10Mb 10ms DropTail $ns duplex-link $n1 $n2 10Mb 10ms DropTail $ns duplex-link $n3 $n2 1000Mb 10ms WF2Q #$ns duplex-link $n4 $n2 0.1Mb 10ms DropTail $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link-op $n2 $n3 orient right set q [$ns get-queue $n3 $n2] #Monitor the queue for the link between node 2 and node 3 $ns duplex-link-op $n2 $n3 queuePos 0.5 #Create a CBR agent and attach it to node n0 set cbr0 [new Agent/CBR] $ns attach-agent $n0 $cbr0 $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 set fid_ 1 #Create a CBR agent and attach it to node n1 set cbr1 [new Agent/CBR] $ns attach-agent $n1 $cbr1 $cbr1 set packetSize_ 500 $cbr1 set interval_ 0.005 $cbr1 set fid_ 2 #Create a Null agent (a traffic sink) and attach it to node n3 set null0 [new Agent/Null] $ns attach-agent $n3 $null0 #Connect the traffic sources with the traffic sink $ns connect $cbr0 $null0 $ns connect $cbr1 $null0 $q set-queue-size 1 250000 $q set-queue-size 2 250000 $q set-flow-weight 1 0.1 $q set-flow-weight 2 0.9 #Schedule events for the CBR agents $ns at 0.0 "record" $ns at 0.5 "$cbr0 start" $ns at 0.6 "$cbr1 start" $ns at 8.0 "$cbr1 stop" $ns at 8.0 "$cbr0 stop" #Call the finish procedure after 5 seconds of simulation time $ns at 10.0 "finish" #Run the simulation $ns run