Skip to content

Add fields to IR and IROptions used by settting the path origin from the YANG module name or a specified name. #1030

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

keogaki
Copy link

@keogaki keogaki commented Apr 15, 2025

…mand option to set the path origin from the YANG module name or an arbitrarily specified name.
@coveralls
Copy link

coveralls commented Apr 15, 2025

Coverage Status

coverage: 88.811% (+0.003%) from 88.808%
when pulling f59371e on keogaki:set_path_origin
into de2c33d on openconfig:master.

@keogaki keogaki changed the title Add fields to IR and IROptions used by settting the path origin from the YANG module name or an specified name. Add fields to IR and IROptions used by settting the path origin from the YANG module name or a specified name. Apr 15, 2025
Copy link
Contributor

@robshakir robshakir left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution -- but this doesn't look like the right design to me. We're adding things to the ygot-generated IR that are not really in-line with what the IR should be specifying -- i.e., pre-parsed details of YANG structures that code-generation can use.

ygen/ir.go Outdated
@@ -312,6 +312,13 @@ type IR struct {
// fakeroot stores the fake root's AST node for creating a serialized
// version of the AST if needed.
fakeroot *yang.Entry

// UseModuleNameAsPathOrigin specifies whether the YANG module name is
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem to make sense in the IR -- rather than storing the argument of the flag, we should rather provide information in the IR for each leaf that specifies what the origin that should be used is.

Copy link
Author

Choose a reason for hiding this comment

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

As you suggested, I modified this to parse the origin name information during IR generation, remove the flag field from IR struct and move the origin name field under NodeDetails struct.

ygen/ir.go Outdated
// set to the origin for generated gNMI paths.
UseModuleNameAsPathOrigin bool

// PathOriginName specifies the orign name for generated gNMI paths.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// PathOriginName specifies the orign name for generated gNMI paths.
// PathOriginName specifies the origin name for generated gNMI paths.

Copy link
Author

Choose a reason for hiding this comment

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

I made a mistaken Re-request review. We will fix later.

Copy link
Author

Choose a reason for hiding this comment

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

This comment was removed.

ygen/genir.go Outdated
opts: opts,
fakeroot: rootEntry,
parsedModules: mdef.modules,
UseModuleNameAsPathOrigin: opts.UseModuleNameAsPathOrigin,
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem the right information to be including in the IR -- you're strictly handing flags that are provided as options back to the caller, rather than doing the parsing for them.

Per the design here: https://github.com/openconfig/ygot/blob/master/docs/code-generation-design.md -- the IR is designed to abstract the details of the YANG away such that multiple downstream consumers can use the same representation.

A better design here would be to have ygen parse the information and populate a field in the IR that is specified per-node (leaf/container/list etc.) that determines what origin should be used for that particular field.

Copy link
Author

Choose a reason for hiding this comment

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

@robshakir
Thanks for your prompt review.
From my understanding of the design, it seems appropreate to add the OriginName field to NodeDetails struct defined in ygen/ir.go and put the desired origin name there depending on the modified IROptions struct value in getOrderedDirDetails() function in ygen/directory.go.
Then, we can retrieve the origin name in pathgen/pathgen.go and remove the both added fields from IR struct.
Is this right approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you can add an Origin field to the YANGNodeDetails struct in ygen/ir.go as one option. Alternatively, you already have BelongingModule there, which seems like it should include the contents that you want already?

Copy link
Author

Choose a reason for hiding this comment

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

I added the origin name filed, PathOriginName, to NodeDetails struct instead of YANGNodeDetails struct, since the origin itself doesn't intirincically related to and isn't always specified by YANG schema. This PR includes not only to set YANG module name to the origin, but also set an arbitrarily name to all the nodes from generator command option.
As you suggested, IR shouldn't convey any option flag from the design policy. If we use the BelongingModule depending on the flag during the code generation, not the IR generation, this is same as the initial commit.

@keogaki keogaki marked this pull request as ready for review April 23, 2025 08:33
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

Successfully merging this pull request may close these issues.

4 participants