Closed apratimmukherjee closed 2 years ago
It looks like you're using TogNMINotifications
, which marshals output into scalar types. Indeed scalar types doesn't support unkeyed lists because there is no way to specify, using the current gNMI specification, a path that points to a particular element within an unkeyed list. This is certainly a limitation of YANG/gNMI.
It looks to me that in order for you to marshal these state data, you would need to marshal the value to a JSON value, for example using ygot.Marshal7951
.
@robshakir I'm thinking one way to support keyless lists for TogNMINotifications
is to just call Marshal7951
whenever we hit them, and package them in a TypedValue_JsonIetf{}
. This functionality is already set-up, we just need to uncomment the block of code OP referenced and add it to leaves
:
https://github.com/openconfig/ygot/blob/6f722a0cce2a47949294afa0c3f23b080d51e501/ygot/render.go#L643-L657
https://github.com/openconfig/ygot/blob/6f722a0cce2a47949294afa0c3f23b080d51e501/ygot/render.go#L423-L433
@wenovus , Thanks a ton for the quick reply. We will definitely explore your suggestion to " to marshal the value to a JSON value, for example using ygot.Marshal7951" to solve the problem. We will probably be able to provide an update within a few days or by beginning of the next week.
@wenovus, Thanks a lot. We are able to solve the issue using Marshal7951
- using EncodeTypedValue
with Encoding_JSON_IETF
encoding format. I am closing this issue.
@robshakir, adding the new function TypedValue_JsonIetf{}
will be very helpful. At present, EncodeTypedValue() with Encoding_JSON_IETF format works for GoStruct
and sliceToScalarArray()
but fails for slice of structs. So, if we use the function for a container having keyless list of AS-Path, it works perfectly. But fails if try to use the function to encode directly the slice of AS-path(s).
We are facing some issues when trying to generate ygot stubs for gnmi model with keyless lists for AS Path segments and Community in BGP RIB routes. We have our own variant of the gnmi definition but attempt to keep it similar to open-config . https://github.com/open-traffic-generator/models-yang/blob/main/artifacts/open-traffic-generator-bgp.txt
When trying to add as-path and community to BGP telemetry for learned routes, ideally we would like them to be key-less lists like in openconfig specification:
| | +--ro as-path | | | +--ro as-segment* [] <<<< | | | +--ro state | | | +--ro type? oc-bgpt:as-path-segment-type | | | +--ro member* oc-inet:as-number
But when we try to use ygot to generate the stubs for these key-less lists and then try to fetch the routes with AS Path, we seem to be hitting this issue in ygot code generation: https://github.com/openconfig/ygot/blob/master/ygot/render.go :: findUpdatedLeaves()... case reflect.Slice: if fval.Type().Elem().Kind() == reflect.Ptr { // This is a keyless list - currently unsupported for mapping since there is // not an explicit path that can be used. errs.Add(fmt.Errorf("unimplemented: keyless list cannot be output: %v", mapPaths[0])) <<< hitting this. continue } // This is a leaf-list, so add it as though it were a leaf. for _, p := range mapPaths { leaves[&path{p}] = fval.Interface() } ....
Is this really not supported? Or are we missing something in our understanding here. One way which is working is to add a dummy key such as a sequence no. but this does not seem to be ideal.