switch & swith -globe question

Hello,

I could not manage to work this irule. Please help me to make it run.

Thanks

Lilly

=============================

**************

**************

**************

when CLIENT_DATA {

set pay1 [TCP::payload 8]

binary scan $pay1 IA4 len1 trx1

switch [IP::addr [IP::client_addr]]{

“x.x.x.x/24”{

switch -glob [class match $trx1 ] {

“A”{

do smthng}

}

“B” {

do something

}

“C” {

do something

}

default {

do something

}

}

}

“y.y.y.y/24”{

switch -glob [class match $trx1 ] {

“D”{

do something

}

“E” {

do something

}

“F” {

do something

}

default {

do something

}

}

}

}

}

=============================

Hi LillyM,

You cannot switch an IP::addr command the way that you were doing it. See this conversation switch statement, [IP::addr], and varying subnet masks.

The class command (class match $trx1), works with Data Groups. The $trx1, is the variable set in your binary scan. So you can switch off of it, but not perform a class match against it.

Try something like this and let us know if it works for you:

when CLIENT_DATA {
set pay1 [TCP::payload 8]
binary scan $pay1 IA4 len1 trx1

if { [IP::addr [IP::client_addr] equals "x.x.x.x/24" ] } {
switch -glob [ $trx1 ] {
"A" { do something }
"B" { do something }
"C" { do something }
default { do something else }
}
}
elseif { [IP::addr [IP::client_addr] equals "y.y.y.y/24" ] } {
switch -glob [ $trx1 ] {
"D" { do something }
"E" { do something }
"F" { do something }
default { do something else }
}
}
}

Hope this helps!

Hi Micheal,

It gave some error, I am trying to figure them out. If I could, then I will let you know in a few minutes.

Otherwise, I will send you the error and the code that I modified.

Million thanks

Lilly

Hi again Micheal,

I am taking the following error for these lines: " switch -glob [$trx1] {"

[invalid list: list element in quotes followed by “{” instead of space] []

I will appreciate it if you could help on this too..

Thanks

Lilly

=============================================================

when CLIENT_DATA {

set pay1 [TCP::payload 8]

binary scan $pay1 IA4 len1 trx1

if { [IP::addr [IP::client_addr] equals X.X.X.X/24]}{

switch -glob [$trx1] {

“A”{

do something

}

“B” {

do something

}

“C” {

do something

}

default {

do something else

}

}

}

if { [IP::addr [IP::client_addr] equals Y.Y.Y.Y/24]}{

switch -glob [$trx1] {

“D”{

do something

}

“E” {

do something

}

“F” {

do something

}

default {

do something else

}

}

}

}

=============================================================

You should investigate your binary scan command and possibly log the value to your LTM Log to see what you are getting.

TCL Reference Manual: binary

4 character ascii command and no problem in it. It seems to me that it is related with switch -globe command and the error also says like this.

Why do you think it is about binary scan?

Thanks

Can you post the error that it is logging?

I cannot even load and save this IRULE, I got the following error:

[invalid list: list element in quotes followed by “{” instead of space] []

Thanks

Lilly

You should just need to remove the square braces from the switch string:

when CLIENT_DATA {
set pay1 [TCP::payload 8]
binary scan $pay1 IA4 len1 trx1

if { [IP::addr [IP::client_addr] equals "x.x.x.x/24" ] } {
switch -glob $trx1 {
"A" { do something }
"B" { do something }
"C" { do something }
default { do something else }
}
}
elseif { [IP::addr [IP::client_addr] equals "y.y.y.y/24" ] } {
switch -glob $trx1 {
"D" { do something }
"E" { do something }
"F" { do something }
default { do something else }
}
}
}

Aaron

I would have thought that the square brackets could have caused that problem.

Learn something new all the time.

Can you let us know if Hoolio’s suggestion works?

Hello All,

Firstly I want to thank you for your help and suggestions. In that case (the last one ,Hoolio’s suggestion I meant) I only compare the $trx with some strings A, B,C etc.

But What I really want to do is, comparing with the content of an external file Like "class match $trx1"does.

Is this possible?

Thanks a lot..

Hello Hoolio,

Although this is not the exact equivalent what I want to do, I tried to modified my ırule like this. It is also is not working. I gave the following error:“01070151:3: Rule [IRule error: line 22: [invalid list: list element in quotes followed by “{” instead of space] []”

line 22 => switch -glob $trx1 {

thank you for your help.

Hello,

I read many things in the forums and now I am more confused:)

I want to make my question clear, and waiting for your help as soon as possible. I need to give my irule cpu comparison report today..

Million thanks for your help in advance

---Firstly, I am doing all the following items with IF claues in prod enviroment without any problem but we want to make cpu utilization & and if it is possible we want to use switch clause.

* I have 4- 5 Ip ranges, and I need to decide which external group files will be chose.

* I have many external data group files. They all have many string values inside.

* I need to check $trx1 value, with these string values those inside the external datagroup files

* I could do this with IF statement but it comsumes so much CPU

* Thats why I am trying to using SWITCH clause instead of IF clause

Example:

If ip is in the x.x.x.x/24 ip range

If $trx1 in the A external datagroup file - do something

If $trx1 in the B external datagroup file- do something

If $trx1 in the C external datagroup file- do something

else- do something else

If ip is in the y.y.y.y/24 ip range

If $trx1 in the D external datagroup file - do something

If $trx1 in the E external datagroup file - do something

If $trx1 in the F external datagroup file - do something

else - do something else

else

do something - go to default pool

Hamish replied here:

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

Aaron