Forum Discussion

William_Wright_'s avatar
William_Wright_
Icon for Nimbostratus rankNimbostratus
Dec 20, 2005

Basic cookie session iRule

I need to create a basic iRule that keeps persistence based on JSESSION and load balances accordingly otherwise. I have tried all the standard persistence methods but it always goes back to defaulting to source IP. I have found quite a few example iRules but most of them get very involved. Can someone get me an example of how a basic iRule for session persistence using JSESSION would be??

 

 

Thank you

 

9 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Here's a simplified version of the rule given in this thread Click here

    
    when HTTP_REQUEST {  
      set jsess [findstr [HTTP::uri] "jsessionid" 11 ";"]  
      if { $jsess != "" } {  
        persist uie $jsess  
      }  
    }

    This should enable persistence based on the jsessionid in the uri, assuming it matches the format the findstr command in this example is looking for ( jsessionid=x...y; ).

    -Colin
  • I did an ethereal trace and found that the JSESSIONID. here is what it looks like:

     

     

    Set-Cookie: JSESSIONID=78B127CEBC4D19E5FDA6F69259667964;

     

     

    Also what does the number designate in this line: "jsessionid" 11 " ?

     

     

  • That will strip jsessionid= (11 characters) out of the string so that only the session id is persisted on.
  • I also need to put an else statement that uses a pool if the JSESSIONID does not exist. Where would I put that???

     

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    This should be pretty straight forward. There are literally hundreds of examples of this sort of thing in the forums if you look around a little. It's always best to use the search function or even just browse around to see if there are answers to the questions you have, as many people are working on or have worked on similar rules that can help each other with their experience.

    In any event, it would look like this:

    
    when HTTP_REQUEST {  
      set jsess [findstr [HTTP::uri] "jsessionid" 11 ";"]  
      if { $jsess != "" } {  
        persist uie $jsess  
      } else {
        pool yourPool
      }
    }

    hth,

    -Colin
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    You might also want to check out askf5.com for some iRules documentation on the different commands like HTTP::cookie.

     

     

    Check it out here: Click here - http://tech.f5.com/home/bigip-next/manuals/bigip9_2/bigip9_2config/BIG_IP9_2ConfigGuide-14-1.htmlwp1200312

     

     

    Note: that link points to the 9.2 documentation...earlier versions are available.

     

     

    -Colin
  • I am getting inconsistant results. Sometimes the persistence works and sometimes it does not. After using some ethereal traces I found that even using an iRule to do JSESSIONID persistence it also uses source port. Is there anyway to write a rule that will only look at the JSESSIONID and not the source port??

     

     

  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    Do you mean the source port embedded in the JSESSIONID?

     

     

    UIE persistence uses whatever data you give it, so parsing different parts of the JSESSIONID are certainly possible.

     

    I haven't looked at a JSESSIONID recently, so I'm not sure what the format looks like now.