Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

computing average throughput for 500 values

Status
Not open for further replies.

BabyPinky8888

Programmer
Feb 24, 2009
10
0
0
US
Hi Folks:

I need to compute the average for 500 values of throughputs in a file.. I am wanting to do it in TCL script.. any suggestions ?

my code is as follows just in case u wanted to see what i have done..! Please assist


source /home/kbhaskaran/ns2/ns-allinone-2.33/ns-2.33/obs-0.9a/tcl/lib/ns-obs-lib.tcl
source /home/kbhaskaran/ns2/ns-allinone-2.33/ns-2.33/obs-0.9a/tcl/lib/ns-obs-defaults.tcl
source /home/kbhaskaran/ns2/ns-allinone-2.33/ns-2.33/obs-0.9a/tcl/lib/ns-optic-link.tcl


StatCollector set debug_ 1
Classifier/BaseClassifier/EdgeClassifier set type_ 0
Classifier/BaseClassifier/CoreClassifier set type_ 1
Classifier/BaseClassifier set nfdl 16
Classifier/BaseClassifier set fdldelay 0.000
Classifier/BaseClassifier set maxfdls 5
Classifier/BaseClassifier set ebufoption 0
#no FDLs:
Classifier/BaseClassifier set option 0
OBSFiberDelayLink set FDLdelay 0.0

#Tcp Flow

set tcpflow 4

#bandwidth (bps) that EACH channel gets
set bwpc 1000000000
set delay .5ms
#number of control channels
set ncc 4
#number of data channels
set ndc 4

#burst assembly time (s)
BurstManager bursttimeout 0.003
#burst size threshold (bytes)
#1000000 (1MB)
BurstManager maxburstsize 50000

#.000001 (1us)
BurstManager offsettime 0.00004
Classifier/BaseClassifier/CoreClassifier set bhpProcTime .000001
Classifier/BaseClassifier/EdgeClassifier set bhpProcTime .000001


Agent/TCP set packetSize_ 1000
Agent/TCP set window_ 10000
Agent/TCP set max_ssthresh_ 512
Agent/TCP set windowOption_ 8


#simulator object
set ns [new Simulator]
#stat collector
set sc [new StatCollector]

#Kavitha

set trace [open trace1a.tr w]

for { set i 0 } { $i < $tcpflow } { incr i } {
set cwn($i) [open cwnd$i.tr w]
set tp($i) [open tp$i.tr w]
}


$ns trace-all $trace


#called when the simulation is complete
proc finish {} {

global ns sc bytes


#display the stats
$sc display-sim-list

puts "done"
exit 0
}




#add method create topology to simulator object
proc create_topology { } {
global E C ns tcpSrc cwnd bytes
global bwpc ncc ndc delay


set edge_count 6
set core_count 2

for { set i 0 } { $i < $edge_count } { incr i } {
set E($i) [$ns create-edge-node $edge_count]
}

for { set i 0 } { $i < $core_count } { incr i } {
set C($i) [$ns create-core-node $core_count]
}


set maxch [expr $ncc + $ndc]
$ns createDuplexFiberLink $E(0) $C(0) $bwpc 1ms $ncc $ndc $maxch
$ns createDuplexFiberLink $C(0) $E(1) $bwpc 1ms $ncc $ndc $maxch
$ns createDuplexFiberLink $E(2) $C(0) $bwpc 1ms $ncc $ndc $maxch
$ns createDuplexFiberLink $C(0) $C(1) $bwpc 5ms $ncc $ndc $maxch
$ns createDuplexFiberLink $C(1) $E(3) $bwpc 1ms $ncc $ndc $maxch
$ns createDuplexFiberLink $C(1) $E(4) $bwpc 1ms $ncc $ndc $maxch
$ns createDuplexFiberLink $C(1) $E(5) $bwpc 1ms $ncc $ndc $maxch


$ns build-routing-table
}

#writes all the data to the trace files

proc record { } {

global ns tcp sink cwn tp sink
global tcpflow
set time 0.5
set now [$ns now]


$ns at [expr $now + $time] "record"


for { set i 0 } { $i < $tcpflow } { incr i } {

set cwd_val($i) [$tcp($i) set cwnd_]
set byte($i) [$sink($i) set bytes_]

puts $cwn($i) "$now $cwd_val($i)"

if { $now > 0 } {
set tp1($i) [expr $byte($i)/$now]
puts "$bytes($i)"
puts $tp($i) "$now $tp1($i)"
$sink($i) set bytes_ 0

}
}

}


proc create-tcp-connection { tcp_type sink_type source_node dest_node ns_object } {

set tcpSource [new Agent/$tcp_type]
set tcpSink [new Agent/$sink_type]

$ns_object attach-agent $source_node $tcpSource
$ns_object attach-agent $dest_node $tcpSink

set ftp [new Application/FTP]
$ftp attach-agent $tcpSource

$ns_object connect $tcpSource $tcpSink
return [list $tcpSource $tcpSink $ftp]



}


proc setup-flows {} {
global E
global ns
global tcpflow
global tcp sink


for { set i 0 } { $i < $tcpflow} { incr i } {

set make_tcp_conn [create-tcp-connection "TCP/Sack1" "TCPSink/Sack1" $E(0) $E(3) $ns]
set make_tcp_conn1 [create-tcp-connection "TCP/Sack1" "TCPSink/Sack1" $E(1) $E(4) $ns]
set tcp($i) [lindex $make_tcp_conn 0]
set sink($i) [lindex $make_tcp_conn 1]
$ns at 0.0 "[lindex $make_tcp_conn 2] start "
}

}


create_topology
setup-flows


$ns at 0.0 "record"
$ns at 500 "finish"
$ns run
 
BabyPinky8888 said:
I need to compute the average for 500 values of throughputs in a file.. I am wanting to do it in TCL script.. any suggestions ?

my code is as follows just in case u wanted to see what i have done..!

But I don't see, which part of your code deals with the average from a file? Please post only the relevant part of code.
 
I really don't have the energy right now to figure out exactly what you're doing, but maybe I can offer a suggestion anyway.

You say:
values of throughputs

I infer from that that somewhere in your script you are putting some measurement through your system. I would isolate that process in a proc (that can call other procs of course). Then, in that isolated proc, take the time at the start (with clock seconds). At the end, subtract that from another clock seconds and append the difference (elapsed time) to a list in the global scope. Once you're done, you can average the elements of the list.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top