请教:yang模型中的union类型怎么赋值才能通过ODL的校验?


最近在做netconf协议应用,使用ODL控制器来验证。
遇到了一个union类型的赋值问题,请懂的大神帮忙指导一下,谢谢!

引用的是标准Yang模型,关键部分定义如下:

identity OPENCONFIG_HARDWARE_COMPONENT {
description
"Base identity for hardware related components in a managed
device. Derived identities are partially based on contents
of the IANA Entity MIB.";
reference
"IANA Entity MIB and RFC 6933";
}

identity CHASSIS {
base OPENCONFIG_HARDWARE_COMPONENT;
description
"Chassis component, typically with multiple slots / shelves";
}

leaf type {
type union {
type identityref {
base oc-platform-types:OPENCONFIG_HARDWARE_COMPONENT;
}
type identityref {
base oc-platform-types:OPENCONFIG_SOFTWARE_COMPONENT;
}
}
description
"Type of component as identified by the system";
}

设备通过netconf协议返回xml数据,其中union类型的type填充了字符串CHASSIS,具体报文如下:
<?xml version="1.0" encoding="utf-8"?>
<data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<components xmlns="http://openconfig.net/yang/platform";>
<component>
<name>OTN100</name>
<state>
<name>OTN 100</name>
<admin-status>up</admin-status>
<type>CHASSIS</type>
.....

通过ODL请求rest接口返回这个异常:
java.lang.IllegalArgumentException: Invalid data "CHASSIS" for union type.
at org.opendaylight.yangtools.yang.data.util.AbstractStringUnionCodec.serialize(AbstractStringUnionCodec.java:47)
at org.opendaylight.yangtools.yang.data.codec.gson.JSONStringUnionCodec.serializeToWriter(JSONStringUnionCodec.java:30)
at org.opendaylight.yangtools.yang.data.codec.gson.JSONNormalizedNodeStreamWriter.writeValue(JSONNormalizedNodeStreamWriter.java:226)
at org.opendaylight.yangtools.yang.data.codec.gson.JSONNormalizedNodeStreamWriter.leafNode(JSONNormalizedNodeStreamWriter.java:116)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.wasProcessAsSimpleNode(NormalizedNodeWriter.java:150)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.write(NormalizedNodeWriter.java:104)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.writeChildren(NormalizedNodeWriter.java:171)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.wasProcessedAsCompositeNode(NormalizedNodeWriter.java:196)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.write(NormalizedNodeWriter.java:100)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.writeChildren(NormalizedNodeWriter.java:171)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter$OrderedNormalizedNodeWriter.writeMapEntryNode(NormalizedNodeWriter.java:282)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.wasProcessedAsCompositeNode(NormalizedNodeWriter.java:208)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.write(NormalizedNodeWriter.java:100)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.writeChildren(NormalizedNodeWriter.java:171)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.wasProcessedAsCompositeNode(NormalizedNodeWriter.java:238)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.write(NormalizedNodeWriter.java:100)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.writeChildren(NormalizedNodeWriter.java:171)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.wasProcessedAsCompositeNode(NormalizedNodeWriter.java:196)
at org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.write(NormalizedNodeWriter.java:100)
at org.opendaylight.netconf.sal.rest.impl.RestconfDelegatingNormalizedNodeWriter.write(RestconfDelegatingNormalizedNodeWriter.java:37)
at org.opendaylight.netconf.sal.rest.impl.RestconfDelegatingNormalizedNodeWriter.write(RestconfDelegatingNormalizedNodeWriter.java:19)
at org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter.writeNormalizedNode(NormalizedNodeJsonBodyWriter.java:124)
at org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter.writeTo(NormalizedNodeJsonBodyWriter.java:90)
at org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter.writeTo(NormalizedNodeJsonBodyWriter.java:51)
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
已邀请:

要回复问题请先登录注册