Application Delivery (ADX)

Cookie Switching

by pmorrissey on ‎04-29-2009 08:18 PM (1,430 Views)

Summary

 

We want to enable persistance to the same server using cookies.To achieve persistence, we will insert cookies in all connections coming from new clients. We will layer-4 load-balance the connections, and at the same time insert a cookie.

 

The cookie value will contain the server-id to which the connection was load-balanced. Next time when the same client connects, it will present the cookie. Using the cookie value, we will know which real-server to choose and send the connection to it.

 

Specifics

 

Implementation notes

  • Connections from new clients will not have the cookie. To handle such clients, the ServerIron will send them to a pre-defined group. We need group-id to be assigned to each real-server.Once a real server is selected, its ServerID will be used as the cookie value. Each real server should have a defined server-id
  • For new connections, ServerIron will use the cookie name specified so that a set-cookie: CookieName=value can be sent by the ServerIron to the client.
  • This is one of the more common approaches to cookie persistence. Their a range of other cookie persistence methods available. consult here for those

 

Topology Diagram

 

Not needed.

 

Sample Code/Configuration

 

csw-rule "r1" header "cookie" search "ServerID="
!
csw-policy "p1"
    match "r1" persist offset 0 length 4 group-or-server-id
    default forward 1
    default rewrite insert-cookie "ServerID"
!
server real rs18 10.45.4.18
    port http
    port http url "HEAD /"
    port http server-id 1218
    port http group-id 1 1
!
server real rs11 10.45.4.11
    port http
    port http url "HEAD /"
    port http server-id 1211
    port http group-id 1 1
!
server virtual vip1 10.45.4.245
    port http
    port http csw-policy "p1"
    port http csw
    bind http rs18 http rs11 http

 

Tips / Caveats

 

Optionally, You can also use the following options for the rewrite action inserting the cookie:

 

  • domain
  • path
  • age 

-> default rewrite insert-cookie "ServerID" "domain.com" "/path/subpath" 60

 

Further Reading

 

You can also insert different cookies depending on the csw-rule being hit. A sample config is: MultipleCookiesinsert