diff options
author | CNlucius <lukai1@huawei.com> | 2016-09-13 11:40:12 +0800 |
---|---|---|
committer | CNlucius <lukai1@huawei.com> | 2016-09-13 11:41:53 +0800 |
commit | b731e2f1dd0972409b136aebc7b463dd72c9cfad (patch) | |
tree | 5107d7d80c19ad8076c2c97c2b5ef8d1cf3ab903 /framework/src/onos/providers/ovsdb/device | |
parent | ee93993458266114c29271a481ef9ce7ce621b2a (diff) |
ONOSFW-171
O/S-SFC-ONOS scenario documentation
Change-Id: I51ae1cf736ea24ab6680f8edca1b2bf5dd598365
Signed-off-by: CNlucius <lukai1@huawei.com>
Diffstat (limited to 'framework/src/onos/providers/ovsdb/device')
4 files changed, 0 insertions, 414 deletions
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) { - - } - } - -} |