Forum Discussion
iRule with switch
I have an application that needs to be routed based on the incoming port . They have 5 different pools each with 25 ports. I'm thinking 1 VS with all ports open and then using an iRule to control the pool selection. I've found a lot of examples with 3-4 ports or a single port range but none with 125 ports in 5 different ranges. I'm looking at either a switch or a data group. Can you use a range in a switch? Can you use a range in a datagroup or does it have to be an exact match?
I'm sure my syntax is wrong but something like this:
when CLIENT_ACCEPTED { switch [TCP::local_port] { 10000-10024 { pool pool-site1 } 10025-10049 { pool pool-site2 } 10050-10074 { pool pool-site3 } default { pool default_pool } }
- leonline_225556Altostratus
Hi LeaV97,
Using the regexp argument with the switch command you can easily match on numeric ranges. The following iRule will probably help you.
when CLIENT_ACCEPTED { switch -regexp [TCP::local_port] { [10000-10024] { pool pool-site1 } [10025-10049] { pool pool-site2 } [10050-10074] { pool pool-site3 } default { pool default_pool } } }
- LeaV97_339056Nimbostratus
Thank you!
Can you do the same with a datagroup or is that only a 1:1 mapping?
- JGCumulonimbus
Just curious, but why do you prefer a possible data group solution?
- Stanislas_Piro2Cumulonimbus
you can also use this:
set port [TCP::local_port] switch 1 \ [expr {$port>=10000 && $port<10025}] {pool pool-site1} \ [expr {$port>=10025 && $port<10050}] {pool pool-site2} \ [expr {$port>=10050 && $port<10075}] {pool pool-site3} \ default {pool default_pool}
Make sure you let 1 in switch value, each expression is evaluated and the result is compared with 1 until one success.
This switch command can't have curly brackets because of expression evaluation, that's why the \ is mandatory at the end of each line but the last.
- LeaV97_339056Nimbostratus
Supportability, operations knows how to edit a data group. They don't have access to edit an iRule.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com