Forum Discussion
AppleBee_108607
Nov 02, 2010Historic F5 Account
CMP compatible strict Round Robin
Hi,
In addition to my another post, I have to urgently write an iRule to facilitate strict Round Robin event if the Virtual is CMPenabled.
I wrote code as follows but still have tw...
spark_86682
Nov 02, 2010Historic F5 Account
To answer your questions:
You can't access the session table in RULE_INIT or any other global event, that's true. However, don't forget that entries in the session table deliberately expire, so even if you could initialize them in RULE_INIT, they may be gone later, and your iRule has to cope with that (that's one reason there are so many variations on things like the set command). Fortunately, the table commands are written with that in mind as well, and tend to Do The Right Thing in the case where there is no existing entry. To give one example (that will become relevant shortly), if you do something like increment a key that doesn't exist, it automatically starts it as 0.
I don't think there is a way to explicitly say that a value is a string or a number; Tcl generally converts automatically when necessary. However, I can't see where you're running into this problem. Could you elaborate a bit?
Yes, to set variables in RULE_INIT, just use "set static::myvarname myvalue".
As for your round-robin iRule, I think that you're waaaaaay overthinking this. How about something like:
when CLIENT_ACCEPTED {
set poolname "test-pool"
if { [active_members $poolname] < 1 } {
No active pool members; reset client
reject
return
}
set count [members $poolname]
set attempt 0
while { $attempt < $count } {
set num [table incr "round-robin:$poolname"]
set num [expr $num % $count]
set mbr [lindex [members -list $poolname]]
set mbr_ip [lindex $mbr 0]
set mbr_port [lindex $mbr 1]
if { [LB::status pool $poolname member $mbr_ip $mbr_port up } {
pool $poolname member $mbr_ip $mbr_port
return
}
incr attempt
}
}
Again, not actually tested or syntax-checked code, and written for clarity, not compactness or performance.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