Forum Discussion

Ganesh_Ramamoor's avatar
Ganesh_Ramamoor
Icon for Nimbostratus rankNimbostratus
Nov 30, 2005

UDP iRule help

Can I write an iRule to distribute a UDP packet based on a specific set of bytes, say byte 10 to byte 20 is less than 100 use pool A, and if the same of set of bytes is between 100 to 200 use pool B and so on?

 

 

Thanks in advance.

 

10 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    You certainly can. To do this, you'd use the UDP::payload information and only act upon the specific pieces you're interested in.

     

     

    Here's an example of a more complex UDP rule, but you should be able to get the idea of using parts of the payload.

     

     

    Click here

     

     

    HTH,

     

    -Colin
  • Thanks for the reference.

     

     

    Alternatively, if I want to send all requests from a particular client (a particular source ip address) to a particular server, is there an easier way to do this rather than maintaining a table of source ip address ranges versus the server pools? Basically what I'm looking for is: the first time a client sends a message pick a random server and for all subsequent requests from that client pick the same server.

     

     

    Thanks

     

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    There sure is...

     

     

    What you're describing we refer to as persistence. It's the notion that once an inbound client is load balanced to a particular server in a pool, that client continues to interact with the same server in that pool for an amount of time determined by the persistence settings.

     

     

    Check out these threads for some examples:

     

     

    Click here

     

    Click here

     

     

    HTH,

     

    -Colin
  • I'm sorry I didn't make myself clear. You are talking about having a persistence profile, right? I was looking for a persistence that I can dynamically turn on and off based on the information in the incoming UDP packet. And in fact, turn it on only for those clients that come in with the specific information. Can I have a persistence profile (or even create one) dynamically and enable/disable it in my iRule? Even if that's possible, will it have any performance impact? Or is there an easier/better way to do this?

     

     

    Thanks

     

  • Yes, you can.

    
    if {  }
      persist 
    } elseif {  }
      persist none
    }
  • Oh, I see in the second reference I see,

     

     

    persist uie "[IP::client_addr]:[TCP::client_port]"

     

     

    Would this persist only this particular client? And do I have to have a persistence profile along with this?

     

     

    Thanks

     

     

  • yes, that would persist only that client. You can use a profile, such as:

     

     

    persist src_addr

     

     

    It is my assumption that using src_addr would be slightly more efficient in the rule processing than uie and calling [IP::remote_addr], but you do lose the port information, and open yourself to persisting all connections behind a proxy.
  • Great! Thanks.

     

     

    So combining that with load balancing, I would do something like:

     

     

    when CLIENT_DATA {

     

    if { [UDP::payload 50] contains "XYZ" } {

     

    pool xyz_servers

     

    persist uie "[IP::client_addr]:[UDP::client_port]" 300

     

    } else {

     

    pool web_servers

     

    }

     

    }

     

     

    This should pick one from xyz_servers the first time if the packet contains XYZ and then persist with that server for 300 seconds, is that correct? And within the 300 seconds, if the server that was picked had crashed, the subsequent request would go to another server like how the default load balancing works, right?

     

     

     

  • Correct, once the LTM recognizes that the service is no longer available, any persistence records associated with that service will be deleted.