Forum Discussion

Raimar_Melchior's avatar
Raimar_Melchior
Icon for Nimbostratus rankNimbostratus
Jul 13, 2005

Cookie Persistence with iRule

Hi everybody,

 

 

I want to achieve cookie persistence by means of extracting a string from a cookie and directing the client to the appropriate pool member based on that unique string. It would also be nice when a match would be logged.

 

 

Cookie: BBIGipServerpoola=353479690.11465.0000;JServSessionId1111...

 

 

1111 is the unique string which should be extracted (1111 identifies node1 and 2222 identifies node2). The pool has only this two members.

 

 

I would be very pleased when someone could give me a sample iRule on this.

 

 

Thanks

 

cyb

 

  • Martin_Machacek's avatar
    Martin_Machacek
    Historic F5 Account
    Assuming that your unique identifier is really part of the cookie name and not the cookie value, following configuration should work:

    
    class my_nodes {
      "1111 10.1.1.1:80"
      "2222 10.1.1.2:80"
    }
    pool my_pool {
      select mapclass2node(findstr(http_header("Cookie"), "JServSessionId", 14, 4), my_nodes)
      member 10.1.1.1:80
      member 10.1.1.2:80
    }
    virtual 1.2.3.4:80 {
      use pool my_pool
    }

    The basic idea is to use the mapclass2node function to select a node based on unique identifier parsed out of the Cookie header. The call to the findstr function above returns 4 characters at offset 14 after matching string JServSessionId.If the id cannot be parsed out of the cookie or if the cookie header is not present or if the unique id does not match any entry in the class, BIG-IP will loadbalance the request based on loadbalancing method defined for the pool (round-robin in the example above).