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; ...@@ -38,6 +38,9 @@ import com.google.common.collect.Sets;
38 */ 38 */
39 public final class ClusterMetadata { 39 public final class ClusterMetadata {
40 40
41 + // Name to use when the ClusterMetadataService is in transient state
42 + public static final String NO_NAME = "";
43 +
41 private String name; 44 private String name;
42 private Set<ControllerNode> nodes; 45 private Set<ControllerNode> nodes;
43 private Set<Partition> partitions; 46 private Set<Partition> partitions;
......
...@@ -17,6 +17,7 @@ package org.onosproject.provider.lldp.impl; ...@@ -17,6 +17,7 @@ package org.onosproject.provider.lldp.impl;
17 17
18 import org.onosproject.mastership.MastershipService; 18 import org.onosproject.mastership.MastershipService;
19 import org.onosproject.net.LinkKey; 19 import org.onosproject.net.LinkKey;
20 +import org.onosproject.net.device.DeviceService;
20 import org.onosproject.net.link.LinkProviderService; 21 import org.onosproject.net.link.LinkProviderService;
21 import org.onosproject.net.packet.PacketService; 22 import org.onosproject.net.packet.PacketService;
22 23
...@@ -47,6 +48,13 @@ interface DiscoveryContext { ...@@ -47,6 +48,13 @@ interface DiscoveryContext {
47 PacketService packetService(); 48 PacketService packetService();
48 49
49 /** 50 /**
51 + * Returns the DeviceService reference.
52 + *
53 + * @return the device service interface
54 + */
55 + DeviceService deviceService();
56 +
57 + /**
50 * Returns the probe rate in millis. 58 * Returns the probe rate in millis.
51 * 59 *
52 * @return probe rate 60 * @return probe rate
......
...@@ -43,6 +43,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; ...@@ -43,6 +43,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
43 import static org.onosproject.net.PortNumber.portNumber; 43 import static org.onosproject.net.PortNumber.portNumber;
44 import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; 44 import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
45 import static org.slf4j.LoggerFactory.getLogger; 45 import static org.slf4j.LoggerFactory.getLogger;
46 +import static org.onosproject.cluster.ClusterMetadata.NO_NAME;
46 47
47 /** 48 /**
48 * Run discovery process from a physical switch. Ports are initially labeled as 49 * Run discovery process from a physical switch. Ports are initially labeled as
...@@ -159,6 +160,10 @@ class LinkDiscovery implements TimerTask { ...@@ -159,6 +160,10 @@ class LinkDiscovery implements TimerTask {
159 160
160 ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth); 161 ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
161 if (onoslldp != null) { 162 if (onoslldp != null) {
163 + if (notMy(onoslldp)) {
164 + return true;
165 + }
166 +
162 PortNumber srcPort = portNumber(onoslldp.getPort()); 167 PortNumber srcPort = portNumber(onoslldp.getPort());
163 PortNumber dstPort = packetContext.inPacket().receivedFrom().port(); 168 PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
164 DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString()); 169 DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString());
...@@ -182,6 +187,26 @@ class LinkDiscovery implements TimerTask { ...@@ -182,6 +187,26 @@ class LinkDiscovery implements TimerTask {
182 return false; 187 return false;
183 } 188 }
184 189
190 + // true if *NOT* this cluster's own probe.
191 + private boolean notMy(ONOSLLDP onoslldp) {
192 + if (onoslldp.getDomainTLV() == null) {
193 + // not finger-printed - but we can check the source
194 + DeviceId src = DeviceId.deviceId(onoslldp.getDeviceString());
195 + if (context.deviceService().getDevice(src) == null) {
196 + return true;
197 + }
198 + return false;
199 + }
200 +
201 + String us = context.fingerprint();
202 + String them = onoslldp.getDomainString();
203 + // if: Our and/or their MetadataService in poorly state, conservative 'yes'
204 + if (NO_NAME.equals(us) || NO_NAME.equals(them)) {
205 + return true;
206 + } else {
207 + return !us.equals(them);
208 + }
209 + }
185 210
186 /** 211 /**
187 * Execute this method every t milliseconds. Loops over all ports 212 * 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 ...@@ -27,6 +27,7 @@ import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FAC
27 import static org.onosproject.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY; 27 import static org.onosproject.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY;
28 import static org.onosproject.net.config.basics.SubjectFactories.DEVICE_SUBJECT_FACTORY; 28 import static org.onosproject.net.config.basics.SubjectFactories.DEVICE_SUBJECT_FACTORY;
29 import static org.slf4j.LoggerFactory.getLogger; 29 import static org.slf4j.LoggerFactory.getLogger;
30 +import static org.onosproject.cluster.ClusterMetadata.NO_NAME;
30 31
31 import java.util.Dictionary; 32 import java.util.Dictionary;
32 import java.util.EnumSet; 33 import java.util.EnumSet;
...@@ -47,6 +48,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -47,6 +48,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
47 import org.onlab.packet.Ethernet; 48 import org.onlab.packet.Ethernet;
48 import org.onlab.util.Tools; 49 import org.onlab.util.Tools;
49 import org.onosproject.cfg.ComponentConfigService; 50 import org.onosproject.cfg.ComponentConfigService;
51 +import org.onosproject.cluster.ClusterMetadata;
50 import org.onosproject.cluster.ClusterMetadataService; 52 import org.onosproject.cluster.ClusterMetadataService;
51 import org.onosproject.cluster.ClusterService; 53 import org.onosproject.cluster.ClusterService;
52 import org.onosproject.core.ApplicationId; 54 import org.onosproject.core.ApplicationId;
...@@ -426,6 +428,7 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -426,6 +428,7 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
426 removeDevice(device.id()); 428 removeDevice(device.id());
427 return Optional.empty(); 429 return Optional.empty();
428 } 430 }
431 +
429 LinkDiscovery ld = discoverers.computeIfAbsent(device.id(), 432 LinkDiscovery ld = discoverers.computeIfAbsent(device.id(),
430 did -> new LinkDiscovery(device, context)); 433 did -> new LinkDiscovery(device, context));
431 if (isFingerprinted(device.id())) { 434 if (isFingerprinted(device.id())) {
...@@ -749,7 +752,13 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -749,7 +752,13 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
749 752
750 @Override 753 @Override
751 public String fingerprint() { 754 public String fingerprint() {
752 - return clusterMetadataService.getClusterMetadata().getName(); 755 + ClusterMetadata mdata = clusterMetadataService.getClusterMetadata();
756 + return mdata == null ? NO_NAME : mdata.getName();
757 + }
758 +
759 + @Override
760 + public DeviceService deviceService() {
761 + return deviceService;
753 } 762 }
754 } 763 }
755 764
......