Application Delivery (ADX)

Cookie Switching

by pmorrissey on ‎04-29-2009 10:18 PM (336 Views)

<body><h2><span><span style="font-family: times new roman,times; font-size: 18pt;">Summary</span></span></h2><p></p><p><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">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.</span></p><p><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">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.</span></p><p></p><h2><span><span style="font-family: times new roman,times; font-size: 18pt;">Specifics</span></span></h2><p></p><p><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">Implementation notes<br/></span></p><ul><li><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">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.</span><span style="font-size: 10pt;"><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">O</span></span><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">nce a real server is selected, its ServerID will be used as the cookie value. Each real server should have a defined server-id</span></li><li><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">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.</span></li><li><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">This is one of the more common approaches to cookie persistence. Their a range of other cookie persistence methods available. consult here for those<br/></span></li></ul><p></p><h2><span><span style="font-family: times new roman,times; font-size: 18pt;">Topology Diagram</span></span></h2><p></p><p>not needed</p><p></p><h2><span><span style="font-family: times new roman,times; font-size: 18pt;">Sample Code/Configuration</span></span></h2><p></p><pre><span style="font-family: courier new,courier; color: #ff0000; font-size: 10pt;">csw-rule "r1" header "cookie" search "ServerID="<br/>!<br/>csw-policy "p1"<br/>    match "r1" persist offset 0 length 4 group-or-server-id<br/>    default forward 1<br/>    default rewrite insert-cookie</span><span></span> <span style="font-family: courier new,courier; font-size: 10pt;"></span><span><span style="font-family: courier new,courier; color: #ff0000; font-size: 10pt;">"ServerID"</span></span><span style="font-family: courier new,courier; font-size: 10pt;"><br/>!<br/>server real rs18 10.45.4.18<br/>    port http<br/>    port http url "HEAD /"<br/>    port http server-id 1218<br/>    port http group-id 1 1<br/>!<br/>server real rs11 10.45.4.11<br/>    port http<br/>    port http url "HEAD /"<br/>    port http server-id 1211<br/>    port http group-id 1 1<br/>!<br/>server virtual vip1 10.45.4.245<br/>    port http<br/></span><span style="font-family: courier new,courier; color: #ff0000; font-size: 10pt;">    port http csw-policy "p1"</span><span style="font-family: courier new,courier; font-size: 10pt;"><br/><span style="color: #ff0000;">    port http csw<br/></span>    bind http rs18 http rs11 http</span><span style="font-family: courier new,courier;"><br/></span></pre><p></p><h2><span><span><span style="font-family: times new roman,times; font-size: 18pt;">Tips / Caveats</span></span></span></h2><p></p><p><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">Optionally, You can also use the following options for the rewrite action inserting the cookie:<br/></span></p><p><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"><br/></span></p><ul><li><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">domain</span></li><li><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">path</span></li><li><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">age</span></li></ul><p></p><p>-&gt; <span style="font-family: courier new,courier; color: #ff0000;">default rewrite insert-cookie "ServerID" "domain.com" "/path/subpath" 60</span></p><h2><span><span style="font-family: times new roman,times; font-size: 18pt;">Further Reading</span></span></h2><p></p><p><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">You can also insert different cookies depending on the csw-rule being hit.  A sample config is : <span class="active_link">MultipleCookiesinsert</span></span></p></body>