ZTE Netconf driver for ODTN-phase 1.0

Change-Id: I2cfa65fb889f13ed0e4cab1559229f79cdd7a42b
diff --git a/drivers/zte/BUILD b/drivers/zte/BUILD
new file mode 100644
index 0000000..b560a12
--- /dev/null
+++ b/drivers/zte/BUILD
@@ -0,0 +1,43 @@
+COMPILE_DEPS = CORE_DEPS + JACKSON + [
+    "@commons_jxpath//jar",
+    "@javax_ws_rs_api//jar",
+    "@httpcore_osgi//jar",
+    "//core/store/serializers:onos-core-serializers",
+    "//drivers/utilities:onos-drivers-utilities",
+    "//models/openconfig:onos-models-openconfig",
+    "//protocols/netconf/api:onos-protocols-netconf-api",
+    "//protocols/rest/api:onos-protocols-rest-api",
+    "//apps/odtn/api:onos-apps-odtn-api",
+    "//apps/optical-model:onos-apps-optical-model",
+    "//drivers/optical:onos-drivers-optical",
+]
+
+BUNDLES = [
+    ":onos-drivers-zte",
+    "//drivers/utilities:onos-drivers-utilities",
+]
+
+osgi_jar_with_tests(
+    resources = glob(["src/main/resources/**"]),
+    resources_root = "src/main/resources",
+    deps = COMPILE_DEPS,
+)
+
+onos_app(
+    app_name = "org.onosproject.drivers.zte",
+    category = "Drivers",
+    description = "Adds support for ZTE devices.",
+    included_bundles = BUNDLES,
+    required_apps = [
+        "org.onosproject.netconf",
+        "org.onosproject.restsb",
+        "org.onosproject.netconf",
+        "org.onosproject.config",
+        "org.onosproject.odtn-api",
+        "org.onosproject.drivers.netconf",
+        "org.onosproject.drivers.optical",
+        "org.onosproject.optical-model",
+    ],
+    title = "ZTE Drivers",
+    url = "http://onosproject.org",
+)
diff --git a/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZteDeviceDiscoveryImpl.java b/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZteDeviceDiscoveryImpl.java
new file mode 100644
index 0000000..9f23f7b
--- /dev/null
+++ b/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZteDeviceDiscoveryImpl.java
@@ -0,0 +1,225 @@
+/*
+ * Copyright 2019-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.zte;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.io.CharSource;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
+import org.onlab.packet.ChassisId;
+import org.onosproject.drivers.utilities.XmlConfigParser;
+import org.onosproject.net.ChannelSpacing;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.OchSignal;
+import org.onosproject.net.OduSignalType;
+import org.onosproject.net.Port.Type;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DefaultDeviceDescription;
+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.net.optical.device.OchPortHelper;
+import org.onosproject.netconf.NetconfController;
+import org.onosproject.netconf.NetconfException;
+import org.onosproject.netconf.NetconfSession;
+import org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery;
+import org.onosproject.net.AnnotationKeys;
+import org.slf4j.Logger;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+public class ZteDeviceDiscoveryImpl
+        extends AbstractHandlerBehaviour
+        implements OdtnDeviceDescriptionDiscovery, DeviceDescriptionDiscovery {
+    private final Logger log = getLogger(getClass());
+
+    @Override
+    public DeviceDescription discoverDeviceDetails() {
+        DeviceId deviceId = handler().data().deviceId();
+        log.info("Discovering ZTE device {}", deviceId);
+
+        NetconfController controller = handler().get(NetconfController.class);
+        NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
+
+        String hwVersion = "ZTE hw";
+        String swVersion = "ZTE sw";
+        String serialNumber = "000000000000";
+
+        try {
+            String reply = session.requestSync(buildDeviceInfoRequest());
+            XMLConfiguration cfg = (XMLConfiguration) XmlConfigParser.loadXmlString(getDataOfRpcReply(reply));
+            hwVersion = cfg.getString("components.component.state.hardware-version");
+            swVersion = cfg.getString("components.component.state.software-version");
+            serialNumber = cfg.getString("components.component.state.serial-no");
+        } catch (NetconfException e) {
+            log.error("ZTE device discovery error.", e);
+        }
+
+        return new DefaultDeviceDescription(deviceId.uri(),
+                Device.Type.OTN,
+                "ZTE",
+                hwVersion,
+                swVersion,
+                serialNumber,
+                new ChassisId(1));
+    }
+
+    private String buildDeviceInfoRequest() {
+        StringBuilder rpc = new StringBuilder();
+        rpc.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">");
+        rpc.append("<get>");
+        rpc.append("<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">");
+        rpc.append("<components xmlns=\"http://openconfig.net/yang/platform\">");
+        rpc.append("<component>");
+        rpc.append("<name>CHASSIS-1-1</name>");
+        rpc.append("<state></state>");
+        rpc.append("</component>");
+        rpc.append("</components>");
+        rpc.append("</filter>");
+        rpc.append("</get>");
+        rpc.append("</rpc>");
+
+        return rpc.toString();
+    }
+
+    private String getDataOfRpcReply(String rpcReply) {
+        String data = null;
+        int begin = rpcReply.indexOf("<data>");
+        int end = rpcReply.lastIndexOf("</data>");
+        if (begin != -1 && end != -1) {
+            data = (String) rpcReply.subSequence(begin, end + "</data>".length());
+        } else {
+            data = rpcReply;
+        }
+        return data;
+    }
+
+    @Override
+    public List<PortDescription> discoverPortDetails() {
+        DeviceId deviceId = handler().data().deviceId();
+        log.info("Discovering ZTE device ports {}", deviceId);
+
+        NetconfController controller = handler().get(NetconfController.class);
+        NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
+        XMLConfiguration cfg = new XMLConfiguration();
+        try {
+            String reply = session.requestSync(buildPortDetailRequest(), 30);
+            String data = getDataOfRpcReply(reply);
+            if (data == null) {
+                log.error("No valid response found from {}:\n{}", deviceId, reply);
+                return ImmutableList.of();
+            }
+            cfg.load(CharSource.wrap(data).openStream());
+            return discoverPorts(cfg);
+        } catch (Exception e) {
+            log.error("ZTE device port discovery error.", e);
+        }
+
+        return ImmutableList.of();
+    }
+
+    private String buildPortDetailRequest() {
+        StringBuilder rpc = new StringBuilder();
+        rpc.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">");
+        rpc.append("<get>");
+        rpc.append("<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">");
+        rpc.append("<components xmlns=\"http://openconfig.net/yang/platform\">");
+        rpc.append("</components>");
+        rpc.append("</filter>");
+        rpc.append("</get>");
+        rpc.append("</rpc>");
+
+        return rpc.toString();
+    }
+
+    private List<PortDescription> discoverPorts(XMLConfiguration cfg) {
+        cfg.setExpressionEngine(new XPathExpressionEngine());
+        List<HierarchicalConfiguration> components = cfg.configurationsAt("components/component");
+        return components.stream()
+                .filter(this::isPortComponent)
+                .map(this::toPortDescriptionInternal)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toList());
+    }
+
+    private boolean isPortComponent(HierarchicalConfiguration component) {
+        String name = component.getString("name");
+        String type = component.getString("state/type");
+
+        return name != null && name.startsWith("PORT") && type != null
+                && type.equals("openconfig-platform-types:PORT");
+    }
+
+    private PortDescription toPortDescriptionInternal(HierarchicalConfiguration component) {
+        Map<String, String> annotations = new HashMap<>();
+        String name = component.getString("name");
+        String type = component.getString("state/type");
+
+        annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
+        annotations.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);
+        annotations.putIfAbsent(AnnotationKeys.PORT_NAME, name);
+
+        // PORT-1-4-C1
+        String[] textStr = name.split("-");
+
+        // use different value of portNumber on the same equipment
+        String portComponentIndex = textStr[textStr.length - 1];
+        int slotIndex = Integer.parseInt(textStr[2]);
+        int slotPortIndex = Integer.parseInt(portComponentIndex.substring(1));
+        int portNumber = slotIndex * 10 + slotPortIndex;
+
+        annotations.putIfAbsent(ONOS_PORT_INDEX, portComponentIndex);
+        annotations.putIfAbsent(CONNECTION_ID, "connection:" + Integer.parseInt(portComponentIndex.substring(1)));
+
+        if (portComponentIndex.charAt(0) == 'L') {
+            // line
+            annotations.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
+            OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
+            return OchPortHelper.ochPortDescription(
+                    PortNumber.portNumber(portNumber + 100L),
+                    true,
+                    OduSignalType.ODUC2,
+                    true,
+                    signalId,
+                    DefaultAnnotations.builder().putAll(annotations).build());
+        } else if (portComponentIndex.charAt(0) == 'C') {
+            // client
+            annotations.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
+            Builder builder = DefaultPortDescription.builder();
+            builder.withPortNumber(PortNumber.portNumber(portNumber))
+                    .isEnabled(true)
+                    .portSpeed(100000L)
+                    .type(Type.PACKET)
+                    .annotations(DefaultAnnotations.builder().putAll(annotations).build());
+
+            return builder.build();
+        }
+
+        return null;
+    }
+}
diff --git a/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZteDriversLoader.java b/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZteDriversLoader.java
new file mode 100644
index 0000000..f11c503
--- /dev/null
+++ b/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZteDriversLoader.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2019-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.zte;
+
+import org.onosproject.net.driver.AbstractDriverLoader;
+import org.osgi.service.component.annotations.Component;
+
+@Component(immediate = true)
+public class ZteDriversLoader extends AbstractDriverLoader {
+    public ZteDriversLoader() {
+        super("/zte-drivers.xml");
+    }
+}
diff --git a/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZteNetconfDeviceTransceiver.java b/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZteNetconfDeviceTransceiver.java
new file mode 100644
index 0000000..c064426
--- /dev/null
+++ b/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZteNetconfDeviceTransceiver.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2019-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.zte;
+
+import com.google.common.base.Strings;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.odtn.behaviour.ConfigurableTransceiver;
+import org.onosproject.odtn.behaviour.PlainTransceiver;
+import org.slf4j.Logger;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME;
+import static org.slf4j.LoggerFactory.getLogger;
+
+public class ZteNetconfDeviceTransceiver
+        extends PlainTransceiver
+        implements ConfigurableTransceiver {
+
+    private final Logger log = getLogger(getClass());
+    private static final String ANOTATION_NAME = "xc:operation";
+
+    @Override
+    public List<CharSequence> enable(PortNumber client, PortNumber line, boolean enable) {
+        DeviceId deviceId = handler().data().deviceId();
+        log.info("Discovering ZTE device {}", deviceId);
+
+        Port port = handler().get(DeviceService.class).getPort(deviceId, client);
+        if (port == null) {
+            log.warn("{} does not exist on {}", client, deviceId);
+            return Collections.emptyList();
+        }
+
+        String component = port.annotations().value(OC_NAME);
+        if (Strings.isNullOrEmpty(component)) {
+            log.warn("{} annotation not found on {}@{}", OC_NAME, client, deviceId);
+            return Collections.emptyList();
+        }
+
+        String componentName = component.replace("PORT", "TRANSCEIVER");
+        return enable(componentName, enable);
+    }
+
+
+}
diff --git a/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZtePortStatisticsDiscovery.java b/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZtePortStatisticsDiscovery.java
new file mode 100644
index 0000000..94e1875
--- /dev/null
+++ b/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZtePortStatisticsDiscovery.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2019-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.zte;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.onosproject.drivers.utilities.XmlConfigParser;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
+import org.onosproject.net.device.DefaultPortStatistics;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.device.PortStatistics;
+import org.onosproject.net.device.PortStatisticsDiscovery;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.netconf.NetconfController;
+import org.onosproject.netconf.NetconfException;
+import org.onosproject.netconf.NetconfSession;
+import org.slf4j.Logger;
+
+import java.util.Collection;
+import java.util.List;
+
+import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME;
+import static org.slf4j.LoggerFactory.getLogger;
+
+public class ZtePortStatisticsDiscovery extends AbstractHandlerBehaviour
+        implements PortStatisticsDiscovery {
+
+    private static final Logger LOG = getLogger(ZtePortStatisticsDiscovery.class);
+
+    @Override
+    public Collection<PortStatistics> discoverPortStatistics() {
+        DeviceId deviceId = handler().data().deviceId();
+        LOG.debug("Discovering ZTE PortStatistics for device {}", deviceId);
+
+        NetconfController controller = handler().get(NetconfController.class);
+
+        if (null == controller) {
+            LOG.error("Cannot find NetconfController");
+            return null;
+        }
+
+        NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
+
+        if (null == session) {
+            LOG.error("No session available for device {}", deviceId);
+            return null;
+        }
+
+        DeviceService deviceService = this.handler().get(DeviceService.class);
+        List<Port> ports = deviceService.getPorts(deviceId);
+
+        Collection<PortStatistics> portStatistics = Lists.newArrayList();
+
+        ports.stream()
+                .filter(Port::isEnabled)
+                .filter(this::isClientPort)
+                .forEach(port -> portStatistics.add(discoverSpecifiedPortStatistics(session, deviceId, port)));
+
+        return portStatistics;
+    }
+
+    private boolean isClientPort(Port port) {
+        String portName = port.annotations().value(OC_NAME);
+        if (Strings.isNullOrEmpty(portName)) {
+            return false;
+        }
+        String[] portInfos = portName.split("-");
+        return portInfos.length == 4 && portInfos[3].startsWith("C");
+    }
+
+    private String getDataOfRpcReply(String rpcReply) {
+        String data = null;
+        int begin = rpcReply.indexOf("<data>");
+        int end = rpcReply.lastIndexOf("</data>");
+        if (begin != -1 && end != -1) {
+            data = (String) rpcReply.subSequence(begin, end + "</data>".length());
+        } else {
+            data = rpcReply;
+        }
+        return data;
+    }
+
+    private PortStatistics discoverSpecifiedPortStatistics(NetconfSession session, DeviceId deviceId, Port port) {
+
+        String portName = port.annotations().value(OC_NAME);
+        String rpc = buildPortStatisticsRequest("INTERFACE" + portName.substring("PORT".length()));
+
+        try {
+            String reply = session.requestSync(rpc);
+            XMLConfiguration cfg = (XMLConfiguration) XmlConfigParser.loadXmlString(getDataOfRpcReply(reply));
+            DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
+
+            builder.setPort(port.number())
+                    .setPacketsReceived(getInteger(cfg, "in-pks"))
+                    .setPacketsSent(getInteger(cfg, "out-pkts"))
+                    .setBytesReceived(getInteger(cfg, "in-octets"))
+                    .setBytesSent(getInteger(cfg, "out-octets"))
+                    .setPacketsRxDropped(getInteger(cfg, "in-fcs-errors"))
+                    .setPacketsTxDropped(getInteger(cfg, "carrier-transitions"))
+                    .setPacketsRxErrors(getInteger(cfg, "in-errors"))
+                    .setPacketsTxErrors(getInteger(cfg, "out-errors"))
+                    .setDeviceId(deviceId);
+
+            return builder.build();
+        } catch (NetconfException e) {
+            LOG.error("ZTE device portStatistic request error.", e);
+            return null;
+        }
+    }
+
+    private String buildPortStatisticsRequest(String portName) {
+        StringBuilder rpc = new StringBuilder();
+        rpc.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">");
+        rpc.append("<get>");
+        rpc.append("<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">");
+        rpc.append("<interfaces xmlns=\"http://openconfig.net/yang/interfaces\">");
+        rpc.append("<interface>");
+        rpc.append("<name>");
+        rpc.append(portName);
+        rpc.append("</name>");
+        rpc.append("<state>");
+        rpc.append("<counters>");
+        rpc.append("</counters>");
+        rpc.append("</state>");
+        rpc.append("</interface>");
+        rpc.append("</interfaces>");
+        rpc.append("</filter>");
+        rpc.append("</get>");
+        rpc.append("</rpc>");
+
+        return rpc.toString();
+    }
+
+    private int getInteger(XMLConfiguration cfg, String item) {
+        String numString = cfg.getString("interfaces.interface.state.counters." + item);
+        if (Strings.isNullOrEmpty(numString)) {
+            LOG.debug("Cannot get port statistic data for {}, set 0 as default.", item);
+            return 0;
+        }
+
+        try {
+            return Integer.parseInt(numString);
+        } catch (NumberFormatException e) {
+            LOG.warn("Cannot convert data for {}", item);
+            return 0;
+        }
+    }
+}
diff --git a/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZteTransceiver.java b/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZteTransceiver.java
new file mode 100644
index 0000000..3a713ad
--- /dev/null
+++ b/drivers/zte/src/main/java/org/onosproject/drivers/zte/ZteTransceiver.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2019-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.zte;
+
+import com.google.common.base.Strings;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.odtn.behaviour.ConfigurableTransceiver;
+import org.onosproject.odtn.behaviour.OdtnTerminalDeviceDriver.Operation;
+import org.onosproject.odtn.utils.openconfig.OpenConfigAssignmentHandler;
+import org.onosproject.odtn.utils.openconfig.OpenConfigChannelHandler;
+import org.onosproject.odtn.utils.openconfig.OpenConfigConfigOfAssignmentHandler;
+import org.onosproject.odtn.utils.openconfig.OpenConfigConfigOfChannelHandler;
+import org.onosproject.odtn.utils.openconfig.OpenConfigLogicalChannelAssignmentsHandler;
+import org.onosproject.odtn.utils.openconfig.OpenConfigLogicalChannelsHandler;
+import org.onosproject.odtn.utils.openconfig.OpenConfigTerminalDeviceHandler;
+import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanassignmentconfig.AssignmentTypeEnum;
+import org.slf4j.Logger;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME;
+import static org.slf4j.LoggerFactory.getLogger;
+
+public class ZteTransceiver extends AbstractHandlerBehaviour
+        implements ConfigurableTransceiver {
+
+    private final Logger log = getLogger(getClass());
+
+    private static final String ANOTATION_NAME = "xc:operation";
+
+    private final int[] clientPortIndexs = new int[] {
+            20975681, 18878529, 19927105, 17829953,
+            20975745, 18878593, 19927169, 17830017,
+            20975809, 18878657, 19927233, 17830081,
+            20975873, 18878721, 19927297, 17830145
+    };
+
+    private final int[] linePortIndexs = new int[] {
+            21499969, 19402817, 20451393, 18354241,
+            21500033, 19402881, 20451457, 18354305
+    };
+
+    @Override
+    public List<CharSequence> enable(PortNumber client, PortNumber line, boolean enable) {
+        DeviceId deviceId = handler().data().deviceId();
+        log.info("Discovering ZTE device {}", deviceId);
+
+        Port clientPort = handler().get(DeviceService.class).getPort(deviceId, client);
+        if (clientPort == null) {
+            log.warn("{} does not exist on {}", client, deviceId);
+            return Collections.emptyList();
+        }
+
+        String clientName = clientPort.annotations().value(OC_NAME);
+        if (Strings.isNullOrEmpty(clientName)) {
+            log.warn("{} annotations not exist on {}@{}", OC_NAME, client, deviceId);
+            return Collections.emptyList();
+        }
+
+        Port linePort = handler().get(DeviceService.class).getPort(deviceId, line);
+        if (linePort == null) {
+            log.warn("{} does not exist on {}", line, deviceId);
+            return Collections.emptyList();
+        }
+
+        String lineName = linePort.annotations().value(OC_NAME);
+        if (Strings.isNullOrEmpty(lineName)) {
+            log.warn("{} annotations not exist on {}@{}", OC_NAME, line, deviceId);
+            return Collections.emptyList();
+        }
+
+        int clientIndex, lineIndex;
+
+        try {
+            clientIndex = getPortIndex(clientName);
+            lineIndex = getPortIndex(lineName);
+        } catch (IllegalArgumentException e) {
+            return Collections.emptyList();
+        }
+
+        // create <terminal-device xmlns="http://openconfig.net/yang/terminal-device">
+        //        </terminal-device>
+        OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler();
+        // add <logical-channels></logical-channels>
+        OpenConfigLogicalChannelsHandler logicalChannels =
+                new OpenConfigLogicalChannelsHandler(terminalDevice);
+        // add <channel><index>"clientIndex"</index></channel>
+        OpenConfigChannelHandler channel =
+                new OpenConfigChannelHandler(clientIndex, logicalChannels);
+
+        // add <channel xc:operation="merge/delete">
+        if (enable) {
+            channel.addAnnotation(ANOTATION_NAME, Operation.MERGE.value());
+        } else {
+            channel.addAnnotation(ANOTATION_NAME, Operation.DELETE.value());
+        }
+
+        // add <config><index>"clientIndex"</index></config>
+        OpenConfigConfigOfChannelHandler configOfChannel =
+                new OpenConfigConfigOfChannelHandler(channel);
+        configOfChannel.addIndex(clientIndex);
+
+        // add <logical-channel-assignments></logical-channel-assignments>
+        OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments =
+                new OpenConfigLogicalChannelAssignmentsHandler(channel);
+
+        // add <assignment><index>1</index></assignment>
+        OpenConfigAssignmentHandler assignment =
+                new OpenConfigAssignmentHandler(1, logicalChannelAssignments);
+
+        // add <config><assignment-type>LOGICAL_CHANNEL</assignment-type>
+        //             <logical-channel>"lineIndex"</logical-channel>
+        //     </config>
+        OpenConfigConfigOfAssignmentHandler configOfAssignment =
+                new OpenConfigConfigOfAssignmentHandler(assignment);
+        configOfAssignment.addAssignmentType(AssignmentTypeEnum.LOGICAL_CHANNEL);
+        configOfAssignment.addLogicalChannel("" + lineIndex);
+
+        return terminalDevice.getListCharSequence();
+    }
+
+    // index should be fixed
+    private int getPortIndex(String portName) throws IllegalArgumentException {
+        //PORT-1-4-C1
+        String[] portInfos = portName.split("-");
+        if (portInfos.length == 4) {
+            throw new IllegalArgumentException("ZTE device port name illegal.");
+        }
+
+        int slotIndex = Integer.parseInt(portInfos[2]);
+        int index = Integer.parseInt(portInfos[3].substring(1));
+
+        if (portInfos[3].startsWith("C")) {
+            return clientPortIndexs[index * 4 - slotIndex];
+        } else if (portInfos[3].startsWith("C")) {
+            return linePortIndexs[index * 4 - slotIndex];
+        }
+
+        throw new IllegalArgumentException("Connot match port index for ZTE device.");
+    }
+
+}
diff --git a/drivers/zte/src/main/java/org/onosproject/drivers/zte/package-info.java b/drivers/zte/src/main/java/org/onosproject/drivers/zte/package-info.java
new file mode 100644
index 0000000..df337be
--- /dev/null
+++ b/drivers/zte/src/main/java/org/onosproject/drivers/zte/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2019-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.
+ */
+
+/**
+ * Zte netconf drivers.
+ */
+package org.onosproject.drivers.zte;
\ No newline at end of file
diff --git a/drivers/zte/src/main/resources/zte-drivers.xml b/drivers/zte/src/main/resources/zte-drivers.xml
new file mode 100644
index 0000000..1f1d728
--- /dev/null
+++ b/drivers/zte/src/main/resources/zte-drivers.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2016 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="zte-netconf" manufacturer="ZTE" hwVersion="ZTE hw" swVersion="ZTE sw">
+        <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
+                   impl="org.onosproject.drivers.zte.ZteDeviceDiscoveryImpl"/>
+        <behaviour api="org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery"
+                   impl="org.onosproject.drivers.zte.ZteDeviceDiscoveryImpl"/>
+        <behaviour api ="org.onosproject.net.optical.OpticalDevice"
+                   impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
+        <behaviour api="org.onosproject.odtn.behaviour.ConfigurableTransceiver"
+                   impl="org.onosproject.drivers.zte.ZteNetconfDeviceTransceiver"/>
+        <behaviour api="org.onosproject.net.device.PortStatisticsDiscovery"
+                   impl="org.onosproject.drivers.zte.ZtePortStatisticsDiscovery"/>
+    </driver>
+</drivers>