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] Basic support for @p4runtime_translation and @p4runtime_translation_mappings. #4363

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

fruffy-g
Copy link
Contributor

@fruffy-g fruffy-g commented Jan 25, 2024

This PR adds support for @p4runtime_translation and @p4runtime_translation_mappings in the Protobuf IR back end of P4Testgen. There are two phases.

  1. Since the P4Runtime translation annotations are only attached to the basic type definitions, we add a pass which propagates the annotations to any control plane element which uses the type. We can now reference the annotations when generating tests.

  2. In the Protobuf IR back end, we add two checks for @p4runtime_translation and @p4runtime_translation_mappings. For @p4runtime_translation, we simply override the behavior of the getFormatOfNode function. If a @p4runtime_translation annotation is present, we return the value mapped in the annotation. Otherwise we default for normal behavior.

  3. @p4runtime_translation_mappings are experimental and not well defined, so we simply brute-force inference here. We generate a <cstring, cstring> map which maps the second element in the pair to the first. We also parse the annotation as a list expression. We add a wrapper to formatNetworkValue which overrides the returned value if it is contained in the map.

  4. Tests are missing. These properties are difficult to test with the current infrastructure. We could try to parse some programs which have these annotations.

@fruffy fruffy added the p4tools Topics related to the P4Tools back end label Jan 25, 2024
@fruffy-g fruffy-g force-pushed the fruffy/p4runtime_translation branch 6 times, most recently from ab501fc to f901822 Compare February 1, 2024 15:43
@fruffy fruffy changed the base branch from main to fruffy/metrics February 5, 2024 17:35
@fruffy-g fruffy-g force-pushed the fruffy/p4runtime_translation branch 3 times, most recently from aa6825f to 93929f7 Compare February 8, 2024 19:05
@fruffy fruffy changed the base branch from fruffy/metrics to main February 8, 2024 23:16
@fruffy fruffy force-pushed the fruffy/p4runtime_translation branch from 7f37566 to 3bd0b18 Compare February 9, 2024 14:07
@fruffy-g fruffy-g force-pushed the fruffy/p4runtime_translation branch 2 times, most recently from 6ce09b6 to 5a6b11e Compare February 15, 2024 13:48
/// Tries to find the @format annotation of a node and, if present, returns the format specified
/// in this annotation. Returns "hex" by default.
/// Checks whether the node has a `@p4runtime_translation` attached to it. If that is the case,
/// returns the translated type contained within the annotation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the translated type?

@fruffy fruffy enabled auto-merge (squash) February 15, 2024 21:14
@fruffy fruffy merged commit 662b64d into p4lang:main Feb 15, 2024
16 checks passed
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

Successfully merging this pull request may close these issues.

3 participants