AWK and Cisco WLC

When you see an hacker movie you see people typing on the keyboard very fast. Actually the toughest the hacker is the faster he types very long commands and all of them work the first time.

Want to impress friends and colleagues? Type on the hackertyper ;-)

More experienced network engineers, as I learn during my CCIE studies, type in a [text language=“editor”][/text]2 then copy/paste on the CLI.

This approach make easier to spot typos, faster to reuse configuration snippets and to change portions of configuration and more.

Then comes Cisco WLC.

Do not misunderstand me, I really like the product and after many installations I really appreciate it’s reliability and features.

What I don’t like are repetitive tasks and web interface.

In this post I’ll show you how I automate some configurations on WLC’s CLI with these rules in mind:

Script all the things!

Among the common tasks we usually do on Cisco WLC are:

  • rename AP
  • set AP antenna gain
  • enable Flexconnect and VLAN support

I’ll show these examples, the scripts are easily customizable for any other platform and task.

Choose the right tool

There are many scripting tools available, my choice for this particular use is AWK.

If you know something better just send me a note but keep in mind the rules above.

The scripts

Get the data

Let’s start with the most repetitive task when a WLC is first installed: rename APs.

Usually I do this after all the APs are connected and joined the controller. Get the AP list from the WLC CLI whit these commands:

config paging disable
show ap summary

Then copy and paste on your favorite spreadsheet.

You see all the APs have a name like APxxxx.xxxx.xxxx where xxxx.xxxx.xxxx is the MAC address.

Set parameters

Now add a second column and type the AP name you want to set according to the naming convention in use.

If you use external antennas add a third column with the correct gain in dBi.

Now export the data in a file named aplist.txt values should be separated by a space.

Your file should look like something like this:

AP54a2.7469.6316 AP01
AP54a2.8458.4666 AP02
AP54a2.c346.9837 AP03 2.5
AP54a2.7646.3339 AP04 2.5
AP54a2.3015.5053 AP05 2.5
AP54a2.0336.9286 AP06 2.5
AP54a2.4517.995a AP07 2.5
AP54a2.1000.8907 AP08 2.5
AP54a2.5344.3444 AP09 5
AP54a2.6856.2293 AP10 5

First script: rename APs

Create a file named wlc_rename_ap.awk with this commands:

# RENAME ACCESS POINTS
# $1 = old name
# $2 = new name
{print "config ap name ",$2," ",$1}

Now run:

cat aplist.txt | awk -f wlc_rename_ap.awk

The expected output:

config ap name  AP01   AP54a2.7469.6316
config ap name  AP02   AP54a2.8458.4666
config ap name  AP03   AP54a2.c346.9837
config ap name  AP04   AP54a2.7646.3339
config ap name  AP05   AP54a2.3015.5053
config ap name  AP06   AP54a2.0336.9286
config ap name  AP07   AP54a2.4517.995a
config ap name  AP08   AP54a2.1000.8907
config ap name  AP09   AP54a2.5344.3444
config ap name  AP10   AP54a2.6856.2293

Good! Now just copy/paste on WLC’s CLI and all the APs will have the correct name.

Second script: set AP antenna gain

When the antenna gain is set the value to put is the double of the actual value:

Notice also in aplist.txt not all APs have antenna gain set, some have internal antenna.

I set the same gain for both 802.11b and 802.11a radios because in my case I use dual-band antennas.

Let’s see the script:

# RENAME ACCESS POINTS
# $1 = old name
# $2 = new name
# $3 =  actual antenna gain
{if ($3)
{
print "config 802.11b disable "$2;
print "config 802.11b antenna extAntGain "$3*2;
print "config 802.11b enable "$2;
print "config 802.11a disable "$2;
print "config 802.11a antenna extAntGain "$3*2;
print "config 802.11a enable "$2;
}}

The if statement runs the print commands only if the antenna gain is specified.

The second print command prints twice the value of the gain.

Check the output:

config 802.11b disable AP03
config 802.11b antenna extAntGain 5
config 802.11b enable AP03
config 802.11a disable AP03
config 802.11a antenna extAntGain 5
config 802.11a enable AP03
config 802.11b disable AP04
config 802.11b antenna extAntGain 5
config 802.11b enable AP04
config 802.11a disable AP04
config 802.11a antenna extAntGain 5
config 802.11a enable AP04
config 802.11b disable AP05
config 802.11b antenna extAntGain 5
config 802.11b enable AP05
config 802.11a disable AP05
config 802.11a antenna extAntGain 5
config 802.11a enable AP05
config 802.11b disable AP06
config 802.11b antenna extAntGain 5
config 802.11b enable AP06
config 802.11a disable AP06
config 802.11a antenna extAntGain 5
config 802.11a enable AP06
config 802.11b disable AP07
config 802.11b antenna extAntGain 5
config 802.11b enable AP07
config 802.11a disable AP07
config 802.11a antenna extAntGain 5
config 802.11a enable AP07
config 802.11b disable AP08
config 802.11b antenna extAntGain 5
config 802.11b enable AP08
config 802.11a disable AP08
config 802.11a antenna extAntGain 5
config 802.11a enable AP08
config 802.11b disable AP09
config 802.11b antenna extAntGain 10
config 802.11b enable AP09
config 802.11a disable AP09
config 802.11a antenna extAntGain 10
config 802.11a enable AP09
config 802.11b disable AP10
config 802.11b antenna extAntGain 10
config 802.11b enable AP10
config 802.11a disable AP10
config 802.11a antenna extAntGain 10
config 802.11a enable AP10

Looks good! APs AP01 and AP02 are not listed as expected, all the gain values are the double of the value in the file.

Third script: enable flexconnect and VLAN support

This is very simple, just some commands to disable the AP (required to enable FlexConnect), enable FlexConnect, VLAN support an enable the AP again:

# ENABLE FLEXCONNECT AND VLAN SUPPORT ON AP
# $2 = new name
{
print "config ap disable "$2;
print "config ap mode flexconnect "$2;
print "config ap flexconnect vlan enable "$2;
print "config ap enable "$2
}

The output:

config ap disable AP01
config ap mode flexconnect AP01
config ap flexconnect vlan enable AP01
config ap enable AP01
config ap disable AP02
config ap mode flexconnect AP02
config ap flexconnect vlan enable AP02
config ap enable AP02
config ap disable AP03
config ap mode flexconnect AP03
config ap flexconnect vlan enable AP03
config ap enable AP03
config ap disable AP04
config ap mode flexconnect AP04
config ap flexconnect vlan enable AP04
config ap enable AP04
config ap disable AP05
config ap mode flexconnect AP05
config ap flexconnect vlan enable AP05
config ap enable AP05
config ap disable AP06
config ap mode flexconnect AP06
config ap flexconnect vlan enable AP06
config ap enable AP06
config ap disable AP07
config ap mode flexconnect AP07
config ap flexconnect vlan enable AP07
config ap enable AP07
config ap disable AP08
config ap mode flexconnect AP08
config ap flexconnect vlan enable AP08
config ap enable AP08
config ap disable AP09
config ap mode flexconnect AP09
config ap flexconnect vlan enable AP09
config ap enable AP09
config ap disable AP10
config ap mode flexconnect AP10
config ap flexconnect vlan enable AP10
config ap enable AP10

Wrap up

In this post I showed how to reduce the mouse clicks, avoid typing errors and save time.

AWK is a very powerful tool, I just scratched the surface but as a network engineer I don’t want to master it, I just want to be able to use it at my own advantage in the most efficient way.

I hope you enjoyed this post, please share it if you find it useful and feel free to comment if you find errors or want to add you point of view.

Awk tutorial on grymoire.com

The GNU Awk User’s Guide

 
comments powered by Disqus