summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/providers/ovsdb/device
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/providers/ovsdb/device')
-rw-r--r--framework/src/onos/providers/ovsdb/device/pom.xml39
-rw-r--r--framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProvider.java134
-rw-r--r--framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/package-info.java21
-rw-r--r--framework/src/onos/providers/ovsdb/device/src/test/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProviderTest.java198
4 files changed, 392 insertions, 0 deletions
diff --git a/framework/src/onos/providers/ovsdb/device/pom.xml b/framework/src/onos/providers/ovsdb/device/pom.xml
new file mode 100644
index 00000000..e5010fa6
--- /dev/null
+++ b/framework/src/onos/providers/ovsdb/device/pom.xml
@@ -0,0 +1,39 @@
+<?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.3.0-SNAPSHOT</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
new file mode 100644
index 00000000..10e745e3
--- /dev/null
+++ b/framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProvider.java
@@ -0,0 +1,134 @@
+/*
+ * 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.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.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) {
+ // TODO: This will be implemented later.
+ log.info("Triggering probe on device {}", deviceId);
+ }
+
+ @Override
+ public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
+ // TODO: This will be implemented later.
+ }
+
+ @Override
+ public boolean isReachable(DeviceId deviceId) {
+ return true;
+ }
+
+ 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);
+
+ }
+ }
+}
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
new file mode 100644
index 00000000..1636371a
--- /dev/null
+++ b/framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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
new file mode 100644
index 00000000..5e4c5677
--- /dev/null
+++ b/framework/src/onos/providers/ovsdb/device/src/test/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProviderTest.java
@@ -0,0 +1,198 @@
+/*
+ * 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.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;
+ }
+
+ }
+
+}