1 # ui-mgamon.tcl --
2 #
3 # FIXME: This file needs a description here.
4 #
5 # Copyright (c) 1997-2002 The Regents of the University of California.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
10 #
11 # A. Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # B. Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 # C. Neither the names of the copyright holders nor the names of its
17 # contributors may be used to endorse or promote products derived from this
18 # software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #
31 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/mgamon/ui-mgamon.tcl,v 1.37 2002/02/03 04:27:48 lim Exp $
32
33 import TopLevelWindow MeGa AnnounceListenManager/AS/MeGaMon mashutils
34
35 #
36 # The user interface for the "Media Gateway Architecture Monitor".
37 #
38 Class MGAMonUI -superclass TopLevelWindow
39
40 set uniqid 0
41
42 #
43 MGAMonUI instproc init { path } {
44 $self next $path
45
46 $self instvar agenttext_
47
48 $self build $path
49
50 set megaspec [$self get_option asCtrl]
51 set bw [$self get_option asCtrlBW]
52 $self instvar al_
53 foreach m { audio video sdp mb hm mars} {
54 set spec [MeGa ctrlchan $m $megaspec]
55 set al_($m) [new AnnounceListenManager/AS/MeGaMon \
56 $self $spec $bw]
57 }
58 set o [$self get_option doLog]
59 if { $o != "" } {
60 $self instvar log_
61 foreach a [split $o :] {
62 set log_($a) 1
63 }
64 }
65 }
66
67 #
68 MGAMonUI instproc build { w } {
69 $self instvar agenttext_ frames_ agentlist_
70
71 set f [$self get_option smallfont]
72 set mf [$self get_option medfont]
73
74 frame $w.top
75 set rt $w.top.rt
76 frame $rt -relief groove -borderwidth 1
77 frame $rt.gw
78 label $rt.gw.l -text "Gateways" -font $mf
79 pack $rt.gw.l -side top -fill x
80 frame $rt.gw.d
81
82 frame $rt.clients
83 label $rt.clients.l -text "Clients" -font $mf
84 pack $rt.clients.l -side top -fill x
85 frame $rt.clients.d
86
87 foreach t { {srv video VGW} {srv audio AGW} {srv sdp SDGW} \
88 {srv mb MBGW} {srv mars MARS}} {
89 set atype [lindex $t 0]
90 set media [lindex $t 1]
91 set name [lindex $t 2]
92 set w0 $rt.gw.d.f$name
93 frame $w0 -relief groove -borderwidth 2
94 set agentlist_($atype,$media) [new AgentList $w0 $name]
95 pack $w0 -side left -expand 1 -fill both
96 frame $w0.info
97 button $w0.info.b -text "death" -font $f \
98 -command "$self build_death $media"
99 frame $w0.info.glue
100 label $w0.info.l -text "0 agent(s)" -font $f
101 $agentlist_($atype,$media) set numlabel_ $w0.info.l
102 pack $w0.info.b -side left
103 pack $w0.info.glue -side left -fill x -expand 1
104 pack $w0.info.l -side left
105 pack $w0.info -side top -ipady 0 -expand 1 -fill x
106 }
107 pack $rt.gw.d -side top -expand 1 -fill both
108 foreach t { {client,video Video} {client,audio Audio} \
109 {client,sdp SDP} {client,mb MB} {client,mars ROVER}} {
110 set atype [lindex $t 0]
111 set name [lindex $t 1]
112 set w0 $rt.clients.d.f$name
113 frame $w0 -relief groove -borderwidth 2
114 set agentlist_($atype) [new AgentList $w0 $name]
115 pack $w0 -side left -expand 1 -fill both
116 frame $w0.info
117 frame $w0.info.glue
118 label $w0.info.l -text "0 agent(s)" -font $f
119 $agentlist_($atype) set numlabel_ $w0.info.l
120 pack $w0.info.glue -side left -fill x -expand 1
121 pack $w0.info.l -side left
122 pack $w0.info -side top -ipady 0 -expand 1 -fill x
123 }
124 pack $rt.clients.d -side top -expand 1 -fill both
125 pack $rt.gw $rt.clients -side top -expand 1 -fill both
126
127 # Build hm window
128 set left [frame $w.top.left -relief groove -borderwidth 1]
129 frame $left.hm
130 label $left.hm.l -text "Host Managers" -font $mf
131 pack $left.hm.l -side top -fill x -anchor n
132 set w0 $left.hm.d
133 frame $w0 -relief groove -borderwidth 2
134 set agentlist_(hm) [new AgentList $w0 HM]
135 pack $w0 -side left -expand 1 -fill both
136 frame $w0.info
137 button $w0.info.b -text "death" -font $f \
138 -command "$self build_death hm"
139 frame $w0.info.glue
140 label $w0.info.l -text "0 agent(s)" -font $f
141 $agentlist_(hm) set numlabel_ $w0.info.l
142 pack $w0.info.b -side left
143 pack $w0.info.glue -side left -fill x -expand 1
144 pack $w0.info.l -side left
145 pack $w0.info -side top -ipady 0 -fill x
146 pack $left.hm -side top -expand 1 -fill both
147 pack $rt $left -side right -expand 1 -fill both
148
149 set f [$self get_option smallfont]
150 frame $w.bot -relief ridge -borderwidth 2
151 label $w.bot.a -text "Control Address: [$self get_option asCtrl]" \
152 -font $f
153 label $w.bot.l -text "Media Gateway Architecture Monitor v[version] (ASCP v2.0)" \
154 -font $f
155 button $w.bot.quit -text "Quit" -command "exit 0" -font $f \
156 -borderwidth 2
157
158 pack $w.bot.a -side left
159 pack $w.bot.l -side left -expand 1 -fill x
160 pack $w.bot.quit -side right
161 pack $w.top $w.bot -side top -fill both -expand 1
162 }
163
164 #
165 MGAMonUI instproc build_death { atype } {
166
167 $self instvar al_
168 set al $al_($atype)
169
170 set o "ASCP v[AnnounceListenManager/AS version]"
171 set n mgamon
172 set o $o\n$n
173 set n [$al agent_instance]
174 set o $o\n$n
175 set n "DEATH"
176 set o $o\n$n
177 set n $atype
178 set o $o\n$n
179 set n "-"
180 set o $o\n$n
181 set n "-"
182 set o $o\n$n
183
184 $al announce $o
185 }
186
187 #
188 MGAMonUI instproc register { atype aspec addr msg } {
189 $self instvar agentlist_
190
191 set logtype $atype
192 if { $atype == "srv" || $atype == "client" } {
193 if { $msg == "Mars"} {
194 set media $msg
195 if { $media == "" } {
196 return
197 }
198 set mtype "mars"
199 set atype $atype,$mtype
200 } else {
201 set media [lindex [$msg set allmedia_] 0]
202 if { $media == "" } {
203 return
204 }
205 set mtype [$media set mediatype_]
206 set atype $atype,$mtype
207 }
208 } else {
209 set mtype "-"
210 }
211 set l $agentlist_($atype)
212 $l insert_item $atype $aspec $addr $msg
213 update idletasks
214 $self instvar log_
215 if [info exists log_($logtype)] {
216 puts "[gettimeofday] + $aspec $logtype $mtype $addr"
217 }
218 }
219
220 #
221 MGAMonUI instproc unregister { atype aspec addr msg } {
222 $self instvar agentlist_
223
224 set logtype $atype
225 if { $atype == "srv" || $atype == "client"} {
226 if { $msg == "Mars"} {
227 set media $msg
228 if { $media == "" } {
229 return
230 }
231 set mtype "mars"
232 set atype $atype,$mtype
233 } else {
234 set media [lindex [$msg set allmedia_] 0]
235 if { $media == "" } {
236 return
237 }
238 set mtype [$media set mediatype_]
239 set atype $atype,$mtype
240 }
241 } else {
242 set mtype "-"
243 }
244 set l $agentlist_($atype)
245 $l remove_item $aspec
246 update idletasks
247 $self instvar log_
248 if [info exists log_($logtype)] {
249 puts "[gettimeofday] - $aspec $logtype $mtype $addr"
250 }
251 }
252
253 #
254 MGAMonUI instproc recv_msg { atype aspec addr msg delta } {
255 $self instvar agentlist_
256
257 if { $atype == "srv" || $atype == "client" } {
258 if { $msg == "Mars"} {
259 set media $msg
260 if { $media == "" } {
261 return
262 }
263 set mtype "mars"
264 set atype $atype,$mtype
265 } else {
266 set media [lindex [$msg set allmedia_] 0]
267 if { $media == "" } {
268 return
269 }
270 set mtype [$media set mediatype_]
271 set atype $atype,$mtype
272 }
273 }
274
275 set l $agentlist_($atype)
276 $l update_data $aspec $addr $msg $delta
277 update idletasks
278 }
279
280 #
281 Class AgentList
282
283 #
284 AgentList instproc init { w agentname } {
285 $self next
286 $self instvar bottom_ list_ agentname_
287
288 set agentname_ $agentname
289 set bottom_ 2
290
291 set f [$self get_option smallfont]
292
293 $self instvar bottom_
294
295 label $w.title -text "$agentname" -font $f
296 frame $w.bot -relief sunken -borderwidth 1
297 scrollbar $w.bot.scroll -relief groove -borderwidth 2 \
298 -command "$w.bot.list yview" -width 10
299 canvas $w.bot.list -relief groove -borderwidth 0 \
300 -height 160 -width 160 -yscrollcommand "$w.bot.scroll set"
301 pack $w.bot.scroll -side left -fill y
302 pack $w.bot.list -side left -expand 1 -fill both
303
304 pack $w.title -side top -fill x
305 pack $w.bot -side top -fill both -expand 1
306
307 set list_ $w.bot.list
308 }
309
310 #
311 AgentList instproc insert_item { atype aspec addr msg } {
312 $self instvar bottom_ list_ items_ agentname_ entrywin_ numlabel_
313 global uniqid
314 incr uniqid
315 set w .al$uniqid
316 set entrywin_($aspec) \
317 [new AgentEntryWindow/$agentname_ $w $atype $aspec]
318 set f [$self get_option smallfont]
319
320 set id [$list_ create text 5 $bottom_ -font $f -text \
321 "$aspec" -anchor nw]
322 set bottom_ [lindex [$list_ bbox $id] 3]
323 $list_ bind $id <Enter> "$list_ itemconfigure $id -fill red"
324 $list_ bind $id <Leave> "$list_ itemconfigure $id -fill black"
325 $list_ bind $id <ButtonPress> "$entrywin_($aspec) toggle"
326 $list_ bind $id <ButtonRelease-3> "$entrywin_($aspec) toggle"
327 set items_($aspec) $id
328 incr bottom_ 2
329 $list_ config -scrollregion "0 0 2.5i $bottom_"
330 $numlabel_ configure -text "[llength [array names items_]] agent(s)"
331 }
332
333 #
334 AgentList instproc update_data { aspec addr msg delta } {
335 $self instvar entrywin_
336 if [info exists entrywin_($aspec)] {
337 $entrywin_($aspec) update_data $addr $msg $delta
338 }
339 }
340
341 #
342 AgentList instproc remove_item { aspec } {
343 $self instvar items_ list_ bottom_ entrywin_ numlabel_
344 set id $items_($aspec)
345 set thresh [lindex [$list_ coords $id] 1]
346 set bb [$list_ bbox $id]
347 set height [expr [lindex $bb 3] - [lindex $bb 1]]
348 incr height 2
349 $list_ delete $id
350
351 $self adjust_entries $thresh $height
352
353 delete $entrywin_($aspec)
354 unset entrywin_($aspec)
355 unset items_($aspec)
356 $numlabel_ configure -text "[llength [array names items_]] agent(s)"
357 }
358
359 #
360 AgentList instproc adjust_entries { thresh h } {
361 $self instvar items_ list_ bottom_
362 foreach s [array names items_] {
363 set y [lindex [$list_ coords $items_($s)] 1]
364 if { $y > $thresh } {
365 $list_ move $items_($s) 0 -$h
366 }
367 }
368 incr bottom_ -$h
369 $list_ config -scrollregion "0 0 2.5i $bottom_"
370 }
371
372 #
373 Class AgentEntryWindow -superclass TopLevelWindow
374
375 #
376 AgentEntryWindow instproc init { w atype aspec } {
377 $self next $w
378
379 set f [$self get_option smallfont]
380 $self create-window $w "$atype $aspec"
381 label $w.title -text "$atype $aspec" -font $f
382
383 frame $w.data -relief sunken -borderwidth 1
384 $self build_data $w.data
385
386 button $w.dismiss -text Dismiss -command "$self toggle" -font $f
387 pack $w.title -expand 1 -fill x -ipadx 4 -ipady 2 -side top
388 pack $w.data -expand 1 -fill x -side top -ipady 2
389 pack $w.dismiss -side top
390 }
391
392 # A Gateway window for the "Media Gateway Architecture Monitor" user interface.
393 Class AgentEntryWindow/GW -superclass AgentEntryWindow
394
395 # A Session Directory Gateway window for the "Media Gateway Architecture Monitor" user interface.
396 Class AgentEntryWindow/SDGW -superclass AgentEntryWindow/GW
397
398 # A MediaBoard Gateway window for the "Media Gateway Architecture Monitor" user interface.
399 Class AgentEntryWindow/MBGW -superclass AgentEntryWindow/GW
400
401 # A Video Gateway window for the "Media Gateway Architecture Monitor" user interface.
402 Class AgentEntryWindow/VGW -superclass AgentEntryWindow/GW
403
404 # An Audio Gateway window for the "Media Gateway Architecture Monitor" user interface.
405 Class AgentEntryWindow/AGW -superclass AgentEntryWindow/GW
406
407 # A Client window for the "Media Gateway Architecture Monitor" user interface.
408 Class AgentEntryWindow/Client -superclass AgentEntryWindow/GW
409
410 # A Video Client window for the "Media Gateway Architecture Monitor" user interface.
411 Class AgentEntryWindow/Video -superclass AgentEntryWindow/Client
412
413 # An Audio Client window for the "Media Gateway Architecture Monitor" user interface.
414 Class AgentEntryWindow/Audio -superclass AgentEntryWindow/Client
415
416 # A Session Directory Client window for the "Media Gateway Architecture Monitor" user interface.
417 Class AgentEntryWindow/SDP -superclass AgentEntryWindow/Client
418
419 # A Mediaboard Client window for the "Media Gateway Architecture Monitor" user interface.
420 Class AgentEntryWindow/MB -superclass AgentEntryWindow/Client
421
422 # A Host Manager Client window for the "Media Gateway Architecture Monitor" user interface.
423 Class AgentEntryWindow/HM -superclass AgentEntryWindow
424
425 Class AgentEntryWindow/ROVER -superclass AgentEntryWindow/Client
426 Class AgentEntryWindow/MARS -superclass AgentEntryWindow/GW
427
428
429
430 #foreach a { SDGW MBGW VGW AGW Client HM } {
431 # AgentEntryWindow/$a instproc init { w atype aspec } "
432 # \$self next \$w \$atype \$aspec
433 # "
434 #}
435
436 #
437 AgentEntryWindow instproc mkfield { w text id } {
438 set f [$self get_option smallfont]
439 frame $w.$id
440 label $w.$id.l -text "$text=" -font $f
441 label $w.$id.v -text "" -font $f
442 pack $w.$id.l $w.$id.v -side left -anchor w
443 pack $w.$id -side top -anchor w
444
445 return $w.$id.v
446 }
447
448 #
449 AgentEntryWindow/GW instproc build_data { w } {
450 $self instvar fields_ awin_ tstime_ tsfrom_
451 set f [$self get_option smallfont]
452
453 frame $w.d
454 set fields_(o) [$self mkfield $w.d "Agent ID" o]
455 set fields_(s) [$self mkfield $w.d "Session ID" s]
456 set fields_(toolname) [$self mkfield $w.d Tool toolname]
457
458 set s [frame $w.sessions -relief ridge -borderwidth 1]
459 label $s.top -text "Sessions"
460 frame $s.bot -relief sunken -borderwidth 1
461 pack $s.top $s.bot -side top
462 $self set sesswin_ $s.bot
463
464 frame $w.ts
465 $self mkts $w.ts
466 pack $w.d $w.sessions $w.ts -side top -fill x -side top
467 }
468
469 #
470 AgentEntryWindow instproc mkts { w } {
471 $self instvar fields_
472 set fields_(tstime) [$self mkfield $w "Last heard" tstime]
473 set fields_(tsfrom) [$self mkfield $w "Heard from" tsfrom]
474 set fields_(delta) [$self mkfield $w "Delta" delta]
475 }
476
477 #
478 AgentEntryWindow/GW instproc update_data { addr msg delta } {
479 $self instvar fields_ sesswin_ sessions_
480 set i 0
481 $fields_(o) configure -text [join [$msg field_value o] :]
482 $fields_(s) configure -text [join [$msg field_value s] :]
483 $fields_(toolname) configure -text [$msg attr_value tool]
484 $fields_(tstime) configure -text [gettimeofday ascii]
485 $fields_(tsfrom) configure -text $addr
486 $fields_(delta) configure -text $delta
487
488 # Sessions
489 set i 0
490 foreach media [$msg set allmedia_] {
491 if ![info exists sessions_($i)] {
492 set w \
493 [frame $sesswin_.x$i -relief groove -borderwidth 1]
494 set fields_($i,addr) [$self mkfield $w Addr x$i,addr]
495 set sessions_($i) $w
496 pack $w -side top -fill x -expand 1
497 }
498 set tmp [split [$media set caddr_] /]
499 set caddr [lindex $tmp 0]/[$media set port_]/[lindex $tmp 1]
500 $fields_($i,addr) configure -text $caddr
501 incr i
502 }
503 }
504
505 AgentEntryWindow/MARS instproc update_data { addr msg delta } {
506 $self instvar fields_ sesswin_ sessions_
507 set i 0
508 $fields_(o) configure -text ""
509 $fields_(s) configure -text ""
510 $fields_(toolname) configure -text ""
511 $fields_(tstime) configure -text [gettimeofday ascii]
512 $fields_(tsfrom) configure -text $addr
513 $fields_(delta) configure -text $delta
514 set i 0
515 set media "Mars"
516 if ![info exists sessions_($i)] {
517 set w \
518 [frame $sesswin_.x$i -relief groove -borderwidth 1]
519 set fields_($i,addr) [$self mkfield $w Addr x$i,addr]
520 set sessions_($i) $w
521 pack $w -side top -fill x -expand 1
522 }
523 #set tmp [split [$media set caddr_] /]
524 #set caddr [lindex $tmp 0]/[$media set port_]/[lindex $tmp 1]
525 $fields_($i,addr) configure -text ""
526 incr i
527
528 }
529
530
531 #
532 AgentEntryWindow/Client instproc build_data { w } {
533 $self instvar fields_ awin_ tstime_ tsfrom_
534 set f [$self get_option smallfont]
535
536 frame $w.d
537 set fields_(o) [$self mkfield $w.d "Agent ID" o]
538 set fields_(s) [$self mkfield $w.d "Session ID" s]
539 set fields_(global) [$self mkfield $w.d "Global Addr" c]
540 set fields_(local) [$self mkfield $w.d "Local Addr" local]
541 set fields_(toolname) [$self mkfield $w.d Tool toolname]
542 set fields_(sessionbw) [$self mkfield $w.d Bandwidth sessionbw]
543 $fields_(sessionbw) configure -text N/A
544
545 frame $w.ts
546 $self mkts $w.ts
547 pack $w.d $w.ts -side top -fill x -side top
548 }
549
550 #
551 AgentEntryWindow/Client instproc update_data { addr msg delta } {
552 $self instvar fields_ sesswin_ sessions_
553 set i 0
554 $fields_(o) configure -text [join [$msg field_value o] :]
555 $fields_(s) configure -text [join [$msg field_value s] :]
556 $fields_(global) configure -text [$msg set caddr_]
557 $fields_(toolname) configure -text [$msg attr_value tool]
558 $fields_(tstime) configure -text [gettimeofday ascii]
559 $fields_(tsfrom) configure -text $addr
560 $fields_(delta) configure -text $delta
561
562 if [$msg have_field b] {
563 set bwval [$msg set bwval_]
564 set bwval [AgentEntryWindow format_bps $bwval]
565 $fields_(sessionbw) configure -text $bwval
566 }
567
568 set media [$msg set allmedia_]
569 $fields_(local) configure -text [$media set caddr_]
570 }
571
572 AgentEntryWindow/ROVER instproc update_data { addr msg delta } {
573 $self instvar fields_ sesswin_ sessions_
574 set i 0
575 $fields_(o) configure -text ""
576 $fields_(s) configure -text ""
577 $fields_(global) configure -text ""
578 $fields_(toolname) configure -text ""
579 $fields_(tstime) configure -text [gettimeofday ascii]
580 $fields_(tsfrom) configure -text $addr
581 $fields_(delta) configure -text $delta
582 set bwval 0
583 set bwval [AgentEntryWindow format_bps $bwval]
584 $fields_(sessionbw) configure -text $bwval
585
586 $fields_(local) configure -text ""
587 }
588
589 #
590 AgentEntryWindow proc format_bps b {
591 set bps $b
592 if { $bps < 1 } {
593 set bps "0 bps"
594 } elseif { $bps < 1000 } {
595 set bps [format "%3.0f bps" $bps]
596 } elseif { $bps < 1000000 } {
597 set bps [format "%3.0f kb/s" [expr $bps / 1000.]]
598 } else {
599 set bps [format "%.1f Mb/s" [expr $bps / 1000000.]]
600 }
601 return $bps
602 }
603
604 #
605 AgentEntryWindow/HM instproc build_data { w } {
606 $self instvar fields_ awin_ tstime_ tsfrom_
607 set f [$self get_option smallfont]
608
609 frame $w.d
610 # set fields_(o) [$self mkfield $w.d "Agent ID" o]
611
612 frame $w.ts
613 $self mkts $w.ts
614 pack $w.d $w.ts -side top -fill x -side top
615 }
616
617 #
618 AgentEntryWindow/HM instproc update_data { addr msg delta } {
619 $self instvar fields_ sesswin_ sessions_
620 set i 0
621 # $fields_(o) configure -text $aspec_
622 $fields_(tstime) configure -text [gettimeofday ascii]
623 $fields_(tsfrom) configure -text $addr
624 $fields_(delta) configure -text $delta
625 }
626
627
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.