P4 Match action tables with "range" as the match kind

Any examples for implementing rules in p4 match action table with range as matchkind via p4runtime? I see an unknown grpc error while passing the range as a python list for writeTableEntry function. Any kind of guidance will be appreciated.

Hi :wave:

Could you post the code you are using to install the rule?

Thank you!

Hi @ederollora ,

Thank you so much for your response. Here you go, the code.

Metadata Declaration

bit<16> meta_1;
bit<14> class;

Table declaration in p4 code

table table_1  {
         key = {
               meta.meta_1: range
           }
         actions = {
                action_1;
           }
         size = 1024;
    }

action action_1(bit<14> flag)
{
           meta.class = flag;
}

Control plane:
(Please pardon the indentation)

def writeRules(p4infoHelper, ingress_sw, range_list, flag_value):
        table_entry = p4info_helper.buildTableEntry(
                  table_name="MyIngress.table_1",
                  match_fields = {
                         "meta.meta_1": range_list
                  },
                  action_name = "MyIngress.action_1",
                  action_params={
                          "flag": flag_value,
               })
          ingress_sw.WriteTableEntry(table_entry)

Function call:

writeRules(p4info_helper, s1, [100, 150], 1)

This is a tricky one. If you check buildTableEntry at helper.py in the tutorials:

def buildTableEntry(self, (...), match_fields=None, (...)):
    if match_fields:
            table_entry.match.extend([
                self.get_match_field_pb(table_name, match_field_name, value)
                for match_field_name, value in match_fields.items()
            ])

then we check get_match_field_pb at helper.py too:

def get_match_field_pb(self, table_name, match_field_name, value):
    # (...)
    elif match_type == p4info_pb2.MatchField.RANGE:
            lpm = p4runtime_match.range
            lpm.low = encode(value[0], bitwidth)
            lpm.high = encode(value[1], bitwidth)

So I actually expect that you pass by a list like you did (or maybe a tuple)?.

I can see form the tutorials that the controller passes (dst_ip_addr, 32) when installing an LPM rule. That seems tu be a tuple, have you tried the same? I mean: writeRules(p4info_helper, s1, (100, 150), 1)

I am really not sure about the error so it would be nice the help of someone else if you do not manage to solve it this time.

Could you post the error log too?

Cheers,

Hi @ederollora,

The tuple didn’t work either. So I am posting a bunch of log messages that are concerning to me.

  1. P4DeviceConfig is deprecated message: I am using the tutorial vms only and I see this deprecated message in the logs.
New connection
P4Runtime SetForwardingPipelineConfig
[04:22:59.023] [bmv2] [W] [thread 3015] [P4Runtime] p4::tmp::P4DeviceConfig is deprecated
[04:22:59.025] [bmv2] [D] [thread 3015] Set default default entry for table 'tbl_act': act_1 -
[04:22:59.025] [bmv2] [D] [thread 3015] Set default default entry for table 'tbl_act_0': act -
  1. hdr.ipv4.isValid() returning false while it should be true

[04:22:59.026] [bmv2] [D] [thread 3024] [0.0] [cxt 0] Table 'tbl_act': miss
[04:22:59.026] [bmv2] [D] [thread 3024] [0.0] [cxt 0] Action entry is act_1 -
[04:22:59.026] [bmv2] [T] [thread 3024] [0.0] [cxt 0] Action act_1
[04:22:59.026] [bmv2] [T] [thread 3024] [0.0] [cxt 0] Primitive (no source info)
[04:22:59.026] [bmv2] [T] [thread 3024] [0.0] [cxt 0] basic.p4(185) Condition "hdr.ipv4.isValid()" (node_3) is false
[04:22:59.026] [bmv2] [D] [thread 3024] [0.0] [cxt 0] Pipeline 'ingress': end

  1. P4Runtime Write
[04:22:59.027] [bmv2] [D] [thread 3024] [1.0] [cxt 0] Parser 'parser': end
P4Runtime Write
election_id {
  low: 1
}
updates {
  type: MODIFY
  entity {
    table_entry {
      table_id: 33574068
      action {
        action {
          action_id: 16805608
        }
      }
      is_default_action: true
    }
  }
}
[04:22:59.028] [bmv2] [D] [thread 3024] [1.0] [cxt 0] Pipeline 'ingress': start


[04:22:59.029] [bmv2] [D] [thread 3024] [2.0] [cxt 0] Extracting header 'ethernet'
P4Runtime Write
election_id {
  low: 1
}
updates {
  type: INSERT
  entity {
    table_entry {
      table_id: 33574068
      match {
        field_id: 1
        lpm {
          value: "\n\000\001\001"
          prefix_len: 32
        }
      }
      action {
        action {
          action_id: 16799317
          params {
            param_id: 1
            value: "\000\000\000\000\001\001"
          }
          params {
            param_id: 2
            value: "\000\001"
          }
        }
      }
    }
  }
}
[04:22:59.029] [bmv2] [D] [thread 3024] [2.0] [cxt 0] Parser state 'start': key is 86dd

Any kind of guidance will be appreciated. Thank you very much in advance.

Best,
Aparna

Hi,

Could you share your P4 pipeline? I could try to see if I can test it in the following days :slight_smile:

Cheers,