[P4Testgen] Basic support for @p4runtime_translation
and @p4runtime_translation_mappings
.
#4363
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for
@p4runtime_translation
and@p4runtime_translation_mappings
in the Protobuf IR back end of P4Testgen. There are two phases.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.
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 thegetFormatOfNode
function. If a@p4runtime_translation
annotation is present, we return the value mapped in the annotation. Otherwise we default for normal behavior.@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 toformatNetworkValue
which overrides the returned value if it is contained in the map.Tests are missing. These properties are difficult to test with the current infrastructure. We could try to parse some programs which have these annotations.