proc dmsCreateAlarm {sess} {global DmsPriv Dm_Radio Dm_AlarmIndex
if [catch {dmsRmonCheckEnabled $sess} err] {if {$err != ""} {dm_Prompt .err $err Ok}
return}
set w .alarm
if [winfo exists $w] {wm deiconify $w
raise $w
$w.status config -text ""} else {set DmsPriv(alarmInterval) 10
set Dm_AlarmIndex 1
dm_MakeDlg $w "Insert Alarm" {
			{ComboMenu Variable {}}
			{Radio "Sample Type" {Absolute Delta}}
			{Spin "Sample Interval" 1 DmsPriv(alarmInterval) 3600 "1..3600 (secs)"}
			{Spin Index 1 Dm_AlarmIndex 65535 "1..65535"}}
$w.f.v0 config -width 40
grid config $w.f.f0 -columnspan 2
dmsBuildAlarmMenu $w.f.mb0.m
$w.f.v1.r0 config -value 1
$w.f.v1.r1 config -value 2
set Dm_Radio($w.f.v1) 2
set row 4
foreach lab {"Threshold Type" Value "Event Index" Severity Script} {label $w.f.l$row -text $lab:
grid $w.f.l$row -row $row -column 0 -sticky e
incr row}
loop col 1 3 {set row 4
foreach fType {label entry entry radio entry} {if {$fType == "radio"} {set f [frame $w.f.v$row-$col -class FRadio]
set Dm_Radio($f) 3
loop i 1 6 {pack [radiobutton $f.r$i -text $i -value $i -indicatoron 0 -selectcolor "" -variable Dm_Radio($f)] -side left}} else {$fType $w.f.v$row-$col}
grid $w.f.v$row-$col -row $row -column $col -sticky w -padx 4
incr row}}
$w.f.v4-1 config -text "Rising Value"
$w.f.v4-2 config -text "Falling Value"
$w.f.v6-1 config -width 10
$w.f.v6-1 insert 0 default
$w.f.v6-2 config -width 10
$w.f.v6-2 insert 0 default
$w.fb.ok config -text Insert -command "dmsCreateAlarmCB $w $sess"
button $w.fb.script -text Scripts... -command "dmsRmonAlarmScripts"
pack $w.fb.script -side left -before $w.fb.cancel
$w.fb.cancel config -command "wm withdraw $w"
$w.fb.help config -state normal -command "dm_Help help/rmon.html#createAlarm"}
focus $w.f.v0
update idletasks
if [catch {dmsGetAlarmIndex $sess} err] {$w.status config -text $err}}
proc dmsCreateAlarmCB {w sess} {global Dm_Radio Dm_AlarmIndex DmsRmonScript
set var [$w.f.v0 get]
if [catch {dmsRmonAlarmCheck $var "" $sess} err] {$w.status config -text $err
bell
focus $w.f.v0
return}
set index [$w.f.v3 get]
if ![catch {dmsRmonAlarmCheck alarmIndex $index $sess}] {$w.status config -text "Alarm $index already exists"
focus $w.f.v3
bell
return}
lappend vbl [list alarmStatus.$index {} 2]
set startupAlarm 0
loop t 1 3 {if {[set eventI [$w.f.v6-$t get]] == "default"} {set eventI [expr 60533+$t]}
if {[catch {format "%d" $eventI}] || $eventI < 0 || $eventI > 65535} {$w.status config -text "Event Index must be between 0..65535"
bell
focus $w.f.v6-$t
return}
if $eventI {if [catch {dmsRmonAlarmCheck eventIndex $eventI $sess} err] {$w.status config -text $err
bell
focus $w.f.v6-$t
return}}
set value [$w.f.v5-$t get]
if [catch {format "%d" $value} err] {$w.status config -text $err
bell
focus $w.f.v5-$t
return}
if {$t == 1} {lappend vbl [list alarmRisingThreshold.$index {} $value]
lappend vbl [list alarmRisingEventIndex.$index {} $eventI]} else {lappend vbl [list alarmFallingThreshold.$index {} $value]
lappend vbl [list alarmFallingEventIndex.$index {} $eventI]}
incr startupAlarm $t}
lappend vbl [list alarmVariable.$index {} $var]] [list alarmInterval.$index {} [$w.f.v2 get]] [list alarmSampleType.$index {} $Dm_Radio($w.f.v1)] [list alarmStartupAlarm.$index {} $startupAlarm] [list alarmOwner.$index {} [info hostname]]
if [catch {$sess set null $vbl} err] {$w.status config -text "[dm_SnmpError err] during create&wait"
bell
catch {puts stderr $vbl}} elseif [catch {$sess set null [list [list alarmStatus.$index {} 1]]} err] {$w.status config -text [dm_SnmpError err]
bell} else {$w.status config -text "Created Alarm $index"
if {[set script [$w.f.v8-1 get]] != ""} {set DmsRmonScript(risingAlarm.$index) "$script $Dm_Radio($w.f.v7-1)"}
if {[set script [$w.f.v8-2 get]] != ""} {set DmsRmonScript(fallingAlarm.$index) "$script $Dm_Radio($w.f.v7-2)"}
incr Dm_AlarmIndex}}
proc dmsCreateEvent {sess index desc} {global Dm_Pref
lappend vbl [list eventStatus.$index "" 2] [list eventDescription.$index "" $desc] [list eventType.$index "" 4] [list eventCommunity.$index DisplayString $Dm_Pref(readComm)] [list eventOwner.$index "" [info hostname]]
if [catch {$sess set null $vbl} err] {error "[dm_SnmpError err] event during create&wait"} elseif [catch {$sess set null [list [list eventStatus.$index "" 1]]} err] {error "[dm_SnmpError err] event"}}
proc dmsRmonAlarmCheck {var inst sess} {if {$inst != ""} {append var .$inst}
if [string match noSuch* [lindex [lindex [lindex [$sess get null $var] 4] 0] 2]] {error "$var doesn't exist"}}
proc dmsAlarmMenu {m} {set w .alarm.f.v0
$w delete 0 end
set var [$m entrycget active -label]
if {[string first . $var] == -1} {if [string match etherStats* $var] {catch {append var .[dmsPromptEtherStats]}} else {if {[set port [dmsPromptPort]] != ""} {catch {append var .[dmsIndexPort $port]}}}} elseif [string match *. $var] {.alarm.status config -text "Please add instance to variable"} else {.alarm.status config -text ""}
$w insert 0 $var}
proc dmsPromptPort {{instList ""}} {global DmsAlarmPort Dm_WinInst Dm_Pref
if {$instList == ""} {foreach i [lsort -integer [array names Dm_WinInst]] {if [string match Port* [rlindex Dm_WinInst($i) 0]] {lappend instList [dmsIfIndex2Port [rlindex Dm_WinInst($i) 1]]}}
if {$instList == ""} {return ""}}
set w .rcPort
toplevel $w -highlightthickness 1
wm withdraw $w
wm overrideredirect $w 1
grid [label $w.l -text "Which Port?"] -row 0 -column 1 -columnspan 16 -sticky w
set DmsAlarmPort ""
set slots ""
set i 0
foreach inst $instList {scan $inst %d/%d cardNo portNo
if {[lsearch $slots $cardNo] == -1} {lappend slots $cardNo}
radiobutton $w.r$i -indicatoron 0 -variable DmsAlarmPort -value $inst -text $portNo
grid $w.r$i -row $cardNo -column $portNo
incr i}
foreach s $slots {grid [label $w.l$s -text $s/ -font $Dm_Pref(boldFont)] -row $s -column 0 -sticky e}
bind $w <1> {set DmsAlarmPort [set DmsAlarmPort]}
bind $w <Escape> {set DmsAlarmPort ""}
dm_OnScreen $w
focus $w
grab $w
vwait DmsAlarmPort
grab release $w
destroy $w
return $DmsAlarmPort}
proc dmsPromptEtherStats {} {global DmsPriv
foreach n [array names DmsPriv RmonStatsIndex.*] {lappend instList [dmsIfIndex2Port [lindex [split $n .] 1]]}
if [info exists instList] {set inst [dmsPromptPort $instList]
return $DmsPriv(RmonStatsIndex.[dmsIndexPort $inst])}
return "."}
proc dmsCheckRmonTrap {type alarmIndex} {global DmsRmonScript
if ![info exists DmsRmonScript($type.$alarmIndex)] return
catch {eval exec $DmsRmonScript($type.$alarmIndex) &}}
proc dmsRmonAlarmScripts {} {global DmsRmonScript env
set w .rmonscript
if [dm_MakeDlg $w "Alarm Scripts" {{Label ""} {List ""}}] return
grid forget $w.f.l0 $w.f.l1
pack forget $w.status
$w.f.v0 config -text "Contents of $env(HOME)/.rmonscript"
$w.f.v1 delete 0 end
foreach s [array names DmsRmonScript] {$w.f.v1 insert end "$s   $DmsRmonScript($s)"}
if ![info exists s] {$w.fb.ok config -state disabled}
$w.fb.ok config -text Delete -command "dmsRmonAlarmDeleteScript $w.f.v1"}
proc dmsRmonAlarmDeleteScript {list} {global DmsRmonScript
if {[set sel [$list curselection]] == ""} return
unset DmsRmonScript([lindex [$list get $sel] 0])
$list delete $sel $sel}
proc dmsRmonHistory {table ifIndex sess vars} {global dmsRmonHist
if ![info exists dmsRmonHist(index.$ifIndex)] {error "$sess 0 {Please enable history} 0"}
if [catch {set vb [lindex [$sess next null etherHistoryIntervalStart.$dmsRmonHist(index.$ifIndex)] 4]} err] {if {[rlindex err 2] == "end"} {error "$sess 0 {No history yet recorded} 0"} else {error $err}}
set startTime [lindex [rlindex vb 0] 2]
upvar #0 $table tab
upvar $vars varList
set maxRept $dmsRmonHist(size.$ifIndex)
$sess config -maxrept $maxRept
set oid [snmpinfo mibprop [rlindex varList 0] value].$dmsRmonHist(index.$ifIndex)
set row 0
foreach v $varList {set col 0
set sampleIndex 0
while {1} {if {[catch {set tmp [$sess next null $v.$dmsRmonHist(index.$ifIndex).$sampleIndex] }]==1 } break
set vb [lindex [lindex $tmp 4] 0]
if {$row == 0 && [string first $oid [rlindex vb 0]] == -1} {set maxRept $col
$sess config -maxrept $maxRept
break}
if {[lindex [split [lindex $vb 0] .] 11] != $dmsRmonHist(index.$ifIndex)} break
set tab($row,$col) [rlindex vb 2]
incr col
set sampleIndex [lindex [split [lindex $vb 0] .] end]}
if {$col < $maxRept} {append errMsg "$v: [expr $maxRept-$col] intervals truncated\n"
loop c $col $maxRept {set tab($row,$c) N/A}}
incr row}
if [info exists errMsg] {dm_Prompt .err "History Table is too large at $maxRept intervals:\n\n$errMsg" Continue}
if {$tab(1,-1) == "Utilization"} {loop c 0 $maxRept {catch {set tab(1,$c) [format %.2f [expr $tab(1,$c)/100.0]]}}}
set tab(-1,0) [lindex [dmsSinceSysUpTime $startTime] 3]
set i [expr $dmsRmonHist(interval.$ifIndex)*100]
loop c 1 $maxRept {incr startTime $i
set tab(-1,$c) [lindex [dmsSinceSysUpTime $startTime] 3]}
if {$i >= 6000} {loop c 0 $maxRept {set tab(-1,$c) [string range $tab(-1,$c) 0 4]}}
return $maxRept}
proc dmsCheckRmonHistory {ifIndex sess} {global dmsRmonHist Dm_Status Dm_SysUpTime
catch {unset dmsRmonHist}
set dmsRmonHist(lastIndex) 0
set tabSize 1024
$sess config -maxrept $tabSize
set ifIndexOffset [expr [string length [snmpinfo mibprop ifIndex value]]+1]
set indexOffset [expr [string length [snmpinfo mibprop historyControlDataSource value]]+1]
set inst 0
while {1} {if {[catch {set tmp [$sess next null historyControlDataSource.$inst]}]== 1 } break
set data [lindex [lindex $tmp 4] 0]
if {$data != {}} {set dataSource [lindex $data 0]
if {[string first "1.3.6.1.2.1.16.2.1.1.2" $dataSource]== 0 } {set index [string range [lindex $data 2] $ifIndexOffset end]
set inst [string range $dataSource $indexOffset end]
set dmsRmonHist(index.$index) $inst
set r [$sess get null historyControlBucketsGranted.$inst]
set dmsRmonHist(size.$index) [lindex [lindex [lindex $r 4] 0] 2]
set r [$sess get null historyControlInterval.$inst]
set dmsRmonHist(interval.$index) [lindex [lindex [lindex $r 4] 0] 2]} else {break}} else {break}}
set dmsRmonHist(lastIndex) $inst
return [info exists dmsRmonHist(index.$ifIndex)]}
proc dmsCvtIfIndex2RmonHistIndex {ifIndex} {global dmsRmonHist
if [info exists dmsRmonHist(index.$ifIndex)] {return $dmsRmonHist(index.$ifIndex)}
return 0}
proc dmsRmonEnableHistory {} {global dmsRmonHist Dm_Status
if [catch {dmsRmonCheckEnabled Sess0} err] {dm_Prompt .err $err Ok
return}
foreach i [dm_GetSelInst Port] {if ![dmsCheckRmonHistory $i Sess0] {if [info exists dmsRmonHist(lastIndex)] {set etherIndex [incr dmsRmonHist(lastIndex)]} else {set etherIndex 1}
if [catch {Sess0 set null [list [list historyControlStatus.$etherIndex "" 2] [list historyControlOwner.$etherIndex "" [info hostname]] [list historyControlDataSource.$etherIndex "" 1.3.6.1.2.1.2.2.1.1.$i]]} err] {dm_Prompt .err [dm_SnmpError err] Ok
return}
if [catch {Sess0 set null [list [list historyControlStatus.$etherIndex "" 1]]} err] {dm_Prompt .err [dm_SnmpError err] Ok
return}}}
set Dm_Status ok}
proc dmsRmonControlBuildCB {f inst sess isTable} {set top [winfo toplevel $f]
$top.fBtn.remove config -command "[$top.fBtn.remove cget -command]; catch {unset dmsRmonHist}"
dmsRmonEtherBuildCB $f $inst $sess $isTable}
proc dmsRmonEtherBuildCB {f inst sess isTable} {if [catch {dmsRmonCheckEnabled $sess} err] {if {$err != ""} {dm_Prompt .err $err Ok}
return}}
proc dmsRmonEnableStat {} {global DmsPriv Dm_Status
if [catch {dmsRmonCheckEnabled Sess0} err] {dm_Prompt .err $err Ok
return}
foreach i [dm_GetSelInst Port] {if ![dmsCheckRmonStats $i Sess0] {set etherIndex [incr DmsPriv(RmonStatsLastIndex)]
if [catch {Sess0 set null [list [list etherStatsStatus.$etherIndex "" 2] [list etherStatsOwner.$etherIndex "" [info hostname]] [list etherStatsDataSource.$etherIndex "" 1.3.6.1.2.1.2.2.1.1.$i]]} err] {dm_Prompt .err [dm_SnmpError err] Ok} elseif [catch {Sess0 set null [list [list etherStatsStatus.$etherIndex "" 1]]} err] {dm_Prompt .err [dm_SnmpError err] Ok}}}
set Dm_Status ok}
proc dmsCheckRmonStats {ifIndex sess} {global DmsPriv
set DmsPriv(RmonStatsLastIndex) 0
foreach n [array names DmsPriv RmonStatsIndex.*] {unset DmsPriv($n)}
if [catch {set r [$sess get null rcTblRmonStatSize.0]}] {return 0}
if {[set tabSize [lindex [lindex [rlindex r 4] 0] 2]] == 0} {return 0}
$sess config -maxrept [lindex [lindex [rlindex r 4] 0] 2]
set indexOffset [expr [string length [snmpinfo mibprop etherStatsDataSource value]]+1]
foreach vb [lindex [$sess bulk null etherStatsDataSource.0] 4] {set inst [string range [rlindex vb 0] $indexOffset end]
set DmsPriv(RmonStatsIndex.[string range [rlindex vb 2] 20 end]) $inst}
set DmsPriv(RmonStatsLastIndex) $inst
return [info exists DmsPriv(RmonStatsIndex.$ifIndex)]}
proc dmsCvtIfIndex2RmonIndex {ifIndex} {global DmsPriv
if [info exists DmsPriv(RmonStatsIndex.$ifIndex)] {return $DmsPriv(RmonStatsIndex.$ifIndex)}
return 9999}
proc dmsTrapRegisterProc {sess} {set inst [getIPAddr [info hostname]]
$sess get "dmsTrapRegisterProcCB $inst" rcSysTrapRecvRowStatus.$inst}
proc dmsTrapRegisterProcCB {inst sess reqid err errI vbl} {if {$err != "noError"} {global Dm_Status
set Dm_Status "Trap registration failed: $err"}
if [string match noSuch* [lindex [rlindex vbl 0] 2]] {global Dm_Pref tcl_platform
set devIpAddr [getIPAddr $Dm_Pref(devName)]
set vbl {}
lappend vbl "rcSysTrapRecvRowStatus.$inst {} 4" "rcSysTrapRecvCommunity.$inst {} public"
if {$tcl_platform(platform) == "windows"} {lappend vbl "rcSysTrapRecvVersion.$inst {} 2"}
$sess set dmsTrapRegisterSetProcCB $vbl}}
proc dmsTrapRegisterSetProcCB {s reqid err errI vbl} {if {$err != "noError"} {global Dm_Status
set Dm_Status "Trap registration failed: $err"}}
proc dmsTrapProc {time trap vbl} {global Dm_Pref
if {[string compare 1.3.6.1.2.1.16.1 $trap] == 0} {set trap risingAlarm
dmsCheckRmonTrap $trap [lindex [rlindex vbl 0] 2]} elseif {[string compare 1.3.6.1.2.1.16.2 $trap] == 0} {set trap fallingAlarm
dmsCheckRmonTrap $trap [lindex [rlindex vbl 0] 2]} elseif {[string compare 1.3.6.1.6.3.1.1.4.1.0 $trap] == 0} {set oid [lindex [lindex $vbl end] 0]
if {$oid == "1.3.6.1.2.1.16.3.1.1.7"} {set trap risingAlarm
dmsCheckRmonTrap $trap [lindex [rlindex vbl 0] 2]} elseif {$oid == "1.3.6.1.2.1.16.3.1.1.8"} {set trap fallingAlarm
dmsCheckRmonTrap $trap [lindex [rlindex vbl 0] 2]} elseif {$oid == "1.3.6.1.6.3.1.1.4.3.0"} {set vb [lindex $vbl 2]
if {[snmpinfo mibprop [rlindex vb 0] descriptor] == "ifOperStatus"} {if {[rlindex vb 2] == 1} {set trap linkUp} else {set trap linkDown}}}} else {set trap [snmpinfo mibprop $trap descriptor]}
dm_RecordTrap $time $trap vbl
if [string match link* $trap] {if $Dm_Pref(pollFreq) {dm_PollDevice $Dm_Pref(pollFreq)} else {dm_GetStatus}
return} elseif {$trap == "coldStart"} {global Dm_SysUpTime Dm_SysUpTimeOrig
set Dm_SysUpTimeOrig $time
set Dm_SysUpTime [timeticks clock $time]
after 5000 dm_Rediscover}}
proc rcVlanStaticMembers.modify {val inst} {return [dmsModifyPortBitmap $val]}
proc rcVlanNotAllowToJoin.modify {val inst} {return [dmsModifyPortBitmap $val]}
proc dmsModifyPortBitmap {val} {if {$val == ""} {return 00}
return [port parse $val]}
proc rcVlanPortMembers.display {val} {return [port print $val range]}
proc rcVlanStaticMembers.display {val} {return [port print $val range]}
proc rcVlanNotAllowToJoin.display {val} {return [port print $val range]}
proc rcVlanActiveMembers.display {val} {return [port print $val range]}
proc dot1dStaticAllowedToGoTo.display {val} {return [rcVlanPortMembers.display $val]}
proc dmsCheckVlanCache {sess} {global DmsPriv Dm_Status
if [catch {set resp [$sess get null {rcSysLastVlanChange.0 rcVlanNumVlans.0}]} err] {set Dm_Status "Can't get VLANs: [rlindex err 0]"
return}
set lastChange [lindex [lindex [rlindex resp 4] 0] 2]
if {![info exists DmsPriv(vlanCache)] || $lastChange != $DmsPriv(vlanCache)} {set DmsPriv(vlanCache) $lastChange
foreach n [array names DmsPriv vlan.name.*] {unset DmsPriv($n)}
set offset [string length [snmpinfo mibprop rcVlanName value]]
incr offset
$sess config -maxrept [lindex [lindex [rlindex resp 4] 1] 2]
foreach {name ports ifIndex} [lindex [$sess bulk null {rcVlanName.0 rcVlanPortMembers.0 rcVlanIfIndex.0}] 4] {set id [string range [rlindex name 0] $offset end]
set DmsPriv(vlan.name.$id) [rlindex name 2]
set DmsPriv(vlan.ports.$id) [bit print [rlindex ports 2]]
set ifIndex [rlindex ifIndex 2]
set DmsPriv(vlan.ifIndex.$id) $ifIndex
set DmsPriv(vlan.ifIndex2Id.$ifIndex) $id}}}
proc dmsIgnoreVlanNull {inst sess} {return 0}
proc dmsCheckUseIPConfig {ifIndex sess} {global DmsPriv Dm_Status
if [catch {set rc [$sess get null rcVlanRoutingEnable.$DmsPriv(vlan.ifIndex2Id.$ifIndex)]} err] {set Dm_Status [dm_SnmpError err]
return 0}
if {[lindex [lindex [rlindex rc 4] 0] 2] == 1} {return 1} else {return 0}}
proc dmsVlanSelectBridge {t sess} {global Dm_Pref DmsPriv
upvar #0 [$t cget -var] tab
set row [$t index active row]
if [catch {set vlanId $tab($row,-1)}] return
set DmsPriv(selectedVLAN) $vlanId
$sess config -rd $Dm_Pref(readComm)@$vlanId -wr $Dm_Pref(writeComm)@$vlanId
set w .edBridge
if [winfo exists $w] {$w.fBtn.refresh invoke
raise $w} else {dm_Dialog edit Bridge 0}
wm title $w "($Dm_Pref(devName)) - edit Bridge ($tab($row,0) VLAN)"
global Dm_VendorMac Dm_Path
catch {source $Dm_Path/dmdb/chameleon/v1003/vendors}}
proc dmsVlanSelectRouting {t sess} {global Dm_Pref DmsPriv
upvar #0 [$t cget -var] tab
set row [$t index active row]
if [catch {set vlanIfIndex $tab($row,10)}] return
set DmsPriv(vlan.ifIndex2Id.$vlanIfIndex) $tab($row,-1)
set w .edVlan_IP
if [winfo exists $w] {[string range $w 1 end] configure -GlobInst $vlanIfIndex -CatInst $vlanIfIndex
$w.fBtn.refresh invoke
raise $w} else {dm_Dialog edit Vlan_IP $vlanIfIndex}
wm title $w "($Dm_Pref(devName)) - edit Vlan_IP ($tab($row,0) VLAN)"}
proc dmsVlanPortBuildCB {w inst sess isTable} {dmsCheckVlanCache $sess}
proc dmsVlanBuildCB {w inst sess isTable} {set tabObj ::DMedit::[string range $w 1 end]
$w.t tag coltag popup 4
$tabObj setPopupCmd 4 "dmsVlanEditMembership $w.t $sess"
$w.t tag coltag popup 1
$tabObj setPopupCmd 1 "dmsVlanModifyColor $w.t $tabObj"}
proc dmsVlanEditMembership {t sess} {global DmsPriv Dm_Pref Dm_Radio
set w .vlanMembers
if [winfo exists $w] {raise $w
set numPorts $Dm_Pref(numPorts)} else {toplevel $w
dm_transient $w [winfo toplevel $t]
wm geom $w "+[winfo pointerx .]+[winfo pointery .]"
wm resizable $w 0 0
set numPorts [dmsCreatePortGrid $w.f button]
set Dm_Pref(numPorts) $numPorts
frame $w.l
set i 1
foreach text {Never Potential Always} color {red yellow green} {
			pack [button $w.l.l$i -text $text -bg $color -font $Dm_Pref(normalFont) -padx 2 -pady 1 -command "dmsVlanChangeColor $w.f $color $numPorts"]
			incr i
		}
pack [label $w.l.l$i -text "Active" -font $Dm_Pref(italicFont) -fg blue -bd 1 -relief sunken]
frame $w.fBtn -class FBtn
button $w.fBtn.ok -text Ok
button $w.fBtn.cancel -text Cancel -command "destroy $w"
pack $w.fBtn.cancel $w.fBtn.ok -side right -pady 5
bind $w <Escape> "$w.fBtn.cancel invoke"
bind $w <Return> "$w.fBtn.ok invoke"
grid $w.l -row 0 -column 0
grid $w.f -row 0 -column 1
grid $w.fBtn -row 1 -column 0 -columnspan 2}
set row [$t index active row]
upvar #0 [$t cget -var] tab
set vlanId $tab($row,-1)
set byPort [expr {$tab($row,2) == "byPort"}]
set DmsPriv($w.f.byPort) $byPort
wm title $w "($Dm_Pref(devName)) - VLAN $tab($row,0)($vlanId) Ports"
$w.fBtn.ok config -command "dmsVlanEditMembershipCB $w $t $row $numPorts $byPort"
if $byPort {pack forget $w.l.l2 $w.l.l4} else {pack $w.l.l2 $w.l.l4}
set bg [$w cget -bg]
loop i 0 $numPorts {set port2Check($Dm_Radio($w.f.c$i)) $w.f.c$i
$w.f.c$i config -bg $bg -fg black -font $Dm_Pref(normalFont)}
if $byPort {loop i 0 $numPorts {if {[$w.f.c$i cget -state] == "normal"} {$w.f.c$i config -bg red}}
foreach p [bit print [dmsModifyPortBitmap [list $tab($row,4)]]] {if [info exists port2Check($p)] {$port2Check($p) config -bg green}}} else {loop i 0 $numPorts {if {[$w.f.c$i cget -state] == "normal"} {$w.f.c$i config -bg yellow}}
foreach p [bit print [dmsModifyPortBitmap [list $tab($row,5)]]] {if [info exists port2Check($p)] {$port2Check($p) config -fg blue -font $Dm_Pref(italicFont)}}
foreach p [bit print [dmsModifyPortBitmap [list $tab($row,6)]]] {if [info exists port2Check($p)] {$port2Check($p) config -bg green}}
foreach p [bit print [dmsModifyPortBitmap [list $tab($row,7)]]] {if [info exists port2Check($p)] {$port2Check($p) config -bg red}}}}
proc dmsVlanEditMembershipCB {w t row numPorts byPort} {global Dm_Radio
if ![winfo exists $t] return
upvar #0 [$t cget -var] tab
if $byPort {set ports ""
loop i 0 $numPorts {if {[$w.f.c$i cget -state] == "normal" && [$w.f.c$i cget -bg] == "green"} {lappend ports $Dm_Radio($w.f.c$i)}}
set tab($row,4) [port print [bit parse $ports] range]
$t tag celltag edited $row,4} else {set staticPorts ""
set notAllowedPorts ""
set potentialPorts ""
loop i 0 $numPorts {if {[$w.f.c$i cget -state] == "normal"} {set bg [$w.f.c$i cget -bg]
if {$bg == "green"} {lappend staticPorts $Dm_Radio($w.f.c$i)} elseif {$bg == "red"} {lappend notAllowedPorts $Dm_Radio($w.f.c$i)} elseif {$bg == "yellow"} {lappend potentialPorts $Dm_Radio($w.f.c$i)}}}
set tab($row,4) [port print [bit parse [concat $potentialPorts $staticPorts]] range]
$t tag celltag edited $row,4}
[winfo toplevel $t].fBtn.apply config -state normal
[winfo toplevel $t].fBtn.apply invoke
destroy $w}
proc dmsVlanModifyColor {t tabObj} {global Dm_Radio
dm_RadioBox .color color
upvar #0 [$t cget -var] tab
set row [$t index active row]
set tab($row,1) $Dm_Radio(.color)
$t tag celltag edited $row,1
$tabObj hide popup
[winfo toplevel $t].fBtn.apply config -state normal}
proc dmsBridgeForwardingBuildCB {w inst sess isTable} {}
proc dmsMac2IPHost {t sess} {upvar #0 [$t cget -var] tab
scan [$t index active] %d,%d row col
if {[dm_GetTYPE [rlindex tab(-2,$col) 0]] == "MacAddress"} {global Dm_VendorMac}}
proc dmsBridgeStaticInsertCB {w inst sess} {$w.f.f1.b config -command "dmsBridgeInsertPort $w $sess"}
proc dmsBridgeInsertPort {w sess} {global DmsPriv
dmsCheckVlanCache $sess
set ports ""
foreach ifIndex $DmsPriv(vlan.ports.$DmsPriv(selectedVLAN)) {lappend ports [dmsIfIndex2Port $ifIndex]}
if [catch {set inst [dmsPromptPort $ports]}] {set inst ""}
$w.f.v1 delete 0 end
$w.f.v1 insert 0 $inst}
proc dmsBridgeFilterInsertCB {w inst sess} {global DmsPriv
dmsCheckVlanCache $sess
set ports ""
foreach ifIndex $DmsPriv(vlan.ports.$DmsPriv(selectedVLAN)) {lappend ports [dmsIfIndex2Port $ifIndex]}
dm_PortSetEnable $w.f.f2 [port parse $ports]}
proc dmsCreatePortGrid {f widget} {global Dm_WinInst Dm_Radio Dm_Pref
set instList ""
foreach i [lsort -integer [array names Dm_WinInst]] {if [string match Port* [rlindex Dm_WinInst($i) 0]] {lappend instList [dmsIfIndex2Port [rlindex Dm_WinInst($i) 1]]}}
frame $f -bd 1 -relief sunken
set numPorts 0
set slots ""
foreach inst $instList {scan $inst %d/%d cardNo portNo
if {[lsearch $slots $cardNo] == -1} {lappend slots $cardNo}
if {$widget == "check"} {set Dm_Radio($f.c$numPorts) 0
checkbutton $f.c$numPorts -indicatoron 0 -onvalue [dmsIndexPort $inst] -text $portNo -selectcolor white -variable Dm_Radio($f.c$numPorts)} else {set Dm_Radio($f.c$numPorts) [dmsIndexPort $inst]
button $f.c$numPorts -font $Dm_Pref(normalFont) -text $portNo -padx 1 -pady 1
bind $f.c$numPorts <1> "dmsVlanTriState %W"
bind $f.c$numPorts <space> "dmsVlanTriState %W"}
grid $f.c$numPorts -row [lindex [split $inst /] 0] -column [lindex [split $inst /] 1]
incr numPorts}
foreach s $slots {label $f.l$s -text $s/ -font $Dm_Pref(boldFont)
grid $f.l$s -row $s -column 0 -sticky e}
return $numPorts}
proc dmsCreatePortGridCB {src target numPorts} {global Dm_Radio
set ports ""
loop i 0 $numPorts {if $Dm_Radio($src.c$i) {lappend ports $Dm_Radio($src.c$i)}}
$target delete 0 end
$target insert 0 [port print [bit parse $ports] range]}
proc dmsIPAddrInsertCB {w inst sess} {global DmsPriv
$w.f.v0 delete 0 end
$w.f.v0 insert 0 $inst
grid forget $w.f.l0 $w.f.f0
focus $w.f.v1
if [info exists DmsPriv(vlan.$inst.subnet)] {$w.f.v1 insert 0 $DmsPriv(vlan.$inst.subnet)}
bind $w.f.v1 <Tab> "dmsIPAddrInsertTab $w.f.v1 $w.f.v2"}
proc dmsVlanSelectSnoop {t sess} {global Dm_Pref DmsPriv
upvar #0 [$t cget -var] tab
set row [$t index active row]
set vlanId $tab($row,-1)
set w .edSnoop
if [winfo exists $w] {[string range $w 1 end] configure -GlobInst $vlanId -CatInst $vlanId
$w.fBtn.refresh invoke
raise $w} else {dm_Dialog edit Snoop $vlanId}
wm title $w "($Dm_Pref(devName)) - edit Snoop ($tab($row,0) VLAN)"}
proc dmsVlanIgmpSnoopStart {inst sess} {return $inst}
proc dmsVlanIgmpSnoopStop {inst currInst sess} {return ![string match $inst.* $currInst]}
proc dmsVlanIgmpSnoopStaticInsertCB {w inst sess} {$w.f.v1 config -width 15
button $w.f.f1.range -text "..." -command "dmsShowIPMAddr $w" -padx 2 -pady 0
pack $w.f.f1.range -side right}
proc dmsShowIPMAddr {w} {if {[set ipAddr [$w.f.v1 get]] == ""} {dm_Prompt .err "Please enter a multicast address first" Continue} else {dm_MakeDlg .ipm "MultiCast" {{Label "" "MultiCast Range:"} {List ""}}
grid forget .ipm.f.l0 .ipm.f.l1
.ipm.f.v1 config -width 16
foreach ip [ipmShowIpAddr $ipAddr] {.ipm.f.v1 insert end $ip}
pack forget .ipm.fb.ok}}
proc dmsVlanInsertCB {w inst sess} {global Dm_Path Dm_Radio Dm_Pref Dm_WinInst DmsVlanMembers DmsPriv
$w.f.v2 insert 0 [rlindex Dm_Pref(colors) [expr [$w.f.v0 get] % 32]]
bind $w.f.v2 <FocusOut> break
$w.f.v2 config -width 20
pack forget $w.f.f2.l
button $w.f.f2.b -bitmap @$Dm_Path/bitmaps/pulldown.xbm -command "dmsVlanInsertColor $w.f.v2"
pack $w.f.f2.b -side left
set Dm_Radio(.color) [$w.f.v2 get]
grid forget $w.f.l3 $w.f.v3
grid forget $w.f.l6 $w.f.f6
grid forget $w.f.l5 $w.f.v5
grid forget $w.f.l9 $w.f.v9
grid forget $w.f.l4 $w.f.v4
grid $w.f.v7 -pady 8
$w.f.l7 config -font $Dm_Pref(boldFont)
$w.f.v7.r0 config -command "dmsVlanInsertCBType $w port"
grid forget $w.f.v7.r1 $w.f.v7.r2
$w.f.v7.r2 config -command "dmsVlanInsertCBType $w protocol"
destroy $w.f.l10
grid forget $w.f.v10 $w.f.v11
set numPorts [dmsCreatePortGrid $w.f.f10 button]
frame $w.f.l10
pack [label $w.f.l10.l0 -text "Dynamic Membership:"]
set i 1
foreach text {Never Potential Always} color {red yellow green} {
		pack [button $w.f.l10.l$i -text $text -bg $color -font $Dm_Pref(normalFont) -padx 2 -pady 1 -command "dmsVlanChangeColor $w.f.f10 $color $numPorts"]
		incr i
	}
$w.fb.ok config -command "dmsVlanInsertApply $w $numPorts; [$w.fb.ok cget -command]"
bind $w.f.v12 <Tab> "dmsIPAddrInsertTab $w.f.v12 $w.f.v13"
set DmsPriv($w.f.f8.byPort) 1
dmsVlanInsertCBType $w port
dmsVlanShowTrunksInStatic $w.f.f10 $sess}
proc dmsVlanInsertApply {w numPorts} {global Dm_Radio
if {$Dm_Radio($w.f.v7) == 1} {$w.f.v9 delete 0 end
$w.f.v10 delete 0 end
$w.f.v14 delete 0 end} else {set potentialMembers ""
set staticMembers ""
set notAllowed ""
loop i 0 $numPorts {if {[set color [$w.f.f10.c$i cget -bg]] == "red"} {lappend notAllowed $Dm_Radio($w.f.f10.c$i)} elseif {$color == "green"} {lappend staticMembers $Dm_Radio($w.f.f10.c$i)} elseif {$color == "yellow"} {lappend potentialMembers $Dm_Radio($w.f.f10.c$i)}}
dm_PortSetDisplay $w.f.f8 [bit parse [concat $staticMembers $potentialMembers]]
$w.f.v9 delete 0 end
$w.f.v9 insert 0 [port print [bit parse $staticMembers] range]
$w.f.v10 delete 0 end
$w.f.v10 insert 0 [port print [bit parse $notAllowed] range]
if {[$w.f.v1 get] == ""} {if {$Dm_Radio($w.f.v7) == 2} {$w.f.v1 insert 0 [$w.f.v12 get]} else {foreach e [snmpinfo mibprop rcVlanProtocolId enums] {if {$Dm_Radio($w.f.v11) == [rlindex e 0]} {$w.f.v1 insert 0 [rlindex e 1]
break}}}}}}
proc dmsVlanStgMenu {w numPorts m e sess} {proc dmsVlanStgMenuCB {w numPorts e id instList} {global Dm_Radio
$e config -state normal
$e delete 0 end
$e insert 0 $id
$e config -state disabled
dm_PortSetEnable $w.f.f8 $instList
set bg [$w cget -bg]
loop i 0 $numPorts {set port2Btn($Dm_Radio($w.f.f10.c$i)) $w.f.f10.c$i
$w.f.f10.c$i config -state disabled -bg $bg}
foreach p [bit print $instList] {catch {$port2Btn($p) config -state normal -bg yellow}}}
set numStgs [lindex [lindex [lindex [$sess get null rcStgNumStgs.0] 4] 0] 2]
$sess config -maxrept $numStgs
set offset [string length [snmpinfo mibprop rcStgPortMembers value]]
incr offset
foreach vb [lindex [$sess bulk null rcStgPortMembers.0] 4] {set id [string range [rlindex vb 0] $offset end]
$m add command -label "$id: [port print [rlindex vb 2] range]" -command "dmsVlanStgMenuCB $w $numPorts $e $id [rlindex vb 2]"}}
proc dmsVlanTriState {w} {if {[$w cget -state] == "disabled"} return
global DmsPriv
set top [winfo parent $w]
if {[info exists DmsPriv($top.byPort)] && $DmsPriv($top.byPort)} {if {[set color [$w cget -bg]] == "green"} {set nextColor red} else {set nextColor green}} else {if {[set color [$w cget -bg]] == "yellow"} {set nextColor green} elseif {$color == "green"} {set nextColor red} else {set nextColor yellow}}
$w config -bg $nextColor}
proc dmsVlanChangeColor {f color numPorts} {loop i 0 $numPorts {if {[$f.c$i cget -state] != "disabled"} {$f.c$i config -bg $color}}}
proc dmsVlanInsertCBType {w type} {if {$type == "port"} {grid $w.f.l8 -row 8 -column 0 -sticky e
grid $w.f.f8 -row 8 -column 1 -sticky w
foreach i {11 12 13} {grid forget $w.f.l$i $w.f.v$i}
foreach i {10 14} {grid forget $w.f.l$i $w.f.f$i}} elseif {$type == "protocol"} {foreach i {10 14} {grid $w.f.l$i -row $i -column 0 -sticky e
grid $w.f.f$i -row $i -column 1 -sticky w}
grid $w.f.l11 -row 11 -column 0 -sticky e
grid $w.f.v11 -row 11 -column 1 -sticky w
foreach i {8 12 13} {grid forget $w.f.l$i $w.f.v$i}
grid forget $w.f.f8} else {foreach i {10 14} {grid $w.f.l$i -row $i -column 0 -sticky e
grid $w.f.f$i -row $i -column 1 -sticky w}
foreach i {12 13} {grid $w.f.l$i -row $i -column 0 -sticky e
grid $w.f.v$i -row $i -column 1 -sticky w}
foreach i {8 9 11} {grid forget $w.f.l$i $w.f.v$i}
grid forget $w.f.f8}}
proc dmsVlanInsertColor {e} {global Dm_Radio
dm_RadioBox .color color
$e delete 0 end
$e insert 0 $Dm_Radio(.color)}
proc dmsVlanShowTrunksInStatic {f sess} {global Dm_WinInst
foreach i [lsort -integer [array names Dm_WinInst]] {if [string match Port* [rlindex Dm_WinInst($i) 0]] {lappend vbl rcVlanPortType.[rlindex Dm_WinInst($i) 1]}}
if [info exists vbl] {catch {$sess get "dmsVlanShowTrunksInStaticCB $f" $vbl}}}
proc dmsVlanShowTrunksInStaticCB {f sess reqId err errI vbl} {if {$err != "noError" || ![winfo exists $f]} return
set numPorts 0
foreach vb $vbl {if {[rlindex vb 2] == 2} {$f.c$numPorts config -bg green}
incr numPorts}}
proc dmsStgBuildCB {w inst sess isTable} {set tabObj ::DMedit::[string range $w 1 end]
$w.t tag coltag popup 8
$tabObj setPopupCmd 8 "dmsStgBuildPromptPort $w.t 8"}
proc dmsStgBuildPromptPort {t portMembersCol} {global Dm_Pref Dm_Radio
set w .stgPort
if [winfo exists $w] {raise $w} else {toplevel $w
dm_transient $w [winfo toplevel $t]
wm geom $w "+[winfo pointerx .]+[winfo pointery .]"
wm resizable $w 0 0
set Dm_Pref(numPorts) [dmsCreatePortGrid $w.f check]
frame $w.fBtn -class FBtn
button $w.fBtn.ok -text Ok
button $w.fBtn.cancel -text Cancel -command "destroy $w"
pack $w.fBtn.cancel $w.fBtn.ok -side right -pady 5
pack $w.f $w.fBtn
bind $w <Escape> "$w.fBtn.cancel invoke"
bind $w <Return> "$w.fBtn.ok invoke"}
set row [$t index active row]
upvar #0 [$t cget -var] tab
$w.fBtn.ok config -command "dmsStgBuildPromptPortCB $w $t $row $Dm_Pref(numPorts) $portMembersCol"
wm title $w "($Dm_Pref(devName)) - STG $tab($row,-1) PortMembers"
foreach p [bit print [dmsModifyPortBitmap [list $tab($row,$portMembersCol)]]]] {set assigned($p) 1}
loop i 0 $Dm_Pref(numPorts) {if [info exists assigned([$w.f.c$i cget -onvalue])] {set Dm_Radio($w.f.c$i) [$w.f.c$i cget -onvalue]} else {set Dm_Radio($w.f.c$i) 0}}}
proc dmsStgBuildPromptPortCB {w t row numPorts portMembersCol} {global Dm_Radio
if ![winfo exists $t] return
set ports ""
loop i 0 $numPorts {if $Dm_Radio($w.f.c$i) {lappend ports [$w.f.c$i cget -onvalue]}}
upvar #0 [$t cget -var] tab
set tab($row,$portMembersCol) [rcVlanPortMembers.display [bit parse $ports]]
$t tag celltag edited $row,$portMembersCol
[winfo toplevel $t].fBtn.apply config -state normal
[winfo toplevel $t].fBtn.apply invoke
destroy $w}
proc dmsStgInsertCB {w inst sess} {global Dm_WinInst Dm_Pref Dm_Radio
set nextIndex [dmsGetNextAvailableIndex [wm group $w].fCat0.t]
$w.f.v0 insert 0 $nextIndex
focus $w.f.v1
catch {$w.f.v2 insert 0 [expr 4000+$nextIndex]}
grid forget $w.f.v9
set numPorts [dmsCreatePortGrid $w.f.f9 check]
grid $w.f.f9 -row 9 -column 1
if ![catch {set r [$sess get null rcStgUnassignedPorts.0]} err] {foreach p [bit print [lindex [lindex [rlindex r 4] 0] 2]] {set unassigned($p) 1}}
loop i 0 $numPorts {if [info exists unassigned([$w.f.f9.c$i cget -onvalue])] {set Dm_Radio($w.f.f9.c$i) [$w.f.f9.c$i cget -onvalue]}}
$w.fb.ok config -command "dmsCreatePortGridCB $w.f.f9 $w.f.v9 $numPorts; [$w.fb.ok cget -command]"}
proc sysUpTime.display {val} {return "[timeticks uptime $val] ([timeticks now $val])"}
proc dot1dStpPortDesignatedRoot.display {val} {global DmsPriv
if {[string compare [string range $val 6 end] $DmsPriv(defaultBridge)] == 0} {return self}
return $val}
proc ifLastChange.display {val} {return [dmsSinceSysUpTime $val]}
proc etherHistoryIntervalStart.display {val} {return [dmsSinceSysUpTime $val]}
proc eventLastTimeSent.display {val} {return [dmsSinceSysUpTime $val]}
proc logTime.display {val} {return [dmsSinceSysUpTime $val]}
proc dmsSinceSysUpTime {val} {if {$val==0} {return none}
global Dm_SysUpTime
if {[set val [expr [timeticks ticks $Dm_SysUpTime]-$val]] < 0} {set val 0}
return [timeticks now $val]}
proc historyControlDataSource.display {val} {if {$val != "0.0"} {return [dmsIfIndex2Port [string range $val 20 end]]}
return $val}
proc etherStatsDataSource.display {val} {return [historyControlDataSource.display $val]}
proc alarmVariable.display {val} {return [dm_GetNameFromOid $val]}
proc rcVlanColor.display {val} {global Dm_Pref
if {[set color [rlindex Dm_Pref(colors) $val]] == 0} {return $val}
return $color}
proc rcVlanPortVlanIds.display {val} {set i 0
foreach hex [split $val :] {if [expr $i && ($i%2 == 0)] {append str " "}
append str $hex
incr i}
if [info exists str] {set result ""
foreach hex $str {if {$hex == 0} {append result Unassigned,} elseif {$hex == 1} {append result Default,} else {append result [format %d 0x$hex],}}
return [string trimright $result ,]}
return $val}
proc ipAdEntIfIndex.display {val} {global DmsPriv
return [dmsIfIndex2Port $val]}
proc ipRouteIfIndex.display {val} {return [ipAdEntIfIndex.display $val]}
proc ipNetToMediaIfIndex.display {val} {return [ipAdEntIfIndex.display $val]}
proc dot1dTpFdbPort.display {val} {return [ipAdEntIfIndex.display $val]}
proc dot1dTpFdbAddress.display {val} {global Dm_VendorMac
set vendor [string range $val 0 7]
if [info exists Dm_VendorMac($vendor)] {return $Dm_VendorMac($vendor)[string range $val 8 end]}
return $val}
proc rcVlanAgingTime.display {val} {if {$val == 0} {return N/A}
return $val}
proc rcVlanSubnetAddr.display {val} {if {$val == "0.0.0.0"} {return N/A}
return $val}
proc rcVlanSubnetMask.display {val} {return [rcVlanSubnetAddr.display $val]}
proc s5AgTrpRcvrComm.display {val} {return [octet2string [split $val :]]}
proc s5AgUnAuthComm.display {val} {return [octet2string [split $val :]]}
proc s5AgMyIfMacAddr.display {val} {return [octet2string [split $val :]]}
proc ifMtu.display { val} {return "$val bytes"}
proc s5AgTrpRcvrNetAddr.display {val} {return [octet2ip $val]}
proc octet2ip {val} {if {[set n [scan $val %x:%x:%x:%x a b c d]] == 4} {return $a.$b.$c.$d}
return $val}
proc ifSpeed.display { val} {set speed [expr $val/1000000]
return "$speed Mbps"}
proc logTime.display {val} {return [dmsSinceSysUpTime $val]}
proc ifLastChange.display {val} {return [dmsSinceSysUpTime $val]}
proc etherHistoryIntervalStart.display {val} {return [dmsSinceSysUpTime $val]}
proc eventLastTimeSent.display {val} {return [dmsSinceSysUpTime $val]}
proc alarmVariable.display {val} {return [dm_GetNameFromOid $val]}
proc dot1dStpTimeSinceTopologyChange.display {val} {if {$val==0} {return none}
return [timeticks uptime $val]}
proc s5ChasComType.display {val} {set mdaType [lindex [split $val .] end]
switch -exact $mdaType {653 {
			return "450 24-TX Chassis"
		}
654 {
			return "450 12-TX Chassis"
		}
656 {
			return "450 1-SX MDA"
		}
657 {
			return "450 1-SR MDA"
		}
658 {
			return "450 4-TX MDA"
		}
659 {
			return "450 2-FX MDA"
		}
662 {
			return "450 1-LX MDA"
		}
663 {
			return "450 1-LR MDA"
		}
default {
			return "Unsupported MDA"
		}}}
proc s5AgTrpRcvrComm.modify {val inst} {return [string2octet $val]}
proc historyControlDataSource.modify {val inst} {return 1.3.6.1.2.1.2.2.1.1.[dmsCheckIfIndex $val]}
proc etherStatsDataSource.modify {val inst} {return [historyControlDataSource.modify $val $inst]}
proc alarmVariable.modify {val inst} {return [dm_GetOidFromName $val]}
proc historyControlDataSource.modify {val inst} {return 1.3.6.1.2.1.2.2.1.1.[ddCheckIfIndex $val]}
proc etherStatsDataSource.modify {val inst} {return [historyControlDataSource.modify $val $inst]}
proc ipNetToMediaIfIndex.modify {val inst} {return [ddCheckIfIndex $val]}
proc ipAdEntIfIndex.modify {val inst} {return [ddCheckIfIndex $val]}
proc ipRouteIfIndex.modify {val inst} {return [ddCheckIfIndex $val]}
proc rcVlanColor.modify {val inst} {global Dm_Pref
if {[set color [lsearch $Dm_Pref(colors) $val]] == -1} {return $val}
return $color}
global Dm_Vendor
set Dm_Vendor {Bay Networks, Inc}
proc octet2string { octetList } {set str ""
foreach octet $octetList {scan $octet %x i
set c [format %c $i]
append str $c}
return $str}
proc string2octet {val } {set octetList {}
foreach ch [split $val {}] {scan $ch %c i
append octetList [format %x $i]:}
return [string trim $octetList :]}
proc dmsCheckIfIndex {val} {if {[set n [scan $val %d/%d cardNo portNo]] == 2} {return $portNo}
return $val}
proc dmsRmonCheckEnabled {sess} {return}
proc dmsGetAlarmIndex {sess} {global Dm_AlarmIndex
if [catch {set resp [$sess get null {eventStatus.60535}]} err] {if {[string match noSuch* [lindex $err 2]]} {dmsCreateEvent $sess 60535 "Falling Event"}}
if [catch {set resp [$sess get null {eventStatus.60534}]} err] {if {[string match noSuch* [lindex $err 2]]} {dmsCreateEvent $sess 60534 "Rising Event"}}}
proc dmsBuildAlarmMenu {m} {set menuNo 0
foreach mdef {
		{Bridge {
		dot1dStpTimeSinceTopologyChange.0 dot1dStpTopChanges.0 dot1dStpMaxAge.0
		dot1dStpPortForwardTransitions -
		dot1dTpPortInFrames dot1dTpPortOutFrames dot1dTpPortInDiscards -
		dot1dTpLearnedEntryDiscards.0}}
		{Interface {
		ifInOctets ifInDiscards ifInErrors ifInMulticastPkts
		ifInBroadcastPkts ifInUnknownProtos -
		ifOutOctets ifOutDiscards ifOutErrors
		ifOutMulticastPkts ifOutBroadcastPkts -
		ifOperStatus ifLastChange }}
		{"Ethernet Errors" {
		dot3StatsAlignmentErrors dot3StatsFCSErrors
		dot3StatsSingleCollisionFrames dot3StatsMultipleCollisionFrames
		dot3StatsSQETestErrors dot3StatsDeferredTransmissions
		dot3StatsLateCollisions dot3StatsExcessiveCollisions
		dot3StatsInternalMacTransmitErrors dot3StatsCarrierSenseErrors
		dot3StatsFrameTooLongs dot3StatsInternalMacReceiveErrors}}
		{"RMON Stats" {
		etherStatsOctets. etherStatsPkts.
		etherStatsBroadcastPkts. etherStatsMulticastPkts.
		etherStatsCRCAlignErrors. etherStatsUndersizePkts.
		etherStatsOversizePkts. etherStatsFragments.
		etherStatsCollisions.}}
		{IP {
		ipInReceives.0 ipInHdrErrors.0 ipInAddrErrors.0
		ipForwDatagrams.0 ipInUnknownProtos.0 ipInDiscards.0
		ipInDelivers.0 ipOutRequests.0 ipOutDiscards.0
		ipOutNoRoutes.0 -
		ipFragOKs.0 ipFragFails.0 ipFragCreates.0 ipReasmReqds.0
		ipReasmOKs.0 ipReasmFails.0 -
		icmpInSrcQuenchs.0 icmpInRedirects.0 icmpInEchos.0
		icmpInEchoReps.0 icmpInTimestamps.0 icmpInTimestampReps.0
		icmpInAddrMasks.0 icmpInAddrMaskReps.0 icmpInParmProbs.0
		icmpInDestUnreachs.0 icmpInTimeExcds.0 -
		icmpOutSrcQuenchs.0 icmpOutRedirects.0 icmpOutEchos.0
		icmpOutEchoReps.0 icmpOutTimestamps.0 icmpOutTimestampReps.0
		icmpOutAddrMasks.0 icmpOutAddrMaskReps.0 icmpOutParmProbs.0
		icmpOutDestUnreachs.0 icmpOutTimeExcds.0}}
		{SNMP {
		snmpInPkts.0 snmpOutPkts.0 - snmpInBadVersions.0
		snmpInBadCommunityNames.0 snmpInBadCommunityUses.0
		snmpInASNParseErrs.0 snmpInTooBigs.0 snmpInNoSuchNames.0
		snmpInBadValues.0 snmpInReadOnlys.0 snmpInGenErrs.0
		snmpInTotalReqVars.0 snmpInTotalSetVars.0 snmpInGetRequests.0
		snmpInGetNexts.0 snmpInSetRequests.0 snmpInGetResponses.0
		snmpInTraps.0 - snmpOutTooBigs.0 snmpOutNoSuchNames.0
		snmpOutBadValues.0 snmpOutGenErrs.0 snmpOutGetRequests.0
		snmpOutGetNexts.0 snmpOutSetRequests.0 snmpOutGetResponses.0
		snmpOutTraps.0}}
		} {$m add cascade -label [rlindex mdef 0] -menu $m.$menuNo
set mc [menu $m.$menuNo]
incr menuNo
foreach v [rlindex mdef 1] {if {$v == "-"} {$mc add separator} else {$mc add command -label $v -command "dmsAlarmMenu $mc"}}}}
proc dmsIfIndex2Port {inst} {return 1/$inst}
proc dmsIndexPort {inst {display 0}} {if $display {return [dmsIfIndex2Port $inst]}
scan $inst "%d/%d" cardNo portNo
return $portNo}
proc dmsBitIfIndex2Port {inst} {return 1/[expr $inst]}
proc dmsBitIndexPort {inst} {scan $inst "%d/%d" cardNo portNo
return [expr $portNo]}
proc dmsIPAddrInsertTab {ip mask} {$mask delete 0 end
if {$ip == {0.0.0.0}} {$mask insert 0 0.0.0} elseif {[scan [$ip get] %d a] == 1} {if {$a < 128} {$mask insert 0 255.0.0.0} elseif {$a < 192} {$mask insert 0 255.255.0.0} elseif {$a < 256} {$mask insert 0 255.255.255.0}}}
proc dmsDiscoverMdaType {numCards inst parent sess} {global DmDMS Dm_Pref
catch {
		unset DmDMS(Chassis.Card.subClasses)
		#unset DmDMS(Chassis.Card.instances)
	}
if {[string first "450_24" $Dm_Pref(dmsFile)] != -1 ||
		[string first "350_24" $Dm_Pref(dmsFile)] != -1} {set chasType "24"} else {set chasType "12"}
lappend vbl "1.3.6.1.4.1.45.1.6.3.3.1.1.4.3.1.1"
if [catch {set resp [Sess0 get null $vbl]} err] {if {[rlindex err 2] == "noSuchName"} {if {$chasType == "24"} {set card(1) 24000} else {set card(1) 12000}
lappend DmDMS(Chassis.Card.subClasses) $card(1)} else {dm_Prompt .err "No cards returned. AGENT ERROR: [rlindex err 2]" Continue}
return}
set vbl [rlindex resp 4]
set s5ChasComType [lindex [rlindex vbl 0] 2]
set mdaType [lindex [split $s5ChasComType .] end]
set card(1) ${chasType}${mdaType}
if $Dm_Pref(trace) {puts "s5ChasComType=$s5ChasComType    mda=$mdaType"}
lappend DmDMS(Chassis.Card.subClasses) $card(1)}
proc dmsEndDiscovery {sess} {global DmsPriv Dm_Pref tcl_platform Dm_Path env DmsRmonScript DmDMS
catch {unset DmsPriv(vlanCache)}
if [catch {set r [Sess0 get null dot1dBaseBridgeAddress.0]}] {set DmsPriv(defaultBridge) ""} else {set DmsPriv(defaultBridge) [lindex [lindex [rlindex r 4] 0] 2]}
if {$tcl_platform(platform) == "unix" && [file isdirectory /opt/OV]} {if {[.mBar.help.m type 3] == "separator"} {.mBar.help.m insert 3 command -label "Run HP OpenView Install on Console" -command "exec $Dm_Path/dmdb/chameleon/v1003/OV/install &"}}
if ![info exists DmPref(rmonScriptsRead)] {if ![catch {set fd [open $env(HOME)/.rmonscript r]}] {while {[set line [gets $fd]] != ""} {set line [split $line =]
set DmsRmonScript([rlindex line 0]) [rlindex line 1]}
close $fd}
set DmPref(rmonScriptsRead) 1}}
proc ddCheckIfIndex {val} {if {[set n [scan $val %d/%d cardNo portNo]] == 2} {return $portNo}
return $val}
proc dmsARPBuildCB {frm inst sess isTable} {dmsCheckVlanCache $sess}
proc dmsPortInVlanCB {w id sess} {global DmsPriv
if [winfo exists .rcPort] {destroy .rcPort}
catch {
		foreach p [bit print [lindex [lindex [lindex [$sess get null rcVlanPortMembers.$id] 4] 0] 2]] {
			#in Chameleon, bit 0 is ifIndex 1
			incr p
			lappend membership [dmsIfIndex2Port $p]
		}
		set ifIndex [dmsIndexPort [dmsPromptPort $membership]]
		$w.f.v0 delete 0 end
		$w.f.v0 insert 0 [expr ($ifIndex<<16) + $DmsPriv(vlan.ifIndex.$id)]
	}}
proc dmsChasCardInstance {inst} {return 3.1.0}
proc dmsLedsStatusInstanceProc {inst} {return 1}
proc dmsLedsStatusProc {sess status} {global DmDMS Dm_Pref
if $Dm_Pref(trace) {puts "LedsStatus $status"}
set ledList(1) [.chassis find withtag Led::1]
set ledList(2) [.chassis find withtag Led::2]
set ledList(3) [.chassis find withtag Led::3]
set ledList(4) [.chassis find withtag Led::4]
set ledWinList ""
set mdaType $DmDMS(Chassis.Card.subClasses)
if {$mdaType < 24000} {set blk 1} else {set blk 2}
if {($mdaType == 24658) || ($mdaType == 12658)} {set i(1) 4
set i(2) 4
set i(3) 4
set i(4) 4} elseif {($mdaType == 24659) || ($mdaType == 12659)} {set i(1) 2
set i(2) 0
set i(3) 2
set i(4) 2} else {set i(1) 0
set i(2) 0
set i(3) 0
set i(4) 0}
for {set bcnt 1} {$bcnt <= $blk} {incr bcnt} {for {set gp 1} {$gp <= 4} {incr gp} {set j($gp) [expr $i($gp) + 11]
set ledWinList [concat $ledWinList [lrange $ledList($gp) $i($gp) $j($gp)]]
incr i($gp) 12}}
if {($mdaType == 24658) || ($mdaType == 12658)} {for {set gp 1} {$gp <= 4} {incr gp} {set ledWinList [concat $ledWinList [lrange $ledList($gp) 0 3]]}} elseif {($mdaType == 24659) || ($mdaType == 12659)} {set ledWinList [concat $ledWinList [lrange $ledList(1) 0 1]]
set ledWinList [concat $ledWinList [lrange $ledList(3) 0 1]]
set ledWinList [concat $ledWinList [lrange $ledList(4) 0 1]]} elseif {($mdaType == 24657) || ($mdaType == 12657) ||
($mdaType == 24656) || ($mdaType == 12656) ||
($mdaType == 24662) || ($mdaType == 12662) ||
($mdaType == 24663) || ($mdaType == 12663)} {set ledList(5) [.chassis find withtag Led::5]
set ledWinList [concat $ledWinList $ledList(5)]}
set statusList [lrange [split $status :] 5 end]
set inx -1
foreach st $statusList {set hi [string index $st 0]
set lo [string index $st 1]
foreach nibble "$hi $lo" {set win [rlindex ledWinList [incr inx]]
if {[expr $nibble & 001] || [expr $nibble & 005]} {.chassis itemconfig $win -foreground green} elseif {[expr $nibble & 002] || [expr $nibble & 006]} {.chassis itemconfig $win -foreground orange} elseif [expr $nibble & 004] {.chassis itemconfig $win -foreground green} else {.chassis itemconfig $win -foreground black}}}}
proc dmsActLedsStatusProc {statusList} {global DmDMS
set si 0
set li 0
set ledList [.chassis find withtag Led::4]
set mdaType $DmDMS(Chassis.Card.subClasses)
if {($mdaType == 24658) || ($mdaType == 12658)} {for {set j 0} {$j < 4} {incr j} {if {[rlindex statusList $j] == 9} {set clr green} else {set clr black}
.chassis itemconfig [rlindex ledList $j] -foreground $clr}
set si 4
set li 4} elseif {($mdaType == 24659) || ($mdaType == 12659)} {for {set j 0} {$j < 2} {incr j} {if {[rlindex statusList $j] == 9} {set clr green} else {set clr black}
.chassis itemconfig [rlindex ledList $j] -foreground $clr}
set si 2
set li 2} elseif {($mdaType == 24656) || ($mdaType == 12656) ||
($mdaType == 24662) || ($mdaType == 12662)} {set led5List [.chassis find withtag Led::5]
set tot [llength $led5List]
if {[rlindex statusList 0] == 9} {set clr green} else {set clr black}
.chassis itemconfig [rlindex led5List [expr $tot - 1]] -foreground $clr
set si 1
set li 0} elseif {($mdaType == 24657) || ($mdaType == 12657) ||
($mdaType == 24663) || ($mdaType == 12663)} {set led5List [.chassis find withtag Led::5]
set tot [llength $led5List]
if {[rlindex statusList 0] == 9} {set clr green} else {set clr black}
.chassis itemconfig [rlindex led5List [expr $tot - 2]] -foreground $clr
set si 1
set li 0}
set tot [llength $ledList]
for {} {$li < $tot} {incr si; incr li} {if {[rlindex statusList $si] == 9} {set clr green} else {set clr black}
.chassis itemconfig [rlindex ledList $li] -foreground $clr}}
