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 learned during my CCIE studies, type in a text editor then copy/paste on the CLI.
This approach make easier to spot typos, faster to reuse configuration snippets and to change portions of configuration.
Then comes the 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 to be performed through the web interface.
In this post I'll show you how I automated some configurations on WLC's CLI with these rules in mind:
- respect Pareto principle
- do not use a cannon to kill a mosquito
- acceptable learning curve
- code reusability, readability and portability
Script all the things!
Among the common tasks I usually do on a Cisco WLC are:
- rename an AP
- set the 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:
1config paging disable
2show ap summary
Then copy and paste the output 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 to the spreadsheet 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 from the spreadsheet to a text file named aplist.txt, values should be separated by a space or a comma.
Your file should look like something like this:
1AP54a2.7469.6316 AP01
2AP54a2.8458.4666 AP02
3AP54a2.c346.9837 AP03 2.5
4AP54a2.7646.3339 AP04 2.5
5AP54a2.3015.5053 AP05 2.5
6AP54a2.0336.9286 AP06 2.5
7AP54a2.4517.995a AP07 2.5
8AP54a2.1000.8907 AP08 2.5
9AP54a2.5344.3444 AP09 5
10AP54a2.6856.2293 AP10 5
First script: rename APs
Now use the text editor to create a file named wlc_rename_ap.awk with this commands:
1# RENAME ACCESS POINTS
2# $1 = old name
3# $2 = new name
4{print "config ap name ",$2," ",$1}
Now run:
1awk -f wlc_rename_ap.awk aplist.txt
The expected output is the list of commands for the WLC CLI to rename the access-points:
1config ap name AP01 AP54a2.7469.6316
2config ap name AP02 AP54a2.8458.4666
3config ap name AP03 AP54a2.c346.9837
4config ap name AP04 AP54a2.7646.3339
5config ap name AP05 AP54a2.3015.5053
6config ap name AP06 AP54a2.0336.9286
7config ap name AP07 AP54a2.4517.995a
8config ap name AP08 AP54a2.1000.8907
9config ap name AP09 AP54a2.5344.3444
10config ap name AP10 AP54a2.6856.2293
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 antennas.
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:
|
|
The if statement in line 5 runs the print commands only if the antenna gain is set.
The print commands in lins 8 and 11 prints twice the value of the gain, because in the WLC configuration the gain is in steps of 0,5dBi.
Check the output:
1config 802.11b disable AP03
2config 802.11b antenna extAntGain 5
3config 802.11b enable AP03
4config 802.11a disable AP03
5config 802.11a antenna extAntGain 5
6config 802.11a enable AP03
7config 802.11b disable AP04
8config 802.11b antenna extAntGain 5
9config 802.11b enable AP04
10config 802.11a disable AP04
11config 802.11a antenna extAntGain 5
12config 802.11a enable AP04
13config 802.11b disable AP05
14config 802.11b antenna extAntGain 5
15config 802.11b enable AP05
16config 802.11a disable AP05
17config 802.11a antenna extAntGain 5
18config 802.11a enable AP05
19config 802.11b disable AP06
20config 802.11b antenna extAntGain 5
21config 802.11b enable AP06
22config 802.11a disable AP06
23config 802.11a antenna extAntGain 5
24config 802.11a enable AP06
25config 802.11b disable AP07
26config 802.11b antenna extAntGain 5
27config 802.11b enable AP07
28config 802.11a disable AP07
29config 802.11a antenna extAntGain 5
30config 802.11a enable AP07
31config 802.11b disable AP08
32config 802.11b antenna extAntGain 5
33config 802.11b enable AP08
34config 802.11a disable AP08
35config 802.11a antenna extAntGain 5
36config 802.11a enable AP08
37config 802.11b disable AP09
38config 802.11b antenna extAntGain 10
39config 802.11b enable AP09
40config 802.11a disable AP09
41config 802.11a antenna extAntGain 10
42config 802.11a enable AP09
43config 802.11b disable AP10
44config 802.11b antenna extAntGain 10
45config 802.11b enable AP10
46config 802.11a disable AP10
47config 802.11a antenna extAntGain 10
48config 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 show some examples about how to reduce number of the mouse clicks, avoid typing errors and save time with some simple scritps.
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.