Can Tofino2 TCAM support non-contiguous wildcard encoding like 000*1*? How to represent it via control plane?

Hi ,

I have a question about TCAM matching capability on Tofino2, especially regarding non-contiguous wildcard patterns.

Suppose I want to install a TCAM entry with the following bit-level match pattern:

LCP = 000*1*

Here * means don’t care / wildcard, so the intended semantics is:

  • bit[5:3] = 000

  • bit[2] = *

  • bit[1] = 1

  • bit[0] = *

This is not a prefix, and the wildcards are non-contiguous.

My questions:

  1. Does Tofino2 TCAM support this kind of arbitrary bitmask matching?
    That is, can a TCAM entry match something like:

    value = 000010
    mask  = 111010
    
    

    to represent 000*1*?

  2. If yes, how should this be expressed from the P4 control plane?

    • In P4Runtime / BFRT, how can I specify such a bitmask / ternary match?

    • Is it done by explicitly providing (value, mask) pairs?

  3. Are there any hardware constraints or performance implications when using such sparse wildcard patterns in Tofino2 TCAM (e.g., entry expansion, resource overhead, pipeline limitations)?

Background:

I am implementing a range / prefix encoding scheme for packet classification, and some of the generated codes naturally produce patterns like 000*1*, which cannot be expressed as simple prefixes. I want to confirm whether Tofino2 TCAM can directly support this type of encoding, and what the recommended way is to program it via the control plane.

Any insight, examples, or references would be greatly appreciated.

Thanks in advance!

Dear @1418915702 ,

Yes, this is supported! In fact, it is the ability to use non-contiguous masks that separates TCAMs and ternary match kind from lpm one. (As an aside,the lpm’s requirement for the mask to be a contiguous prefix only, allows is to be efficiently supported on other kinds of hardware that requires less area and/or power).

Just declare the key field(s) to have ternary match kind and Tofino compiler will place the table into the TCAM, while at the same time on the control plane size you will see that:

  1. A field f with the ternary match kind will be transformed into a pair of fields: f and f_mask. They will have the same width.
  2. As long as the table has at least one field with the ternary match kind, another field, named $MATCH_PRORITY will be added to the table, so that the control plane API could arrange entries in the TCAM properly.

You can learn more about TCAMs in various courses offered by Intel Connectivity Academy (XFG) by P4ica, e.g. ICA-XFG-101 and ICA-XFG-201. They are available for purchase at P4ica Archives.

Happy hacking,
Vladimir