cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1805
Views
0
Helpful
4
Replies

TCL scripting

Network Scenario:

We have a Client-Server enterprise network, and nature of servers is to broadcast some stats/info to all the clients.

We are using two 6509-E at core with HSRP to provide the redundancy for servers. I have attached the network layout (not the real one) with some description with this thread. On both switches we have configured “ip helper-addresses” to forward the broadcast to multiple destinations(different VLANs). Every thing is working fine with respect to HSRP.

Problem:

Under normal circumstances, both ACTIVE and STANDBY hsrp switches generates broadcast which causing duplication of every broadcast packet and Client end receiving every packet twice. Cisco already claimed that standby switch will forward the broadcast. As an alternate TAC has advised to use the TCL script as a work around which we attempted to however no success at the end.

Please let me know if some one can help me in modifying TCL script.

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

::cisco::eem::event_register_syslog occurs 1 pattern .*STANDBY.*STATECHANGE.* maxrun 90

#------------------------------------------------------------------

# EEM policy used to detect an HSRP state change. Once change is detected, analize the

# type of change and modify the configuration about helper address.

#

# The script looks for the DHCP server ip address in dhcp_server environment variable

# and adds or removes the command 'ip helper-address dhcp_server' to the interface on

# which HSRP status has changed.

#

# April 2006, Cisco Europe & Emerging TME Team

#

# Copyright (c) 2006 by cisco Systems, Inc.

# All rights reserved.

#------------------------------------------------------------------

###

### The script uses the following environment variables:

#   $dhcp_server - ip address of the DCHP server in four octect dotted notation

#

#

# 1. check if all the env variables we need exist and if not abort

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

if {![info exists dhcp_server]} {

    set result "EEM Policy Error: variable dhcp_server has not been set"

    error $result $errorInfo

}

#

# 2. Local procedure for CLI show commands

# Pass a list of cli commands and it returns a list of outputs

#

proc CLICmdProc {cmds} {

    if [catch {cli_open} result] {

        error $result $errorInfo

    } else {

        array set cli1 $result

        }

    if [catch {cli_exec $cli1(fd) "enable"} result] {

        error $result $errorInfo

    }

    foreach a_cmd $cmds {

        if [catch {cli_exec $cli1(fd) $a_cmd} result] {

            error $result $errorInfo

        } else {

            lappend cmd_output $result

        }

    }

    if [catch {cli_close $cli1(fd) $cli1(tty_id)} result] {

        error $result $errorInfo

    }

    return $cmd_output

}

#

# 3. Local procedure for CLI configuration commands

# Pass a list of cli commands

#

proc CLICfgProc {cmds} {

    if [catch {cli_open} result] {

        error $result $errorInfo

    } else {

        array set cli1 $result

        }

    if [catch {cli_exec $cli1(fd) "enable"} result] {

        error $result $errorInfo

    }

    if [catch {cli_exec $cli1(fd) "config terminal"} result] {

        error $result $errorInfo

    }

    foreach a_cmd $cmds {

        if [catch {cli_exec $cli1(fd) $a_cmd} result] {

            error $result $errorInfo

        } else {

            set cmd_output $result

        }

    }

    if [catch {cli_exec $cli1(fd) "end"} result] {

        error $result $errorInfo

    }

    if [catch {cli_exec $cli1(fd) "write mem"} result] {

        error $result $errorInfo

    }

    if [catch {cli_close $cli1(fd) $cli1(tty_id)} result] {

        error $result $errorInfo

    }

}

# 4. query the information of latest triggered eem event

array set arr_einfo [event_reqinfo]

if {$_cerrno != 0} {

    set result [format "component=%s; subsys err=%s; posix err=%s;\n%s" \

        $_cerr_sub_num $_cerr_sub_err $_cerr_posix_err $_cerr_str]

    error $result

}        

set msg $arr_einfo(msg)

# 5. we save the interface which triggered the event in interface

regexp {(Vlan[0-9]{1,4}).*-> ([A-Z,a-z]*$)} $msg result interface action

if {$action == "Active"} {

              lappend clicmd "interface $interface"

              lappend clicmd "ip helper-address $dhcp_server"

}

if {$action != "Active"} {

              lappend clicmd "interface $interface"

              lappend clicmd "no ip helper-address $dhcp_server"

}

set cliout [CLICfgProc $clicmd]

action_syslog msg "Updating the configuration of interface $interface"

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

hsrp_double_bcast.jpg

4 Replies 4

Joe Clarke
Cisco Employee
Cisco Employee

Based on the code you posted, it seems you want to remove the helper addresses from the non-active interface, is that correct?

Hi Clarke !

Yup you are correct, we want to add/delete helper addresses on active/standy hsrp switches thorugh TCL scripting.

Thank You.

Try this version.  You will need to first set an environment variable, dhcp_servers to be a comma separated list of IP addresses (i.e. the helper addresses) to configure/unconfigure.  For example:

event manager environment dhcp_servers 192.168.10.255,192.168.12.255,192.168.14.255

Hi Clarke !

Thank you for your reply, I will test what you suggested but it required maintenance window. Hopefully I will back in couple of days.

Regards,

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Innovations in Cisco Full Stack Observability - A new webinar from Cisco