Forum Discussion
William_Benett1
Nimbostratus
Mar 28, 2007TCL capabilities in iRules
So i'm working on an iRule that will require me to do bitwise math in order to determine if the port number is odd or even. I believe I looked up the operator (&) but the iRuler gives me a syntax err...
William_Benett1
Nimbostratus
Mar 29, 2007Okay, so sides stepping the TCL knowledge stuff, I don't think I have a method to do what I want to do with my iRule.
when RULE_INIT {
set ::currentserver 1
}
when CLIENT_ACCEPTED {
switch -glob [TCP::local_port] {
49* { if {[TCP::local_port] > 49151 && 49250 > [TCP::local_port]} {
if { [expr [TCP::local_port] & 1] } {
odd port section:
TCP::collect
} else {
even port section: use src based persistence only
if {$::currentserver eq 1} {
if {[LB::status node 10.10.4.150] eq "down"} {
set ::currentserver 0
node 10.10.4.154
persist source_addr 300
} else {
set ::currentserver 0
node 10.10.4.150
persist source_addr 300
}
} else {
if {[LB::status node 10.10.4.154] eq "down"} {
set ::currentserver 1
node 10.10.4.150
persist source_addr 300
} else {
set ::currentserver 1
node 10.10.4.154
persist source_addr 300
}
}
}
}
}
default { discard }
}
}
when LB_FAILED {
if {$::currentserver eq 1} {
if {[LB::status node 10.10.4.150] eq "down"} {
set ::currentserver 0
set ::lbserver [session lookup source_addr [IP::client_addr]]
log local0. "server $::lbserver"
node 10.10.4.154
TCP::release
} else {
set ::currentserver 0
node 10.10.4.150
set ::lbserver [session lookup source_addr [IP::client_addr]]
log local0. "server $::lbserver"
TCP::release
}
}
if {$::currentserver eq 0} {
if {[LB::status node 10.10.4.154] eq "down"} {
set ::currentserver 1
node 10.10.4.150
set ::lbserver [session lookup source_addr [IP::client_addr]]
log local0. "server $::lbserver"
TCP::release
} else {
set ::currentserver 1
node 10.10.4.154
set ::lbserver [session lookup source_addr [IP::client_addr]]
log local0. "server $::lbserver"
TCP::release
}
}
}The idea behind the irule is this: the application I'm load balancing for listens on around 100 ports. The client makes a connection on an even numbered port, then it connects on the next highest port. After that it sends some data on the 1st connection, but never on the second connection. I can't think of any good reason to design an application like this, but I digress. I have to send the 2nd connection to the same server as 1st connection. The issue is that I can't use simple source address based persistence because I might get 20 different connections (on different ports) from the same source IP address. Doing so would mean that load would be uneven, because one IP address could connect 20 times, while another connected 4 times and one server would have 20 connections and the other server 4. I should add, this iRule runs on a wildcard virtual server, so it isn't bound to a particular port.
The way i'm trying to make this work is by detecting the 1st connection (since I know it will be on an even numbered port) and using simple source based persistence for that connection. Then i'm hoping to delay load balancing selection on the 2nd connection (which I can detect because it is always odd and +1 to the 1st connection's dest port) so that I can lookup the persistence table entry for the 1st connection and then load balance the 2nd connection to the same server.
It seems as though I cannot perform persistence table lookups from LB_FAILED or NAME_RESOLVED. Trying to do this in LB_FAILED is something of a lark. I figured that if i could perform a dummy DNS lookup (using NAME::lookup) I could make my decision when the DNS query failed.
There was a thread that I found on this board that indicated that I couldn't set persistence while in the CLIENT_ACCEPTED event. If that's the case, is there a good event I can try and do this in? Thanks in advance.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects