Forum Discussion
James_Thomson
Employee
Dec 10, 2004mapclass2node
Along the same lines off an an earlier post by Natty about persistence. I'm trying to just read a cookie that is handed out by the server and persist a user on it. One example is where the cookie is static and therefore, I thought of user mapclass2node.
class nodes {
"s1s1 10.11.1.10:80"
"s1s2 10.11.1.20:80"
}
I'd like to search the request and map as appropriate. I used to do this in the pool with a select command:
select mapclass2node ((http_cookie,("server")),nodes)
How does this work now? Do I need to do a when HTTP_REQUEST and then some if statement.
when HTTP_REQUEST {
if {HTTP::cookie]} {
select mapclass2node((http_cookie,("server")),nodes)
}}
- unRuleY_95363Historic F5 AccountIt's pretty simple, though not configured quite the same as the select statement on the pool. Here's what to do:
class node_class { "s1s1 10.11.1.10:80" "s1s2 10.11.1.20:80" } rule direct_select { when HTTP_REQUEST { node [findclass [HTTP::cookie "server"] $::node_class " "] } }
- unRuleY_95363Historic F5 AccountWe discovered an issue in 9.0.2 with the separator argument of the findclass command. The getfield command should be used in conjunction with the findclass command until 9.0.3 where the issue has been resolved.
rule direct_select { when HTTP_REQUEST { set server [HTTP::cookie "server"] set entry [findclass $server $::node_class] if { $entry ne "" } { node [getfield $entry " " 2] } else { log "Bad server cookie: $server" reject } } }
- James_Thomson
Employee
Thanks, I used this and it works great.rule select_on_cookie { when HTTP_REQUEST { if {[HTTP::cookie exists "server"]} { set result [findclass [HTTP::cookie "server"] $::nodes] if {$result ne ""} { node [getfield $result " " 2] } } } } class nodes { "s1s1 10.11.1.10:80" "s1s2 10.11.1.20:80" }
- David_Zuk_10432
Nimbostratus
Hi there. I'm trying to follow your example and am having absolutley no luck. When I try to define the class in the iRule, it doesn't allow it. I created the data group that is supposed to do the same thing, but that fails as well. I am running BigIP 9.0.3 and any help would be greatly appreciated. - In the example above, this is what is stored in the system configuration file. If you are using the GUI, you will need to create a Data Group List of name "nodes" and then only include the when part of the rule.
- David_Zuk_10432
Nimbostratus
Joe, - Now I'm a bit confused. Your code above shows sessions with the "server" cookie set, will be routed to pool "staging" and all other sessions will be routed to "Staging" as well. This rule is equivalent to setting the virtual's default pool to "Staging" without an iRule.
- David_Zuk_10432
Nimbostratus
Joe,when HTTP_REQUEST { set server [HTTP::cookie "server"] set entry [findclass $server $::staging_nodes] if { $entry ne "" } { node [getfield $entry " " 2] } else { log "Bad server cookie: $server" reject } }
- unRuleY_95363Historic F5 AccountYup, sounds like you are on the right track.
when HTTP_REQUEST { set server [HTTP::cookie "server"] set entry [findclass $server $::staging_nodes] if { $entry ne "" } { node [getfield $entry " " 2] [IP::local_addr] } else { log "Bad server cookie: $server" reject } }
- First a little on findclass and matchclass. matchclass will search a data group list for an exact string match while findclass will search for a string in the class that starts with the search string. Either should work for your case but I just wanted to make clear the subtle difference.
// assuming $server is of the form "xx ip4_addr:port" set server_addr [getfield $server ":" 1];
set entry [findclass $server_addr $::staging_nodes]
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