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 { ...@@ -163,16 +163,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
163 ld = new LinkDiscovery(device, packetService, masterService, 163 ld = new LinkDiscovery(device, packetService, masterService,
164 providerService, useBDDP); 164 providerService, useBDDP);
165 discoverers.put(device.id(), ld); 165 discoverers.put(device.id(), ld);
166 - for (Port p : deviceService.getPorts(device.id())) { 166 + addPorts(ld, device.id());
167 - if (rules.isSuppressed(p)) {
168 - log.debug("LinkDiscovery from {}@{} disabled by configuration",
169 - p.number(), device.id());
170 - continue;
171 - }
172 - if (!p.number().isLogical()) {
173 - ld.addPort(p);
174 - }
175 - }
176 } 167 }
177 168
178 executor = newSingleThreadScheduledExecutor(groupedThreads("onos/device", "sync-%d")); 169 executor = newSingleThreadScheduledExecutor(groupedThreads("onos/device", "sync-%d"));
...@@ -183,6 +174,17 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -183,6 +174,17 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
183 log.info("Started"); 174 log.info("Started");
184 } 175 }
185 176
177 + private void addPorts(LinkDiscovery discoverer, DeviceId deviceId) {
178 + for (Port p : deviceService.getPorts(deviceId)) {
179 + if (rules.isSuppressed(p)) {
180 + continue;
181 + }
182 + if (!p.number().isLogical()) {
183 + discoverer.addPort(p);
184 + }
185 + }
186 + }
187 +
186 @Deactivate 188 @Deactivate
187 public void deactivate() { 189 public void deactivate() {
188 cfgService.unregisterProperties(getClass(), false); 190 cfgService.unregisterProperties(getClass(), false);
...@@ -431,26 +433,20 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -431,26 +433,20 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
431 } 433 }
432 // check what deviceService sees, to see if we are missing anything 434 // check what deviceService sees, to see if we are missing anything
433 try { 435 try {
434 - LinkDiscovery ld = null;
435 for (Device dev : deviceService.getDevices()) { 436 for (Device dev : deviceService.getDevices()) {
436 if (rules.isSuppressed(dev)) { 437 if (rules.isSuppressed(dev)) {
437 continue; 438 continue;
438 } 439 }
439 DeviceId did = dev.id(); 440 DeviceId did = dev.id();
440 synchronized (discoverers) { 441 synchronized (discoverers) {
441 - if (!discoverers.containsKey(did)) { 442 + LinkDiscovery discoverer = discoverers.get(did);
442 - ld = new LinkDiscovery(dev, packetService, 443 + if (discoverer == null) {
443 - masterService, providerService, useBDDP); 444 + discoverer = new LinkDiscovery(dev, packetService,
444 - discoverers.put(did, ld); 445 + masterService, providerService, useBDDP);
445 - for (Port p : deviceService.getPorts(did)) { 446 + discoverers.put(did, discoverer);
446 - if (rules.isSuppressed(p)) {
447 - continue;
448 - }
449 - if (!p.number().isLogical()) {
450 - ld.addPort(p);
451 - }
452 - }
453 } 447 }
448 +
449 + addPorts(discoverer, did);
454 } 450 }
455 } 451 }
456 } catch (Exception e) { 452 } catch (Exception e) {
......
...@@ -15,22 +15,6 @@ ...@@ -15,22 +15,6 @@
15 */ 15 */
16 package org.onosproject.provider.lldp.impl; 16 package org.onosproject.provider.lldp.impl;
17 17
18 -import static com.google.common.base.Preconditions.checkNotNull;
19 -import static java.util.concurrent.TimeUnit.MILLISECONDS;
20 -import static org.onosproject.net.MastershipRole.MASTER;
21 -import static org.onosproject.net.PortNumber.portNumber;
22 -import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
23 -import static org.slf4j.LoggerFactory.getLogger;
24 -
25 -import java.nio.ByteBuffer;
26 -import java.util.Collections;
27 -import java.util.HashMap;
28 -import java.util.HashSet;
29 -import java.util.Iterator;
30 -import java.util.Map;
31 -import java.util.Set;
32 -import java.util.concurrent.atomic.AtomicInteger;
33 -
34 import org.jboss.netty.util.Timeout; 18 import org.jboss.netty.util.Timeout;
35 import org.jboss.netty.util.TimerTask; 19 import org.jboss.netty.util.TimerTask;
36 import org.onlab.packet.Ethernet; 20 import org.onlab.packet.Ethernet;
...@@ -52,6 +36,22 @@ import org.onosproject.net.packet.PacketContext; ...@@ -52,6 +36,22 @@ import org.onosproject.net.packet.PacketContext;
52 import org.onosproject.net.packet.PacketService; 36 import org.onosproject.net.packet.PacketService;
53 import org.slf4j.Logger; 37 import org.slf4j.Logger;
54 38
39 +import java.nio.ByteBuffer;
40 +import java.util.Collections;
41 +import java.util.HashMap;
42 +import java.util.HashSet;
43 +import java.util.Iterator;
44 +import java.util.Map;
45 +import java.util.Set;
46 +import java.util.concurrent.atomic.AtomicInteger;
47 +
48 +import static com.google.common.base.Preconditions.checkNotNull;
49 +import static java.util.concurrent.TimeUnit.MILLISECONDS;
50 +import static org.onosproject.net.MastershipRole.MASTER;
51 +import static org.onosproject.net.PortNumber.portNumber;
52 +import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
53 +import static org.slf4j.LoggerFactory.getLogger;
54 +
55 // TODO: add 'fast discovery' mode: drop LLDPs in destination switch but listen for flow_removed messages 55 // TODO: add 'fast discovery' mode: drop LLDPs in destination switch but listen for flow_removed messages
56 56
57 /** 57 /**
...@@ -141,15 +141,20 @@ public class LinkDiscovery implements TimerTask { ...@@ -141,15 +141,20 @@ public class LinkDiscovery implements TimerTask {
141 * @param port the port 141 * @param port the port
142 */ 142 */
143 public void addPort(final Port port) { 143 public void addPort(final Port port) {
144 - this.log.debug("Sending init probe to port {}@{}", 144 + boolean newPort = false;
145 - port.number().toLong(), device.id()); 145 + synchronized (this) {
146 + if (!containsPort(port.number().toLong())) {
147 + newPort = true;
148 + this.slowPorts.add(port.number().toLong());
149 + }
150 + }
151 +
146 boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER; 152 boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER;
147 - if (isMaster) { 153 + if (newPort && isMaster) {
154 + this.log.debug("Sending init probe to port {}@{}",
155 + port.number().toLong(), device.id());
148 sendProbes(port.number().toLong()); 156 sendProbes(port.number().toLong());
149 } 157 }
150 - synchronized (this) {
151 - this.slowPorts.add(port.number().toLong());
152 - }
153 } 158 }
154 159
155 /** 160 /**
......