Forum Discussion

Mario_Eury_6049's avatar
Mario_Eury_6049
Icon for Nimbostratus rankNimbostratus
Dec 18, 2006

Switch Command

I'm trying to use the "switch" syntac command to load balance traffic based on a client's subnet/network address. I have a list of subnets that would need to be listed to load balance to the test_pool and everything else would go to the default pool. Here is what I have.

 

 

when CLIENT_ACCEPTED {

 

set IPADDR [IP::remote_addr]

 

switch $IPADDR {

 

192.168.100.0/255.255.255.192

 

{

 

pool test_pool

 

}

 

default

 

{

 

pool default_pool

 

}

 

}

 

}

 

 

The actual "syntac" of this rule works, but I can't seem to get the "functionality" to work. Can anyone help with this.

3 Replies

  • I don't think you can do comparisons within the switch conditions. You could try using an if/elseif/elseif/else format:

    
    when CLIENT_ACCEPTED {
       set IPADDR [IP::remote_addr]
       if { [IP::addr $IPADDR equals 192.168.100.0/26] }{
          pool test_pool
       }
       elseif { [IP::addr $IPADDR equals 10.10.0.0/16] }{
          pool condition2_pool
       }
       else {
          pool default_pool
       }
    }

    Aaron
  • thanks for the reply. I can use the if/elseif syntac, but for what i'm trying to do, that would be a long script. We use vlans and most of our segments are 64 and 128 address segments. Campus wide we have about 800 vlans. If I was to elseif all the segments for this, it would be too long. I'm trying to figure out how to use the switch command to list all my variables to test against then send the client to the right pool. Hopefully, i explained it a little better. Thanks
  • You could add your subnets and corresponding pools to a class (called a datagroup in the GUI) and then use the findclass command to get the mapping.

     

     

    Check this post for a related example (Click here)

     

     

    The findclass wiki page also has some good info: (Click here)

     

     

    Aaron