[SDFAB-944] Add support for `id` leaf in GNMI driver
The id is available through /interfaces/interface[name=*]/state/id,
if the device does not support `id` leaf uses as fall back ifindex
Change-Id: I22ff5e1df11485ba277644778f4309b1bd407849
diff --git a/drivers/gnmi/src/main/java/org/onosproject/drivers/gnmi/OpenConfigGnmiDeviceDescriptionDiscovery.java b/drivers/gnmi/src/main/java/org/onosproject/drivers/gnmi/OpenConfigGnmiDeviceDescriptionDiscovery.java
index eb41f4d..5717ffe 100644
--- a/drivers/gnmi/src/main/java/org/onosproject/drivers/gnmi/OpenConfigGnmiDeviceDescriptionDiscovery.java
+++ b/drivers/gnmi/src/main/java/org/onosproject/drivers/gnmi/OpenConfigGnmiDeviceDescriptionDiscovery.java
@@ -92,6 +92,7 @@
final Map<String, DefaultPortDescription.Builder> ports = Maps.newHashMap();
final Map<String, DefaultAnnotations.Builder> annotations = Maps.newHashMap();
+ final Map<String, PortNumber> portIds = Maps.newHashMap();
// Creates port descriptions with port name and port number
response.getNotificationList()
@@ -106,7 +107,7 @@
}
final DefaultPortDescription.Builder builder = ports.get(ifName);
final DefaultAnnotations.Builder annotationsBuilder = annotations.get(ifName);
- parseInterfaceInfo(update, ifName, builder, annotationsBuilder);
+ parseInterfaceInfo(update, ifName, builder, annotationsBuilder, portIds);
});
});
@@ -117,9 +118,14 @@
if (!annotationsBuilder.build().keys().contains(LAST_CHANGE)) {
annotationsBuilder.set(LAST_CHANGE, String.valueOf(0));
}
+ // Override port number if /interfaces/interface/state/id is available
+ if (portIds.containsKey(key)) {
+ value.withPortNumber(portIds.get(key));
+ }
DefaultAnnotations annotation = annotations.get(key).build();
portDescriptionList.add(value.annotations(annotation).build());
});
+
return portDescriptionList;
}
@@ -144,15 +150,17 @@
private void parseInterfaceInfo(Update update,
String ifName,
DefaultPortDescription.Builder builder,
- DefaultAnnotations.Builder annotationsBuilder) {
+ DefaultAnnotations.Builder annotationsBuilder,
+ Map<String, PortNumber> portIds) {
final Path path = update.getPath();
final List<PathElem> elems = path.getElemList();
final Gnmi.TypedValue val = update.getVal();
if (elems.size() == 4) {
- // /interfaces/interface/state/ifindex
- // /interfaces/interface/state/oper-status
- // /interfaces/interface/state/last-change
+ /* /interfaces/interface/state/ifindex
+ /interfaces/interface/state/oper-status
+ /interfaces/interface/state/last-change
+ /interfaces/interface/state/id */
final String pathElemName = elems.get(3).getName();
switch (pathElemName) {
case "ifindex": // port number
@@ -164,6 +172,12 @@
case "last-change":
annotationsBuilder.set(LAST_CHANGE, String.valueOf(val.getUintVal()));
return;
+ case "id":
+ /* Temporary stored in portIds and eventually substituted
+ when all updates have been processed. This is done because
+ there is no guarantee about the order of the updates delivery */
+ portIds.put(ifName, PortNumber.portNumber(val.getUintVal(), ifName));
+ return;
default:
break;
}