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

What does BMv2 do with a header object in a calculation? #739

Open
jafingerhut opened this issue Mar 24, 2019 · 4 comments
Open

What does BMv2 do with a header object in a calculation? #739

jafingerhut opened this issue Mar 24, 2019 · 4 comments

Comments

@jafingerhut
Copy link
Contributor

From these lines of BMv2 code, it appears that at least when the code was written, it was expected that a checksum verification and/or update calculation could include not only constants and fields, but also entire headers: https://github.com/p4lang/behavioral-model/blob/master/src/bm_sim/P4Objects.cpp#L1391-L1394

I got a little lost in the implementation of how BMv2 actually does the calculation, and had the following questions:

  • Is allowing full headers in calculations intended to be supported?
  • If one appears there, does the calculation's behavior depend upon the validity bit of the header?
  • If so, how?
  • If the header validity bit is ignored, are header fields of invalid headers included in the calculation as garbage/undefined values?
@jafingerhut
Copy link
Contributor Author

Following up on my own question, it appears that the P4_14 language spec says that if a header is in a field list, it should be treated as if it is expanded into all of its fields. If that is true, then probably my last bullet item is the correct answer here, at least for P4_14, and it is up to the P4 programmer to set the conditions for using any calculation result only when its inputs are well-defined.

@antoninbas
Copy link
Member

The implementation is here: https://github.com/p4lang/behavioral-model/blob/master/src/bm_sim/calculations.cpp#L95. It is fairly straightforward since it only supports 3 cases: field, header and constant. We iterate over the members of the "field" list and build a buffer over which the hash is eventually computed. For headers and fields, the buffer is built using the same underlying methods as for the emit implementation in the deparser.

  • if a header is not valid, it is skipped
  • headers must start and end at a byte boundary
  • the last byte of the buffer is padded with 0s if it is incomplete (least significant bits)

@jafingerhut
Copy link
Contributor Author

In your answer "if a header is not valid, it is skipped", I understand that can be useful behavior.

Do you agree that it is a bit different then the P4_14 language specification behavior from Section 2.4 "Field Lists", where it claims the following for a field_list that contains the name of a header variable:

"Each entry may be a specific field instance reference, a header instance (which is equivalent to listing all the header’s fields in order) or a fixed value."

If so, it wouldn't be the first time the implementation diverged a bit from the P4_14 language spec.

I am just digging for a few details here when thinking about how to document the behavior of P4_16 v1model and PSA functions like checksum and hash that are passed lists of "things", if those things happen to be headers. It is not supported to have header values in such lists for v1model, according to the documentation in v1model.p4 comments, and perhaps it shouldn't be supported for PSA, either.

If they are supported, it seems good to nail down these kinds of behavior details, so thanks for the info.

@antoninbas
Copy link
Member

@jafingerhut any follow-up needed on this year-old issue? Or can we close it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants