Forum Discussion

Hille_de_Graaf_'s avatar
Hille_de_Graaf_
Icon for Nimbostratus rankNimbostratus
Mar 25, 2008

Simplify iRule

I have an iRule which would look at the content of the HTTP-header and loadbalance on behalve of that content.

 

Is there a more efficient way to build an iRule with the same results as the example below?

 

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] ends_with "ACCBPMv1" } {

 

pool xml-fw

 

} elseif { [HTTP::uri] ends_with "ACCTVIv1" } {

 

pool xml-fw

 

} elseif { [HTTP::uri] ends_with "ACCDVSv1" } {

 

pool xml-fw

 

} elseif { [HTTP::uri] ends_with "BPMv1" } {

 

pool xml-fw

 

} elseif { [HTTP::uri] ends_with "TVIv1" } {

 

pool xml-fw

 

} elseif { [HTTP::uri] ends_with "DVSv1" } {

 

pool xml-fw

 

} else {

 

pool ws-accxml

 

}

 

}

 

 

Regards,

 

 

Hille

2 Replies

  • There are 2 ways I can see this work.

    1) Using SWITCH

    You can use the switch statement

    
    when HTTP_REQUEST {
      switch [HTTP::uri] {
      "ACCBPMv1" {pool xml-fw }
      "ACCTVIv1" { pool xml-fw }
      "ACCTDSv1" { pool xml-fw }
      "BPMv1" { pool xml-fw }
      "TVIv1" { pool xml-fw }
      "DVSv1" { pool xml-fw }
      }
    }

    or

    
    when HTTP_REQUEST {
     switch -glob [HTTP::uri] {
      "ACC*" {pool xml-fw }
      "BPMv1" { pool xml-fw }
      "TVIv1" { pool xml-fw }
      "DVSv1" { pool xml-fw }
     }
    }

    or

    
    when HTTP_REQUEST {
     switch -glob [HTTP::uri] {
      "*v1" {pool xml-fw }
      }
    }

    You would then set the virtual server to the default pool to ws-accxml for any of the switch irules listed above.

    2) Using Datagroup the solution looks a bit cleaner.

    
    class uricontains {
    "ACCBPMv2"
    "ACCBPMv1"
    "ACCTVIv1" 
    "ACCTDSv1"
    "BPMv1"
    "TVIv1"
    "DVSv1"
    }
    when HTTP_REQUEST {
       if { [matchclass [HTTP::uri] contains $::uricontains] } { 
          pool xml-fw 
        } else {pool xml-accxml }
    }

    Hope this helps

    /CB

  • Hi,

     

     

    Switch is the most efficient way to do the job if you have < 100 entries. If you have more entries then datagroup is the most efficient one

     

     

    HTH