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...
AppleBee_108607
Nov 02, 2010Historic F5 Account
Wheeww. I finally got it working, referring to an iRule from my colleague, which I guess comes from somewhere in DevCentral.
This one is much nicer coz you have to only modify the pool name.
I hope "initial setup" section can be moved to other EVENTs that is triggered only once after the iRule is loaded. And periodically update the list of pool member with "after" command or something.
---------------------------------------------------------
when RULE_INIT {
set pool name
set static::poolname "test-pool"
}
when CLIENT_ACCEPTED {
initial setup
$num_pm: number of the pool member
set num_pm [members $static::poolname]
set pm_list [members -list $static::poolname]
table add -subtable tbl_rr_$static::poolname "last_mod" 0
per connection process
choose index of the pool member to LB to
set last_mod [table lookup -subtable tbl_rr_$static::poolname "last_mod"]
set new_mod [expr {[expr {$last_mod + 1}] % $num_pm}]
table set -subtable tbl_rr_$static::poolname "last_mod" $new_mod
check pool availability
if { [active_members $static::poolname] < 1 } {
if there is no active member, reject
reject
}
round robin LB
set pm [lindex $pm_list $new_mod]
set mon_stat [LB::status pool $static::poolname member [lindex $pm 0] [lindex $pm 1]]
if {$mon_stat == "up"} {
pool $static::poolname member [lindex $pm 0] [lindex $pm 1]
} else {
for {set i 1} {$i < $num_pm} {incr i} {
set j [expr {[expr {$i + $new_mod}] % $num_pm}]
set pm [lindex $pm_list $j]
set mon_stat [LB::status pool $static::poolname member [lindex $pm 0] [lindex $pm 1]]
if {$mon_stat == "up"} {
pool $static::poolname member [lindex $pm 0] [lindex $pm 1]
table set -subtable tbl_rr_$static::poolname "last_mod" $J
break
}
}
}
}
----------------------------------------------------------------
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