Reputation: 61
I'm studying on the p4 program code recently. However, I do not understand what does this 'current(0,4)' mean in the parser.p4.
parser parse_mpls_bos {
extract(mpls_bos);
return select(current(0, 4)) {
0x4 : parse_ipv4;
default : ingress;
}
}
The header for mpls_bos
header_type mpls_t {
fields {
label : 20;
tc : 3;
bos : 1;
ttl : 8;
}
}
Which fields should be equals to 0x4 here to parse_ipv4? Can someone help to explain/answer?
Thanks in advance.
Upvotes: 0
Views: 101
Reputation: 1
current
allows you to reference bits that have not been parsed yet without extract them. It is a valid statement in p4_14 but is not available in p4_16.
The first argument of current
is the bit offset, 0 in this case means that you're pointing at the end of the mpls_bos
header. The second argument is the width in bits.
Since MPLS layer does not contain information regarding what the next header is, here the code is working on the assumption that if the 4 bits following the MPLS header are equal to 4 then it means you are parsing the version field of the IPv4 header.
In the parse_ipv4
state you can extract the IP header without issues since the first 4-bits of its header have been used for the transition but not yet extracted.
Upvotes: 0