Tuesday, September 28, 2010

Lab Notes - Misc 9.26.2010

w2(config-if)#mls qos ?
  cos            cos keyword
  dscp-mutation  dscp-mutation keyword
  ipe            ipe keyword
  trust          trust keyword
  vlan-based     vlan-based keyword

sw2(config-if)#mls qos


sw2(config)#mls qos ?
  aggregate-policer  Named aggregate policer
  map                qos map keyword
  queue-set          Choose a queue set for this queue
  rewrite            Rewrite Packet/Frame
  srr-queue          Configure SRR receive queues
  <cr>

sw2(config)#mls qos ma
sw2(config)#mls qos map ?
  cos-dscp       cos-dscp map: eight dscp values for cos 0-7
  dscp-cos       dscp-cos map keyword
  dscp-mutation  dscp-mutation map keyword
  ip-prec-dscp   dscp values for ip precedences 0 - 7
  policed-dscp   policed-dscp map keyword

sw2(config)#mls qos map

interface Port-channel1
 switchport trunk encapsulation dot1q
 switchport mode trunk
 link state group 1 downstream

link state track 1

interface FastEthernet0/23
 switchport trunk encapsulation dot1q
 switchport mode trunk
 link state group 1 downstream
 channel-group 1 mode on
!
interface FastEthernet0/24
 switchport trunk encapsulation dot1q
 switchport mode trunk
 link state group 1 downstream
 channel-group 1 mode on
!

interface fa 0/23
sw1(config-if)#mls qos vlan-based
sw1(config-if)#mls
sw1(config-if)#mls qo
sw1(config-if)#mls qos tr
sw1(config-if)#mls qos trust dscp
port is vlan-based for interface FastEthernet0/23
sw1(config-if)#inter fa 0/24
sw1(config-if)#mls qos tr
sw1(config-if)#mls qos trust dscp
sw1(config-if)#

!
class-map match-all cm-dscp-ef
 match ip dscp ef
class-map match-all cm-24
 match input-interface  FastEthernet0/24
!
!
policy-map vlan10
 class cm-dscp-ef
  trust dscp
policy-map vlan30
 class class-default
  trust dscp
policy-map vlan20
 class class-default
  trust dscp
policy-map port24ef
 class cm-dscp-ef
  police 80000 8000 exceed-action policed-dscp-transmit
 class cm-24
  police 80000 8000 exceed-action drop

interface Vlan10
 no ip address
 service-policy input vlan10
!
interface Vlan20
 no ip address
 service-policy input vlan20
!
interface Vlan30
 no ip address
 service-policy input vlan30

sw1(config)#do sh policy-map interface
 Vlan10

  Service-policy input: vlan10

    Class-map: cm-dscp-ef (match-all)
      0 packets, 0 bytes
      5 minute offered rate 0 bps, drop rate 0 bps
      Match: ip dscp ef (46)

    Class-map: class-default (match-any)
      0 packets, 0 bytes
      5 minute offered rate 0 bps, drop rate 0 bps
      Match: any
        0 packets, 0 bytes
        5 minute rate 0 bps
 Vlan20

  Service-policy input: vlan20

    Class-map: class-default (match-any)
      0 packets, 0 bytes
      5 minute offered rate 0 bps, drop rate 0 bps
      Match: any
        0 packets, 0 bytes
        5 minute rate 0 bps
 Vlan30

  Service-policy input: vlan30

    Class-map: class-default (match-any)
      0 packets, 0 bytes
      5 minute offered rate 0 bps, drop rate 0 bps
      Match: any
        0 packets, 0 bytes
        5 minute rate 0 bps
sw1(config)#



sw2(config)#mls qos

sw2(config-if)#do sh mls qos inter fa 0/24 queu
FastEthernet0/24
Egress Priority Queue : disabled
Shaped queue weights (absolute) :  4 4 0 0
Shared queue weights  :  1 1 7 3
The port bandwidth limit : 100  (Operational

Bandwidth:100.0)
The port is mapped to qset : 1

sw2(config-if)#srr-queue bandwidth ?
  limit  Configure bandwidth-limit for this interface
  shape  Configure shaping on transmit queues
  share  Configure shared bandwidth

sw2(config-if)#srr-queue bandwidth

sw2(config-if)#srr-queue bandwidth share 4 4 1 4
sw2(config-if)#srr-queue bandwidth shape 0 0 3 0
sw2(config-if)#do sh mls qos interfa fa 0/23 q
FastEthernet0/23
Egress Priority Queue : disabled
Shaped queue weights (absolute) :  0 0 3 0
Shared queue weights  :  4 4 1 4
The port bandwidth limit : 100  (Operational

Bandwidth:100.0)
The port is mapped to qset : 1

r2#sh event manager policy available detailed 

sl_intf_down.tcl
::cisco::eem::event_register_syslog occurs 1 pattern

$_syslog_pattern maxrun 90
#----------------------------------
# EEM policy to monitor for a specified syslog message.
# Designed to be used for syslog interface-down messages.
# When event is triggered, the given config commands will be

run.
#
#
# July 2005, Cisco EEM team
#
# Copyright (c) 2005-2006 by cisco Systems, Inc.
# All rights reserved.
#----------------------------------
### The following EEM environment variables are used:
###
### _syslog_pattern (mandatory)        - A regular

expression pattern match string
###                                      that is used to

compare syslog messages
###                      to determine when policy runs
### Example: _syslog_pattern            

.*UPDOWN.*FastEthernet0/0.*
###
### _email_server (mandatory)          - A Simple Mail

Transfer Protocol (SMTP)
###                      mail server used to send e-mail.
### Example: _email_server              

mailserver.customer.com
###
### _email_from (mandatory)            - The address from

which e-mail is sent.
### Example: _email_from                

devtest@customer.com
###
### _email_to (mandatory)              - The address to

which e-mail is sent.
### Example: _email_to                  

engineering@customer.com
###
### _email_cc (optional)               - The address to

which the e-mail must
###                      be copied.
### Example: _email_cc                  

manager@customer.com
###
### _config_cmd1 (optional)            - The first

configuration command that
###                                      is executed.
### Example: _config_cmd1                interface

Ethernet1/0
###
### _config_cmd2 (optional)            - The second

configuration command that
###                      is executed.
### Example: _config_cmd2                no shutdown
###
# check if all the env variables we need exist
# If any of them doesn't exist, print out an error msg and

quit
if {![info exists _email_server]} {
    set result \
        "Policy cannot be run: variable _email_server has

not been set"
    error $result $errorInfo
}
if {![info exists _email_from]} {
    set result \
        "Policy cannot be run: variable _email_from has not

been set"
    error $result $errorInfo
}
if {![info exists _email_to]} {
    set result \
        "Policy cannot be run: variable _email_to has not

been set"
    error $result $errorInfo
}
if {![info exists _email_cc]} {
     #_email_cc is an option, must set to empty string if

not set.
     set _email_cc ""
}
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
# 1. 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)
set config_cmds ""
# 2. execute the user-defined config commands
if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}
if [catch {cli_exec $cli1(fd) "en"} result] {
    error $result $errorInfo
}
if [catch {cli_exec $cli1(fd) "config t"} result] {
    error $result $errorInfo
}
if {[info exists _config_cmd1]} {
    if [catch {cli_exec $cli1(fd) $_config_cmd1} result] {
        error $result $errorInfo
    }
    append config_cmds $_config_cmd1
}
if {[info exists _config_cmd2]} {
    if [catch {cli_exec $cli1(fd) $_config_cmd2} result] {
        error $result $errorInfo
    }
    append config_cmds "\n"
    append config_cmds $_config_cmd2
}
if [catch {cli_exec $cli1(fd) "end"} result] {
    error $result $errorInfo
}
if [catch {cli_close $cli1(fd) $cli1(tty_id)} result] {
    error $result $errorInfo
}
after 60000
# 3. send the notification email
set routername [info hostname]
if {[string match "" $routername]} {
    error "Host name is not configured"
}
if [catch {smtp_subst [file join $tcl_library

email_template_cfg.tm]} result] {
    error $result $errorInfo
}
if [catch {smtp_send_email $result} result] {
    error $result $errorInfo
}

r2#


r2#show event manager policy available detailed

tm_cli_cmd.tcl
::cisco::eem::event_register_timer cron name crontimer2

cron_entry $_cron_entry maxrun 240
#----------------------------------
# EEM policy that will periodically execute a cli command

and email the
# results to a user.
#
# July 2005, Cisco EEM team
#
# Copyright (c) 2005-2006 by cisco Systems, Inc.
# All rights reserved.
#----------------------------------
### The following EEM environment variables are used:
###
### _cron_entry (mandatory)            - A CRON

specification that determines
###                                      when the policy

will run. See the
###                      IOS Embedded Event Manager
###                                      documentation for

more information
###                      on how to specify a cron entry.
### Example: _cron_entry                 0-59/1 0-23/1 * *

0-7
###
### _log_file (mandatory without _email_....)
###                                    - A filename to

append the output to.
###                                      If this variable is

defined, the
###                                      output is appended

to the specified
###                      file with a timestamp added.
### Example: _log_file                   disk0:/my_file.log
###
### _email_server (mandatory without _log_file)
###                                    - A Simple Mail

Transfer Protocol (SMTP)
###                                      mail server used to

send e-mail.
### Example: _email_server              

mailserver.customer.com
###
### _email_from (mandatory without _log_file)
###                                    - The address from

which e-mail is sent.
### Example: _email_from                

devtest@customer.com
###
### _email_to (mandatory without _log_file)
###                    - The address to which e-mail is

sent.
### Example: _email_to                  

engineering@customer.com
###
### _email_cc (optional)               - The address to

which the e-mail must
###                                      be copied.
### Example: _email_cc                  

manager@customer.com
###
### _show_cmd (mandatory)              - The CLI command to

be executed when
###                                      the policy is run.
### Example: _show_cmd                   show version
###
# check if all the env variables we need exist
# If any of them doesn't exist, print out an error msg and

quit
if {![info exists _log_file]} {
    if {![info exists _email_server]} {
        set result \
                "Policy cannot be run: variable _log_file or

_email_server has not been set"
        error $result $errorInfo
    }
    if {![info exists _email_from]} {
        set result \
                "Policy cannot be run: variable _log_file or

_email_from has not been set"
        error $result $errorInfo
    }
    if {![info exists _email_to]} {
        set result \
                "Policy cannot be run: variabl _log_file ore

_email_to has not been set"
        error $result $errorInfo
    }
    if {![info exists _email_cc]} {
        #_email_cc is an option, must set to empty string if

not set.
        set _email_cc ""
    }
}
if {![info exists _show_cmd]} {
    set result \
        "Policy cannot be run: variable _show_cmd has not

been set"
    error $result $errorInfo
}
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
#query the event info and log a message
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
}
global timer_type timer_time_sec
set timer_type $arr_einfo(timer_type)
set timer_time_sec $arr_einfo(timer_time_sec)
set routername [info hostname]
#log a message
set msg [format "timer event: timer type %s, time expired

%s" \
        $timer_type [clock format $timer_time_sec]]
action_syslog priority info msg $msg
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
}
# 1. execute the command
if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}
if [catch {cli_exec $cli1(fd) "en"} result] {
    error $result $errorInfo
}
# save exact execution time for command
set time_now [clock seconds]
# execute command
if [catch {cli_exec $cli1(fd) $_show_cmd} result] {
    error $result $errorInfo
} else {
    set cmd_output $result
    # format output: remove trailing router prompt
    set prompt [format

"(.*\n)(%s)(\\(config\[^\n\]*\\))?(#|>)" $routername]
    if [regexp "[set prompt]" $result dummy cmd_output] {
       # do nothing, match will be in $cmd_output
    } else {
       # did not match router prompt so use original output
       set cmd_output $result
    }
}
if [catch {cli_close $cli1(fd) $cli1(tty_id)} result] {
    error $result $errorInfo
}

# 2. log the success of the CLI command
set msg [format "Command \"%s\" executed successfully"

$_show_cmd]
action_syslog priority info msg $msg
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
}
# 3. if _log_file is defined, then attach it to the file
if {[info exists _log_file]} {
    # attach output to file
    if [catch {open $_log_file a+} result] {
        error $result
    }
    set fileD $result
    # save timestamp of command execution
    #      (Format = 00:53:44 PDT Mon May 02 2005)
    set time_now [clock format $time_now -format "%T %Z %a

%b %d %Y"]
    puts $fileD "%%% Timestamp = $time_now"
    puts $fileD $cmd_output
    close $fileD
}
# 4. if _email_server is defined send the email out
if {[info exists _email_server]} {
    if {[string match "" $routername]} {
        error "Host name is not configured"
    }
    if [catch {smtp_subst [file join $tcl_library

email_template_cmd.tm]} \
            result] {
        error $result $errorInfo
    }
    if [catch {smtp_send_email $result} result] {
        error $result $errorInfo
    }
}

r2#

No comments:

Post a Comment