Document

Page 1

################################################### #! /bin/sh # The next line restarts using expect \ exec expect "$0" "$@" ############################################################################## # # intgtest.1.19.99.SpikeStrikerTunnelPortDisable.exp # # DESCRIPTION # # REQUIREMENTS #

1.

# # CREATED BY # David Lin,

June, 1 2009

# # MODIFIED BY # # ############################################################################## # # # Brocade Communications Systems, Inc. Proprietary and Confidential Information # All rights reserved. #

Copyright (c) 2005


############################################################################## #

source /vobs/multisite/intgtest/sdk/commonLib/support/libraries.inc source /vobs/multisite/intgtest/lib/saturn.lib source /vobs/multisite/intgtest/lib/marathon.lib source /vobs/multisite/intgtest/lib/platform.lib source /vobs/multisite/intgtest/lib/fcip_common.lib source /vobs/multisite/intgtest/inc/saturn.inc source /vobs/multisite/intgtest/lib/striker.lib ############################################################################## # # Create a header in the log file of the inputs for this script ############################################################################## # set cl_test_name "intgtest.1.19.99.SpikeStrikerTunnelPortDisable.exp: Portdisable/Portenable of 1g FCIP Tunnels on Spike between Striker and Spike" summarize_inputs

############################################################################## # Run the Serial Console Monitors ############################################################################## source $cl_inc_path/monitor.inc

global cl_PORTCFGDEFAULT_SUCCESS


global cl_WAIT_TIME_FCIP global cl_NETMASK global cl_MTU global cl_OPSTATUS global cl_geSUT_list global cl_geSEC_list global cl_veSUT_list global cl_veSEC_list global cl_xgeSUT_list global cl_xgeTERC_list global cl_xveSUT_list global cl_xveTERC_list global cl_telnet_pause global cl_telnet_timeout global cl_telnet_attempts

set PORTCFGDEFAULT_SUCCESS $cl_PORTCFGDEFAULT_SUCCESS set WAIT_TIME_FCIP $cl_WAIT_TIME_FCIP set NETMASK $cl_NETMASK set MTU $cl_MTU set OPSTATUS $cl_OPSTATUS set geSUT $cl_geSUT_list set geSEC $cl_geSEC_list set veSUT $cl_veSUT_list set veSEC $cl_veSEC_list


set xgeSUT $cl_xgeSUT_list set xgeTERC $cl_xgeTERC_list set xveSUT $cl_xveSUT_list set xveTERC $cl_xveTERC_list add_info "STATUS OF veSEC $cl_veSEC_list" add_info "STATUS OF veSUT $cl_veSUT_list"

global PORTCFGDEFAULT_SUCCESS set PORTCFGDEFAULT_SUCCESS "Suceeded" global WAIT_TIME_FCIP set WAIT_TIME_FCIP 30 global NETMASK set NETMASK 255.255.0.0 global MTU set MTU 1500 global OPSTATUS set OPSTATUS Up global env

set SUT [lindex $cl_ip_address_list 0] set SEC [lindex $cl_ip_address_list 1] set TERC [lindex $cl_ip_address_list 2] ######################################################################## # SWITCH LOGINS ########################################################################


foreach ip $cl_ip_address_list { if {[telnet_switch $ip] != 0} { add_status "CRITICAL ==> telnet to $ip failed after $cl_telnet_attempts tries with $cl_telnet_timeout seconds timeout on each" 1 } else { add_status "SUCCESS ==> telnet to $ip succeeded" } }

proc parse_portshowipif {geport} { global cl_ip_address set output [get_command "portshow ipif $geport"] set output_lines [split $output "\n"] set ip_list "" foreach line $output_lines { if {[regexp {\s.*ge[0-9]+\s*([0-9]+.[0-9]+.[0-9]+.[0-9]+)\s*/\s*([0-9]+)\s*([0-9]+)\s*} $line ignore ip netmask mtu] ==1} { lappend ip_list $ip } } return $ip_list }

proc Interface_creation {} { uplevel {1} {


######################################################################## # Find the striker slots, or determine that switch is spike. # re-do the above port lists with the proper striker slot # will ALWAYS take the last striker slot in the chassis!! ########################################################################

######################################################################## # AND Clean up all FCIP configurations ######################################################################## set SUT_slot "" set TERC_slot ""

set_spawn_id $SUT set platform [get_switch_platform] if { $platform > 48000 } { set slot_num "" set slots [get_slotshow_info 1] foreach slot $slots { if {[lindex $slot 1] == $env(STRIKER_BLADE_ID)} { set slot_num [lindex $slot 0] } } if {$slot_num == ""} { add_status "CRITICAL ==> no striker blade found in chassis!" 0


} set xgeSUT [list $slot_num/[lindex $xgeSUT 0]] set geSUT [list $slot_num/[lindex $geSUT 0] $slot_num/[lindex $geSUT 1] $slot_num/[lindex $geSUT 2] $slot_num/[lindex $geSUT 3]] set veSUT [list $slot_num/[lindex $veSUT 0] $slot_num/[lindex $veSUT 1] $slot_num/[lindex $veSUT 2] $slot_num/[lindex $veSUT 3]] set xveSUT [list $slot_num/[lindex $xveSUT 0]] #clean up by doing portcfgdefault on all ports for striker blade, or for the entire spike switch set SUT_slot $slot_num delete_all_by_slot $slot_num } else { add_status "no chassis" }

set_spawn_id $SEC set platform [get_switch_platform] if { $platform > 48000 } { set slot_num "" set slots [get_slotshow_info 1] foreach slot $slots { if {[lindex $slot 1] == $env(STRIKER_BLADE_ID)} { set slot_num [lindex $slot 0] } } if {$slot_num == ""} { add_status "CRITICAL ==> no striker blade found in chassis!" 0


} set geSEC [list $slot_num/[lindex $geSEC 0] $slot_num/[lindex $geSEC 1] $slot_num/[lindex $geSEC 2] $slot_num/[lindex $geSEC 3]] set veSEC [list $slot_num/[lindex $veSEC 0] $slot_num/[lindex $veSEC 1] $slot_num/[lindex $veSEC 2] $slot_num/[lindex $veSEC 3]] #clean up by doing portcfgdefault on all ports for striker blade, or for the entire spike switch } else { add_status "not chassis" delete_all_by_slot }

set geSEC [list [lindex $geSEC 0] [lindex $geSEC 1] [lindex $geSEC 2] [lindex $geSEC 3]] set veSEC [list [lindex $veSEC 0] [lindex $veSEC 1] [lindex $veSEC 2] [lindex $veSEC 3]]

add_info "STATUS OF veSEC IS $veSEC"

set_spawn_id $TERC set platform [get_switch_platform] if { $platform > 48000 } { set slot_num "" set slots [get_slotshow_info 1] foreach slot $slots { if {[lindex $slot 1] == $env(STRIKER_BLADE_ID)} { set slot_num [lindex $slot 0] } }


if {$slot_num == ""} { add_status "CRITICAL ==> no striker blade found in chassis!" 0 } set xgeTERC [list $slot_num/[lindex $xgeTERC 0]] set xveTERC [list $slot_num/[lindex $xveTERC 0]] #clean up by doing portcfgdefault on all ports for striker blade, or for the entire spike switch set TERC_slot $slot_num delete_all_by_slot $slot_num } else { add_status "not chassis" }

add_status "geSUT is $geSUT, geSEC is $geSEC" add_status "xgeSUT is $xgeSUT, xgeTERC is $xgeTERC, xveSUT is $xveSUT, xveTERC is $xveTERC"

add_info "\#\#\#\# Step 1: Setup FCIP Configuration Initially \#\#\#\#" ###################################################################### # INTERFACE GENERATION STRIKER(SUT)/SPIKE(SEC) ######################################################################

set start_ip 10 foreach index $geSUT { for {set i 1} {$i < 5} {incr i} {


lappend interfaceSUT($index) "$start_ip.$start_ip.1.$i" } set start_ip [expr $start_ip + 10] } set start_ip 10

foreach index $geSEC { for {set i 1} {$i < 5} {incr i} { lappend interfaceSEC($index) "$start_ip.$start_ip.2.$i" } set start_ip [expr $start_ip + 10] }

foreach item $geSUT { add_status "interfaceSUT($item) = $interfaceSUT($item)" }

foreach item $geSEC { add_status "interfaceSEC($item) = $interfaceSEC($item)" }

###################################################################### # PROGRAM INTERFACES ONTO STRIKER(SUT)/SPIKE(SEC)


###################################################################### set_spawn_id $SUT foreach ge $geSUT { foreach ip $interfaceSUT($ge) { do_command "portcfg ipif $ge create $ip netmask $NETMASK" } } show_interfaces $geSUT set_spawn_id $SEC foreach ge $geSEC { foreach ip $interfaceSEC($ge) { do_command "portcfg ipif $ge create $ip netmask $NETMASK" } } show_interfaces $geSEC

###################################################################### # PROGRAM TUNNELS ONTO STRIKER(SUT)/SPIKE(SEC) ######################################################################

for {set i 0} {$i < 4} {incr i} { set_spawn_id $SUT do_command "portcfg fciptunnel [lindex $veSUT $i] create -S [lindex $interfaceSUT([lindex $geSUT $i]) 0] -D [lindex $interfaceSEC([lindex $geSEC $i]) 0] -b 1000000 -B 1000000" set_spawn_id $SEC do_command "portcfg fciptunnel [lindex $veSEC $i] create -S [lindex $interfaceSEC([lindex


$geSEC $i]) 0] -D [lindex $interfaceSUT([lindex $geSUT $i]) 0] -b 1000000 -B 1000000" }

###################################################################### # PROGRAM CIRCUITS ONTO STRIKER(SUT)/SPIKE(SEC) ######################################################################

set j 0 for {set i 3} {$i >= 0} {set i [expr $i -1]} { set_spawn_id $SUT do_command "portcfg fcipcircuit [lindex $veSUT $j] create 1 -S [lindex $interfaceSUT([lindex $geSUT $i]) 1] -D [lindex $interfaceSEC([lindex $geSEC $i]) 1] -b 100000 -B 100000" set_spawn_id $SEC do_command "portcfg fcipcircuit [lindex $veSEC $j] create 1 -S [lindex $interfaceSEC([lindex $geSEC $i]) 1] -D [lindex $interfaceSUT([lindex $geSUT $i]) 1] -b 100000 -B 100000" incr j }

set_spawn_id $SUT add_status "showing all tunnels for $SUT" show_tunnels $veSUT set_spawn_id $SEC add_status "showing all tunnels for $SEC" show_tunnels $veSEC

#set_spawn_id $SUT


#delete_all $veSUT $geSUT

#set_spawn_id $SEC #delete_all $veSEC $geSEC

#set sw SUT #add_status "$interface[set sw](ge0)" 0 #add_status "$interfaceSEC($index)" 0

sleep $WAIT_TIME_FCIP

} }

proc striker_striker_interface {} { uplevel {1} { ###################################################################### # SET STRIKER BLADE MODES FOR 10GE CONFIGURATION BETWEEN STRIKER (SUT) # and STRIKER (SUT) ###################################################################### set_spawn_id $SUT do_command "bladecfggemode --set dual -slot $SUT_slot" verify_dualmode_striker set_spawn_id $TERC do_command "bladecfggemode --set dual -slot $TERC_slot"


verify_dualmode_striker

###################################################################### # INTERFACE GENERATION STRIKER(SUT)/STRIKER(TERC) ###################################################################### set start_ip 11 foreach index $xgeSUT { for {set i 1} {$i < 5} {incr i} { lappend interfaceSUTXGE($index) "$start_ip.$start_ip.1.$i" } set start_ip [expr $start_ip + 10] } set start_ip 11 foreach index $xgeTERC { for {set i 1} {$i < 5} {incr i} { lappend interfaceTERCXGE($index) "$start_ip.$start_ip.2.$i" } set start_ip [expr $start_ip + 10] }

foreach item $xgeSUT { add_status "interfaceSUTXGE($item) = $interfaceSUTXGE($item)" }

foreach item $xgeTERC {


add_status "interfaceTERCXGE($item) = $interfaceTERCXGE($item)" }

###################################################################### # PROGRAM IP INTERFACES STRIKER/STRIKER 10GE ###################################################################### #set interfaceSUTXGE #set interfaceTERCXGE

set_spawn_id $SUT foreach xge $xgeSUT { foreach ip $interfaceSUTXGE($xge) { do_command "portcfg ipif $xge create $ip netmask $NETMASK" } }

set_spawn_id $TERC foreach xge $xgeTERC { foreach ip $interfaceTERCXGE($xge) { do_command "portcfg ipif $xge create $ip netmask $NETMASK"


} }

###################################################################### # PROGRAM VE TUNNELS STRIKER/STRIKER 10GE ###################################################################### set stop [expr [llength $xveSUT] -1] for {set i 0} {$i <= $stop} {incr i} {

set_spawn_id $SUT do_command "portcfg fciptunnel [lindex $xveSUT $i] create -S [lindex $interfaceSUTXGE([lindex $xgeSUT $i]) 0] -D [lindex $interfaceTERCXGE([lindex $xgeTERC $i]) 0] -b 1000000 -B 1000000" set_spawn_id $TERC do_command "portcfg fciptunnel [lindex $xveTERC $i] create -S [lindex $interfaceTERCXGE([lindex $xgeTERC $i]) 0] -D [lindex $interfaceSUTXGE([lindex $xgeSUT $i]) 0] -b 1000000 -B 1000000"

}

###################################################################### # SHOW ALL TUNNELS ###################################################################### set_spawn_id $SUT add_status "showing all tunnels for $SUT"


show_tunnels $xveSUT set_spawn_id $TERC add_status "showing all tunnels for $TERC" show_tunnels $xveTERC

###################################################################### # PROGRAM VE CIRCUITS STRIKER/STRIKER 10GE ###################################################################### set stop [expr [llength $xveSUT] -1] set j 0 for {set i $stop} {$i >= 0} {set i [expr $i -1]} { set_spawn_id $SUT do_command "portcfg fcipcircuit [lindex $xveSUT $j] create 1 -S [lindex $interfaceSUTXGE([lindex $xgeSUT $i]) 1] -D [lindex $interfaceTERCXGE([lindex $xgeTERC $i]) 1] -b 100000 -B 100000" set_spawn_id $TERC do_command "portcfg fcipcircuit [lindex $xveTERC $j] create 1 -S [lindex $interfaceTERCXGE([lindex $xgeTERC $i]) 1] -D [lindex $interfaceSUTXGE([lindex $xgeSUT $i]) 1] -b 100000 -B 100000" incr j }

sleep 120 } }


proc verify_striker_spike {} { uplevel {1} { add_info "\#\#\#\# Step 2: Verify FCIP Configuration Setup Properly \#\#\#\#" ###################################################################### # VERIFY IP INTERFACES STRIKE(SUT)/SPIKE(SEC) ###################################################################### #sleep $WAIT_TIME_FCIP set_spawn_id $SUT foreach ge $geSUT { set rt [parse_portshowipif $ge] set ips [lsort $rt ] add_status "$ips" if {$ips == [lsort $interfaceSUT($ge)]} { add_status "FCIP interface IPs persist properly on $SUT $ge" 3 set pass_flag 1 } else { add_status "FCIP interface IPs did not persist on $SUT $ge, they should be [lsort $interfaceSUT($ge)]" 1 set pass_flag 0 } }

if {$pass_flag == 1} { set pass_flag "PASS" } else { set pass_flag "FAIL"


} add_info " FCIP 1GE interface IPs persistence on Striker($SUT) between Striker($SUT) and Spike($SEC) .............. $pass_flag"

set_spawn_id $SEC foreach ge $geSEC { set rt [parse_portshowipif $ge] set ips [lsort $rt ] add_status "$ips" if {$ips == [lsort $interfaceSEC($ge)]} { add_status "FCIP interface IPs persist properly on $SEC $ge" 3 set pass_flag 1 } else { add_status "FCIP interface IPs did not persist on $SEC $ge, they should be [lsort $interfaceSEC($ge)]" 1 set pass_flag 0 } }

if {$pass_flag == 1} { set pass_flag "PASS" } else { set pass_flag "FAIL" } add_info "FCIP 1GE interface IPs programmed on Spike $SEC between Striker($SUT) and Spike($SEC) .............. $pass_flag"


###################################################################### # VERIFY TUNNELS STRIKER(SUT)/SPIKE(SEC) ###################################################################### set_spawn_id $SUT set pass_flag [parse_portshowfciptunnel $veSUT "Verifying 1GE Tunnel Creation Proper on $SUT"] if {$pass_flag == 1} { set pass_flag "PASS" } else { set pass_flag "FAIL" } add_info "FCIP 1GE Tunnels programmed on Striker($SUT) between Striker($SUT) and Spike($SEC) .............. $pass_flag"

set_spawn_id $SEC set pass_flag [parse_portshowfciptunnel $veSEC "Verifying 1GE Tunnel Creation Proper on $SEC"] if {$pass_flag == 1} { set pass_flag "PASS" } else { set pass_flag "FAIL" } add_info "FCIP 1GE Tunnels programmed on Spike($SEC) between Striker($SUT) and Spike($SEC) .............. $pass_flag" ######################################################################


# VERIFY CIRCUITS STRIKER(SUT)/SPIKE(SEC) ###################################################################### set_spawn_id $SUT set pass_flag [parse_portshowfciptunnelcircuit $veSUT $geSUT "Verifying 1GE Circuit Creation Proper $SUT"] if {$pass_flag == 1} { set pass_flag "PASS" } else { set pass_flag "FAIL" } add_info "FCIP 1GE Circuits programmed on Striker($SUT) between Striker($SUT) and Spike($SEC) .............. $pass_flag" set_spawn_id $SEC set pass_flag [parse_portshowfciptunnelcircuit $veSEC $geSEC "Verifying 1GE Circuit Creation Proper $SEC"] if {$pass_flag == 1} { set pass_flag "PASS" } else { set pass_flag "FAIL" } add_info "FCIP 1GE Circuits programmed on Spike($SEC) between Striker($SUT) and Spike($SEC) .............. $pass_flag"

} }

proc verify_striker_striker {} {


uplevel {1} { ###################################################################### # VERIFY IP INTERFACES STRIKER STRIKER 10GE ###################################################################### set_spawn_id $SUT foreach xge $xgeSUT { set rt [parse_portshowipif $xge] set ips [lsort $rt ] if {$ips == [lsort $interfaceSUTXGE($xge)]} { add_status "FCIP interface IPs persist properly on $SUT $xge" 3 set pass_flag 1 } else { add_status "FCIP interface IPs did not persist on $SUT $xge, they should be [lsort $interfaceSUTXGE($xge)]" 1 set pass_flag 0 } }

if {$pass_flag == 1} { set pass_flag "PASS" } else { set pass_flag "FAIL" } add_info "FCIP 10GE interface IPs programmed on Striker($SUT) between Striker($SUT) and Striker($TERC) .............. $pass_flag"


set_spawn_id $TERC foreach xge $xgeTERC { set rt [parse_portshowipif $xge] set ips [lsort $rt ] if {$ips == [lsort $interfaceTERCXGE($xge)]} { add_status "FCIP interface IPs persist properly on $TERC $xge" 3 set pass_flag 1 } else { add_status "FCIP interface IPs did not persist on $TERC $xge, they should be [lsort $interfaceTERCXGE($xge)]" 1 set pass_flag 0 } }

if {$pass_flag == 1} { set pass_flag "PASS" } else { set pass_flag "FAIL" }

add_info "FCIP 10GE interface IPs programmed on Striker($TERC) between Striker($SUT) and Striker($TERC) .............. $pass_flag" ###################################################################### # VERIFY TUNNELS STRIKER(SUT)/ STRIKER (TERC) ###################################################################### set_spawn_id $SUT


set pass_flag [parse_portshowfciptunnel $xveSUT "Verifying 10GE Tunnel Creation Proper on $SUT"] if {$pass_flag == 1} { set pass_flag "PASS" } else { set pass_flag "FAIL" } add_info "FCIP 10ge tunnel(s) programmed on Striker($SUT) between Striker($SUT) and Striker($TERC) .............. $pass_flag" set_spawn_id $TERC set pass_flag [parse_portshowfciptunnel $xveTERC "Verifying 10GE Tunnel Creation Proper on $TERC"] if {$pass_flag == 1} { set pass_flag "PASS" } else { set pass_flag "FAIL" } add_info "FCIP 10ge tunnel(s) programmed on Striker($TERC) between Striker($SUT) and Striker($TERC) .............. $pass_flag"

###################################################################### # VERIFY CIRCUITS STRIKER(SUT)/ STRIKER(TERC) ###################################################################### set_spawn_id $SUT set pass_flag [parse_portshowfciptunnelcircuit $xveSUT $xgeSUT "Verifying 10GE Circuit Creation Proper on $SUT"] if {$pass_flag == 1} {


set pass_flag "PASS" } else { set pass_flag "FAIL" } add_info "FCIP 10ge circuit(s) programmed on Striker($SUT) between Striker($SUT) and Striker($TERC) .............. $pass_flag"

set_spawn_id $TERC set pass_flag [parse_portshowfciptunnelcircuit $xveTERC $xgeTERC "Verifying 10GE Circuit Creation Proper on $TERC"] if {$pass_flag == 1} { set pass_flag "PASS" } else { set pass_flag "FAIL" } add_info "FCIP 10ge circuit(s) programmed on Striker($TERC) between Striker($SUT) and Striker($TERC) .............. $pass_flag"

} }

Interface_creation

verify_striker_spike verify_striker_striker


add_info "\#\#\#\# Step 3: All FCIP Configuration Right after setup can be found below \#\#\#\#" set sut_path [collect_env_fcip $SUT [concat $geSUT $xgeSUT] "Striker" "AfterFCIPConfiguration"] add_info "FCIP Config for $SUT after programming FCIP Config ==> $sut_path" set sec_path [collect_env_fcip $SUT $geSEC "Spike" "AfterFCIPConfiguration"] add_info "FCIP Config for $SEC after programming FCIP Config ==> $sec_path" set terc_path [collect_env_fcip $TERC $xgeTERC "Striker" "AfterFCIPConfiguration"] add_info "FCIP Config for $TERC after programming FCIP Config ==> $terc_path"

############################################## # test disruption ############################################## set_spawn_id $SEC #do_command "slotpoweroff $SUT_slot" #sleep 2 #do_command "slotpoweron $SUT_slot" add_info "\#\#\#\# Step 4: Scenario 1: Portdisable/portenable VE ports on Striker $SUT \#\#\#\#"

foreach ve $veSEC { do_command "portdisable $ve" do_command "portenable $ve" } #######################################################################


##############################################

sleep 200

verify_striker_spike verify_striker_striker

add_info "\#\#\#\# Final Step: All FCIP Configuration Persistence after Scenario 1 can be found below \#\#\#\#" set sut_path [collect_env_fcip $SUT [concat $geSUT $xgeSUT] "Striker" "AfterScenarioConfiguration"] add_info "FCIP Config for $SUT after Scenario FCIP Config ==> $sut_path" set sec_path [collect_env_fcip $SUT $geSEC "Spike" "AfterScenarioConfiguration"] add_info "FCIP Config for $SEC after Scenario FCIP Config ==> $sec_path" set terc_path [collect_env_fcip $TERC $xgeTERC "Striker" "AfterScenarioConfiguration"] add_info "FCIP Config for $TERC after Scenario FCIP Config ==> $terc_path"

############################################################################ # Exit the script by returning the error count ############################################################################ add_status "intgtest.1.19.99.SpikeStrikerTunnelPortDisable.exp script completed and ended properly" 3


exit $cl_error_count

#############################################

namespace eval HERCULES {

proc map_switchid {cmd_test cmds switch_id} { puts "from hercules" set cmd_test [trim_string $cmd_test] global cl_vcs_mode if {$cl_vcs_mode == 0} { set switch_id 1 } if {[regexp {switchId|switchid|rbridge-id|rbridgeId} $cmd_test] } { # set cmd_list [list "clear" "clock" "interface" "sflow" "show" "qos" "vlan" "mac" "macaddress-table" "ip" "lldp" "gn_show_commands"] if {![regexp "/" $cmd_test]} { set indx1 [lsearch -regexp $cmd_test "rbridge-id|rbridgeId"] set indx_c [expr $indx1 + 1] set cmd_test [lreplace $cmd_test $indx_c $indx_c $switch_id] # add_status "cmd test 0 :==> $cmd_test" } else { set cmd_test [trim_string [split $cmd_test "/"]] set indx [lsearch -regexp $cmd_test "switch"] set len_cmd [llength [lindex $cmd_test $indx]] if {$len_cmd > 1} {


set value [trim_string [split [lindex $cmd_test $indx] " "]] set value [combine_lists $value] set indx_1 [lsearch -regexp $value "switch"] regsub [lindex $value $indx_1] $value $switch_id value set value [combine_lists $value] regsub [lindex $cmd_test $indx] $cmd_test $value cmd_test set cmd_test [trim_string $cmd_test] set cmd_test [trim_string [join $cmd_test "/"]] # add_status "cmd test 1 === > $cmd_test" } else { regsub [lindex $cmd_test $indx] $cmd_test $switch_id cmd_test set cmd_test [trim_string [join $cmd_test "/"]] # add_status "cmd test 2=== > $cmd_test"

}

} } return [trim_string $cmd_test] }

#API to do support save, 0 - success and 1 - failure proc do_supportsave {host user password path {switchid ""} {protocol "ftp"}} { global timeout cl_NOS_PROMPT cl_log_path cl_ip_address


set ret_val 0 if {[regexp -nocase {logdir} $path]} { set ts [exec date +%Y%m%d%H%M%S] set ss_dir "SS_${ts}_${cl_ip_address}" exec mkdir ${cl_log_path}/dumps/$ss_dir set path "${cl_log_path}/dumps/$ss_dir" catch {exec chmod -R 777 $path} } if {$switchid == ""} { set cmd "copy support $protocol directory $path host $host user $user password $password" } else { set cmd "copy support $protocol directory $path host $host user $user password $password rbridge-id $switchid" } if {$protocol == "usb"} { set cmd "copy support usb directory $path rbridge-id all" } send_command "$cmd" set tmp_timeout $timeout set timeout 600 expect { -re "SupportSave failed" { add_status "Support save Failed" 1 incr ret_val exp_continue


} -re "copy support complete" { add_status "Support save completed successfully" 3 exp_continue } -re "$cl_NOS_PROMPT" {

} timeout { add_status "Support save timed out" 2 } } set timeout $tmp_timeout return $ret_val } proc get_vcs_status {ip} { brcd_nos_login $ip set retval -1 set output [n_get_output "show vcs detail"] set mode -1 regexp {(?:Config Mode|state)[ \t]+:[ \t]+([^\r\n]+)} $output ignore mode

if {[regexp -nocase {Disabled} $mode]} { set retval 0 } elseif {[regexp {Local-Only|Distributed} $mode]} {


set no_of_failed_nodes [regexp -all -nocase {Condition[ \t]+:[ \t]+Failed} $output] if {$no_of_failed_nodes > 0} { set retval 2 } else { set retval 1 } } else { } # set no_of_nodes [regexp -all {Vcs Mode[ \t]+:|state[ \t]+:} $output] # set no_of_disabled_nodes [regexp -nocase -all {state[ \t]+:[ \t]+Disabled|Vcs Mode[ \t]+:[ \t] +Disabled} $output] # if {$no_of_nodes == $no_of_disabled_nodes} { #

set retval 0

# } else { #

set retval 1

# } return $retval }

}

proc get_vcs_param_list {vcs_arr param} { upvar $vcs_arr vcs_arr_ set param_list [list] foreach name [array names vcs_arr_] { if {[regexp "$param" $name]} {


if {$param == "Management IP"} { set value $vcs_arr_($name) regexp {\d+\.\d+\.\d+\.\d+} $value value } elseif {$param == "Rbridge-Id"} { set value $vcs_arr_($name) regexp {\d+} $value value } else { set value $vcs_arr_($name) } lappend param_list $value } } return $param_list }

proc enable_managed_cluster {ip_list {vcsid 1} {rbridgeid AUTO}} { global cl_mc_wait_time set mc_file "mc_cluster.txt" execute_cmd_parallel "=enable_vcs $rbridgeid $vcsid yes no yes" $ip_list $mc_file close_spawn_list if {[info exists cl_mc_wait_time]} { set MC_WAIT_TIME $cl_mc_wait_time } else { set MC_WAIT_TIME 180 }


add_status "Wait $MC_WAIT_TIME sec for Managed Cluster to up" sleep $MC_WAIT_TIME brcd_nos_login [lindex $ip_list 0] parse_vcs_info vcs_arr set cluster_list [get_vcs_param_list vcs_arr "Management IP"] set disjoint_list [get_list_disjoint $cluster_list $ip_list] set intersection_list [get_list_intersection $disjoint_list $ip_list] if {[llength $intersection_list] == 0} { add_status "All the given IPs are present in the managed cluster mode" 3 set mc_sw_state_list [get_vcs_param_list vcs_arr "Condition"] set mc_sw_state_in_good_condition [lsearch -all -inline $mc_sw_state_list "Good"] if {[llength $mc_sw_state_in_good_condition] != [llength $ip_list]} { add_status "Some of the nodes are not in Good state" 1 return 1 } else { return 0 } } else { add_status "Some IPs are missing in the managed cluster mode,$intersection_list" 1 return 1 } }

proc enable_isl_r_rdy {interface_list {type "FibreChannel"}} { foreach interface $interface_list {


n_do_command "config>>interface $type $interface>>isl-r_rdy" } }

proc disable_isl_r_rdy {interface_list {type "FibreChannel"}} { foreach interface $interface_list { n_do_command "config>>interface $type $interface>>no isl-r_rdy" } }

proc compare_vcs_fabric {vcs_arr {mode "MC"}} { upvar $vcs_arr vcs_arr_ set failed 0 set fabric_info [parse_show_fabric_all num_switches vcs_id vcs_mode] #Check vcs_mode from fabric show is "Managed Cluster" add_status "Checking VCS formation for vcs_mode - $vcs_mode" if {$mode == "FC"} { set mode_out "Fabric Cluster|Local" } elseif {$mode == "MC"} { set mode_out "Managed Cluster|Distributed" } if {![regexp -nocase "$mode_out" $vcs_mode]} { add_status "vcs_mode not in \"[lindex [split $mode_out "|"] 0]\" mode in show fabric all output" 1 } #Check number of nodes are same in both show vcs and show fabric all


puts "num_switches-$num_switches and TOTAL_NODES - $vcs_arr_(TOTAL_NODES)" if {$num_switches != $vcs_arr_(TOTAL_NODES)} { add_status "Total no. of nodes not matching between show vcs and show fabric all. Former: $vcs_arr_(TOTAL_NODES), Latter:$num_switches" 1 incr failed } #Check primary and principal switch is same #get principal from show fabric all set f_principal_ip "" set f_all_ip_list [list] set f_all_rbridgeid_list [list] foreach info $fabric_info { set info [lindex $info 0] lappend f_all_ip_list [lindex $info 3] if {[regexp {^>} [lindex $info 4]]} { set f_principal_ip [lindex $info 3] set f_all_rbridgeid_list [lindex $info 0] } } add_status "Principal switches from show fabric all is $f_principal_ip and ip list is $f_all_ip_list" #get primary from show vcs set v_primary_ip "" set v_all_ip_list [list] set v_all_rbridgeid_list [list] foreach name [array names vcs_arr_] {


if {![regexp {,} $name]} { continue } set node [lindex [split $name ","] 0] set node_info [lindex [split $name ","] 1]

if {[regexp {Management IP$} $name]} { puts "====>1. name - $name , expected - Management IP" set ip $vcs_arr_($name) regexp {\d+\.\d+\.\d+\.\d+} $ip ip lappend v_all_ip_list $ip lappend v_all_rbridgeid_list $vcs_arr_($node,Rbridge-Id) } if {$vcs_arr_($node,Co-ordinator) == "YES"} { puts "=====>2. name - $name, expected ,principal node, $node, $vcs_arr_($node,Coordinator)" set v_primary_ip $vcs_arr_($node,Management IP) regexp {\d+\.\d+\.\d+\.\d+} $v_primary_ip v_primary_ip set current_version [join [lrange [regexp -inline {([0-9])\.([0-9])\.*} [get_version_nos]] 1 end] ""] if {$current_version <= 40 } { set state "Status" } else { set state "VCS Status" } if {![regexp {Co-ordinator} $vcs_arr_($node,$state)]} { add_status "Primary and Principal not referring to the same node in show vcs output" 1 incr failed


} } } puts "v_primary_ip- $v_primary_ip and v_all_ip_list -$v_all_ip_list" if {$f_principal_ip != $v_primary_ip} { add_status "Principal and Primary switches not matched between show vcs($v_primary_ip) and show fabric all($f_principal_ip) output" 1 incr failed } #Check all IPs are same in both the output set disjoint_list [get_list_disjoint $v_all_ip_list $f_all_ip_list] if {[llength $disjoint_list] > 0} { add_status "Some mismatch in IP list between show vcs and show fabric all output" 1 incr failed }

#Check cluster generic status to be good if {$mode == "MC" && $vcs_arr_(CLUSTER_CONDITION) != "Good"} { add_status "Cluster status not in good state" 1 incr failed } if {$failed == 0} { add_status "All comparisons passed between show vcs and show fabric all" 3 return 1 } return 0


}

#this procedure will be used to verify the details from show fabric all #the verfy_string is the list , first element contains the field to be checked and second element contains the value #for eg. in the script it will be called as "set verify_strng [list "Rbridge-id" 5] or set verify_strng [list "Name" "fcr_fd_126"]

proc verify_fabric_show_output {verfy_string {fabriclist ""} } { if {$fabriclist == ""} { set fabriclist [parse_show_fabric_all num_switches] } foreach fabriclst $fabriclist { if {[lindex $verfy_string 0] == "Rbridge-id"} { set rbrdg_id [lindex [lindex $fabriclst 0] 0] if {$rbrdg_id == [lindex $verfy_string 1]} { #add_status "Verified the rbridge-id is correctly displayed as $rbrdg_id" 3 set pass 1 break } else { set pass 0 } } if {[lindex $verfy_string 0] == "WWN"} { set wwn [lindex [lindex $fabriclst 0] 2] if {$wwn == [lindex $verfy_string 1]} {


#add_status "Verified the wwn is correctly displayed as $wwn" 3 set pass 1 break } else { set pass 0 } } if {[lindex $verfy_string 0] == "IP Address"} { set ip_addr [lindex [lindex $fabriclst 0] 3] if {$ip_addr == [lindex $verfy_string 1]} { #

add_status "Verified the ip address is correctly displayed as

$ip_addr" 3 set pass 1 break } else { set pass 0 } } if {[lindex $verfy_string 0] == "Name"} { #

add_status "What is this [lindex $fabriclst 0]" 3 set name [lindex [lindex $fabriclst 0] 4]

#

add_status "name=$name" 3 if {[regexp "fcr_fd" [lindex $verfy_string 1]]} { if {[regexp "[lindex $verfy_string 1]" $name]} { #

displayed as $name" 3

add_status "Verified the front domain name is correctly


set pass 1 break } else { set pass 0 } } elseif {[regexp "fcr_xd" [lindex $verfy_string 1]]} { if {[regexp "[lindex $verfy_string 1]" $name]} { # correctly disaplayed as $name" 3

add_status "Verified the translate domain name is set pass 1 break

} else { set pass 0 } } else { if {$name == [lindex $verfy_string 1]} { add_status "Verified the switch name is correctly displayed as $name" 3 set pass 1 break } else { set pass 0 } } } }


if {[lindex $verfy_string 0] == "Rbridge-id"} { if {$pass == 1} { add_status "Verified the rbridge-id is correctly displayed as $rbrdg_id" 3 } else { add_status "Error the rbridge-id is wrongly displayed as $rbrdg_id" 1 } } elseif {[lindex $verfy_string 0] == "WWN"} { if {$pass == 1} { add_status "Verified the wwn is correctly displayed as $wwn" 3 } else { add_status "Error the wwn is wrongly displayed as $wwn" 1 } } elseif {[lindex $verfy_string 0] == "IP Address"} { if {$pass == 1} { add_status "Verified the ip address is correctly displayed as $ip_addr" 3 } else { add_status "Error the ip address is wrongly displayed as $ip_addr" 3 } } elseif {[lindex $verfy_string 0] == "Name"} { if {[regexp "fcr_fd" [lindex $verfy_string 1]]} { if {$pass == 1} { add_status "Verified the front domain name is correctly displayed as $name" 3 } else { add_status "Error The front domain name is wrongly displayed as $name" 1


} } elseif {[regexp "fcr_xd" [lindex $verfy_string 1]]} { if {$pass == 1} { add_status "Verified the translate domain name is correctly disaplayed as $name" 3 } else { add_status "Error The translate domain name is wrongly displayed as $name" 1 } } else { if {$pass == 1} { add_status "Verified the switch name is corectly disaplyed as $name" 3 } else { add_status "Error the switch name is wrongly disaplyed as $name" 1 } } } }

proc get_random_id {min max exception_list} { set id [get_random_integer $min $max] if {[lsearch $exception_list $id] != -1} { get_random_ids $min $max $exception_list } else { return $id


} }

proc execute_debug_cmd {ip cmd} { brcd_nos_login $ip "fos" set status [get_command "/fabos/libexec/DcmClient.Linux.powerpc debug $cmd" 60] if {[regexp {^ERROR|FAIL} $status]} { add_status "Found some error or failures in debug cmd $cmd" 1 } brcd_nos_login $ip }

proc get_param_list_fabricshow {fabric_list param} { if {$param == "rbridge" } { set index 0 } elseif {$param == "ip"} { set index 3 } elseif {$param == "wwn"} { set index 2 } elseif {$param == "name"} { set index 4 } else { #No param specified } set TOTAL_COLS 5


set current_param_list [list] foreach line $fabric_list { set line [lindex $line 0] if {[llength $line] == $TOTAL_COLS} { lappend current_param_list [lindex $line $index] } } return $current_param_list }

proc create_vlan {vlan_id} { set current_version [join [lrange [regexp -inline {([0-9])\.([0-9])\.*} [get_version_nos]] 1 end] ""] add_status "Current Version: $current_version" if { $current_version < 40 } { set cmd "config>>interface vlan $vlan_id>>no shut" } else { set cmd "config>>interface vlan $vlan_id" } if {[n_do_command $cmd] != 0} { add_status "Error in VLAN creation" 1 } }

proc remove_vlan {vlan_id} { set cmd "config>>no interface vlan $vlan_id"


if {[n_do_command $cmd] != 0} { add_status "Error in VLAN removal" 1 } }

proc get_node_num_from_vcs_arr {vcs_arr ip} { upvar $vcs_arr vcs_arr_ foreach name [array names vcs_arr_] { set node_num [lindex [split $name ","] 0] set param [lindex [split $name ","] 1] if {$param == "Management IP" && [regexp "$ip" $vcs_arr_($node_num,Management IP)]} { return $node_num } } return -1 }

proc get_vcs_arr_param_value {vcs_arr ip param} { upvar $vcs_arr vcs_arr_ set node_num [get_node_num_from_vcs_arr vcs_arr_ $ip] if {$node_num != -1} { if {[info exists vcs_arr_($node_num,$param)]} { return $vcs_arr_($node_num,$param) } else { add_status "Given param $param is invalid or not found in the vcs_arr" 2


} } else { add_status "Given IP:$ip not found in the given vcs_arr" 2 } }

proc verify_isl_segmentation {local_node seg_err} { #Get all local eports set l_port_list [get_all_eports_from_tb $local_node] add_status "l_port_list=$l_port_list==>" brcd_nos_login $local_node set l_segmented_ports [get_isl_ports_for "op_state" $seg_err] set non_segmented_list [list] foreach l_port $l_port_list { if {[lsearch $l_segmented_ports $l_port] == -1} { #segment error not found in local switch, verify in remote switch set remote_info [get_remote_node_port $local_node $l_port] set remote_node [lindex $remote_info 0] set remote_port [lindex $remote_info 1] brcd_nos_login $remote_node set r_segmented_ports [get_isl_ports_for "op_state" $seg_err] add_status "remoted switch - $remote_node and segmented ports -$r_segmented_ports ## remote_port=$remote_port" if {[lsearch $r_segmented_ports $remote_port] == -1} { regexp {\d+\/\d+\/(\d+)} $l_port ignore l_port lappend non_segmented_list $l_port


} } } if {[llength $non_segmented_list] > 0} { set expected_list [list] set temp_list [regexp -all -inline {\d+/\d+/(\d+)} $l_port_list] for {set i 1} {$i < [llength $temp_list]} {incr i 2} { lappend expected_list [lindex $temp_list $i] } add_status "Some of the expected ports not segmented(verified both local and remote switch), $non_segmented_list, Expected:$expected_list" 1 } else { add_status "Verified the segmentation error successfully" 3 } }

proc verify_config_cleared {rbridge_id {negative -1}} { set notCleared_list [list] #collecting all configuration with keyword rbridge set op1 [compress_list [split [n_get_output "show running-config | include rbridge"] "\r\n"]] set op1 [lrange $op1 1 end-1] set temp_list [list] foreach line $op1 { if {[regexp "rbridge\(-id\|Id|Id|id\)?\[ \t]+$rbridge_id\(\$|\[ \t]+)" $line]} { puts "line - $line" lappend temp_list $line }


} lappend notCleared_list $temp_list #collecting all configuration with keyword switchid or switch-id set op1 [compress_list [split [n_get_output "show running-config | include switchid|switchid"] "\r\n"]] set op1 [lrange $op1 1 end-1] set temp_list [list] foreach line $op1 { if {[regexp "switchid\|switch-id\[ \t]+$rbridge_id\(\$|\[ \t]+)" $line]} { lappend temp_list $line } } lappend notCleared_list $temp_list #Collecting all Tengig interface status set op1 [compress_list [split [n_get_output "show running-config | include TenGigabitEthernet"] "\r\n"]] set op1 [lrange $op1 1 end-1] set temp_list [list] foreach line $op1 { if {[regexp "TenGigabitEthernet\[ \t]+$rbridge_id/\\d+/\\d+" $line]} { lappend temp_list $line } } lappend notCleared_list $temp_list #Collecting all Fcoe status set op1 [compress_list [split [n_get_output "show running-config | include Fcoe"] "\r\n"]]


set op1 [lrange $op1 1 end-1] set temp_list [list] foreach line $op1 { if {[regexp "Fcoe\[ \t]+\\d+/$rbridge_id/\\d+" $line]} { lappend temp_list $line } } lappend notCleared_list $temp_list #Collecting management interface info set op1 [compress_list [split [n_get_output "show running-config | include Management"] "\r\n"]] set op1 [lrange $op1 1 end-1] set temp_list [list] foreach line $op1 { if {[regexp "Management\[ \t]+$rbridge_id/\\d+" $line]} { lappend temp_list $line } } lappend notCleared_list $temp_list set notCleared_list [compress_list $notCleared_list] if {$negative == -1} { if {[llength $notCleared_list] == 0} { add_status "Config cleared successfully for the node $rbridge_id" 3 } else { add_status "Error in config clear for the node, $rbridge_id. Non cleared list: $notCleared_list" 1


} } else { if {[llength $notCleared_list] > 0} { add_status "Config not cleared for rbridgeid, $rbridge_id" 3 } else { add_status "Config cleared for rbridgid, $rbridge_id which is not expected" 1 } } }

proc set_vip {ipaddr {verify "yes"}} { if {[n_do_command "config>>vcs virtual ip address $ipaddr" ] == 0} { add_status "VIP configured successfully" 3 } else { add_status "VIP failed to set" 1 } if {$verify == "yes"} { verify_vip $ipaddr } copy_config }

proc remove_vip {ipaddr {verify "yes"} } { if {[n_do_command "config>>no vcs virtual ip address $ipaddr"] == 0} {


add_status "VIP removed successfully" 3 } else { add_status "VIP removal failed " 1 } if {$verify == "yes"} { verify_removal_vip $ipaddr } }

proc get_pri_ip_rbgid {vcs_arr} { upvar $vcs_arr vcs_arr_ foreach name [array names vcs_arr_] { if {![regexp {,} $name]} { continue } set node [lindex [split $name ","] 0] if {$vcs_arr_($node,Co-ordinator) == "YES"} { set v_primary_ip $vcs_arr_($node,Management IP) regexp {\d+\.\d+\.\d+\.\d+} $v_primary_ip v_primary_ip set rbgid $vcs_arr_($node,Rbridge-Id) regexp {\d+} $rbgid rbgid set v_primary_ip $v_primary_ip } } add_status "Primary IP : ===> $v_primary_ip and rbgid ==> $rbgid" return [list $v_primary_ip $rbgid] }


proc set_hostname {hname rbid {verify "yes"}} { if {[n_do_command "config>>switch-attributes $rbid host-name $hname"] == 0} { add_status "Host name: $hname configured successfully" 3 } else { add_status "Host name : $hname failed to set" 1 } if {$verify == "yes"} { verify_hname_fabricall $hname } }

proc verify_FCmode {} { set output [n_get_output "show vcs detail"] if {([regexp -nocase {Config Mode[ \t]+:[ \t]+Local-Only} $output]) } { set value 1 } else { set value 0 } return $value }


proc verify_MCmode {} { set output [n_get_output "show vcs detail"] if {[regexp -nocase {Config Mode[ \t]+:[ \t]+Distributed} $output]} { if {[regexp -nocase -all {Condition[ \t]+:[ \t]+Failed|Vcs Mode[ \t]+:[ \t]+Disabled} $output]} { set retval 0 } else { set retval 1 } } else { set retval 0 } return $retval

}

proc SD_FC_MC {ip mode } { set SUT [lindex $ip 0] set cluster_ip_list $ip while {1} { add_status "Set all switches to standalone mode" set cmd_input "rm_cluster.txt" execute_cmd_parallel "=remove_cluster_config" $cluster_ip_list $cmd_input


if {$mode == "MC"} { add_status "Enable Managed cluster mode in all the switches" if {[enable_managed_cluster $cluster_ip_list ] != 0} { add_status "Error in forming managed cluster mode" 1 break } add_status "Matching \"show vcs\" output with \"show fabric all\"" brcd_nos_login $SUT parse_vcs_info vcs_arr compare_vcs_fabric vcs_arr } elseif {$mode == "FC"} { add_status "Enabling VCS in all the switches" if {[enable_vcs_parallel $cluster_ip_list "no"] != 0} { add_status "Error in enabling VCS" 0 } add_status "Verify fabric formation" verify_fabric $cluster_ip_list } else { add_status "Supported options - MC and FC" 2 }

break }


}

proc FC_MC {ip mode } { global cl_SD_FC_MC set SUT [lindex $ip 0] set cluster_ip_list $ip while {1} { set cmd_input "rm_cluster.txt" if {$mode == "MC"} { if {$cl_SD_FC_MC == 1} { SD_FC_MC $cluster_ip_list $mode } else { set value [verify_MCmode] if {$value == 0} { add_status "Set all switches to standalone mode" execute_cmd_parallel "=remove_cluster_config" $cluster_ip_list $cmd_input add_status "Enable Managed cluster mode in all the switches" if {[enable_managed_cluster $cluster_ip_list ] != 0} { add_status "Error in forming managed cluster mode" 1 break } add_status "Matching \"show vcs\" output with \"show fabric all\"" brcd_nos_login $SUT


parse_vcs_info vcs_arr compare_vcs_fabric vcs_arr } else { add_status " The switches are already in Managed Cluster mode" 3 } } } elseif {$mode == "FC"} { if {$cl_SD_FC_MC == 1} { SD_FC_MC $cluster_ip_list $mode } else { set value 0 foreach ip $cluster_ip_list { brcd_nos_login $ip set retval [verify_FCmode] if {$retval == 1} { add_status "$ip is in Fabirc cluster mode" } else { set value 1 } } if {$value == 1} { add_status "All the switches are not in Fabric cluster mode" add_status "Set all switches to standalone mode" execute_cmd_parallel "=remove_cluster_config" $cluster_ip_list $cmd_input add_status "Enabling VCS in all the switches"


if {[enable_vcs_parallel $cluster_ip_list "no"] != 0} { add_status "Error in enabling VCS" 1 } add_status "Verify fabric formation" verify_fabric $cluster_ip_list } } } else { add_status "Supported options - MC and FC" 2 }

break } }

proc add_member_entry {zone_name_list wwn_lol {cluster_list ""} {verify "yes"}} { foreach zone_name $zone_name_list wwn_list $wwn_lol { foreach wwn $wwn_list { set cmd "config>>zoning defined-configuration zone $zone_name>>member-entry $wwn" if {[n_do_command $cmd] != 0} { add_status "Error in command $cmd execution" 1 } after 1000 } }


if {$verify == "yes"} { verify_member_entry $zone_name_list $wwn_lol $cluster_list } }

proc verify_member_entry {zone_name_list wwn_lol {cluster_list ""}} { global cl_ip_address if {$cluster_list == ""} { set ip_list_to_verify $cl_ip_address } else { set ip_list_to_verify $cluster_list } foreach ip $ip_list_to_verify { brcd_nos_login $ip add_status "Verifying in switch $ip" set defined_cfg [parse_defined_zoning] if {$defined_cfg == -1} { add_status "No defined configuration" 2 return } array set zone_cfg_arr [lindex $defined_cfg 1] foreach zone_name $zone_name_list wwn_list $wwn_lol { if {[info exists zone_cfg_arr($zone_name)]} { set current_member_list $zone_cfg_arr($zone_name) set disjoint_list [get_list_disjoint $current_member_list $wwn_list]


set inter_list [get_list_intersection $disjoint_list $wwn_list] if {[llength $inter_list] > 0} { add_status "All the given wwns not present in the defined configuration in zone $zone_name, Expected:$wwn_list, Actual:$zone_cfg_arr($zone_name)" 1 } else { add_status "All the given wwns are present in the defined configurations in zone $zone_name" 3 } } else { add_status "Zone $zone_name does not exist in defined configuration" 1 } } }

}

proc add_member_zone {cfg_name_list zone_lol {cluster_list ""} {verify "yes"}} { foreach cfg_name $cfg_name_list zone_name_list $zone_lol { foreach zone_name $zone_name_list { set cmd "config>>zoning defined-configuration cfg $cfg_name>>member-zone $zone_name" if {[n_do_command $cmd] != 0} { add_status "Error in command $cmd execution" 1 } after 1000 } }


if {$verify == "yes"} { verify_member_zone $cfg_name_list $zone_lol $cluster_list }

}

proc verify_member_zone {cfg_name_list zone_lol {cluster_list ""}} { global cl_ip_address if {$cluster_list == ""} { set ip_list_to_verify $cl_ip_address } else { set ip_list_to_verify $cluster_list } foreach ip $ip_list_to_verify { add_status "Verifying in switch $ip" brcd_nos_login $ip set defined_cfg [parse_defined_zoning] if {$defined_cfg == -1} { add_status "No defined configuration" 2 return } array set cfg_arr [lindex $defined_cfg 0] foreach cfg_name $cfg_name_list zone_name_list $zone_lol { if {[info exists cfg_arr($cfg_name)]} { set current_member_list $cfg_arr($cfg_name)


set disjoint_list [get_list_disjoint $current_member_list $zone_name_list] set inter_list [get_list_intersection $disjoint_list $zone_name_list] if {[llength $inter_list] > 0} { add_status "All the given zones not present in the defined configuration in cfg $cfg_name, Expected:$zone_name_list, Actual:$cfg_arr($cfg_name)" 1 } else { add_status "All the given zones are present in the defined configurations in cfg $cfg_name" 3 } } else { add_status "Cfg $cfg_name does not exist in defined configuration" 1 } } }

}

proc def_zone_noaccess {{config "noaccess"}} { if {$config == "noaccess"} { set set_to "noaccess" } else { set set_to "allaccess" } set cmd "config>>zoning enabled-configuration default-zone-access $set_to" if {[n_do_command $cmd] != 0} {


add_status "Error in command $cmd execution" 1 }

} proc enable_cfg {cfg_name {zone_members ""} {cluster_list ""} {verify "yes"}} { set cmd "config>>zoning enabled-configuration cfg-name $cfg_name" if {[n_do_command $cmd] != 0} { add_status "Error in command $cmd execution" 1 } if {$verify == "yes"} { verify_cfg $cfg_name $zone_members $cluster_list } }

proc verify_cfg {cfgname {zone_members ""} {cluster_list ""}} { global cl_ip_address if {$cluster_list == ""} { set ip_list_to_verify $cl_ip_address } else { set ip_list_to_verify $cluster_list } foreach ip $ip_list_to_verify { add_status "Verifying in switch $ip" brcd_nos_login $ip set enabled_cfg [parse_enabled_zoning]


set enabled_cfgname [lindex [lindex $enabled_cfg 0] 0] regexp {(?:\")?(.*) (?:\(\*\)\")?} $enabled_cfgname ig enabled_cfgname ; #this line is to avoid if cfg name comes with "cfgname (*)" like format if {$enabled_cfgname == $cfgname} { add_status "Given cfgname $cfgname is present in enabled configuration" 3 } else { add_status "Given cfgname $cfgname is not in the enabled configuration, Expected: $cfgname, Actual:$enabled_cfgname" 1 } if {$zone_members != ""} { puts "====>zone_members - $zone_members" array set expected_zone_arr $zone_members array set actual_zone_arr [lindex $enabled_cfg 1] foreach zone [array names expected_zone_arr] { if {[info exists actual_zone_arr($zone)]} { set disjoint_list [get_list_disjoint $expected_zone_arr($zone) $actual_zone_arr($zone)] if {[llength $disjoint_list] > 0} { add_status "Mimatch in enabled zone members, Expected: $expected_zone_arr($zone), Actual:$actual_zone_arr($zone)" 1 } } else { add_status "Expected zone, $zone not in the enabled configuration" 1 } } } }


}

proc remove_member_entry {zone_name_list wwn_lol {cluster_list ""} {verify "yes"}} { set defined_cfg [parse_defined_zoning] array set zone_cfg_arr [lindex $defined_cfg 1] set last_entry_zones [list] foreach zone_name $zone_name_list wwn_list $wwn_lol { if {[info exists zone_cfg_arr($zone_name)] } { set disjoint_list [get_list_disjoint $zone_cfg_arr($zone_name) $wwn_list] if {[llength $disjoint_list] == 0} { lappend last_entry_zones $zone_name } } foreach wwn $wwn_list { set cmd "config>>zoning defined-configuration zone $zone_name>>no member-entry $wwn" if {[n_do_command $cmd] != 0} { add_status "Error in command $cmd execution" 1 } after 1000 } } if {$verify == "yes"} { verify_remove_member_entry $zone_name_list $wwn_lol $last_entry_zones $cluster_list } }


proc verify_remove_member_entry {zone_name_list wwn_lol {last_entry_zones ""} {cluster_list ""}} { global cl_ip_address if {$cluster_list == ""} { set ip_list_to_verify $cl_ip_address } else { set ip_list_to_verify $cluster_list } foreach ip $ip_list_to_verify { add_status "Verifying in switch $ip" brcd_nos_login $ip set defined_cfg [parse_defined_zoning] array set zone_arr [lindex $defined_cfg 1] foreach zone_name $zone_name_list wwn_list $wwn_lol { if {[lsearch $last_entry_zones $zone_name] != -1} { if {[info exists zone_arr($zone_name)]} { add_status "Zone $zone_name not deleted after deleting last wwn member" 1 } else { add_status "Zone $zone_name deleted after deleting last wwn member" 3 } continue } else { set inter_list [get_list_intersection $zone_arr($zone_name) $wwn_list] if {[llength $inter_list] > 0} {


add_status "Given wwn list $wwn_list from the zone $zone_name not removed properly" 1 } else { add_status "Given wwn list $wwn_list removed from the zone $zone_name properly" 3 } } } } }

proc remove_member_zone {cfg_name_list zone_lol {cluster_list ""} {verify "yes"}} { set defined_cfg [parse_defined_zoning] array set cfg_arr [lindex $defined_cfg 0] set last_entry_cfg [list] foreach cfg_name $cfg_name_list zone_name_list $zone_lol { if {[info exists cfg_arr($cfg_name)]} { set disjoint_list [get_list_disjoint $cfg_arr($cfg_name) $zone_name_list] add_status "zones in cfg $cfg_arr($cfg_name), actual - $zone_name_list" if {[llength $disjoint_list] == 0} { lappend last_entry_cfg $cfg_name } } foreach zone_name $zone_name_list { set cmd "config>>zoning defined-configuration cfg $cfg_name>>no member-zone $zone_name" if {[n_do_command $cmd] != 0} {


add_status "Error in command $cmd execution" 1 } after 1000 } } if {$verify == "yes"} { verify_remove_member_zone $cfg_name_list $zone_lol $last_entry_cfg $cluster_list }

}

proc verify_remove_member_zone {cfg_name_list zone_lol {last_entry_cfg ""} {cluster_list ""}} { global cl_ip_address if {$cluster_list == ""} { set ip_list_to_verify $cl_ip_address } else { set ip_list_to_verify $cluster_list } foreach ip $ip_list_to_verify { add_status "Verifying in switch $ip" brcd_nos_login $ip set defined_cfg [parse_defined_zoning] array set cfg_arr [lindex $defined_cfg 0]

foreach cfg_name $cfg_name_list zone_name_list $zone_lol {


add_status "====>cfg_name- $cfg_name and last_entry_cfg $last_entry_cfg" if {[lsearch $last_entry_cfg $cfg_name] != -1} { if {[info exists cfg_arr($cfg_name)]} { add_status "Cfg $cfg_name not deleted after deleting last zone member" 1 } else { add_status "Cfg $cfg_name deleted after deleting last zone member" 3 } continue } else { set inter_list [get_list_intersection $cfg_arr($cfg_name) zone_name_list] if {[llength $inter_list] > 0} { add_status "Given zone list $zone_name_list from the cfg $cfg_name not removed properly" 1 } else { add_status "Given zone list $zone_name_list removed from the cfg $cfg_name properly" 3 } } } }

}

proc disable_cfg {{cluster_list ""} {verify "yes"}} { set cmd "config>>zoning enabled-configuration cfg-action cfg-disable" if {[n_do_command $cmd] != 0} {


add_status "Error in command $cmd execution" 1 } if {$verify == "yes"} { verify_disable_cfg $cluster_list } }

proc verify_disable_cfg {{cluster_list ""}} { global cl_ip_address if {$cluster_list == ""} { set ip_list_to_verify $cl_ip_address } else { set ip_list_to_verify $cluster_list } foreach ip $ip_list_to_verify { add_status "Verifying in switch $ip" brcd_nos_login $ip set enabled_config [parse_enabled_zoning] set cfg_info [lindex $enabled_config 0] if {[lindex $cfg_info 0] == "\"\""} { add_status "cfg disabled successfully" 3 } else { add_status "cfg not disabled successfully" 1 } }


}

proc cfg_clear {{cluster_list ""} {verify "yes"} {save "yes"}} { set initial_chk_list [parse_enabled_zoning] set chk_for_cfgname [lindex [lindex $initial_chk_list 0] 0] add_status "The chk_for_cfgname is $chk_for_cfgname" 3 if {$chk_for_cfgname != "\"\""} { set cmd "config>>zoning enabled-configuration cfg-action cfg-disable" set oput [split [n_get_output $cmd] "\n\r"] #if {[n_do_command $cmd] != 0} { if { [regexp -nocase "Error|Aborted|syntax|unknown|fail" [lindex $oput [expr [llength $oput] - 3] ] ] } { if { ![regexp "No effective configuration found" [lindex $oput [expr [llength $oput] - 3] ] ] } { add_status "Error in command execution" 1 } } #} } set cmd1 "config>>zoning enabled-configuration cfg-action cfg-clear" if {[n_do_command $cmd1] != 0} { add_status "Error in command execution" 1 } if {$save == "yes"} { sleep 2 set cmd2 "config>>zoning enabled-configuration cfg-action cfg-save"


if {[n_do_command $cmd2] != 0} { add_status "Error in command execution" 1 } } if {$verify == "yes"} { verify_cfg_clear $cluster_list } }

proc verify_cfg_clear {{cluster_list ""}} { global cl_ip_address if {$cluster_list == ""} { set ip_list_to_verify $cl_ip_address } else { set ip_list_to_verify $cluster_list } foreach ip $ip_list_to_verify { add_status "Verifying in switch $ip" brcd_nos_login $ip set defined_config [parse_defined_zoning] if {$defined_config == -1} { add_status "Configuration cleared successfully" } else { add_status "Error in config clear" 1


} } }

proc delete_zone {zone_name_list {cluster_list ""} {verify "yes"}} { foreach zone_name $zone_name_list { set cmd "config>>no zoning defined-configuration zone $zone_name" if {[n_do_command $cmd] != 0} { add_status "Error in command $cmd execution" 1 } after 1000 } if {$verify == "yes"} { verify_delete_zone $cluster_list } }

proc verify_delete_zone {zone_name_list {cluster_list ""}} { global cl_ip_address if {$cluster_list == ""} { set ip_list_to_verify $cl_ip_address } else { set ip_list_to_verify $cluster_list }


foreach ip $ip_list_to_verify { add_status "Verifying in switch $ip" brcd_nos_login $ip set defined_config [parse_defined_zoning] array set zone_arr [lindex $defined_config 1] set current_zone_names [array names zone_arr] set inter_list [get_list_intersection $current_zone_names $zone_name_list] if {[llength $inter_list] > 0} { add_status "Some/All of the given zones are not deleted successfully" 1 } else { add_status "All the given zones are deleted successfully" 3 } } }

proc delete_cfg {cfg_name_list {cluster_list ""} {verify "yes"}} { foreach cfg_name $cfg_name_list { set cmd "config>>no zoning defined-configuration cfg $cfg_name" if {[n_do_command $cmd] != 0} { add_status "Error in command $cmd execution" 1 } } if {$verify == "yes"} { verify_delete_cfg $cluster_list }


}

proc verify_delete_cfg {cfg_name_list {cluster_list ""}} { global cl_ip_address if {$cluster_list == ""} { set ip_list_to_verify $cl_ip_address } else { set ip_list_to_verify $cluster_list } foreach ip $ip_list_to_verify { add_status "Verifying in switch $ip" brcd_nos_login $ip set defined_config [parse_defined_zoning] array set cfg_arr [lindex $defined_config 0] set current_cfg_names [array names cfg_arr] set inter_list [get_list_intersection $current_cfg_names $cfg_name_list] if {[llength $inter_list] > 0} { add_status "Some/All of the given cfg are not deleted successfully" 1 } else { add_status "All the given cfg are deleted successfully" 3 } } }


proc verify_fcports_speed {port_list speed_to_verify} { set counter 0 foreach port $port_list { set speed_from_switch [parse_fcport_speed $port] if {$speed_from_switch == $speed_to_verify} { incr counter } } if {$counter == [llength $port_list]} { add_status "Speed verification success... All the ports are in $speed_to_verify speed" 3 } else { add_status "Speed verification failed... All the ports are not in $speed_to_verify speed" 1 } }

proc verify_isl_r_rdy {port_list} { set counter 0 foreach port $port_list { set isl_mode_from_switch [parse_isl_r_rdy_state $port] if {$isl_mode_from_switch == "isl-r_rdy"} { incr counter } else { add_status "isl-r_rdy mode is not enabled in port $port" 1 } }


if {$counter == [llength $port_list]} { add_status "isl-r_rdy is enabled in all the ports" 3 } }

proc verify_no_isl_r_rdy {port_list} { set counter 0 foreach port $port_list { set isl_mode_from_switch [parse_isl_r_rdy_state $port] if {$isl_mode_from_switch == "no isl-r_rdy"} { incr counter } else { add_status "isl-r_rdy mode is enabled in port $port" 1 } } if {$counter == [llength $port_list]} { add_status "isl-r_rdy is disabled in all the ports" 3 } }

#This api is use to get host info like switch ip to which connected and its port number #if given wwn not present, no info will be present #all info will be stored in an array proc get_node_info {wwn_list {ip_list ""}} {


global cl_ip_address set fabric_info [parse_show_fabric_all num_switches] array set rid_ip_arr [list] foreach info $fabric_info { set info [lindex $info 0] set rid_ip_arr([lindex $info 0]) [lindex $info 3] } parse_show_fcoe_login dev_info $ip_list foreach name [array names dev_info] { foreach line $dev_info($name) { set current_wwn [lindex $line 2] add_status "c wwn - $current_wwn" if {[lsearch $wwn_list $current_wwn] != -1} { set teport [lindex $line) 1] set rid [lindex [split $teport "/"] 0] add_status "inside lsearch cwwn. Val=$teport rid=$rid" 3 add_status "arr=$rid_ip_arr($rid)" 3 set host_info_arr($current_wwn) [list $rid_ip_arr($rid) $teport] } } } return [array get host_info_arr] }

proc cfg_save {} {


sleep 5 set cmd "config>>zoning enabled-configuration cfg-action cfg-save" if {[n_do_command $cmd] != 0} { add_status "Error in command $cmd execution" 1 } }

# pass null for IP list to just use SUT

#ab proc initial_config {{ip_list ""}} { set pass 0 set sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 } } foreach ip $ip_list { if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else {


enter_confdcli } } set pass 0 set oput [n_get_output "show running-config ldap-server maprole"] if {[regexp "No entries found" $oput]} { set pass 1 } else { set otput [lrange [compress_list [split $oput "\r\n"]] 1 end-1] foreach ele $otput { if {[regexp "group (\[^ \t]+)" $ele ignore match]} { set cmd "config>>no ldap-server maprole group $match" if {[n_do_command "$cmd"] == 0} { } } } set oput [n_get_output "show running-config ldap-server maprole"] if {[regexp "No entries found" $oput]} { set pass 1 } } set pass 0 set oput [n_get_output "show running-config rule"] if {![regexp "No entries found" $oput]} { delete_rule "all" "yes"


set oput [n_get_output "show running-config rule"] if {[regexp "No entries found" $oput]} { set pass 1 } } else { set pass 1 } set pass 0 set oput [lrange [compress_list [split [n_get_output "show running-config username"] "\r\n"]] 1 end-1] foreach ele $oput { set pass 0 if {[regexp "username (\[^ \t]+)" $ele ignore match]} { if {($match != "admin") && ($match != "user")} { if {[n_do_command "config>>no username $match"] == 0} { add_status "The username $match is deleted successsfully" 3 } else { add_status "Error in deleteing the username" 1 } } } else { set pass 1 } } set pass 0


set oput [lrange [compress_list [split [n_get_output "show running-config role name"] "\r\n"]] 1 end-1] foreach ele $oput { set pass 0 if {![regexp "role name admin" $ele] && ![regexp "role name user" $ele]} { if {[n_do_command "config>>no role name [lindex $ele 2]"] == 0} { add_status "The role deleted succesfully" 3 } else { add_status "Error in deleting the role" 1 } set temp_oput [n_get_output "show running-config role name"] if {![regexp "role name $ele" $temp_oput]} { set pass 1 } } else { set pass 1 } } set pass 0 set oput [n_get_output "show running-config aaa authentication login"] if {[regexp "aaa authentication login local" $oput]} { set pass 1 } else { set cmd "config>>aaa authentication login local" if {[n_do_command $cmd] == 0} {


set pass 1 } close_spawn_list end_telnet brcd_nos_login $ip_list } set pass 0 set oput [compress_list [split [n_get_output "show running-config ldap-server host"] "\r\n"]] foreach ele $oput { if {[regexp "host (\[^ \t]+)" $ele ignore host_ip]} { set cmd "config>>no ldap-server host $host_ip" if {[n_do_command "$cmd"] == 0} { set pass 1 } } else { set pass 1 } } } if {$pass == 1} { add_status "The initial configuration is done successfuly" 3 } else { add_status "Error in doing initial configuration" 1 } }


proc configure_ldap_login {{mode "local"} {ip_list ""} {verify "yes"} {login_chk "no"} {server_name "ldap"}} { global spawn_id global cl_RELEASE global cl_spawn_list if { $cl_RELEASE == "HYDRA" && [info exists cl_RELEASE]} { if {$mode == "default"} { set cmd "aaa authentication login $server_name local" } else { set cmd "aaa authentication login $server_name $mode" } } else { if {$mode == "default"} { set cmd "aaa authentication login local" } else { set cmd "aaa authentication login $mode" } } set ip [get_current_spawn_ip] set ip_use $ip if {$ip == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 } set timeout 5


exp_send "config\r" expect { "Entering configuration" { add_status "entered configuration terminal" 3 } } exp_send "$cmd\r" expect { "Connection closed" { add_status "LDAP authentication set to $mode, telnet session closed" 3 } timeout { add_status "LDAP authentication set to $mode, telnet session not closed, closing explicitly" 3 } } close_spawn_list

if {$login_chk == "no"} { brcd_nos_login $ip_use } else { return 1 }

if {$verify == "yes"} { add_status "Verifying LDAP authentication set to local in running-config" return [verify_ldap_authentication $mode $ip_list]


}

return 1 }

proc verify_ldap_authentication {mode {ip_list ""}} { set pass 0 set overall_pass 1 set sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 }

} foreach ip $ip_list { add_status "ip is $ip" 3 if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli }


}

set oput [n_get_output "show running-config aaa authentication login"] set oput [split $oput "\n"] foreach line $oput { if {($mode == "default") || ($mode == "local")} { if {[string first "aaa authentication login local" $line] >= 0} { set pass 1 add_status "properly verified default mode for ldap authentication in running-config for switch: $ip" 3 } } else { if {[string first "aaa authentication login $mode" $line] >= 0} { set pass 1 add_status "properly verified local mode for ldap authentication in running-config for switch: $ip" 3 } } } if {$pass == 0} { add_status "failed $mode verification for switch: $ip" 1 set overall_pass 0 } #end_telnet

}


if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli } return $overall_pass }

#ab proc verify_ldap_user_login {{ip_list ""} {flag 0} {user_nm "trial"} {passwrd "Changeme123"}} { set pass 0 set overall_pass 1 set sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 } } foreach ip $ip_list { add_status "ip is $ip" 3 # if {[set_spawn_id $ip] == 1} { # # #

if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else {


#

enter_confdcli

#

}

# } set ret_value [brcd_nos_login_user $ip $user_nm $passwrd] add_status "The returned value is: $ret_value" #set ret_value [split $ret_value "\r\n"] #foreach line $ret_value { if {[regexp "$user_nm connected" $ret_value]} { set pass 1 add_status "The user login is successful in $ip" 3 } else { set overall_pass 0 add_status "The user does not have permission to login to $ip, Exiting test case" 1 end_telnet } #} if {$pass == 1} { set val [n_get_output "config"] if {[regexp "Entering configuration mode terminal" $val]} { add_status "User $user_nm is able to login with Admin priviledge" 3 } else { set overall_pass 0 if {$flag == 0} { add_status "User $user_nm cannot login with Admin priviledge" 1 }


} } } set_spawn_id $sut return $overall_pass }

#ab proc add_group_to_switchrole {{ip_list ""} {grp_name "admin"} {switch_role "securityadmin"} {verify "yes"}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 } set cmd "config>>ldap-server maprole group $grp_name role $switch_role" if {[n_do_command "$cmd"] == 0} { add_status "The group $grp_name has been successfuly mapped with switch role $switch_role" 3


} else { add_status "Error in mapping group to switch role" 1 }

if {$verify == "yes"} { add_status "Verifying the mapping between group to switch role" set return_val [verify_group_mapto_switchrole $ip_list $grp_name $switch_role] } return $return_val }

#ab proc verify_group_mapto_switchrole {{ip_list ""} group_name switch_role} { set count 0 set pass 1 set group_name_set_correct 0 set role_name_set_correct 0 set sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 } } foreach ip $ip_list {


add_status "ip is $ip" 3 if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli } } set cmd "show running-config ldap-server maprole" set ret_val [n_get_output $cmd] #set ret_val_list [split $ret_val " "] if {[regexp "$group_name" $ret_val]} { set group_name_set_correct 1 set pass 1 } set pass 0 if {[regexp "$switch_role" $ret_val]} { set role_name_set_correct 1 set pass 1 } if {$pass == 1} { if {$group_name_set_correct == 0} { add_status "The Group Name in running-config was not set properly to $group_name on switch: $ip" 1 } else { add_status "LDAP Group Name in running-config was set properly to $group_name on


switch: $ip" 3 } if {$role_name_set_correct == 0} { add_status "The Switch Role Name in running-config was not set properly to $switch_role on switch: $ip" 1 } else { add_status "The Switch Role Name in running-config was set properly to $switch_role on switch: $ip" 3 } } # if {[regexp "ldap-server maprole group admin role securityadmin" $ret_val]} { #

set pass 1

# } else { #

set pass 0

# } } if {$pass} { return 1 } else { return 0 } }

#ab proc delete_group_to_switchrole {{ip_list ""} {grp_name "admin"} {switch_role "securityadmin"} {verify "yes"} {def ""}} {


global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 } # brcd_nos_login $ip_sut set cmd "config>>no ldap-server maprole group $grp_name" if {[n_do_command "$cmd"] == 0} { add_status "The group $grp_name has been successfuly deleted from the role name $switch_role" 3 } else { add_status "Error in mapping group to switch role" 1 } if {$def == ""} { if {$verify == "yes"} { add_status "Verifying the deletion of mapping using show command" set return_val [verify_group_mapto_switchrole $ip_list $grp_name null] } } else {


set return_val 1 } return $return_val }

proc delete_ldap {ip {ip_list ""} {verify "yes"} {def ""}} { set cmd "config>>no ldap-server host $ip" if {[n_do_command "$cmd"] == 0} { add_status "LDAP at $ip deleted successfully" 3 if {$def == ""} { if {$verify == "yes"} { add_status "Verifying deletion of LDAP in running-config" 3 set return_val [verify_ldap $ip null null null null $ip_list yes] } } else { set return_val 1 } } else { add_status "Error deleting LDAP" 1 set return_val 0 } end_telnet return $return_val }


proc add_ldap {ldap_ip {port "389"} {base_domain "sec.brocade.com"} {tmout "4"} {retries "2"} {ip_list ""} {verify "yes"} {def ""}} { global cl_ip_address_list if {$ip_list == ""} { set ip_sut [lindex $cl_ip_address_list 0] } else { set ip_sut [lindex $ip_list 0] } brcd_nos_login $ip_sut set cmd "config>>ldap-server host $ldap_ip" if {$base_domain != ""} { append cmd " basedn $base_domain" } if {$retries != ""} { append cmd " retries $retries" } if {$tmout != ""} { append cmd " timeout $tmout" } if {$port != ""} { append cmd " port $port" } if {[n_do_command "$cmd"] == 0} { add_status "LDAP at $ldap_ip created successfully" 3


if {$def == ""} { if {$verify == "yes"} { add_status "Verifying LDAP in running-config" 3 set return_val [verify_ldap $ldap_ip $port $base_domain $tmout $retries $ip_list] } } else { set return_val 1 } } else { add_status "Error adding LDAP" 1 set return_val 0 } return $return_val }

# returns 1 on success, 0 on failure

proc verify_ldap {ip_ldap {port "389"} {base_domain "sec.brocade.com"} {tmout "4"} {retries "2"} {ip_list ""} {delete "no"}} { set overall_pass_flag 1 set sut [get_current_spawn_ip]

if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login


configuration, have to quit" 0 } }

foreach ip $ip_list { if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli } } if {$delete == "yes"} { set pass 0 set oput [n_get_output "show running-config ldap-server host"] #set oput [split $oput "\n"] #foreach line $oput { if {([regexp "No entries found" $oput]) || (![regexp "host $ip_ldap" $oput])} { set pass 1 add_status "properly verified deletion of ldap configuration in running-config on switch: $ip" 3 } else { add_status "Error...The configuration in ldap server has not been removed on switch: $ip" 1 } # }


set overall_pass_flag $pass } else { set host_entry_correct 0 set retry_entry_correct 0 set tmout_entry_correct 0 set basedn_entry_correct 0 set port_entry_correct 0 set oput [n_get_output "show running-config ldap-server host"] set oput [split $oput "\n"] foreach line $oput { if {[string first "ldap-server host" $line] >= 0} { if {[string first $ip_ldap $line] >= 0} { set host_entry_correct 1 } } if {$retries != ""} { if {[string first "retries" $line] >= 0} { if {[string first $retries $line] >= 0} { set retry_entry_correct 1

} } } if {$tmout != ""} { if {[string first "timeout" $line] >= 0} {


if {[string first $tmout $line] >= 0} { set tmout_entry_correct 1 } } } if {$base_domain != ""} { if {[string first "basedn" $line] >= 0} { if {[string first $base_domain $line] >= 0} { set basedn_entry_correct 1 } } } if {$port != ""} { if {[string first "port" $line] >= 0} { if {[string first $port $line] >= 0} { set port_entry_correct 1 } } } } if {$host_entry_correct == 0} { add_status "LDAP host entry in running-config was not set properly to $ip_ldap on switch: $ip" 1 } else { add_status "LDAP host entry in running-config was set properly to $ip_ldap on switch: $ip" 3


} if {$port != ""} { if {$port_entry_correct == 0} { add_status "LDAP host entry in running-config was not set properly to $port on switch: $ip" 1 } else { add_status "LDAP host entry in running-config was set properly to $port on switch: $ip" 3 } } if {$retries != ""} { if {$retry_entry_correct == 0} { add_status "LDAP retries entry in running-config was not set properly to: $retries on switch: $ip" 1 } else { add_status "LDAP retries entry in running-config was set properly to: $retries on switch: $ip" 3 } } if {$tmout != ""} { if {$tmout_entry_correct == 0} { add_status "LDAP timeout entry in running-config was not set properly to $tmout on switch: $ip" 1 } else { add_status "LDAP timeout entry in running-config was set properly to $tmout on switch: $ip" 3 } }


if {$base_domain != ""} { if {$basedn_entry_correct == 0} { add_status "LDAP base domain entry in running-config was not set properly to: $base_domain on switch: $ip" 1 } else { add_status "LDAP base domain entry in running-config was set properly to: $base_domain on switch: $ip" 3 } } if {($port != "") && ($retries != "") && ($tmout != "") && ($base_domain != "")} { if {($host_entry_correct == 1) && ($retry_entry_correct == 1) && ($tmout_entry_correct == 1) && ($basedn_entry_correct == 1) && ($port_entry_correct == 1)} { set overall_pass_flag 1 } else { set overall_pass_flag 0 } } else {

} } } set_spawn_id $sut return $overall_pass_flag }

#snmp


proc initial_snmp_configuration {{ip_list ""}} { set pass 0 set sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP for re-login after SNMP configuration, have to quit" 0 } } foreach ip $ip_list { if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli } } if {[copy_config "default" "startup"] == 1} { set pass 1 } #do_reload set current_version [join [lrange [regexp -inline {([0-9])\.([0-9])\.*} [get_version_nos]] 1 end] ""] if {$current_version < 40 && [is_chassis] != 1 } { do_reload


} else { do_reload "reload system" } } if {$pass == 1} { add_status "The initial configuration is done successfuly" 3 } else { add_status "Error in doing initial configuration" 1 } }

#ab proc delete_snmp_user {{ip_list ""} user_name {host_ip "172.26.22.120"} {skip 0} {verify "yes"}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 }


if {$skip == 0} { set cmd1 "config>>no snmp-server user $user_name" if {[n_do_command "$cmd1"] == 0} { add_status "Success...The user $user_name is deleted" 3 if {$verify == "yes"} { add_status "Verifying deletion of user $user_name in running-config on IP : $ip_sut" 3 set return_val [verify_snmp_user $ip_list "0" $user_name $host_ip null null null null null "yes"] } else { return 1 } } else { add_status "Error deleting user $user_name" 1 set return_val 0 } } else { add_status "Verifying deletion of user $user_name in running-config on Ip : $ip_sut" 3 set return_val [verify_snmp_user $ip_list "0" $user_name $host_ip null null null null null "yes" $skip] } return $return_val }

#ab proc add_snmp_user {{ip_list ""} {default_chk 0} user_name {grp_name "snmpuser"}


{auth_mode "noauth"} {pwd ""} {priv_policy "nopriv"} {priv_pwd ""} {verify "yes"}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 } set cmd "config>>snmp-server user $user_name" if {$grp_name != ""} { append cmd " groupname $grp_name" } if {$default_chk == 1} { if {$auth_mode != ""} { append cmd " auth $auth_mode" } if {$pwd != ""} { append cmd " auth-password $pwd" } if {$priv_policy != ""} { append cmd " priv $priv_policy"


} if {$priv_pwd != ""} { append cmd " priv-password $priv_pwd" } } if {[n_do_command "$cmd"] == 0} { add_status "Success...The user $user_name is added" 3 if {$verify == "yes"} { add_status "Verifying Addition of user $user_name in running-config on IP : $ip_sut" 3 set return_val [verify_snmp_user $ip_list $default_chk $user_name null $grp_name $auth_mode $pwd $priv_policy $priv_pwd] } else { #add_status "kqbduvqwvdywvdyvweydvywvdywvdyv" 3 return 1 } } else { add_status "Error adding user $user_name" 1 set return_val 0 } return $return_val }

proc verify_snmp_user {{ip_list ""} {default_chk 0} user_nm {host_nm "172.26.22.121"} {grp_name "snmpuser"} {auth_mode "noauth"} {pwd ""} {priv_policy "nopriv"} {priv_pwd ""} {delete "no"} {skip 0}} { set overall_pass_flag 1


set sut [get_current_spawn_ip]

if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 } }

foreach ip $ip_list { if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli } }

if {$delete == "yes"} { set pass 0 if {$skip == 0} { set oput [n_get_output "show running-config snmp-server user"] if {[regexp "$user_nm" $oput] == 0} { set pass 1 add_status "properly verified deletion of user $user_nm on IP: $ip" 3


} } else { set oput [n_get_output "config>>no snmp-server user $user_nm"] if {[regexp "illegal reference 'snmp-server v3host $host_nm $user_nm username'|(This user is associated with the v3host Entry)" $oput]} { set pass 1 add_status "Verified that SNMP user $user_nm cannot be deleted when v3 hostname is associated on Ip : $ip" 3 } else { set pass 0 add_status "Error...User $user_nm is deleted even after v3 hostname is associated on Ip: $ip" 1 } } set overall_pass_flag $pass } else { set user_name_entry_correct 0 set cmd "show running-config snmp-server user" if {$grp_name != ""} { append cmd " $user_nm groupname" set group_name_entry_correct 0 } if {$default_chk == 1} { append cmd " $user_nm" if {$auth_mode != ""} { append cmd " auth" set auth_mode_entry_correct 0


} if {$priv_policy != ""} { append cmd " priv" set priv_policy_entry_correct 0 } } set oput [n_get_output $cmd] if {[regexp "$user_nm" $oput]} { set user_name_entry_correct 1 set pass 1 } if {$grp_name != ""} { set pass 0 if {[regexp "$grp_name" $oput]} { set group_name_entry_correct 1 set pass 1 } } if {$default_chk == 1} { if {$auth_mode != ""} { set pass 0 if {[regexp "$auth_mode" $oput"]} { set auth_mode_entry_correct 1 set pass 1 }


} if {$priv_policy != ""} { set pass 0 if {[regexp "$priv_policy" $oput]} { set priv_policy_entry_correct 1 set pass 1 } } } set pass 1 if {$pass == 1} { if {$user_name_entry_correct == 1} { add_status "Success....The SNMP username in running-config is set properly to $user_nm on Ip: $ip" 3 } else { add_status "Error....The SNMP username in running-config is not set properly on Ip: $ip" 1 } if {([info exists group_name_entry_correct]) && ($grp_name != "")} { if {$group_name_entry_correct == 1} { add_status "Success....The SNMP groupname in running-config is set properly to $grp_name on Ip: $ip" 3 } else { add_status "Error....The SNMP groupname in running-config is not set properly on Ip: $ip" 1 }


} if {$default_chk == 1} { if {([info exists auth_mode_entry_correct]) && ($auth_mode != "")} { if {$auth_mode_entry_correct == 1} { add_status "Success....The SNMP Auth policy in running-config is set properly to $auth_mode on Ip: $ip" 3 } else { add_status "Error....The SNMP Auth policy in running-config is not set properly on IP: $ip" 1 } } if {([info exists priv_policy_entry_correct]) && ($priv_policy != "")} { if {$priv_policy_entry_correct == 1} { add_status "Success....The SNMP Priv policy in running-config is set properly to $priv_policy on Ip: $ip" 3 } else { add_status "Error....The SNMP Priv policy in running-config is not set properly on Ip: $ip" 1 } } } } } } if {$pass} { return 1


} else { return 0 } }

proc add_snmp_community {{ip_list ""} comm_name {mode "ro"} {verify "no"} {pos_neg 0}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } set cmd "config>>snmp-server community $comm_name" if {$mode != ""} { append cmd " $mode" } if {[n_do_command $cmd] == 0} { if {$verify == "yes"} { add_status "Verifying the addition of community $comm_name on Ip: $ip_sut" 3 set return_val [verify_snmp_community $ip_list $comm_name $mode]


} else { if {$pos_neg == 0} { set return_val 1 } else { set return_val 0 } } } else { if {$pos_neg == 0} { add_status "Error in creating the community" 1 } set return_val 0 } return $return_val }

proc clear_snmp_users {{ip_list ""} user_list} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] }


if {$ip_sut == -1} { add_status "problem getting the current spawn's IP" 0 } foreach user_name $user_list { set hosts_configured [get_snmp_v3hosts $ip_list $user_name] if {[llength $hosts_configured] != 0} { foreach item $hosts_configured { delete_snmp_host_community $ip_list $user_name $item "" "" "no" 0 "yes" } delete_snmp_user $ip_list $user_name "no" } else { delete_snmp_user $ip_list $user_name "no" } } set user_list [get_snmp_users $ip_list] if {[llength $user_list] == 0} { add_status "Deleted all users successfully" 3 } else { add_status "Error in deleting : $user_list" 1 } }

proc clear_snmp_communities {{ip_list ""} comm_list} { global spawn_id


global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP" 0 } foreach comm_name $comm_list { set hosts_configured [get_snmp_host_community $ip_list $comm_name] if {[llength $hosts_configured] != 0} { foreach item $hosts_configured { delete_snmp_host_community $ip_list $comm_name $item "" "" "no" } set hosts_configured [get_snmp_host_community $ip_list $comm_name] if {[llength $hosts_configured] == 0} { add_status "Deleted all hosts in $comm_name community" 3 delete_snmp_community $ip_list $comm_name "no" } else { add_status "Error in deleting hosts : $hosts_configured in $comm_name community" 3 } } else { delete_snmp_community $ip_list $comm_name "no"


} }

set comm_list [get_snmp_community $ip_list] if {[llength $comm_list] == 0} { add_status "Deleted all communities successfully" 3 } else { add_status "Error in deleting : $comm_list" 1 }

}

proc delete_snmp_community {{ip_list ""} comm_name {verify "no"}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP" 0 } set cmd1 "config>>no snmp-server community \"$comm_name\""


if {[n_do_command "$cmd1"] == 0} { if {$verify == "yes"} { add_status "Verifying deletion of community $comm_name in running-config on IP : $ip_sut" 3 set return_val [verify_snmp_community $ip_list $comm_name "" "yes"] } else { set return_val 1 } } else { add_status "Error deleting community $comm_name" 1 set return_val 0 } return $return_val }

proc verify_snmp_community {{ip_list ""} comm_name {mode ""} {delete "no"}} { set overall_pass_flag 1 set sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 } } set pass 0


foreach ip $ip_list { brcd_nos_login $ip if {$delete == "yes"} { set cmd [n_get_output "show running-config snmp-server community"] if {([regexp "$comm_name" $cmd] == 0) || [regexp "No entries found" $cmd]} { add_status "Verified...The community deleted succesfully" 3 set pass 1 } else { add_status "Error...The community is not deleted succesfully" 1 } } else { set mode_comm_name 0 set oput [split [n_get_output "show running-config snmp-server community"] "\r\n"] foreach ele $oput { if {[regexp "$comm_name" $ele]} { set pass 1 set mode_comm_name 1 } if {$mode != ""} { set mode_correct 0 set pass 0 if {[regexp "$mode" $ele]} { set pass 1 set mode_correct 1 }


} } if {$pass == 1} { if {$mode_comm_name == 1} { add_status "Success....The SNMP community-name in running-config is set properly to $comm_name on Ip: $ip" 3 } else { add_status "Error....The SNMP community-name in running-config is not set properly on Ip: $ip" 1 } if {[info exists mode_correct]} { if {$mode_correct == 1} { add_status "Success....The SNMP mode in running-config is set properly displayed as \"$mode\" on Ip: $ip" 3 } else { add_status "Error....The SNMP mode in running-config is not set properly displayed as \"$mode\" Ip: $ip" 1 } } } } } if {$pass} { return 1 } else { return 0 }


}

proc add_snmp_host_community {{ip_list ""} comm_name host_ip {udp_port 162} {sevr_lvl "None"} {version "version 2c"} {verify "no"} {pos_neg 0} {v3 ""}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } if {($v3 != "") && ($v3 == "yes")} { set cmd "config>>snmp-server v3host $host_ip $comm_name" } else { set cmd "config>>snmp-server host $host_ip $comm_name" } if {$udp_port != ""} { append cmd " udp-port $udp_port" } if {$sevr_lvl != ""} { append cmd " severity-level $sevr_lvl" }


if {$version != ""} { append cmd " $version" } if {[n_do_command $cmd] == 0} { if {$verify == "yes"} { add_status "Verifying the addition of host on $comm_name on Ip: $ip_sut" 3 set return_val [verify_snmp_host_community $comm_name $host_ip $udp_port $sevr_lvl $version $v3] } else { set return_val 1 } } else { if {$pos_neg == 0} { add_status "Error in creating the community" 1 } set return_val 0 } return $return_val }

proc verify_snmp_host_community {comm_name host_ip {udp_port 162} {sevr_lvl "None"} {version "version 2c"} {v3 ""} {delete "no"}} { set overall_pass 0 if {$delete == "yes"} { if {($v3 != "") && ($v3 == "yes")} {


set cmd "show running-config snmp-server v3host" } else { set cmd "show running-config snmp-server host" } set cmd [n_get_output $cmd] if {([regexp "$host_ip" $cmd] == 0) || [regexp "No entries found" $cmd]} { add_status "Verified...The host deleted succesfully" 3 set pass 1 } else { add_status "Error...The host is not deleted succesfully" 1 } } else { if {($v3 != "") && ($v3 == "yes")} { set cmd "show running-config snmp-server v3host" } else { set cmd "show running-config snmp-server host" } if {$udp_port != ""} { append cmd " $host_ip $comm_name udp-port" } if {$sevr_lvl != ""} { append cmd " $host_ip $comm_name severity-level" } set comm_name_pass 0 set udp_port_pass 0


set host_ip_pass 0 set sevr_lvl_pass 0 set oput [compress_list [split [n_get_output $cmd] "\r\n"]] if {[regexp "$comm_name" $oput]} { set comm_name_pass 1 set pass 1 } set pass 0 if {[regexp "$host_ip" $oput]} { set host_ip_pass 1 set pass 1 } if {$udp_port != ""} { set pass 0 if {[regexp "$udp_port" $oput]} { set udp_port_pass 1 set pass 1 } } if {$sevr_lvl != ""} { set pass 0 if {[regexp -nocase "$sevr_lvl" $oput]} { set sevr_lvl_pass 1 set pass 1 }


} if {$pass == 1} { if {$comm_name_pass == 1} { add_status "Verified....The community name is reflecting properly" 3 set overall_pass 1 } else { add_status "Error...The community name is wrongly displayed" 1 } set overall_pass 0 if {$host_ip_pass == 1} { add_status "Verified...The host name is reflecting properly" 3 set overall_pass 1 } else { add_status "Error...The host name is wrongly displayed" 1 } if {$udp_port != ""} { set overall_pass 0 if {$udp_port_pass == 1} { add_status "Verified...The udp port value is correctly displayed" 3 set overall_pass 1 } else { add_status "Error...The udp port value is wrongly displayed" 1 } }


if {$sevr_lvl != ""} { set overall_pass 0 if {$sevr_lvl_pass == 1} { add_status "Verified...The severity level is correctly displayed" 3 set overall_pass 1 } else { add_status "Error...The severity level is wrongly displayed" 1 } } } } if {($pass == 1) && ($overall_pass == 1)} { return 1 } else { return 0 } }

proc delete_snmp_host_community {{ip_list ""} comm_name host_ip {udp_port "no"} {sevr_lvl "no"} {verify "no"} {pos_neg 0} {v3 ""}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} {


set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } if {($v3 != "") && ($v3 == "yes")} { set cmd "config>>no snmp-server v3host $host_ip \"$comm_name\"" } else { set cmd "config>>no snmp-server host $host_ip \"$comm_name\"" } if {$udp_port == "yes"} { append cmd " udp-port" } if {$sevr_lvl == "yes"} { append cmd " severity-level" } if {[n_do_command $cmd] == 0} { add_status "Success...host deleted successfuly from community $comm_name" 3 if {$verify == "yes"} { add_status "Verifying the deletion of host from $comm_name on Ip: $ip_sut" 3 set return_val [verify_snmp_host_community $comm_name $host_ip $udp_port $sevr_lvl] } else { set return_val 1


} } else { if {$pos_neg == 0} { add_status "Error in deleting the community" 1 } set return_val 0 } return $return_val }

proc add_v3_trap_reciever {{ip_list ""} usr_name host_ip {default_chk 0} {engnid "00:00:00:00:00:00:00:00:00"} {notify_typ "traps"} {udp_port 162} {sevrty_level "None"} {verify "no"} {pos_neg 0}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } set cmd "config>>snmp-server v3host $host_ip $usr_name" if {$default_chk == 1} {


if {$engnid != ""} { append cmd " engineid $engnid" } if {$notify_typ != ""} { append cmd " notifytype $notify_typ" } if {$udp_port != ""} { append cmd " udp-port $udp_port" } if {$sevrty_level != ""} { append cmd " severity-level $sevrty_level" } } if {[n_do_command $cmd] == 0} { add_status "Success...host added successfuly to community $usr_name" 3 if {$verify == "yes"} { add_status "Verifying the addition of host on $usr_name on Ip: $ip_sut" 3 set return_val [verify_v3_trap_reciever $ip_list $usr_name $host_ip $default_chk $engnid $notify_typ $udp_port $sevrty_level] } else { set return_val 1 } } else { if {$pos_neg == 0} { add_status "Error in creating the community" 1 }


set return_val 0 } return $return_val }

proc delete_v3_trap_reciever {{ip_list ""} usr_name host_ip {default_chk 0} {engnid "00:00:00:00:00:00:00:00:00"} {notify_typ "traps"} {udp_port 162} {sevrty_level "None"} {verify "no"} {pos_neg 0}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } set cmd "config>>no snmp-server v3host $host_ip $usr_name" if {$default_chk == 1} { if {$engnid != ""} { append cmd " $engnid" } if {$notify_typ != ""} { append cmd " $notify_typ"


} if {$udp_port != ""} { append cmd " udp-port" } if {$sevrty_level != ""} { append cmd " severity-level" } } if {[n_do_command $cmd] == 0} { add_status "Success...host deleted successfuly from community $usr_name" 3 if {$verify == "yes"} { add_status "Verifying the deletion of host from $usr_name on Ip: $ip_sut" 3 set return_val [verify_v3_trap_reciever $ip_list $usr_name $host_ip $default_chk $engnid $notify_typ $udp_port $sevrty_level "yes"] } else { set return_val 1 } } else { if {$pos_neg == 0} { add_status "Error in deleting the community" 1 } set return_val 0 } return $return_val }


proc verify_v3_trap_reciever {{ip_list ""} usr_name host_ip {default_chk 0} {engnid "00:00:00:00:00:00:00:00:00"} {notify_typ "traps"} {udp_port 162} {sevrty_level "None"} {delete "no"}} { set overall_pass_flag 1 set sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 } } set pass 0 foreach ip $ip_list { if {$delete == "yes"} { set cmd [n_get_output "show running-config snmp-server v3host"] if {([regexp "$host_ip $usr_name" $cmd] == 0) || ([regexp "No entries found" $cmd])} { add_status "Verified...The v3host is deleted succesfully" 3 } else { add_status "Error...The v3host is not deleted succesfully" 1 } } else { set cmd "show running-config snmp-server v3host" if {$default_chk == 1} { if {$engnid != ""} { append cmd " $host_ip $usr_name engineid" }


if {$notify_typ != ""} { append cmd " $host_ip $usr_name notifytype" } if {$udp_port != ""} { append cmd " $host_ip $usr_name udp-port" } if {$sevrty_level != ""} { append cmd " $host_ip $usr_name severity-level" } } set user_name_entry_correct 0 set oput [n_get_output $cmd] if {[regexp "$usr_name" $oput]} { set user_name_entry_correct 1 set pass 1 } if {$default_chk == 1} { if {$engnid != ""} { set engnid_name_entry_correct 0 set pass 0 if {[regexp "$engnid" $oput"]} { set engnid_name_entry_correct 1 set pass 1 } }


if {$notify_typ != ""} { set notify_type_entry_correct 0 set pass 0 if {[regexp "$notify_typ" $oput]} { set notify_type_entry_correct 1 set pass 1 } } if {$udp_port != ""} { set udp_port_entry_correct 0 set pass 0 if {[regexp "$udp_port" $oput]} { set udp_port_entry_correct 1 set pass 1 } } if {$sevrty_level != ""} { set sevrty_level_entry_correct 0 set pass 0 if {[regexp "$sevrty_level" $oput]} { set sevrty_level_entry_correct 1 set pass 1 } } }


if {$pass == 1} { if {$user_name_entry_correct == 1} { add_status "Success....The SNMP username in running-config is set properly to $usr_name on Ip: $ip" 3 } else { add_status "Error....The SNMP username in running-config is not set properly on Ip: $ip" 1 } if {$default_chk == 1} { if {([info exists engnid_name_entry_correct]) && ($engnid != "")} { if {$engnid_name_entry_correct == 1} { add_status "Success....The SNMP engineid in running-config is set properly to $engnid on Ip: $ip" 3 } else { add_status "Error....The SNMP engineid in running-config is not set properly on Ip: $ip" 1 } } if {([info exists notify_type_entry_correct]) && ($notify_typ != "")} { if {$notify_type_entry_correct == 1} { add_status "Success....The SNMP notify type in running-config is set properly to $notify_typ on Ip: $ip" 3 } else { add_status "Error....The SNMP notify type in running-config is not set properly on IP: $ip" 1 } } if {([info exists udp_port_entry_correct]) && ($udp_port != "")} {


if {$udp_port_entry_correct == 1} { add_status "Success....The SNMP UDP Port in running-config is set properly to $udp_port on Ip: $ip" 3 } else { add_status "Error....The SNMP UDp Port in running-config is not set properly on Ip: $ip" 1 } } if {([info exists sevrty_level_entry_correct]) && ($sevrty_level != "")} { if {$sevrty_level_entry_correct == 1} { add_status "Success....The SNMP Severity Level in running-config is set properly to $sevrty_level on Ip: $ip" 3 } else { add_status "Error...The SNMP Severity level in running-config is not set properly on Ip: $ip" 1 } } } } } } if {$pass} { return 1 } else { return 0 }


}

#ab proc execute_no_command {{ip_list ""} command checking default_chk {verify "yes"}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } set return_val 1 if {$ip_sut == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 } set cmd "config>>no snmp-server $command" if {[n_do_command "$cmd"] == 0} { add_status "\"No\" command executed successfully" 3 if {$verify == yes} { add_status "Verifying the execution of \"no\" users in running-config on Ip : $ip_sut" 3 set return_val [verify_no_command $ip_list $command $checking $default_chk] } } else { add_status "Error in executing \"no\" command" 1


set return_val 0 } return $return_val }

#ab proc verify_no_command {{ip_list ""} command checking default_chk} { set pass 0 set sut [get_current_spawn_ip]

if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 } }

foreach ip $ip_list { if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli } }


set oput [n_get_output "show running-config snmp-server $command"] add_status "Checking is -$checking-" 3 add_status "Default check is $default_chk" 3 if {$checking == "groupname"} { if {[regexp "$default_chk" $oput]} { set pass 1 add_status "Properly verified that default value changed to $default_chk for $checking on IP : $ip" 3 } else { add_status "regular expression is wrong" 3 } } elseif {$checking == "notifytype"} { if {[regexp "$default_chk" $oput]} { set pass 1 add_status "Properly verified that default value changed to $default_chk for $checking on Ip : $ip" 3 } } elseif {$checking == "udp-port"} { if {[regexp "$default_chk" $oput]} { set pass 1 add_status "Properly verified that default value changed to $default_chk for $checking on Ip : $ip" 3 } } elseif {$checking == "engineid"} { if {[regexp "$default_chk" $oput]} { set pass 1 add_status "Properly verified that default value changed to $default_chk for $checking


on Ip : $ip" 3 } } else { add_status "jibeudfeudbuebvdvedvyv" 3 } } if {$pass} { return 1 } else { return 0 } }

proc verify_policy {{ip_list ""} command username policy} { set pass 0 # set sut [get_current_spawn_ip]

# if {$ip_list == ""} { #

set ip_list $sut

#

if {$ip_list == -1} {

# add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 #

}

# }

# foreach ip $ip_list {


#

if {[set_spawn_id $ip] == 1} {

#

if {[telnet_switch $ip] != 0} {

#

add_status "Switch $ip not available" 0

#

} else {

#

enter_confdcli

#

}

#

} global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} {

add_status "problem getting the current spawn's IP for re-login after ldap login configuration, have to quit" 0 } n_do_command "show running-config snmp-server user" set oput [n_get_output "config>>snmp-server user $username $command"] if {[regexp "Invalid password length" $oput]} { set pass 1 add_status "Success...verified that $policy policy cannot be set without providing password on IP: $ip_sut" 3 } else {


add_status "Error...Able to set $policy policy without providing password on IP: $ip_sut" 1 } # } if {$pass} { return 1 } else { return 0 } }

proc verify_snmp_runingcfg_val {expected_value actual_val {pos_neg 0}} { set len_val [llength $expected_value] set i 0 foreach val1 $expected_value val2 $actual_val { if {[regexp "(\[^*]+)" $val1 match]} { set new_val1 $match } if {[regexp "(\[^*]+)" $val1 match]} { set new_val2 $match } add_status "$new_val1 ******* $new_val2" 3 if {[regexp "$new_val1" $new_val2]} { incr i #

add_status "i= $i" 3


} } #add_status "len_val=$len_val *** i=$i" 3 if {$len_val == $i} { if {$pos_neg == 0} { add_status "Verified...The running-config displays the default values" 3 } else { add_status "Verified...The running-config does not displayes the previous configuration" 3 } } else { if {$pos_neg == 0} { add_status "Error...The running-config does not displayes the default values" 1 } else { add_status "Error...The running-config remains the same even after the update" 1 } } }

proc show_environment {{ip_list ""} {mode "FC"}} { set sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} {


add_status "problem getting the current spawn's IP, have to quit" 0 } } foreach ip $ip_list { if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli } } set oput [n_get_output "show environment sensor"] set num_fan 0 set num_power 0 set num_temp 0 set entire_output [split $oput "\r\n"] foreach line $entire_output { if {[regexp "Temperature" $line]} { incr num_temp } set pass 0 if {[regexp "Fan" $line]} { incr num_fan } set pass 0


if {[regexp "Power Supply" $line]} { incr num_power } } add_status "The number of Fan is $num_fan" 3 add_status "The number of Power Supply is $num_power" 3 add_status "The number of Temperature is $num_temp" 3 lappend list_env_variable $num_fan $num_power $num_temp } return $list_env_variable }

proc chk_fru_threshold_value {env_val alert_val {mode "FC"} {verify_chk 0} {fru "fan"} {rb ""}} { set sut [get_current_spawn_ip] if {$rb == ""} { set rbrdg [get_mapped_id $sut] } else { set rbrdg $rb } global cl_RELEASE if {$mode == "MC"} { set oput [n_get_output "show running-config rbridge-id $rbrdg system-monitor $fru"] } else { if { $mode == "SA" && [info exists cl_RELEASE] && $cl_RELEASE == "HYDRA" } { set oput [n_get_output "show running-config system-monitor $fru"]


} elseif { $mode == "FC" && [info exists cl_RELEASE] && $cl_RELEASE == "HYDRA"} { set oput [n_get_output "config>>rbridge-id $rbrdg>>do show running-config systemmonitor $fru"] } elseif { $mode == "FC" && [info exists cl_RELEASE] && $cl_RELEASE == "LEO"} { set oput [n_get_output "config>>rbridge-id $rbrdg>>do show runningconfig rbridge-id $rbrdg system-monitor $fru"] } else { set oput [n_get_output "show running-config system-monitor"] } }

set full_output [split $oput "\r\n"] foreach line $full_output { if {[regexp "fan threshold marginal-threshold (\[0-9]+) down-threshold (\[0-9]+)" $line ignore mt dt] && $env_val != ""} { if {($dt == [lindex [lindex $env_val 0] 0]) && ($mt == [lindex [lindex $env_val 0] 1])} { add_status "For FAN, Down-Threshold --> $dt and MarginalThreshold --> $mt" 3 if {$verify_chk == 1} { add_status "Verified...The values are retained for FAN" 3 } } else { add_status "The values of down-threshold and marginalthreshold are not set properly for FAN to [lindex $env_val 0]" 1 } }


if {[regexp "power threshold marginal-threshold (\[0-9]+) down-threshold (\[09]+)" $line ignore mt dt] && $env_val != ""} { if {($dt == [lindex [lindex $env_val 1] 0]) && ($mt == [lindex [lindex $env_val 1] 1])} { add_status "For POWER, Down-Threshold --> $dt and MarginalThreshold --> $mt" 3 if {$verify_chk == 1} { add_status "Verified...The values are retained for POWER" 3 } } else { add_status "The values of down-threshold and marginalthreshold are not set properly for POWER to [lindex $env_val 1]" 1 } } if {[regexp "temp threshold marginal-threshold (\[0-9]+) down-threshold (\[09]+)" $line ignore mt dt] && $env_val != ""} { if {($dt == [lindex [lindex $env_val 2] 0]) && ($mt == [lindex [lindex $env_val 2] 1])} { add_status "For TEMPARATURE, Down-Threshold --> $dt and Marginal-Threshold --> $mt" 3 if {$verify_chk == 1} { add_status "Verified...The values are retained for TEMPARATURE" 3 } } else { add_status "The values of down-threshold and marginalthreshold are not set properly for TEMPARATURE to [lindex $env_val 2]" 1 } } if {[regexp "compact-flash threshold marginal-threshold (\[0-9]+) down-


threshold (\[0-9]+)" $line ignore mt dt] && $env_val != ""} { if {($dt == [lindex [lindex $env_val 3] 0]) && ($mt == [lindex [lindex $env_val 3] 1])} { add_status "For COMPACT-FLASH, Down-Threshold --> $dt and Marginal-Threshold --> $mt" 3 if {$verify_chk == 1} { add_status "Verified...The values are retained for COMPACT-FLASH" 3 } } else { add_status "The values of down-threshold and marginalthreshold are not set properly for COMPACT-FLASH [lindex [lindex $env_val 3] 0] [lindex [lindex $env_val 3] 1]" 1 } } if {[regexp "MM threshold marginal-threshold (\[0-9]+) down-threshold (\[0-9]+)" $line ignore mt dt] && $env_val != ""} { if {($dt == [lindex [lindex $env_val 5] 0]) && ($mt == [lindex [lindex $env_val 5] 1])} { add_status "For MM, Down-Threshold --> $dt and Marginal-Threshold --> $mt" 3 if {$verify_chk == 1} { add_status "Verified...The values are retained for MM" 3 } } else { add_status "The values of down-threshold and marginal-threshold are not set properly for MM [lindex [lindex $env_val 5] 0] [lindex [lindex $env_val 5] 1]" 1 } } if {[regexp "cid-card threshold marginal-threshold (\[0-9]+) down-threshold (\[0-9]+)" $line ignore mt dt] && $env_val != ""} {


if {($dt == [lindex [lindex $env_val 4] 0]) && ($mt == [lindex [lindex $env_val 4] 1])} { add_status "For CID-CARD, Down-Threshold --> $dt and Marginal-Threshold --> $mt" 3 if {$verify_chk == 1} { add_status "Verified...The values are retained for CID-CARD" 3 } } else { add_status "The values of down-threshold and marginal-threshold are not set properly for CID-CARD [lindex [lindex $env_val 4] 0] [lindex [lindex $env_val 4] 1]" 1 } } if {[regexp "SFM threshold marginal-threshold (\[0-9]+) down-threshold (\[0-9]+)" $line ignore mt dt] && $env_val != ""} { if {($dt == [lindex [lindex $env_val 6] 0]) && ($mt == [lindex [lindex $env_val 6] 1])} { add_status "For SFM, Down-Threshold --> $dt and Marginal-Threshold --> $mt" 3 if {$verify_chk == 1} { add_status "Verified...The values are retained for SFM" 3 } } else { add_status "The values of down-threshold and marginal-threshold are not set properly for SFM [lindex [lindex $env_val 6] 0] [lindex [lindex $env_val 6] 1]" 1 } } if {[regexp "LineCard threshold marginal-threshold (\[0-9]+) down-threshold (\[0-9]+)" $line ignore mt dt] && $env_val != ""} { add_status "LineCard marginal-threshold: $dt , down-threshold: $mt , act_dt: [lindex [lindex $env_val 7] 0] , act_mt: [lindex [lindex $env_val 7] 1]" 3 if {($dt == [lindex [lindex $env_val 7] 0]) && ($mt == [lindex [lindex $env_val 7] 1])} {


add_status "For LC, Down-Threshold --> $dt and Marginal-Threshold --> $mt" 3 if {$verify_chk == 1} { add_status "Verified...The values are retained for LC" 3 } } else { add_status "The values of down-threshold and marginal-threshold are not set properly for LC [lindex [lindex $env_val 7] 0] [lindex [lindex $env_val 7] 1]" 1

} } if {[regexp {system-monitor fan alert state (.*) action (.*)} $line ignore a_state a_action] && [lindex $alert_val 0] != ""} { set a_state_list [split $a_state ","] set a_action_list [split $a_action ','] set state_disjoint [get_list_disjoint $a_state_list [lindex [lindex $alert_val 0] 0]] set action_disjoint [get_list_disjoint $a_action_list [lindex [lindex $alert_val 0] 1]] if {[llength $state_disjoint] == 0 && [llength $action_disjoint] == 0} { add_status "For FAN, State is $a_state and Action is $a_action" 3 if {$verify_chk == 1} { add_status "Verified the given values - [lindex [lindex $alert_val 0] 0] [lindex [lindex $alert_val 0] 1] for fan alert" 3 } } else { add_status "The state and action not matched with given values [lindex [lindex $alert_val 0] 0] [lindex [lindex $alert_val 0] 1] for fan" 1 } }


if {[regexp {system-monitor power alert state (.*) action (.*)} $line ignore a_state a_action] && [lindex $alert_val 1] != ""} { set a_state_list [split $a_state ","] set a_action_list [split $a_action ','] set state_disjoint [get_list_disjoint $a_state_list [lindex [lindex $alert_val 1] 0]] set action_disjoint [get_list_disjoint $a_action_list [lindex [lindex $alert_val 1] 1]] if {[llength $state_disjoint] == 0 && [llength $action_disjoint] == 0} { add_status "For POWER, State is $a_state and Action is $a_action" 3 if {$verify_chk == 1} { add_status "Verified the given values - [lindex [lindex $alert_val 1] 0] [lindex [lindex $alert_val 1] 1] for power alert" 3 } } else { add_status "The state and action not matched with given values [lindex [lindex $alert_val 1] 0] [lindex [lindex $alert_val 1] 1] for power" 1 } } if {[regexp {system-monitor cid-card alert state (.*) action (.*)} $line ignore a_state a_action] && [lindex $alert_val 2] != ""} { set a_state_list [split $a_state ","] set a_action_list [split $a_action ','] set state_disjoint [get_list_disjoint $a_state_list [lindex [lindex $alert_val 2] 0]] set action_disjoint [get_list_disjoint $a_action_list [lindex [lindex $alert_val 2] 1]] if {[llength $state_disjoint] == 0 && [llength $action_disjoint] == 0} { add_status "For cid-card, State is $a_state and Action is $a_action" 3 if {$verify_chk == 1} { add_status "Verified the given values - [lindex [lindex $alert_val 2] 0] [lindex [lindex


$alert_val 2] 1] for cid-card alert" 3 } } else { add_status "The state and action not matched with given values [lindex [lindex $alert_val 2] 0] [lindex [lindex $alert_val 2] 1] for cid-card" 1 } } if {[regexp {system-monitor LineCard alert state (.*) action (.*)} $line ignore a_state a_action] && [lindex $alert_val 3] != ""} { set a_state_list [split $a_state ","] set a_action_list [split $a_action ','] set state_disjoint [get_list_disjoint $a_state_list [lindex [lindex $alert_val 3] 0]] set action_disjoint [get_list_disjoint $a_action_list [lindex [lindex $alert_val 3] 1]] if {[llength $state_disjoint] == 0 && [llength $action_disjoint] == 0} { add_status "For LineCard, State is $a_state and Action is $a_action" 3 if {$verify_chk == 1} { add_status "Verified the given values - [lindex [lindex $alert_val 3] 0] [lindex [lindex $alert_val 3] 1] for LineCard alert" 3 } } else { add_status "The state and action not matched with given values [lindex [lindex $alert_val 3] 0] [lindex [lindex $alert_val 3] 1] for LineCard" 1 } } } }


proc show_environment_chk {li {mode "FC"}} { global mode cl_RELEASE set sut [get_current_spawn_ip] set rbrdg [get_mapped_id $sut] if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { set oput [n_get_output "show running-config rbridge-id $rbrdg systemmonitor"] } } else { set oput [n_get_output "show running-config system-monitor"] } set num_fan 0 set num_power 0 set num_temp 0 set full_output [split $oput "\r\n"] foreach line $full_output { if {[regexp "Temperature" $line]} { incr num_temp } set pass 0 if {[regexp "Fan" $line]} { incr num_fan } set pass 0 if {[regexp "Power Supply" $line]} {


incr num_power } } if {$num_fan == [lindex $li 0]} { add_status "Verified...that values $num_fan is retained" 3 } else { add_status "Error...The value $num_fan is changed" 1 } if {$num_power == [lindex $li 1]} { add_status "Verified...that values $num_power is retained" 3 } else { add_status "Error...The value $num_power is changed" 1 } if {$num_temp == [lindex $li 2]} { add_status "Verified...that values $num_temp is retained" 3 } else { add_status "Error...The value $num_temp is changed" 1 } }

proc set_fw_env_variable {{ip_list ""} env_variable li {mode "FC"} {single_cmd "no"} {verify_check "0"} {rb ""}} { global spawn_id global cl_spawn_list global cl_RELEASE set ip_sut [get_current_spawn_ip]


if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } if {$rb == ""} { set rbrdg [get_mapped_id $ip_sut] } else { set rbrdg $rb } #

if {$mode == "MC" } {

#

brcd_nos_login $ip_sut

#

set sw [get_mc_switches]

#

set pri [lindex $sw 0]

#

add_status "Logging into primary Node.."

#

brcd_nos_login $pri

#

} for {set i 0} {$i < [llength $env_variable]} {incr i} {

add_status "Setting the threshold for [lindex $env_variable $i] with marginal threshold [lindex [lindex $li $i] 1] and down threshold [lindex [lindex $li $i] 0]" 3 if {$single_cmd == "no"} { if { [lindex [lindex $li $i] 0] != "" } { if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} {


if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { #if {$mode == "MC" || ( $mode == "FC" && [info exists cl_RELEASE] && $cl_RELEASE == "HYDRA" )} { set cmd1 "config>>rbridge-id $rbrdg>>system-monitor [lindex $env_variable $i] threshold down-threshold [lindex [lindex $li $i] 0]" #} } } else { set cmd1 "config>>system-monitor [lindex $env_variable $i] threshold down-threshold [lindex [lindex $li $i] 0]" } set get_cmd1 [n_get_output $cmd1] if {[regexp "Threshold value provided is greater than number of components" $get_cmd1]} { set get_cmd1 [n_get_output $cmd1] add_status "Verified. . . Values greater than number of components are not accepted for threshold" 3 } elseif {[regexp "" $get_cmd1]} { add_status "Command executed successfully" 3 } else { add_status "Error in executing the command" 1 } } if { [lindex [lindex $li $i] 1] != "" } { if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { # if {$mode == "MC" || ( $mode == "FC" && [info exists cl_RELEASE] && $cl_RELEASE == "HYDRA" )} {


set cmd2 "config>>rbridge-id $rbrdg>>system-monitor [lindex $env_variable $i] threshold marginal-threshold [lindex [lindex $li $i] 1]" #

} } } else {

set cmd2 "config>>system-monitor [lindex $env_variable $i] threshold marginal-threshold [lindex [lindex $li $i] 1]" } set get_cmd2 [n_get_output $cmd2] if {[regexp "Threshold value provided is greater than number of components" $get_cmd2]} { add_status "Verified. . . Values greater than number of components are not accepted for threshold" 3 } elseif {[regexp "" $get_cmd2]} { add_status "Command executed successfuly" 3 } else { add_status "Error in executing the command" 1 } } } else { if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { # if {$mode == "MC" || ( $mode == "FC" && [info exists cl_RELEASE] && $cl_RELEASE == "HYDRA" )} { set cmd1 "config>>rbridge-id $rbrdg>>system-monitor [lindex $env_variable $i] threshold down-threshold [lindex [lindex $li $i] 0] marginal-threshold [lindex [lindex $li $i] 1]" #

} }


} else { set cmd1 "config>>system-monitor [lindex $env_variable $i] threshold down-threshold [lindex [lindex $li $i] 0] marginal-threshold [lindex [lindex $li $i] 1]" } set get_cmd1 [n_get_output $cmd1] if {[regexp "Threshold value provided is greater than number of components" $get_cmd1]} { add_status "Verified. . . Values greater than number of components are not accepted for threshold" 3 } elseif {[regexp "" $get_cmd1]} { add_status "Command executed successfully" 3 } else { add_status "Error in executing the command" 1 } } } #

set cmpct_flash [lindex $env_variable end]

#

if {$mode == "MC"} {

# set cmd1 "config>>rbridge-id $rbrdg>>system-monitor $cmpct_flash threshold down-threshold $val" #

} else {

# $val"

set cmd1 "config>>system-monitor $cmpct_flash threshold down-threshold

#

}

#

if {$mode == "MC"} {

# set cmd2 "config>>rbridge-id $rbrdg>>system-monitor $cmpct_flash threshold marginal-threshold $val" #

} else {


# $val"

set cmd2 "config>>system-monitor $cmpct_flash threshold marginal-threshold

#

}

#

set get_cmd1 [n_get_output $cmd1]

#

set get_cmd2 [n_get_output $cmd2]

# if {[regexp "Threshold value provided is greater than number of components" $get_cmd1]} { # add_status "Verified. . . Values greater than number of components are not accepted for threshold" 3 # } elseif {[regexp "" $get_cmd1]} { #

add_status "Command executed successfully" 3

# } else { #

add_status "Error in executing the command" 1

# } # if {[regexp "Threshold value provided is greater than number of components" $get_cmd2]} { # add_status "Verified. . . Values greater than number of components are not accepted for threshold" 3 # } elseif {[regexp "" $get_cmd2]} { #

add_status "Command executed successfully" 3

# } else { #

add_status "Error in executing the command" 1

# } }

proc set_different_val_state_alert {{ip_list ""} {cond 0} variable {cmd_to_execute "all"} {mode "FC"} {lst1 0} {lst2 0}} { set pass1 0


set pass2 0 global spawn_id global cl_spawn_list global cl_RELEASE set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } set rbrdg [get_mapped_id $ip_sut] if {$cond == 0 } { foreach var $variable { foreach ele $cmd_to_execute { add_status "Setting the alert state for $var with the value $ele" 3 set pass1 0 if { $var == "SFP" && $ele == "on" } { #Do nothing } else { if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { set cmd "config>>rbridge-id


$rbrdg>>system-monitor $var alert state $ele" } } else { set cmd "config>>system-monitor $var alert state $ele" } n_do_command $cmd if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { set cmmd "show running-config rbridge-id $rbrdg system-monitor $var" } } elseif { ( $mode == "FC" && [info exists cl_RELEASE] && $cl_RELEASE == "HYDRA")} { set cmmd "config>>rbridge-id $rbrdg>>do show running-config system-monitor $var"

set cmmd "show running-config system-monitor $var" } set oput [n_get_output "$cmmd"] if {[regexp "state $ele" $oput]} { set pass1 1 add_status "The alert state for $ele is set properly" 3 } else { add_status "The alert state for $ele is not set properly" 1


} } } } } else { foreach var $variable { foreach ele1 $lst1 { foreach ele2 $lst2 { add_status "Setting the alert state for $var with the value $ele1,$ele2" 3 set pass2 0 if { $var == "SFP" && $ele2 == "on" } { #Do nothing } else { if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { set cmd "config>>rbridge-id $rbrdg>>system-monitor $var alert state $ele1,$ele2" } } else { set cmd "config>>system-monitor $var alert state $ele1,$ele2" } set oput [n_get_output "$cmd"] if {[regexp "Not a supported state" $oput]} { set pass2 1 add_status "Verified...The system-monitor alert state $ele1,$ele2 is


not accepted" 3 } else { add_status "Error...Verified...The system-monitor alert state for $ele1,$ele2 is accepted" 1 } } } } } set pass2 0 if { $var == "SFP" && [lindex $lst1 1] == "on" } { #Do Nothing } else { if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { set cmd "config>>rbridge-id $rbrdg>>systemmonitor $var alert state [lindex $lst1 0],[lindex $lst1 1]" } } else { set cmd "config>>system-monitor $var alert state [lindex $lst1 0],[lindex $lst1 1]" } set oput [n_get_output "$cmd"] if {[regexp "Not a supported state" $oput]} { set pass2 1 add_status "Verified...The system-monitor alert state [lindex $lst1 0],[lindex $lst1 1] is not accepted" 3


} else { add_status "Error...Verified...The system-monitor alert state [lindex $lst1 0],[lindex $lst1 1] is accepted" 1 } } } if {$cond == 0} { if {$pass1} { return 1 } else { return 0 } } else { if {$pass2} { return 1 } else { return 0 } } }

proc set_different_val_action_alert {{ip_list ""} {cond 0} variable {cmd_to_execute "all"} {mode "FC"} {lst1 0} {lst2 0}} { global spawn_id global cl_spawn_list global cl_RELEASE


set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } set rbrdg [get_mapped_id $ip_sut] if {$cond == 0 } { foreach var $variable { foreach ele $cmd_to_execute { add_status "Setting the alert action for $var with the value $ele" 3 set pass1 0 if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { set cmd "config>>rbridge-id $rbrdg>>system-monitor $var alert action $ele" } } else { set cmd "config>>system-monitor $var alert action $ele" } n_do_command $cmd if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } {


set cmmd "show running-config rbridge-id $rbrdg system-monitor $var" } } elseif {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { set cmmd "config>>rbridge-id $rbrdg>>do show running-config system-monitor $var" } } else { set cmmd "show running-config system-monitor $var" } set oput [n_get_output $cmmd] if {[regexp "action $ele" $oput]} { set pass1 1 add_status "The action state for $ele is set properly" 3 } else { add_status "The action state for $ele is not set properly" 1 } } } } else { foreach var $variable { foreach ele1 $lst1 { foreach ele2 $lst2 { add_status "Setting the alert action for $var with the value $ele1,$ele2" 3 set pass2 0


if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { set cmd "config>>rbridge-id $rbrdg>>system-monitor $var alert action $ele1,$ele2" } } else { set cmd "config>>system-monitor $var alert action $ele1,$ele2" } set oput [n_get_output "$cmd"] if {[regexp "Not a supported action" $oput]} { set pass2 1 add_status "Verified...The system-monitor alert action $ele1,$ele2 is not accepted" 3 } else { add_status "Error...The system-monitor alert action $ele1,$ele2 is accepted" 1 } } } } set pass2 0 if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { set cmd "config>>rbridge-id $rbrdg>>system-monitor $var alert action [lindex $lst1 0],[lindex $lst1 1]" }


} else { set cmd "config>>system-monitor $var alert action [lindex $lst1 0], [lindex $lst1 1]" } set oput [n_get_output "$cmd"] if {[regexp "Not a supported action" $oput]} { set pass2 1 add_status "Success...The system-monitor alert action [lindex $lst1 0],[lindex $lst1 1] is not accepted" 3 } else { add_status "Error...The system-monitor alert action [lindex $lst1 0],[lindex $lst1 1] is accepted" 1 } } if {$cond == 0} { if {$pass1} { return 1 } else { return 0 } } else { if {$pass2} { return 1 } else { return 0 } }


}

proc set_default_val_using_no_cmd {{ip_list ""} {comp_list "fan"} {chk_cond "threshold downthreshold"} {mode "FC"}} { global spawn_id global cl_spawn_list global cl_RELEASE global cl_ip_address_list #set platform [get_switch_platform] set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } set rbrdg [get_mapped_id $ip_sut] foreach ele $comp_list { foreach var $chk_cond { add_status "Setting default values of $var for $ele" if {!((($ele == "temp") && (($var == "alert action") || ($var == "alert state"))) || (($ele == "compact-flash") && (($var == "alert action") || ($var == "alert state"))))} { if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } {


set cmd "config>>rbridge-id $rbrdg>>no system-monitor $ele $var" } } else { set cmd "config>>no system-monitor $ele $var" } n_do_command $cmd #set cmmd "show running-config rbridge-id $rbrdg systemmonitor $var" #set oput [n_get_output $cmmd] #if {[regexp "" $oput]} { # add_status "Success...The command has been executed succesfully for component $ele for $var" 3 #} else { # add_status "Error...The command is not executed succesfully for component $ele for $var" 1 #} } } if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { set cmd "show running-config rbridge-id $rbrdg system-monitor $ele" } } elseif { ( $mode == "FC" && [info exists cl_RELEASE] && $cl_RELEASE == "HYDRA")} { set cmd "config>>rbridge-id $rbrdg>>do show running-config systemmonitor $ele" } elseif { ( $mode == "FC" && [info exists cl_RELEASE] && $cl_RELEASE ==


"LEO")} { set cmd "config>>do show running-config rbridge-id $rbrdg systemmonitor $ele" } else { set cmd "show running-config system-monitor $ele" } set oput [n_get_output $cmd] if { [info exists cl_RELEASE] && [regexp "HYDRA|LEO" $cl_RELEASE] } { if { [regexp "threshold down-threshold|threshold marginal-threshold" [lindex $chk_cond 0] ] } { if { [regexp "marginal-threshold (\[0-9]) down-threshold (\[0-9])" $oput ignore match1 match2] } { if { $ele == "fan" || $ele == "temp" || ([is_chassis] != 1 && $ele == "power")} { set marginal_thres "1" set down_thres "2" } elseif {[is_chassis] == 1 && $ele == "power" } { brcd_nos_login $cl_ip_address_list "fos" "root" "fibranne" set sw_type [get_switch_platform] if { $sw_type eq "M4" } { set marginal_thres "3" set down_thres "4" } elseif { $sw_type eq "M8" } { set marginal_thres "6" set down_thres "7" } end_telnet $cl_ip_address_list brcd_nos_login $cl_ip_address_list


} else { set marginal_thres "1" set down_thres "0" } if {($match1 == $marginal_thres ) && ($match2 == $down_thres)} { add_status "Success...Default value has been matched succesfully" 3 add_status "marginal-threshold -> ($match1 cli),($marginal_thres, actual)... down-threshold -> ($match2 cli),($down_thres actual)" 3 } else { add_status "Error...Default value is not matched properly" 1 add_status "The wrong entry is for any of marginal-threshold -> ($match1 cli),($marginal_thres, actual)... down-threshold -> ($match2 cli),($down_thres, actual)" 1 } } } if { [regexp "alert action|alert state" [lindex $chk_cond 0] ] } { if { [regexp "alert state (\[a-zA-Z]+) action (\[a-zA-Z]+)" $oput ignore match1 match2] } { if { $ele == "SFP" } { set state "none" } else { set state "removed" } if { $ele == "SFP" } { set action "none"


} else { set action "raslog" } if {($match1 == $state ) && ($match2 == $action)} { add_status "Success...Default value has been matched succesfully" 3 add_status "alert state -> ($match1 cli),($state, actual)... action -> ($match2 cli),($action actual)" 3 } else { add_status "Error...Default value is not matched properly" 1 add_status "The wrong entry is for any of alert state -> ($match1 cli),($state, actual)... action -> ($match2 cli),($action actual)" 1 } } } } else { if {($ele == "fan") || ($ele == "power")} { regexp "marginal-threshold (\[0-9]) down-threshold (\[0-9]). +state (\[a-zA-A]+) action (\[a-zA-Z]+)" $oput ignore match1 match2 match3 match4 if {($match1 == 1) && ($match2 == 2) && ($match3 == "removed") && ($match4 == "raslog")} { add_status "Success...Default value has been matched succesfully" 3 add_status "marginal-threshold -> ($match1 cli),(1 actual)... down-threshold -> ($match2 cli),(2 actual) ... state -> ($match3 cli),(removed actual) ... action -> ($match4 cli),(raslog actual)" 3 } else { add_status "Error...Default value is not matched properly" 1 add_status "The wrong entry is any of marginal-


threshold -> ($match1 cli),(1 actual)... down-threshold -> ($match2 cli),(2 actual) ... state -> ($match3 cli),(removed actual) ... action -> ($match4 cli),(raslog actual)" 1 } } elseif {$ele == "temp"} { regexp "marginal-threshold (\[0-9]) down-threshold (\[0-9])" $oput ignore match1 match2 if {($match1 == 1) && ($match2 == 2)} { add_status "Success...Default value has been matched succesfully" 3 add_status "marginal-threshold -> ($match1 cli),(1 actual)... down-threshold -> ($match2 cli),(2 actual)" 3 } else { add_status "Error...Default value is not matched properly" 1 add_status "The wrong entry is for any of marginal-threshold -> ($match1 cli),(1 actual)... down-threshold -> ($match2 cli),(2 actual)" 1 } } else { regexp "marginal-threshold (\[0-9]) down-threshold (\[0-9])" $oput ignore match1 match2 if {($match1 == 1) && ($match2 == 0)} { add_status "Success...Default value has been matched succesfully" 3 add_status "marginal-threshold -> ($match1 cli),(1 actual)... down-threshold -> ($match2 cli),(2 actual)" 3 } else { add_status "Error...Default value is not matched properly" 1 add_status "The wrong entry is for any of marginalthreshold -> ($match1 cli),(1 actual)... down-threshold -> ($match2 cli),(2 actual)" 1 }


} } } }

proc set_emailid_for_sys_monitor {{ip_list ""} {email "abcd@brocade.com"} {mode "FC"} {fru "fru"}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } brcd_nos_login $ip_sut foreach id $email { set cmd1 "config>>system-monitor-mail $fru $id" n_do_command $cmd1 } set cmd2 "config>>system-monitor-mail $fru enable" n_do_command $cmd2


if {$mode == "MC" } { set nodes [get_mc_switches] foreach node $nodes { set result 0 add_status "Verifying the system-monitor-mail from node: $node" 3 brcd_nos_login $node set cmd1 "show running-config system-monitor-mail" set oput [n_get_output $cmd1] foreach id $email { if {[regexp "system-monitor-mail $fru $id" $oput] && [regexp "system-monitor-mail $fru enable" $oput]} { incr result } } if { $result == [llength $email]} { add_status "Success...The email-id $email has been succesfully added and has been enabled" 3 } else { add_status "Error...The email-id $email has not been added succefully and not enabled" 1 } } } else { set cmd1 "show running-config system-monitor-mail" set oput [n_get_output $cmd1] if {[regexp "system-monitor-mail $fru $email" $oput] && [regexp "system-monitor-mail $fru enable" $oput]} {


add_status "Success...The email-id $email has been succesfully added and has been enabled" 3 } else { add_status "Error...The email-id $email has not been added succefully and not enabled" 1 } } }

proc delete_emailid_using_no {{ip_list ""} {email "abcd@brocade.com"} {mode "FC"}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } set rbrdg [get_mapped_id $ip_sut] if {$mode == "MC"} { set cmd1 "config>>rbridge-id $rbrdg>>no system-monitor-mail fru $email" } else { set cmd1 "config>>no system-monitor-mail fru $email" }


n_do_command $cmd1 if {$mode == "MC"} { set cmd1 "show running-config rbridge-id $rbrdg system-monitor-mail" } else { set cmd1 "show running-config system-monitor-mail" } set oput [n_get_output $cmd1] if {![regexp "system-monitor-mail fru $email" $oput]} { add_status "Success...The emailid has been succesfully removed" 3 } else { add_status "Error...The emailid is still existing" 1 } if {$mode == "MC"} { set cmd2 "config>>rbridge-id $rbrdg>>no system-monitor-mail fru enable" } else { set cmd2 "config>>no system-monitor-mail fru enable" } n_do_command $cmd2 if {$mode == "MC"} { set cmd2 "show running-config rbridge-id $rbrdg system-monitor-mail" } else { set cmd2 "show running-config system-monitor-mail" } set oput1 [n_get_output $cmd2] if {[regexp "No entries found" $oput1]} {


add_status "Success...The system-monitor-mail feature has been disabled properly" 3 } else { add_status "Error...The system-monitor-mail feature has not been disabled properly" 1 } }

proc initial_ipfltr_configuration {{ip_list ""}} { set pass 0 set sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's" 0 } } foreach ip $ip_list { brcd_nos_login $ip set rbrdgid [get_mapped_id $ip] set cmd "show running-config interface Management ip access-group" set n_oput [n_get_output $cmd] if {[regexp "access-group +(\[^ \t]+)" $n_oput ignore match]} { add_status "Access filter is applied in the interface management, removing the existing rules" 3 set cmd "config>>interface Management $rbrdgid/0>>no ip access-


group $match" n_do_command $cmd set cmd "show running-config interface Management ip access-group" set n_oput [n_get_output $cmd] if {![regexp "access-group +$match" $n_oput]} { add_status "Verified...The applied rule $match has been successfully removed from Interface Management" 3 set pass 1 } else { add_status "Error...The applied rule $match has not been removed from Interface Management" 1 } } else { add_status "No access filter in the interface management, proceeding with next steps" 3 } set cmd "show running-config ip access-list" set n_oput [n_get_output $cmd] if {[regexp "No entries found" $n_oput]} { set pass 1 add_status "Into the if block Pass = $pass" 3 } else { add_status "Into the else block" 3 set list_std "" set list_ext "" set split_oput [compress_list [split $n_oput "\r\n"]] foreach ele $split_oput {


if {[regexp "standard (\[^ \t]+)" $ele match std]} { lappend list_std $std } if {[regexp "extended (\[^ \t]+)" $ele match ext]} { lappend list_ext $ext } } add_status "The list_std => $list_std ..... The list_ext => $list_ext" 3 if {$list_std != ""} { foreach ele $list_std { set cmd "show running-config ip access-list standard $ele" set oput [n_get_output $cmd] set split_oput [split $oput "\r\n"] set list_seqno "" foreach line $split_oput { if {[regexp "seq (\[0-9]+)" $line ignore seq_no]} { lappend list_seqno $seq_no } } if {$list_seqno != ""} { foreach num $list_seqno { set cmd "config>>ip access-list standard $ele>>no seq $num" n_do_command $cmd }


} set cmd "show running-config ip access-list standard $ele" set oput [n_get_output $cmd] if {![regexp "seq" $oput]} { set cmd "config>>no ip access-list standard $ele" n_do_command $cmd } } }

if {$list_ext != ""} { foreach ele $list_ext { set cmd "show running-config ip access-list extended $ele" set oput [n_get_output $cmd] set split_oput [split $oput "\r\n"] set list_seqno "" foreach line $split_oput { if {[regexp "seq (\[0-9]+)" $line ignore seq_no]} { lappend list_seqno $seq_no } } if {$list_seqno != ""} { foreach num $list_seqno { set cmd "config>>ip access-list extended $ele>>no seq $num"


n_do_command $cmd } } set cmd "show running-config ip access-list extended $ele" set oput [n_get_output $cmd] if {![regexp "seq" $oput]} { set cmd "config>>no ip access-list extended $ele" n_do_command $cmd } } } set cmd "show running-config ip access-list" set oput [n_get_output $cmd] add_status "oput=$oput" 3 if {[regexp "No entries found" $oput]} { set pass 1 add_status "into the else block Pass = $pass" 3 } }

#

if {[copy_config "default" "startup"] == 1} {

#

set pass 1

#

}

#

do_reload }


if {$pass == 1} { add_status "The initial configuration is done successfuly" 3 } else { add_status "Error in doing initial configuration" 1 } }

proc set_ipfltr_stndrd_access_list {{ip_list ""} {ipstd_name "std1"} {seqno 0} {accsvar "deny"} {accscond "any"} {verify "yes"}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } #add_status "the value of accscond is $accscond" 3 set cmd1 "config>>ip access-list standard $ipstd_name" if {$seqno != ""} { append cmd1 ">>seq $seqno" } if {$accsvar != ""} {


append cmd1 " $accsvar" } if {$accscond != ""} { append cmd1 " $accscond" } if {[n_do_command $cmd1] == 0} { add_status "Command executed properly" 3 } else { add_status "Error in executing the command" 1 } sleep 1 #

set sut [get_current_spawn_ip]

# if {$ip_list == ""} { #

set ip_list $ip_sut

#

if {$ip_list == -1} {

#

add_status "problem getting the current spawn's IP" 0

#

}

# } #

foreach ip $ip_list {

#

add_status "ip is $ip" 3

#

if {[set_spawn_id $ip] == 1} {

#

if {[telnet_switch $ip] != 0} {

# # #

add_status "Switch $ip not available" 0 } else { enter_confdcli


#

}

#

} if {$verify == "yes"} { set command "show running-config ip access-list standard

$ipstd_name" set oput [n_get_output $command] set cmd1 "" if {$seqno != ""} { append cmd1 "seq\\s*$seqno" } if {$accsvar != ""} { append cmd1 "\\s*$accsvar" } if {$accscond != ""} { append cmd1 "\\s*$accscond" } if {([regexp "standard\\s*$ipstd_name" $oput]) && ([regexp "$cmd1" $oput])} { add_status "Success...The access list standard $ipstd_name is correctly displayed" 3 add_status "Success...The seq $seqno the access permission $accsvar on $accscond is correctly displayed" 3 } else { add_status "Error...The access list standard $ipstd_name is wrongly displayed" 1 add_status "Error...The seq $seqno the access permission $accsvar on $accscond is wrongly displayed" 1 }


} #

}

}

proc set_ipfltr_extnd_access_list {{ip_list ""} {value 23} {port_var "range"} {ipext_name "ext1"} {seqno 1} {accsvar "deny"} {protocol "tcp"} {accscond "any"} {verify "yes"}} { brcd_nos_login $ip_list set cmd1 "config>>ip access-list extended $ipext_name" if {$seqno != ""} { append cmd1 ">>seq $seqno" } if {$accsvar != ""} { append cmd1 " $accsvar" } if {$protocol != ""} { append cmd1 " $protocol" } if {$accscond != ""} { append cmd1 " $accscond" } if {$port_var != ""} { if {$port_var == "range"} { append cmd1 " any range [lindex $value 0] [lindex $value 1]" } elseif {$port_var == "eq"} { append cmd1 " any eq $value" } else {


append cmd1 " $port_var" } } if {[n_do_command $cmd1] == 0} { add_status "Command executed properly" 3 } else { add_status "Error in executing the command" 1 } if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP" 0 } } # foreach ip $ip_list { #

add_status "ip is $ip" 3

#

if {[set_spawn_id $ip] == 1} {

#

if {[telnet_switch $ip] != 0} {

#

add_status "Switch $ip not available" 0

#

} else {

#

enter_confdcli

# #

} } if {$verify == "yes"} { set command "show running-config ip access-list extended"


set oput [n_get_output $command] set cmd1 "" if {$seqno != ""} { append cmd1 "seq $seqno" } if {$accsvar != ""} { append cmd1 " $accsvar" } if {$protocol != ""} { append cmd1 " $protocol" } if {$accscond != ""} { append cmd1 " $accscond" } if {$port_var != ""} { if {$port_var == "range"} { append cmd1 " any range [lindex $value 0] [lindex $value 1]" } elseif {$port_var == "eq"} { if { $value == "23" } { set value "telnet" } append cmd1 " any eq $value" } else { append cmd1 " $port_var" }


} if {$port_var == "range"} { if {([regexp "extended $ipext_name" $oput]) && ([regexp "$cmd1" $oput])} { add_status "Success...The access list extended $ipext_name is correctly displayed" 3 add_status "Success...The seq $seqno the access permission $accsvar on $accscond and range from [lindex $value 0] to [lindex $value 1] is correctly displayed" 3 } else { add_status "Error...The access list extended $ipext_name is wrongly displayed" 1 add_status "Error...The seq $seqno the access permission $accsvar on $accscond and range from [lindex $value 0] to [lindex $value 1] is wrongly displayed" 1 } } elseif {$port_var == "eq"} { if {([regexp "extended $ipext_name" $oput]) && ([regexp "$cmd1" $oput])} { add_status "Success...The access list extended $ipext_name is correctly displayed" 3 add_status "Success...The seq $seqno the access permission $accsvar on $accscond and eq of $value is correctly displayed" 3 } else { add_status "Error...The access list standard $ipext_name is wrongly displayed" 1 add_status "Error...The seq $seqno the access permission $accsvar on $accscond and eq of $value is wrongly displayed" 1 } } else { if {([regexp "extended $ipext_name" $oput]) && ([regexp "$cmd1" oput])} {


add_status "Success...The access list standard $ipext_name is correctly displayed" 3 add_status "Success...The seq $seqno the access permission $accsvar on $accscond is correctly displayed" 3 } else { add_status "Error...The access list standard $ipext_name is wrongly displayed" 1 add_status "Error...The seq $seqno the access permission $accsvar on $accscond is wrongly displayed" 1 } } } #

}

}

proc set_ipfltr_to_mgmt_interface {{ip_list ""} {acc_grp_name "ext1"} {verify "yes"}} { global spawn_id global cl_spawn_list global cl_RELEASE global cl_mm_interface_list set ip_sut [get_current_spawn_ip] add_status "Value: $ip_list" if {$ip_list == ""} { set ip_sut $ip_sut } else { #set ip_sut [lindex $ip_list 0] set ip_sut $ip_list }


if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } set rbrdgid [get_mapped_id $ip_sut] if { [info exists cl_RELEASE] && [regexp "HYDRA|LEO" $cl_RELEASE] } { set intf [convert_slotport_tengig $cl_mm_interface_list ] set cmd "config>>interface Management [lindex $intf 0]>>ip access-group $acc_grp_name in" } else { set cmd "config>>interface Management $rbrdgid/0>>ip access-group $acc_grp_name in" } if {[n_do_command $cmd] == 0} { add_status "The command executed succesfully" 3 } else { add_status "Error in executing the command" 1 } #

if {$ip_list == ""} {

#

set ip_list $sut

#

if {$ip_list == -1} {

# #

add_status "problem getting the current spawn's IP" 0 }

# } # foreach ip $ip_list { #

add_status "ip is $ip" 3

#

if {[set_spawn_id $ip] == 1} {


#

if {[telnet_switch $ip] != 0} {

#

add_status "Switch $ip not available" 0

#

} else {

#

enter_confdcli

# #

} } if {$verify == "yes"} { set cmd "show running-config interface Management ip access-group" set oput [n_get_output $cmd]

if {([regexp "Management $rbrdgid/0" $oput]) && ([regexp "ip accessgroup $acc_grp_name" $oput])} { add_status "Success...The interface management $rbrdgid/0 for ip access-group $acc_grp_name has been set correctly" 3 } else { add_status "Error...the interface management and ip accessgroup has not been set properly to $rbrdgid/0 and $acc_grp_name" 1 } } #

}

}

proc remove_ipfltr_acl_mgmt_interface {{ip_list ""} {ipext_name "ext1"} {some_chk_cond 0}} { brcd_nos_login $ip_list # global spawn_id global cl_RELEASE global cl_mm_interface_list


# global cl_spawn_list # set ip_sut [get_current_spawn_ip] # if {$ip_list == ""} { #

set ip_sut $ip_sut

# } else { #

set ip_sut [lindex $ip_list 0]

# } # if {$ip_sut == -1} { #

add_status "problem getting the current spawn's IP, have to quit" 0

# } set rbrdg [get_mapped_id $ip_list] if { [info exists cl_RELEASE] && [regexp "HYDRA|LEO" $cl_RELEASE] } { set intf [convert_slotport_tengig $cl_mm_interface_list ] set cmd "config>>interface Management $intf>>no ip access-group $ipext_name" } else { set cmd "config>>interface Management $rbrdg/0>>no ip access-group $ipext_name" } if {[n_do_command $cmd] == 0} { add_status "The command executed succesfully" 3 } else { add_status "Error in executing the command" 1 } if {$ip_list == ""} { set ip_list $sut


if {$ip_list == -1} { add_status "problem getting the current spawn's IP" 0 } } foreach ip $ip_list { add_status "ip is $ip" 3 if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli } } if {$some_chk_cond != 1} { set cmd "show running-config interface Management $rbrdg/0 ip access-group" set oput [n_get_output $cmd] if {[regexp "No entries found" $oput]} { add_status "Success...The ACL has been succesfully removed" 3 } else { add_status "Error...The ACL has not been removed succesfully" 1 } } } }


proc delete_ipfltr_entry_acess_list {{ip_list ""} {acc_name "ext2"} {acc_var "extended"} {rule_no ""}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } if {$rule_no == ""} { if {$acc_var == "extended"} { set cmd "show running-config ip access-list extended $acc_name" } else { set cmd "show running-config ip access-list standard $acc_name" } set oput [n_get_output $cmd] set splt_oput [split $oput "\r\n"] foreach ele $splt_oput { if {[regexp "seq (\[0-9]+)" $ele ignore match]} { lappend seq_list $match }


} add_status "The sequences present are $seq_list" 3 foreach seq_no $seq_list { if {$acc_var == "extended"} { set cmd "config>>ip access-list extended $acc_name>>no seq $seq_no" } else { set cmd "config>>ip access-list standard $acc_name>>no seq $seq_no" } if {[n_do_command $cmd] == 0} { add_status "The command is executed succesfully" 3 } else { add_status "Error in executing the command" 1 } } } else { if {$acc_var == "extended"} { set cmd "config>>ip access-list extended $acc_name>>no seq $rule_no" } else { set cmd "config>>ip access-list standard $acc_name>>no seq $rule_no" } if {[n_do_command $cmd] == 0} { add_status "The command is executed succesfully" 3 } else { add_status "Error in executing the command" 1


} } if {$ip_list == ""} { set ip_list $ip_sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP" 0 } } foreach ip $ip_list { if {$rule_no == ""} { foreach seq_no $seq_list { if {$acc_var == "extended"} { set cmd "show running-config ip access-list extended $acc_name seq $seq_no" } else { set cmd "show running-config ip access-list standard $acc_name seq $seq_no" } set oput [n_get_output $cmd] if {[regexp "element does not exist" $oput] || [regexp "unknown match" $oput]} { add_status "Success...The entry has been removed succesfully" 3 } else { add_status "Error...the entry has not been removed properly" 1 }


} } else { if {$acc_var == "extended"} { set cmd "show running-config ip access-list extended $acc_name seq $rule_no" } else { set cmd "show running-config ip access-list standard $acc_name seq $rule_no" } set oput [n_get_output $cmd] if {[regexp "element does not exist" $oput] || [regexp "unknown match" $oput]} { add_status "Success...The entry has been removed succesfully" 3 } else { add_status "Error...the entry has not been removed properly" 1 } } } }

proc delete_ipfltr_accs_lst {{ip_list ""} {acc_name "ext2"} {acc_var "extended"}} { set pass 0 global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut


} else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } if {$acc_var == "extended"} { set cmd "show running-config ip access-list extended" } else { set cmd "show running-config ip access-list standard" } set oput [n_get_output $cmd] if {[regexp "No entries found" $oput]} { add_status "There is no entry in the access-list" 3 } else { if {$acc_var == "extended"} { set cmd "config>>no ip access-list extended $acc_name" } else { set cmd "config>>no ip access-list standard $acc_name" } set oput [n_get_output $cmd] if {([regexp "Error: Policy contains rules" $oput]) || ([regexp "Error: Enforced policy cannot be deleted" $oput])} { add_status "Verified...Cannot delete the access-list. Rules are present" 3 set pass 2 } elseif {[regexp "#" $oput]} {


add_status "Verified...The access-list has been deleted succesfully" 3 set pass 1 } else { add_status "Error...The command did not execute succesfully" 1 } } if {$pass == 2} { return 2 } elseif {$pass == 1} { return 1 } else { return 0 } }

proc verify_ipfltr_accs_lst_delete {{ip_list ""} acclst_name} { set sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP for re-login, have to quit" 0 } } foreach ip $ip_list { add_status "ip is $ip" 3


if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli } } set cmd "show running-config ip access-list $acclst_name" set oput [n_get_output $cmd] if {[regexp "element does not exist" $oput]} { add_status "Success...The access list $acclst_name does not exist" 3 } else { add_status "Error...The access list $acclst_name has not been deleted properly, The rule is not deleted" 1 } } }

proc get_vcs_mode {ip} { brcd_nos_login $ip set retval -1 set output [n_get_output "show vcs detail"] set mode -1 regexp {(?:Config Mode|state)[ \t]+:[ \t]+([^\r\n]+)} $output ignore mode

if {[regexp -nocase {Disabled} $mode]} {


set retval 0 } elseif {[regexp {Local-Only} $mode]} { set retval 1 } elseif {[regexp {Distributed} $mode]} { set retval 2 } else { } return $retval }

proc configure_auditlog {class_list {cluster_list ""} {verify "yes"} {verify_raslog "no"}} { set msgid "RAS-2003" foreach class $class_list { if {[n_do_command "config>>logging auditlog class $class"] != 0} { add_status "Error in command execution" 1 } if {$verify_raslog != "no"} { n_verify_ras_log $msgid } } if {$verify == "yes"} { verify_auditlog_config $class_list } }


proc verify_auditlog_config {class_list {cluster_list ""}} { global cl_ip_address if {$cluster_list == ""} { set ip_list_to_verify $cl_ip_address } else { set ip_list_to_verify $cluster_list } foreach ip $ip_list_to_verify { set auditlog_configured [parse_logging_audit] set disjoint_list [get_list_disjoint $class_list $auditlog_configured] set intersection_list [get_list_intersection $disjoint_list $class_list] if {[llength $intersection_list] == 0} { add_status "All the given classess $class_list are configured properly" 3 } else { add_status "Mismatch in some class, $class_list" 1 } } }

proc remove_auditlog_class {class_list {cluster_list ""} {verify "yes"}} { foreach class $class_list { if {[n_do_command "config>>no logging auditlog class $class"] != 0} { add_status "Error in command execution" 1 } }


if {$verify == "yes"} { verify_no_auditlog_config $class_list } }

proc verify_no_auditlog_config {class_list {cluster_list ""}} { global cl_ip_address if {$cluster_list == ""} { set ip_list_to_verify $cl_ip_address } else { set ip_list_to_verify $cluster_list } foreach ip $ip_list_to_verify { set auditlog_configured [parse_logging_audit] set intersection_list [get_list_intersection $auditlog_configured $class_list] if {[llength $intersection_list] == 0} { add_status "All the given classess $class_list are removed properly" 3 } else { add_status "Some classes are not removed properly, $intersection_list" 1 } } }

proc initial_ipfltr_configuration_ip6 {{ip_list ""} {ipv6_add ""} {first "no"}} {


set pass 0 set sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's" 0 } } set i 0 foreach ip $ip_list { if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli } }

if {$first == "yes"} { set rbrdg_id [get_mapped_id $ip] add_status "ipv6=[lindex $ipv6_add $i]" 3 set ipv6_cmplt_address "[lindex $ipv6_add $i]/64" set cmd "config>>interface Management $rbrdg_id/0>>ipv6 address $ipv6_cmplt_address>>no ipv6 address autoconfig" n_do_command $cmd }


set cmd "show running-config interface Management ipv6 access-group" set n_oput [n_get_output $cmd] if {[regexp "access-group +(\[^ \t]+)" $n_oput ignore match]} { add_status "Access filter is applied in the interface management, removing the existing rules" 3 set cmd "config>>interface Management $rbrdg_id/0>>no ipv6 access-group $match" n_do_command $cmd set cmd "show running-config interface Management ipv6 access-group" set n_oput [n_get_output $cmd] if {![regexp "access-group +$match" $n_oput]} { add_status "Verified...The applied rule $match has been successfully removed from Interface Management" 3 set pass 1 } else { add_status "Error...The applied rule $match has not been removed from Interface Management" 1 } } else { add_status "No access filter in the interface management, proceeding with next steps" 3 } set cmd "show running-config ipv6 access-list" set n_oput [n_get_output $cmd] if {[regexp "No entries found" $n_oput]} { set pass 1 } else { set list_std "" set list_ext ""


set split_oput [split $n_oput "\r\n"] foreach ele $split_oput { if {[regexp "standard (\[a-zA-Z0-9]+)" $ele match std]} { lappend list_std $std } if {[regexp "extended (\[a-zA-Z0-9]+)" $ele match ext]} { lappend list_ext $ext } } if {$list_std != ""} { foreach ele $list_std { set cmd "show running-config ipv6 access-list standard $ele" set oput [n_get_output $cmd] set split_oput [split $oput "\r\n"] set list_seqno "" foreach line $split_oput { if {[regexp "seq (\[0-9]+)" $line ignore seq_no]} { lappend list_seqno $seq_no } } if {$list_seqno != ""} { foreach num $list_seqno { set cmd "config>>ipv6 access-list standard $ele>>no seq $num" n_do_command $cmd }


} set cmd "show running-config ipv6 access-list standard $ele" set oput [n_get_output $cmd] if {![regexp "seq" $oput]} { set cmd "config>>no ipv6 access-list standard $ele" n_do_command $cmd } } }

if {$list_ext != ""} { foreach ele $list_ext { set cmd "show running-config ipv6 access-list extended $ele" set oput [n_get_output $cmd] set split_oput [split $oput "\r\n"] set list_seqno "" foreach line $split_oput { if {[regexp "seq (\[0-9]+)" $line ignore seq_no]} { lappend list_seqno $seq_no } } if {$list_seqno != ""} { foreach num $list_seqno { set cmd "config>>ipv6 access-list extended $ele>>no seq $num" n_do_command $cmd


} } set cmd "show running-config ipv6 access-list extended $ele" set oput [n_get_output $cmd] if {![regexp "seq" $oput]} { set cmd "config>>no ipv6 access-list extended $ele" n_do_command $cmd } } } set cmd "show running-config ipv6 access-list" set oput [n_get_output $cmd] if {[regexp "No entries found" $oput]} { set pass 1 } }

#if {[copy_config "default" "startup"] == 1} { # set pass 1 #} #do_reload incr i } if {$pass == 1} {


add_status "The initial configuration is done successfuly" 3 } else { add_status "Error in doing initial configuration" 1 } }

proc set_ipv6_ipfltr_stndrd_access_list {{ip_list ""} {ipstd_name "std1"} {seqno 0} {accsvar "deny"} {accscond "any"} {verify "yes"}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } add_status "the value of accscond is $accscond" 3 set cmd1 "config>>ipv6 access-list standard $ipstd_name" if {$seqno != ""} { append cmd1 ">>seq $seqno" } if {$accsvar != ""} {


append cmd1 " $accsvar" } if {$accscond != ""} { append cmd1 " $accscond" } if {[n_do_command $cmd1] == 0} { add_status "Command executed properly" 3 } else { add_status "Error in executing the command" 1 } sleep 1 # set sut [get_current_spawn_ip] # if {$ip_list == ""} { #

set ip_list $ip_sut

#

if {$ip_list == -1} {

# #

add_status "problem getting the current spawn's IP" 0 }

# } # foreach ip $ip_list { #

add_status "ip is $ip" 3

#

if {[set_spawn_id $ip] == 1} {

# # # #

if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli


# #

} } if {$verify == "yes"} { set command "show running-config ipv6 access-list standard $ipstd_name" set oput [n_get_output $command] set cmd1 "" if {$seqno != ""} { append cmd1 "seq $seqno" } if {$accsvar != ""} { append cmd1 " $accsvar" } if {$accscond != ""} { append cmd1 " $accscond" } if {([regexp "standard $ipstd_name" $oput]) && ([regexp "$cmd1" $oput])} { add_status "Success...The access list standard $ipstd_name is correctly displayed"

3 add_status "Success...The seq $seqno the access permission $accsvar on $accscond is correctly displayed" 3 } else { add_status "Error...The access list standard $ipstd_name is wrongly displayed" 1 add_status "Error...The seq $seqno the access permission $accsvar on $accscond is wrongly displayed" 1 } } #

}


}

proc set_ipv6_ipfltr_extnd_access_list {{ip_list ""} {value 23} {port_var "range"} {ipext_name "ext1"} {seqno 1} {accsvar "deny"} {protocol "tcp"} {accscond "any"} {verify "yes"}} { brcd_nos_login $ip_list set cmd1 "config>>ipv6 access-list extended $ipext_name" if {$seqno != ""} { append cmd1 ">>seq $seqno" } if {$accsvar != ""} { append cmd1 " $accsvar" } if {$protocol != ""} { append cmd1 " $protocol" } if {$accscond != ""} { append cmd1 " $accscond" } if {$port_var != ""} { if {$port_var == "range"} { append cmd1 " any range [lindex $value 0] [lindex $value 1]" } elseif {$port_var == "eq"} { append cmd1 " any eq $value" } else { append cmd1 " $port_var" }


} if {[n_do_command $cmd1] == 0} { add_status "Command executed properly" 3 } else { add_status "Error in executing the command" 1 } if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP" 0 } } # foreach ip $ip_list { #

add_status "ip is $ip" 3

#

if {[set_spawn_id $ip] == 1} {

#

if {[telnet_switch $ip] != 0} {

#

add_status "Switch $ip not available" 0

#

} else {

#

enter_confdcli

# #

} } if {$verify == "yes"} { set command "show running-config ipv6 access-list extended" set oput [n_get_output $command] set cmd1 ""


if {$seqno != ""} { append cmd1 "seq $seqno" } if {$accsvar != ""} { append cmd1 " $accsvar" } if {$protocol != ""} { append cmd1 " $protocol" } if {$accscond != ""} { append cmd1 " $accscond" } if {$port_var != ""} { if {$port_var == "range"} { append cmd1 " any range [lindex $value 0] [lindex $value 1]" } elseif {$port_var == "eq"} { append cmd1 " any eq $value" } else { append cmd1 " $port_var" } } if {$port_var == "range"} { if {([regexp "extended $ipext_name" $oput]) && ([regexp "$cmd1" $oput])} { add_status "Success...The access list extended $ipext_name is correctly displayed" 3


add_status "Success...The seq $seqno the access permission $accsvar on $accscond and range from [lindex $value 0] to [lindex $value 1] is correctly displayed" 3 } else { add_status "Error...The access list extended $ipext_name is wrongly displayed" 1 add_status "Error...The seq $seqno the access permission $accsvar on $accscond and range from [lindex $value 0] to [lindex $value 1] is wrongly displayed" 1 } } elseif {$port_var == "eq"} { if {([regexp "extended $ipext_name" $oput]) && ([regexp "$cmd1" $oput])} { add_status "Success...The access list extended $ipext_name is correctly displayed" 3 add_status "Success...The seq $seqno the access permission $accsvar on $accscond and eq of $value is correctly displayed" 3 } else { add_status "Error...The access list extended $ipext_name is wrongly displayed" 1 add_status "Error...The seq $seqno the access permission $accsvar on $accscond and eq of $value is wrongly displayed" 1 } } else { if {([regexp "extended $ipext_name" $oput]) && ([regexp "$cmd1" $oput])} { add_status "Success...The access list extended $ipext_name is correctly displayed" 3 add_status "Success...The seq $seqno the access permission $accsvar on $accscond is correctly displayed" 3 } else { add_status "Error...The access list extended $ipext_name is wrongly displayed" 1


add_status "Error...The seq $seqno the access permission $accsvar on $accscond is wrongly displayed" 1 } } } #

}

}

proc set_ipv6_ipfltr_to_mgmt_interface {{ip_list ""} {acc_grp_name "std1"} {verify "yes"}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } set rbrdgid [get_mapped_id $ip_sut] set cmd "config>>interface Management $rbrdgid/0>>ipv6 access-group $acc_grp_name in" if {[n_do_command $cmd] == 0} { add_status "The command executed succesfully" 3 } else { add_status "Error in executing the command" 1 } # if {$ip_list == ""} {


#

set ip_list $sut

#

if {$ip_list == -1} {

# #

add_status "problem getting the current spawn's IP" 0 }

# } # foreach ip $ip_list { #

add_status "ip is $ip" 3

#

if {[set_spawn_id $ip] == 1} {

#

if {[telnet_switch $ip] != 0} {

#

add_status "Switch $ip not available" 0

#

} else {

#

enter_confdcli

# #

} } if {$verify == "yes"} { set cmd "show running-config interface Management ipv6 access-group" set oput [n_get_output $cmd]

if {([regexp "Management $rbrdgid/0" $oput]) && ([regexp "ipv6 access-group $acc_grp_name" $oput])} { add_status "Success...The interface management $rbrdgid/0 for ip access-group $acc_grp_name has been set correctly" 3 } else { add_status "Error...the interface management and ip access-group has not been set properly to $rbrdgid/0 and $acc_grp_name" 1 } } # }


}

proc remove_ipv6_ipfltr_acl_mgmt_interface {{ip_list ""} {ipext_name "ext1"} {some_chk_cond 0}} { brcd_nos_login $ip_list # global spawn_id # global cl_spawn_list # set ip_sut [get_current_spawn_ip] # if {$ip_list == ""} { #

set ip_sut $ip_sut

# } else { #

set ip_sut [lindex $ip_list 0]

# } # if {$ip_sut == -1} { #

add_status "problem getting the current spawn's IP, have to quit" 0

# } set rbrdg [get_mapped_id $ip_list] set cmd "config>>interface Management $rbrdg/0>>no ipv6 access-group $ipext_name" if {[n_do_command $cmd] == 0} { add_status "The command executed succesfully" 3 } else { add_status "Error in executing the command" 1 } if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} {


add_status "problem getting the current spawn's IP" 0 } } foreach ip $ip_list { add_status "ip is $ip" 3 if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli } } if {$some_chk_cond != 1} { set cmd "show running-config interface Management $rbrdg/0 ipv6 access-group" set oput [n_get_output $cmd] if {[regexp "No entries found" $oput]} { add_status "Success...The ACL has been succesfully removed" 3 } else { add_status "Error...The ACL has not been removed succesfully" 1 } } } }


proc delete_ipv6_ipfltr_entry_acess_list {{ip_list ""} {acc_name "ext2"} {acc_var "extended"} {rule_no ""}} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } if {$rule_no == ""} { if {$acc_var == "extended"} { set cmd "show running-config ipv6 access-list extended $acc_name" } else { set cmd "show running-config ipv6 access-list standard $acc_name" } set oput [n_get_output $cmd] set splt_oput [split $oput "\r\n"] foreach ele $splt_oput { if {[regexp "seq (\[0-9]+)" $ele ignore match]} { lappend seq_list $match } }


add_status "The sequences present are $seq_list" 3 foreach seq_no $seq_list { if {$acc_var == "extended"} { set cmd "config>>ipv6 access-list extended $acc_name>>no seq $seq_no" } else { set cmd "config>>ipv6 access-list standard $acc_name>>no seq $seq_no" } if {[n_do_command $cmd] == 0} { add_status "The command is executed succesfully" 3 } else { add_status "Error in executing the command" 1 } } } else { if {$acc_var == "extended"} { set cmd "config>>ipv6 access-list extended $acc_name>>no seq $rule_no" } else { set cmd "config>>ipv6 access-list standard $acc_name>>no seq $rule_no" } if {[n_do_command $cmd] == 0} { add_status "The command is executed succesfully" 3 } else { add_status "Error in executing the command" 1 } }


if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP" 0 } } foreach ip $ip_list { if {$rule_no == ""} { foreach seq_no $seq_list { if {$acc_var == "extended"} { set cmd "show running-config ipv6 access-list extended $acc_name seq $seq_no" } else { set cmd "show running-config ipv6 access-list standard $acc_name seq $seq_no" } set oput [n_get_output $cmd] if {[regexp "element does not exist" $oput] || [regexp "unknown match" $oput]} { add_status "Success...The entry has been removed succesfully" 3 } else { add_status "Error...the entry has not been removed properly" 1 } } } else { if {$acc_var == "extended"} { set cmd "show running-config ipv6 access-list extended $acc_name seq $rule_no" } else {


set cmd "show running-config ipv6 access-list standard $acc_name seq $rule_no" } set oput [n_get_output $cmd] if {[regexp "element does not exist" $oput] || [regexp "unknown match" $oput]} { add_status "Success...The entry has been removed succesfully" 3 } else { add_status "Error...the entry has not been removed properly" 1 } } } }

proc delete_ipv6_ipfltr_accs_lst {{ip_list ""} {acc_name "ext2"} {acc_var "extended"}} { set pass 0 global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0


} if {$acc_var == "extended"} { set cmd "show running-config ipv6 access-list extended" } else { set cmd "show running-config ipv6 access-list standard" } set oput [n_get_output $cmd] if {[regexp "No entries found" $oput]} { add_status "There is no entry in the access-list" 3 } else { if {$acc_var == "extended"} { set cmd "config>>no ipv6 access-list extended $acc_name" } else { set cmd "config>>no ipv6 access-list standard $acc_name" } set oput [n_get_output $cmd] if {([regexp "Error: Policy contains rules" $oput]) || ([regexp "Error: Enforced policy cannot be deleted" $oput])} { add_status "Verified...Cannot delete the extended access-list. Rules are present" 3 set pass 2 } elseif {[regexp "#" $oput]} { add_status "Verified...The extended access-list has been deleted succesfully" 3 set pass 1 } else { add_status "Error...The command did not execute succesfully" 1 }


} if {$pass == 2} { return 2 } elseif {$pass == 1} { return 1 } else { return 0 } }

proc verify_ipv6_ipfltr_accs_lst_delete {{ip_list ""} acclst_name} { set sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP for re-login" 0 } } foreach ip $ip_list { add_status "ip is $ip" 3 if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else {


enter_confdcli } } set cmd "show running-config ipv6 access-list $acclst_name" set oput [n_get_output $cmd] if {[regexp "element does not exist" $oput]} { add_status "Success...The access list $acclst_name has been removed" 3 } else { add_status "Error...The access list $acclst_name has not been deleted properly, The rule is not deleted" 1 } } }

proc do_transabort {{verify "yes"}} { set cmd "config>>zoning enabled-configuration cfg-action cfg-transaction-abort" n_do_command $cmd if {$verify == "yes"} { set transtoken [lindex [parse_zoning_operation_info] 4] if {$transtoken == 0} { add_status "Transaction aborted successfully and transtoken resets to 0" 3 } else { add_status "Error in transaction abort, transtoken still in 1" 1 } }


}

proc ldapfull_cli_functionality {var host_nm prompt_val cmd_to_send def_val vald_val test_value {bndry_val ""} {lst_invld_val ""}} { add_status "Checking whether user able to add ldap server without $var field, $var field being optional" 3 set cmd "config>>ldap-server host $host_nm $cmd_to_send" if {[n_do_command $cmd] == 0} { add_status "The command executed succesfully without providing $var field" 3 } else { add_status "Error in executing the command" 1 } add_status "Verifying using the show command that the default $var is $def_val" set cmd "show running-config ldap-server host $host_nm $var" set oput [n_get_output $cmd] if {[regexp "$var ($def_val)" $oput ignore match]} { add_status "Verified...The default value obtained is $def_val" 3 } else { add_status "Error...The default value is different than $def_val" 1 } add_status "Verifying whether user is prompeted for input of $var field if no parameter is send" 3 set cmd "config>>ldap-server host $host_nm $var" n_get_output $cmd interactive_op $prompt_val if {$interactive_op != ""} { add_status "Seeks for port number - Successful" 3 } else {


add_status "Seeks for port number - Failed" 1 } add_status "Checking for the valid parameter" 3 set cmd "config>>ldap-server host $host_nm $var $def_val" n_do_command $cmd set cmd "show running-config ldap-server host $host_nm $var" set oput [n_get_output $cmd] if {[regexp "$var $def_val" $oput]} { add_status "The input provided is valid and is accepted" 3 } else { add_status "Error...The input is not reflected properly" 1 } if {$var != "basedn"} { add_status "Checking for the boundary values" 3 set low_val [lindex $bndry_val 0] set high_val [lindex $bndry_val 1] set val_list [list $low_val $high_val] foreach ele $val_list { set cmd "config>>ldap-server host $host_nm $var $ele" n_do_command $cmd set cmd "show running-config ldap-server host $host_nm" set oput [n_get_output $cmd] if {[regexp "$var $ele" $oput]} { add_status "The input provided is accepted and displayed properly" 3 } else {


add_status "Error in displaying the correct output" 1 } } add_status "Checking whether the invalid values are accepted or not" 3 foreach ele $lst_invld_val { set cmd "config>>ldap-server host $host_nm $var $ele" if {[n_do_command $cmd] != 0} { add_status "Verified...the command throws error for invalid $var value" 3 } else { add_status "Error...the command is accepted for invalid $var value" 1 } } } add_status "Checking whether \"no\" command makes the $var number to default" 3 set cmd "config>>ldap-server host $host_nm $var $test_value" n_do_command $cmd set cmd "show running-config ldap-server host $host_nm $var" set oput [n_get_output $cmd] if {[regexp "$var $test_value" $oput]} { add_status "The $var field value is correctly displayed" 3 } else { add_status "Error in displaying the $var field value" 1 } add_status "Verifying the \"no\" command to bring back $var to default number" 3 set cmd "config>>no ldap-server host $host_nm $var"


n_do_command $cmd set cmd "show running-config ldap-server host $host_nm $var" set oput [n_get_output $cmd] if {[regexp "$var $def_val" $oput]} { add_status "The $var number is displayed is $def_val after executing no command" 3 } else { add_status "Error in displaying default $var number $def_val after no command" 1 } }

proc ldapfull_cli_invalid_val {host_ip var var_no {ip_list ""}} { global cl_ip_address_list if {$ip_list == ""} { set ip_sut [lindex $cl_ip_address_list 0] } else { set ip_sut [lindex $ip_list 0] } if {$var == "port"} { set cmd_output [n_get_output "config>>ldap-server host $host_ip $var $var_no"] if {[regexp "\"$var_no\" is not a valid value" $cmd_output]} { add_status "Verified...The invalid value is not accepted" 3 } else { add_status "Error...The invalid value is accepted" 1 } }


if {$var == "retries"} { set cmd_output [n_get_output "config>>ldap-server host $host_ip $var $var_no"] if {[regexp "Retries must be in the range 0 - 100" $cmd_output]} { add_status "Verified...The invalid value is not accepted" 3 } else { add_status "Error...The invalid value is accepted" 1 } } if {$var == "timeout"} { set cmd_output [n_get_output "config>>ldap-server host $host_ip $var $var_no"] if {[regexp "Timeout must be in the range 1 - 60" $cmd_output]} { add_status "Verified...The invalid value is not accepted" 3 } else { add_status "Error...The invalid value is accepted" 1 } } }

proc possible_combination {cmd_to_execute possible_match} { set output [n_get_output $cmd_to_execute] add_status "the output is $output" 3 set count 0 set output [compress_list [split $output "\r\n"]] foreach ele $output {


foreach term $possible_match { if {[regexp "$term" $ele]} { incr count } } } add_status "count=$count" 3 if {$count > 0} { add_status "Given possible match is obtained sucessfully" 3 } else { add_status "Failed to get the possible match. Expected match: $possible_match" 1 } }

proc ipfilter_server_authentication {hostnm hostip hostpwd script_file testbed_file input_file log_file touch_file verify process {apply_acl_mgmt ""} {apply_deny_rule_in_acl ""} {ipv6_add "no"}} { global cl_HOST_PROMPT global env set timeout 100 exp_spawn ssh -l $hostnm $hostip expect { -re "Are you sure you want to continue connecting" { exp_send "yes\r" exp_continue }


-re "password:" { exp_send "$hostpwd\r" exp_continue } -re $cl_HOST_PROMPT { } } exp_send "exec rm -f fvt_intgtest_main_01/.ssh/known_hosts\r" expect { -re "remove regular file" { exp_send "yes\r" } -re $cl_HOST_PROMPT { } } exp_spawn ssh -l $hostnm $hostip expect { -re "Are you sure you want to continue connecting" { exp_send "yes\r" exp_continue } -re "password:" { exp_send "$hostpwd\r" exp_continue }


-re $cl_HOST_PROMPT { } } exp_send "$script_file $testbed_file $input_file $log_file > /dev/null &\r" sleep 5 expect { -re $cl_HOST_PROMPT { } } exp_send "logout\r" expect { -re $cl_HOST_PROMPT { } } if {$apply_acl_mgmt != ""} { exp_spawn ssh -l $hostnm $hostip expect { -re "Are you sure you want to continue connecting" { exp_send "yes\r" exp_continue } -re "password:" { exp_send "$hostpwd\r" exp_continue }


-re $cl_HOST_PROMPT { } } exp_send "ps -ef | grep $testbed_file | cut -f2\r" expect { -re $cl_HOST_PROMPT { set oput $expect_out(buffer) #add_status "the output is $oput" 3 set oput1 [lrange [compress_list [split $oput "\r\n"]] 1 end] set list_process_id "" foreach ele $oput1 { if {[regexp "\[a-zA-Z]+ +(\[^ \t]+)" $ele ignore match]} { lappend list_process_id $match } } set process_id [lindex $list_process_id 0] add_status "the process_is=$process_id" 3 #add_status "the process id is $process_id" 3 #set abnc 12 } } exp_send "logout\r" expect { -re $cl_HOST_PROMPT { }


} #exp_close

add_status "Applying the filter [lindex $apply_acl_mgmt 0] to interface management" 3 if {$ipv6_add == "no"} { n_do_command "config>>interface Management [lindex $apply_acl_mgmt 1]/0>>ip access-group [lindex $apply_acl_mgmt 0] in" } else { n_do_command "config>>interface Management [lindex $apply_acl_mgmt 1]/0>>ipv6 access-group [lindex $apply_acl_mgmt 0] in" } sleep 30 add_status "Checking for the host $hostip whether the sesssion is closed" 3 exp_spawn ssh -l $hostnm $hostip expect { -re "Are you sure you want to continue connecting" { exp_send "yes\r" exp_continue } -re "password:" { exp_send "$hostpwd\r" exp_continue } -re $cl_HOST_PROMPT { } }


set lg_dir $input_file exp_send "ps -ef | grep $testbed_file | cut -f2\r" expect { -re $cl_HOST_PROMPT { set process_output "$expect_out(buffer)" set opu1 [lrange [compress_list [split $process_output "\r\n"]] 1 end] set list_proc_id "" foreach ele $opu1 { if {[regexp "\[a-zA-Z]+ +(\[^ \t]+)" $ele ignore match]} { lappend list_proc_id $match } } set process_output [lindex $list_proc_id 0] add_status "The output of process output is $process_output" 3 # set process_out 10 if {$process_output != $process_id} { add_status "Verified...The present telnet session is closed" 3 catch "exec touch $lg_dir/touch_file.txt" got_match add_status "The got_the_match is $got_match" 3 if {[regexp "No such file or directory" $got_match]} { add_status "Error...touch file is not present" 1 } else { add_status "Verified...touch file is present" 3 }


} else { add_status "Error...The telnet session is not closed" 1 # got_match

catch "exec touch $log_directory/touch_file.txt" } }

} } if {$apply_deny_rule_in_acl != ""} { exp_spawn ssh -l $hostnm $hostip expect { -re "Are you sure you want to continue connecting" { exp_send "yes\r" exp_continue } -re "password:" { exp_send "$hostpwd\r" exp_continue } -re $cl_HOST_PROMPT { } } exp_send "ps -ef | grep $testbed_file | cut -f2\r" expect { -re $cl_HOST_PROMPT { set oput $expect_out(buffer)


#add_status "the output is $oput" 3 set oput1 [lrange [compress_list [split $oput "\r\n"]] 1 end] set list_process_id "" foreach ele $oput1 { if {[regexp "\[a-zA-Z]+ +(\[^ \t]+)" $ele ignore match]} { lappend list_process_id $match } } set process_id [lindex $list_process_id 0] add_status "the process_is=$process_id" 3 #add_status "the process id is $process_id" 3 #set abnc 12 } } exp_send "logout\r" expect { -re $cl_HOST_PROMPT { } } #exp_close

add_status "Applying the filter [lindex $apply_deny_rule_in_acl 1] to interface management. It does not contain any deny permission. The session should be alive" 3 if {$ipv6_add == "no"} { n_do_command "config>>interface Management [lindex $apply_deny_rule_in_acl 4]/0>>ip access-group [lindex $apply_deny_rule_in_acl 1] in"


} else { n_do_command "config>>interface Management [lindex $apply_deny_rule_in_acl 4]/0>>ipv6 access-group [lindex $apply_deny_rule_in_acl 1] in" } sleep 30 add_status "Checking for the host $hostip whether the sesssion is alive or not" 3 exp_spawn ssh -l $hostnm $hostip expect { -re "Are you sure you want to continue connecting" { exp_send "yes\r" exp_continue } -re "password:" { exp_send "$hostpwd\r" exp_continue } -re $cl_HOST_PROMPT { } } set lg_dir $input_file exp_send "ps -ef | grep $testbed_file | cut -f2\r" expect { -re $cl_HOST_PROMPT { set process_output "$expect_out(buffer)" set opu1 [lrange [compress_list [split $process_output "\r\n"]] 1 end] set list_proc_id ""


foreach ele $opu1 { if {[regexp "\[a-zA-Z]+ +(\[^ \t]+)" $ele ignore match]} { lappend list_proc_id $match } } set process_output [lindex $list_proc_id 0] add_status "The output of process output is $process_output" 3 if {$process_output == $process_id} { add_status "Verified...The present [lindex $apply_deny_rule_in_acl 7] session is still alive" 3 } else { add_status "Error...The [lindex $apply_deny_rule_in_acl 7] session is closed" 1 } } } exp_send "logout\r" expect { -re $cl_HOST_PROMPT { } } add_status "Now adding new rule to the existing ACL rule applied to the interface management. Applying [lindex $apply_deny_rule_in_acl 3] with seq [lindex $apply_deny_rule_in_acl 2] on hostip $hostip" if {[lindex $apply_deny_rule_in_acl 0] == "standard"} { if {$ipv6_add == "no"} { n_do_command "config>>ip access-list [lindex $apply_deny_rule_in_acl 0] [lindex $apply_deny_rule_in_acl 1]>>seq [lindex $apply_deny_rule_in_acl 2] [lindex


$apply_deny_rule_in_acl 3] host $hostip" } else { n_do_command "config>>ipv6 access-list [lindex $apply_deny_rule_in_acl 0] [lindex $apply_deny_rule_in_acl 1]>>seq [lindex $apply_deny_rule_in_acl 2] [lindex $apply_deny_rule_in_acl 3] host [lindex $apply_deny_rule_in_acl 5]" } } else { if {$ipv6_add == "no"} { n_do_command "config>>ip access-list [lindex $apply_deny_rule_in_acl 0] [lindex $apply_deny_rule_in_acl 1]>>seq [lindex $apply_deny_rule_in_acl 2] [lindex $apply_deny_rule_in_acl 3] tcp host $hostip any [lindex $apply_deny_rule_in_acl 5] [lindex $apply_deny_rule_in_acl 6]" } else { n_do_command "config>>ipv6 access-list [lindex $apply_deny_rule_in_acl 0] [lindex $apply_deny_rule_in_acl 1]>>seq [lindex $apply_deny_rule_in_acl 2] [lindex $apply_deny_rule_in_acl 3] tcp host [lindex $apply_deny_rule_in_acl 7] any [lindex $apply_deny_rule_in_acl 5] [lindex $apply_deny_rule_in_acl 6]" } } sleep 30 if {[lindex $apply_deny_rule_in_acl 8] == "telnet"} { add_status "Checking for the host $hostip whether the [lindex $apply_deny_rule_in_acl 7] sesssion is closed" 3 } else { add_status "Checking for the host $hostip whether the [lindex $apply_deny_rule_in_acl 7] session is open" 3 } exp_spawn ssh -l $hostnm $hostip


expect { -re "Are you sure you want to continue connecting" { exp_send "yes\r" exp_continue } -re "password:" { exp_send "$hostpwd\r" exp_continue } -re $cl_HOST_PROMPT { } } set lg_dir $input_file exp_send "ps -ef | grep $testbed_file | cut -f2\r" expect { -re $cl_HOST_PROMPT { set process_output "$expect_out(buffer)" set opu1 [lrange [compress_list [split $process_output "\r\n"]] 1 end] set list_proc_id "" foreach ele $opu1 { if {[regexp "\[a-zA-Z]+ +(\[^ \t]+)" $ele ignore match]} { lappend list_proc_id $match } } set process_output [lindex $list_proc_id 0]


add_status "The output of process output is $process_output" 3 # set process_out 10 if {[lindex $apply_deny_rule_in_acl 8] == "telnet"} { if {$process_output != $process_id} { add_status "Verified...The present telnet session is closed" 3 catch "exec touch $lg_dir/touch_file.txt" got_match add_status "The got_the_match is $got_match" 3 if {[regexp "No such file or directory" $got_match]} { add_status "Error...touch file is not present" 1 } else { add_status "Verified...file is present" 3 } } else { add_status "Error...The telnet session is not closed" 1 } } else { if {$process_output == $process_id} { add_status "Verified...The present ssh session is not closed" 3 catch "exec touch $lg_dir/touch_file.txt" got_match add_status "The got_the_match is $got_match" 3 if {[regexp "No such file or directory" $got_match]} { add_status "Error...touch file is not present" 1 } else { add_status "Verified...file is present" 3


} set its_pass 1 } else { add_status "Error...The ssh session is closed" 1 } } } } } if {([lindex $apply_deny_rule_in_acl 8] == "ssh") && ($its_pass == 1)} { exp_send "exec kill $process_id\r" expect { -re $cl_HOST_PROMPT { } } sleep 2 exp_spawn ssh -l $hostnm $hostip expect { -re "Are you sure you want to continue connecting" { exp_send "yes\r" exp_continue } -re "password:" { exp_send "$hostpwd\r" exp_continue


} -re $cl_HOST_PROMPT { } } #add_status "Checking whether the process is killed or not" 3 #exp_send "ps -ef | grep $testbed_file | cut -f2\r" #expect { # -re $cl_HOST_PROMPT { #

set process_output "$expect_out(buffer)"

#

set opu1 [lrange [compress_list [split $process_output "\r\n"]] 1 end]

#

set list_proc_id ""

#

foreach ele $opu1 {

#

if {[regexp "\[a-zA-Z]+ +(\[^ \t]+)" $ele ignore match]} {

#

lappend list_proc_id $match

#

}

#

}

#

set process_output [lindex $list_proc_id 0]

#

add_status "The output of process output is $process_output" 3 #

if {$process_output != $process_id} {

#

add_status "Verified...The ssh is killed" 3

#

} else {

#

add_status "Else...The ssh is not killed" 1

# # #}

} }


} exp_send "exec rm -f fvt_intgtest_main_01/.ssh/known_hosts\r" expect { -re "remove regular file" { exp_send "yes\r" } -re $cl_HOST_PROMPT { } }

if {($apply_acl_mgmt == "") && ($apply_deny_rule_in_acl == "")} { catch "exec ls $touch_file" got_the_match add_status "The got_the_match is $got_the_match" 3 if {[regexp "No such file or directory" $got_the_match]} { if {$verify == "yes"} { add_status "Error...$process was not succesful from host ip $hostip" 1 } else { add_status "Verified...$process was not succesful from host ip $hostip" 3 } } else { if {$verify == "yes"} { add_status "Verified...$process was succesful from host ip $hostip" 3 } else { add_status "Error...$process was succesful from host ip $hostip" 1


} } } else { set delete_file "$lg_dir/touch_file.txt" catch "exec ls $delete_file" got_the_match add_status "The got_the_match is $got_the_match" 3 if {[regexp "No such file or directory" $got_the_match]} { if {$verify == "yes"} { add_status "Error...$process was succesful from host ip $hostip" 1 } else { add_status "Error...$process was not successful from host ip $hostip" 1 } } else { if {$verify == "yes"} { add_status "Verified...$process was not succesful from host ip $hostip" 3 } else { add_status "Verified...$process was successful from host ip $hostip" 3 } } exec rm -f $delete_file } exec rm -f $touch_file catch "exec ls $touch_file" got_the_match add_status "the got_the_match is $got_the_match" 3


if {[regexp "No such file or directory" $got_the_match]} { add_status "Verified...The file has been succesfully removed" 3 } else { add_status "Error...The file has not been removed" 1 } # n_do_command "config>>interface Management [lindex $apply_acl_mgmt 1]/0>>no ip access-group [lindex $apply_acl_mgmt 0]" exec rm -f $env(HOME)/.ssh/known_hosts }

proc delete_all_monitor_email_list {} { set email_list [parse_sysmonitor_mailids] foreach email $email_list { n_do_command "config>>no system-monitor-mail fru $email" } set email_list [parse_sysmonitor_mailids] if {$email_list == -1 | [llength $email_list] == 0} { add_status "All email entries deleted successfuly" 3 } else { add_status "Error in deleting all email ids" 1 } }

#Status list should be in the order switch power_supply temp fan compact-flash


proc verify_switch_fru_health_status {status_list {rbridge_id ""}} { set actual_status [parse_system_monitor_health $rbridge_id] if {[lindex $status_list 0] == [lindex $actual_status 0]} { add_status "Expected SWITCH status obtained, [lindex $status_list 0]" 3 } else { add_status "Error in expected SWITCH status, Actual: [lindex $actual_status 0], Expected: [lindex $status_list 0]" 1 } if {[lindex $status_list 1] == [lindex $actual_status 1]} { add_status "Expected POWER status obtained, [lindex $status_list 1]" 3 } else { add_status "Error in expected POWER status, Actual: [lindex $actual_status 1], Expected: [lindex $status_list 1]" 1 } if {[lindex $status_list 2] == [lindex $actual_status 2]} { add_status "Expected TEMP status obtained, [lindex $status_list 2]" 3 } else { add_status "Error in expected TEMP status, Actual: [lindex $actual_status 2], Expected: [lindex $status_list 2]" 1 } if {[lindex $status_list 3] == [lindex $actual_status 3]} { add_status "Expected FAN status obtained, [lindex $status_list 3]" 3 } else { add_status "Error in expected FAN status, Actual: [lindex $actual_status 3], Expected: [lindex $status_list 3]" 1 } if {[lindex $status_list 4] == [lindex $actual_status 4]} {


add_status "Expected COMPACT-FLASH status obtained, [lindex $status_list 4]" 3 } else { add_status "Error in expected COMPACT-FLASH status, Actual: [lindex $actual_status 4], Expected: [lindex $status_list 4]" 1 }

}

proc introduce_faulty_events {fru {fru_no 1}} { global cl_ip_address brcd_nos_login $cl_ip_address "fos" if {$fru == "fan"} { do_command "ln -s /fabos/cliexec/em /fabos/bin/emtestfrufault" do_command "emtestfrufault 3 $fru_no" } elseif {$fru == "power"} { do_command "ln -s /fabos/cliexec/em /fabos/bin/emtestfrufault" do_command "emtestfrufault 2 $fru_no" } elseif {$fru == "cid-card"} { do_command "ln -s /fabos/cliexec/em /fabos/bin/emtestfrufault" do_command "emtestfrufault 4 $fru_no" } elseif { $fru == "LineCard" || $fru == "MM" || $fru == "SFM"} { do_command "ln -s /fabos/cliexec/em /fabos/bin/emtestfrufault" do_command "emtestfrufault 1 $fru_no" } else { add_status "Given FRU:$fru not supported" }


brcd_nos_login $cl_ip_address }

proc recover_from_fru_fault_simulation {} { global cl_ip_address set ip $cl_ip_address set ps_fan [parse_show_system] if {[regexp -nocase "Ok" [lindex $ps_fan 0]] == 0 || [regexp -nocase "Ok" [lindex $ps_fan 1]] == 0} { add_status "No Good FAN/POWER found, rebooting the switch" do_reload } end_telnet brcd_nos_login $ip set ps_fan [parse_show_system] if {[regexp -nocase "Ok" [lindex $ps_fan 0]] == 0 || [regexp -nocase "Ok" [lindex $ps_fan 1]] == 0} { add_status "No FRUs up even after reboot" 2 return -1 } else { return 1 } }

proc set_fru_alert_state {fru alert_list action_list {mode "FC"} {rbrdg ""}} { if {$mode == "FC" } {


set cmd "config>>system-monitor $fru alert state [join $alert_list ","]" } elseif {$mode == "MC" } { set cmd "config>>rbridge-id $rbrdg>>system-monitor $fru alert state [join $alert_list ","]" } if {$action_list != ""} { append cmd " action [join $action_list ","]" } add_status "cmd - $cmd" if {[n_do_command $cmd] != 0} { add_status "Error in command execution" 1 } }

proc verify_default_val_using_no_cmd {{ip_list ""} {comp_list "fan"} {chk_cond "threshold down-threshold"} {mode "FC"}} { global spawn_id global cl_spawn_list global cl_RELEASE global cl_ip_address_list #set platform [get_switch_platform] set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0]


} if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } set rbrdg [get_mapped_id $ip_sut] foreach ele $comp_list { if {([regexp "MC|FC" $mode] && [info exists cl_RELEASE])} { if { [regexp "HERCULES|HYDRA|LEO" $cl_RELEASE ] } { set cmd "show running-config rbridge-id $rbrdg system-monitor $ele" } } elseif { ( $mode == "FC" && [info exists cl_RELEASE] && $cl_RELEASE == "HYDRA" ) } { set cmd "config>>rbridge-id $rbrdg>>do show running-config systemmonitor $ele" } elseif { ( $mode == "FC" && [info exists cl_RELEASE] && $cl_RELEASE == "LEO" ) } { set cmd "config>>rbridge-id $rbrdg>>do show running-config rbridge-id $rbrdg systemmonitor $ele" } else { set cmd "show running-config system-monitor $ele" } set oput [n_get_output $cmd] if { [info exists cl_RELEASE] && [regexp "HYDRA|LEO" $cl_RELEASE] } { if { [regexp "threshold down-threshold|threshold marginal-threshold" [lindex $chk_cond 0] ] } { if { [regexp "marginal-threshold (\[0-9]) down-threshold (\[0-9])" $oput ignore match1 match2] } { if { $ele == "fan" || $ele == "temp" || ([is_chassis] != 1 && $ele == "power")} {


set marginal_thres "1" set down_thres "2" } elseif {[is_chassis] == 1 && $ele == "power" } { brcd_nos_login $cl_ip_address_list "fos" "root" "fibranne" set sw_type [get_switch_platform] if { $sw_type eq "M4" } { set marginal_thres "3" set down_thres "4" } elseif { $sw_type eq "M8" } { set marginal_thres "6" set down_thres "7" } end_telnet $cl_ip_address_list brcd_nos_login $cl_ip_address_list } else { set marginal_thres "1" set down_thres "0" } if {($match1 == $marginal_thres ) && ($match2 == $down_thres)} { add_status "Success...Default value has been matched succesfully" 3 add_status "marginal-threshold -> ($match1 cli),($marginal_thres, actual)... downthreshold -> ($match2 cli),($down_thres actual)" 3 } else { add_status "Error...Default value is not matched properly" 1 add_status "The wrong entry is for any of marginal-threshold -> ($match1 cli), ($marginal_thres, actua


l)... down-threshold -> ($match2 cli),($down_thres, actual)" 1 } } } if { [regexp "alert action|alert state" [lindex $chk_cond 0] ] } { if { [regexp "alert state (\[a-zA-Z]+) action (\[a-zA-Z]+)" $oput ignore match1 match2] } { if { $ele == "SFP" } { set state "none" } else { set state "removed" } if { $ele == "SFP" } { set action "none" } else { set action "raslog" } if {($match1 == $state ) && ($match2 == $action)} { add_status "Success...Default value has been matched succesfully" 3 add_status "alert state -> ($match1 cli),($state, actual)... action -> ($match2 cli), ($action actual)" 3 } else { add_status "Error...Default value is not matched properly" 1 add_status "The wrong entry is for any of alert state -> ($match1 cli),($state, actual)... action -> ($match2 cli),($action actual)" 1 } }


} } else { if {($ele == "fan") || ($ele == "power")} { regexp "marginal-threshold (\[0-9]) down-threshold (\[0-9]).+state (\[a-zA-A]+) action (\ [a-zA-Z]+)" $oput ignore match1 match2 match3 match4 if {($match1 == 1) && ($match2 == 2) && ($match3 == "removed") && ($match4 == "raslog")} { add_status "Success...Default value has been matched succesfully" 3 add_status "marginal-threshold -> ($match1 cli),(1 actual)... down-threshold -> ($match2 cli),(2 actual) ... state -> ($match3 cli),(removed actual) ... action -> ($match4 cli), (raslog actual)" 3 } else { add_status "Error...Default value is not matched properly" 1 add_status "The wrong entry is any of marginal-threshold -> ($match1 cli),(1 actual)... down-threshold - ($match2 cli),(2 actual) ... state -> ($match3 cli),(removed actual) ... action -> ($match4 cli),(raslog actual)" 1 } } elseif {$ele == "temp"} { regexp "marginal-threshold (\[0-9]) down-threshold (\[0-9])" $oput ignore match1 match2 if {($match1 == 1) && ($match2 == 2)} { add_status "Success...Default value has been matched succesfully" 3 add_status "marginal-threshold -> ($match1 cli),(1 actual)... down-threshold -> ($match2 cli),(2 actual)" 3 } else { add_status "Error...Default value is not matched properly" 1 add_status "The wrong entry is for any of marginal-threshold -> ($match1 cli),(1 actual)... down-threshold -> ($match2 cli),(2 actual)" 1 }


} else { regexp "marginal-threshold (\[0-9]) down-threshold (\[0-9])" $oput ignore match1 match2 if {($match1 == 1) && ($match2 == 0)} { add_status "Success...Default value has been matched succesfully" 3 add_status "marginal-threshold -> ($match1 cli),(1 actual)... down-threshold -> ($match2 cli),(2 actual)" 3 } else { add_status "Error...Default value is not matched properly" 1 add_status "The wrong entry is for any of marginal-threshold -> ($match1 cli),(1 actual)... down-threshold -> ($match2 cli),(2 actual)" 1 } } } } }

############################################################################## ##### #TACACS related apis ############################################################################## #####

proc clear_tacacs_host {ip_list} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip]


if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } brcd_nos_login $ip_sut set host_list [get_tacacs_host $ip_sut] if {[llength $host_list] !=0} { foreach host_name $host_list { add_status "Deleting tacacs-server : $host_name" 3 set cmd "config>>no tacacs-server host $host_name" if {[n_do_command $cmd] != 0} { add_status "Error in deleting tacacs host : $host_name" 1 } } set cmd "show running-config tacacs-server host" set output [n_get_output "$cmd"] if {[regexp "No entries found" $output]} { add_status "All tacacs hosts cleared.." 3 } else { add_status "Hosts still not deleted : [get_tacacs_host $ip_sut]" 1 }


} else { add_status "No tacacs entries found" 3 } }

proc get_tacacs_host {ip_list} { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } brcd_nos_login $ip_sut set host_list [list] set cmd "show running-config tacacs-server host" set output [lrange [compress_list [split [n_get_output "$cmd"] "\r\n"]] 1 end-1] foreach line $output { if {[regexp "tacacs-server host (.*)" $line match host]} { lappend host_list $host }


}

return $host_list }

proc add_tacacs_host {ip_list host_ip {key "sharedsecret"} {port "49"} {protocol "chap"} {timeout_tacacs "5"} {retries "5"} {verify "yes"} {encrypt_level ""} } { global spawn_id global cl_spawn_list set ip_sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_sut $ip_sut } else { set ip_sut [lindex $ip_list 0] } if {$ip_sut == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } brcd_nos_login $ip_sut set cmd "config>>tacacs-server host $host_ip" if {$key != ""} { append cmd " key $key" } if {$port != ""} { append cmd " port $port" }


if {$protocol != ""} { append cmd " protocol $protocol" } if {$timeout_tacacs != ""} { append cmd " timeout $timeout_tacacs" } if {$retries != ""} { append cmd " retries $retries" } if { $encrypt_level != "" } { append cmd " encryption-level $encrypt_level" } if {[n_do_command "$cmd"] == 0} { add_status "Tacacs-server at $host_ip created successfully" 3 if {$verify == "yes"} { add_status "Verifying TACACS in running-config" 3 set return_val [verify_tacacs_host $ip_list $host_ip $key $port $protocol $timeout_tacacs $retries] } else { set return_val 1 } } else { add_status "Error adding Tacacs host" 1 set return_val 0 } return $return_val


}

proc verify_tacacs_host {ip_list host_ip {key "sharedsecret"} {port "49"} {protocol "chap"} {timeout_tacacs "5"} {retries "5"} {delete "no"}} { set overall_pass_flag 1 set sut [get_current_spawn_ip] if {$ip_list == ""} { set ip_list $sut if {$ip_list == -1} { add_status "problem getting the current spawn's IP, have to quit" 0 } } foreach ip $ip_list { if {[set_spawn_id $ip] == 1} { if {[telnet_switch $ip] != 0} { add_status "Switch $ip not available" 0 } else { enter_confdcli } } if {$delete == "yes"} { set pass 0 set oput [n_get_output "show running-config tacacs-server host"] if {([regexp "No entries found" $oput]) || (![regexp "host $host_ip" $oput])} { set pass 1 add_status "properly verified deletion of tacacs host in running-config on switch: $ip" 3


} else { add_status "Error...The tacacs host has not been removed on switch: $ip" 1 } set overall_pass_flag $pass } else { set host_entry_correct 0 set retry_entry_correct 0 set tmout_entry_correct 0 set protocol_entry_correct 0 set key_entry_correct 0 set port_entry_correct 0 set oput [n_get_output "show running-config tacacs-server host"] set oput [split $oput "\n"] foreach line $oput { if {[string first "tacacs-server host" $line] >= 0} { if {[string first $host_ip $line] >= 0} { set host_entry_correct 1 } } if {$retries != ""} { if {[string first "retries" $line] >= 0} { if {[string first $retries $line] >= 0} { set retry_entry_correct 1

}


} } if {$timeout_tacacs != ""} { if {[string first "timeout" $line] >= 0} { if {[string first $timeout_tacacs $line] >= 0} { set tmout_entry_correct 1 } } } if {$port != ""} { if {[string first "port" $line] >= 0} { if {[string first $port $line] >= 0} { set port_entry_correct 1 } } } if {$protocol != ""} { if {[string first "protocol" $line] >= 0} { if {[string first $protocol $line] >= 0} { set protocol_entry_correct 1 } } } if {$key != ""} { if {[string first "key" $line] >= 0} {


if {[string first $key $line] >= 0} { set key_entry_correct 1 } } } } if {$host_entry_correct == 0} { add_status "TACACS host entry in running-config was not set properly to $host_ip on switch: $ip" 1 } else { add_status "TACACS host entry in running-config was set properly to $host_ip on switch: $ip" 3 } if {$port != ""} { if {$port_entry_correct == 0} { add_status "TACACS port entry in running-config was not set properly to $port on switch: $ip" 1 } else { add_status "TACACS port entry in running-config was set properly to $port on switch: $ip" 3 } } if {$retries != ""} { if {$retry_entry_correct == 0} { add_status "TACACS retries entry in running-config was not set properly to: $retries on switch: $ip" 1 } else {


add_status "TACACS retries entry in running-config was set properly to: $retries on switch: $ip" 3 } } if {$timeout_tacacs != ""} { if {$tmout_entry_correct == 0} { add_status "TACACS timeout entry in running-config was not set properly to $timeout_tacacs on switch: $ip" 1 } else { add_status "TACACS timeout entry in running-config was set properly to $timeout_tacacs on switch: $ip" 3 } } if {$key != ""} { if {$key_entry_correct == 0} { add_status "TACACS key entry in running-config was not set properly to: $key on switch: $ip" 1 } else { add_status "TACACS key entry in running-config was set properly to: $key on switch: $ip" 3 } } if {$protocol != ""} { if {$protocol_entry_correct == 0} { add_status "TACACS protocol entry in running-config was not set properly to $protocol on switch: $ip" 1 } else { add_status "TACACS protocol entry in running-config was set properly to $protocol


on switch: $ip" 3 } } if {($port != "") && ($retries != "") && ($timeout_tacacs != "") && ($key != "") && ($protocol != "")} { if {($host_entry_correct == 1) && ($retry_entry_correct == 1) && ($tmout_entry_correct == 1) && ($key_entry_correct == 1) && ($port_entry_correct == 1) && ($protocol_entry_correct ==1)} { set overall_pass_flag 1 } else { set overall_pass_flag 0 } } } } set_spawn_id $sut return $overall_pass_flag }

proc login_user_fail {sw_ip user password } { global cl_PROMPT cl_NOS_PROMPT exp_spawn telnet $sw_ip set timeout 60 expect { -re "login:" { exp_send "$user\r" exp_continue


} -re "assword:" { exp_send "$password\r" # puts "sending password $password" exp_continue } -re "ogin incorrect" { set login_output $expect_out(buffer) } -re "$cl_PROMPT|$cl_NOS_PROMPT" { set login_output $expect_out(buffer) } timeout { set login_output "Timed out" } } return $login_output }

proc possible_entries {cmd_to_execute check entries} { set output [n_get_output $cmd_to_execute] set count 0 set length [llength $entries] set output [compress_list [split $output "\r\n"]] if {$check == 1} {


foreach term $entries { if {[regexp "$term" $output]} { incr count } } } elseif {$check == 0} { foreach term $entries { if {[regexp "$term" $output] == 0} { incr count } } } if {$count >= $length} { return 1 } else { return 0 } }

proc possible_entries_chk {cmd_to_execute check entries} { set output [n_get_output $cmd_to_execute] set count 0 set length [llength $entries] set output [compress_list [split $output "\r\n"]] if {$check == 1} {


foreach term $entries { set term1 "" foreach ele $term { if { $ele == "*" } { set ele "\\$ele" } append term1 "$ele\\s*" } if {[regexp "$term1" $output]} { incr count add_status "$count: Expected: $term1 Actual: $output" 3 } } } elseif {$check == 0} { foreach term $entries { set term1 "" foreach ele $term { append term1 "$ele\\s*" } if {[regexp "$term1" $output] == 0} { incr count add_status "$count: Expected: $term1 Actual: $output" 3 } } }


add_status "Count: $count Length: $length" 3 if {$count >= $length} { return 1 } else { return 0 } }

proc check_wwn_domain_line {cmd_to_execute check wwn domain_id} { set cmd_output [lrange [split [string trim [n_get_output $cmd_to_execute]] "\r\n"] 1 end] set new_cmdoutput [list] foreach element $cmd_output { if {$element != ""} { lappend new_cmdoutput $element } } set count 0 if {$check == 1} { foreach line $new_cmdoutput { if {[regexp "$wwn" $line] && [regexp "$domain_id" $line]} { incr count } } } elseif {$check == 0} {


set num 0 foreach line $new_cmdoutput { if {[regexp "$wwn" $line] == 0 && [regexp "$domain_id" $line] == 0} { incr num } } set length [llength $new_cmdoutput] if {$length == $num} { incr count } }

if {$count >= 1} { return 1 } else { return 0 }

}

proc check_port_stateerror {index int_type interface {error_msg ""} {rbridge ""}} {

if {$rbridge == ""} { set cmd_output [lrange [split [string trim [n_get_output "show fabric islports"]] "\r\n"] 1 end] } else {


set cmd_output [lrange [split [string trim [n_get_output "show fabric islports rbridge-id $rbridge"]] "\r\n"] 1 end] } set new_cmdoutput [list] foreach element $cmd_output { if {$element != ""} { lappend new_cmdoutput $element } } foreach line $new_cmdoutput { if {[regexp "\[ \t]*$index\[ \t]+$int_type\[ \t]+$interface" $line]} { set value_line $line } } set count 0 if {$error_msg != ""} { if {[regexp "$error_msg" $value_line] && [regexp "Down" $value_line]} { incr count } } else { if {[regexp "Up" $value_line]} { incr count } }

if {$count == 1} {


return 1 } else { return 0 }

}

proc verify_ipfltr_to_mgmt_interface {interface acc_grp_name {check "1"}} { set cmd "show running-config interface Management $interface ip access-group" set oput [n_get_output $cmd] if {$check == 1} { if {([regexp "Management $interface" $oput]) && ([regexp "ip access-group $acc_grp_name" $oput])} { add_status "Success...The interface management $interface for ip access-group $acc_grp_name shows correctly" 3 } else { add_status "Error...the interface management and ip access-group doesnt show properly the $interface and $acc_grp_name" 1 } } else { if {![regexp "ip access-group $acc_grp_name" $oput]} { add_status "Success...The interface management $interface doesnt have ip access-group $acc_grp_name" 3 } else { add_status "Error...the interface management have ip access-group $acc_grp_name" 1 } }


}

proc verify_ipv6_ipfltr_to_mgmt_interface {interface acc_grp_name {check "1"}} { set cmd "show running-config interface Management $interface ipv6 access-group" set oput [n_get_output $cmd] if {$check == 1} { if {([regexp "Management $interface" $oput]) && ([regexp "ipv6 access-group $acc_grp_name" $oput])} { add_status "Success...The interface management $interface for ipv6 access-group $acc_grp_name shows correctly" 3 } else { add_status "Error...the interface management and ip access-group doesnt show properly the $interface and $acc_grp_name" 1 } } else { if {![regexp "ipv6 access-group $acc_grp_name" $oput]} { add_status "Success...The interface management $interface doesnt have ipv6 accessgroup $acc_grp_name" 3 } else { add_status "Error...the interface management have ipv6 access-group $acc_grp_name" 1 } } }

proc get_mgmt_interface {{rbridge_id ""}} { global cl_ip_address if {$rbridge_id == ""} {


close_spawn_list brcd_nos_login $cl_ip_address set rbridge_id [get_mapped_id $cl_ip_address] close_spawn_list brcd_login $cl_ip_address } if {[is_chassis] == 1 } { if {[is_dual_mm] == 0} { set chassis 1 add_status "This is a Mercury Chassis with Single MM" set oput [split [get_command "hashow"] "\r\n"] foreach line $oput { regexp {Local \(([A-Z0-9]*)\)\:\s([a-zA-Z]*)\,} $line match mm_active state_active } set active_mm [string index $mm_active 1] set mgmt_int "$rbridge_id/$active_mm" } else { set chassis 1 add_status "This is a Mercury Chassis with Dual MM" set oput [split [get_command "hashow"] "\r\n"] foreach line $oput { regexp {Local \(([A-Z0-9]*)\)\:\s([a-zA-Z]*)\,} $line match mm_active state_active } set active_mm [string index $mm_active 1] set mgmt_int "$rbridge_id/$active_mm"


} } else { set chassis 0 add_status "This is a Pizza Box" set mgmt_int "$rbridge_id/0" } return $mgmt_int }

proc configure_ipv6_address {ip {intf ""}} { brcd_nos_login $ip set rbrdgid [get_mapped_id $ip] if { $intf == "" } { set cmd_output [lrange [split [string trim [n_get_output "show interface Management"]] "\r\n"] 1 end] } else { set cmd_output [lrange [split [string trim [n_get_output "show interface Management $intf"]] "\r\n"] 1 end] } set new_cmdoutput [list] foreach element $cmd_output { if {$element != ""} { lappend new_cmdoutput $element } } set ipv6line ""


foreach line $new_cmdoutput { if {[regexp "ipv6 ipv6-address.*stateless.*preferred" $line]} { set ipv6line $line } } add_status "Ipv6 line - $ipv6line" if {[regexp "stateless.*preferred" $ipv6line]} { add_status "IPv6 address has already been defined for the switch" 3 } else { add_status "IPv6 address has not been defined for the switch, so defining now" 3 if { $intf == "" } { set mgmt_int [get_mgmt_interface $rbrdgid] } else { set mgmt_int $intf } close_spawn_list brcd_nos_login $ip if {[n_do_command "config>>interface Management $mgmt_int>>ipv6 address autoconfig"] == 0} { add_status "Auto configuring the management interface is successful" 3 } else { add_status "Auto configuring the management interface is not successful" 1 } sleep 60 set cmd_output2 [lrange [split [string trim [n_get_output "show interface Management"]] "\r\n"] 1 end]


set new_cmdoutput2 [list] set ipv6line_new "" foreach element $cmd_output2 { if {$element != ""} { lappend new_cmdoutput2 $element } } foreach line $new_cmdoutput2 { if {[regexp "ipv6 ipv6-address.*stateless.*preferred" $line]} { set ipv6line_new $line } } if {[regexp "stateless.*preferred" $ipv6line_new]} { add_status "IPv6 address has been defined for the switch after configuration" 3 } else { add_status "IPv6 address has not been defined even after configuration for the switch" 1 } } close_spawn_list }

proc verify_clear_session { ip_list {rbridge_id ""} {verify "yes" } } {

set result 0 global cl_NOS_PROMPT


global cl_spawn_list if { $rbridge_id == "" } { set rbridge_id "all" } exp_send "clear sessions rbridge-id $rbridge_id\r" expect { "to continue (yes/no)" { exp_send "y\r" exp_continue } "Connection closed by foreign host" { add_status "Command executed Successfully" 3 add_status "Verify all sessions are closed using spawn ids" foreach spawn $cl_spawn_list { if {[set_spawn_id $spawn] == 0} { incr result } } } "Error" { add_status "Command Execution failed" 1 return -1 } -re $cl_NOS_PROMPT { add_status "HERE: $cl_NOS_PROMPT"


} timeout { add_status "Command Timed Out" 1 } } if {$result > 0} { add_status "Some of the sessions are active, after issuing clear sessions command" 1 } else { add_status "All the sessions got closed after executing clear sessions command" 3 } }

###############################################

namespace eval HERCULES { proc parse_env_sensor {sensor_arr {sw_id ""}} { upvar $sensor_arr sensor_arr_ set cmd "show environment sensor" if {$sw_id != ""} { append cmd " rbridge-id $sw_id" } set output [split [n_get_output $cmd] "\n"] array set sensor_arr_ [list] set pattern1 {(?:switch ([0-9]+): )?sensor[ \t]+([0-9]+):[ \t]+\((.*)\)[ \t]+is[ \t]+(.*),[ \t]*.*[ \t] +is(.*)$} set pattern2 {(?:switch ([0-9]+): )?sensor[ \t]+([0-9]+):[ \t]+\((.*)\)[ \t]+is[ \t]+([^,]*)$}


foreach line $output { if {([regexp "$pattern1" $line ignore switchid sensor_id name state value]) || ([regexp "$pattern2" $line ignore switchid sensor_id name state value])} { set switchid [trim_string $switchid] if {$sw_id == ""} { set switchid 1 } set sensor_id [trim_string $sensor_id] set name [trim_string $name] set state [trim_string $state] set value [trim_string $value] if {$switchid != "" & $sensor_id != ""} { set sensor_arr_($switchid,$sensor_id,name) $name set sensor_arr_($switchid,$sensor_id,state) $state set sensor_arr_($switchid,$sensor_id,value) $value } } }

} proc parse_env_temp {temp_arr {sw_id ""}} { upvar $temp_arr temp_arr_ set cmd "show environment temp" if {$sw_id != ""} { append cmd " rbridge-id $sw_id" } set output [lindex [split [n_make_matrix $cmd "====" ""] "\n"] 0] array set temp_arr_ [list]


foreach line $output { set line [lindex $line 0] #puts "line - $line" #

set switchid [lrange [regexp -inline {([0-9]+):} [lindex $line 1]] 1 1] if {$sw_id == ""} { set switchid 1 } set sensorid [lindex $line 0] set state [lindex $line 1] set value "[lindex $line 2] C" set temp_arr_($switchid,$sensorid,name) "Temperature" set temp_arr_($switchid,$sensorid,state) $state set temp_arr_($switchid,$sensorid,value) $value }

# #puts "==>$output" }

proc parse_env_fanPS {unit temp_arr {sw_id ""}} { upvar $temp_arr temp_arr_ if {[string match $unit "fan"]} { set cmd "show environment fan" set name "Fan" set pattern {(?:switch ([0-9]+): )?Fan[ \t]+([0-9]+)[ \t]+is[ \t]+([^,]*)(?:,[ \t]*speed[ \t]+is[ \t]+ (.*))?$} } elseif {[string match $unit "power"]} { set cmd "show environment power" set name "Power" set pattern {(?:switch ([0-9]+): )?Power Supply[ \t]+#([0-9]+)[ \t]+is[ \t]+([^,]*)$}


} else { add_status "No proper unit input. Can be \"fan\" or \"power\"" 2 return -1 } if {$sw_id != ""} { append cmd " rbridge-id $sw_id" } set output [split [n_get_output $cmd] "\n"] array set temp_arr_ [list] if {[regexp -nocase {Not supported} $output]} { add_status "Not Supported on this platform, switchid-$sw_id" return -1 }

foreach line $output { if {[regexp $pattern $line ignore switchid unit_num state value]} { set switchid [trim_string $switchid] if {$sw_id == ""} { set switchid 1 } set unit_num [trim_string $unit_num] set state [trim_string $state] set value [trim_string $value] set temp_arr_($switchid,$unit_num,name) $name set temp_arr_($switchid,$unit_num,state) $state set temp_arr_($switchid,$unit_num,value) $value }


} if {[llength [array get temp_arr_]] == 0} { add_status "No output from command" 2 return -1 } } proc parse_show_fabric_isl {} { global cl_ip_address set output [n_make_matrix "show fabric isl" "------" ""] set return_list [list] foreach line $output {

add_status " nmatrix line values $line" 3 set line [lindex $line 0] #"7" is the number of columns if {[llength $line] < 7} { add_status "Not obtained expected output in islshow" 2 continue } set lp [lindex $line 2] regexp {te([0-9\/]+)} $lp ignore lp set rp [lindex $line 5] regexp {te([0-9\/]+)} $rp ignore rp set rwwn [lindex $line 6] set rdid [lindex [split $rp "/"] 0]


set rsw_name [lindex $line 9] set bw [lindex $line 7] set trunk_state [lindex $line 8] lappend return_list [list $lp $rp $rwwn $rdid $rsw_name $bw $trunk_state] } return $return_list }

proc parse_trunk_info {trunk_arr} { upvar $trunk_arr trunk_arr_ array unset trunk_arr_ set output [n_make_matrix "show fabric trunk" "----" ""] foreach line $output { set line [lindex $line 0] set group_id [lindex $line 0] lappend trunk_arr_($group_id) [list [lindex $line 3] [lindex $line 6] [lindex $line 7]] } }

proc parse_topology {top_arr {ip_list ""}} { upvar $top_arr top_arr_ array unset top_arr_ if {$ip_list == ""} { #if no ip list passed, take the IPs from the fabric show set fabric_list [parse_show_fabric_all num_switches]


set ip_list [list] foreach line $fabric_list { set line [lindex $line 0] lappend ip_list [lindex $line 3] } } set unique_ip_list [lsort -unique $ip_list] if {[llength $unique_ip_list] < [llength $ip_list]} { add_status "Some redundant IPs present in the fabric show" 1 } foreach ip $ip_list { brcd_nos_login $ip set output [n_make_matrix "show fabric route topology" "----" ""] set srcid "" foreach line $output { set line [lindex $line 0] puts "====>line - $line" if {([regexp {Te} [lindex $line 3]])} { puts "inside if - > [lindex $line 3]" set srcid [lindex $line 0] set dstid [lindex $line 1] set outport [lindex $line 4] regexp {te([0-9\/]+)} $outport ignore outport set hop [lindex $line 5] set metric [lindex $line 6]


set bw [lindex $line 10] lappend top_arr_($srcid) [list $dstid $outport $hop $bw $metric] } if {($srcid != "") && ([regexp {Te} [lindex $line 2]])} { puts "next if - > [lindex $line 1]" set dstid [lindex $line 0] set outport [lindex $line 3] regexp {te([0-9\/]+)} $outport ignore outport set hop [lindex $line 4] set metric [lindex $line 5] set bw [lindex $line 9] lappend top_arr_($srcid) [list $dstid $outport $hop $bw $metric] } }

} }

proc parse_multicast_route {rbridgeid mcast_route_arr} { upvar $mcast_route_arr mcast_route_arr_ array unset mcast_route_arr_

add_status " inside Herc name space" 3 set cmd "show fabric route multicast" if {$rbridgeid == "all"} {


append cmd " all" } else { append cmd " rbridgeid $rbridgeid" } set output [split [n_get_output $cmd] "\r\n"] set nbr_split [lsearch -regexp $output "Src-Index" ] add_status "nbr_split value is $nbr_split" 3 set r_id [lindex $output [expr $nbr_split-2]]

regexp {Rbridge-id: (\d+)} $r_id ignore r_id set nbr_list [list] add_status "NBR List values are $nbr_list[list]" 3 for {set i 0} {$i < [llength $output]} {incr i} { set line [lindex $output $i] add_status "each line value is $line" 3 if {$line == ""} { continue } if {[regexp {Root of the Multicast-Tree} $line]} { set j $i set arr_name "ROOT_INFO" incr i 2 set domain "" set mcast_priority "" set enet_ip ""


set wwn "" set sw_name "" for {set i $j} {$i < [expr $nbr_split-4]} {incr i} { set line [lindex $output $i] add_status "ROFMT: line = $line" 3 if {[regexp {(.*): (.*)} $line ignore name value]} { add_status "inside for loop ROFMT: line = $line ignore = $ignore name = $name value = $value" 3 set name [trim_string $name] set value [trim_string $value] add_status "uvel ==> name value is $name" 3 if {[string match $name "Rbridge-id"]} { set domain $value } elseif {[string match $name "Mcast Priority"]} { set mcast_priority $value } elseif {[string match $name "Enet IP Addr"]} { set enet_ip $value } elseif {[string match $name "WWN"]} { set wwn $value } elseif {[string match $name "Name"]} { set sw_name $value } else { } } } add_status "uvelusam: $domain $mcast_priority $enet_ip $wwn $sw_name"


set mcast_route_arr_($arr_name) [list $domain $mcast_priority $enet_ip $wwn $sw_name] } if {$i > $nbr_split} { set arr_name "NBR_INFO" } if {[regexp {Te (\d+/\d+/\d+)[ \t]+Te (\d+/\d+/\d+)[ \t]+(\d+)G[ \t]+([^\r\n]*)} $line ignore src_port nbr_port bw trunk_state]} { lappend nbr_list [list $src_port $nbr_port $bw $trunk_state] } } set mcast_route_arr_($arr_name) $nbr_list

}

}

proc parse_vcs_info {vcs_arr {ignore_cluster_ip_chk 1} {ip_addr_list ""}} { upvar $vcs_arr vcs_arr_ global cl_ip_address_list if {$ignore_cluster_ip_chk == 0} { if {$ip_addr_list == ""} { set ip_addr_list $cl_ip_address_list } set ip_length [llength $ip_addr_list] array unset vcs_arr_


add_status "Checking whether all switches ($ip_addr_list) are found in online state in show vcs" set cmd "show vcs" set num_of_nodes -1 set no_of_time 1 set error 1 clear_buffer set output [get_command $cmd] while {$no_of_time <= 3} { if {[regexp -all "Online" $output] == [expr $ip_length * 2]} { set error 0 break } add_status "Couldn't find switches - $ip_addr_list in online state on show vcs. Waiting for 5 minutes to check again" 2 sleep 300 incr no_of_time clear_buffer set output [get_command $cmd] } if {$error && ([regexp -all "Online" $output] != [expr $ip_length * 2])} { add_status "Switches - $ip_addr_list not came up in online state after waiting for 15 minutes" 1 return $num_of_nodes } add_status "All the switches - $ip_addr_list came up in online state" 3 }


set output [get_command "show vcs detail"] set num_of_nodes [regexp -all {Node[ \t]*:[ \t]*([0-9]+)} $output ignore] set output [split $output \r\n] set node 1 array set vcs_arr_ [list] foreach line $output { if {$line == ""} { continue } if {[regexp {Config Mode[ \t]+:[ \t]+(.*)} $line ignore config_mode]} { set vcs_arr_(CONFIG_MODE) $config_mode continue } if {[regexp {VCS ID[ \t]+:[ \t]+(.*)} $line ignore vcs_id]} { set vcs_arr_(VCS_ID) $vcs_id continue } if {[regexp {VCS GUID[ \t]+:[ \t]+(.*)} $line ignore vcs_guid]} { set vcs_arr_(VCS_GUID) $vcs_guid continue } if {[regexp {Total Number of Nodes[ \t]+:[ \t]+([0-9]+)} $line ignore nodes]} { set vcs_arr_(TOTAL_NODES) $nodes continue } if {[regexp {Nodes Disconnected from Cluster[ \t]+:[ \t]+([0-9]+)} $line ignore nodes_disc]} { set vcs_arr_(N_DISCONNECTED) $nodes_disc


continue } if {[regexp {Cluster Condition[ \t]+:[ \t]+(.*)} $line ignore cluster_condition]} { set vcs_arr_(CLUSTER_CONDITION) $cluster_condition continue } if {[regexp {Cluster Status[ \t]+:[ \t]+(.*)} $line ignore cluster_status]} { set vcs_arr_(CLUSTER_STATUS) $cluster_status continue } set name "" set value "" if {[regexp {^Node :([0-9]+)} $line ignore node]} { set node [trim_string $node] continue } if {[regexp {([^:]*)[ \t]*:(.*)} $line ignore name value]} { set name [trim_string $name] set value [trim_string $value] set vcs_arr_($node,$name) $value } } return $num_of_nodes }


proc parse_fcport_speed {port} { set cmd "show running-config interface FibreChannel $port speed" set output [lrange [split [n_get_output $cmd] "!"] 0 end-1] foreach info $output { if {[regexp {speed (.*)} $info match speed]} { set fcport_speed [trim_string $speed] } } return $fcport_speed }

proc parse_isl_r_rdy_state {port} { set cmd "show running-config interface FibreChannel $port isl-r_rdy" set output [lrange [split [n_get_output $cmd] "!\n"] 0 end-1] set isl_r_rdy_state [trim_string [lindex $output 2]] return $isl_r_rdy_state }

proc parse_vlan_ids {} { set cmd "show running-config interface vlan" set output [lrange [split [n_get_output $cmd] "!"] 0 end-1] set vlan_list [list] foreach info $output { if {[regexp {interface Vlan (\d+)} $info ignore vlanid]} { lappend vlan_list $vlanid


} } return $vlan_list

}

proc parse_vcs_virtual {} { set cmd "show running-config vcs virtual" set output [lrange [split [n_get_output $cmd] "\r\n"] 0 end-1] # add_status "output\n====$output\n===" set ip "" set vip_info [list] foreach info $output { #

add_status "info =====> $info" if {[regexp "ip address (\[^/]+/\[0-9]+)" $info ignore ip] != -1} { set vcs_ip $ip }

} return $vcs_ip }

proc verify_removal_vip {ipaddr } { set rem_vip [parse_vcs_virtual] if {![regexp $ipaddr $rem_vip]} { add_status "Removed VIP is not shown in show running-config vcs virtual successfully" 3


} else { add_status "Removed VIP is still shown in show running-config vcs virtual " 1 } }

proc verify_vip {vip {mode "MC"}} { set vcs_ip [parse_vcs_virtual] #set vcs_ip [lindex [split $vcs_ip "/"] 0] #add_status "vcs_ip ==> $vcs_ip" #set value [get_list_disjoint $vip $vcs_ip] #add_status "value == $value" if {[llength [get_list_disjoint $vip $vcs_ip]] == 0} { add_status "Configured VIP: $vip is shown properly in show running-config vcs virtual" 3 } else { if {$mode == "FC"} { add_status "The Original Configured VIP $vip is retained after merging" 3 set vip $vcs_ip return $vip } else { add_status "Failed to display the configured VIP: $vip in show running-config vcs virtual" 1 } }

}


proc verify_pri_vip_hname {pri_out vip_out hname } { set status 0 set pri_info [split $pri_out "\r\n"] set vip_info [split $vip_out "\r\n"]

foreach info $pri_info infos $vip_info { if {([regexp $hname $info]) != 0 && ([regexp $hname $infos]) != 0} { set status 1 } } return $status }

proc parse_pri_hname_fabricall { } { set fabric_list [parse_show_fabric_all num_switches] set pri_hname [list] set pri_ip [list] set rbgid [list] foreach line $fabric_list { set line [lindex $line 0] #

add_status "line ===> $line" 3


set hname [lindex $line 4] #

add_status "hname ===> $hname" 3 if {[regexp {>\"(.*)\"} $hname ig hname]} { lappend pri_hname $hname lappend pri_ip [lindex $line 3] lappend rbgid [lindex $line 0]

} } add_status "pri_hname ===> $pri_hname pri_ip ===> $pri_ip rbgid ===> $rbgid" 3 return [list $pri_hname $pri_ip $rbgid]

}

proc verify_hname_fabricall {hname} { set output [parse_pri_hname_fabricall] set current_hname [list] set current_hname [lindex $output 0] if {[regexp $hname $current_hname] } { add_status "Configured host name $hname is shown in show fabric all output" 3 } else { add_status "Configured host name $hname failed to show in show fabric all output" 1 } }


proc power_off {ip port_list} { exp_spawn telnet $ip set timeout 20 expect { "login:" { exp_send "user\r" exp_continue } "assword:" { exp_send "pass\r" exp_continue } "cli->" { exp_send "ls\r" } timeout { add_status "timed out 20 seconds, trying to login and get to prompt of power tower" 0 }

} set firmware "older" expect { "cli->" { foreach item $expect_out(buffer) { if {[string first "access" $item] >= 0} { #new 2.0 power tower has access under the parent directory called CLI


# older does not set firmware "newer" } }

# exp_send "cd power_management/management\r" }

} if {$firmware == "older"} { exp_send "cd power_management/management\r" expect { "cli->" { if {[string first "management" $expect_out(buffer)] >=0} { add_status "correctly got into the management directory in power tower" 3 } else { add_status "did not find string \"management\" in the prompt of power tower, did not change directories properly" 0 } exp_send "ls\r" }

} expect { "cli->" { add_status "*** $expect_out(buffer)"


foreach line $expect_out(buffer) { if {[regexp "^(\[-_0-9A-Za-z]+)/" $line ignore dirName]} { add_status "dirName found: $dirName" 3 } } exp_send "cd $dirName/outlet_table\r" }

} expect { "cli->" { if {[string first $dirName $expect_out(buffer)]>=0} { add_status "correctly changed directory to $dirName" 3 } else { add_status "did not find string \"$dirName\" in the prompt of power tower, did not change directories properly" 0 } if {[string first "outlet_table" $expect_out(buffer)]>=0} { add_status "correctly changed directory to outlet_table, ready to power cycle" 3 } else { add_status "did not find string \"outlet_table\" in the prompt of power tower, did not change directories properly" 0 } # turn off ports if {[llength $port_list] == 2} { set group "[lindex $port_list 0],[lindex $port_list 1]"


} else { set group $port_list } exp_send "off $group\r" exp_continue } ":" { exp_send "yes\r" } } expect { "cli->" { add_status "hit prompt after confirming power of $port_list port(s)" 3 } timeout { add_status "timed out waiting for prompt after confirming power of $port_list ports" 0 }

} } else { exp_send "cd access\r" expect { "cli->" { if {[string first "access" $expect_out(buffer)] >=0} { add_status "correctly got into the access directory in power tower" 3 } else { add_status "did not find string \"access\" in the prompt of power tower, did not change directories properly" 0


} exp_send "ls\r" }

} expect { "cli->" { set nextDir -1 foreach item $expect_out(buffer) { if {[string first "PS" $item] == -1} { if {[string first "/" $item] >= 0} { set item [trim_string $item "/"] add_status "item is $item" set nextDir $item } } } if {$nextDir == -1} { add_status "could not find name directory under \"access\" that did not have \"PS\" in its name" 0 } else { exp_send "cd $nextDir\r" } } } expect {


"cli->" { set new_port_list "" foreach h $port_list { set toAppend $nextDir append toAppend _$h lappend new_port_list $toAppend } #add_status "new_port_list is $new_port_list" 0 if {[llength $new_port_list] == 2} { set group "[lindex $new_port_list 0],[lindex $new_port_list 1]" } else { set group $new_port_list } exp_send "off $group\r" exp_continue } ":" { exp_send "yes\r" } }

expect { "cli->" { add_status "hit prompt after confirming the power of $new_port_list port(s)" 3 } timeout { add_status "timed out waiting for prompt after confirming power of $new_port_list ports" 0


}

}

}

}

proc power_on {ip port_list} { exp_spawn telnet $ip set timeout 20 expect { "login:" { exp_send "user\r" exp_continue } "assword:" { exp_send "pass\r" exp_continue } "cli->" { exp_send "ls\r" } timeout { add_status "timed out 20 seconds, trying to login and get to prompt of power tower" 0 }


} set firmware "older" expect { "cli->" { foreach item $expect_out(buffer) { if {[string first "access" $item] >= 0} { #new 2.0 power tower has access under the parent directory called CLI # older does not set firmware "newer" } }

# exp_send "cd power_management/management\r" }

} if {$firmware == "older"} { exp_send "cd power_management/management\r" expect { "cli->" { if {[string first "management" $expect_out(buffer)] >=0} { add_status "correctly got into the management directory in power tower" 3 } else { add_status "did not find string \"management\" in the prompt of power tower, did not change directories properly" 0


} exp_send "ls\r" }

} expect { "cli->" { add_status "*** $expect_out(buffer)" foreach line $expect_out(buffer) { if {[regexp "^(\[-_0-9A-Za-z]+)/" $line ignore dirName]} { add_status "dirName found: $dirName" 3 } } exp_send "cd $dirName/outlet_table\r" }

} expect { "cli->" { set new_port_list "" foreach h $port_list { set toAppend $nextDir append toAppend _$h lappend new_port_list $toAppend }


#add_status "new_port_list is $new_port_list" 0 if {[llength $new_port_list] == 2} { set group "[lindex $new_port_list 0],[lindex $new_port_list 1]" } else { set group $new_port_list } add_status "got prompt for turning on $new_port_list port(s)" 3 exp_send "on $group\r" exp_continue } ":" { exp_send "yes\r" } } expect { "cli->" { add_status "hit prompt after confirming the re-power on $new_port_list port(s)" 3 } timeout { add_status "timed out waiting for prompt after confirming repower on of $new_port_list ports" 0 }

} } else { exp_send "cd access\r" expect { "cli->" {


if {[string first "access" $expect_out(buffer)] >=0} { add_status "correctly got into the access directory in power tower" 3 } else { add_status "did not find string \"access\" in the prompt of power tower, did not change directories properly" 0 } exp_send "ls\r" }

} expect { "cli->" { set nextDir -1 foreach item $expect_out(buffer) { if {[string first "PS" $item] == -1} { if {[string first "/" $item] >= 0} { set item [trim_string $item "/"] add_status "item is $item" set nextDir $item } } } if {$nextDir == -1} { add_status "could not find name directory under \"access\" that did not have \"PS\" in its name" 0 } else {


exp_send "cd $nextDir\r" } } }

expect { "cli->" { set new_port_list "" foreach h $port_list { set toAppend $nextDir append toAppend _$h lappend new_port_list $toAppend } #add_status "new_port_list is $new_port_list" 0 if {[llength $new_port_list] == 2} { set group "[lindex $new_port_list 0],[lindex $new_port_list 1]" } else { set group $new_port_list }

add_status "got prompt for turning on port(s)" 3 exp_send "on $group\r" exp_continue } ":" { exp_send "yes\r"


} } expect { "cli->" { add_status "hit prompt after confirming the re-power on port(s)" 3 } timeout { add_status "timed out waiting for prompt after confirming repower on ports" 0 }

}

}

}

proc parse_show_interface_management {} { set cmd "show interface Management" set output [split [n_get_output $cmd ] "\n"] set ip_list [list] foreach item $output { if {[string first "ip address" $item] >= 0} { if {[regexp "ip address (\[^/]+)/(\[0-9]+)" $item ignore ip] != -1} { lappend ip_list $ip


} else { add_status "couldn't parse the ip address" 3 } } elseif {[string first "ip gateway-address" $item] >= 0} { if {[regexp "ip gateway-address (\[0-9.]+)" $item ignore gateway] != -1} { lappend ip_list $gateway } else { add_status "couldn't parse the ip gateway address" 3 } } elseif {[string first "vcs virtual ip address" $item] > 0} { if {[regexp "vcs virtual ip address (\[^/]+)/(\[0-9]+)" $item ignore vcs_ip] != -1} { lappend ip_list $vcs_ip } else { add_status "couldn't parse the vcs ip" 3 } } } return $ip_list }

proc parse_defined_zoning {} { set cmd "show running-config zoning defined-configuration" set output [split [n_get_output $cmd] "\r\n"] if {[regexp {No entries found} $output]} { return -1


} array set cfg_arr_list [list] array set zone_arr_list [list] for {set i 0} {$i < [llength $output]} {incr i} { set line [lindex $output $i] if {[regexp {zoning defined-configuration cfg ([^\r\n]+)} $line ignore cfg_name]} { for {set i [expr $i+1]} {$i < [llength $output]} {incr i} { set next_line [lindex $output $i] if {[regexp {^zoning defined-configuration} $next_line]} { incr i -1;break } if {[regexp {member-zone ([^\r\n]+)} $next_line ignore member_zone]} { lappend cfg_arr_list($cfg_name) $member_zone } }

} if {[regexp {zoning defined-configuration zone ([^\r\n]+)} $line ignore zone_name]} { for {set i [expr $i+1]} {$i < [llength $output]} {incr i} { set next_line [lindex $output $i] if {[regexp {^zoning defined-configuration} $next_line]} { incr i -1;break } if {[regexp {member-entry ([^\r\n]+)} $next_line ignore member_wwn]} { lappend zone_arr_list($zone_name) $member_wwn } }

}


}

return [list [array get cfg_arr_list] [array get zone_arr_list]] }

proc parse_enabled_zoning {} { set current_version [join [lrange [regexp -inline {([0-9])\.([0-9])\.*} [get_version_nos]] 1 end] ""] if {$current_version >= 40 } { set cmd "show zoning enabled-configuration" } else { set cmd "show running-config zoning enabled-configuration" } set output [split [n_get_output $cmd] "\r\n"] #Initialize variables set cfg_name "" set cfg_action "" set db_max "" set db_avail "" set db_committed "" set db_transaction "" set transaction_token "" set default_zone_access "" for {set i 0} {$i < [llength $output]} {incr i} { set line [lindex $output $i] array set zone_arr [list]


if {![regexp {zoning enabled-configuration ([^ \t]+) ([^\r\r]+$)} $line ignore name value]} { continue } switch -regexp $name { "cfg-name" { set cfg_name $value } "cfg-action" { set cfg_action $value } "db-max" { set db_max $value } "db-avail" { set db_avail $value } "db-committed" { set db_committed $value } "db-transaction" { set db_transaction $value } "transaction-token" { set transaction_token $value } "default-zone-access" { set default_zone_access $value


} "enabled-zone" { set zone_name $value

for {set i [expr $i+1]} {$i < [llength $output]} {incr i} { set next_line [lindex $output $i] if {[regexp {^zoning enabled-configuration enabled-zone ([^\r\n]+)} $next_line ignore zone_name]} { continue } if {[regexp {member-entry ([^\n\r]+)} $next_line ignore member_entry]} { lappend zone_arr($zone_name) $member_entry } } } } } set general_info [list $cfg_name $cfg_action $db_max $db_avail $db_committed $db_transaction $transaction_token $default_zone_access] set zone_info [array get zone_arr] return [list $general_info $zone_info] }

proc parse_logging_audit {} { set cmd "show running-config logging auditlog" set output [split [n_get_output "$cmd"] "\r\n"]


set auditlog_cfg_list [list] foreach line $output { if {[regexp {logging auditlog class ([^\r\n]+)} $line ignore class]} { lappend auditlog_cfg_list $class } } return $auditlog_cfg_list }

proc parse_zoning_operation_info {} { set cmd "show zoning operation-info" set output [split [n_get_output "$cmd"] "\r\n"] set db-max "";set db-avail "";set db-committed "";set db-transaction "";set transaction-token ""

foreach line $output { puts "line - $line" if {[regexp {(db-max|db-avail|db-committed|db-transaction|transaction-token) (.*)} $line ignore var val]} { switch $var { "db-max" { set db-max $val } "db-avail" { set db-avail $val }


"db-committed" { set db-committed $val } "db-transaction" { set db-transaction $val } "transaction-token" { set transaction-token $val } } } } set return_list [list ${db-max} ${db-avail} ${db-committed} ${db-transaction} ${transactiontoken}] return $return_list }

proc parse_system_monitor_health {{rbridge_id ""}} { set cmd "show system monitor" if {$rbridge_id != ""} { append cmd " rbridge-id $rbridge_id" } set output [split [n_get_output $cmd] "\r\n"] set switch_status ""; set ps_status ""; set temp_status ""; set fan_status ""; set flash_status ""; set report_time "" foreach line $output {


regexp {switch status[ \t]+:[ \t]+(.*)} $line ignore switch_status regexp {Time of Report[ \t]+:[ \t]+(.*)} $line ignore report_time regexp {Power supplies monitor[ \t]+:[ \t]+(.*)} $line ignore ps_status regexp {Temperatures monitor[ \t]+:[ \t]+(.*)} $line ignore temp_status regexp {Fans monitor[ \t]+:[ \t]+(.*)} $line ignore fan_status regexp {Flash monitor[ \t]+:[ \t]+(.*)} $line ignore flash_status } set ret_val [list $switch_status $ps_status $temp_status $fan_status $flash_status $report_time] return $ret_val }

proc parse_sysmonitor_mailids {} { set cmd "show running-config system-monitor-mail" set output [n_get_output $cmd] if {[regexp {No entries found} $output]} { return -1} set email_list [regexp -inline -all {[^ \t\r\n@]+\@[^\r\n]+} $output] return $email_list }

#Return two lists - fan list and ps list in a format "<fru_no> <fru_state>" such as if fan1 is ab and fan2 is ok it will be like "1 ab" "2 ok" proc parse_show_system {} { set cmd "show system" set output [split [n_get_output $cmd] "\r\n"] set ps_list [list]


set fan_list [list] foreach line $output { if {[regexp {PS(\d) is (.*)} $line ignore ps_no ps_status]} { lappend ps_list "$ps_no $ps_status" } if {[regexp {Fan (\d) is (.*)} $line ignore fan_no fan_status]} { lappend fan_list "$fan_no $fan_status" } } return [list $ps_list $fan_list]

} #######################################

namespace eval HERCULES { proc n_get_raslog {msg_id {switch_id ""}} { set cmd "show logging raslog" if {$switch_id != ""} { append cmd " rbridge-id $switch_id" } append cmd " | include $msg_id" set output [lrange [split [n_get_output $cmd] "\n"] 1 end] set log_matched -1 for {set i 0} {$i < [llength $output]} {incr i} { set line [lindex $output end-$i]


puts "-->$line" if {[regexp "$msg_id" $line]} { set log_matched $line break } } return $log_matched }

}

proc n_get_auditlog {msg_id {rbridge_id ""}} { set cmd "show logging auditlog" if {$rbridge_id != ""} { append cmd " rbridge-id $rbridge_id" } append cmd " | include $msg_id" set output [lrange [split [n_get_output $cmd] "\n"] 1 end] set log_matched -1 for {set i 0} {$i < [llength $output]} {incr i} { set line [lindex $output end-$i] puts "-->$line" if {[regexp "$msg_id" $line]} { set log_matched $line


break } } return $log_matched

}

proc n_clear_auditlog {{verify "yes"}} { global cl_ip_address set cmd "clear logging auditlog" set rbridge_id [get_mapped_id $cl_ip_address] if {$rbridge_id != -1} { append cmd " rbridge-id $rbridge_id" } if {[n_do_command $cmd] != 0} { add_status "Error in clearing auditlog" 1 } else { add_status "Log clear sent successfully" 3 } sleep 1 if {$verify != "yes"} { return 0 } set cmd "show logging auditlog" set output [n_get_output $cmd] if {[regexp "No messages" $output]} { add_status "Auditlog cleared successfully" 3


} else { add_status "Error in clearing auditlog" 1 } }

######################################


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.