Tuesday, July 29, 2008

Switch Macros

Take a look at this examples of Switch Macros  available at the Switching Video-on-Demand from IPExpert, just a few, but, the possibilities for it are huge!

First one... Create a Macro to configure our "Access-Ports", this will include the VLAN, Portfast, BPDUGuard and Storm-Control... Seens simple... but how the assign the correct VLAN to each port?! Using variables!  Take a look:

macro name Port
switchport mode access
switchport access vlan $V
spanning-tree portfast
spanning-tree bpduguard enable
storm-control $T level $L

Now,  apply this to port FastEthernet 0/10 for example, and assign it to VLAN 10, Storm-Control Type Broadcast and Level 20:

int fa0/10
macro trace Port $V 10 $T broadcast $L 20

See?! Easy! One line, instead of 5!

In the show run, the field macro description Port | Port will show us how many times this macro "Port" (the one we created earlier) was applied to this interface (in this specific case, 2 times!).

Macro Example

Another example, a macro to create some VLANs:

macro name MakeVlan
vlan 101
name My101
vlan 102
name My102
name My103

Just be careful, after the last VLAN (in our case vlan103) we need to type exit, if you don´t, this VLAN will not be created!

We can double check if everything is ok with the command: sh vlan brief

Another tip in this Video is if you get asked to assign a data VLAN, Voice VLAN and Portsecure allowing 2 Mac-Addresses in this port using just one command line (I talked briefly about it yesterday), how to do it?!

Seens a bit strange, but possible, first, check the Macros "pre-defined" in your switch using the command: show parser macro , your output will look much similar to this one:

Show Parser Macro Example

Now that we found our macro, apply it to the desired interface:

int f0/16
macro apply cisco-phone $access_vlan 10 $voice_vlan 20

And finally, take a look at the configuration:

Macro Apply

You may ask yourself, how the proctor is going to grade that?! How he´s going to know that I actually used a Macro, or even better, how he´s going to know that I didn´t created a Macro to do it, and just deleted from the Switch after that?!

Well... the answer is simple... first, take a look at the line: macro description cisco-phone this description is telling us that this specific macro (cisco-phone in this case) was applied to this interface. Also, the macro configured the VLANs (Data and Voice) and Portsecure as asked, but it also configured some extra stuff (QoS, Portfast, etc), and that tells the Proctor that you actually used this macro! So, be cool, just understand exactly what the question is asking, and you´ll be fine!

To apply a macro we can use the commands:

  • macro apply <macro-name>
  • macro trace <macro-name> -> if you want to see it going through the commands.
  • macro global apply <macro-name>
  • macro global trace <macro-name> -> if you want to see it going through the commands.

No comments: