Jonathan Hart

Fix issue with link discovery missing ports.

ONOS-2477.

Ported from onos-1.2 branch.

Change-Id: I8d82ac687d6a3177b5216a19c99f0823a047529e
......@@ -163,16 +163,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
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 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
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() {
cfgService.unregisterProperties(getClass(), false);
......@@ -431,26 +433,20 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
}
// 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) {
......
......@@ -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.PacketContext;
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
/**
......@@ -141,15 +141,20 @@ public class LinkDiscovery implements TimerTask {
* @param port the port
*/
public void addPort(final Port port) {
this.log.debug("Sending init probe to port {}@{}",
port.number().toLong(), device.id());
boolean newPort = false;
synchronized (this) {
if (!containsPort(port.number().toLong())) {
newPort = true;
this.slowPorts.add(port.number().toLong());
}
}
boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER;
if (isMaster) {
if (newPort && isMaster) {
this.log.debug("Sending init probe to port {}@{}",
port.number().toLong(), device.id());
sendProbes(port.number().toLong());
}
synchronized (this) {
this.slowPorts.add(port.number().toLong());
}
}
/**
......