[ODTN] OpenConfig device discovery

Change-Id: Iac2917ac8a65de662b55b238b920936635fc45f4
diff --git a/apps/odtn/BUCK b/apps/odtn/BUCK
index eef902a..9408d9b 100644
--- a/apps/odtn/BUCK
+++ b/apps/odtn/BUCK
@@ -7,7 +7,7 @@
 
     # strictly speaking following are not mandatory
     'org.onosproject.restconf',
-    'org.onosproject.drivers.netconf',
+    'org.onosproject.drivers.netconf',# probably don't need this
     'org.onosproject.netconf',
     'org.onosproject.configsync-netconf',
     'org.onosproject.protocols.restconfserver'
diff --git a/apps/odtn/src/main/java/org/onosproject/odtn/behaviour/OdtnDeviceDescriptionDiscovery.java b/apps/odtn/src/main/java/org/onosproject/odtn/behaviour/OdtnDeviceDescriptionDiscovery.java
new file mode 100644
index 0000000..025f1c5
--- /dev/null
+++ b/apps/odtn/src/main/java/org/onosproject/odtn/behaviour/OdtnDeviceDescriptionDiscovery.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.odtn.behaviour;
+
+import java.util.List;
+
+import org.onosproject.net.device.DeviceDescriptionDiscovery;
+import org.onosproject.net.device.PortDescription;
+
+/**
+ * DeviceDescriptionDiscovery used in ODTN.
+ *
+ * Certain Annotations will be required.
+ */
+public interface OdtnDeviceDescriptionDiscovery
+        extends DeviceDescriptionDiscovery {
+
+    /**
+     * Annotations key, which stores OpenConfig component name.
+     */
+    String OC_NAME = "oc-name";
+
+    /**
+     * Annotations key, which stores OpenConfig component type.
+     */
+    String OC_TYPE = "oc-type";
+
+    // overriding just to make checkstyle happy
+    @Override
+    List<PortDescription> discoverPortDetails();
+
+}
diff --git a/drivers/odtn-driver/BUCK b/drivers/odtn-driver/BUCK
new file mode 100644
index 0000000..9078939
--- /dev/null
+++ b/drivers/odtn-driver/BUCK
@@ -0,0 +1,39 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//protocols/netconf/api:onos-protocols-netconf-api',
+    '//lib:commons-jxpath',
+    '//apps/odtn:onos-apps-odtn', # FIXME direction of dependency not ideal
+]
+
+TEST_DEPS = [
+    '//lib:TEST_ADAPTERS',
+    '//core/api:onos-api-tests',
+    '//lib:slf4j-jdk14',
+]
+
+BUNDLES = [
+    ':onos-drivers-odtn-driver',
+    '//lib:commons-jxpath',
+    '//lib:commons-beanutils', # jxpath dependency
+    '//lib:jdom',  # jxpath dependency
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+    test_deps = TEST_DEPS,
+    resources_root = 'src/main/resources',
+    resources = glob(['src/main/resources/**']),
+)
+
+onos_app (
+    app_name = 'org.onosproject.drivers.odtn-driver',
+    title = 'ODTN Driver',
+    category = 'Drivers',
+    url = 'https://wiki.onosproject.org/display/ODTN/ODTN',
+    description = 'Drivers related to ODTN',
+    included_bundles = BUNDLES,
+    required_apps = [
+        'org.onosproject.netconf',
+        'org.onosproject.odtn',
+    ],
+)
diff --git a/drivers/odtn-driver/pom.xml b/drivers/odtn-driver/pom.xml
new file mode 100644
index 0000000..0f93c09
--- /dev/null
+++ b/drivers/odtn-driver/pom.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2018-present Open Networking Foundation
+  ~
+  ~ 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/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>onos-drivers-general</artifactId>
+        <groupId>org.onosproject</groupId>
+        <version>1.14.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>onos-drivers-odtn-driver</artifactId>
+    <packaging>bundle</packaging>
+
+    <properties>
+    </properties>
+
+    <dependencies>
+
+        <!-- FIXME direction of dependency not ideal -->
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-apps-odtn</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-protocols-netconf-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-jxpath</groupId>
+            <artifactId>commons-jxpath</artifactId>
+            <version>1.3</version>
+        </dependency>
+
+    </dependencies>
+
+</project>
diff --git a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/OpenConfigDeviceDiscovery.java b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/OpenConfigDeviceDiscovery.java
new file mode 100644
index 0000000..54e2601
--- /dev/null
+++ b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/OpenConfigDeviceDiscovery.java
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.drivers.odtn;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port.Type;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.DefaultPortDescription.Builder;
+import org.onosproject.net.device.DeviceDescription;
+import org.onosproject.net.device.DeviceDescriptionDiscovery;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.netconf.NetconfController;
+import org.onosproject.netconf.NetconfDevice;
+import org.onosproject.netconf.NetconfRpcParserUtil;
+import org.onosproject.netconf.NetconfRpcReply;
+import org.onosproject.netconf.NetconfSession;
+import org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery;
+import org.slf4j.Logger;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
+import com.google.common.io.CharSource;
+
+/**
+ * OpenConfig based device and port discovery.
+ */
+public class OpenConfigDeviceDiscovery
+    extends AbstractHandlerBehaviour
+    implements OdtnDeviceDescriptionDiscovery, DeviceDescriptionDiscovery {
+
+    private static final Logger log = getLogger(OpenConfigDeviceDiscovery.class);
+
+    @Override
+    public DeviceDescription discoverDeviceDetails() {
+        // TODO Auto-generated method stub
+        // Not really used right now
+        return null;
+    }
+
+    @Override
+    public List<PortDescription> discoverPortDetails() {
+        try {
+            return discoverPorts();
+        } catch (Exception e) {
+            log.error("Error discovering port details on {}", data().deviceId(), e);
+            return ImmutableList.of();
+        }
+    }
+
+    private List<PortDescription> discoverPorts() throws ConfigurationException, IOException {
+        DeviceId did = data().deviceId();
+        NetconfSession ns = Optional.ofNullable(handler().get(NetconfController.class))
+                    .map(c -> c.getNetconfDevice(did))
+                    .map(NetconfDevice::getSession)
+                    .orElseThrow(() -> new IllegalStateException("No NetconfSession found for " + did));
+
+        // TODO convert this method into non-blocking form?
+
+        NetconfRpcReply reply = ns.asyncGet()
+            .thenApply(NetconfRpcParserUtil::parseRpcReply)
+            .join();
+
+        if (reply.hasError()) {
+            log.error("Netconf error replies from {}:\n{}", did, reply.errors());
+            return ImmutableList.of();
+        }
+
+        String data = reply.responses().stream()
+                .filter(s -> s.startsWith("<data"))
+                .findFirst()
+                .orElse(null);
+
+        if (data == null) {
+            log.error("No valid response found from {}:\n{}", did, reply);
+            return ImmutableList.of();
+        }
+
+        XMLConfiguration cfg = new XMLConfiguration();
+        cfg.load(CharSource.wrap(data).openStream());
+
+        return discoverPorts(cfg);
+    }
+
+    /**
+     * Parses port information from OpenConfig XML configuration.
+     *
+     * @param cfg tree where the root node is {@literal <data>}
+     * @return List of ports
+     */
+    @VisibleForTesting
+    protected List<PortDescription> discoverPorts(XMLConfiguration cfg) {
+        // If we want to use XPath
+        cfg.setExpressionEngine(new XPathExpressionEngine());
+
+        // converting components into PortDescription.
+        List<HierarchicalConfiguration> components = cfg.configurationsAt("components/component");
+        return components.stream()
+            .map(this::toPortDescription)
+            .filter(Objects::nonNull)
+            .collect(Collectors.toList());
+    }
+
+    // wrapper to make parsing exception safe
+    private PortDescription toPortDescription(HierarchicalConfiguration component) {
+        try {
+            return toPortDescriptionInternal(component);
+        } catch (Exception e) {
+            log.error("Unexpected exception parsing component {} on {}",
+                      component.getString("name"),
+                      data().deviceId(), e);
+            return null;
+        }
+    }
+
+    /**
+     * Converts Component subtree to PortDescription.
+     *
+     * @param component subtree to parse
+     * @return PortDescription or null if component is not an ONOS Port
+     */
+    private PortDescription toPortDescriptionInternal(HierarchicalConfiguration component) {
+
+        // to access other part of <data> tree:
+        //log.warn("parent data Node: {}",
+        //       ((SubnodeConfiguration) component).getParent().getRootNode().getName());
+
+        Map<String, String> props = new HashMap<>();
+
+        String name = component.getString("name");
+        String type = component.getString("state/type");
+        checkNotNull(name);
+        checkNotNull(type);
+        props.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
+        props.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);
+
+        component.configurationsAt("properties/property").forEach(prop -> {
+            String pName = prop.getString("name");
+            String pValue = prop.getString("config/value");
+            props.put(pName, pValue);
+        });
+
+        if (!props.containsKey("onos-index")) {
+            log.info("DEBUG: Component {} does not include onos-index, skipping", name);
+            // ODTN: port must have onos-index property
+            return null;
+        }
+
+        Builder builder = DefaultPortDescription.builder();
+        builder.withPortNumber(PortNumber.portNumber(Long.parseLong(props.get("onos-index")), name));
+
+        switch (type) {
+        case "oc-platform-types:PORT":
+        case "oc-platform-types:TRANSCEIVER":
+        case "oc-opt-types:OPTICAL_CHANNEL":
+            // TODO assign appropriate port type & annotations at some point
+            // for now we just need a Port with annotations
+            builder.type(Type.PACKET);
+            break;
+
+        default:
+            log.info("DEBUG: Unknown component type {}", type);
+            return null;
+        }
+
+        builder.annotations(DefaultAnnotations.builder().putAll(props).build());
+
+        return builder.build();
+
+    }
+
+}
diff --git a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/impl/OdtnDriversLoader.java b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/impl/OdtnDriversLoader.java
new file mode 100644
index 0000000..cf4a2ba
--- /dev/null
+++ b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/impl/OdtnDriversLoader.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.drivers.odtn.impl;
+
+import org.apache.felix.scr.annotations.Component;
+import org.onosproject.net.driver.AbstractDriverLoader;
+import org.onosproject.odtn.behaviour.ConfigurableTransceiver;
+
+@Component(immediate = true)
+public class OdtnDriversLoader extends AbstractDriverLoader {
+
+    // for injecting package dependencies for OSGi/BND
+    ConfigurableTransceiver transceiver;
+
+    public OdtnDriversLoader() {
+        super("/odtn-drivers.xml");
+    }
+}
diff --git a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/impl/package-info.java b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/impl/package-info.java
new file mode 100644
index 0000000..afeb3f23
--- /dev/null
+++ b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/impl/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.
+ */
+/**
+ * ODTN Driver implementations.
+ */
+package org.onosproject.drivers.odtn.impl;
diff --git a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/package-info.java b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/package-info.java
new file mode 100644
index 0000000..7280792
--- /dev/null
+++ b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.
+ */
+/**
+ * ODTN Driver.
+ */
+package org.onosproject.drivers.odtn;
diff --git a/drivers/odtn-driver/src/main/resources/odtn-drivers.xml b/drivers/odtn-driver/src/main/resources/odtn-drivers.xml
new file mode 100644
index 0000000..fd4aab1
--- /dev/null
+++ b/drivers/odtn-driver/src/main/resources/odtn-drivers.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2018-present Open Networking Foundation
+  ~
+  ~ 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.
+  -->
+<drivers>
+    <driver name="odtn" manufacturer="" hwVersion="" swVersion="">
+        <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
+                  impl="org.onosproject.drivers.odtn.OpenConfigDeviceDiscovery"/>
+        <behaviour api="org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery"
+                  impl="org.onosproject.drivers.odtn.OpenConfigDeviceDiscovery"/>
+        <behaviour api="org.onosproject.odtn.behaviour.ConfigurableTransceiver"
+                  impl="org.onosproject.odtn.behaviour.PlainTransceiver"/>
+    </driver>
+</drivers>
+
diff --git a/drivers/odtn-driver/src/test/java/org/onosproject/drivers/odtn/OpenConfigDeviceDiscoveryTest.java b/drivers/odtn-driver/src/test/java/org/onosproject/drivers/odtn/OpenConfigDeviceDiscoveryTest.java
new file mode 100644
index 0000000..4b2e1c4
--- /dev/null
+++ b/drivers/odtn-driver/src/test/java/org/onosproject/drivers/odtn/OpenConfigDeviceDiscoveryTest.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.drivers.odtn;
+
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME;
+import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_TYPE;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.junit.Test;
+import org.onosproject.net.device.PortDescription;
+import com.google.common.io.CharSource;
+
+public class OpenConfigDeviceDiscoveryTest {
+
+    @Test
+    public void testToPortDescription() throws ConfigurationException, IOException {
+        // CHECKSTYLE:OFF
+        String input =
+        "<data>\n" +
+        "<components  xmlns=\"http://openconfig.net/yang/platform\">\n" +
+        "\n" +
+        "  <component>\n" +
+        "    <name>TPC_1_1_4_N2_200G</name>\n" +
+        "    <config>\n" +
+        "      <name>TPC_1_1_4_N2_200G</name>\n" +
+        "    </config>\n" +
+        "    <state>\n" +
+        "      <name>TPC_1_1_4_N2_200G</name>\n" +
+        "      <type  xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:LINECARD</type>\n" +
+        "    </state>\n" +
+        "  </component>\n" +
+        "\n" +
+        "  <component>\n" +
+        "    <name>CLIPORT_1_1_4_1</name>\n" +
+        "    <config>\n" +
+        "      <name>CLIPORT_1_1_4_1</name>\n" +
+        "    </config>\n" +
+        "    <state>\n" +
+        "      <name>CLIPORT_1_1_4_1</name>\n" +
+        "      <type  xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:PORT</type>\n" +
+        "    </state>\n" +
+        "  </component>\n" +
+        "\n" +
+        "  <component>\n" +
+        "    <name>LINEPORT_1_1_4</name>\n" +
+        "    <config>\n" +
+        "      <name>LINEPORT_1_1_4</name>\n" +
+        "    </config>\n" +
+        "    <state>\n" +
+        "      <name>LINEPORT_1_1_4</name>\n" +
+        "      <type  xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:PORT</type>\n" +
+        "    </state>\n" +
+        "  </component>\n" +
+        "\n" +
+        "  <component>\n" +
+        "    <name>TRANSCEIVER_1_1_4_1</name>\n" +
+        "    <config>\n" +
+        "      <name>TRANSCEIVER_1_1_4_1</name>    \n" +
+        "    </config>\n" +
+        "    <state>\n" +
+        "      <name>TRANSCEIVER_1_1_4_1</name>\n" +
+        "      <type  xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:TRANSCEIVER</type>\n" +
+        "    </state>\n" +
+        "        <properties>\n" +
+        "          <property>\n" +
+        "            <name>onos-index</name>\n" +
+        "            <config>\n" +
+        "              <name>onos-index</name>\n" +
+        "              <value>42</value>\n" +
+        "            </config>\n" +
+        "          </property>\n" +
+        "        </properties>\n" +
+        "    <transceiver  xmlns=\"http://openconfig.net/yang/platform/transceiver\">\n" +
+        "      <config>\n" +
+        "        <enabled>true</enabled>\n" +
+        "        <form-factor-preconf  xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:QSFP28</form-factor-preconf>\n" +
+        "        <ethernet-pmd-preconf  xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:ETH_100GBASE_LR4</ethernet-pmd-preconf>\n" +
+        "      </config>\n" +
+        "      <state>\n" +
+        "        <enabled>true</enabled>\n" +
+        "        <form-factor-preconf  xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:QSFP28</form-factor-preconf>\n" +
+        "        <ethernet-pmd-preconf  xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:ETH_100GBASE_LR4</ethernet-pmd-preconf>\n" +
+        "      </state>\n" +
+        "    </transceiver>\n" +
+        "  </component>\n" +
+        "\n" +
+        "  <component>\n" +
+        "    <name>OPTCHANNEL_1_1_4</name>\n" +
+        "    <config>\n" +
+        "      <name>OPTCHANNEL_1_1_4</name>\n" +
+        "    </config>\n" +
+        "    <state>\n" +
+        "      <name>OPTCHANNEL_1_1_4</name>\n" +
+        "      <type  xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:OPTICAL_CHANNEL</type>\n" +
+        "    </state>\n" +
+        "    <optical-channel  xmlns=\"http://openconfig.net/yang/terminal-device\">\n" +
+        "      <config>\n" +
+        "        <frequency>191500000</frequency>\n" +
+        "        <target-output-power>0.0</target-output-power>\n" +
+        "      </config>\n" +
+        "      <state>\n" +
+        "        <frequency>191500000</frequency>\n" +
+        "        <target-output-power>0.0</target-output-power>\n" +
+        "      </state>\n" +
+        "    </optical-channel>\n" +
+        "  </component>\n" +
+        "\n" +
+        "</components>\n" +
+        "</data>";
+        // CHECKSTYLE:ON
+
+        OpenConfigDeviceDiscovery sut = new OpenConfigDeviceDiscovery();
+
+        XMLConfiguration cfg = new XMLConfiguration();
+        cfg.load(CharSource.wrap(input).openStream());
+
+        List<PortDescription> ports = sut.discoverPorts(cfg);
+
+        assertThat(ports, hasSize(1));
+        PortDescription portDescription = ports.get(0);
+        assertThat(portDescription.portNumber().toLong(), is(42L));
+        assertThat(portDescription.portNumber().name(), is("TRANSCEIVER_1_1_4_1"));
+
+
+        assertThat(portDescription.annotations().value(OC_NAME), is("TRANSCEIVER_1_1_4_1"));
+        assertThat(portDescription.annotations().value(OC_TYPE), is("oc-platform-types:TRANSCEIVER"));
+
+    }
+
+}
diff --git a/drivers/pom.xml b/drivers/pom.xml
index c0c7bf6..efb497e 100644
--- a/drivers/pom.xml
+++ b/drivers/pom.xml
@@ -57,6 +57,7 @@
         <module>hp</module>
         <module>microsemi/ea1000</module>
         <module>gnmi</module>
+        <module>odtn-driver</module>
     </modules>
 
     <!--<properties>
diff --git a/lib/BUCK b/lib/BUCK
index 3ae6307..031b328 100644
--- a/lib/BUCK
+++ b/lib/BUCK
@@ -1,4 +1,4 @@
-# ***** This file was auto-generated at Sat, 21 Apr 2018 05:05:33 GMT. Do not edit this file manually. *****
+# ***** This file was auto-generated at Mon, 7 May 2018 18:44:21 GMT. Do not edit this file manually. *****
 # ***** Use onos-lib-gen *****
 
 pass_thru_pom(
@@ -251,6 +251,33 @@
 )
 
 remote_jar (
+  name = 'commons-jxpath',
+  out = 'commons-jxpath-1.3.jar',
+  url = 'mvn:commons-jxpath:commons-jxpath:jar:1.3',
+  sha1 = 'c22d7d0f0f40eb7059a23cfa61773a416768b137',
+  maven_coords = 'commons-jxpath:commons-jxpath:1.3',
+  visibility = [ 'PUBLIC' ],
+)
+
+remote_jar (
+  name = 'commons-beanutils',
+  out = 'commons-beanutils-1.9.2.jar',
+  url = 'mvn:commons-beanutils:commons-beanutils:jar:1.9.2',
+  sha1 = '7a87d845ad3a155297e8f67d9008f4c1e5656b71',
+  maven_coords = 'commons-beanutils:commons-beanutils:1.9.2',
+  visibility = [ 'PUBLIC' ],
+)
+
+remote_jar (
+  name = 'jdom',
+  out = 'jdom-1.0.jar',
+  url = 'mvn:jdom:jdom:jar:1.0',
+  sha1 = 'a2ac1cd690ab4c80defe7f9bce14d35934c35cec',
+  maven_coords = 'jdom:jdom:jar:NON-OSGI:1.0',
+  visibility = [ 'PUBLIC' ],
+)
+
+remote_jar (
   name = 'commons-lang',
   out = 'commons-lang-2.6.jar',
   url = 'mvn:commons-lang:commons-lang:jar:2.6',
@@ -305,15 +332,6 @@
 )
 
 remote_jar (
-  name = 'commons-beanutils',
-  out = 'commons-beanutils-1.9.2.jar',
-  url = 'mvn:commons-beanutils:commons-beanutils:jar:1.9.2',
-  sha1 = '7a87d845ad3a155297e8f67d9008f4c1e5656b71',
-  maven_coords = 'commons-beanutils:commons-beanutils:1.9.2',
-  visibility = [ 'PUBLIC' ],
-)
-
-remote_jar (
   name = 'concurrent-trees',
   out = 'concurrent-trees-2.6.1.jar',
   url = 'mvn:com.googlecode.concurrent-trees:concurrent-trees:jar:2.6.1',
diff --git a/lib/deps.json b/lib/deps.json
index 46d6d30..73067f7 100644
--- a/lib/deps.json
+++ b/lib/deps.json
@@ -121,6 +121,9 @@
     "commons-collections": "mvn:commons-collections:commons-collections:3.2.2",
     "commons-configuration": "mvn:commons-configuration:commons-configuration:1.10",
     "commons-io": "mvn:commons-io:commons-io:2.6",
+    "commons-jxpath": "mvn:commons-jxpath:commons-jxpath:1.3",
+    "commons-beanutils": "mvn:commons-beanutils:commons-beanutils:1.9.3",
+    "jdom": "mvn:jdom:jdom:1.0",
     "commons-lang": "mvn:commons-lang:commons-lang:2.6",
     "commons-lang3": "mvn:org.apache.commons:commons-lang3:3.6",
     "commons-logging": "mvn:commons-logging:commons-logging:1.2",
diff --git a/modules.defs b/modules.defs
index 9d131d9..5f6ce6d 100644
--- a/modules.defs
+++ b/modules.defs
@@ -118,6 +118,7 @@
     '//drivers/gnmi:onos-drivers-gnmi-oar',
     '//drivers/polatis/netconf:onos-drivers-polatis-netconf-oar',
     '//drivers/polatis/openflow:onos-drivers-polatis-openflow-oar',
+    '//drivers/odtn-driver:onos-drivers-odtn-driver-oar',
 ]
 
 ONOS_PROVIDERS = [
@@ -297,4 +298,3 @@
 
 APPS = ONOS_DRIVERS + ONOS_PROVIDERS + ONOS_APPS + MODELS + PIPELINES \
         + PROTOCOL_APPS
-