ONOS-7750
Support Juniper "lldp-remote-port-id" message as String during link discovery
Change-Id: Ic1881c973e07df780692b34772a61dec6cbdc157
diff --git a/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/JuniperUtils.java b/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/JuniperUtils.java
index 60baded..3cf5eec 100644
--- a/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/JuniperUtils.java
+++ b/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/JuniperUtils.java
@@ -104,8 +104,11 @@
private static final String LLDP_LO_PORT = "lldp-local-port-id";
private static final String LLDP_REM_CHASS = "lldp-remote-chassis-id";
+ private static final String LLDP_REM_PORT_SUBTYPE = "lldp-remote-port-id-subtype";
private static final String LLDP_REM_PORT = "lldp-remote-port-id";
private static final String LLDP_REM_PORT_DES = "lldp-remote-port-description";
+ private static final String LLDP_SUBTYPE_MAC = "Mac address";
+ private static final String LLDP_SUBTYPE_INTERFACE_NAME = "Interface name";
private static final String REGEX_ADD =
".*Private base address\\s*([:,0-9,a-f,A-F]*).*";
private static final Pattern ADD_PATTERN =
@@ -523,15 +526,24 @@
neighborsInfo.configurationsAt(LLDP_NBR_INFO);
for (HierarchicalConfiguration neighbor : neighbors) {
String localPortName = neighbor.getString(LLDP_LO_PORT);
- MacAddress mac = MacAddress.valueOf(
- neighbor.getString(LLDP_REM_CHASS));
- long remotePortIndex =
- neighbor.getInt(LLDP_REM_PORT, -1);
+ MacAddress mac = MacAddress.valueOf(neighbor.getString(LLDP_REM_CHASS));
+ String remotePortId = null;
+ long remotePortIndex = -1;
+ String remotePortIdSubtype = neighbor.getString(LLDP_REM_PORT_SUBTYPE, null);
+ if (remotePortIdSubtype != null) {
+ if (remotePortIdSubtype.equals(LLDP_SUBTYPE_MAC)
+ || remotePortIdSubtype.equals(LLDP_SUBTYPE_INTERFACE_NAME)) {
+ remotePortId = neighbor.getString(LLDP_REM_PORT, null);
+ } else {
+ remotePortIndex = neighbor.getLong(LLDP_REM_PORT, -1);
+ }
+ }
String remotePortDescription = neighbor.getString(LLDP_REM_PORT_DES, null);
LinkAbstraction link = new LinkAbstraction(
localPortName,
mac.toLong(),
remotePortIndex,
+ remotePortId,
remotePortDescription);
neighbour.add(link);
}
@@ -546,12 +558,14 @@
protected String localPortName;
protected ChassisId remoteChassisId;
protected long remotePortIndex;
+ protected String remotePortId;
protected String remotePortDescription;
- protected LinkAbstraction(String pName, long chassisId, long pIndex, String pDescription) {
+ protected LinkAbstraction(String pName, long chassisId, long pIndex, String pPortId, String pDescription) {
this.localPortName = pName;
this.remoteChassisId = new ChassisId(chassisId);
this.remotePortIndex = pIndex;
+ this.remotePortId = pPortId;
this.remotePortDescription = pDescription;
}
}
diff --git a/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/LinkDiscoveryJuniperImpl.java b/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/LinkDiscoveryJuniperImpl.java
index af93653..37e655a 100644
--- a/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/LinkDiscoveryJuniperImpl.java
+++ b/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/LinkDiscoveryJuniperImpl.java
@@ -110,18 +110,29 @@
//find destination port by interface index
Optional<Port> remotePort = deviceService.getPorts(remoteDevice.id())
.stream().filter(port -> {
- if (port.number().toLong() == linkAbs.remotePortIndex) {
- return true;
- }
- if (port.annotations().value(AnnotationKeys.PORT_NAME) != null
- && port.annotations().value(AnnotationKeys.PORT_NAME).equals(linkAbs.remotePortDescription)) {
- return true;
- }
- return false;
- }).findAny();
+ if (port.number().toLong() == linkAbs.remotePortIndex) {
+ return true;
+ }
+ if (port.annotations().value(AnnotationKeys.PORT_MAC) != null
+ && linkAbs.remotePortId != null
+ && port.annotations().value(AnnotationKeys.PORT_MAC).equals(linkAbs.remotePortId)) {
+ return true;
+ }
+ if (port.annotations().value(AnnotationKeys.PORT_NAME) != null
+ && linkAbs.remotePortId != null
+ && port.annotations().value(AnnotationKeys.PORT_NAME).equals(linkAbs.remotePortId)) {
+ return true;
+ }
+ if (port.annotations().value(AnnotationKeys.PORT_NAME) != null
+ && linkAbs.remotePortDescription != null
+ && port.annotations().value(AnnotationKeys.PORT_NAME)
+ .equals(linkAbs.remotePortDescription)) {
+ return true;
+ }
+ return false;
+ }).findAny();
if (!remotePort.isPresent()) {
- log.warn("Port number {} and Port description {} do not exist in device {}",
- linkAbs.remotePortIndex, linkAbs.remotePortDescription, remoteDevice.id());
+ log.warn("Port Index and Port Id and Port description do not exist in device {}", remoteDevice.id());
continue;
}