-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstat-collector.tcl
More file actions
68 lines (61 loc) · 2.58 KB
/
stat-collector.tcl
File metadata and controls
68 lines (61 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Author : Hari Balakrishnan
# Class that encapsulates all statistics collection.
Class StatCollector
StatCollector instproc init {id ctype} {
$self set srcid_ $id
$self set ctype_ $ctype; # type of congestion control / tcp
$self set numbytes_ 0
$self set ontime_ 0.0; # total time connection was in ON state
$self set cumrtt_ 0.0
$self set rtt_samples_ {}
$self set nsamples_ 0
$self set nconns_ 0
}
StatCollector instproc showstats {final id} {
global opt
set res [$self results]
set totalbytes [lindex $res 0]
set totaltime [lindex $res 1]
set totalrtt [lindex $res 2]
set nsamples [lindex $res 3]
set nconns [lindex $res 4]
set all_rtt_samples [lindex $res 5]
if { $nsamples > 0.0 } {
set avgrtt [expr 1000*$totalrtt/$nsamples]
} else {
set avgrtt 0.0
}
set reqd_index [expr round (floor ($nsamples * 0.95)) ]
set sorted [lsort $all_rtt_samples]
set rtt95th [expr [lindex $sorted $reqd_index] * 1000]
if { $totaltime > 0.0 } {
set throughput [expr 8.0 * $totalbytes / $totaltime]
set utility [expr log($throughput) - [expr log($rtt95th)]]
if { $final == True } {
puts [ format "FINAL id %d bytes %d mbps %.3f avgrtt %.1f rtt-95th %.1f on_percentage %.4f utility %.2f num_connections %d nsamples %d" $id $totalbytes [expr $throughput/1000000.0] $avgrtt $rtt95th [expr 100.0*$totaltime/$opt(duration)] $utility $nconns $nsamples ]
} else {
puts [ format "----- id %d bytes %d mbps %.3f avgrtt %.1f rtt-95th %.1f on_percentage %.4f utility %.2f num_connections %d nsamples %d" $id $totalbytes [expr $throughput/1000000.0] $avgrtt $rtt95th [expr 100.0*$totaltime/$opt(duration)] $utility $nconns $nsamples ]
}
}
}
StatCollector instproc update {newbytes newtime cumrtt nsamples rtt_samples} {
global ns opt
$self instvar srcid_ numbytes_ ontime_ cumrtt_ nsamples_ nconns_ rtt_samples_
incr numbytes_ $newbytes
set ontime_ [expr $ontime_ + $newtime]
set cumrtt_ [expr $cumrtt_ + $cumrtt]
incr nsamples_ $nsamples
set rtt_samples_ $rtt_samples
incr nconns_
if {$opt(verbose)} {
puts [format "%.2f: updating stats $srcid_: $newbytes %.2f %.3f $nsamples" [$ns now] $newtime $cumrtt]
puts [format "%.2f: Total so far: $numbytes_ %.2f %.3f $nsamples_" [$ns now] $ontime_ $cumrtt_]
}
if { $opt(partialresults) } {
$self showstats False
}
}
StatCollector instproc results { } {
$self instvar numbytes_ ontime_ cumrtt_ nsamples_ nconns_ rtt_samples_
return [list $numbytes_ $ontime_ $cumrtt_ $nsamples_ $nconns_ $rtt_samples_]
}