Forum Discussion
Load balancing amongst pool members while preserving ports
Hopefully I'm not overlooking an easy way to do this, but I need to load balance traffic amongst multiple pool members, but I need to preserve the port the traffic comes in and goes out on. Using the the provided port preservation doesn't seem to do this so I implemented an iRule that will always preserve the port the traffic was received on and will use the same port to send the received traffic out on. However, my iRule uses a primary and secondary node which has the destination IPs defined so it will always use the primary IP unless it's not able to connect then it will use the secondary. Is there an easy way to do this such as not setting any static entries? My iRule with minor edits is below:
when RULE_INIT {
Log debug messages to /var/log/ltm? 1=yes, 0=no
set static::disxd__pool_debug 1
Name of the pool where the pool members reside
set static::xd__pool pool__pool
Set primary and secondary guard nodes, these are the separate physical
servers that are already defined on the LTM. They should also have
associated pool members for the particular ports they are responsible for
set static::xd__pool_pri_node xxx.xxx.xxx.xxx
set static::xd__pool_sec_node xxx.xxx.xxx.xxx
}
when CLIENT_ACCEPTED {
set dst_port [TCP::local_port]
Try the primary pool member first
if { [LB::status pool $static::xd__pool member $static::xd__pool_pri_node $dst_port] ne "down" }
{ pool $static::xd__pool member $static::xd__pool_pri_node:$dst_port
if {$static::disxd__pool_debug} { log local0. "Request to $dst_port directed to $static::xd__pool_pri_node:$dst_port" }
return
Try the secondary pool member if the primary fails
}
elseif { [LB::status pool $static::xd__pool member $static::xd__pool_sec_node $dst_port] ne "down" }
{ pool $static::xd__pool member $static::xd__pool_sec_node:$dst_port
if {$static::disxd__pool_debug} { log local0. "Request to $dst_port directed to $static::xd__pool_sec_node:$dst_port" }
return
Both pool members failed, reject the packet and log the error
} else {
log local0. "FATAL ERROR: Both pool members ($static::xd__pool_pri_node:$dst_port and $static::xd__pool_sec_node:$dst_port appear to be down"
reject
}
}
Thx in advance!
D
Recent Discussions
Related Content
* 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