Range Check In Action Part

Here is the complete description of my problem, Please read it completely and help me.

What I want to do is, first check 1 field of the incoming packet in the Match-Part of the table then I want to check another field of the incoming packet in the action part of the same table and then set a marker field.

Here In the Action Part, I don’t want to hardcode the values whose against I will do a range check. I want them to be dynamic or their values should be able to modify.

After that, I want to use that marker field in the second table that is sequentially after the first table in the pipeline and when a packet goes out then the marker field should be dropped.

I will once again brief my main problems.
1)How to do a range check over any field in the action part of the table and how the p4 code will look for doing this. I had heard about some limits also applied to range check in the action part, if there is something like this please enlighten about that also.

2)In the same action part of, How to set marker bit/field.

3)How to use that marker field in the second subsequent table.

Sorry for not providing a complete example, but maybe something to get you going.

You can of course use the match kind range in the key of a P4 table to indicate that you want a key to match an entry only if the value of that field in the key is within the [min, max] range configured when the control plane adds an entry to the table.

If you want to do more checks after matching a particular table entry, in the action, then one way would be to write an action that looks like this:

action checkRange (bit<16> min_val, bit<16> max_val) {
marker = ((min_val <= hdr.some.field) && (hdr.some.field <= max_val)) ? 1 : 0;
}

Doing this will allow you to choose min_val and max_val independently for each entry you add to the table, but except for the control plane modifying entries or adding new entries, you will not be able to change those ranges merely from a packet being processed and executing your P4 program.

After executing an action like the above, the value of marker will be assigned a value of 1 or 0, based on the condition shown, and you can use it however you wish in later table keys, actions, and/or if statements. To use it as a key in a table, just do something like key = { marker : exact; /* more keys here if you wish */ } in the definition of that later table. You need not use ‘exact’ as in my example, e.g. you could do ternary, lpm, range, etc., although for a 1-bit field exact or ternary would be the most likely to be useful.

Hello Andy
Thank you for your reply, it is quite helpful and gave a thought to me about working of things.

Due to some issues I was not able to work on it but as I started working on my problem it comes out that I have a little bit different thing to implement.
So I am explaining It little bit more.

1)For a given entry in table, I have more than 1 ranges. The example you gave is about 1 range so how will I handle more than 1 ranges is action part because the packet will only lie in one of these ranges.

Do I need to pass all the min_vals and max_vals to action function or is there some other way of doing this available.

Is there any functionality like array available in P4.

2)How will I pass these values action function from table, do I need to specify them in json file or is there any other way possible to pass the values to action function.

3)Is it possible to implement dynamic ranges in action function like if the values of ranges changes , I don’t need to modify code ?

Hello p4 community, please help me with some other details about p4.
1)How to use registers in p4_16 , can i directly assign values to them from table/control plane or i have to assign values to them manually in code.

2)I want to change the rules stored in a table and those changed rules I want to store in another table to do some extra checks. How to store changed rules in another table.
I think that I will need another header and think of using a struct metadata header but still not sure how to assign the values of the changed rule to this header.

I will explain 2nd point again, In my original table i am using hdr.ipv4.dst_addr as match part values but i needed to change these values and created some new rules that needed to change before this and those new rules i am storing in a new table, and the problem is these values are not standard values so i don’t know how to store these rules/values in new table and then do a check on them.

Please anyone who can help me, help me , i will be grateful to you.
Thank you in advance.

Hello Andy
I don’t know why nobody is replying me on the forum so i am asking question here.

Could please tell me that can we use Resisters in p4_16 or not and if we can then how we do it?

I asked other queries on forum, please answer those also.

Thank you
Aryan Sharma

Registers are not part of the base P4_16 language. They are part of several P4_16 architectures, including v1model, PSA, and TNA, with somewhat differing APIs.

All of the register implementations I am aware of enable you to do the following operations:

  • from the control plane:
    • read the value from one index at a time
    • write a value to one index at a time
  • from the data plane:
    • read the value of one index
    • write the value at one index
    • read the value at one index, calculate a new value, and write that new value back to the same index

The purely software-based implementations like BMv2 also allow multiple reads and writes to the same register for a single packet, but for a high speed 1-packet-per-clock-cycle-throughput device like Tofino, that is not possible because of memory bandwidth reasons, and you are limited to the operations I describe above for a single packet and a single register (although you can access multiple P4 registers while processing a single packet, but each register at most once per packet).

An example of using the register extern included with the v1model architecture can be found here: p4-guide/demo6.p4_16.p4 at master · jafingerhut/p4-guide · GitHub

If you want examples of using the registers in a different architecture, please specify which one you are interested in.

aryansh007 wrote:
1)For a given entry in table, I have more than 1 ranges. The example you gave is about 1 range so how will I handle more than 1 ranges is action part because the packet will only lie in one of these ranges.

Do I need to pass all the min_vals and max_vals to action function or is there some other way of doing this available.

Andy replies: Yes, you can pass all min_vals and max_vals to a single action, and have multiple range checks performed within the same action. I am sure there are other ways, but that way is straightforward and should do what you want.

Is there any functionality like array available in P4.

Andy replies: There are currently no arrays available in P4, except in the form of header stacks, which are like arrays, but each element is a value with the same header type.

aryansh007 wrote:
2)How will I pass these values action function from table, do I need to specify them in json file or is there any other way possible to pass the values to action function.

Andy replies: Every parameter of an action that is an action of some table, that doesn’t have a direction like in/out/inout, must have the value of that action parameter specified by the control plane software when it adds an entry to the table that uses the action.

Any json file you are describing, e.g. like used in the p4lang/tutorials repository, is a special custom-crafted json schema for those examples, and are basically always implemented by having some control plane software read the json file, and then make the necessary control plane calls to add the desired table entries to the data plane. They typically only let you specify the initial table entries to add when the control plane software starts up, but after that they will never change. You can write whatever control plane software you want, that could read from a json or any other file format you want to describe initial table entries, if you wish, or you can write control plane software that never reads from any files at all, and uses other mechanisms to decide what table entries to add. Control plane software is a program you can write, and do whatever you want it to do.

aryansh007 wrote:
3)Is it possible to implement dynamic ranges in action function like if the values of ranges changes , I don’t need to modify code ?

Andy replies: If the min and max values are parameters of actions that are installed as table entries, then without changing any P4 code, you can change the action parameters by modifying the entries currently installed in a table, deleting entries in a table, adding new entries to a table, etc. from the control plane software.