1
2 #provide TrafficSource
3 #provide TrafficSink
4
5 TrafficSink set npkts_ 0
6 TrafficSink set ndrops_ 0
7 TrafficSink set nmisordered_ 0
8
9 TrafficSink instproc init { } {
10 $self next
11
12 $self instvar periodic_interval_ gain_
13 set periodic_interval_ 1000
14 set gain_ 0.125
15
16 after $periodic_interval_ "$self periodic"
17 }
18
19 TrafficSink instproc periodic { } {
20 $self instvar periodic_interval_ gain_
21 global srcinfo
22
23 foreach s [$self sources] {
24 set L [split $s /]
25 set stats [$self srcinfo [lindex $L 0] [lindex $L 1]]
26
27 if ![info exists srcinfo($s,pkts)] {
28 rate_variable srcinfo($s,rate) $gain_
29 rate_variable srcinfo($s,lossrate) $gain_
30 set srcinfo($s,pkts) 0
31 set srcinfo($s,drops) 0
32 }
33
34 set npkts [lindex $stats 0]
35 set nbytes [lindex $stats 1]
36 set ndrops [lindex $stats 2]
37 set pktdiff [expr $npkts - $srcinfo($s,pkts)]
38 set lossdiff [expr $ndrops - $srcinfo($s,drops)]
39 if { $pktdiff == 0 } {
40 set loss 0
41 } else {
42 set loss [expr 100. * $lossdiff / $pktdiff]
43 }
44
45 set srcinfo($s,pkts) $npkts
46 set srcinfo($s,drops) $ndrops
47 set srcinfo($s,rate) [expr 8 * $nbytes]
48 set srcinfo($s,lossrate) $loss
49 }
50
51 after $periodic_interval_ "$self periodic"
52 }
53
54 TrafficSink instproc get-all-stats { } {
55 global srcinfo
56
57 set L ""
58 foreach key [array names srcinfo "*,pkts"] {
59 set s [lindex [split $key ,] 0]
60 lappend L [list $s $srcinfo($s,pkts) $srcinfo($s,drops) \
61 $srcinfo($s,rate) $srcinfo($s,lossrate)]
62 }
63 return $L
64 }
65
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.