[ONOS-4424] Tag LLDP/BDDP source address with fingerprint

Link probes incorporate cluster fingerprint in source
MAC address. This removes the need for an additional TLV and the
complexity associated with it, and also adds fingerprinting to
BDDPs for free.

 - fingerprint in Ethernet source address. The old default MAC
   value is only used when the CusterMetadata service isn't ready.
 - remove support for TLV fingerprint field and associated config
   knobs.
 - links at control domain boundary are classified as EDGE type links.

Change-Id: Idb07dd06fbeee25e9fcee3fbdddec7a7dbb2c397
diff --git a/providers/lldpcommon/src/main/java/org/onosproject/provider/lldpcommon/LinkDiscovery.java b/providers/lldpcommon/src/main/java/org/onosproject/provider/lldpcommon/LinkDiscovery.java
index a15a0a2..9d021e4 100644
--- a/providers/lldpcommon/src/main/java/org/onosproject/provider/lldpcommon/LinkDiscovery.java
+++ b/providers/lldpcommon/src/main/java/org/onosproject/provider/lldpcommon/LinkDiscovery.java
@@ -34,6 +34,7 @@
 import org.onosproject.net.packet.DefaultOutboundPacket;
 import org.onosproject.net.packet.OutboundPacket;
 import org.onosproject.net.packet.PacketContext;
+import org.onosproject.net.link.ProbedLinkProvider;
 import org.slf4j.Logger;
 
 import java.nio.ByteBuffer;
@@ -43,7 +44,6 @@
 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
@@ -56,8 +56,6 @@
 
     private final Logger log = getLogger(getClass());
 
-    private static final String SRC_MAC = "DE:AD:BE:EF:BA:11";
-
     private final Device device;
     private final LinkDiscoveryContext context;
 
@@ -66,8 +64,6 @@
 
     private Timeout timeout;
     private volatile boolean isStopped;
-    // This LinkDiscovery can handle remote link probes (default false).
-    private volatile boolean fingerprinted;
     // Set of ports to be probed
     private final Set<Long> ports = Sets.newConcurrentHashSet();
 
@@ -93,7 +89,6 @@
         bddpEth.setDestinationMACAddress(ONOSLLDP.BDDP_MULTICAST);
         bddpEth.setPad(true);
 
-        fingerprinted = false;
         isStopped = true;
         start();
         log.debug("Started discovery manager for switch {}", device.id());
@@ -160,8 +155,12 @@
 
         ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
         if (onoslldp != null) {
-            if (notMy(onoslldp)) {
-                return true;
+            Type lt;
+            if (notMy(eth.getSourceMAC().toString())) {
+                lt = Type.EDGE;
+            } else {
+                lt = eth.getEtherType() == Ethernet.TYPE_LLDP ?
+                        Type.DIRECT : Type.INDIRECT;
             }
 
             PortNumber srcPort = portNumber(onoslldp.getPort());
@@ -172,10 +171,7 @@
             ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
             ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
 
-            LinkDescription ld = eth.getEtherType() == Ethernet.TYPE_LLDP ?
-                    new DefaultLinkDescription(src, dst, Type.DIRECT) :
-                    new DefaultLinkDescription(src, dst, Type.INDIRECT);
-
+            LinkDescription ld = new DefaultLinkDescription(src, dst, lt);
             try {
                 context.providerService().linkDetected(ld);
                 context.touchLink(LinkKey.linkKey(src, dst));
@@ -188,24 +184,13 @@
     }
 
     // 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)) {
+    private boolean notMy(String mac) {
+        // if we are using DEFAULT_MAC, clustering hadn't initialized, so conservative 'yes'
+        String ourMac = context.fingerprint();
+        if (ProbedLinkProvider.defaultMac().equalsIgnoreCase(ourMac)) {
             return true;
-        } else {
-            return !us.equals(them);
         }
+        return !mac.equalsIgnoreCase(ourMac);
     }
 
     /**
@@ -242,7 +227,7 @@
             return null;
         }
         ONOSLLDP lldp = getLinkProbe(port);
-        ethPacket.setSourceMACAddress(SRC_MAC).setPayload(lldp);
+        ethPacket.setSourceMACAddress(context.fingerprint()).setPayload(lldp);
         return new DefaultOutboundPacket(device.id(),
                                          builder().setOutput(portNumber(port)).build(),
                                          ByteBuffer.wrap(ethPacket.serialize()));
@@ -259,18 +244,14 @@
             return null;
         }
         ONOSLLDP lldp = getLinkProbe(port);
-        bddpEth.setSourceMACAddress(SRC_MAC).setPayload(lldp);
+        bddpEth.setSourceMACAddress(context.fingerprint()).setPayload(lldp);
         return new DefaultOutboundPacket(device.id(),
                                          builder().setOutput(portNumber(port)).build(),
                                          ByteBuffer.wrap(bddpEth.serialize()));
     }
 
     private ONOSLLDP getLinkProbe(Long port) {
-        return fingerprinted
-                ? ONOSLLDP.fingerprintedLLDP(device.id().toString(), device.chassisId(),
-                                             port.intValue(), context.fingerprint())
-                : ONOSLLDP.onosLLDP(device.id().toString(), device.chassisId(),
-                                    port.intValue());
+        return ONOSLLDP.onosLLDP(device.id().toString(), device.chassisId(), port.intValue());
     }
 
     private void sendProbes(Long portNumber) {
@@ -286,12 +267,4 @@
     public boolean containsPort(long portNumber) {
         return ports.contains(portNumber);
     }
-
-    public void enableFingerprint() {
-        fingerprinted = true;
-    }
-
-    public void disableFingerprint() {
-        fingerprinted = false;
-    }
 }