Committed by
Gerrit Code Review
Unit tests for NetworkCongifLinksProvider
Also fixed a few bugs in the provider that were turned up by the new tests. Change-Id: Icafc945251b4d35ac3f285302af150c0a4d646d6
Showing
9 changed files
with
260 additions
and
100 deletions
| ... | @@ -17,6 +17,8 @@ package org.onosproject.net.config; | ... | @@ -17,6 +17,8 @@ package org.onosproject.net.config; |
| 17 | 17 | ||
| 18 | import java.util.Set; | 18 | import java.util.Set; |
| 19 | 19 | ||
| 20 | +import com.google.common.collect.ImmutableSet; | ||
| 21 | + | ||
| 20 | /** | 22 | /** |
| 21 | * Test adapter for network configuration service registry. | 23 | * Test adapter for network configuration service registry. |
| 22 | */ | 24 | */ |
| ... | @@ -29,11 +31,11 @@ public class NetworkConfigRegistryAdapter extends NetworkConfigServiceAdapter im | ... | @@ -29,11 +31,11 @@ public class NetworkConfigRegistryAdapter extends NetworkConfigServiceAdapter im |
| 29 | } | 31 | } |
| 30 | 32 | ||
| 31 | public Set<ConfigFactory> getConfigFactories() { | 33 | public Set<ConfigFactory> getConfigFactories() { |
| 32 | - return null; | 34 | + return ImmutableSet.of(); |
| 33 | } | 35 | } |
| 34 | 36 | ||
| 35 | public <S, C extends Config<S>> Set<ConfigFactory<S, C>> getConfigFactories(Class<S> subjectClass) { | 37 | public <S, C extends Config<S>> Set<ConfigFactory<S, C>> getConfigFactories(Class<S> subjectClass) { |
| 36 | - return null; | 38 | + return ImmutableSet.of(); |
| 37 | } | 39 | } |
| 38 | 40 | ||
| 39 | public <S, C extends Config<S>> ConfigFactory<S, C> getConfigFactory(Class<C> configClass) { | 41 | public <S, C extends Config<S>> ConfigFactory<S, C> getConfigFactory(Class<C> configClass) { | ... | ... |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | package org.onosproject.net.config; | 16 | package org.onosproject.net.config; |
| 17 | 17 | ||
| 18 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | +import com.google.common.collect.ImmutableSet; | ||
| 19 | 20 | ||
| 20 | import java.util.Set; | 21 | import java.util.Set; |
| 21 | 22 | ||
| ... | @@ -25,7 +26,7 @@ import java.util.Set; | ... | @@ -25,7 +26,7 @@ import java.util.Set; |
| 25 | public class NetworkConfigServiceAdapter implements NetworkConfigService { | 26 | public class NetworkConfigServiceAdapter implements NetworkConfigService { |
| 26 | @Override | 27 | @Override |
| 27 | public Set<Class> getSubjectClasses() { | 28 | public Set<Class> getSubjectClasses() { |
| 28 | - return null; | 29 | + return ImmutableSet.of(); |
| 29 | } | 30 | } |
| 30 | 31 | ||
| 31 | @Override | 32 | @Override |
| ... | @@ -45,17 +46,17 @@ public class NetworkConfigServiceAdapter implements NetworkConfigService { | ... | @@ -45,17 +46,17 @@ public class NetworkConfigServiceAdapter implements NetworkConfigService { |
| 45 | 46 | ||
| 46 | @Override | 47 | @Override |
| 47 | public <S> Set<S> getSubjects(Class<S> subjectClass) { | 48 | public <S> Set<S> getSubjects(Class<S> subjectClass) { |
| 48 | - return null; | 49 | + return ImmutableSet.of(); |
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | @Override | 52 | @Override |
| 52 | public <S, C extends Config<S>> Set<S> getSubjects(Class<S> subjectClass, Class<C> configClass) { | 53 | public <S, C extends Config<S>> Set<S> getSubjects(Class<S> subjectClass, Class<C> configClass) { |
| 53 | - return null; | 54 | + return ImmutableSet.of(); |
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | @Override | 57 | @Override |
| 57 | public <S> Set<? extends Config<S>> getConfigs(S subject) { | 58 | public <S> Set<? extends Config<S>> getConfigs(S subject) { |
| 58 | - return null; | 59 | + return ImmutableSet.of(); |
| 59 | } | 60 | } |
| 60 | 61 | ||
| 61 | @Override | 62 | @Override | ... | ... |
| ... | @@ -16,10 +16,15 @@ | ... | @@ -16,10 +16,15 @@ |
| 16 | package org.onosproject.net.link; | 16 | package org.onosproject.net.link; |
| 17 | 17 | ||
| 18 | import org.junit.Test; | 18 | import org.junit.Test; |
| 19 | +import org.onosproject.net.ConnectPoint; | ||
| 19 | import org.onosproject.net.DefaultAnnotations; | 20 | import org.onosproject.net.DefaultAnnotations; |
| 20 | import org.onosproject.net.DeviceId; | 21 | import org.onosproject.net.DeviceId; |
| 22 | +import org.onosproject.net.Link; | ||
| 23 | +import org.onosproject.net.NetTestTools; | ||
| 21 | import org.onosproject.net.PortNumber; | 24 | import org.onosproject.net.PortNumber; |
| 22 | 25 | ||
| 26 | +import com.google.common.testing.EqualsTester; | ||
| 27 | + | ||
| 23 | import static org.junit.Assert.assertEquals; | 28 | import static org.junit.Assert.assertEquals; |
| 24 | import static org.junit.Assert.assertTrue; | 29 | import static org.junit.Assert.assertTrue; |
| 25 | import static org.onosproject.net.DefaultLinkTest.cp; | 30 | import static org.onosproject.net.DefaultLinkTest.cp; |
| ... | @@ -44,7 +49,48 @@ public class DefaultLinkDescriptionTest { | ... | @@ -44,7 +49,48 @@ public class DefaultLinkDescriptionTest { |
| 44 | assertEquals("incorrect src", cp(DID1, P1), desc.src()); | 49 | assertEquals("incorrect src", cp(DID1, P1), desc.src()); |
| 45 | assertEquals("incorrect dst", cp(DID2, P1), desc.dst()); | 50 | assertEquals("incorrect dst", cp(DID2, P1), desc.dst()); |
| 46 | assertEquals("incorrect type", DIRECT, desc.type()); | 51 | assertEquals("incorrect type", DIRECT, desc.type()); |
| 47 | - assertTrue("incorrect annotatios", desc.toString().contains("Key=Value")); | 52 | + assertTrue("incorrect annotations", desc.toString().contains("Key=Value")); |
| 48 | } | 53 | } |
| 49 | 54 | ||
| 55 | + /** | ||
| 56 | + * Tests the equals(), hashCode() and toString() methods. | ||
| 57 | + */ | ||
| 58 | + @Test | ||
| 59 | + public void testEquals() { | ||
| 60 | + ConnectPoint connectPoint1 = NetTestTools.connectPoint("sw1", 1); | ||
| 61 | + ConnectPoint connectPoint2 = NetTestTools.connectPoint("sw2", 2); | ||
| 62 | + ConnectPoint connectPoint3 = NetTestTools.connectPoint("sw3", 3); | ||
| 63 | + | ||
| 64 | + DefaultLinkDescription link1 = | ||
| 65 | + new DefaultLinkDescription(connectPoint1, connectPoint2, | ||
| 66 | + Link.Type.DIRECT); | ||
| 67 | + DefaultLinkDescription sameAsLink1 = | ||
| 68 | + new DefaultLinkDescription(connectPoint1, connectPoint2, | ||
| 69 | + Link.Type.DIRECT); | ||
| 70 | + DefaultLinkDescription link2 = | ||
| 71 | + new DefaultLinkDescription(connectPoint1, connectPoint2, | ||
| 72 | + Link.Type.INDIRECT); | ||
| 73 | + DefaultLinkDescription link3 = | ||
| 74 | + new DefaultLinkDescription(connectPoint1, connectPoint3, | ||
| 75 | + Link.Type.DIRECT); | ||
| 76 | + DefaultLinkDescription link4 = | ||
| 77 | + new DefaultLinkDescription(connectPoint2, connectPoint3, | ||
| 78 | + Link.Type.DIRECT); | ||
| 79 | + DefaultLinkDescription link5 = | ||
| 80 | + new DefaultLinkDescription(connectPoint1, connectPoint2, | ||
| 81 | + Link.Type.DIRECT, false); | ||
| 82 | + DefaultLinkDescription link6 = | ||
| 83 | + new DefaultLinkDescription(connectPoint2, connectPoint3, | ||
| 84 | + Link.Type.DIRECT, DA); | ||
| 85 | + | ||
| 86 | + new EqualsTester() | ||
| 87 | + .addEqualityGroup(link1, sameAsLink1) | ||
| 88 | + .addEqualityGroup(link2) | ||
| 89 | + .addEqualityGroup(link3) | ||
| 90 | + .addEqualityGroup(link4) | ||
| 91 | + .addEqualityGroup(link5) | ||
| 92 | + .addEqualityGroup(link6) | ||
| 93 | + .testEquals(); | ||
| 94 | + | ||
| 95 | + } | ||
| 50 | } | 96 | } | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.net.link; | ||
| 17 | + | ||
| 18 | +import java.util.Set; | ||
| 19 | + | ||
| 20 | +import org.onosproject.net.provider.ProviderId; | ||
| 21 | + | ||
| 22 | +import com.google.common.collect.ImmutableSet; | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * Testing adapter for the LinkProviderRegistry API. | ||
| 26 | + */ | ||
| 27 | +public class LinkProviderRegistryAdapter implements LinkProviderRegistry { | ||
| 28 | + | ||
| 29 | + LinkProviderServiceAdapter providerService = null; | ||
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public LinkProviderService register(LinkProvider provider) { | ||
| 33 | + providerService = new LinkProviderServiceAdapter(provider); | ||
| 34 | + return providerService; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + public void unregister(LinkProvider provider) { | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + public Set<ProviderId> getProviders() { | ||
| 43 | + return ImmutableSet.of(providerService.provider().id()); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public LinkProviderServiceAdapter registeredProvider() { | ||
| 47 | + return providerService; | ||
| 48 | + } | ||
| 49 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.net.link; | ||
| 17 | + | ||
| 18 | +import java.util.HashMap; | ||
| 19 | +import java.util.List; | ||
| 20 | +import java.util.Map; | ||
| 21 | + | ||
| 22 | +import org.onosproject.net.ConnectPoint; | ||
| 23 | +import org.onosproject.net.DeviceId; | ||
| 24 | +import org.onosproject.net.LinkKey; | ||
| 25 | +import org.onosproject.net.provider.AbstractProviderService; | ||
| 26 | + | ||
| 27 | +import com.google.common.collect.Lists; | ||
| 28 | +import com.google.common.collect.Maps; | ||
| 29 | + | ||
| 30 | +public class LinkProviderServiceAdapter | ||
| 31 | + extends AbstractProviderService<LinkProvider> | ||
| 32 | + implements LinkProviderService { | ||
| 33 | + | ||
| 34 | + List<DeviceId> vanishedDpid = Lists.newLinkedList(); | ||
| 35 | + List<Long> vanishedPort = Lists.newLinkedList(); | ||
| 36 | + Map<DeviceId, DeviceId> discoveredLinks = Maps.newHashMap(); | ||
| 37 | + Map<LinkKey, LinkDescription> discoveredLinkDescriptions = new HashMap<>(); | ||
| 38 | + | ||
| 39 | + protected LinkProviderServiceAdapter(LinkProvider provider) { | ||
| 40 | + super(provider); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @Override | ||
| 44 | + public void linkDetected(LinkDescription linkDescription) { | ||
| 45 | + LinkKey key = LinkKey.linkKey(linkDescription.src(), linkDescription.dst()); | ||
| 46 | + discoveredLinkDescriptions.put(key, linkDescription); | ||
| 47 | + DeviceId sDid = linkDescription.src().deviceId(); | ||
| 48 | + DeviceId dDid = linkDescription.dst().deviceId(); | ||
| 49 | + discoveredLinks.put(sDid, dDid); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public void linkVanished(LinkDescription linkDescription) { | ||
| 54 | + LinkKey key = LinkKey.linkKey(linkDescription.src(), linkDescription.dst()); | ||
| 55 | + discoveredLinkDescriptions.remove(key); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + @Override | ||
| 59 | + public void linksVanished(ConnectPoint connectPoint) { | ||
| 60 | + vanishedPort.add(connectPoint.port().toLong()); | ||
| 61 | + | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Override | ||
| 65 | + public void linksVanished(DeviceId deviceId) { | ||
| 66 | + vanishedDpid.add(deviceId); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public List<DeviceId> vanishedDpid() { | ||
| 70 | + return vanishedDpid; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public List<Long> vanishedPort() { | ||
| 74 | + return vanishedPort; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + public Map<DeviceId, DeviceId> discoveredLinks() { | ||
| 78 | + return discoveredLinks; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + public Map<LinkKey, LinkDescription> discoveredLinkDescriptions() { | ||
| 82 | + return discoveredLinkDescriptions; | ||
| 83 | + } | ||
| 84 | +} |
| ... | @@ -15,13 +15,14 @@ | ... | @@ -15,13 +15,14 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.provider.lldp.impl; | 16 | package org.onosproject.provider.lldp.impl; |
| 17 | 17 | ||
| 18 | -import com.google.common.collect.ArrayListMultimap; | 18 | +import java.nio.ByteBuffer; |
| 19 | -import com.google.common.collect.ImmutableList; | 19 | +import java.util.Collections; |
| 20 | -import com.google.common.collect.ImmutableMap; | 20 | +import java.util.HashMap; |
| 21 | -import com.google.common.collect.ImmutableSet; | 21 | +import java.util.HashSet; |
| 22 | -import com.google.common.collect.Lists; | 22 | +import java.util.List; |
| 23 | -import com.google.common.collect.Maps; | 23 | +import java.util.Map; |
| 24 | -import com.google.common.collect.Sets; | 24 | +import java.util.Set; |
| 25 | +import java.util.concurrent.CompletableFuture; | ||
| 25 | 26 | ||
| 26 | import org.junit.After; | 27 | import org.junit.After; |
| 27 | import org.junit.Before; | 28 | import org.junit.Before; |
| ... | @@ -65,10 +66,8 @@ import org.onosproject.net.device.DeviceEvent; | ... | @@ -65,10 +66,8 @@ import org.onosproject.net.device.DeviceEvent; |
| 65 | import org.onosproject.net.device.DeviceListener; | 66 | import org.onosproject.net.device.DeviceListener; |
| 66 | import org.onosproject.net.device.DeviceServiceAdapter; | 67 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 67 | import org.onosproject.net.flow.TrafficTreatment; | 68 | import org.onosproject.net.flow.TrafficTreatment; |
| 68 | -import org.onosproject.net.link.LinkDescription; | 69 | +import org.onosproject.net.link.LinkProviderRegistryAdapter; |
| 69 | -import org.onosproject.net.link.LinkProvider; | 70 | +import org.onosproject.net.link.LinkProviderServiceAdapter; |
| 70 | -import org.onosproject.net.link.LinkProviderRegistry; | ||
| 71 | -import org.onosproject.net.link.LinkProviderService; | ||
| 72 | import org.onosproject.net.link.LinkServiceAdapter; | 71 | import org.onosproject.net.link.LinkServiceAdapter; |
| 73 | import org.onosproject.net.packet.DefaultInboundPacket; | 72 | import org.onosproject.net.packet.DefaultInboundPacket; |
| 74 | import org.onosproject.net.packet.InboundPacket; | 73 | import org.onosproject.net.packet.InboundPacket; |
| ... | @@ -76,27 +75,24 @@ import org.onosproject.net.packet.OutboundPacket; | ... | @@ -76,27 +75,24 @@ import org.onosproject.net.packet.OutboundPacket; |
| 76 | import org.onosproject.net.packet.PacketContext; | 75 | import org.onosproject.net.packet.PacketContext; |
| 77 | import org.onosproject.net.packet.PacketProcessor; | 76 | import org.onosproject.net.packet.PacketProcessor; |
| 78 | import org.onosproject.net.packet.PacketServiceAdapter; | 77 | import org.onosproject.net.packet.PacketServiceAdapter; |
| 79 | -import org.onosproject.net.provider.AbstractProviderService; | ||
| 80 | import org.onosproject.net.provider.ProviderId; | 78 | import org.onosproject.net.provider.ProviderId; |
| 81 | 79 | ||
| 82 | -import java.nio.ByteBuffer; | 80 | +import com.google.common.collect.ArrayListMultimap; |
| 83 | -import java.util.HashMap; | 81 | +import com.google.common.collect.ImmutableList; |
| 84 | -import java.util.HashSet; | 82 | +import com.google.common.collect.ImmutableMap; |
| 85 | -import java.util.List; | 83 | +import com.google.common.collect.ImmutableSet; |
| 86 | -import java.util.Map; | 84 | +import com.google.common.collect.Lists; |
| 87 | -import java.util.Set; | 85 | +import com.google.common.collect.Sets; |
| 88 | -import java.util.Collections; | ||
| 89 | -import java.util.concurrent.CompletableFuture; | ||
| 90 | 86 | ||
| 91 | import static org.easymock.EasyMock.createMock; | 87 | import static org.easymock.EasyMock.createMock; |
| 92 | import static org.easymock.EasyMock.expect; | 88 | import static org.easymock.EasyMock.expect; |
| 93 | import static org.easymock.EasyMock.replay; | 89 | import static org.easymock.EasyMock.replay; |
| 94 | -import static org.junit.Assert.assertNull; | ||
| 95 | -import static org.junit.Assert.assertNotNull; | ||
| 96 | import static org.junit.Assert.assertEquals; | 90 | import static org.junit.Assert.assertEquals; |
| 91 | +import static org.junit.Assert.assertFalse; | ||
| 92 | +import static org.junit.Assert.assertNotNull; | ||
| 93 | +import static org.junit.Assert.assertNull; | ||
| 97 | import static org.junit.Assert.assertTrue; | 94 | import static org.junit.Assert.assertTrue; |
| 98 | import static org.onosproject.provider.lldp.impl.LldpLinkProvider.DEFAULT_RULES; | 95 | import static org.onosproject.provider.lldp.impl.LldpLinkProvider.DEFAULT_RULES; |
| 99 | -import static org.junit.Assert.assertFalse; | ||
| 100 | 96 | ||
| 101 | 97 | ||
| 102 | public class LldpLinkProviderTest { | 98 | public class LldpLinkProviderTest { |
| ... | @@ -111,7 +107,7 @@ public class LldpLinkProviderTest { | ... | @@ -111,7 +107,7 @@ public class LldpLinkProviderTest { |
| 111 | private static Port pd4; | 107 | private static Port pd4; |
| 112 | 108 | ||
| 113 | private final LldpLinkProvider provider = new LldpLinkProvider(); | 109 | private final LldpLinkProvider provider = new LldpLinkProvider(); |
| 114 | - private final TestLinkRegistry linkRegistry = new TestLinkRegistry(); | 110 | + private final LinkProviderRegistryAdapter linkRegistry = new LinkProviderRegistryAdapter(); |
| 115 | private final TestLinkService linkService = new TestLinkService(); | 111 | private final TestLinkService linkService = new TestLinkService(); |
| 116 | private final TestPacketService packetService = new TestPacketService(); | 112 | private final TestPacketService packetService = new TestPacketService(); |
| 117 | private final TestDeviceService deviceService = new TestDeviceService(); | 113 | private final TestDeviceService deviceService = new TestDeviceService(); |
| ... | @@ -119,7 +115,7 @@ public class LldpLinkProviderTest { | ... | @@ -119,7 +115,7 @@ public class LldpLinkProviderTest { |
| 119 | private final TestNetworkConfigRegistry configRegistry = new TestNetworkConfigRegistry(); | 115 | private final TestNetworkConfigRegistry configRegistry = new TestNetworkConfigRegistry(); |
| 120 | 116 | ||
| 121 | private CoreService coreService; | 117 | private CoreService coreService; |
| 122 | - private TestLinkProviderService providerService; | 118 | + private LinkProviderServiceAdapter providerService; |
| 123 | 119 | ||
| 124 | private PacketProcessor testProcessor; | 120 | private PacketProcessor testProcessor; |
| 125 | private DeviceListener deviceListener; | 121 | private DeviceListener deviceListener; |
| ... | @@ -154,7 +150,10 @@ public class LldpLinkProviderTest { | ... | @@ -154,7 +150,10 @@ public class LldpLinkProviderTest { |
| 154 | provider.providerRegistry = linkRegistry; | 150 | provider.providerRegistry = linkRegistry; |
| 155 | provider.masterService = masterService; | 151 | provider.masterService = masterService; |
| 156 | provider.clusterMetadataService = new TestMetadataService(); | 152 | provider.clusterMetadataService = new TestMetadataService(); |
| 153 | + | ||
| 157 | provider.activate(null); | 154 | provider.activate(null); |
| 155 | + | ||
| 156 | + providerService = linkRegistry.registeredProvider(); | ||
| 158 | } | 157 | } |
| 159 | 158 | ||
| 160 | @Test | 159 | @Test |
| ... | @@ -521,7 +520,7 @@ public class LldpLinkProviderTest { | ... | @@ -521,7 +520,7 @@ public class LldpLinkProviderTest { |
| 521 | 520 | ||
| 522 | private boolean vanishedDpid(DeviceId... dids) { | 521 | private boolean vanishedDpid(DeviceId... dids) { |
| 523 | for (int i = 0; i < dids.length; i++) { | 522 | for (int i = 0; i < dids.length; i++) { |
| 524 | - if (!providerService.vanishedDpid.contains(dids[i])) { | 523 | + if (!providerService.vanishedDpid().contains(dids[i])) { |
| 525 | return false; | 524 | return false; |
| 526 | } | 525 | } |
| 527 | } | 526 | } |
| ... | @@ -530,7 +529,7 @@ public class LldpLinkProviderTest { | ... | @@ -530,7 +529,7 @@ public class LldpLinkProviderTest { |
| 530 | 529 | ||
| 531 | private boolean vanishedPort(Long... ports) { | 530 | private boolean vanishedPort(Long... ports) { |
| 532 | for (int i = 0; i < ports.length; i++) { | 531 | for (int i = 0; i < ports.length; i++) { |
| 533 | - if (!providerService.vanishedPort.contains(ports[i])) { | 532 | + if (!providerService.vanishedPort().contains(ports[i])) { |
| 534 | return false; | 533 | return false; |
| 535 | } | 534 | } |
| 536 | } | 535 | } |
| ... | @@ -538,9 +537,9 @@ public class LldpLinkProviderTest { | ... | @@ -538,9 +537,9 @@ public class LldpLinkProviderTest { |
| 538 | } | 537 | } |
| 539 | 538 | ||
| 540 | private boolean detectedLink(DeviceId src, DeviceId dst) { | 539 | private boolean detectedLink(DeviceId src, DeviceId dst) { |
| 541 | - for (DeviceId key : providerService.discoveredLinks.keySet()) { | 540 | + for (DeviceId key : providerService.discoveredLinks().keySet()) { |
| 542 | if (key.equals(src)) { | 541 | if (key.equals(src)) { |
| 543 | - return providerService.discoveredLinks.get(src).equals(dst); | 542 | + return providerService.discoveredLinks().get(src).equals(dst); |
| 544 | } | 543 | } |
| 545 | } | 544 | } |
| 546 | return false; | 545 | return false; |
| ... | @@ -631,65 +630,6 @@ public class LldpLinkProviderTest { | ... | @@ -631,65 +630,6 @@ public class LldpLinkProviderTest { |
| 631 | SuppressionConfig.class)); | 630 | SuppressionConfig.class)); |
| 632 | } | 631 | } |
| 633 | 632 | ||
| 634 | - | ||
| 635 | - private class TestLinkRegistry implements LinkProviderRegistry { | ||
| 636 | - | ||
| 637 | - @Override | ||
| 638 | - public LinkProviderService register(LinkProvider provider) { | ||
| 639 | - providerService = new TestLinkProviderService(provider); | ||
| 640 | - return providerService; | ||
| 641 | - } | ||
| 642 | - | ||
| 643 | - @Override | ||
| 644 | - public void unregister(LinkProvider provider) { | ||
| 645 | - } | ||
| 646 | - | ||
| 647 | - @Override | ||
| 648 | - public Set<ProviderId> getProviders() { | ||
| 649 | - return null; | ||
| 650 | - } | ||
| 651 | - | ||
| 652 | - } | ||
| 653 | - | ||
| 654 | - private class TestLinkProviderService | ||
| 655 | - extends AbstractProviderService<LinkProvider> | ||
| 656 | - implements LinkProviderService { | ||
| 657 | - | ||
| 658 | - List<DeviceId> vanishedDpid = Lists.newLinkedList(); | ||
| 659 | - List<Long> vanishedPort = Lists.newLinkedList(); | ||
| 660 | - Map<DeviceId, DeviceId> discoveredLinks = Maps.newHashMap(); | ||
| 661 | - | ||
| 662 | - protected TestLinkProviderService(LinkProvider provider) { | ||
| 663 | - super(provider); | ||
| 664 | - } | ||
| 665 | - | ||
| 666 | - @Override | ||
| 667 | - public void linkDetected(LinkDescription linkDescription) { | ||
| 668 | - DeviceId sDid = linkDescription.src().deviceId(); | ||
| 669 | - DeviceId dDid = linkDescription.dst().deviceId(); | ||
| 670 | - discoveredLinks.put(sDid, dDid); | ||
| 671 | - } | ||
| 672 | - | ||
| 673 | - @Override | ||
| 674 | - public void linkVanished(LinkDescription linkDescription) { | ||
| 675 | - } | ||
| 676 | - | ||
| 677 | - @Override | ||
| 678 | - public void linksVanished(ConnectPoint connectPoint) { | ||
| 679 | - vanishedPort.add(connectPoint.port().toLong()); | ||
| 680 | - | ||
| 681 | - } | ||
| 682 | - | ||
| 683 | - @Override | ||
| 684 | - public void linksVanished(DeviceId deviceId) { | ||
| 685 | - vanishedDpid.add(deviceId); | ||
| 686 | - } | ||
| 687 | - | ||
| 688 | - | ||
| 689 | - } | ||
| 690 | - | ||
| 691 | - | ||
| 692 | - | ||
| 693 | private class TestPacketContext implements PacketContext { | 633 | private class TestPacketContext implements PacketContext { |
| 694 | 634 | ||
| 695 | protected Device device; | 635 | protected Device device; | ... | ... |
| ... | @@ -56,6 +56,15 @@ | ... | @@ -56,6 +56,15 @@ |
| 56 | <artifactId>easymock</artifactId> | 56 | <artifactId>easymock</artifactId> |
| 57 | <scope>test</scope> | 57 | <scope>test</scope> |
| 58 | </dependency> | 58 | </dependency> |
| 59 | + | ||
| 60 | + <dependency> | ||
| 61 | + <groupId>org.onosproject</groupId> | ||
| 62 | + <artifactId>onos-api</artifactId> | ||
| 63 | + <version>${project.version}</version> | ||
| 64 | + <classifier>tests</classifier> | ||
| 65 | + <scope>test</scope> | ||
| 66 | + </dependency> | ||
| 67 | + | ||
| 59 | </dependencies> | 68 | </dependencies> |
| 60 | 69 | ||
| 61 | </project> | 70 | </project> | ... | ... |
| ... | @@ -117,7 +117,7 @@ public class NetworkConfigLinksProvider | ... | @@ -117,7 +117,7 @@ public class NetworkConfigLinksProvider |
| 117 | private final InternalDeviceListener deviceListener = new InternalDeviceListener(); | 117 | private final InternalDeviceListener deviceListener = new InternalDeviceListener(); |
| 118 | private final InternalConfigListener cfgListener = new InternalConfigListener(); | 118 | private final InternalConfigListener cfgListener = new InternalConfigListener(); |
| 119 | 119 | ||
| 120 | - private Set<LinkKey> configuredLinks = new HashSet<>(); | 120 | + protected Set<LinkKey> configuredLinks = new HashSet<>(); |
| 121 | 121 | ||
| 122 | public NetworkConfigLinksProvider() { | 122 | public NetworkConfigLinksProvider() { |
| 123 | super(new ProviderId("lldp", PROVIDER_NAME)); | 123 | super(new ProviderId("lldp", PROVIDER_NAME)); |
| ... | @@ -259,6 +259,35 @@ public class NetworkConfigLinksProvider | ... | @@ -259,6 +259,35 @@ public class NetworkConfigLinksProvider |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | /** | 261 | /** |
| 262 | + * Removes after stopping discovery helper for specified device. | ||
| 263 | + * @param deviceId device to remove | ||
| 264 | + */ | ||
| 265 | + private void removeDevice(final DeviceId deviceId) { | ||
| 266 | + discoverers.computeIfPresent(deviceId, (did, ld) -> { | ||
| 267 | + ld.stop(); | ||
| 268 | + return null; | ||
| 269 | + }); | ||
| 270 | + | ||
| 271 | + } | ||
| 272 | + | ||
| 273 | + /** | ||
| 274 | + * Removes a port from the specified discovery helper. | ||
| 275 | + * @param port the port | ||
| 276 | + */ | ||
| 277 | + private void removePort(Port port) { | ||
| 278 | + if (port.element() instanceof Device) { | ||
| 279 | + Device d = (Device) port.element(); | ||
| 280 | + LinkDiscovery ld = discoverers.get(d.id()); | ||
| 281 | + if (ld != null) { | ||
| 282 | + ld.removePort(port.number()); | ||
| 283 | + } | ||
| 284 | + } else { | ||
| 285 | + log.warn("Attempted to remove non-Device port", port); | ||
| 286 | + } | ||
| 287 | + } | ||
| 288 | + | ||
| 289 | + | ||
| 290 | + /** | ||
| 262 | * Processes incoming packets. | 291 | * Processes incoming packets. |
| 263 | */ | 292 | */ |
| 264 | private class InternalPacketProcessor implements PacketProcessor { | 293 | private class InternalPacketProcessor implements PacketProcessor { |
| ... | @@ -355,21 +384,21 @@ public class NetworkConfigLinksProvider | ... | @@ -355,21 +384,21 @@ public class NetworkConfigLinksProvider |
| 355 | updateDevice(device).ifPresent(ld -> updatePort(ld, port)); | 384 | updateDevice(device).ifPresent(ld -> updatePort(ld, port)); |
| 356 | } else { | 385 | } else { |
| 357 | log.debug("Port down {}", port); | 386 | log.debug("Port down {}", port); |
| 358 | - //removePort(port); | 387 | + removePort(port); |
| 359 | providerService.linksVanished(new ConnectPoint(port.element().id(), | 388 | providerService.linksVanished(new ConnectPoint(port.element().id(), |
| 360 | port.number())); | 389 | port.number())); |
| 361 | } | 390 | } |
| 362 | break; | 391 | break; |
| 363 | case PORT_REMOVED: | 392 | case PORT_REMOVED: |
| 364 | log.debug("Port removed {}", port); | 393 | log.debug("Port removed {}", port); |
| 365 | - //removePort(port); | 394 | + removePort(port); |
| 366 | providerService.linksVanished(new ConnectPoint(port.element().id(), | 395 | providerService.linksVanished(new ConnectPoint(port.element().id(), |
| 367 | port.number())); | 396 | port.number())); |
| 368 | break; | 397 | break; |
| 369 | case DEVICE_REMOVED: | 398 | case DEVICE_REMOVED: |
| 370 | case DEVICE_SUSPENDED: | 399 | case DEVICE_SUSPENDED: |
| 371 | log.debug("Device removed {}", deviceId); | 400 | log.debug("Device removed {}", deviceId); |
| 372 | - //removeDevice(deviceId); | 401 | + removeDevice(deviceId); |
| 373 | providerService.linksVanished(deviceId); | 402 | providerService.linksVanished(deviceId); |
| 374 | break; | 403 | break; |
| 375 | case DEVICE_AVAILABILITY_CHANGED: | 404 | case DEVICE_AVAILABILITY_CHANGED: |
| ... | @@ -378,7 +407,7 @@ public class NetworkConfigLinksProvider | ... | @@ -378,7 +407,7 @@ public class NetworkConfigLinksProvider |
| 378 | updateDevice(device).ifPresent(ld -> updatePorts(ld, deviceId)); | 407 | updateDevice(device).ifPresent(ld -> updatePorts(ld, deviceId)); |
| 379 | } else { | 408 | } else { |
| 380 | log.debug("Device down {}", deviceId); | 409 | log.debug("Device down {}", deviceId); |
| 381 | - //removeDevice(deviceId); | 410 | + removeDevice(deviceId); |
| 382 | providerService.linksVanished(deviceId); | 411 | providerService.linksVanished(deviceId); |
| 383 | } | 412 | } |
| 384 | break; | 413 | break; | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment