-
Notifications
You must be signed in to change notification settings - Fork 106
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
Support explicitly setting field tags #339
base: master
Are you sure you want to change the base?
Support explicitly setting field tags #339
Conversation
The YANG to Protobuf specification mentions using extensions to explicitly set the field tag of generated Protobuf fields. Add support for annotating field tags. * Support setting the field number with occodegenext:field-number. * Support offsetting the field number with occodegenext:field-number-offset. * Reject field number annotations that result in a value in the Protobuf reserved range.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for helping to meet the specification, looks like this implementation was missing.
Could you also add an integration test by modifying one of the yang files used as a test for TestGenerateProto3 within codegen_test.go?
Added an integration test and changed the code to only allow annotated field numbers in range 1-1000. |
Hi Jason, thanks for your changes. It seems that ygot doesn't have good support for extensions (no helpers), and as a result I see two immediate concerns (due to this ygot limitation). I've listed them below and some thoughts on how to address them. I'd like to answer these concerns before this change is merged. Would be happy to hear your thoughts on it.
Thoughts on solutions:
|
Hi Wen, The proposed solutions make sense to me. My take on the edge cases
|
TLDR: In any case, I agree that we should add both duplicate-check and overlap-check functionality into proto generation, if you don't mind. Then, assuming the extensions get pushed (and there is no objections right now), goyang's Thanks Jason. It's a good point that it's hard to rule out allowing duplicate extensions in general. However, following the idea that ygot should throw an error if the extension's sematics is invalid, then at least for this extension it should also error out on duplicates. It totally makes sense to me that if there is an error, that ygot should be able to catch it before it causes any trouble, as ygot is responsible for generating usable proto in the first place, and has already assumed understanding of everything about proto generation in order to always generate valid and usable protos. |
On further thought, should we allow multiple Erroring on getting multiple |
Good eye, nested uses statements definitely makes sense as a use-case to me. Added openconfig/goyang#113 to test extensions for nested use statements. List of Error Checks:
|
@jasonewang btw I'm working on getting your changes in. |
I have the change ready now, though it's dependent on openconfig/goyang#183. |
Credits to @jasonewang for posting the first implementation at #339. I've modified this a bit to read the extension values from the new openconfig-codegen-extensions.yang model that's now in openconfig/public, and also to address some of the corner cases that were discussed in the PR. Spec: https://github.com/openconfig/ygot/blob/master/docs/yang-to-protobuf-transformations-spec.md#field-numbering Corner cases not mentioned in the spec: 1. multiple `field-number` extensions. - Error out. 1. multiple `field-number-offset` extensions. - Add them up. 1. `field-number` or `field-number-offset` extensions on non-leaves. - Silently ignore. 1. `field-number-offset` on non-uses statements, including leafs. - Allow. 1. Conflicts. - Allow. The proto compilation will of course fail. Automated checking can be added here if we'd prefer. I made some simple choices for the above items. Erroring out for 3 and 4 would likely require changing `goyang` to specifically support checking these cases, which I'm not sure is worth it here.
@jasonewang Do you think you could consent again at #549? Thanks. For some reason googlebot needs another consent if the PR submitter changed. |
Credits to @jasonewang for posting the first implementation at openconfig#339. I've modified this a bit to read the extension values from the new openconfig-codegen-extensions.yang model that's now in openconfig/public, and also to address some of the corner cases that were discussed in the PR. Spec: https://github.com/openconfig/ygot/blob/master/docs/yang-to-protobuf-transformations-spec.md#field-numbering Corner cases not mentioned in the spec: 1. multiple `field-number` extensions. - Error out. 1. multiple `field-number-offset` extensions. - Add them up. 1. `field-number` or `field-number-offset` extensions on non-leaves. - Silently ignore. 1. `field-number-offset` on non-uses statements, including leafs. - Allow. 1. Conflicts. - Allow. The proto compilation will of course fail. Automated checking can be added here if we'd prefer. I made some simple choices for the above items. Erroring out for 3 and 4 would likely require changing `goyang` to specifically support checking these cases, which I'm not sure is worth it here.
@robshakir I realized I can just push to Jason's fork. When you have time could you take a look? changes at ygen/protogen.go |
The YANG to Protobuf specification mentions using extensions to explicitly set
the field tag of generated Protobuf fields. Add support for annotating field
tags.
Support setting the field number with occodegenext:field-number.
Support offsetting the field number with occodegenext:field-number-offset.
Reject field number annotations that result in a value in the Protobuf
reserved range.