Forum Discussion

jaimes_39948's avatar
jaimes_39948
Icon for Nimbostratus rankNimbostratus
Aug 02, 2012

GTM iRule To Load Balance DNS Resolution

Greetings,

 

 

I am an iRule newbie who inherited the administration of a GTM. I have an application request which requires the GTM to load balance the DNS resolution of a URL between (2) web servers based on the clients ip address 3rd octet. If the third octet is < 128, it would resolve to the address of web server A and if it is > 128 it would resolve to the address of web server B.

 

 

 

I have never written an iRule so I am a bit lost here. I have looked at the pdf's but keep hitting a brick wall when it comes to how to check for the 3rd octet.

 

 

 

Anyone here willing to help me with this? I am running GTM software version 10.1.0 on a LTM1600.

 

 

 

Thanks in advance.

 

Jaime

 

3 Replies

  • Hi Jaime,

     

     

    What about using rand() to select a portion of the traffic to two pools?

     

     

    https://devcentral.f5.com/wiki/iRules.ratio_load_balancing_using_rand_function.ashx

     

     

    Aaron
  • jaimes, that's a pretty strange load balancing method, but you can get the third octet of a client's LDNS with getfield. Something like this would do what you want:

    
    when DNS_REQUEST {
      if { [getfield [IP::client_addr] "." 3] < 128 } {
        pool poolA
      } else {
        pool poolB
      }
    }
    
  • Thanks for the reply. Actually the third octet match would be more of a selective match like 3rd octet = 25, 30, etc...

     

     

    I am doing something similar on the ltm using the following rule:

     

     

    when HTTP_REQUEST {

     

    set abtest_pool "wa-en-varnishab_pool"

     

    set default_pool "ac-ad_pool"

     

    set abtest_web_pool "wa-en-webab_pool"

     

    set term [getfield [IP::client_addr] "." 3]

     

    log local0. "Client IP is [IP::client_addr] and term 3 is $term."

     

    if {[HTTP::header User-Agent] contains "noabtest4me"} {

     

    pool $default_pool

     

    log local0. "Client sent noabtest4me header and is exempt from the ab test."

     

    }

     

    elseif {[HTTP::header User-Agent] contains "abtestme"} {

     

    HTTP::header insert "answ_abtest" "true"

     

    pool $abtest_pool

     

    log local0. "Client sent abtestme and forced ab test participation."

     

    }

     

    elseif {[class match $term equals abtest_ips]}{

     

    if {![class match [HTTP::header User-Agent] contains botagents]}{

     

    if {[active_members $abtest_pool] >= 1 && [active_members $abtest_web_pool] >= 1} {

     

    pool $abtest_pool

     

    HTTP::header insert "answ_abtest" "true"

     

    log local0. "hit AB pool from [IP::client_addr] to [HTTP::uri] and term is $term"

     

    }

     

    else {

     

    pool $default_pool

     

    log local0. "hit AB pool but all servers were down from [IP::client_addr] to [HTTP::uri]"

     

    }

     

    }

     

    }

     

     

    I tried doing the same on the GTM with the below rule:

     

     

    when DNS_REQUEST {

     

    set term [getfield [IP::client_addr] "." 3]

     

    if {[class match $term equals resellerrating10percent_ips]}{

     

    cname www-1378117844.us-west-1.elb.amazonaws.com

     

    } else {

     

    cname lb-www-1818231038.us-west-1.elb.amazonaws.com

     

    }

     

    }

     

     

    resellerrating10percent_ips

     

    5

     

    6

     

    24

     

     

    But just realized that the GTM doesn't support "Data Group Lists" to set the $TERM statement.

     

     

    Basically, what I am trying to accomplish is some Amazon CDN switching using 2 different CNAME's with a 90/10 resolution split. The CNAME that gets the 90 percent is the legacy one and the one with the 10 percent is a new one that we would like to test with production traffic. Since there is a 90/10 split, I need to make the client connections somehow sticky to the same CNAME and associated AWS servers. That was the thought of match the 3rd octet so the recycled client connections would always get the same CNAME resolution for persistence.