Forum Discussion

KB_'s avatar
KB_
Icon for Nimbostratus rankNimbostratus
Aug 28, 2020

Setting Cookie, and subsequently loadbalancing using the cookie!

Hello!

I have seen around and tried to find something similar but havent found much.

The requirement is as follows and needed some help with it.

  1. Client connects to VIP initially, it will not have any cookie info- this needs to go to pool 1.
  2. pool1 contains same nodes of pool2 and pool 3, so basically pool 1 = pool 2+pool 3
  3. if LB selects node from pool1 that belongs to pool2 as well - set cookie "TC" (big ip should do cookie insert)
  4. if LB selects node from pool1 that belongs to pool3 as well- set cookie "DY"(big ip should only send back the cookie set by server ie big ip is passive)
  5. Any subsequent requests from client with these cookies(TC,DY) willl go to pool 2, pool3 respectively.

below is what i have tried so far, but do not know how to create a hash for the server IP and port and add it to irule while inserting cookie. I know something significatnt is missing, any pointers will be helpful.

 

#https://clouddocs.f5.com/api/irules/LB__select.html

#https://devcentral.f5.com/s/question/0D51T00006i7YuC/getting-cookie-value-and-using-switch

#https://clouddocs.f5.com/api/irules/HTTP__cookie.html

 

when HTTP_REQUEST {

   #log cookies of client in request

    log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]"

    foreach cookie [HTTP::cookie names] {

     log local0. "[IP::client_addr]:[TCP::client_port]: Cookie $cookie = [HTTP::cookie value $cookie]"

if {not ([HTTP::cookie exists "TCS"] or[HTTP::cookie exists "DY"]) }

pool pool1

set bool 1

log local0."Pool assigned bool :$bool"

}

elseif{

if{([HTTP::cookie exists "TC"])}

{

pool pool2

}

else{

if{([HTTP::cookie exists "DY"])}

{

pool pool3

}

}

  }

when HTTP_RESPONSE {

if {bool ==1 and ([LB::server addr]==10.45. or 10.45.)}

{

#Cookie insert method BigIP needs to actively insert cookie

{HTTP::cookie insert name "TC" value "TC"}

}

else {

#Passive cookie by BigIP as server will set to cookie for DY

{HTTP::cookie insert name "DY" value "DY"}

}

}

No RepliesBe the first to reply