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 { ...@@ -784,6 +784,7 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
784 784
785 @Override 785 @Override
786 public void event(NetworkConfigEvent event) { 786 public void event(NetworkConfigEvent event) {
787 + executor.submit(() -> {
787 if (event.configClass() == LinkDiscoveryFromDevice.class && 788 if (event.configClass() == LinkDiscoveryFromDevice.class &&
788 CONFIG_CHANGED.contains(event.type())) { 789 CONFIG_CHANGED.contains(event.type())) {
789 790
...@@ -822,6 +823,7 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -822,6 +823,7 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
822 reconfigureSuppressionRules(cfg); 823 reconfigureSuppressionRules(cfg);
823 log.trace("Network config reconfigured"); 824 log.trace("Network config reconfigured");
824 } 825 }
826 + });
825 } 827 }
826 } 828 }
827 } 829 }
......
...@@ -93,6 +93,7 @@ import static org.junit.Assert.assertFalse; ...@@ -93,6 +93,7 @@ import static org.junit.Assert.assertFalse;
93 import static org.junit.Assert.assertNotNull; 93 import static org.junit.Assert.assertNotNull;
94 import static org.junit.Assert.assertNull; 94 import static org.junit.Assert.assertNull;
95 import static org.junit.Assert.assertTrue; 95 import static org.junit.Assert.assertTrue;
96 +import static org.onlab.junit.TestTools.assertAfter;
96 import static org.onosproject.provider.lldp.impl.LldpLinkProvider.DEFAULT_RULES; 97 import static org.onosproject.provider.lldp.impl.LldpLinkProvider.DEFAULT_RULES;
97 98
98 99
...@@ -101,6 +102,7 @@ public class LldpLinkProviderTest { ...@@ -101,6 +102,7 @@ public class LldpLinkProviderTest {
101 private static final DeviceId DID1 = DeviceId.deviceId("of:0000000000000001"); 102 private static final DeviceId DID1 = DeviceId.deviceId("of:0000000000000001");
102 private static final DeviceId DID2 = DeviceId.deviceId("of:0000000000000002"); 103 private static final DeviceId DID2 = DeviceId.deviceId("of:0000000000000002");
103 private static final DeviceId DID3 = DeviceId.deviceId("of:0000000000000003"); 104 private static final DeviceId DID3 = DeviceId.deviceId("of:0000000000000003");
105 + private static final int EVENT_MS = 500;
104 106
105 private static Port pd1; 107 private static Port pd1;
106 private static Port pd2; 108 private static Port pd2;
...@@ -222,12 +224,13 @@ public class LldpLinkProviderTest { ...@@ -222,12 +224,13 @@ public class LldpLinkProviderTest {
222 DID3, 224 DID3,
223 LinkDiscoveryFromDevice.class)); 225 LinkDiscoveryFromDevice.class));
224 226
227 + assertAfter(EVENT_MS, () -> {
225 // discovery helper for device is expected to be gone or stopped 228 // discovery helper for device is expected to be gone or stopped
226 LinkDiscovery linkDiscovery = provider.discoverers.get(DID3); 229 LinkDiscovery linkDiscovery = provider.discoverers.get(DID3);
227 if (linkDiscovery != null) { 230 if (linkDiscovery != null) {
228 assertTrue("Discovery expected to be stopped", linkDiscovery.isStopped()); 231 assertTrue("Discovery expected to be stopped", linkDiscovery.isStopped());
229 } 232 }
230 - 233 + });
231 } 234 }
232 235
233 @Test 236 @Test
...@@ -499,7 +502,7 @@ public class LldpLinkProviderTest { ...@@ -499,7 +502,7 @@ public class LldpLinkProviderTest {
499 "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId(), annotations); 502 "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId(), annotations);
500 } 503 }
501 504
502 - @SuppressWarnings(value = { "unused" }) 505 + @SuppressWarnings(value = {"unused"})
503 private DeviceEvent portEvent(DeviceEvent.Type type, DeviceId did, PortNumber port) { 506 private DeviceEvent portEvent(DeviceEvent.Type type, DeviceId did, PortNumber port) {
504 return new DeviceEvent(type, deviceService.getDevice(did), 507 return new DeviceEvent(type, deviceService.getDevice(did),
505 deviceService.getPort(did, port)); 508 deviceService.getPort(did, port));
...@@ -578,8 +581,10 @@ public class LldpLinkProviderTest { ...@@ -578,8 +581,10 @@ public class LldpLinkProviderTest {
578 581
579 configEvent(NetworkConfigEvent.Type.CONFIG_UPDATED); 582 configEvent(NetworkConfigEvent.Type.CONFIG_UPDATED);
580 583
584 + assertAfter(EVENT_MS, () -> {
581 assertTrue(provider.rules().getSuppressedDeviceType().contains(deviceType1)); 585 assertTrue(provider.rules().getSuppressedDeviceType().contains(deviceType1));
582 assertTrue(provider.rules().getSuppressedDeviceType().contains(deviceType2)); 586 assertTrue(provider.rules().getSuppressedDeviceType().contains(deviceType2));
587 + });
583 } 588 }
584 589
585 @Test 590 @Test
...@@ -594,9 +599,11 @@ public class LldpLinkProviderTest { ...@@ -594,9 +599,11 @@ public class LldpLinkProviderTest {
594 599
595 configEvent(NetworkConfigEvent.Type.CONFIG_ADDED); 600 configEvent(NetworkConfigEvent.Type.CONFIG_ADDED);
596 601
602 + assertAfter(EVENT_MS, () -> {
597 assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key1)); 603 assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key1));
598 assertEquals(value1, provider.rules().getSuppressedAnnotation().get(key1)); 604 assertEquals(value1, provider.rules().getSuppressedAnnotation().get(key1));
599 assertFalse(provider.rules().getSuppressedAnnotation().containsKey(key2)); 605 assertFalse(provider.rules().getSuppressedAnnotation().containsKey(key2));
606 + });
600 } 607 }
601 608
602 @Test 609 @Test
...@@ -610,19 +617,23 @@ public class LldpLinkProviderTest { ...@@ -610,19 +617,23 @@ public class LldpLinkProviderTest {
610 617
611 configEvent(NetworkConfigEvent.Type.CONFIG_ADDED); 618 configEvent(NetworkConfigEvent.Type.CONFIG_ADDED);
612 619
620 + assertAfter(EVENT_MS, () -> {
613 assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key1)); 621 assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key1));
614 assertEquals(value1, provider.rules().getSuppressedAnnotation().get(key1)); 622 assertEquals(value1, provider.rules().getSuppressedAnnotation().get(key1));
615 assertFalse(provider.rules().getSuppressedAnnotation().containsKey(key2)); 623 assertFalse(provider.rules().getSuppressedAnnotation().containsKey(key2));
624 + });
616 625
617 annotation.put(key2, value2); 626 annotation.put(key2, value2);
618 cfg.annotation(annotation); 627 cfg.annotation(annotation);
619 628
620 configEvent(NetworkConfigEvent.Type.CONFIG_UPDATED); 629 configEvent(NetworkConfigEvent.Type.CONFIG_UPDATED);
621 630
631 + assertAfter(EVENT_MS, () -> {
622 assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key1)); 632 assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key1));
623 assertEquals(value1, provider.rules().getSuppressedAnnotation().get(key1)); 633 assertEquals(value1, provider.rules().getSuppressedAnnotation().get(key1));
624 assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key2)); 634 assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key2));
625 assertEquals(value2, provider.rules().getSuppressedAnnotation().get(key2)); 635 assertEquals(value2, provider.rules().getSuppressedAnnotation().get(key2));
636 + });
626 } 637 }
627 638
628 private void configEvent(NetworkConfigEvent.Type evType) { 639 private void configEvent(NetworkConfigEvent.Type evType) {
...@@ -706,6 +717,7 @@ public class LldpLinkProviderTest { ...@@ -706,6 +717,7 @@ public class LldpLinkProviderTest {
706 private final Map<DeviceId, Device> devices = new HashMap<>(); 717 private final Map<DeviceId, Device> devices = new HashMap<>();
707 private final ArrayListMultimap<DeviceId, Port> ports = 718 private final ArrayListMultimap<DeviceId, Port> ports =
708 ArrayListMultimap.create(); 719 ArrayListMultimap.create();
720 +
709 public TestDeviceService() { 721 public TestDeviceService() {
710 Device d1 = new DefaultDevice(ProviderId.NONE, DID1, Device.Type.SWITCH, 722 Device d1 = new DefaultDevice(ProviderId.NONE, DID1, Device.Type.SWITCH,
711 "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId()); 723 "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId());
...@@ -727,7 +739,7 @@ public class LldpLinkProviderTest { ...@@ -727,7 +739,7 @@ public class LldpLinkProviderTest {
727 devices.put(deviceId, device); 739 devices.put(deviceId, device);
728 } 740 }
729 741
730 - private void putPorts(DeviceId did, Port...ports) { 742 + private void putPorts(DeviceId did, Port... ports) {
731 this.ports.putAll(did, Lists.newArrayList(ports)); 743 this.ports.putAll(did, Lists.newArrayList(ports));
732 } 744 }
733 745
......