Forum Discussion
Nathan_McMahon_
May 05, 2005Historic F5 Account
Direct requests based on hashed cookie data
I have a requirement to pull a numerical value from a cookie and direct the request to one of 12 pools based on the hashed value of that cookie data. For example, a client's cookie contains 62. Divi...
May 05, 2005
Aren't you just looking for the modulus operator? If all you want is the remainder from the first number divided by the second, you could just use the % operator. In your example, 62 % 12 would return 2. Here's an iRule as a reference.
when HTTP_REQUEST {
set CookieId [HTTP::cookie User_cookie]
if { [string is integer $CookieId] } {
set PoolId [expr $CookieId % 12 ]
set PoolName "Pool_$PoolId"
pool $PoolName
log "cookieid_rule: CookieId = $CookieId; PoolId = $PoolId; PoolName = $PoolName"
} else {
log "cookieid_rule: Invalid CookieId - not in integer format!"
}
}
By the way, it looks like the floor() math function is not included in our implementation. I'll verify this and post a list of available builtin functions. Your example would likely cause a runtime violation in the iRule producing an error similar to the following:
syntax error in expression "set TempCookieId2 [expr floor $TempCookieId]": variable references require proceeding $...".
If you replace your code with floor($TempCookieId) you would get a configuration error stating something like the following:
unknown math function "floor" while compiling "expr floor($TempCookieId)...
-Joe
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
