Forum Discussion

patrick_osewal1's avatar
patrick_osewal1
Historic F5 Account
Dec 11, 2007

First attempt with address datagroup

Hello,

 

 

Below you will find my first attempt at using an address datagroup. My objective is to create a list of IP addresses in a class.

 

 

class1 and load balance them to pool1

 

class2 and load balance them to pool2

 

class3 and load balance them to pool3

 

 

Please let me know if there is a better way to achieve this goal and any advice is greatly appreciated.

 

 

 

iRule: source address parsing

 

when CLIENT_ACCEPTED {

 

if { [matchclass $my_client equals $::networks_class] } {

 

pool pool1

 

}

 

 

} elseif

 

if { [matchclass $my_client equals $::networks_class2] } {

 

pool pool2

 

}

 

 

} elseif

 

if { [matchclass $my_client equals $::networks_class3] } {

 

pool pool3

 

}

 

}

 

}

 

} else {

 

discard

 

}

 

}

 

 

class networks_class1 {

 

network 10.1.2.3 mask 255.255.255.0

 

network 10.1.2.4 mask 255.255.255.0

 

network 10.1.2.5 mask 255.255.255.0

 

}

 

 

class networks_class2 {

 

network 10.1.2.6 mask 255.255.255.0

 

network 10.1.2.7 mask 255.255.255.0

 

network 10.1.2.8 mask 255.255.255.0

 

}

 

 

class networks_class3 {

 

network 10.1.2.9 mask 255.255.255.0

 

network 10.1.2.10 mask 255.255.255.0

 

network 10.1.2.11 mask 255.255.255.0

 

}

 

  • Youv'e got a lot of extra braces in there. Your iRule can be simplified to the following:

    when CLIENT_ACCEPTED {
      if { [matchclass $my_client equals $::networks_class] } {
        pool pool1
      } elseif { [matchclass $my_client equals $::networks_class2] } {
        pool pool2
      } elseif { [matchclass $my_client equals $::networks_class3] } {
        pool pool3
      } else {
        discard
      }
    }

    You didn't include it, but I'm assuming you are assigning the "my_client" variable with something like IP::remote_addr...

    -Joe
  • Joe,

     

     

    Can we use switch instead of If in this case?

     

     

    I read the article you wrote about using switch instead of multiple if statement. However I did not see example using switch with match class

     

     

    Thanks,

     

    Ferdy