Forum Discussion

hooleylist's avatar
hooleylist
Icon for Cirrostratus rankCirrostratus
Oct 07, 2009

matchclass versus class in v10 for address comparisons?

Is there any advantage to using class match versus matchclass to evaluate an IP address against an address type datagroup?

Here is a simple iRule I used to test class/matchclass for an IP against the AOL datagroup. Both commands seem to return expected results (with matchclass returning the record number of the matched result).

 
 when RULE_INIT { 
    log local0. "\[class match 205.188.112.0 equals aol\]: [class match 205.188.112.0 equals aol]" 
    log local0. "\[class match 1.1.1.1 equals aol\]: [class match 1.1.1.1 equals aol]" 
    log local0. "\[matchclass 205.188.112.0 equals aol\]: [matchclass 205.188.112.0 equals aol]" 
    log local0. "\[matchclass 1.1.1.1 equals aol\]: [matchclass 1.1.1.1 equals aol]" 
 } 
 

And the log output from one TMM:

[class match 205.188.112.0 equals aol]: 1

[class match 1.1.1.1 equals aol]: 0

[matchclass 205.188.112.0 equals aol]: 7

[matchclass 1.1.1.1 equals aol]: 0

Thanks,

Aaron

16 Replies

  • I was reading in the wiki under matchclass that matchclass is deprecated in version 10. Also, it said that if you do something like this: [matchclass [HTTP::uri] starts_with $::my_data_class] that $::my_data_class name will now return the name of the data class instead of a list.

     

     

    I understand that using class is better but what about compatibility for upgrading. If what I read is true, I have to rewrite a large number of iRules before I come up on version 10. I am running version 9.6 now.

     

     

    I would appreciate it if anyone could clarify.

     

     

    Regards,

     

     

    Tom Schaefer
  • Hi Tom,

    The minimal change you have to make is to remove the $:: prefix from the datagroup names in the iRules. If you do this you can continue to use findclass and/or matchclass in v10 or v11 as you did in v9.

    To gain performance you should ideally change matchclass and findclass to the corresponding class sub-commands. You can also take advantage of the new name=value pairs available in 10.1+ using the class command with the -value option. This last option would require changing your string datagroups from a "key value" space separated format to the new name=value format:

    class string_name_value_class {
       {
          "key1" { "value1" }
          "key2" { "value2" }
       }
    }
    class address_name_value_class {
       {
          host 1.1.1.1 { "value1" }
          network 1.1.2.0/24 { "value2" }
       }
    }
     Sample iRule which gets the value for a string datagroup entry and an address datagroup entry
    when RULE_INIT {
       set value [class match -value "key1" equals string_name_value_class]
       log local0. "Looked up key1 and found $value"
       set value [class match -value 1.1.2.25 equals address_name_value_class]
       log local0. "Looked up 1.1.2.25 and found $value"
    }

    Log output:

    Looked up key1 and found value1

    Looked up 1.1.2.25 and found value2

    Aaron
  • Thanks. I do things now like have multiple data elements related to the row separated by a vertical bar. I then use getfield to break it out. So, if I do a findclass, I then parse the row returned (all after the key in the case of findclass). Is there asimilar concept in that I can have multiple name and valus pairs on a row or should I get away from the row mentality?

     

     

    Thanks,

     

     

    Tom
  • Sure. You can just move that to the value portion:

    
    class string_name_value_class {
       {
          "key1" { "value1a|value1b|value1c" }
          "key2" { "value2a|value2b|value2c" }
       }
    }
    

    Aaron
  •  

     

    Hi Tom,

     

     

    The closing Bracket is missing in your Example :-)

     

    class string_name_value_class {

     

    {

     

    "key1" { "value1" }

     

    "key2" { "value2" }

     

    }

     

    }

     

     

    class address_name_value_class {

     

    {

     

    host 1.1.1.1 { "value1" }

     

    network 1.1.2.0/24 { "value2" }

     

    }

     

    }

     

     

    Sample iRule which gets the value for a string datagroup entry and an address datagroup entry

     

    when RULE_INIT {

     

     

    set value [class match -value "key1" equals string_name_value_class]

     

    log local0. "Looked up key1 and found $value"

     

     

    set value [class match -value 1.1.2.25 equals address_name_value_class]

     

    log local0. "Looked up 1.1.2.25 and found $value"

     

    }

     

     

     

     

    Regards

     

     

    wiesmann

     

     

  • Hi Juerg,

     

     

    That was my bad copy/paste. Thanks for pointing it out. I edited my post.

     

     

    Aaron