Forum Discussion

prax_73377's avatar
prax_73377
Icon for Nimbostratus rankNimbostratus
Mar 18, 2011

Routing based on value of cookie

Hi Gurus,

 

 

Need some help with iRules, I am oracle applications dba and do not know much about the iRule thing in F5. We have 4 web server nodes and I defined 4 pools one server in each pool.

 

Pool-A

 

Pool-B

 

Pool-C

 

Pool-D

 

 

 

I am trying to direct a call from Oracle applications based on value of cookie. Then name of cookie is "OracleCookie"

 

if the value has "OraB" direct to Pool-B, "OraC" direct to Pool-C. "OraD" direct to Pool-D and default direct to Pool-A,

 

 

 

I have a iRule like this:

 

when HTTP_REQUEST {

 

Try to select a pool based on the http cookie containing pool information

 

if { [HTTP::cookie exists "OracleCookie"] and [HTTP::cookie value "OracleCookie"] contains "OraB"} {

 

use pool Pool-B

 

log INTB-Pool-B

 

}

 

elseif { [HTTP::cookie exists "OracleCookie"] and [HTTP::cookie value "OracleCookie"] contains "OraC"} {

 

use pool Pool-C

 

log Pool-C

 

}

 

elseif { [HTTP::cookie exists "OracleCookie"] and [HTTP::cookie value "OracleCookie"] contains "OraD"} {

 

use pool Pool-D

 

log Pool-D

 

}

 

else {

 

use pool Pool-A

 

log Pool-A

 

}

 

}

 

 

 

The rule compiled fine, however the load balancer does not re-direct to the pool. The request comes in a new window opens but nothing is in the page eventually get page cannot be displayed. Could you please let me know if the iRule is correct and any idea how I can trouble shoot this

 

 

 

Thanks in advance!

 

2 Replies

  • Banyan_He_9636's avatar
    Banyan_He_9636
    Historic F5 Account
    I think you may need to show us the whole picture instead of the this iRule. The syntax is good, the logic is good. And I played your iRule here,

     

     

    curl -b "OracleCookie=OraB" http://192.168.28.251/

     

    curl -b "OracleCookie=OraC" http://192.168.28.251/

     

    curl -b "OracleCookie=OraD" http://192.168.28.251/

     

     

    Mar 18 18:30:41 local/tmm info tmm[6224]: 01220002:6: Rule Devcentral_1 : INTB-Pool-1

     

    Mar 18 18:30:47 local/tmm info tmm[6224]: 01220002:6: Rule Devcentral_1 : Pool-2

     

    Mar 18 18:30:54 local/tmm info tmm[6224]: 01220002:6: Rule Devcentral_1 : Pool-3

     

     

    It's working for me. Do you have the sample of your cookie string? Since mine is quit simple.
  • Can you try this? Make sure to use a OneConnect profile (with a /0 source mask if you're using SNAT or /32 with no SNAT).

    
    when CLIENT_ACCEPTED {
       set default_pool [LB::server pool]
    }
    when HTTP_REQUEST {
    
       log local0. "Cookie: [HTTP::cookie value "OracleCookie"]"
        Try to select a pool based on the http cookie containing pool information 
       if { [HTTP::cookie value "OracleCookie"] ne "" }{
          switch [HTTP::cookie value "OracleCookie"] {
             "OraA" {
                pool Pool-A
                log local0. "Using INTB-Pool-A"
             }
             "OraB" {
                pool Pool-B
                log local0. "Using INTB-Pool-B"
             }
             "OraC" {
                pool Pool-C
                log local0. "Using INTB-Pool-C"
             }
             "OraD" {
                pool Pool-D
                log local0. "Using INTB-Pool-D"
             }
             default {
                pool $default_pool
                log local0. "Using $default_pool"
             }
          }
       }
    }
    

    Aaron