I am think can I delete or add the header field. For example, I have a custom header
header custom_h{
bit<8> field 0;
bit<8> field 1;
bit<8> field 2;
bit<8> field 3;
}
After the PHV go through all the match-action table. I want to add or delete some field, let the custom header becomes:
header custom_h{
bit<8> field 0;
bit<8> field 1;
}
or
header custom_h{
bit<8> field 0;
bit<8> field 1;
bit<8> field 2;
bit<8> field 3;
bit<8> field 4;
bit<8> field 5;
}
is it possible?
Certainly, but not really be adding or deleting fields from a single header type in the same program.
One way is to define 3 header formats: one with 2 fields, one with 4 fields, and one with 6 fields. When you make a decision which one of those you want, make that one header valid using setValid(), then initialize the values of all fields that you want to be in that header, and then if necessary, use setInvalidate() to remove the original header, if it was a different one than the one you just did setValid() on.
Another way: Define a single header with 2 fields, and when parsing, extract two instances of it, one immediately after the other, so that you extract 4 bytes from the packet header.
Later, either:
(a) invalidate the second one, so that only one 2-byte header is still valid
(b) make a new third instance of the header valid, and then initialize its fields to the values you want, so that there are 3 2-byte headers that are all valid.
(c) neither, leaving the original 2 2-byte headers valid.
I am sure there are other ways, but these two should be enough to start. you thinking about the options.
1 Like