p4-spec
p4-spec copied to clipboard
Behavior of next index for extracting to header unions
Personnel
- [x] Owner: @mbudiu-vmw
- [ ] Supporters:
Design
- [x] Document: See below
Implementation
- [ ]
p4-spec
: - [ ]
p4c
: https://github.com/p4lang/p4c/pull/2706
Process
- [ ] LDWG discussed:
- [ ] LDWG approved:
- [ ] Merged into
p4-spec
: - [ ] Merged into
p4c
:
=======================================
The actual issue is described here: https://github.com/p4lang/p4c/pull/3193 The problem is in code like this:
header O1 {
bit<8> data;
}
header O2 {
bit<16> data;
}
struct headers {
S base;
U[2] u;
}
...
packet.extract(hdr.u.next.byte);
packet.extract(hdr.u.next.byte);
According to the current spec, this should not increment the next
counter: https://p4.org/p4-spec/docs/P4-16-v1.2.2.html#sec-packet-extract-one
But arguably that is the wrong behavior, and extracting to a header union within a stack should advance the stack pointer.
There is also this section: https://p4.org/p4-spec/docs/P4-16-working-spec.html#sec-parse-header-stacks
The expression mpls.next represents an l-value of type Mpls_h that references an element in the mpls stack. Initially, mpls.next refers to the first element of stack. It is automatically advanced on each successful call to extract. The mpls.last property refers to the element immediately preceding next if such an element exists. Attempting to access mpls.next element when the stack's nextIndex counter is greater than or equal to size causes a transition to reject and sets the error to error.StackOutOfBounds. Likewise, attempting to access mpls.last when the nextIndex counter is equal to 0 causes a transition to reject and sets the error to error.StackOutOfBounds.
Which might be a little too vague in this case then.
There is some pseudocode there too which is precise but different. The pseudocode was written before we introduced header unions.
The green block is the pseudocode.
Related to https://github.com/p4lang/p4-spec/issues/876
In the interest of tidying up the set of active issues on the P4 specification repository, I'm marking this as "stalled" and closing it. Of course, we can always re-open it in the future if there is interest in resurrecting it.