Forum Discussion

sidkhan_366821's avatar
sidkhan_366821
Icon for Nimbostratus rankNimbostratus
Jan 17, 2019

Session ID persistence based on SessionID parameter in JSON

Hello ,

 

Iam trying to write I-rule based on following requirement

 

  1. Client requests to initiate a session  F5 forwards the call to available Node in the pool.

     

  2. Node sends response to F5 containing sessionid  F5 extracts sessionid and creates a new persistence.

     

  3. F5 then forwards the HTTP response to client  Client stores the sessionid .

     

  4. Client uses the sessionid to create a new request using sessionid in the URL  F5 will parse the URL to retrieve the sessionid and use the existing persistence data to redirect the request to the right Node.

     

The F5 script should be clever enough to retrieve sessionid in a case-insensitive way and persist. F5 can distinguish first call from the subsequent calls by parsing the URL as the first call will not contain any sessionid text.

 

Can some one please help iam completely new to F5 .

 

Thanks Uzair

 

2 Replies

  • Hi sidkhan,

     

    its basically impossible for us, to help you without knowing how the SessionID is initially send by your backend application and how the SessionID is send by your clients on subsequent requests.

     

    You would need to provide a detailed traffic flow including the request/response headers/bodies. The SessionID values could be embedded anywhere in the ongoing conversation...

     

    Cheers, Kai

     

  • Hi sidkhan,

    a very generic (aka. not very much optimized) iRule based on the provided application logic may look like that...

    when HTTP_REQUEST {
        STREAM::disable
        if { [set sessionid [URI::query [HTTP::uri] "sessionid"]] ne "" } then {
            log local0.debug "Found incomming Session ID: [URI::query [HTTP::uri] "sessionid"]"
            persist uie $sessionid
        }
    }
    when HTTP_RESPONSE {
        if { [HTTP::header value "Content-Type"] equals "application/json" } then { 
            STREAM::expression {@"SessionId": "([a-z0-9-]+)",@}
            STREAM::enable
        }
    }
    when STREAM_MATCHED {
        if { [set sessionid [getfield [STREAM::match] {"} 4]] ne "" } then {
            log local0.debug "Extracted outgoing Session ID: $sessionid"
            eval "persist add uie \$sessionid 900"
        }
    }
    

    The iRule will

    persist
    incomming requests based on the value of the Query-String parameter "sessionid" .

    If the persist database does not hold an entry for that value, or if the client does not send any "sessionid" parameter, the request will be balanced based on your pool settings.

    The iRule will furthermore

    STREAM
    inspect every outgoing JSON response for a string in the regex format of
    "SessionId": "([a-z0-9-]+)",
    . If a match is found, the iRule would extract the
    ([a-z0-9-]+)
    portion and create/update the persistence database with the currently selected pool member IP.

    Note: You MUST apply a STREAM and ONECONNECT profile to your Virtual Server in order to make this iRule work. You may use the defaults profiles without any further configuration.

    Note: You may monitor the functionality with LTMs log files and using the TMSH command

    (tmsh) show ltm persistence persist-records
    . Once you have verified the functionality of this iRule, you may want to remove the individual log lines from the script...

    Cheers, Kai