ygot icon indicating copy to clipboard operation
ygot copied to clipboard

Does ygot support widlcard in a path ?

Open adibrastegarnia opened this issue 6 years ago • 13 comments

I would like to know if ygot supports wildcard in a path when it retrieves a node from the config tree?

adibrastegarnia avatar Aug 05 '19 16:08 adibrastegarnia

It looks there is a PR already merged for that but I am wondering why it doesn't work for us?

adibrastegarnia avatar Aug 05 '19 16:08 adibrastegarnia

For example:

gnmi_cli -address localhost:10161 -get \
    -proto "path: <elem: <name: 'system'> elem: <name: 'openflow'> elem: <name: '*'>>" \
    -timeout 5s -alsologtostderr \
    -client_crt $ONOS_SIMULATORS_ROOT/pkg/certs/client1.crt \
    -client_key $ONOS_SIMULATORS_ROOT/pkg/certs/client1.key \
    -ca_crt $ONOS_SIMULATORS_ROOT/pkg/certs/onfca.crt;;

adibrastegarnia avatar Aug 05 '19 16:08 adibrastegarnia

It's difficult to debug this with insight into your code, but you may want to check that you're using the right options. Handling wildcards is an option handed to GetNodes: https://github.com/openconfig/ygot/blob/master/ytypes/node.go#L333

robshakir avatar Aug 06 '19 00:08 robshakir

Thanks for your response. I didn't know about that. I will take a look.

adibrastegarnia avatar Aug 06 '19 15:08 adibrastegarnia

@robshakir I got the latest release and go.mod file is updated accordingly but it looks like it still cannot find that prototype:

have (*yang.Entry, ygot.ValidatedGoStruct, *gnmi.Path, ytypes.GetNodeOpt)
	want (*yang.Entry, ygot.GoStruct, *gnmi.Path)

adibrastegarnia avatar Aug 06 '19 16:08 adibrastegarnia

I think it was because I was trying to use the experimental version.

adibrastegarnia avatar Aug 06 '19 16:08 adibrastegarnia

@robshakir We are using this function in our code: node, stat := ygotutils.GetNode(s.model.schemaTreeRoot, s.config, &path)

I tried to use the one in the ytypes but it looks like that is not compatible with this one in terms of type casting. I mean the return values are different. For example, after changing our code to use the new one, the following line doesn't work: nodeStruct, _ := node.(ygot.GoStruct) Please advise if those changes are possible at all.

adibrastegarnia avatar Aug 06 '19 16:08 adibrastegarnia

There is no intention to make the experimental and non-experimental versions of this code compatible with each other. The return type from the public API version is a TreeNode - which has the interface{} type in its return value. This is documented in the GoDoc and the comments in the ytypes/node.go file -- please take a look there, it should be relatively trivial to refactor here.

robshakir avatar Aug 06 '19 17:08 robshakir

Thanks. I will try it.

adibrastegarnia avatar Aug 06 '19 19:08 adibrastegarnia

@robshakir It was a long time ago that I asked this question and I couldn't find time to do refactoring. I started to do some refactoring and I changed the code this way:

               opts := make([]ytypes.GetNodeOpt, 1)
		opts[0] = &ytypes.GetHandleWildcards{}

		var err error
		node, err := ytypes.GetNode(s.model.schemaTreeRoot, s.config, fullPath, opts[0])
		if isNil(node) || err != nil {
			return nil, err
		}

but when I run the above example, I am getting this error:

E1011 19:06:14.449135 45324 gnmi_cli.go:180] target returned RPC error for Get("path:<elem:<name:\"system\" > elem:<name:\"openflow\" > elem:<name:\"*\" > > "): rpc error: code = InvalidArgument desc = no match found in *gostruct.OpenconfigSystem_System_Openflow, for path elem:<name:"*" >

I don't see any test case for wildcard. Have you tested it before?

Thanks, Adib

adibrastegarnia avatar Oct 11 '19 23:10 adibrastegarnia

If my understanding is correct, for the above case this function is called: https://github.com/openconfig/ygot/blob/master/ytypes/node.go#L92 which does not handle wildcard. I am wondering what types of wildcard path you support in ygot?

Thanks, Adib

adibrastegarnia avatar Oct 11 '19 23:10 adibrastegarnia

Hi guys. Any update on this? I'm unable to make it work.

demzys avatar Oct 30 '23 10:10 demzys

Currently, I believe our support for wildcards is just for wildcards in the key of a list, rather than for path elements. Such support could be added, but I don't think we've had significant demand for it. I'd be happy to help with a contribution to add it to the code base :-)

robshakir avatar Nov 03 '23 17:11 robshakir