What could you do with your code in 20 Lines or Less? That's the question I like to ask for the DevCentral community, and every time I go looking to find cool new examples that show just how flexible and powerful iRules can be without getting in over your head.

All switch, all the time. This installment of the 20 Lines or Less (20LoL) is made possible by our friend the switch command (and hoolio). It just so happens that in digging through the forums this week I've found a trio of tasty tech tricks that all revolve around the use of a switch statement within iRules. The switch command is powerful, efficient and flexible, so this comes as no real surprise to me, though I find it intriguing that three examples, each showing different functionality in the end, can all involve the same command, though to be fair two of them don't center specifically around the switch functionality itself.

 

Default Pool in a Switch Statement

https://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/2163372/showtab/groupforums/Default.aspx

To start things off this week, this example shows some good practices when using switch to make pool decisions, and I felt inclined to pass along the information and example. In this particular case the user was making the transition from an if statement to a switch, and ran into a bit of confusion. Aaron is able to set them straight with a brief demo of some basic switch usage, including a clever twist in the CLIENT_ACCEPTED event wherein he sets the default pool, making this iRule completely portable.