Configuring Smartports Macros


This chapter describes how to configure and apply Smartports macros on the Catalyst 2960 switch.


Note For complete syntax and usage information for the commands used in this chapter, see the command reference for this release.


This chapter consists of these sections:

Understanding Smartports Macros

Configuring Smartports Macros

Displaying Smartports Macros

Understanding Smartports Macros

Smartports macros provide a convenient way to save and share common configurations. You can use Smartports macros to enable features and settings based on the location of a switch in the network and for mass configuration deployments across the network.

Each Smartports macro is a set of command-line interface (CLI) commands that you define. Smartports macros do not contain new CLI commands; they are simply a group of existing CLI commands.

When you apply a Smartports macro on an interface, the CLI commands within the macro are configured on the interface. When the macro is applied to an interface, the existing interface configurations are not lost. The new commands are added to the interface and are saved in the running configuration file.

There are Cisco-default Smartports macros embedded in the switch software (see Table 11-1). You can display these macros and the commands they contain by using the show parser macro user EXEC command.

Table 11-1 Cisco-Default Smartports Macros 

Macro Name 1
Description

cisco-global

Use this global configuration macro to enable rapid PVST+, loop guard, and dynamic port error recovery for link state failures.

cisco-desktop

Use this interface configuration macro for increased network security and reliability when connecting a desktop device, such as a PC, to a switch port.

cisco-phone

Use this interface configuration macro when connecting a desktop device such as a PC with a Cisco IP Phone to a switch port. This macro is an extension of the cisco-desktop macro and provides the same security and resiliency features, but with the addition of dedicated voice VLANs to ensure proper treatment of delay-sensitive voice traffic.

cisco-switch

Use this interface configuration macro when connecting an access switch and a distribution switch or between access switches connected using small form-factor pluggable (SFP) modules.

cisco-router

Use this interface configuration macro when connecting the switch and a WAN router.

cisco-wireless

Use this interface configuration macro when connecting the switch and a wireless access point.

1 Cisco-default Smartports macros vary depending on the software version running on your switch.


Cisco also provides a collection of pretested, Cisco-recommended baseline configuration templates for Catalyst switches. The online reference guide templates provide the CLI commands that you can use to create Smartports macros based on the usage of the port. You can use the configuration templates to create Smartports macros to build and deploy Cisco-recommended network designs and configurations. For more information about Cisco-recommended configuration templates, see this Smartports website:

http://www.cisco.com/go/smartports

Configuring Smartports Macros

You can create a new Smartports macro or use an existing macro as a template to create a new macro that is specific to your application. After you create the macro, you can apply it globally to a switch or to a switch interface or range of interfaces.

These sections contain this configuration information:

Default Smartports Macro Configuration

Smartports Macro Configuration Guidelines

Creating Smartports Macros

Applying Smartports Macros

Applying Cisco-Default Smartports Macros

Default Smartports Macro Configuration

There are no Smartports macros enabled.

Smartports Macro Configuration Guidelines

Follow these guidelines when configuring macros on your switch:

When creating a macro, do not use the exit or end commands or change the command mode by using interface interface-id. This could cause commands that follow exit, end, or interface interface-id to execute in a different command mode.

When creating a macro, all CLI commands should be in the same configuration mode.

When creating a macro that requires the assignment of unique values, use the parameter value keywords to designate values specific to the interface. Keyword matching is case sensitive. All matching occurrences of the keyword are replaced with the corresponding value. Any full match of a keyword, even if it is part of a larger string, is considered a match and is replaced by the corresponding value.

Macro names are case sensitive. For example, the commands macro name Sample-Macro and macro name sample-macro will result in two separate macros.

Some macros might contain keywords that require a parameter value. You can use the macro global apply macro-name ? global configuration command or the macro apply macro-name ? interface configuration command to display a list of any required values in the macro. If you apply a macro without entering the keyword values, the commands are invalid and are not applied.

When a macro is applied globally to a switch or to a switch interface, all existing configuration on the interface is retained. This is helpful when applying an incremental configuration.

If you modify a macro definition by adding or deleting commands, the changes are not reflected on the interface where the original macro was applied. You need to reapply the updated macro on the interface to apply the new or changed commands.

You can use the macro global trace macro-name global configuration command or the macro trace macro-name interface configuration command to apply and debug a macro to find any syntax or configuration errors. If a command fails because of a syntax error or a configuration error, the macro continues to apply the remaining commands.

Some CLI commands are specific to certain interface types. If a macro is applied to an interface that does not accept the configuration, the macro will fail the syntax check or the configuration check, and the switch will return an error message.

Applying a macro to an interface range is the same as applying a macro to a single interface. When you use an interface range, the macro is applied sequentially to each interface within the range. If a macro command fails on one interface, it is still applied to the remaining interfaces.

When you apply a macro to a switch or a switch interface, the macro name is automatically added to the switch or interface. You can display the applied commands and macro names by using the show running-config user EXEC command.

There are Cisco-default Smartports macros embedded in the switch software (see Table 11-1). You can display these macros and the commands they contain by using the show parser macro user EXEC command.

Follow these guidelines when you apply a Cisco-default Smartports macro on an interface:

Display all macros on the switch by using the show parser macro user EXEC command. Display the contents of a specific macro by using the show parser macro macro-name user EXEC command.

Keywords that begin with $ mean that a unique parameter value is required. Append the Cisco-default macro with the required values by using the parameter value keywords.

The Cisco-default macros use the $ character to help identify required keywords. There is no restriction on using the $ character to define keywords when you create a macro.

Creating Smartports Macros

Beginning in privileged EXEC mode, follow these steps to create a Smartports macro:

 
Command
Purpose

Step 1 

configure terminal

Enter global configuration mode.

Step 2 

macro name macro-name

Create a macro definition, and enter a macro name. A macro definition can contain up to 3000 characters.

Enter the macro commands with one command per line. Use the @ character to end the macro. Use the # character at the beginning of a line to enter comment text within the macro.

(Optional) You can define keywords within a macro by using a help string to specify the keywords. Enter # macro keywords word to define the keywords that are available for use with the macro. Separated by a space, you can enter up to three help string keywords in a macro.

Macro names are case sensitive. For example, the commands macro name Sample-Macro and macro name sample-macro will result in two separate macros.

We recommend that you do not use the exit or end commands or change the command mode by using interface interface-id in a macro. This could cause any commands following exit, end, or interface interface-id to execute in a different command mode. For best results, all commands in a macro should be in the same configuration mode.

Step 3 

end

Return to privileged EXEC mode.

Step 4 

show parser macro name macro-name

Verify that the macro was created.

The no form of the macro name global configuration command only deletes the macro definition. It does not affect the configuration of those interfaces on which the macro is already applied.

This example shows how to create a macro that defines the switchport access VLAN and the number of secure MAC addresses and also includes two help string keywords by using # macro keywords:

Switch(config)# macro name test
switchport access vlan $VLANID
switchport port-security maximum $MAX
#macro keywords $VLANID $MAX
@

Applying Smartports Macros

Beginning in privileged EXEC mode, follow these steps to apply a Smartports macro:

 
Command
Purpose

Step 1 

configure terminal

Enter global configuration mode.

Step 2 

macro global {apply | trace} macro-name [parameter {value}] [parameter {value}] [parameter {value}]

Apply each individual command defined in the macro to the switch by entering macro global apply macro-name. Specify macro global trace macro-name to apply and debug a macro to find any syntax or configuration errors.

(Optional) Specify unique parameter values that are specific to the switch. You can enter up to three keyword-value pairs. Parameter keyword matching is case sensitive. All matching occurrences of the keyword are replaced with the corresponding value.

Some macros might contain keywords that require a parameter value. You can use the macro global apply macro-name ? command to display a list of any required values in the macro. If you apply a macro without entering the keyword values, the commands are invalid and are not applied.

Step 3 

macro global description text

(Optional) Enter a description about the macro that is applied to the switch.

Step 4 

interface interface-id

(Optional) Enter interface configuration mode, and specify the interface on which to apply the macro.

Step 5 

default interface interface-id

(Optional) Clear all configuration from the specified interface.

Step 6 

macro {apply | trace} macro-name [parameter {value}] [parameter {value}] [parameter {value}]

Apply each individual command defined in the macro to the interface by entering macro apply macro-name. Specify macro trace macro-name to apply and debug a macro to find any syntax or configuration errors.

(Optional) Specify unique parameter values that are specific to the interface. You can enter up to three keyword-value pairs. Parameter keyword matching is case sensitive. All matching occurrences of the keyword are replaced with the corresponding value.

Some macros might contain keywords that require a parameter value. You can use the macro apply macro-name ? command to display a list of any required values in the macro. If you apply a macro without entering the keyword values, the commands are invalid and are not applied.

Step 7 

macro description text

(Optional) Enter a description about the macro that is applied to the interface.

Step 8 

end

Return to privileged EXEC mode.

Step 9 

show parser macro description [interface interface-id]

Verify that the macro is applied to the interface.

Step 10 

copy running-config startup-config

(Optional) Save your entries in the configuration file.

You can delete a global macro-applied configuration on a switch only by entering the no version of each command that is in the macro. You can delete a macro-applied configuration on an interface by entering the default interface interface-id interface configuration command.

This example shows how to apply the user-created macro called snmp, to set the hostname address to test-server, and to set the IP precedence value to 7:

Switch(config)# macro global apply snmp ADDRESS test-server VALUE 7

This example shows how to debug the user-created macro called snmp by using the macro global trace global configuration command to find any syntax or configuration errors in the macro when it is applied to the switch.

Switch(config)# macro global trace snmp VALUE 7
Applying command...`snmp-server enable traps port-security'
Applying command...`snmp-server enable traps linkup'
Applying command...`snmp-server enable traps linkdown'
Applying command...`snmp-server host'
%Error Unknown error.
Applying command...`snmp-server ip precedence 7'

This example shows how to apply the user-created macro called desktop-config and to verify the configuration.

Switch(config)# interface gigabitethernet0/2
Switch(config-if)# macro apply desktop-config
Switch(config-if)# end
Switch# show parser macro description 
Interface    Macro Description
--------------------------------------------------------------
Gi0/2      desktop-config
--------------------------------------------------------------

This example shows how to apply the user-created macro called desktop-config and to replace all occurrences of VLAN 1 with VLAN 25:

Switch(config-if)# macro apply desktop-config vlan 25

Applying Cisco-Default Smartports Macros

Beginning in privileged EXEC mode, follow these steps to apply a Smartports macro:

 
Command
Purpose

Step 1 

show parser macro

Display the Cisco-default Smartports macros embedded in the switch software.

Step 2 

show parser macro macro-name

Display the specific macro that you want to apply.

Step 3 

configure terminal

Enter global configuration mode.

Step 4 

macro global {apply | trace} macro-name [parameter {value}] [parameter {value}] [parameter {value}]

Append the Cisco-default macro with the required values by using the parameter value keywords and apply the macro to the switch. Keywords that begin with $ mean that a unique parameter value is required.

You can use the macro global apply macro-name ? command to display a list of any required values in the macro. If you apply a macro without entering the keyword values, the commands are invalid and are not applied.

Step 5 

interface interface-id

(Optional) Enter interface configuration mode, and specify the interface on which to apply the macro.

Step 6 

default interface interface-id

(Optional) Clear all configuration from the specified interface.

Step 7 

macro {apply | trace} macro-name [parameter {value}] [parameter {value}] [parameter {value}]

Append the Cisco-default macro with the required values by using the parameter value keywords, and apply the macro to the interface. Keywords that begin with $ mean that a unique parameter value is required.

You can use the macro apply macro-name ? command to display a list of any required values in the macro. If you apply a macro without entering the keyword values, the commands are invalid and are not applied.

Step 8 

end

Return to privileged EXEC mode.

Step 9 

show running-config interface interface-id

Verify that the macro is applied to an interface.

Step 10 

copy running-config startup-config

(Optional) Save your entries in the configuration file.

You can delete a global macro-applied configuration on a switch only by entering the no version of each command that is in the macro. You can delete a macro-applied configuration on an interface by entering the default interface interface-id interface configuration command.

This example shows how to display the cisco-desktop macro, how to apply the macro, and to set the access VLAN ID to 25 on an interface:

Switch# show parser macro cisco-desktop
--------------------------------------------------------------
Macro name : cisco-desktop
Macro type : default

# Basic interface - Enable data VLAN only
# Recommended value for access vlan (AVID) should not be 1
switchport access vlan $AVID
switchport mode access

# Enable port security limiting port to a single
# MAC address -- that of desktop
switchport port-security
switchport port-security maximum 1

# Ensure port-security age is greater than one minute
# and use inactivity timer
switchport port-security violation restrict
switchport port-security aging time 2
switchport port-security aging type inactivity

# Configure port as an edge network port
spanning-tree portfast
spanning-tree bpduguard enable
--------------------------------------------------------------
Switch#
Switch# configure terminal
Switch(config)# gigabitethernet0/4
Switch(config-if)# macro apply cisco-desktop $AVID 25

Displaying Smartports Macros

To display the Smartports macros, use one or more of the privileged EXEC commands in Table 11-2.

Table 11-2 Commands for Displaying Smartports Macros 

Command
Purpose

show parser macro

Displays all configured macros.

show parser macro name macro-name

Displays a specific macro.

show parser macro brief

Displays the configured macro names.

show parser macro description [interface interface-id]

Displays the macro description for all interfaces or for a specified interface.