Ayaka Koshibe

[Falcon] link discovery -

- safety checks against fingerprint being null
- checks for foreign fingerprint and probe message origin

Change-Id: I2f3e491802afc2091335bd25fcf24865293bde10
......@@ -38,6 +38,9 @@ import com.google.common.collect.Sets;
*/
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;
......
......@@ -17,6 +17,7 @@ package org.onosproject.provider.lldp.impl;
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 @@ interface DiscoveryContext {
PacketService packetService();
/**
* Returns the DeviceService reference.
*
* @return the device service interface
*/
DeviceService deviceService();
/**
* Returns the probe rate in millis.
*
* @return probe rate
......
......@@ -43,6 +43,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
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 @@ class LinkDiscovery implements TimerTask {
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 @@ class LinkDiscovery implements TimerTask {
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
......
......@@ -27,6 +27,7 @@ import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FAC
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.apache.felix.scr.annotations.ReferenceCardinality;
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 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
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 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
@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;
}
}
......