Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[P4Testgen] Revisit handling of varbit in P4Tools/P4Testgen #4318

Open
vlstill opened this issue Jan 5, 2024 · 0 comments
Open

[P4Testgen] Revisit handling of varbit in P4Tools/P4Testgen #4318

vlstill opened this issue Jan 5, 2024 · 0 comments
Labels
p4tools Topics related to the P4Tools back end

Comments

@vlstill
Copy link
Contributor

vlstill commented Jan 5, 2024

The current handling of varbit fields in testgen is somewhat cumbersome and leads to some non-well-typed expressions. When the program contains varbit field, the testgen needs to remember the actual extracted size and it needs to work with the field accordingly.

  • When the field is emitted, the actual size is emitted.
  • When one varbit field is assigned into another (possibly as part of a header), the size of the source is also propagated to the destination. This may change the actual size of the destination.

The current solution uses SizedVarbit/Extracted_Varbit type, which has some problems. E.g., when there is just a varbit extracted (e.g. testgen-p4c-bmv2-protobuf-ir/issue447-bmv2.p4), the packet expression is something like 0 ++ (SizedVarbit<32><16>)|pktvar_0(bit<16>)| which is of type bit<16> but the optimizer turns it into (SizedVarbit<32><16>)|pktvar_0(bit<16>)| which is SizedVarbit<32><16>.

Looking at the other code that relates to varbits, it seems like these are mostly special cases that treat SizedVarbit<M><N> as bit<N>. However, because of varbit assignments, it is not possible to just replace varbit<M> with bit<N> when it is extracted, as that would lead to wrong assignments. At the same time, it is not sufficient to keep the value just as varbit<M> in the header as ween need to keep the runtime size known.

One possibility I can think of would be to save bit<N> in the packet buffer, but something like VarbitCast<M, N> in the header's varbit field. VarbitCast<M, N> would be an expression that would contain a bit<N> typed expression, but it would itself be of type varbit<M>. This way, it would be possible to assign these expressions and the program should be well typed.

More discussion on the problem can be found in PR #4300.

@vlstill vlstill added the p4tools Topics related to the P4Tools back end label Jan 5, 2024
@vlstill vlstill assigned vlstill and fruffy and unassigned vlstill and fruffy Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4tools Topics related to the P4Tools back end
Projects
None yet
Development

No branches or pull requests

2 participants