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 } }

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 } 
    }
}

http://www.tcl.tk/man/tcl8.4/TclCmd/switch.htmM8

Thank you!

Can you do the same with a datagroup or is that only a 1:1 mapping?

Just curious, but why do you prefer a possible data group solution?

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.

Supportability, operations knows how to edit a data group. They don’t have access to edit an iRule.