Forum Discussion

ppltam_183867's avatar
Apr 03, 2016

Universal Inspection iRule for LTM Session Persistent

Hi DevCentral,

 

Our organization is running F5 LTM version 11.6.0 HotFix 6 for our internal traffic load balancing operations. Our custom application written by a software company will initiate traffic to the F5 LTM Virtual server which will load balancing the traffic to the node members which are running Tomcat web servers.

 

Our company Application will provide an unique runtime "session id" on the HTTP payload and the Header ID "route" on the HTTP header. The "session id" is extracted using iRule findstr function. We are brand new to iRule, have actually written the iRule to cope with our application team's requiements. The high level iRule logic is as follows:

 

HTTP Request from the client. Extract the "session id" from the http payload using the findstr function. If the session id exist on the LTM persistent table persist the traffic using uie Otherwise, Traffic will route to Priority group ONE if http header id "route" has a value of "usb-hsm" or priority group TWO if no such header id is found or the header id contains other value. HTTP response logic is similar to the HTTP request by extracting the http response payload and check against the Persistent table. If find persist the traffic and otherwise add the "session id" into the persistent table.

 

Below please find our iRule code :

 

<< Begin iRule >> when HTTP_REQUEST {

 

set content_length [HTTP::header "Content-Length"] log local0. "Request length $content_length"

 

if { $content_length > 0 } { HTTP::collect $content_length } }

 

when HTTP_REQUEST_DATA { set fmtID [findstr [HTTP::payload] "fmtSessionId xmlns=\"\">" 22 "<"]

 

if { $fmtID != "" } {

   **set node_lookup [persist lookup uie $fmtID node]** 

   if { $node_lookup != "172.21.15.6" || $node_lookup != "172.21.15.10" } {
     if { [HTTP::header "route"] equals "usb-hsm" } {
        pool pool_formatting_staging_g1
        log local0. "go to pool G1"
     } else {
                             pool pool_formatting_staging_g2
                             log local0. "go to pool G2"
                          }
     return
   } else {
     persist uie $fmtID 1800
     log local0. "persisted!"
     return
   }
}

}

 

when HTTP_RESPONSE { set response_length [HTTP::header "Content-Length"] log local0. "Response length $response_length"

 

if { $response_length > 0 } { HTTP::collect $response_length } }

 

when HTTP_RESPONSE_DATA {

 

set response_fmtID [findstr [HTTP::payload] "fmtSessionId xmlns=\"\"\>" 22 "<"]
set response_fmtID [findstr [HTTP::payload] "fmtSessionId\>" 13 "<"]

log local0. "Response payload: [HTTP::payload]"
log local0. "Response_fmtID: $response_fmtID"

if { $response_fmtID != ""} {
  set exist_record ""
  set exist_record [persist lookup uie $response_fmtID node]


  if { $exist_record != "172.21.15.6" || $exist_record != "172.21.15.10" } {
     persist add uie $response_fmtID 1800
     log local0. "persist record add"
  }
}

} << End iRule>>

 

Our questions are as follows:

 

1) The above code seems not able to execute the code set node_lookup [persist lookup uie $fmtID node] correctly and wonder if there is any syntax or iRule logic ?

 

2) For implementation of UIE load balancing methodology, do we need to use the "persist lookup" command to check if it is exist on the run time "persistent table" before adding the persistent record or there is aother better built-in technique to accomplish this ?

 

3) Your comments on the above iRule coding is very much appreciated.

 

Many thanks for your technical advice in advance.

 

Thanks & Regards Patrick

 

  • Able to address the coding issue by refining the persistent lookup. thanks.

     

  • Able to address the coding issue by refining the persistent lookup. thanks.