Fix issue with link discovery missing ports.
ONOS-2477.
Change-Id: I8d82ac687d6a3177b5216a19c99f0823a047529e
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 6a69af8..47ceb2c 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
@@ -163,16 +163,7 @@
ld = new LinkDiscovery(device, packetService, masterService,
providerService, useBDDP);
discoverers.put(device.id(), ld);
- for (Port p : deviceService.getPorts(device.id())) {
- if (rules.isSuppressed(p)) {
- log.debug("LinkDiscovery from {}@{} disabled by configuration",
- p.number(), device.id());
- continue;
- }
- if (!p.number().isLogical()) {
- ld.addPort(p);
- }
- }
+ addPorts(ld, device.id());
}
executor = newSingleThreadScheduledExecutor(groupedThreads("onos/device", "sync-%d"));
@@ -183,6 +174,17 @@
log.info("Started");
}
+ private void addPorts(LinkDiscovery discoverer, DeviceId deviceId) {
+ for (Port p : deviceService.getPorts(deviceId)) {
+ if (rules.isSuppressed(p)) {
+ continue;
+ }
+ if (!p.number().isLogical()) {
+ discoverer.addPort(p);
+ }
+ }
+ }
+
@Deactivate
public void deactivate() {
// TODO revoke all packet requests when deactivate
@@ -252,7 +254,7 @@
TrafficSelector.Builder lldpSelector = DefaultTrafficSelector.builder();
lldpSelector.matchEthType(Ethernet.TYPE_LLDP);
packetService.requestPackets(lldpSelector.build(),
- PacketPriority.CONTROL, appId);
+ PacketPriority.CONTROL, appId);
if (useBDDP) {
TrafficSelector.Builder bddpSelector = DefaultTrafficSelector.builder();
@@ -419,26 +421,20 @@
}
// check what deviceService sees, to see if we are missing anything
try {
- LinkDiscovery ld = null;
for (Device dev : deviceService.getDevices()) {
if (rules.isSuppressed(dev)) {
continue;
}
DeviceId did = dev.id();
synchronized (discoverers) {
- if (!discoverers.containsKey(did)) {
- ld = new LinkDiscovery(dev, packetService,
- masterService, providerService, useBDDP);
- discoverers.put(did, ld);
- for (Port p : deviceService.getPorts(did)) {
- if (rules.isSuppressed(p)) {
- continue;
- }
- if (!p.number().isLogical()) {
- ld.addPort(p);
- }
- }
+ LinkDiscovery discoverer = discoverers.get(did);
+ if (discoverer == null) {
+ discoverer = new LinkDiscovery(dev, packetService,
+ masterService, providerService, useBDDP);
+ discoverers.put(did, discoverer);
}
+
+ addPorts(discoverer, did);
}
}
} catch (Exception e) {
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 6f3ffdc..5ff95c9 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
@@ -15,22 +15,6 @@
*/
package org.onosproject.provider.lldp.impl;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static org.onosproject.net.MastershipRole.MASTER;
-import static org.onosproject.net.PortNumber.portNumber;
-import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
-import static org.slf4j.LoggerFactory.getLogger;
-
-import java.nio.ByteBuffer;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
-
import org.jboss.netty.util.Timeout;
import org.jboss.netty.util.TimerTask;
import org.onlab.packet.Ethernet;
@@ -52,6 +36,22 @@
import org.onosproject.net.packet.PacketService;
import org.slf4j.Logger;
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.onosproject.net.MastershipRole.MASTER;
+import static org.onosproject.net.PortNumber.portNumber;
+import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
+import static org.slf4j.LoggerFactory.getLogger;
+
// TODO: add 'fast discovery' mode: drop LLDPs in destination switch but listen for flow_removed messages
/**
@@ -143,12 +143,18 @@
public void addPort(final Port port) {
this.log.debug("Sending init probe to port {}@{}",
port.number().toLong(), device.id());
- boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER;
- if (isMaster) {
- sendProbes(port.number().toLong());
- }
+
+ boolean newPort = false;
synchronized (this) {
- this.slowPorts.add(port.number().toLong());
+ if (!containsPort(port.number().toLong())) {
+ newPort = true;
+ this.slowPorts.add(port.number().toLong());
+ }
+ }
+
+ boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER;
+ if (newPort && isMaster) {
+ sendProbes(port.number().toLong());
}
}