[Falcon] link discovery -
- safety checks against fingerprint being null
- checks for foreign fingerprint and probe message origin
Change-Id: I2f3e491802afc2091335bd25fcf24865293bde10
diff --git a/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java b/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java
index e1eacfe..6da48fa 100644
--- a/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java
+++ b/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java
@@ -38,6 +38,9 @@
*/
public final class ClusterMetadata {
+ // Name to use when the ClusterMetadataService is in transient state
+ public static final String NO_NAME = "";
+
private String name;
private Set<ControllerNode> nodes;
private Set<Partition> partitions;
diff --git a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java
index 04729e4..74732ea 100644
--- a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java
+++ b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java
@@ -17,6 +17,7 @@
import org.onosproject.mastership.MastershipService;
import org.onosproject.net.LinkKey;
+import org.onosproject.net.device.DeviceService;
import org.onosproject.net.link.LinkProviderService;
import org.onosproject.net.packet.PacketService;
@@ -47,6 +48,13 @@
PacketService packetService();
/**
+ * Returns the DeviceService reference.
+ *
+ * @return the device service interface
+ */
+ DeviceService deviceService();
+
+ /**
* Returns the probe rate in millis.
*
* @return probe rate
diff --git a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java
index 11b8cd3..c0a50f9 100644
--- a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java
+++ b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java
@@ -43,6 +43,7 @@
import static org.onosproject.net.PortNumber.portNumber;
import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
import static org.slf4j.LoggerFactory.getLogger;
+import static org.onosproject.cluster.ClusterMetadata.NO_NAME;
/**
* Run discovery process from a physical switch. Ports are initially labeled as
@@ -159,6 +160,10 @@
ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
if (onoslldp != null) {
+ if (notMy(onoslldp)) {
+ return true;
+ }
+
PortNumber srcPort = portNumber(onoslldp.getPort());
PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString());
@@ -182,6 +187,26 @@
return false;
}
+ // true if *NOT* this cluster's own probe.
+ private boolean notMy(ONOSLLDP onoslldp) {
+ if (onoslldp.getDomainTLV() == null) {
+ // not finger-printed - but we can check the source
+ DeviceId src = DeviceId.deviceId(onoslldp.getDeviceString());
+ if (context.deviceService().getDevice(src) == null) {
+ return true;
+ }
+ return false;
+ }
+
+ String us = context.fingerprint();
+ String them = onoslldp.getDomainString();
+ // if: Our and/or their MetadataService in poorly state, conservative 'yes'
+ if (NO_NAME.equals(us) || NO_NAME.equals(them)) {
+ return true;
+ } else {
+ return !us.equals(them);
+ }
+ }
/**
* Execute this method every t milliseconds. Loops over all ports
diff --git a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
index bf88f57..8c24502 100644
--- a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
+++ b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
@@ -27,6 +27,7 @@
import static org.onosproject.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY;
import static org.onosproject.net.config.basics.SubjectFactories.DEVICE_SUBJECT_FACTORY;
import static org.slf4j.LoggerFactory.getLogger;
+import static org.onosproject.cluster.ClusterMetadata.NO_NAME;
import java.util.Dictionary;
import java.util.EnumSet;
@@ -47,6 +48,7 @@
import org.onlab.packet.Ethernet;
import org.onlab.util.Tools;
import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.cluster.ClusterMetadata;
import org.onosproject.cluster.ClusterMetadataService;
import org.onosproject.cluster.ClusterService;
import org.onosproject.core.ApplicationId;
@@ -426,6 +428,7 @@
removeDevice(device.id());
return Optional.empty();
}
+
LinkDiscovery ld = discoverers.computeIfAbsent(device.id(),
did -> new LinkDiscovery(device, context));
if (isFingerprinted(device.id())) {
@@ -749,7 +752,13 @@
@Override
public String fingerprint() {
- return clusterMetadataService.getClusterMetadata().getName();
+ ClusterMetadata mdata = clusterMetadataService.getClusterMetadata();
+ return mdata == null ? NO_NAME : mdata.getName();
+ }
+
+ @Override
+ public DeviceService deviceService() {
+ return deviceService;
}
}