Thomas Vachuska
Committed by Gerrit Code Review

Moving LLDP provider configuration processing off the event thread.

Change-Id: Ief44d354081107c037870d9a7ede60e8a6447113
......@@ -784,6 +784,7 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
@Override
public void event(NetworkConfigEvent event) {
executor.submit(() -> {
if (event.configClass() == LinkDiscoveryFromDevice.class &&
CONFIG_CHANGED.contains(event.type())) {
......@@ -822,6 +823,7 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
reconfigureSuppressionRules(cfg);
log.trace("Network config reconfigured");
}
});
}
}
}
......
......@@ -93,6 +93,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.onlab.junit.TestTools.assertAfter;
import static org.onosproject.provider.lldp.impl.LldpLinkProvider.DEFAULT_RULES;
......@@ -101,6 +102,7 @@ public class LldpLinkProviderTest {
private static final DeviceId DID1 = DeviceId.deviceId("of:0000000000000001");
private static final DeviceId DID2 = DeviceId.deviceId("of:0000000000000002");
private static final DeviceId DID3 = DeviceId.deviceId("of:0000000000000003");
private static final int EVENT_MS = 500;
private static Port pd1;
private static Port pd2;
......@@ -222,12 +224,13 @@ public class LldpLinkProviderTest {
DID3,
LinkDiscoveryFromDevice.class));
assertAfter(EVENT_MS, () -> {
// discovery helper for device is expected to be gone or stopped
LinkDiscovery linkDiscovery = provider.discoverers.get(DID3);
if (linkDiscovery != null) {
assertTrue("Discovery expected to be stopped", linkDiscovery.isStopped());
}
});
}
@Test
......@@ -499,7 +502,7 @@ public class LldpLinkProviderTest {
"TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId(), annotations);
}
@SuppressWarnings(value = { "unused" })
@SuppressWarnings(value = {"unused"})
private DeviceEvent portEvent(DeviceEvent.Type type, DeviceId did, PortNumber port) {
return new DeviceEvent(type, deviceService.getDevice(did),
deviceService.getPort(did, port));
......@@ -578,8 +581,10 @@ public class LldpLinkProviderTest {
configEvent(NetworkConfigEvent.Type.CONFIG_UPDATED);
assertAfter(EVENT_MS, () -> {
assertTrue(provider.rules().getSuppressedDeviceType().contains(deviceType1));
assertTrue(provider.rules().getSuppressedDeviceType().contains(deviceType2));
});
}
@Test
......@@ -594,9 +599,11 @@ public class LldpLinkProviderTest {
configEvent(NetworkConfigEvent.Type.CONFIG_ADDED);
assertAfter(EVENT_MS, () -> {
assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key1));
assertEquals(value1, provider.rules().getSuppressedAnnotation().get(key1));
assertFalse(provider.rules().getSuppressedAnnotation().containsKey(key2));
});
}
@Test
......@@ -610,19 +617,23 @@ public class LldpLinkProviderTest {
configEvent(NetworkConfigEvent.Type.CONFIG_ADDED);
assertAfter(EVENT_MS, () -> {
assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key1));
assertEquals(value1, provider.rules().getSuppressedAnnotation().get(key1));
assertFalse(provider.rules().getSuppressedAnnotation().containsKey(key2));
});
annotation.put(key2, value2);
cfg.annotation(annotation);
configEvent(NetworkConfigEvent.Type.CONFIG_UPDATED);
assertAfter(EVENT_MS, () -> {
assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key1));
assertEquals(value1, provider.rules().getSuppressedAnnotation().get(key1));
assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key2));
assertEquals(value2, provider.rules().getSuppressedAnnotation().get(key2));
});
}
private void configEvent(NetworkConfigEvent.Type evType) {
......@@ -706,6 +717,7 @@ public class LldpLinkProviderTest {
private final Map<DeviceId, Device> devices = new HashMap<>();
private final ArrayListMultimap<DeviceId, Port> ports =
ArrayListMultimap.create();
public TestDeviceService() {
Device d1 = new DefaultDevice(ProviderId.NONE, DID1, Device.Type.SWITCH,
"TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId());
......@@ -727,7 +739,7 @@ public class LldpLinkProviderTest {
devices.put(deviceId, device);
}
private void putPorts(DeviceId did, Port...ports) {
private void putPorts(DeviceId did, Port... ports) {
this.ports.putAll(did, Lists.newArrayList(ports));
}
......