Range Check In Action Part

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.