p4c: Recirculation does not always copy metadata

This applies to resubmit and probably to clone (Did not try).

Metadata fields are not copied to the recirculated packet unless you copy the entire metadata struct or you create a tuple of individual fields. For example if you have:

struct metadata_t {
   bit<8> count;
}
struct metadata { 
    metadata_t meta1;
    metadata_t meta2;
}

The metadata will be copied in the following cases:

recirculate(meta);
recirculate({meta.meta1.count, meta.meta2.count});

However, I remember (and just tested) that with older versions of bmv2/p4c copying only some structs from the main metadata worked. And the following does not work anymore:

recirculate(meta.meta1);
recirculate({meta.meta1, meta.meta2});

Is this a bug or it’s an intended behaviour ? I personally think that the previous way made it quite easier, for example when you want to copy an entire structure that has 10s of fields.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 80 (74 by maintainers)

Commits related to this issue

Most upvoted comments

@hesingh The goal is to support recirculation in v1model.

Having references would not solve anything. In architectures like Tofino the hardware does not support call-by-reference. Compiling references (in general) for such an architecture may be impossible. Field lists were used only in some very specific ways, and they match very closely the way BMv2 is implemented, that’s why they worked fine for P4-14. The only type of architecture that would really benefit from having references is a software switch.

Even for the case of PSA, there are no shared resources between ingress and egress, so there is no way one can pass a reference between these two. So having references would not help at all.

I think that copy-in/copy-out actually matches quite closely the capabilities of hardware switches, that are deeply pipelined and have lots of parallel non-shared resources.

All our difficulties are confined to v1model. I think that the psa solution is actually very adequate. We should consider v1model a legacy architecture that should be maintained, but not one that has to be evolved.