TE Topology YANG Notification bug fixes in converter
Change-Id: Ifae23070132fdf7a2932445a555cb13cc6b9de52
diff --git a/apps/tenbi/utils/src/main/java/org/onosproject/teyang/utils/topology/EnumConverter.java b/apps/tenbi/utils/src/main/java/org/onosproject/teyang/utils/topology/EnumConverter.java
index 1c07f9b..1e15726 100644
--- a/apps/tenbi/utils/src/main/java/org/onosproject/teyang/utils/topology/EnumConverter.java
+++ b/apps/tenbi/utils/src/main/java/org/onosproject/teyang/utils/topology/EnumConverter.java
@@ -38,6 +38,10 @@
* found
*/
public static TeStatus yang2TeSubsystemOpStatus(TeOperStatus opStatus) {
+ if (opStatus == null) {
+ return null;
+ }
+
switch (opStatus.enumeration()) {
case DOWN:
return TeStatus.DOWN;
@@ -64,6 +68,10 @@
* found
*/
public static TeStatus yang2TeSubsystemAdminStatus(TeAdminStatus adminStatus) {
+ if (adminStatus == null) {
+ return TeStatus.UNKNOWN;
+ }
+
switch (adminStatus.enumeration()) {
case DOWN:
return TeStatus.DOWN;
@@ -87,6 +95,10 @@
* @return the equivalent Enum from YANG TeAdminStatus or null if not found
*/
public static TeAdminStatus teSubsystem2YangAdminStatus(TeStatus adminStatus) {
+ if (adminStatus == null) {
+ return null;
+ }
+
switch (adminStatus) {
case DOWN:
return TeAdminStatus.of(TeAdminStatusEnum.DOWN);
@@ -112,6 +124,10 @@
* @return the equivalent Enum from YANG TeOperStatus or null if not found
*/
public static TeOperStatus teSubsystem2YangOperStatus(TeStatus opStatus) {
+ if (opStatus == null) {
+ return null;
+ }
+
switch (opStatus) {
case DOWN:
return TeOperStatus.of(TeOperStatusEnum.DOWN);
@@ -130,4 +146,4 @@
}
}
-}
\ No newline at end of file
+}
diff --git a/apps/tenbi/utils/src/main/java/org/onosproject/teyang/utils/topology/LinkConverter.java b/apps/tenbi/utils/src/main/java/org/onosproject/teyang/utils/topology/LinkConverter.java
index 3bc16a6..933b9be 100644
--- a/apps/tenbi/utils/src/main/java/org/onosproject/teyang/utils/topology/LinkConverter.java
+++ b/apps/tenbi/utils/src/main/java/org/onosproject/teyang/utils/topology/LinkConverter.java
@@ -936,21 +936,30 @@
*/
public static TeLinkEvent teNetworkLink2yangTeLinkEvent(TeTopologyEventTypeEnum eventType,
NetworkLinkEventSubject linkData) {
- TeLinkEvent.TeLinkEventBuilder builder = new DefaultTeLinkEvent.TeLinkEventBuilder();
+ TeLinkEvent.TeLinkEventBuilder teLinkEventBuilder = new DefaultTeLinkEvent.TeLinkEventBuilder();
TeTopologyEventType yangEventType = new TeTopologyEventType(eventType);
- builder.eventType(yangEventType);
- NetworkId newtorkId = NetworkId.fromString(linkData.key().networkId().toString());
- builder.networkRef(newtorkId);
+ teLinkEventBuilder.eventType(yangEventType);
+ NetworkId networkId = NetworkId.fromString(linkData.key().networkId().toString());
+ teLinkEventBuilder.networkRef(networkId);
LinkId linkId = LinkId.fromString(linkData.key().linkId().toString());
- builder.linkRef(linkId);
+ teLinkEventBuilder.linkRef(linkId);
- NetworkLink link = linkData.networkLink();
- TeLinkAttributes teLinkAttributes = link == null ? null
- : teLink2YangConfig(link.teLink()).teLinkAttributes();
- builder.teLinkAttributes(teLinkAttributes);
+ if (linkData != null && linkData.networkLink() != null) {
+ NetworkLink link = linkData.networkLink();
+ State yangTeLinkState = teLink2YangState(link.teLink());
- return builder.build();
+ teLinkEventBuilder.operStatus(yangTeLinkState.operStatus());
+ teLinkEventBuilder.informationSource(yangTeLinkState.informationSource());
+ teLinkEventBuilder.informationSourceEntry(yangTeLinkState.informationSourceEntry());
+ teLinkEventBuilder.informationSourceState(yangTeLinkState.informationSourceState());
+ teLinkEventBuilder.isTransitional(yangTeLinkState.isTransitional());
+ teLinkEventBuilder.recovery(yangTeLinkState.recovery());
+ teLinkEventBuilder.teLinkAttributes(yangTeLinkState.teLinkAttributes());
+ teLinkEventBuilder.underlay(yangTeLinkState.underlay());
+ }
+
+ return teLinkEventBuilder.build();
}
public static NetworkLinkKey yangLinkEvent2NetworkLinkKey(TeLinkEvent yangLinkEvent) {
@@ -983,6 +992,9 @@
}
NodeTpKey sourceTp = networkLink.source();
+ if (sourceTp == null) {
+ return null;
+ }
NodeTpKey destTp = networkLink.destination();
List<NetworkLinkKey> supportingLinkIds = networkLink.supportingLinkIds();
@@ -1011,13 +1023,13 @@
TeLinkTpKey teLinkKey = oldTeLink.teLinkKey();
+ long teNodeIdDest = 0;
+ long teNodeIdSrc = 0;
- long teNodeIdDest = oldTeLink.peerTeLinkKey().teNodeId();
- long teNodeId = oldTeLink.teLinkKey().teNodeId();
TeLinkTpGlobalKey supportTeLinkId = oldTeLink.supportingTeLinkId();
TeLinkTpKey peerTeLinkKey = oldTeLink.peerTeLinkKey();
- TeLink updatedTeLink = yangLinkAttr2TeLinkAttributes(yangTeLinkAttrs, opStatus, teNodeId, teNodeIdDest,
+ TeLink updatedTeLink = yangLinkAttr2TeLinkAttributes(yangTeLinkAttrs, opStatus, teNodeIdSrc, teNodeIdDest,
teLinkKey, peerTeLinkKey, supportTeLinkId);
return updatedTeLink;
diff --git a/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/TeTopologyRestconfProvider.java b/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/TeTopologyRestconfProvider.java
index 8fdf49c..c75f01d 100644
--- a/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/TeTopologyRestconfProvider.java
+++ b/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/TeTopologyRestconfProvider.java
@@ -53,6 +53,8 @@
import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.Network;
import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.IetfNetworkTopology;
import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.IetfTeTopology;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
+ .IetfTeTopologyEvent;
import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.TeLinkEvent;
import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.TeNodeEvent;
import org.onosproject.yms.ych.YangCodecHandler;
@@ -84,7 +86,7 @@
@Component(immediate = true)
public class TeTopologyRestconfProvider extends AbstractProvider
implements TeTopologyProvider {
- private static final String APP_NAME = "org.onosproject.teprovider.topology";
+ private static final String APP_NAME = "org.onosproject.teprovider";
private static final String RESTCONF = "restconf";
private static final String PROVIDER =
"org.onosproject.teprovider.restconf.domain";
@@ -341,50 +343,97 @@
}
private void handleRestconfLinkNotification(String linkString) {
- YangCompositeEncodingImpl yce =
- new YangCompositeEncodingImpl(YangResourceIdentifierType.URI,
- "ietf-te-topology:te-link-event",
- linkString);
- Object yo = codecHandler.decode(yce,
- YangProtocolEncodingFormat.JSON,
- YmsOperationType.NOTIFICATION);
- if (yo == null) {
- log.error("YMS decoder error");
+ IetfTeTopologyEvent event = convertJson2IetfTeTopologyEvent(
+ "ietf-te-topology:te-link-event",
+ linkString);
+ if (event == null) {
+ log.error("ERROR: json to YO conversion failure");
return;
}
+ if (event.type() != IetfTeTopologyEvent.Type.TE_LINK_EVENT) {
+ log.error("ERROR: wrong YO event type: {}", event.type());
+ return;
+ }
+
+ TeLinkEvent teLinkEvent = event.subject().teLinkEvent();
+
+ log.debug("TeLinkEvent: {}", teLinkEvent);
+
NetworkLinkKey linkKey = LinkConverter.yangLinkEvent2NetworkLinkKey(
- (TeLinkEvent) yo);
+ teLinkEvent);
NetworkLink networkLink = LinkConverter.yangLinkEvent2NetworkLink(
- (TeLinkEvent) yo,
+ teLinkEvent,
teTopologyService);
+ if (networkLink == null) {
+ log.error("ERROR: yangLinkEvent2NetworkLink returns null");
+ return;
+ }
+
+ log.debug("networkLink: {}", networkLink);
+
topologyProviderService.linkUpdated(linkKey, networkLink);
}
- private void handleRestconfNodeNotification(String nodeString) {
+ private IetfTeTopologyEvent convertJson2IetfTeTopologyEvent(String uriString,
+ String jsonBody) {
+
YangCompositeEncodingImpl yce =
new YangCompositeEncodingImpl(YangResourceIdentifierType.URI,
- "ietf-te-topology:te-node-event",
- nodeString);
+ uriString,
+ jsonBody);
Object yo = codecHandler.decode(yce,
YangProtocolEncodingFormat.JSON,
YmsOperationType.NOTIFICATION);
if (yo == null) {
log.error("YMS decoder error");
+ return null;
+ }
+
+ if (!(yo instanceof IetfTeTopologyEvent)) {
+ log.error("ERROR: YO is not IetfTeTopologyEvent");
+ return null;
+ }
+
+ return (IetfTeTopologyEvent) yo;
+ }
+
+ private void handleRestconfNodeNotification(String nodeString) {
+
+ IetfTeTopologyEvent event = convertJson2IetfTeTopologyEvent(
+ "ietf-te-topology:te-node-event",
+ nodeString);
+
+ if (event == null) {
+ log.error("ERROR: json to YO conversion failure");
return;
}
+ if (event.type() != IetfTeTopologyEvent.Type.TE_NODE_EVENT) {
+ log.error("ERROR: wrong YO event type: {}", event.type());
+ return;
+ }
+
+ TeNodeEvent teNodeEvent = event.subject().teNodeEvent();
+
+ log.debug("TeNodeEvent: {}", teNodeEvent);
+
NetworkNodeKey nodeKey = NodeConverter.yangNodeEvent2NetworkNodeKey(
- (TeNodeEvent) yo);
+ teNodeEvent);
NetworkNode networkNode = NodeConverter.yangNodeEvent2NetworkNode(
- (TeNodeEvent) yo,
+ teNodeEvent,
teTopologyService);
+ if (networkNode == null) {
+ log.error("ERROR: yangNodeEvent2NetworkNode returns null");
+ return;
+ }
+
topologyProviderService.nodeUpdated(nodeKey, networkNode);
}
}