diff options
Diffstat (limited to 'framework/src/onos/providers/ovsdb')
16 files changed, 0 insertions, 1391 deletions
diff --git a/framework/src/onos/providers/ovsdb/app/app.xml b/framework/src/onos/providers/ovsdb/app/app.xml deleted file mode 100644 index c3334994..00000000 --- a/framework/src/onos/providers/ovsdb/app/app.xml +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Copyright 2015 Open Networking Laboratory - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - --> -<app name="org.onosproject.ovsdb" origin="ON.Lab" version="${project.version}" - featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" - features="${project.artifactId}"> - <description>${project.description}</description> - - <artifact>mvn:${project.groupId}/onos-ovsdb-rfc/${project.version}</artifact> - <artifact>mvn:${project.groupId}/onos-ovsdb-api/${project.version}</artifact> - <artifact>mvn:${project.groupId}/onos-ovsdb-ctl/${project.version}</artifact> - <artifact>mvn:${project.groupId}/onos-drivers/${project.version}</artifact> - - <artifact>mvn:${project.groupId}/onos-ovsdb-provider-device/${project.version}</artifact> - <artifact>mvn:${project.groupId}/onos-ovsdb-provider-host/${project.version}</artifact> - <artifact>mvn:${project.groupId}/onos-ovsdb-provider-tunnel/${project.version}</artifact> -</app> diff --git a/framework/src/onos/providers/ovsdb/app/features.xml b/framework/src/onos/providers/ovsdb/app/features.xml deleted file mode 100644 index d2cb0aa6..00000000 --- a/framework/src/onos/providers/ovsdb/app/features.xml +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes"?> -<!-- - ~ Copyright 2015 Open Networking Laboratory - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - --> -<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> - <feature name="${project.artifactId}" version="${project.version}" - description="${project.description}"> - <feature>onos-api</feature> - <bundle>mvn:io.netty/netty-common/4.0.23.Final</bundle> - <bundle>mvn:io.netty/netty-buffer/4.0.23.Final</bundle> - <bundle>mvn:io.netty/netty-transport/4.0.23.Final</bundle> - <bundle>mvn:io.netty/netty-handler/4.0.23.Final</bundle> - <bundle>mvn:io.netty/netty-codec/4.0.23.Final</bundle> - <bundle>mvn:${project.groupId}/onos-ovsdb-rfc/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-ovsdb-api/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-ovsdb-ctl/${project.version}</bundle> - - <bundle>mvn:${project.groupId}/onos-ovsdb-provider-device/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-ovsdb-provider-host/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-ovsdb-provider-tunnel/${project.version}</bundle> - </feature> -</features> diff --git a/framework/src/onos/providers/ovsdb/app/pom.xml b/framework/src/onos/providers/ovsdb/app/pom.xml deleted file mode 100644 index 9101c0f8..00000000 --- a/framework/src/onos/providers/ovsdb/app/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Copyright 2015 Open Networking Laboratory - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb-providers</artifactId> - <version>1.4.0-rc1</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>onos-ovsdatabase</artifactId> - <packaging>pom</packaging> - - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb-rfc</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb-api</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb-ctl</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-drivers</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb-provider-device</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb-provider-host</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb-provider-tunnel</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - -</project> diff --git a/framework/src/onos/providers/ovsdb/device/pom.xml b/framework/src/onos/providers/ovsdb/device/pom.xml deleted file mode 100644 index f770d73f..00000000 --- a/framework/src/onos/providers/ovsdb/device/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ -<?xml version="1.0"?> -<!-- - ~ Copyright 2015 Open Networking Laboratory - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - --> -<project - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" - xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb-providers</artifactId> - <version>1.4.0-rc1</version> - </parent> - - <artifactId>onos-ovsdb-provider-device</artifactId> - <packaging>bundle</packaging> - - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - -</project> diff --git a/framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProvider.java b/framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProvider.java deleted file mode 100644 index d573458e..00000000 --- a/framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProvider.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.ovsdb.providers.device; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.slf4j.LoggerFactory.getLogger; - -import java.net.URI; - -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.Service; -import org.onlab.packet.ChassisId; -import org.onlab.packet.IpAddress; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.MastershipRole; -import org.onosproject.net.SparseAnnotations; -import org.onosproject.net.device.DefaultDeviceDescription; -import org.onosproject.net.device.DeviceDescription; -import org.onosproject.net.device.DeviceProvider; -import org.onosproject.net.device.DeviceProviderRegistry; -import org.onosproject.net.device.DeviceProviderService; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.provider.AbstractProvider; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.ovsdb.controller.OvsdbClientService; -import org.onosproject.ovsdb.controller.OvsdbController; -import org.onosproject.ovsdb.controller.OvsdbNodeId; -import org.onosproject.ovsdb.controller.OvsdbNodeListener; -import org.slf4j.Logger; - -/** - * Provider which uses an ovsdb controller to detect device. - */ -@Component(immediate = true) -@Service -public class OvsdbDeviceProvider extends AbstractProvider - implements DeviceProvider { - private final Logger log = getLogger(getClass()); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceProviderRegistry providerRegistry; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceService deviceService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected OvsdbController controller; - - private DeviceProviderService providerService; - private OvsdbNodeListener innerNodeListener = new InnerOvsdbNodeListener(); - protected static final String ISNOTNULL = "OvsdbNodeId is not null"; - private static final String UNKNOWN = "unknown"; - - @Activate - public void activate() { - providerService = providerRegistry.register(this); - controller.addNodeListener(innerNodeListener); - log.info("Started"); - } - - @Deactivate - public void deactivate() { - providerRegistry.unregister(this); - providerService = null; - log.info("Stopped"); - } - - public OvsdbDeviceProvider() { - super(new ProviderId("ovsdb", "org.onosproject.ovsdb.provider.device")); - } - - @Override - public void triggerProbe(DeviceId deviceId) { - log.info("Triggering probe on device {}", deviceId); - if (!isReachable(deviceId)) { - log.error("Failed to probe device {}", deviceId); - providerService.deviceDisconnected(deviceId); - return; - } else { - log.trace("Confirmed device {} connection", deviceId); - } - } - - @Override - public void roleChanged(DeviceId deviceId, MastershipRole newRole) { - // TODO: This will be implemented later. - } - - @Override - public boolean isReachable(DeviceId deviceId) { - OvsdbClientService ovsdbClient = controller.getOvsdbClient(changeDeviceIdToNodeId(deviceId)); - return !(ovsdbClient == null || !ovsdbClient.isConnected()); - } - - private class InnerOvsdbNodeListener implements OvsdbNodeListener { - - @Override - public void nodeAdded(OvsdbNodeId nodeId) { - checkNotNull(nodeId, ISNOTNULL); - DeviceId deviceId = DeviceId.deviceId(nodeId.toString()); - URI uri = URI.create(nodeId.toString()); - ChassisId cid = new ChassisId(); - String ipAddress = nodeId.getIpAddress(); - SparseAnnotations annotations = DefaultAnnotations.builder() - .set("ipaddress", ipAddress).build(); - DeviceDescription deviceDescription = new DefaultDeviceDescription( - uri, - Device.Type.CONTROLLER, - UNKNOWN, UNKNOWN, - UNKNOWN, UNKNOWN, - cid, - annotations); - providerService.deviceConnected(deviceId, deviceDescription); - - } - - @Override - public void nodeRemoved(OvsdbNodeId nodeId) { - checkNotNull(nodeId, ISNOTNULL); - DeviceId deviceId = DeviceId.deviceId(nodeId.toString()); - providerService.deviceDisconnected(deviceId); - - } - } - - private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) { - String[] strings = deviceId.toString().split(":"); - if (strings.length < 1) { - return null; - } - return new OvsdbNodeId(IpAddress.valueOf(strings[1]), 0); - } -} diff --git a/framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/package-info.java b/framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/package-info.java deleted file mode 100644 index 1636371a..00000000 --- a/framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - *Provider that uses ovsdb controller as a means of infrastructure device discovery. - * - */ -package org.onosproject.ovsdb.providers.device;
\ No newline at end of file diff --git a/framework/src/onos/providers/ovsdb/device/src/test/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProviderTest.java b/framework/src/onos/providers/ovsdb/device/src/test/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProviderTest.java deleted file mode 100644 index 7663a64d..00000000 --- a/framework/src/onos/providers/ovsdb/device/src/test/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProviderTest.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.ovsdb.providers.device; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onlab.packet.TpPort; -import org.onosproject.net.DeviceId; -import org.onosproject.net.MastershipRole; -import org.onosproject.net.device.DeviceDescription; -import org.onosproject.net.device.DeviceProvider; -import org.onosproject.net.device.DeviceProviderRegistry; -import org.onosproject.net.device.DeviceProviderService; -import org.onosproject.net.device.PortDescription; -import org.onosproject.net.device.PortStatistics; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.ovsdb.controller.OvsdbClientService; -import org.onosproject.ovsdb.controller.OvsdbController; -import org.onosproject.ovsdb.controller.OvsdbEventListener; -import org.onosproject.ovsdb.controller.OvsdbNodeId; -import org.onosproject.ovsdb.controller.OvsdbNodeListener; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; - -/** - * Test for ovsdb device provider. - */ -public class OvsdbDeviceProviderTest { - private final OvsdbDeviceProvider provider = new OvsdbDeviceProvider(); - private final TestDeviceRegistry registry = new TestDeviceRegistry(); - private final TestController controller = new TestController(); - - @Before - public void startUp() { - provider.providerRegistry = registry; - provider.controller = controller; - provider.activate(); - assertNotNull("provider should be registered", registry.provider); - } - - @After - public void tearDown() { - provider.deactivate(); - provider.controller = null; - provider.providerRegistry = null; - } - - @Test - public void triggerProbe() { - - } - - @Test - public void testNodeAdded() { - controller.listener.nodeAdded(new OvsdbNodeId(IpAddress - .valueOf("192.168.202.36"), 5000)); - assertEquals("ovsdb node added", 1, registry.connected.size()); - } - - @Test - public void testNodeRemoved() { - controller.listener.nodeAdded(new OvsdbNodeId(IpAddress - .valueOf("192.168.202.36"), 5000)); - controller.listener.nodeRemoved(new OvsdbNodeId(IpAddress - .valueOf("192.168.202.36"), 5000)); - assertEquals("ovsdb node removded", 0, registry.connected.size()); - } - - private class TestDeviceRegistry implements DeviceProviderRegistry { - DeviceProvider provider; - - Set<DeviceId> connected = new HashSet<>(); - Multimap<DeviceId, PortDescription> ports = HashMultimap.create(); - PortDescription descr = null; - - @Override - public DeviceProviderService register(DeviceProvider provider) { - this.provider = provider; - return new TestProviderService(); - } - - @Override - public void unregister(DeviceProvider provider) { - } - - @Override - public Set<ProviderId> getProviders() { - return null; - } - - private class TestProviderService implements DeviceProviderService { - - @Override - public DeviceProvider provider() { - return null; - } - - @Override - public void deviceConnected(DeviceId deviceId, - DeviceDescription deviceDescription) { - connected.add(deviceId); - } - - @Override - public void deviceDisconnected(DeviceId deviceId) { - connected.remove(deviceId); - ports.removeAll(deviceId); - } - - @Override - public void updatePorts(DeviceId deviceId, - List<PortDescription> portDescriptions) { - for (PortDescription p : portDescriptions) { - ports.put(deviceId, p); - } - } - - @Override - public void portStatusChanged(DeviceId deviceId, - PortDescription portDescription) { - ports.put(deviceId, portDescription); - descr = portDescription; - } - - @Override - public void receivedRoleReply(DeviceId deviceId, - MastershipRole requested, - MastershipRole response) { - } - - @Override - public void updatePortStatistics(DeviceId deviceId, - Collection<PortStatistics> portStatistics) { - - } - - } - } - - private class TestController implements OvsdbController { - OvsdbNodeListener listener = null; - - @Override - public void addNodeListener(OvsdbNodeListener listener) { - this.listener = listener; - } - - @Override - public void removeNodeListener(OvsdbNodeListener listener) { - this.listener = null; - } - - @Override - public void addOvsdbEventListener(OvsdbEventListener listener) { - - } - - @Override - public void removeOvsdbEventListener(OvsdbEventListener listener) { - - } - - @Override - public List<OvsdbNodeId> getNodeIds() { - return null; - } - - @Override - public OvsdbClientService getOvsdbClient(OvsdbNodeId nodeId) { - return null; - } - - @Override - public void connect(IpAddress ip, TpPort port) { - - } - } - -} diff --git a/framework/src/onos/providers/ovsdb/host/pom.xml b/framework/src/onos/providers/ovsdb/host/pom.xml deleted file mode 100644 index 3acc7a20..00000000 --- a/framework/src/onos/providers/ovsdb/host/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ -<?xml version="1.0"?> -<!-- - ~ Copyright 2015 Open Networking Laboratory - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - --> -<project - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" - xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb-providers</artifactId> - <version>1.4.0-rc1</version> - </parent> - - <artifactId>onos-ovsdb-provider-host</artifactId> - <packaging>bundle</packaging> - - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb-api</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - -</project> diff --git a/framework/src/onos/providers/ovsdb/host/src/main/java/org/onosproject/ovsdb/provider/host/OvsdbHostProvider.java b/framework/src/onos/providers/ovsdb/host/src/main/java/org/onosproject/ovsdb/provider/host/OvsdbHostProvider.java deleted file mode 100644 index 031fda78..00000000 --- a/framework/src/onos/providers/ovsdb/host/src/main/java/org/onosproject/ovsdb/provider/host/OvsdbHostProvider.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.ovsdb.provider.host; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.onlab.util.Tools.toHex; -import static org.slf4j.LoggerFactory.getLogger; - -import java.net.URI; -import java.net.URISyntaxException; - -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.Service; -import org.onlab.packet.VlanId; -import org.onosproject.core.CoreService; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Host; -import org.onosproject.net.HostId; -import org.onosproject.net.HostLocation; -import org.onosproject.net.PortNumber; -import org.onosproject.net.SparseAnnotations; -import org.onosproject.net.host.DefaultHostDescription; -import org.onosproject.net.host.HostDescription; -import org.onosproject.net.host.HostProvider; -import org.onosproject.net.host.HostProviderRegistry; -import org.onosproject.net.host.HostProviderService; -import org.onosproject.net.host.HostService; -import org.onosproject.net.provider.AbstractProvider; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.ovsdb.controller.EventSubject; -import org.onosproject.ovsdb.controller.OvsdbController; -import org.onosproject.ovsdb.controller.OvsdbEvent; -import org.onosproject.ovsdb.controller.OvsdbEventListener; -import org.onosproject.ovsdb.controller.OvsdbEventSubject; -import org.slf4j.Logger; - -/** - * Provider which uses an ovsdb controller to detect host. - */ -@Component(immediate = true) -@Service -public class OvsdbHostProvider extends AbstractProvider implements HostProvider { - private final Logger log = getLogger(getClass()); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected HostProviderRegistry providerRegistry; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected HostService hostService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected OvsdbController controller; - - private HostProviderService providerService; - private OvsdbEventListener innerEventListener = new InnerOvsdbEventListener(); - - @Activate - public void activate() { - providerService = providerRegistry.register(this); - controller.addOvsdbEventListener(innerEventListener); - log.info("Started"); - } - - @Deactivate - public void deactivate() { - providerRegistry.unregister(this); - providerService = null; - log.info("Stopped"); - } - - public OvsdbHostProvider() { - super(new ProviderId("ovsdb", "org.onosproject.ovsdb.provider.host")); - } - - @Override - public void triggerProbe(Host host) { - log.info("Triggering probe on host {}", host); - } - - private class InnerOvsdbEventListener implements OvsdbEventListener { - - @Override - public void handle(OvsdbEvent<EventSubject> event) { - OvsdbEventSubject subject = null; - if (event.subject() instanceof OvsdbEventSubject) { - subject = (OvsdbEventSubject) event.subject(); - } - checkNotNull(subject, "EventSubject is not null"); - // If ifaceid is null,it indicates this is not a vm port. - if (subject.ifaceid() == null) { - return; - } - switch (event.type()) { - case PORT_ADDED: - HostId hostId = HostId.hostId(subject.hwAddress(), VlanId.vlanId()); - DeviceId deviceId = DeviceId.deviceId(uri(subject.dpid().value())); - PortNumber portNumber = PortNumber.portNumber(subject - .portNumber().value(), subject.portName().value()); - HostLocation loaction = new HostLocation(deviceId, portNumber, - 0L); - SparseAnnotations annotations = DefaultAnnotations.builder() - .set("ifaceid", subject.ifaceid().value()).build(); - HostDescription hostDescription = new DefaultHostDescription( - subject.hwAddress(), - VlanId.vlanId(), - loaction, - annotations); - providerService.hostDetected(hostId, hostDescription); - break; - case PORT_REMOVED: - HostId host = HostId.hostId(subject.hwAddress(), VlanId.vlanId()); - providerService.hostVanished(host); - break; - default: - break; - } - - } - - } - - public URI uri(String value) { - try { - return new URI("of", toHex(Long.valueOf(value)), null); - } catch (URISyntaxException e) { - return null; - } - } -} diff --git a/framework/src/onos/providers/ovsdb/host/src/main/java/org/onosproject/ovsdb/provider/host/package-info.java b/framework/src/onos/providers/ovsdb/host/src/main/java/org/onosproject/ovsdb/provider/host/package-info.java deleted file mode 100644 index 895ae2ec..00000000 --- a/framework/src/onos/providers/ovsdb/host/src/main/java/org/onosproject/ovsdb/provider/host/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - *Provider that uses ovsdb controller as a means of infrastructure host discovery. - * - */ -package org.onosproject.ovsdb.provider.host;
\ No newline at end of file diff --git a/framework/src/onos/providers/ovsdb/host/src/test/java/org/onosproject/ovsdb/provider/host/OvsdbHostProviderTest.java b/framework/src/onos/providers/ovsdb/host/src/test/java/org/onosproject/ovsdb/provider/host/OvsdbHostProviderTest.java deleted file mode 100644 index 01e07dd8..00000000 --- a/framework/src/onos/providers/ovsdb/host/src/test/java/org/onosproject/ovsdb/provider/host/OvsdbHostProviderTest.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.ovsdb.provider.host; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.List; -import java.util.Set; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onlab.packet.TpPort; -import org.onosproject.net.DeviceId; -import org.onosproject.net.HostId; -import org.onosproject.net.host.HostDescription; -import org.onosproject.net.host.HostProvider; -import org.onosproject.net.host.HostProviderRegistry; -import org.onosproject.net.host.HostProviderService; -import org.onosproject.net.provider.AbstractProviderService; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.ovsdb.controller.DefaultEventSubject; -import org.onosproject.ovsdb.controller.EventSubject; -import org.onosproject.ovsdb.controller.OvsdbClientService; -import org.onosproject.ovsdb.controller.OvsdbController; -import org.onosproject.ovsdb.controller.OvsdbDatapathId; -import org.onosproject.ovsdb.controller.OvsdbEvent; -import org.onosproject.ovsdb.controller.OvsdbEventListener; -import org.onosproject.ovsdb.controller.OvsdbIfaceId; -import org.onosproject.ovsdb.controller.OvsdbNodeId; -import org.onosproject.ovsdb.controller.OvsdbNodeListener; -import org.onosproject.ovsdb.controller.OvsdbPortName; -import org.onosproject.ovsdb.controller.OvsdbPortNumber; -import org.onosproject.ovsdb.controller.OvsdbPortType; - -/** - * Test for ovsdb host provider. - */ -public class OvsdbHostProviderTest { - private static final MacAddress MAC = MacAddress - .valueOf("00:00:11:00:00:01"); - private final OvsdbHostProvider provider = new OvsdbHostProvider(); - private final TestHostRegistry hostRegistry = new TestHostRegistry(); - protected OvsdbControllerTest controller = new OvsdbControllerTest(); - private TestHostProviderService providerService; - - @Before - public void setUp() { - provider.providerRegistry = hostRegistry; - provider.controller = controller; - provider.activate(); - } - - @Test - public void basics() { - assertNotNull("registration expected", providerService); - assertEquals("incorrect provider", provider, providerService.provider()); - } - - @Test - public void portAdded() { - DefaultEventSubject eventSubject = new DefaultEventSubject(MAC, null, - new OvsdbPortName("portName"), - new OvsdbPortNumber(0L), - new OvsdbDatapathId("10002"), - new OvsdbPortType("vxlan"), - new OvsdbIfaceId("102345")); - controller.ovsdbEventListener - .handle(new OvsdbEvent<EventSubject>( - OvsdbEvent.Type.PORT_ADDED, - eventSubject)); - assertNotNull("never went throught the provider service", - providerService.added); - - } - - @Test - public void portRemoved() { - DefaultEventSubject eventSubject = new DefaultEventSubject(MAC, null, - new OvsdbPortName("portName"), - new OvsdbPortNumber(0L), - new OvsdbDatapathId("10002"), - new OvsdbPortType("vxlan"), - new OvsdbIfaceId("102345")); - controller.ovsdbEventListener - .handle(new OvsdbEvent<EventSubject>( - OvsdbEvent.Type.PORT_REMOVED, - eventSubject)); - assertEquals("port status unhandled", 1, providerService.removeCount); - } - - @After - public void tearDown() { - provider.deactivate(); - provider.coreService = null; - provider.providerRegistry = null; - } - - private class TestHostRegistry implements HostProviderRegistry { - - @Override - public HostProviderService register(HostProvider provider) { - providerService = new TestHostProviderService(provider); - return providerService; - } - - @Override - public void unregister(HostProvider provider) { - } - - @Override - public Set<ProviderId> getProviders() { - return null; - } - - } - - private class TestHostProviderService - extends AbstractProviderService<HostProvider> - implements HostProviderService { - - DeviceId added = null; - DeviceId moved = null; - DeviceId spine = null; - public int removeCount; - - protected TestHostProviderService(HostProvider provider) { - super(provider); - } - - @Override - public void hostDetected(HostId hostId, HostDescription hostDescription, boolean replaceIps) { - DeviceId descr = hostDescription.location().deviceId(); - if (added == null) { - added = descr; - } else if ((moved == null) && !descr.equals(added)) { - moved = descr; - } else { - spine = descr; - } - } - - @Override - public void hostVanished(HostId hostId) { - removeCount++; - } - - @Override - public void removeIpFromHost(HostId hostId, IpAddress ipAddress) { - - } - - } - - private class OvsdbControllerTest implements OvsdbController { - private OvsdbEventListener ovsdbEventListener = null; - - @Override - public void addNodeListener(OvsdbNodeListener listener) { - - } - - @Override - public void removeNodeListener(OvsdbNodeListener listener) { - - } - - @Override - public void addOvsdbEventListener(OvsdbEventListener listener) { - ovsdbEventListener = listener; - - } - - @Override - public void removeOvsdbEventListener(OvsdbEventListener listener) { - ovsdbEventListener = null; - - } - - @Override - public List<OvsdbNodeId> getNodeIds() { - return null; - } - - @Override - public OvsdbClientService getOvsdbClient(OvsdbNodeId nodeId) { - return null; - } - - @Override - public void connect(IpAddress ip, TpPort port) { - - } - } -} diff --git a/framework/src/onos/providers/ovsdb/pom.xml b/framework/src/onos/providers/ovsdb/pom.xml deleted file mode 100644 index 1256f1a2..00000000 --- a/framework/src/onos/providers/ovsdb/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ -<?xml version="1.0"?> -<!-- - ~ Copyright 2015 Open Networking Laboratory - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - --> -<project - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" - xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-providers</artifactId> - <version>1.4.0-rc1</version> - </parent> - - <artifactId>onos-ovsdb-providers</artifactId> - <packaging>pom</packaging> - - <modules> - <module>device</module> - <module>host</module> - <module>tunnel</module> - <module>app</module> - </modules> - - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb-api</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.easymock</groupId> - <artifactId>easymock</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - -</project> diff --git a/framework/src/onos/providers/ovsdb/tunnel/pom.xml b/framework/src/onos/providers/ovsdb/tunnel/pom.xml deleted file mode 100644 index 455b1747..00000000 --- a/framework/src/onos/providers/ovsdb/tunnel/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ -<?xml version="1.0"?> -<!-- - ~ Copyright 2015 Open Networking Laboratory - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - --> -<project - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" - xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb-providers</artifactId> - <version>1.4.0-rc1</version> - </parent> - - <artifactId>onos-ovsdb-provider-tunnel</artifactId> - <packaging>bundle</packaging> - - <dependencies> - <dependency> - <groupId>org.easymock</groupId> - <artifactId>easymock</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - -</project> diff --git a/framework/src/onos/providers/ovsdb/tunnel/src/main/java/org/onosproject/ovsdb/provider/tunnel/OvsdbTunnelProvider.java b/framework/src/onos/providers/ovsdb/tunnel/src/main/java/org/onosproject/ovsdb/provider/tunnel/OvsdbTunnelProvider.java deleted file mode 100644 index 244e6fe0..00000000 --- a/framework/src/onos/providers/ovsdb/tunnel/src/main/java/org/onosproject/ovsdb/provider/tunnel/OvsdbTunnelProvider.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.ovsdb.provider.tunnel; - -import static org.slf4j.LoggerFactory.getLogger; - -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.Service; -import org.onosproject.incubator.net.tunnel.Tunnel; -import org.onosproject.incubator.net.tunnel.TunnelDescription; -import org.onosproject.incubator.net.tunnel.TunnelId; -import org.onosproject.incubator.net.tunnel.TunnelProvider; -import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry; -import org.onosproject.incubator.net.tunnel.TunnelProviderService; -import org.onosproject.incubator.net.tunnel.TunnelService; -import org.onosproject.net.ElementId; -import org.onosproject.net.Path; -import org.onosproject.net.provider.AbstractProvider; -import org.onosproject.net.provider.ProviderId; -import org.slf4j.Logger; - -/** - * Provider which uses when tunnel added/removed. - */ -@Component(immediate = true) -@Service -public class OvsdbTunnelProvider extends AbstractProvider - implements TunnelProvider { - private final Logger log = getLogger(getClass()); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected TunnelProviderRegistry providerRegistry; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected TunnelService tunnelService; - - private TunnelProviderService providerService; - - @Activate - public void activate() { - providerService = providerRegistry.register(this); - log.info("Started"); - } - - @Deactivate - public void deactivate() { - providerRegistry.unregister(this); - providerService = null; - log.info("Stopped"); - } - - public OvsdbTunnelProvider() { - super(new ProviderId("ovsdb", "org.onosproject.ovsdb.provider.tunnel")); - } - - @Override - public void setupTunnel(Tunnel tunnel, Path path) { - // TODO: This will be implemented later. - } - - @Override - public void setupTunnel(ElementId srcElement, Tunnel tunnel, Path path) { - // TODO: This will be implemented later. - } - - @Override - public void releaseTunnel(Tunnel tunnel) { - // TODO: This will be implemented later. - } - - @Override - public void releaseTunnel(ElementId srcElement, Tunnel tunnel) { - // TODO: This will be implemented later. - } - - @Override - public void updateTunnel(Tunnel tunnel, Path path) { - // TODO: This will be implemented later. - } - - @Override - public void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path) { - // TODO: This will be implemented later. - } - - @Override - public TunnelId tunnelAdded(TunnelDescription tunnel) { - return providerService.tunnelAdded(tunnel); - } - - @Override - public void tunnelRemoved(TunnelDescription tunnel) { - providerService.tunnelRemoved(tunnel); - } - - @Override - public void tunnelUpdated(TunnelDescription tunnel) { - providerService.tunnelUpdated(tunnel); - } - - @Override - public Tunnel tunnelQueryById(TunnelId tunnelId) { - // TODO: This will be implemented later. - return null; - } -} diff --git a/framework/src/onos/providers/ovsdb/tunnel/src/main/java/org/onosproject/ovsdb/provider/tunnel/package-info.java b/framework/src/onos/providers/ovsdb/tunnel/src/main/java/org/onosproject/ovsdb/provider/tunnel/package-info.java deleted file mode 100644 index 4f8a1095..00000000 --- a/framework/src/onos/providers/ovsdb/tunnel/src/main/java/org/onosproject/ovsdb/provider/tunnel/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - *Provider that uses ovsdb controller as a means of infrastructure tunnel discovery. - * - */ -package org.onosproject.ovsdb.provider.tunnel;
\ No newline at end of file diff --git a/framework/src/onos/providers/ovsdb/tunnel/src/test/java/org/onosproject/ovsdb/provider/tunnel/OvsdbTunnelProviderTest.java b/framework/src/onos/providers/ovsdb/tunnel/src/test/java/org/onosproject/ovsdb/provider/tunnel/OvsdbTunnelProviderTest.java deleted file mode 100644 index 3d1549e5..00000000 --- a/framework/src/onos/providers/ovsdb/tunnel/src/test/java/org/onosproject/ovsdb/provider/tunnel/OvsdbTunnelProviderTest.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.ovsdb.provider.tunnel; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onosproject.core.DefaultGroupId; -import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription; -import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; -import org.onosproject.incubator.net.tunnel.Tunnel; -import org.onosproject.incubator.net.tunnel.TunnelDescription; -import org.onosproject.incubator.net.tunnel.TunnelEndPoint; -import org.onosproject.incubator.net.tunnel.TunnelId; -import org.onosproject.incubator.net.tunnel.TunnelName; -import org.onosproject.incubator.net.tunnel.TunnelProvider; -import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry; -import org.onosproject.incubator.net.tunnel.TunnelProviderService; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DefaultPath; -import org.onosproject.net.Link; -import org.onosproject.net.SparseAnnotations; -import org.onosproject.net.provider.AbstractProviderService; -import org.onosproject.net.provider.ProviderId; - -/** - * Test for ovsdb tunnel provider. - */ -public class OvsdbTunnelProviderTest { - private final OvsdbTunnelProvider provider = new OvsdbTunnelProvider(); - private final TestTunnelRegistry tunnelRegistry = new TestTunnelRegistry(); - private TestTunnelProviderService providerService; - - @Before - public void setUp() { - provider.providerRegistry = tunnelRegistry; - provider.activate(); - } - - @Test - public void basics() { - assertNotNull("registration expected", providerService); - assertEquals("incorrect provider", provider, providerService.provider()); - } - - @Test - public void testTunnelAdded() { - TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress - .valueOf("192.168.1.1")); - TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress - .valueOf("192.168.1.3")); - SparseAnnotations annotations = DefaultAnnotations.builder() - .set("bandwidth", "1024").build(); - Link link = new DefaultLink( - this.provider.id(), - ConnectPoint.deviceConnectPoint("192.168.2.3/20"), - ConnectPoint.deviceConnectPoint("192.168.2.4/30"), - Link.Type.DIRECT); - List<Link> links = new ArrayList<Link>(); - links.add(link); - TunnelDescription tunnel = new DefaultTunnelDescription( - TunnelId.valueOf("1234"), - src, - dst, - Tunnel.Type.VXLAN, - new DefaultGroupId(0), - this.provider.id(), - TunnelName.tunnelName("tunnel12"), - new DefaultPath(this.provider.id(), links, 0.3), - annotations); - provider.tunnelAdded(tunnel); - assertEquals(1, providerService.tunnelSet.size()); - } - - @Test - public void testTunnelRemoved() { - TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress - .valueOf("192.168.1.1")); - TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress - .valueOf("192.168.1.3")); - SparseAnnotations annotations = DefaultAnnotations.builder() - .set("bandwidth", "1024").build(); - Link link = new DefaultLink( - this.provider.id(), - ConnectPoint.deviceConnectPoint("192.168.2.3/20"), - ConnectPoint.deviceConnectPoint("192.168.2.4/30"), - Link.Type.DIRECT); - List<Link> links = new ArrayList<Link>(); - links.add(link); - TunnelDescription tunnel = new DefaultTunnelDescription( - TunnelId.valueOf("1234"), - src, - dst, - Tunnel.Type.VXLAN, - new DefaultGroupId(0), - this.provider.id(), - TunnelName.tunnelName("tunnel1"), - new DefaultPath(this.provider.id(), links, 0.3), - annotations); - provider.tunnelRemoved(tunnel); - assertEquals(0, providerService.tunnelSet.size()); - } - - @After - public void tearDown() { - provider.deactivate(); - provider.providerRegistry = null; - } - - private class TestTunnelRegistry implements TunnelProviderRegistry { - - @Override - public TunnelProviderService register(TunnelProvider provider) { - providerService = new TestTunnelProviderService(provider); - return providerService; - } - - @Override - public void unregister(TunnelProvider provider) { - - } - - @Override - public Set<ProviderId> getProviders() { - return null; - } - - } - - private class TestTunnelProviderService - extends AbstractProviderService<TunnelProvider> - implements TunnelProviderService { - Set<TunnelDescription> tunnelSet = new HashSet<TunnelDescription>(); - - protected TestTunnelProviderService(TunnelProvider provider) { - super(provider); - } - - @Override - public TunnelId tunnelAdded(TunnelDescription tunnel) { - tunnelSet.add(tunnel); - return null; - } - - @Override - public void tunnelRemoved(TunnelDescription tunnel) { - tunnelSet.remove(tunnel); - } - - @Override - public void tunnelUpdated(TunnelDescription tunnel) { - - } - - @Override - public Tunnel tunnelQueryById(TunnelId tunnelId) { - return null; - } - - } -} |