ltm rule command LB select
iRule(1) BIG-IP TMSH Manual iRule(1)
LB::select
Forces a load balancing selection and returns the result.
SYNOPSIS
DESCRIPTION
This command forces the system to make a load balancing selection based on current conditions, and returns a string in the
form of a pool command that can be eval'd to activate that selection.
This enables an iRule to make LB decision early, and use that information to manage the connection.
Two of the most common scenarios are:
1. To compare the selection that would be made using the load balancing criteria to the actual server that should be
picked, and force the alternative selection before the serverside flow is established with the "wrong" server. If you wait
to evaluate the load balancing selection until after the serverside flow is established (in SERVER_CONNECTED or later),
then use LB::detach / LB::reselect, client data that has already entered the abandoned serverside flow may be lost.
2. To use information about the selected server to influence the characteristics of the serverside flow (ie. specific SNAT
based on selected server, insertion of custom header based on selected server, etc. for other conditions or actions - see
2nd example below.)
Note: The LB::select command will currently only function correctly on connections which use a TCP profile. It will not
function correctly on connections using a UDP, nor on connections which use a FastL4 profile. This issue is tracked by
ID421708.
LB::select
Forces the system to make a load balancing selection based on load balancing criteria and current conditions. Returns a
string in the form of a pool command that can be evaluated to activate that selection:
pool member
This is the same string that would be returned by the LB__server command when invoked with no parameters. This string can in turn be eval'd to actually make the indicated load balancing selection. (You can use the Tcl eval command to evaluate the return value and actually make the pick, then parse the output from LB__select or use LB__server to get pool name, IP, or port - see examples below.)
LB::select transparent_port
Same as LB::select but port translation will be disabled for this pick.
RETURN VALUE
VALID DURING
ANY_EVENT
EXAMPLES
To evaluate the selection early, then use it:
when HTTP_REQUEST {
pool fargo
set mypick [LB::select]
log local0. "The LB choice is: $mypick"
# Execute the pick
eval $mypick
}
To force an early load balancing selection so the details may be used to modify the serverside request attributes:
when HTTP_REQUEST {
log local0. "lbserveraddr: [LB::server addr]"
# check if serverside connection had previously been established
if { [LB::server addr] eq "" }{
# if no serverside connection had previously been established, force one
# so the iRule has the info required to insert a destination-specific header
eval [LB::select]
}
switch [LB::server addr] {
"172.16.5.80" { HTTP::header replace Host www1.customer.com }
"172.16.5.81" { HTTP::header replace Host www2.customer.com }
"172.16.5.82" { HTTP::header replace Host www3.customer.com }
}
}
HINTS
SEE ALSO
Sample Code: Current Pool Member Status
CHANGE LOG
@BIGIP-9.2.4 --First introduced the command.
BIG-IP 2022-04-12 iRule(1)