Skip to content

Correctly model packet_in.extract semantics wrt header stacks #273

@asl

Description

@asl

Consider the following code:

header H {
    bit<8>     s;
    varbit<32> v;
}

header Same {
    bit<8> same;
}

struct headers {
    H h;
    H[2] a;
    Same same;
}

parser p(packet_in b,
                out headers hdr,) {
    state start {
        b.extract(hdr.h, 32);
        b.extract(hdr.a.next, 32);
        b.extract(hdr.a.next, 32);
        transition accept;
    }
}

P4 spec says:

void packet_in.extract<T>(out T headerLValue) {
   bitsToExtract = sizeofInBits(headerLValue);
   lastBitNeeded = this.nextBitIndex + bitsToExtract;
   ParserModel.verify(this.lengthInBits >= lastBitNeeded, error.PacketTooShort);
   headerLValue = this.data.extractBits(this.nextBitIndex, bitsToExtract);
   headerLValue.valid$ = true;
   if headerLValue.isNext$ {
     verify(headerLValue.nextIndex$ < headerLValue.size, error.StackOutOfBounds);
     headerLValue.nextIndex$ = headerLValue.nextIndex$ + 1;
   }
   this.nextBitIndex += bitsToExtract;
}

Note the special case wrt header stacks – extraction also increments nextIndex and does verify. We'd need to to this during corelib dialect lowering.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomers

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions