Yuta HIGUCHI

LLDP LinkDiscovery related fix

- avoid LinkDiscovery from start()-ing multiple times
- Only check device mastership at beginning of probe interval

Change-Id: I0cece8fbcf2a031ea3ac603c6f51dbe87ad454ad
...@@ -145,7 +145,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -145,7 +145,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
145 break; 145 break;
146 case PORT_ADDED: 146 case PORT_ADDED:
147 case PORT_UPDATED: 147 case PORT_UPDATED:
148 - if (event.port().isEnabled()) { 148 + if (port.isEnabled()) {
149 ld = discoverers.get(device.id()); 149 ld = discoverers.get(device.id());
150 if (ld == null) { 150 if (ld == null) {
151 return; 151 return;
...@@ -155,6 +155,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -155,6 +155,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
155 ld.addPort(port); 155 ld.addPort(port);
156 } 156 }
157 } else { 157 } else {
158 + log.debug("Port down {}", port);
158 ConnectPoint point = new ConnectPoint(device.id(), 159 ConnectPoint point = new ConnectPoint(device.id(),
159 port.number()); 160 port.number());
160 providerService.linksVanished(point); 161 providerService.linksVanished(point);
......
...@@ -68,6 +68,7 @@ public class LinkDiscovery implements TimerTask { ...@@ -68,6 +68,7 @@ public class LinkDiscovery implements TimerTask {
68 // send 1 probe every probeRate milliseconds 68 // send 1 probe every probeRate milliseconds
69 private final long probeRate; 69 private final long probeRate;
70 private final Set<Long> slowPorts; 70 private final Set<Long> slowPorts;
71 + // ports, known to have incoming links
71 private final Set<Long> fastPorts; 72 private final Set<Long> fastPorts;
72 // number of unacknowledged probes per port 73 // number of unacknowledged probes per port
73 private final Map<Long, AtomicInteger> portProbeCount; 74 private final Map<Long, AtomicInteger> portProbeCount;
...@@ -125,6 +126,7 @@ public class LinkDiscovery implements TimerTask { ...@@ -125,6 +126,7 @@ public class LinkDiscovery implements TimerTask {
125 log.info("Using BDDP to discover network"); 126 log.info("Using BDDP to discover network");
126 } 127 }
127 128
129 + this.isStopped = true;
128 start(); 130 start();
129 this.log.debug("Started discovery manager for switch {}", 131 this.log.debug("Started discovery manager for switch {}",
130 device.id()); 132 device.id());
...@@ -140,7 +142,10 @@ public class LinkDiscovery implements TimerTask { ...@@ -140,7 +142,10 @@ public class LinkDiscovery implements TimerTask {
140 public void addPort(final Port port) { 142 public void addPort(final Port port) {
141 this.log.debug("Sending init probe to port {}@{}", 143 this.log.debug("Sending init probe to port {}@{}",
142 port.number().toLong(), device.id()); 144 port.number().toLong(), device.id());
143 - sendProbes(port.number().toLong()); 145 + boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER;
146 + if (isMaster) {
147 + sendProbes(port.number().toLong());
148 + }
144 synchronized (this) { 149 synchronized (this) {
145 this.slowPorts.add(port.number().toLong()); 150 this.slowPorts.add(port.number().toLong());
146 } 151 }
...@@ -233,6 +238,13 @@ public class LinkDiscovery implements TimerTask { ...@@ -233,6 +238,13 @@ public class LinkDiscovery implements TimerTask {
233 */ 238 */
234 @Override 239 @Override
235 public void run(final Timeout t) { 240 public void run(final Timeout t) {
241 + boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER;
242 + if (!isMaster) {
243 + // reschedule timer
244 + timeout = Timer.getTimer().newTimeout(this, this.probeRate, MILLISECONDS);
245 + return;
246 + }
247 +
236 this.log.trace("Sending probes from {}", device.id()); 248 this.log.trace("Sending probes from {}", device.id());
237 synchronized (this) { 249 synchronized (this) {
238 final Iterator<Long> fastIterator = this.fastPorts.iterator(); 250 final Iterator<Long> fastIterator = this.fastPorts.iterator();
...@@ -245,6 +257,7 @@ public class LinkDiscovery implements TimerTask { ...@@ -245,6 +257,7 @@ public class LinkDiscovery implements TimerTask {
245 sendProbes(portNumber); 257 sendProbes(portNumber);
246 258
247 } else { 259 } else {
260 + // Link down, demote to slowPorts
248 // Update fast and slow ports 261 // Update fast and slow ports
249 fastIterator.remove(); 262 fastIterator.remove();
250 this.slowPorts.add(portNumber); 263 this.slowPorts.add(portNumber);
...@@ -274,8 +287,12 @@ public class LinkDiscovery implements TimerTask { ...@@ -274,8 +287,12 @@ public class LinkDiscovery implements TimerTask {
274 } 287 }
275 288
276 public void start() { 289 public void start() {
277 - timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS); 290 + if (isStopped) {
278 - isStopped = false; 291 + timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS);
292 + isStopped = false;
293 + } else {
294 + log.warn("LinkDiscovery started multiple times?");
295 + }
279 } 296 }
280 297
281 /** 298 /**
...@@ -317,8 +334,8 @@ public class LinkDiscovery implements TimerTask { ...@@ -317,8 +334,8 @@ public class LinkDiscovery implements TimerTask {
317 } 334 }
318 335
319 private void sendProbes(Long portNumber) { 336 private void sendProbes(Long portNumber) {
320 - boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER; 337 + // TODO: should have suppression port configuration, not by type
321 - if (isMaster && device.type() != Device.Type.ROADM) { 338 + if (device.type() != Device.Type.ROADM) {
322 log.debug("Sending probes out to {}@{}", portNumber, device.id()); 339 log.debug("Sending probes out to {}@{}", portNumber, device.id());
323 OutboundPacket pkt = this.createOutBoundLLDP(portNumber); 340 OutboundPacket pkt = this.createOutBoundLLDP(portNumber);
324 pktService.emit(pkt); 341 pktService.emit(pkt);
......