ONOS-3754 Create driver/behavior for Ciena waveserver
Change-Id: I2e8741f0ad858eb712f7fe4f4a5fdf5e146aefd6
diff --git a/cli/src/main/java/org/onosproject/cli/net/DevicePortGetterCommand.java b/cli/src/main/java/org/onosproject/cli/net/DevicePortGetterCommand.java
new file mode 100644
index 0000000..384d149
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/net/DevicePortGetterCommand.java
@@ -0,0 +1,52 @@
+/*
+ * 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.cli.net;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.PortDiscovery;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.net.driver.DriverService;
+
+/**
+ * Command that gets the configuration of the specified type from the specified
+ * device. If configuration cannot be retrieved it prints an error string.
+ *
+ * This is a temporary development tool for use until yang integration is complete.
+ * This uses a not properly specified behavior. DO NOT USE AS AN EXAMPLE.
+ */
+
+@Command(scope = "onos", name = "device-ports",
+ description = "Gets the ports of the specified device.")
+public class DevicePortGetterCommand extends AbstractShellCommand {
+
+ @Argument(index = 0, name = "uri", description = "Device ID",
+ required = true, multiValued = false)
+ String uri = null;
+ private DeviceId deviceId;
+
+ @Override
+ protected void execute() {
+ DriverService service = get(DriverService.class);
+ deviceId = DeviceId.deviceId(uri);
+ DriverHandler h = service.createHandler(deviceId);
+ PortDiscovery portConfig = h.behaviour(PortDiscovery.class);
+ print(portConfig.getPorts().toString());
+ }
+
+}
\ No newline at end of file
diff --git a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 0d6c229..59ebeb2 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -127,6 +127,12 @@
</completers>
</command>
<command>
+ <action class="org.onosproject.cli.net.DevicePortGetterCommand"/>
+ <completers>
+ <ref component-id="deviceIdCompleter"/>
+ </completers>
+ </command>
+ <command>
<action class="org.onosproject.cli.net.DeviceRemoveCommand"/>
<completers>
<ref component-id="deviceIdCompleter"/>
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/PortDiscovery.java b/core/api/src/main/java/org/onosproject/net/behaviour/PortDiscovery.java
new file mode 100644
index 0000000..a825a8d
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/PortDiscovery.java
@@ -0,0 +1,37 @@
+/*
+ *
+ * * Copyright 2016 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.net.behaviour;
+
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.driver.HandlerBehaviour;
+
+import java.util.List;
+
+/**
+ * Discovers the set of ports from a device through a device specific protocol.
+ * The returned ports are not retrieved from the information stored in ONOS.
+ */
+public interface PortDiscovery extends HandlerBehaviour {
+
+ /**
+ * Retrieves the set of ports from a device.
+ * @return a set of port descriptions.
+ */
+ List<PortDescription> getPorts();
+}
\ No newline at end of file
diff --git a/drivers/features.xml b/drivers/features.xml
index cb2ca0b..0c08678 100644
--- a/drivers/features.xml
+++ b/drivers/features.xml
@@ -25,5 +25,7 @@
<bundle>mvn:${project.groupId}/onos-ovsdb-rfc/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-netconf-api/${project.version}</bundle>
+
+ <bundle>mvn:${project.groupId}/onos-restsb-api/${project.version}</bundle>
</feature>
</features>
diff --git a/drivers/pom.xml b/drivers/pom.xml
index ebf118a..c09b657 100644
--- a/drivers/pom.xml
+++ b/drivers/pom.xml
@@ -52,11 +52,11 @@
<artifactId>onos-of-api</artifactId>
</dependency>
- <dependency>
+ <dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-core-serializers</artifactId>
- <version>${project.version}</version>
- </dependency>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ovsdb-api</artifactId>
@@ -69,6 +69,11 @@
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
+ <artifactId>onos-restsb-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
<artifactId>onos-netconf-api</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/drivers/src/main/java/org/onosproject/driver/XmlConfigParser.java b/drivers/src/main/java/org/onosproject/driver/XmlConfigParser.java
new file mode 100644
index 0000000..a5a05953
--- /dev/null
+++ b/drivers/src/main/java/org/onosproject/driver/XmlConfigParser.java
@@ -0,0 +1,174 @@
+/*
+ * 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.driver;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.configuration.tree.ConfigurationNode;
+import org.onlab.packet.IpAddress;
+import org.onosproject.net.ChannelSpacing;
+import org.onosproject.net.GridType;
+import org.onosproject.net.OchSignal;
+import org.onosproject.net.OduSignalType;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.behaviour.ControllerInfo;
+import org.onosproject.net.device.OchPortDescription;
+import org.onosproject.net.device.PortDescription;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Parser for Netconf XML configurations and replys.
+ */
+public final class XmlConfigParser {
+ public static final Logger log = LoggerFactory
+ .getLogger(XmlConfigParser.class);
+
+ private XmlConfigParser() {
+ //not called, preventing any allocation
+ }
+
+
+ public static HierarchicalConfiguration loadXml(InputStream xmlStream) {
+ XMLConfiguration cfg = new XMLConfiguration();
+ try {
+ cfg.load(xmlStream);
+ return cfg;
+ } catch (ConfigurationException e) {
+ throw new IllegalArgumentException("Cannot load xml from Stream", e);
+ }
+ }
+
+ public static List<ControllerInfo> parseStreamControllers(HierarchicalConfiguration cfg) {
+ List<ControllerInfo> controllers = new ArrayList<>();
+ List<HierarchicalConfiguration> fields =
+ cfg.configurationsAt("data.capable-switch." +
+ "logical-switches." +
+ "switch.controllers.controller");
+ for (HierarchicalConfiguration sub : fields) {
+ controllers.add(new ControllerInfo(
+ IpAddress.valueOf(sub.getString("ip-address")),
+ Integer.parseInt(sub.getString("port")),
+ sub.getString("protocol")));
+ }
+ return controllers;
+ }
+
+ public static String parseSwitchId(HierarchicalConfiguration cfg) {
+ HierarchicalConfiguration field =
+ cfg.configurationAt("data.capable-switch." +
+ "logical-switches." +
+ "switch");
+ return field.getProperty("id").toString();
+ }
+
+ public static String parseCapableSwitchId(HierarchicalConfiguration cfg) {
+ HierarchicalConfiguration field =
+ cfg.configurationAt("data.capable-switch");
+ return field.getProperty("id").toString();
+ }
+
+ public static String createControllersConfig(HierarchicalConfiguration cfg,
+ HierarchicalConfiguration actualCfg,
+ String target, String netconfOperation,
+ String controllerOperation,
+ List<ControllerInfo> controllers) {
+ //cfg.getKeys().forEachRemaining(key -> System.out.println(key));
+ cfg.setProperty("edit-config.target", target);
+ cfg.setProperty("edit-config.default-operation", netconfOperation);
+ cfg.setProperty("edit-config.config.capable-switch.id",
+ parseCapableSwitchId(actualCfg));
+ cfg.setProperty("edit-config.config.capable-switch." +
+ "logical-switches.switch.id", parseSwitchId(actualCfg));
+ List<ConfigurationNode> newControllers = new ArrayList<>();
+ for (ControllerInfo ci : controllers) {
+ XMLConfiguration controller = new XMLConfiguration();
+ controller.setRoot(new HierarchicalConfiguration.Node("controller"));
+ String id = ci.type() + ":" + ci.ip() + ":" + ci.port();
+ controller.setProperty("id", id);
+ controller.setProperty("ip-address", ci.ip());
+ controller.setProperty("port", ci.port());
+ controller.setProperty("protocol", ci.type());
+ newControllers.add(controller.getRootNode());
+ }
+ cfg.addNodes("edit-config.config.capable-switch.logical-switches." +
+ "switch.controllers", newControllers);
+ XMLConfiguration editcfg = (XMLConfiguration) cfg;
+ StringWriter stringWriter = new StringWriter();
+ try {
+ editcfg.save(stringWriter);
+ } catch (ConfigurationException e) {
+ log.error("createControllersConfig()", e);
+ }
+ String s = stringWriter.toString()
+ .replaceAll("<controller>",
+ "<controller nc:operation=\"" + controllerOperation + "\">");
+ s = s.replace("<target>" + target + "</target>",
+ "<target><" + target + "/></target>");
+ return s;
+
+ }
+
+ public static List<HierarchicalConfiguration> parseWaveServerCienaPorts(HierarchicalConfiguration cfg) {
+ return cfg.configurationsAt("ws-ports.port-interface");
+ }
+
+ public static PortDescription parseWaveServerCienaOCHPorts(long portNumber, long oduPortSpeed,
+ HierarchicalConfiguration config,
+ SparseAnnotations annotations) {
+ final List<String> tunableType = Lists.newArrayList("Performance-Optimized", "Accelerated");
+ final String transmitterPath = "ptp-config.transmitter-state";
+ final String tunablePath = "ptp-config.adv-config.tx-tuning-mode";
+ final String gridTypePath = "ptp-config.adv-config.wl-spacing";
+ final String frequencyPath = "ptp-config.adv-config.frequency";
+
+ boolean isEnabled = config.getString(transmitterPath).equals("enabled");
+ boolean isTunable = tunableType.contains(config.getString(tunablePath));
+
+ //FIXME change when all optical types have two way information methods, see jira tickets
+ final int speed100GbpsinMbps = 100000;
+ OduSignalType oduSignalType = oduPortSpeed == speed100GbpsinMbps ? OduSignalType.ODU4 : null;
+ GridType gridType = config.getString(gridTypePath).equals("FlexGrid") ? GridType.FLEX : null;
+ ChannelSpacing chSpacing = gridType == GridType.FLEX ? ChannelSpacing.CHL_6P25GHZ : null;
+
+ //Working in Ghz //(Nominal central frequency - 193.1)/channelSpacing = spacingMultiplier
+ final int baseFrequency = 193100;
+ int spacingMult = (int) (toGbps((Integer.parseInt(config.getString(frequencyPath)) -
+ baseFrequency)) / toGbpsFromHz(chSpacing.frequency().asHz())); //FIXME is there a better way ?
+
+ return new OchPortDescription(PortNumber.portNumber(portNumber), isEnabled, oduSignalType, isTunable,
+ new OchSignal(gridType, chSpacing, spacingMult, 1), annotations);
+ }
+
+ //FIXME remove when all optical types have two way information methods, see jira tickets
+ private static long toGbps(long speed) {
+ return speed * 1000;
+ }
+
+ private static long toGbpsFromHz(long speed) {
+ return speed / 1000;
+ }
+ //TODO implement mor methods for parsing configuration when you need them
+}
diff --git a/drivers/src/main/java/org/onosproject/driver/netconf/NetconfControllerConfig.java b/drivers/src/main/java/org/onosproject/driver/netconf/NetconfControllerConfig.java
index 1805f53..4b81069 100644
--- a/drivers/src/main/java/org/onosproject/driver/netconf/NetconfControllerConfig.java
+++ b/drivers/src/main/java/org/onosproject/driver/netconf/NetconfControllerConfig.java
@@ -17,6 +17,7 @@
package org.onosproject.driver.netconf;
import com.google.common.base.Preconditions;
+import org.onosproject.driver.XmlConfigParser;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.ControllerConfig;
import org.onosproject.net.behaviour.ControllerInfo;
diff --git a/drivers/src/main/java/org/onosproject/driver/netconf/XmlConfigParser.java b/drivers/src/main/java/org/onosproject/driver/netconf/XmlConfigParser.java
deleted file mode 100644
index 5443097..0000000
--- a/drivers/src/main/java/org/onosproject/driver/netconf/XmlConfigParser.java
+++ /dev/null
@@ -1,126 +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.driver.netconf;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.commons.configuration.tree.ConfigurationNode;
-import org.onlab.packet.IpAddress;
-import org.onosproject.net.behaviour.ControllerInfo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Parser for Netconf XML configurations and replys.
- */
-final class XmlConfigParser {
- public static final Logger log = LoggerFactory
- .getLogger(XmlConfigParser.class);
-
- private XmlConfigParser() {
- //not called, preventing any allocation
- }
-
-
- protected static HierarchicalConfiguration loadXml(InputStream xmlStream) {
- XMLConfiguration cfg = new XMLConfiguration();
- try {
- cfg.load(xmlStream);
- return cfg;
- } catch (ConfigurationException e) {
- throw new IllegalArgumentException("Cannot load xml from Stream", e);
- }
- }
-
- protected static List<ControllerInfo> parseStreamControllers(HierarchicalConfiguration cfg) {
- List<ControllerInfo> controllers = new ArrayList<>();
- List<HierarchicalConfiguration> fields =
- cfg.configurationsAt("data.capable-switch." +
- "logical-switches." +
- "switch.controllers.controller");
- for (HierarchicalConfiguration sub : fields) {
- controllers.add(new ControllerInfo(
- IpAddress.valueOf(sub.getString("ip-address")),
- Integer.parseInt(sub.getString("port")),
- sub.getString("protocol")));
- }
- return controllers;
- }
-
- protected static String parseSwitchId(HierarchicalConfiguration cfg) {
- HierarchicalConfiguration field =
- cfg.configurationAt("data.capable-switch." +
- "logical-switches." +
- "switch");
- return field.getProperty("id").toString();
- }
-
- protected static String parseCapableSwitchId(HierarchicalConfiguration cfg) {
- HierarchicalConfiguration field =
- cfg.configurationAt("data.capable-switch");
- return field.getProperty("id").toString();
- }
-
- protected static String createControllersConfig(HierarchicalConfiguration cfg,
- HierarchicalConfiguration actualCfg,
- String target, String netconfOperation,
- String controllerOperation,
- List<ControllerInfo> controllers) {
- //cfg.getKeys().forEachRemaining(key -> System.out.println(key));
- cfg.setProperty("edit-config.target", target);
- cfg.setProperty("edit-config.default-operation", netconfOperation);
- cfg.setProperty("edit-config.config.capable-switch.id",
- parseCapableSwitchId(actualCfg));
- cfg.setProperty("edit-config.config.capable-switch." +
- "logical-switches.switch.id", parseSwitchId(actualCfg));
- List<ConfigurationNode> newControllers = new ArrayList<>();
- for (ControllerInfo ci : controllers) {
- XMLConfiguration controller = new XMLConfiguration();
- controller.setRoot(new HierarchicalConfiguration.Node("controller"));
- String id = ci.type() + ":" + ci.ip() + ":" + ci.port();
- controller.setProperty("id", id);
- controller.setProperty("ip-address", ci.ip());
- controller.setProperty("port", ci.port());
- controller.setProperty("protocol", ci.type());
- newControllers.add(controller.getRootNode());
- }
- cfg.addNodes("edit-config.config.capable-switch.logical-switches." +
- "switch.controllers", newControllers);
- XMLConfiguration editcfg = (XMLConfiguration) cfg;
- StringWriter stringWriter = new StringWriter();
- try {
- editcfg.save(stringWriter);
- } catch (ConfigurationException e) {
- log.error("createControllersConfig()", e);
- }
- String s = stringWriter.toString()
- .replaceAll("<controller>",
- "<controller nc:operation=\"" + controllerOperation + "\">");
- s = s.replace("<target>" + target + "</target>",
- "<target><" + target + "/></target>");
- return s;
-
- }
-
- //TODO implement mor methods for parsing configuration when you need them
-}
diff --git a/drivers/src/main/java/org/onosproject/driver/rest/PortDiscoveryCienaWaveserverImpl.java b/drivers/src/main/java/org/onosproject/driver/rest/PortDiscoveryCienaWaveserverImpl.java
new file mode 100644
index 0000000..fa4abfb
--- /dev/null
+++ b/drivers/src/main/java/org/onosproject/driver/rest/PortDiscoveryCienaWaveserverImpl.java
@@ -0,0 +1,111 @@
+/*
+ *
+ * * Copyright 2016 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.driver.rest;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.onosproject.driver.XmlConfigParser;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.CltSignalType;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.behaviour.PortDiscovery;
+import org.onosproject.net.device.OduCltPortDescription;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.protocol.rest.RestSBController;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Discovers the ports from a Ciena WaveServer Rest device.
+ */
+public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour
+ implements PortDiscovery {
+
+ private static final String SPEED = "speed";
+ private static final String GBPS = "Gbps";
+ private static final String PORT_ID = "port-id";
+ private static final String XML = "xml";
+ private static final String ENABLED = "enabled";
+ private static final String EMPTY_STRING = "";
+ private static final String NAME = "name";
+ private static final String ADMIN_STATE = "admin-state";
+
+ private static final ArrayList<String> LINESIDE = Lists.newArrayList(
+ "1.1", "1.2", "12.1", "12.2");
+
+ private static final String GENERAL_PORT_REQUEST =
+ "yang-api/datastore/ws-ports?config=true&format=xml&depth=unbounded";
+ private static final String SPECIFIC_PORT_PATH = "yang-api/datastore/ws-ptps/ptp/";
+ private static final String SPECIFIC_PORT_CONFIG =
+ "/ptp-config?config=true&format=xml&depth=unbounded";
+
+
+ @Override
+ public List<PortDescription> getPorts() {
+ List<PortDescription> ports = Lists.newArrayList();
+ DriverHandler handler = handler();
+ RestSBController controller = checkNotNull(handler.get(RestSBController.class));
+ DeviceId deviceId = handler.data().deviceId();
+
+
+ HierarchicalConfiguration config = XmlConfigParser.
+ loadXml(controller.get(deviceId, GENERAL_PORT_REQUEST, XML));
+ List<HierarchicalConfiguration> portsConfig =
+ XmlConfigParser.parseWaveServerCienaPorts(config);
+
+ portsConfig.stream().forEach(sub -> {
+ String name = sub.getString(NAME);
+ SparseAnnotations annotations = DefaultAnnotations.builder()
+ .set(AnnotationKeys.NAME, String.valueOf(name)).build();
+ if (LINESIDE.contains(name)) {
+ String wsportInfoRequest = SPECIFIC_PORT_PATH + sub.getLong(PORT_ID) +
+ SPECIFIC_PORT_CONFIG;
+ ports.add(XmlConfigParser.parseWaveServerCienaOCHPorts(
+ sub.getLong(PORT_ID),
+ toGbps(Long.parseLong(sub.getString(SPEED).replace(GBPS, EMPTY_STRING))),
+ XmlConfigParser.loadXml(controller.get(deviceId, wsportInfoRequest, XML)),
+ annotations));
+ } else {
+ //FIXME change when all optical types have two way information methods, see jira tickets
+ final int speed100GbpsinMbps = 100000;
+ CltSignalType cltType = toGbps(Long.parseLong(
+ sub.getString(SPEED).replace(GBPS, EMPTY_STRING))) == speed100GbpsinMbps ?
+ CltSignalType.CLT_100GBE : null;
+ ports.add(new OduCltPortDescription(PortNumber.portNumber(sub.getLong(PORT_ID)),
+ sub.getString(ADMIN_STATE).equals(ENABLED),
+ cltType, annotations));
+ }
+ });
+ return ports;
+ }
+
+ //FIXME remove when all optical types have two way information methods, see jira tickets
+ private long toGbps(long speed) {
+ return speed * 1000;
+ }
+}
+
diff --git a/drivers/src/main/java/org/onosproject/driver/rest/package-info.java b/drivers/src/main/java/org/onosproject/driver/rest/package-info.java
new file mode 100644
index 0000000..1fd813d
--- /dev/null
+++ b/drivers/src/main/java/org/onosproject/driver/rest/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 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.
+ */
+
+/**
+ * Implementations of the REST driver behaviours.
+ */
+package org.onosproject.driver.rest;
\ No newline at end of file
diff --git a/drivers/src/main/resources/onos-drivers.xml b/drivers/src/main/resources/onos-drivers.xml
index 1ab3d6e..fbc9662 100644
--- a/drivers/src/main/resources/onos-drivers.xml
+++ b/drivers/src/main/resources/onos-drivers.xml
@@ -128,7 +128,9 @@
<behaviour api="org.onosproject.net.behaviour.Pipeliner"
impl="org.onosproject.driver.pipeline.OltPipeline"/>
</driver>
- <driver name="rest" manufacturer="" hwVersion="" swVersion="">
+ <driver name="restCiena" manufacturer="Ciena" hwVersion="1.0.0" swVersion="1.0.0">
+ <behaviour api="org.onosproject.net.behaviour.PortDiscovery"
+ impl="org.onosproject.driver.rest.PortDiscoveryCienaWaveserverImpl"/>
</driver>
<!-- The SoftRouter driver is meant to be used by any software/NPU based
~ switch that wishes to implement a simple 2-table router. To use this
diff --git a/drivers/src/main/resources/org/onosproject/driver/netconf/controllers.xml b/drivers/src/main/resources/org/onosproject/driver/controllers.xml
similarity index 100%
rename from drivers/src/main/resources/org/onosproject/driver/netconf/controllers.xml
rename to drivers/src/main/resources/org/onosproject/driver/controllers.xml
diff --git a/drivers/src/test/java/org/onosproject/driver/netconf/XmlConfigParserTest.java b/drivers/src/test/java/org/onosproject/driver/XmlConfigParserTest.java
similarity index 94%
rename from drivers/src/test/java/org/onosproject/driver/netconf/XmlConfigParserTest.java
rename to drivers/src/test/java/org/onosproject/driver/XmlConfigParserTest.java
index d8b695c..40a3b51 100644
--- a/drivers/src/test/java/org/onosproject/driver/netconf/XmlConfigParserTest.java
+++ b/drivers/src/test/java/org/onosproject/driver/XmlConfigParserTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.driver.netconf;
+package org.onosproject.driver;
import org.junit.Test;
import org.onlab.packet.IpAddress;
@@ -27,9 +27,7 @@
import java.util.List;
import static org.junit.Assert.assertTrue;
-import static org.onosproject.driver.netconf.XmlConfigParser.*;
-
-//import static org.junit.Assert.*;
+import static org.onosproject.driver.XmlConfigParser.*;
/**
* Test the XML document Parsing for netconf configuration.
diff --git a/drivers/src/test/resources/org/onosproject/driver/netconf/testConfig.xml b/drivers/src/test/resources/org/onosproject/driver/testConfig.xml
similarity index 100%
rename from drivers/src/test/resources/org/onosproject/driver/netconf/testConfig.xml
rename to drivers/src/test/resources/org/onosproject/driver/testConfig.xml
diff --git a/protocols/rest/ctl/src/main/java/org/onosproject/protocol/rest/ctl/RestSBControllerImpl.java b/protocols/rest/ctl/src/main/java/org/onosproject/protocol/rest/ctl/RestSBControllerImpl.java
index 66f2530..b659d2f 100644
--- a/protocols/rest/ctl/src/main/java/org/onosproject/protocol/rest/ctl/RestSBControllerImpl.java
+++ b/protocols/rest/ctl/src/main/java/org/onosproject/protocol/rest/ctl/RestSBControllerImpl.java
@@ -128,6 +128,7 @@
@Override
public boolean put(DeviceId device, String request, InputStream payload, String mediaType) {
+
WebResource webResource = getWebResource(device, request);
ClientResponse response = null;
if (payload != null) {
diff --git a/providers/rest/device/src/main/java/org/onosproject/provider/rest/device/impl/RestDeviceProvider.java b/providers/rest/device/src/main/java/org/onosproject/provider/rest/device/impl/RestDeviceProvider.java
index 8638561..76f5abd 100644
--- a/providers/rest/device/src/main/java/org/onosproject/provider/rest/device/impl/RestDeviceProvider.java
+++ b/providers/rest/device/src/main/java/org/onosproject/provider/rest/device/impl/RestDeviceProvider.java
@@ -31,6 +31,7 @@
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.behaviour.PortDiscovery;
import org.onosproject.net.config.ConfigFactory;
import org.onosproject.net.config.NetworkConfigEvent;
import org.onosproject.net.config.NetworkConfigListener;
@@ -40,7 +41,8 @@
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.driver.DriverHandler;
+import org.onosproject.net.driver.DriverService;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.protocol.rest.RestSBController;
@@ -51,7 +53,6 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_ADDED;
@@ -84,6 +85,9 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DriverService driverService;
+
private DeviceProviderService providerService;
protected static final String ISNOTNULL = "Rest device is not null";
@@ -170,11 +174,6 @@
controller.addDevice(nodeId);
}
- private void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) {
- // TODO get driver and call behavior to get ports
- //signal the ports to onos
- }
-
//when do I call it ?
public void deviceRemoved(RestSBDevice nodeId) {
Preconditions.checkNotNull(nodeId, ISNOTNULL);
@@ -204,8 +203,15 @@
log.error("Configuration error {}", e);
}
log.info("REST Devices {}", controller.getDevices());
- //TODO ask for ports then call update ports.
-
+ controller.getDevices().keySet().forEach(deviceId -> {
+ DriverHandler h = driverService.createHandler(deviceId);
+ PortDiscovery portConfig = h.behaviour(PortDiscovery.class);
+ if (portConfig != null) {
+ providerService.updatePorts(deviceId, portConfig.getPorts());
+ } else {
+ log.warn("No portGetter behaviour for device {}", deviceId);
+ }
+ });
}
private boolean testDeviceConnection(RestSBDevice device) {
diff --git a/tools/test/configs/restSB-cfg.json b/tools/test/configs/restSB-cfg.json
index 19bf776..b420f7c 100644
--- a/tools/test/configs/restSB-cfg.json
+++ b/tools/test/configs/restSB-cfg.json
@@ -2,7 +2,7 @@
"devices": {
"rest:127.0.0.1:8080": {
"basic": {
- "driver": "rest"
+ "driver": "restCiena"
}
}
},