Configuring SmartPort Macros
This chapter describes how to configure and apply SmartPort macros on the Catalyst 3750 switch.
Note For complete syntax and usage information for the commands used in this chapter, refer to the command reference for this release.
This chapter consists of these sections:
•Understanding SmartPort Macros
•Configuring SmartPort Macros
•Displaying SmartPort Macros
Understanding SmartPort Macros
SmartPort macros provide a convenient way to save and share common configurations. You can use SmartPort 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 SmartPort macro is a set of CLI commands that you define. SmartPort macros do not contain new CLI commands; they are simply a group of existing CLI commands.
When you apply a SmartPort 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 SmartPort macros embedded in the switch software. You can view these macros and the commands they contain by using the show parser macro user EXEC command.
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 SmartPort macros based on the usage of the port. You can use the configuration templates to create SmartPort macros to build and deploy Cisco-recommended network designs and configurations. For more information about Cisco-recommended configuration templates, refer to the release notes for this release.
Configuring SmartPort Macros
You can create a new SmartPort 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 to an interface or range of interfaces.
This section includes information about:
•Default SmartPort Macro Configuration
•SmartPort Macro Configuration Guidelines
•Creating and Applying SmartPort Macros
•Applying Cisco-default SmartPort Macros
Default SmartPort Macro Configuration
There are no SmartPort macros enabled.
SmartPort Macro Configuration Guidelines
Follow these guidelines when configuring macros on your switch:
•Do not use exit or end commands when creating a macro. This could cause commands that follow exit or end to execute in a different command mode.
•When creating a macro, all CLI commands should be interface configuration mode commands.
•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.
•Some CLI commands are specific to certain interface types. The macro will fail the syntax check or the configuration check, and the switch will return an error message if it is applied to an interface that does not accept the configuration.
•When a macro is applied to an interface, all existing configuration on the interface is retained. This is helpful when applying an incremental configuration to an interface.
•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 trace macro-name interface configuration command to apply and show the macros running on an interface or to debug the macro to find any syntax or configuration errors.
•When you apply a macro to an interface, the macro name is automatically added to the interface. You can view the applied commands and macro names by using the show running-config interface interface-id user EXEC command.
•If a command fails because of a syntax error or a configuration error, the macro continues to apply the remaining commands to the interface.
•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.
There are Cisco-default SmartPort macros embedded in the switch software. You can view 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 SmartPort macro on an interface:
•View all macros on the switch by using the show parser macro user EXEC command. View the contents of a specific macro by using the show parser macro macro-name user EXEC command.
•Keywords that begin with $ designate that a unique parameter value is required. Append the Cisco-default macro with the required values by using the parameter value keywords.
Creating and Applying SmartPort Macros
Beginning in privileged EXEC mode, follow these steps to create and apply a SmartPort macro:
|
|
|
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. We recommend that you do not use the exit or end commands in a macro. This could cause any commands following exit or end to execute in a different command mode. For best results, all commands in a macro should be interface configuration mode commands. |
Step 3 |
interface interface-id |
Enter interface configuration mode, and specify the interface on which to apply the macro. |
Step 4 |
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 print each command before it is applied to the interface. (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. |
Step 5 |
macro description text |
(Optional) Enter a description about the macro that is applied to the interface. |
Step 6 |
end |
Return to privileged EXEC mode. |
Step 7 |
show parser macro |
Verify that the macro was created. |
Step 8 |
show running-config interface interface-id |
Verify that the macro is applied to an interface. |
Step 9 |
copy running-config startup-config |
(Optional) Save your entries in the configuration file. |
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. You can delete a macro-applied configuration on an interface by entering the default interface interface-id interface configuration command. Alternatively, you can create an anti-macro for an existing macro that contains the no form of all the corresponding commands in the original macro. Then apply the anti-macro to the interface.
This example shows how to define the desktop-config macro for an access switch interface, apply the macro, add a description to the interface, and verify the configuration.
Switch(config)# macro name desktop-config
# Put the switch in access mode
# Allow port to move to forwarding state quickly
# BPDUs should not be sent into the network
spanning-tree bpduguard enable
# Restrict the port to one address -- that of desktop
switchport port-security maximum 1
# Put all data traffic in vlan 1
Switch(config)# interface gigabitethernet1/0/2
Switch(config-if)# macro apply desktop-config
Switch(config-if)# macro description desktop-config
Switch# show parser macro name desktop-config
Macro name : desktop-config
Macro type : customizable
macro description desktop-config
# Put the switch in access mode
# Allow port to move to forwarding state quickly
# BPDUs should not be sent into the network
spanning-tree bpduguard enable
# Restrict the port to one address -- that of desktop
switchport port-security maximum 1
# Put all data traffic in vlan 1
Switch# show parser macro description
Interface Macro Description
--------------------------------------------------------------
--------------------------------------------------------------
This example shows how to apply the desktop-config macro and replace all occurrences of VLAN 1 with VLAN 25:
Switch(config-if)# macro apply desktop-config vlan 25
Applying Cisco-default SmartPort Macros
Beginning in privileged EXEC mode, follow these steps to modify and apply a SmartPort macro:
|
|
|
Step 1 |
show parser macro |
View the Cisco-default SmartPort macros embedded in the switch software. |
Step 2 |
show parser macro macro-name |
View the specific macro that you want to apply. |
Step 3 |
configure terminal |
Enter global configuration mode. |
Step 4 |
interface interface-id |
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}] |
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 $ designate that a unique parameter value is required. |
Step 7 |
end |
Return to privileged EXEC mode. |
Step 8 |
show running-config interface interface-id |
Verify that the macro is applied to an interface. |
Step 9 |
copy running-config startup-config |
(Optional) Save your entries in the configuration file. |
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 view the cisco-desktop macro and how to apply the macro and set the access VLAN ID to 25 on an interface:
Switch# show parser macro cisco-desktop
--------------------------------------------------------------
Macro name : cisco-desktop
# Basic interface - Enable data VLAN only
# Recommended value for access vlan (AVID) should not be 1
switchport access vlan $AVID
# Enable port security limiting port to a single
# MAC address -- that of desktop
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 bpduguard enable
--------------------------------------------------------------
Switch# configure terminal
Switch(config)# gigabitethernet1/0/4
Switch(config-if)# macro apply cisco-desktop $AVID 25
Displaying SmartPort Macros
To display the SmartPort macros, use one or more of the privileged EXEC commands in Table 12-1.
Table 12-1 Commands for Displaying SmartPort Macros
|
|
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. |