[ONOS-6529] Add Cisco REST device drivers
Change-Id: I97de0a7d326492a90d1541e5c028255f0b735aa0
diff --git a/drivers/cisco/netconf/BUCK b/drivers/cisco/netconf/BUCK
new file mode 100644
index 0000000..b3b082a
--- /dev/null
+++ b/drivers/cisco/netconf/BUCK
@@ -0,0 +1,32 @@
+COMPILE_DEPS = [
+ '//lib:CORE_DEPS',
+ '//drivers/utilities:onos-drivers-utilities',
+ '//protocols/netconf/api:onos-protocols-netconf-api',
+]
+
+TEST_DEPS = [
+ '//lib:TEST_ADAPTERS',
+ '//core/api:onos-api-tests',
+]
+
+BUNDLES = [
+ ':onos-drivers-cisco-netconf',
+ '//drivers/utilities:onos-drivers-utilities',
+]
+
+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.cisco.netconf',
+ title = 'Cisco NETCONF device drivers',
+ category = 'Drivers',
+ url = 'http://onosproject.org',
+ description = 'ONOS Cisco NETCONF device drivers application.',
+ included_bundles = BUNDLES,
+ required_apps = [ 'org.onosproject.netconf', 'org.onosproject.drivers.netconf' ],
+)
diff --git a/drivers/cisco/netconf/features.xml b/drivers/cisco/netconf/features.xml
new file mode 100644
index 0000000..bd2aad5
--- /dev/null
+++ b/drivers/cisco/netconf/features.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ ~ Copyright 2016-present 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.
+ -->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+ <feature name="${project.artifactId}" version="${project.version}"
+ description="${project.description}">
+ <feature>onos-api</feature>
+ <bundle>mvn:${project.groupId}/onos-drivers-netconf/${project.version}</bundle>
+
+ <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
+
+ <bundle>mvn:${project.groupId}/onos-drivers-utilities/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/onos-netconf-api/${project.version}</bundle>
+ </feature>
+</features>
diff --git a/drivers/cisco/netconf/pom.xml b/drivers/cisco/netconf/pom.xml
new file mode 100644
index 0000000..ce4ee0a
--- /dev/null
+++ b/drivers/cisco/netconf/pom.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-present Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project 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-cisco</artifactId>
+ <groupId>org.onosproject</groupId>
+ <version>1.11.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>onos-drivers-cisco-netconf</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>Cisco NETCONF device drivers</description>
+
+ <properties>
+ <onos.app.name>org.onosproject.drivers.cisco.netconf</onos.app.name>
+ <onos.app.origin>ON.Lab</onos.app.origin>
+ <onos.app.category>Drivers</onos.app.category>
+ <onos.app.title>Cisco NETCONF Device Drivers</onos.app.title>
+ <onos.app.url>http://onosproject.org</onos.app.url>
+ <onos.app.requires>
+ org.onosproject.netconf
+ </onos.app.requires>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-drivers-utilities</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-netconf-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/CiscoDriversLoader.java b/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/CiscoDriversLoader.java
new file mode 100644
index 0000000..166cb23
--- /dev/null
+++ b/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/CiscoDriversLoader.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2016-present 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.drivers.cisco;
+
+import org.apache.felix.scr.annotations.Component;
+import org.onosproject.net.driver.AbstractDriverLoader;
+
+/**
+ * Loader for Cisco device drivers.
+ */
+@Component(immediate = true)
+public class CiscoDriversLoader extends AbstractDriverLoader {
+ public CiscoDriversLoader() {
+ super("/cisco-drivers.xml");
+ }
+}
diff --git a/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/CiscoIosDeviceDescription.java b/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/CiscoIosDeviceDescription.java
new file mode 100644
index 0000000..c9552ba
--- /dev/null
+++ b/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/CiscoIosDeviceDescription.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2016-present 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.drivers.cisco;
+
+import com.google.common.collect.ImmutableList;
+
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.device.DefaultDeviceDescription;
+import org.onosproject.net.device.DeviceDescription;
+import org.onosproject.net.device.DeviceDescriptionDiscovery;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.device.PortDescription;
+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.io.IOException;
+import java.util.List;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+public class CiscoIosDeviceDescription extends AbstractHandlerBehaviour
+ implements DeviceDescriptionDiscovery {
+
+
+ private final Logger log = getLogger(getClass());
+ private String version;
+ private String interfaces;
+
+ @Override
+ public DeviceDescription discoverDeviceDetails() {
+ NetconfController controller = checkNotNull(handler().get(NetconfController.class));
+ NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
+ try {
+ version = session.get(showVersionRequestBuilder());
+ } catch (IOException e) {
+ throw new RuntimeException(new NetconfException("Failed to retrieve version info.", e));
+ }
+
+ String[] details = TextBlockParserCisco.parseCiscoIosDeviceDetails(version);
+
+ DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
+ DeviceId deviceId = handler().data().deviceId();
+ Device device = deviceService.getDevice(deviceId);
+
+ return new DefaultDeviceDescription(device.id().uri(), Device.Type.SWITCH,
+ details[0], details[1],
+ details[2], details[3],
+ device.chassisId());
+ }
+
+ @Override
+ public List<PortDescription> discoverPortDetails() {
+ NetconfController controller = checkNotNull(handler().get(NetconfController.class));
+ NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
+ try {
+ interfaces = session.get(showInterfacesRequestBuilder());
+ } catch (IOException e) {
+ log.error("Failed to retrieve Interfaces");
+ return ImmutableList.of();
+ }
+ return ImmutableList.copyOf(TextBlockParserCisco.parseCiscoIosPorts(interfaces));
+ }
+
+ /**
+ * Builds a request crafted to get the configuration required to create
+ * details descriptions for the device.
+ *
+ * @return The request string.
+ */
+ private String showVersionRequestBuilder() {
+ StringBuilder rpc = new StringBuilder("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">");
+ rpc.append("<get>");
+ rpc.append("<filter>");
+ rpc.append("<config-format-text-block>");
+ rpc.append("<text-filter-spec> | include exp_to_match_run_conf </text-filter-spec>");
+ rpc.append("</config-format-text-block>");
+ rpc.append("<oper-data-format-text-block>");
+ rpc.append("<show>version</show>");
+ rpc.append("</oper-data-format-text-block>");
+ rpc.append("</filter>");
+ rpc.append("</get>");
+ rpc.append("</rpc>]]>]]>");
+ return rpc.toString();
+ }
+
+ /**
+ * Builds a request crafted to get the configuration required to create
+ * details descriptions for the device.
+ *
+ * @return The request string.
+ */
+ private String showInterfacesRequestBuilder() {
+ //Message ID is injected later.
+ StringBuilder rpc = new StringBuilder("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">");
+ rpc.append("<get>");
+ rpc.append("<filter>");
+ rpc.append("<config-format-text-block>");
+ rpc.append("<text-filter-spec> | include exp_to_match_run_conf </text-filter-spec>");
+ rpc.append("</config-format-text-block>");
+ rpc.append("<oper-data-format-text-block>");
+ rpc.append("<show>interfaces</show>");
+ rpc.append("</oper-data-format-text-block>");
+ rpc.append("</filter>");
+ rpc.append("</get>");
+ rpc.append("</rpc>]]>]]>");
+ return rpc.toString();
+ }
+
+}
\ No newline at end of file
diff --git a/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/InterfaceConfigCiscoIosImpl.java b/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/InterfaceConfigCiscoIosImpl.java
new file mode 100644
index 0000000..fecd3ef
--- /dev/null
+++ b/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/InterfaceConfigCiscoIosImpl.java
@@ -0,0 +1,504 @@
+/*
+ * Copyright 2016-present 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.drivers.cisco;
+
+import org.onlab.packet.VlanId;
+import org.onosproject.drivers.utilities.XmlConfigParser;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.InterfaceConfig;
+import org.onosproject.net.behaviour.PatchDescription;
+import org.onosproject.net.behaviour.TunnelDescription;
+import org.onosproject.net.device.DeviceInterfaceDescription;
+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.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Configures interfaces on Cisco IOS devices.
+ */
+public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
+ implements InterfaceConfig {
+
+ private final Logger log = getLogger(getClass());
+
+ /**
+ * Adds an access interface to a VLAN.
+ *
+ * @param deviceId the device ID
+ * @param intf the name of the interface
+ * @param vlanId the VLAN ID
+ * @return the result of operation
+ */
+ @Override
+ public boolean addAccessInterface(DeviceId deviceId, String intf, VlanId vlanId) {
+ return addAccessMode(intf, vlanId);
+ }
+
+ /**
+ * Adds an access interface to a VLAN.
+ *
+ * @param intf the name of the interface
+ * @param vlanId the VLAN ID
+ * @return the result of operation
+ */
+ @Override
+ public boolean addAccessMode(String intf, VlanId vlanId) {
+ NetconfController controller = checkNotNull(handler()
+ .get(NetconfController.class));
+
+ NetconfSession session = controller.getDevicesMap().get(handler()
+ .data().deviceId()).getSession();
+ String reply;
+ try {
+ reply = session.requestSync(addAccessModeBuilder(intf, vlanId));
+ } catch (NetconfException e) {
+ log.error("Failed to configure VLAN ID {} on device {} interface {}.",
+ vlanId, handler().data().deviceId(), intf, e);
+ return false;
+ }
+
+ return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
+ new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
+ }
+
+ /**
+ * Builds a request to add an access interface to a VLAN.
+ *
+ * @param intf the name of the interface
+ * @param vlanId the VLAN ID
+ * @return the request string.
+ */
+ private String addAccessModeBuilder(String intf, VlanId vlanId) {
+ StringBuilder rpc = new StringBuilder(getOpeningString(intf));
+ rpc.append("<switchport><access><vlan><VLANIDVLANPortAccessMode>");
+ rpc.append(vlanId);
+ rpc.append("</VLANIDVLANPortAccessMode></vlan></access></switchport>");
+ rpc.append("<switchport><mode><access/></mode></switchport>");
+ rpc.append(getClosingString());
+
+ return rpc.toString();
+ }
+
+ /**
+ * Removes an access interface to a VLAN.
+ *
+ * @param deviceId the device ID
+ * @param intf the name of the interface
+ * @return the result of operation
+ */
+ @Override
+ public boolean removeAccessInterface(DeviceId deviceId, String intf) {
+ return removeAccessMode(intf);
+ }
+
+ /**
+ * Removes an access interface to a VLAN.
+ *
+ * @param intf the name of the interface
+ * @return the result of operation
+ */
+ @Override
+ public boolean removeAccessMode(String intf) {
+ NetconfController controller = checkNotNull(handler()
+ .get(NetconfController.class));
+
+ NetconfSession session = controller.getDevicesMap().get(handler()
+ .data().deviceId()).getSession();
+ String reply;
+ try {
+ reply = session.requestSync(removeAccessModeBuilder(intf));
+ } catch (NetconfException e) {
+ log.error("Failed to remove access mode from device {} interface {}.",
+ handler().data().deviceId(), intf, e);
+ return false;
+ }
+
+ return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
+ new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
+ }
+
+ /**
+ * Builds a request to remove an access interface from a VLAN.
+ *
+ * @param intf the name of the interface
+ * @return the request string.
+ */
+ private String removeAccessModeBuilder(String intf) {
+ StringBuilder rpc = new StringBuilder(getOpeningString(intf));
+ rpc.append("<switchport operation=\"delete\"><access><vlan><VLANIDVLANPortAccessMode>");
+ rpc.append("</VLANIDVLANPortAccessMode></vlan></access></switchport>");
+ rpc.append("<switchport operation=\"delete\"><mode><access/></mode></switchport>");
+ rpc.append(getClosingString());
+
+ return rpc.toString();
+ }
+
+ /**
+ * Adds a trunk interface for VLANs.
+ *
+ * @param deviceId the device ID
+ * @param intf the name of the interface
+ * @param vlanIds the VLAN IDs
+ * @return the result of operation
+ */
+ @Override
+ public boolean addTrunkInterface(DeviceId deviceId, String intf, List<VlanId> vlanIds) {
+ return addTrunkMode(intf, vlanIds);
+ }
+
+ /**
+ * Adds a trunk interface for VLANs.
+ *
+ * @param intf the name of the interface
+ * @param vlanIds the VLAN IDs
+ * @return the result of operation
+ */
+ @Override
+ public boolean addTrunkMode(String intf, List<VlanId> vlanIds) {
+ NetconfController controller = checkNotNull(handler()
+ .get(NetconfController.class));
+
+ NetconfSession session = controller.getDevicesMap().get(handler()
+ .data().deviceId()).getSession();
+ String reply;
+ try {
+ reply = session.requestSync(addTrunkModeBuilder(intf, vlanIds));
+ } catch (NetconfException e) {
+ log.error("Failed to configure trunk mode for VLAN ID {} on device {} interface {}.",
+ vlanIds, handler().data().deviceId(), intf, e);
+ return false;
+ }
+
+ return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
+ new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
+ }
+
+ /**
+ * Builds a request to configure an interface as trunk for VLANs.
+ *
+ * @param intf the name of the interface
+ * @param vlanIds the VLAN IDs
+ * @return the request string.
+ */
+ private String addTrunkModeBuilder(String intf, List<VlanId> vlanIds) {
+ StringBuilder rpc = new StringBuilder(getOpeningString(intf));
+ rpc.append("<switchport><trunk><encapsulation><dot1q/></encapsulation>");
+ rpc.append("</trunk></switchport><switchport><trunk><allowed><vlan>");
+ rpc.append("<VLANIDsAllowedVLANsPortTrunkingMode>");
+ rpc.append(getVlansString(vlanIds));
+ rpc.append("</VLANIDsAllowedVLANsPortTrunkingMode></vlan></allowed></trunk>");
+ rpc.append("</switchport><switchport><mode><trunk/></mode></switchport>");
+ rpc.append(getClosingString());
+
+ return rpc.toString();
+ }
+
+ /**
+ * Removes trunk mode configuration from an interface.
+ *
+ * @param deviceId the device ID
+ * @param intf the name of the interface
+ * @return the result of operation
+ */
+ @Override
+ public boolean removeTrunkInterface(DeviceId deviceId, String intf) {
+ return removeTrunkMode(intf);
+ }
+
+ /**
+ * Removes trunk mode configuration from an interface.
+ *
+ * @param intf the name of the interface
+ * @return the result of operation
+ */
+ @Override
+ public boolean removeTrunkMode(String intf) {
+ NetconfController controller = checkNotNull(handler()
+ .get(NetconfController.class));
+
+ NetconfSession session = controller.getDevicesMap().get(handler()
+ .data().deviceId()).getSession();
+ String reply;
+ try {
+ reply = session.requestSync(removeTrunkModeBuilder(intf));
+ } catch (NetconfException e) {
+ log.error("Failed to remove trunk mode from device {} interface {}.",
+ handler().data().deviceId(), intf, e);
+ return false;
+ }
+
+ return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
+ new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
+}
+
+ /**
+ * Builds a request to remove trunk mode configuration from an interface.
+ *
+ * @param intf the name of the interface
+ * @return the request string.
+ */
+ private String removeTrunkModeBuilder(String intf) {
+ StringBuilder rpc = new StringBuilder(getOpeningString(intf));
+ rpc.append("<switchport><mode operation=\"delete\"><trunk/></mode></switchport>");
+ rpc.append("<switchport><trunk operation=\"delete\"><encapsulation>");
+ rpc.append("<dot1q/></encapsulation></trunk></switchport>");
+ rpc.append("<switchport><trunk operation=\"delete\"><allowed><vlan>");
+ rpc.append("<VLANIDsAllowedVLANsPortTrunkingMode>");
+ rpc.append("</VLANIDsAllowedVLANsPortTrunkingMode></vlan></allowed>");
+ rpc.append("</trunk></switchport>");
+ rpc.append(getClosingString());
+
+ return rpc.toString();
+ }
+
+ /**
+ * Adds a rate limit on an interface.
+ *
+ * @param intf the name of the interface
+ * @param limit the limit as a percentage
+ * @return the result of operation
+ */
+ @Override
+ public boolean addRateLimit(String intf, short limit) {
+ NetconfController controller = checkNotNull(handler()
+ .get(NetconfController.class));
+
+ NetconfSession session = controller.getDevicesMap().get(handler()
+ .data().deviceId()).getSession();
+ String reply;
+ try {
+ reply = session.requestSync(addRateLimitBuilder(intf, limit));
+ } catch (NetconfException e) {
+ log.error("Failed to configure rate limit {}%% on device {} interface {}.",
+ limit, handler().data().deviceId(), intf, e);
+ return false;
+ }
+
+ return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
+ new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
+ }
+
+ /**
+ * Builds a request to configure an interface with rate limit.
+ *
+ * @param intf the name of the interface
+ * @param limit the limit as a percentage
+ * @return the request string.
+ */
+ private String addRateLimitBuilder(String intf, short limit) {
+ StringBuilder rpc = new StringBuilder(getOpeningString(intf));
+ rpc.append("<srr-queue><bandwidth><limit>");
+ rpc.append("<EnterBandwidthLimitInterfaceAsPercentage>");
+ rpc.append(limit);
+ rpc.append("</EnterBandwidthLimitInterfaceAsPercentage>");
+ rpc.append("</limit></bandwidth></srr-queue>");
+ rpc.append(getClosingString());
+
+ return rpc.toString();
+ }
+
+ /**
+ * Removes rate limit from an interface.
+ *
+ * @param intf the name of the interface
+ * @return the result of operation
+ */
+ @Override
+ public boolean removeRateLimit(String intf) {
+ NetconfController controller = checkNotNull(handler()
+ .get(NetconfController.class));
+
+ NetconfSession session = controller.getDevicesMap().get(handler()
+ .data().deviceId()).getSession();
+ String reply;
+ try {
+ reply = session.requestSync(removeRateLimitBuilder(intf));
+ } catch (NetconfException e) {
+ log.error("Failed to remove rate limit from device {} interface {}.",
+ handler().data().deviceId(), intf, e);
+ return false;
+ }
+
+ return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
+ new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
+ }
+
+ /**
+ * Builds a request to remove a rate limit from an interface.
+ *
+ * @param intf the name of the interface
+ * @return the request string.
+ */
+ private String removeRateLimitBuilder(String intf) {
+ StringBuilder rpc = new StringBuilder(getOpeningString(intf));
+ rpc.append("<srr-queue operation=\"delete\"><bandwidth><limit>");
+ rpc.append("</limit></bandwidth></srr-queue>");
+ rpc.append(getClosingString());
+
+ return rpc.toString();
+ }
+
+ /**
+ * Builds the opening of a request for the configuration of an interface.
+ *
+ * @param intf the interface to be configured
+ * @return the opening string
+ */
+ private String getOpeningString(String intf) {
+ StringBuilder rpc =
+ new StringBuilder("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ");
+ rpc.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
+ rpc.append("<edit-config>");
+ rpc.append("<target>");
+ rpc.append("<running/>");
+ rpc.append("</target>");
+ rpc.append("<config>");
+ rpc.append("<xml-config-data>");
+ rpc.append("<Device-Configuration><interface><Param>");
+ rpc.append(intf);
+ rpc.append("</Param>");
+ rpc.append("<ConfigIf-Configuration>");
+
+ return rpc.toString();
+ }
+
+ /**
+ * Builds the closing of a request for the configuration of an interface.
+ *
+ * @return the closing string
+ */
+ private String getClosingString() {
+ StringBuilder rpc = new StringBuilder("</ConfigIf-Configuration>");
+ rpc.append("</interface>");
+ rpc.append("</Device-Configuration>");
+ rpc.append("</xml-config-data>");
+ rpc.append("</config>");
+ rpc.append("</edit-config>");
+ rpc.append("</rpc>");
+
+ return rpc.toString();
+ }
+
+ /**
+ * Builds a string with comma separated VLAN-IDs.
+ *
+ * @param vlanIds the VLAN IDs
+ * @return the string including the VLAN-IDs
+ */
+ private String getVlansString(List<VlanId> vlanIds) {
+ StringBuilder vlansStringBuilder = new StringBuilder();
+
+ for (int i = 0; i < vlanIds.size(); i++) {
+ vlansStringBuilder.append(vlanIds.get(i));
+
+ if (i != vlanIds.size() - 1) {
+ vlansStringBuilder.append(",");
+ }
+ }
+ return vlansStringBuilder.toString();
+ }
+
+ /**
+ * Provides the interfaces configured on a device.
+ *
+ * @param deviceId the device ID
+ * @return the list of the configured interfaces
+ */
+ @Override
+ public List<DeviceInterfaceDescription> getInterfaces(DeviceId deviceId) {
+ return getInterfaces();
+ }
+
+ /**
+ * Provides the interfaces configured on a device.
+ *
+ * @return the list of the configured interfaces
+ */
+ @Override
+ public List<DeviceInterfaceDescription> getInterfaces() {
+ NetconfController controller =
+ checkNotNull(handler().get(NetconfController.class));
+
+ NetconfSession session = controller.getDevicesMap().get(handler()
+ .data().deviceId()).getSession();
+ String reply;
+ try {
+ reply = session.requestSync(getConfigBuilder());
+ } catch (NetconfException e) {
+ log.error("Failed to retrieve configuration from device {}.",
+ handler().data().deviceId(), e);
+ return null;
+ }
+
+ return XmlParserCisco.getInterfacesFromConfig(XmlConfigParser.loadXml(
+ new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
+ }
+
+ /**
+ * Builds a request for getting configuration from device.
+ *
+ * @return the request string.
+ */
+ private String getConfigBuilder() {
+ StringBuilder rpc =
+ new StringBuilder("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ");
+ rpc.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
+ rpc.append("<get-config>");
+ rpc.append("<source>");
+ rpc.append("<running/>");
+ rpc.append("</source>");
+ rpc.append("<filter>");
+ rpc.append("<config-format-xml>");
+ rpc.append("</config-format-xml>");
+ rpc.append("</filter>");
+ rpc.append("</get-config>");
+ rpc.append("</rpc>");
+
+ return rpc.toString();
+ }
+
+ @Override
+ public boolean addTunnelMode(String ifaceName, TunnelDescription tunnelDesc) {
+ throw new UnsupportedOperationException("Add tunnel mode is not supported");
+ }
+
+ @Override
+ public boolean removeTunnelMode(String ifaceName) {
+ throw new UnsupportedOperationException("Remove tunnel mode is not supported");
+ }
+
+ @Override
+ public boolean addPatchMode(String ifaceName, PatchDescription patchDesc) {
+ throw new UnsupportedOperationException("Add patch interface is not supported");
+ }
+
+ @Override
+ public boolean removePatchMode(String ifaceName) {
+ throw new UnsupportedOperationException("Remove patch interface is not supported");
+ }
+}
+
diff --git a/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/TextBlockParserCisco.java b/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/TextBlockParserCisco.java
new file mode 100644
index 0000000..b47411b
--- /dev/null
+++ b/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/TextBlockParserCisco.java
@@ -0,0 +1,298 @@
+/*
+* Copyright 2016-present 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.drivers.cisco;
+
+import com.google.common.collect.Lists;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.PortDescription;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.onosproject.net.Port.Type;
+
+/**
+ *Parser for Netconf XML configurations and replys as plain text.
+ */
+final class TextBlockParserCisco {
+
+ private static final String PHRASE = "bytes of memory.";
+ private static final String VERSION = "Version ";
+ private static final String EOF_VERSION1 = "Software";
+ private static final String EOF_VERSION2 = "Software,";
+ private static final String EOF_VERSION3 = "RELEASE";
+ private static final String PROCESSOR_BOARD = "Processor board ID ";
+ private static final String BANDWIDTH = "BW ";
+ private static final String SPEED = " Kbit/sec";
+ private static final String ETHERNET = "Eth";
+ private static final String FASTETHERNET = "Fas";
+ private static final String GIGABITETHERNET = "Gig";
+ private static final String FDDI = "Fdd";
+ private static final String POS = "POS";
+ private static final String SERIAL = "Ser";
+ private static final String NEWLINE_SPLITTER = "\n";
+ private static final String PORT_DELIMITER = "/";
+ private static final String SPACE = " ";
+ private static final String IS_UP = "is up, line protocol is up";
+ private static final List INTERFACES = Arrays.asList(ETHERNET, FASTETHERNET, GIGABITETHERNET, SERIAL, FDDI, POS);
+ private static final List FIBERINTERFACES = Arrays.asList(FDDI, POS);
+
+
+ private TextBlockParserCisco() {
+ //not called
+ }
+
+ /**
+ * Adding information in an array for CiscoIosDeviceDescriptin call.
+ * @param version the return of show version command
+ * @return the array with the information
+ */
+ static String[] parseCiscoIosDeviceDetails(String version) {
+ String[] details = new String[4];
+ details[0] = getManufacturer(version);
+ details[1] = getHwVersion(version);
+ details[2] = getSwVersion(version);
+ details[3] = serialNumber(version);
+ return details;
+ }
+
+ /**
+ * Retrieving manufacturer of device.
+ * @param version the return of show version command
+ * @return the manufacturer of the device
+ */
+ private static String getManufacturer(String version) {
+ int i;
+ String[] textStr = version.split(NEWLINE_SPLITTER);
+ String[] lineStr = textStr[0].trim().split(SPACE);
+ return lineStr[0];
+ }
+
+ /**
+ * Retrieving hardware version of device.
+ * @param version the return of show version command
+ * @return the hardware version of the device
+ */
+ private static String getHwVersion(String version) {
+ String[] textStr = version.split(NEWLINE_SPLITTER);
+ String processor = SPACE;
+ int i;
+ for (i = 0; i < textStr.length; i++) {
+ if (textStr[i].indexOf(PHRASE) > 0) {
+ String[] lineStr = textStr[i].trim().split(SPACE);
+ processor = lineStr[1];
+ break;
+ } else {
+ processor = SPACE;
+ }
+ }
+ return processor;
+ }
+
+ /**
+ * Retrieving software version of device.
+ * @param version the return of show version command
+ * @return the software version of the device
+ */
+ private static String getSwVersion(String version) {
+ String[] textStr = version.split(NEWLINE_SPLITTER);
+ int i;
+ for (i = 0; i < textStr.length; i++) {
+ if (textStr[i].indexOf(VERSION) > 0) {
+ break;
+ }
+ }
+ String[] lineStr = textStr[i].trim().split(SPACE);
+ StringBuilder sw = new StringBuilder();
+ for (int j = 0; j < lineStr.length; j++) {
+ if (lineStr[j].equals(EOF_VERSION1) || lineStr[j].equals(EOF_VERSION2)
+ ) {
+ sw.append(lineStr[j - 1]).append(SPACE);
+ } else if (lineStr[j].equals(EOF_VERSION3)) {
+ sw.append(lineStr[j - 1]);
+ sw.setLength(sw.length() - 1);
+ }
+ }
+ return sw.toString();
+ }
+
+ /**
+ * Retrieving serial number of device.
+ * @param version the return of show version command
+ * @return the serial number of the device
+ */
+ private static String serialNumber(String version) {
+ String[] textStr = version.split(NEWLINE_SPLITTER);
+ int i;
+ for (i = 0; i < textStr.length; i++) {
+ if (textStr[i].indexOf(PROCESSOR_BOARD) > 0) {
+ break;
+ }
+ }
+ return textStr[i].substring(textStr[i].indexOf(PROCESSOR_BOARD) + PROCESSOR_BOARD.length(),
+ textStr[i].length());
+ }
+
+ /**
+ * Calls methods to create information about Ports.
+ * @param interfacesReply the interfaces as plain text
+ * @return the Port description list
+ */
+ public static List<PortDescription> parseCiscoIosPorts(String interfacesReply) {
+ String parentInterface;
+ String[] parentArray;
+ String tempString;
+ List<PortDescription> portDesc = Lists.newArrayList();
+ int interfacesCounter = interfacesCounterMethod(interfacesReply);
+ for (int i = 0; i < interfacesCounter; i++) {
+ parentInterface = parentInterfaceMethod(interfacesReply);
+ portDesc.add(findPortInfo(parentInterface));
+ parentArray = parentInterface.split(SPACE);
+ tempString = parentArray[0] + SPACE;
+ interfacesReply = interfacesReply.replace(tempString, SPACE + tempString);
+ }
+ return portDesc;
+ }
+
+ /**
+ * Creates the port information object.
+ * @param interfaceTree the interfaces as plain text
+ * @return the Port description object
+ */
+ private static DefaultPortDescription findPortInfo(String interfaceTree) {
+ String[] textStr = interfaceTree.split(NEWLINE_SPLITTER);
+ String[] firstLine = textStr[0].split(SPACE);
+ String firstWord = firstLine[0];
+ Type type = getPortType(textStr);
+ boolean isEnabled = getIsEnabled(textStr);
+ String port = getPort(textStr);
+ long portSpeed = getPortSpeed(textStr);
+ DefaultAnnotations.Builder annotations = DefaultAnnotations.builder()
+ .set(AnnotationKeys.PORT_NAME, firstWord);
+ return "-1".equals(port) ? null : new DefaultPortDescription(PortNumber.portNumber(port),
+ isEnabled, type, portSpeed, annotations.build());
+ }
+
+ /**
+ * Counts the number of existing interfaces.
+ * @param interfacesReply the interfaces as plain text
+ * @return interfaces counter
+ */
+ private static int interfacesCounterMethod(String interfacesReply) {
+ int counter;
+ String first3Characters;
+ String[] textStr = interfacesReply.split(NEWLINE_SPLITTER);
+ int lastLine = textStr.length - 1;
+ counter = 0;
+ for (int i = 1; i < lastLine; i++) {
+ first3Characters = textStr[i].substring(0, 3);
+ if (INTERFACES.contains(first3Characters)) {
+ counter++;
+ }
+ }
+ return counter;
+ }
+
+ /**
+ * Parses the text and seperates to Parent Interfaces.
+ * @param interfacesReply the interfaces as plain text
+ * @return Parent interface
+ */
+ private static String parentInterfaceMethod(String interfacesReply) {
+ String firstCharacter;
+ String first3Characters;
+ boolean isChild = false;
+ StringBuilder anInterface = new StringBuilder("");
+ String[] textStr = interfacesReply.split("\\n");
+ int lastLine = textStr.length - 1;
+ for (int i = 1; i < lastLine; i++) {
+ firstCharacter = textStr[i].substring(0, 1);
+ first3Characters = textStr[i].substring(0, 3);
+ if (!(firstCharacter.equals(SPACE)) && isChild) {
+ break;
+ } else if (firstCharacter.equals(SPACE) && isChild) {
+ anInterface.append(textStr[i]).append(NEWLINE_SPLITTER);
+ } else if (INTERFACES.contains(first3Characters)) {
+ isChild = true;
+ anInterface.append(textStr[i]).append(NEWLINE_SPLITTER);
+ }
+ }
+ return anInterface.toString();
+ }
+
+ /**
+ * Get the port type for an interface.
+ * @param textStr interface splitted as an array
+ * @return Port type
+ */
+ private static Type getPortType(String[] textStr) {
+ String first3Characters;
+ first3Characters = textStr[0].substring(0, 3);
+ return FIBERINTERFACES.contains(first3Characters) ? Type.FIBER : Type.COPPER;
+ }
+
+ /**
+ * Get the state for an interface.
+ * @param textStr interface splitted as an array
+ * @return isEnabled state
+ */
+ private static boolean getIsEnabled(String[] textStr) {
+ return textStr[0].contains(IS_UP);
+ }
+
+ /**
+ * Get the port number for an interface.
+ * @param textStr interface splitted as an array
+ * @return port number
+ */
+ private static String getPort(String[] textStr) {
+ String port;
+ try {
+ if (textStr[0].indexOf(PORT_DELIMITER) > 0) {
+ port = textStr[0].substring(textStr[0].lastIndexOf(PORT_DELIMITER) + 1,
+ textStr[0].indexOf(SPACE));
+ } else {
+ port = "-1";
+ }
+ } catch (RuntimeException e) {
+ port = "-1";
+ }
+ return port;
+ }
+
+ /**
+ * Get the port speed for an interface.
+ * @param textStr interface splitted as an array
+ * @return port speed
+ */
+ private static long getPortSpeed(String[] textStr) {
+ long portSpeed = 0;
+ String result;
+ int lastLine = textStr.length - 1;
+ for (int i = 0; i < lastLine; i++) {
+ if ((textStr[i].indexOf(BANDWIDTH) > 0) && (textStr[i].indexOf(SPEED) > 0)) {
+ result = textStr[i].substring(textStr[i].indexOf(BANDWIDTH) + 3, textStr[i].indexOf(SPEED));
+ portSpeed = Long.valueOf(result);
+ break;
+ }
+ }
+ return portSpeed;
+ }
+
+}
\ No newline at end of file
diff --git a/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/XmlParserCisco.java b/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/XmlParserCisco.java
new file mode 100644
index 0000000..9ab9c55
--- /dev/null
+++ b/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/XmlParserCisco.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2016-present 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.drivers.cisco;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.device.DefaultDeviceInterfaceDescription;
+import org.onosproject.net.device.DeviceInterfaceDescription;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Parser for Netconf XML configurations and replies from Cisco devices.
+ */
+public final class XmlParserCisco {
+
+ private static final String TRUNK_MODE_KEY =
+ "ConfigIf-Configuration.switchport.mode.trunk";
+ private static final String ACCESS_KEY =
+ "ConfigIf-Configuration.switchport.access.vlan.VLANIDVLANPortAccessMode";
+ private static final String TRUNK_VLAN_KEY =
+ "ConfigIf-Configuration.switchport.trunk.allowed.vlan.VLANIDsAllowedVLANsPortTrunkingMode";
+ private static final String RATE_LIMIT_KEY =
+ "ConfigIf-Configuration.srr-queue.bandwidth.limit.EnterBandwidthLimitInterfaceAsPercentage";
+ private static final short NO_LIMIT = -1;
+
+ private XmlParserCisco() {
+ // Not to be called.
+ }
+
+ /**
+ * Parses device configuration and returns the descriptions of the device
+ * interfaces.
+ *
+ * @param cfg an hierarchical configuration
+ * @return list of interface descriptions for the device
+ */
+
+ public static List<DeviceInterfaceDescription> getInterfacesFromConfig(
+ HierarchicalConfiguration cfg) {
+ List<DeviceInterfaceDescription> intfs = Lists.newArrayList();
+ List<HierarchicalConfiguration> subtrees =
+ cfg.configurationsAt("data.xml-config-data.Device-Configuration.interface");
+ for (HierarchicalConfiguration intfConfig :subtrees) {
+ String intfName = getInterfaceName(intfConfig);
+ DeviceInterfaceDescription.Mode intfMode = getInterfaceMode(intfConfig);
+ List<VlanId> intfVlans = getInterfaceVlans(intfConfig, intfMode);
+ short intfLimit = getInterfaceLimit(intfConfig);
+ boolean intfLimited = (intfLimit == NO_LIMIT ? false : true);
+ DeviceInterfaceDescription intf =
+ new DefaultDeviceInterfaceDescription(intfName,
+ intfMode,
+ intfVlans,
+ intfLimited,
+ intfLimit);
+ intfs.add(intf);
+ }
+ return intfs;
+ }
+
+ private static String getInterfaceName(HierarchicalConfiguration intfConfig) {
+ return intfConfig.getString("Param");
+ }
+
+ private static DeviceInterfaceDescription.Mode
+ getInterfaceMode(HierarchicalConfiguration intfConfig) {
+ if (intfConfig.containsKey(TRUNK_MODE_KEY)) {
+ return DeviceInterfaceDescription.Mode.TRUNK;
+ } else if (intfConfig.containsKey(ACCESS_KEY)) {
+ return DeviceInterfaceDescription.Mode.ACCESS;
+ } else {
+ return DeviceInterfaceDescription.Mode.NORMAL;
+ }
+ }
+
+ private static List<VlanId> getInterfaceVlans(
+ HierarchicalConfiguration intfConfig,
+ DeviceInterfaceDescription.Mode mode) {
+ List<VlanId> vlans = Lists.newArrayList();
+ if (mode == DeviceInterfaceDescription.Mode.ACCESS) {
+ vlans.add(getVlanForAccess(intfConfig));
+ } else if (mode == DeviceInterfaceDescription.Mode.TRUNK) {
+ vlans.addAll(getVlansForTrunk(intfConfig));
+ }
+ return vlans;
+ }
+
+ private static VlanId getVlanForAccess(HierarchicalConfiguration intfConfig) {
+ if (intfConfig.containsKey(ACCESS_KEY)) {
+ return VlanId.vlanId(intfConfig.getString(ACCESS_KEY));
+ }
+ return null;
+ }
+
+ private static List<VlanId> getVlansForTrunk(HierarchicalConfiguration intfConfig) {
+ if (intfConfig.containsKey(TRUNK_VLAN_KEY)) {
+ return parseVlans(intfConfig.getStringArray(TRUNK_VLAN_KEY));
+ }
+ return null;
+ }
+
+ private static List<VlanId> parseVlans(String[] vlansString) {
+ List<VlanId> vlans = Lists.newArrayList();
+ List<String> items = Arrays.asList(vlansString);
+ for (String item: items) {
+ int index = item.indexOf("-");
+ if (index == -1) {
+ // Not a range o values
+ vlans.add(VlanId.vlanId(item));
+ } else {
+ // A range of values separated with "-"
+ short lowerVlan = Short.parseShort(item.substring(0, index));
+ short higherVlan = Short.parseShort(item.substring(index + 1));
+ for (short i = lowerVlan; i <= higherVlan; i++) {
+ vlans.add(VlanId.vlanId(i));
+ }
+ }
+ }
+ return vlans;
+ }
+
+ private static short getInterfaceLimit(HierarchicalConfiguration intfConfig) {
+ if (intfConfig.containsKey(RATE_LIMIT_KEY)) {
+ return intfConfig.getShort(RATE_LIMIT_KEY);
+ }
+ return NO_LIMIT;
+ }
+}
diff --git a/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/package-info.java b/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/package-info.java
new file mode 100644
index 0000000..69e4e09
--- /dev/null
+++ b/drivers/cisco/netconf/src/main/java/org/onosproject/drivers/cisco/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present 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 for Cisco device drivers.
+ */
+package org.onosproject.drivers.cisco;
\ No newline at end of file
diff --git a/drivers/cisco/netconf/src/main/resources/cisco-drivers.xml b/drivers/cisco/netconf/src/main/resources/cisco-drivers.xml
new file mode 100644
index 0000000..2c5e16b
--- /dev/null
+++ b/drivers/cisco/netconf/src/main/resources/cisco-drivers.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2016-present 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.
+ -->
+<drivers>
+ <driver name="cisco-netconf" extends="netconf" manufacturer="Cisco"
+ hwVersion="" swVersion="IOS">
+ <behaviour api="org.onosproject.net.behaviour.InterfaceConfig"
+ impl="org.onosproject.drivers.cisco.InterfaceConfigCiscoIosImpl"/>
+ <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
+ impl="org.onosproject.drivers.cisco.CiscoIosDeviceDescription"/>
+ </driver>
+</drivers>
diff --git a/drivers/cisco/netconf/src/test/java/org/onosproject/drivers/cisco/CiscoDriversLoaderTest.java b/drivers/cisco/netconf/src/test/java/org/onosproject/drivers/cisco/CiscoDriversLoaderTest.java
new file mode 100644
index 0000000..e087e42
--- /dev/null
+++ b/drivers/cisco/netconf/src/test/java/org/onosproject/drivers/cisco/CiscoDriversLoaderTest.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2016-present 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.drivers.cisco;
+
+import org.junit.Before;
+import org.onosproject.net.driver.AbstractDriverLoaderTest;
+
+
+/**
+ * Cisco drivers loader test.
+ */
+public class CiscoDriversLoaderTest extends AbstractDriverLoaderTest {
+
+ @Before
+ public void setUp() {
+ loader = new CiscoDriversLoader();
+ }
+}
diff --git a/drivers/cisco/netconf/src/test/java/org/onosproject/drivers/cisco/TextBlockParserCiscoTest.java b/drivers/cisco/netconf/src/test/java/org/onosproject/drivers/cisco/TextBlockParserCiscoTest.java
new file mode 100644
index 0000000..321704f
--- /dev/null
+++ b/drivers/cisco/netconf/src/test/java/org/onosproject/drivers/cisco/TextBlockParserCiscoTest.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2016-present 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.drivers.cisco;
+
+
+import org.junit.Test;
+import org.onlab.packet.ChassisId;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DefaultDevice;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.provider.ProviderId;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.net.Device.Type.SWITCH;
+import static org.onosproject.net.DeviceId.deviceId;
+
+
+/**
+ * Tests the parser for Netconf TextBlock configurations and replies from Cisco devices.
+ */
+public class TextBlockParserCiscoTest {
+
+ private static final PortNumber INTF1_PORT = PortNumber.portNumber(0);
+ private static final String INTF1_NAME = "FastEthernet0/0";
+ private static final PortNumber INTF2_PORT = PortNumber.portNumber(0);
+ private static final String INTF2_NAME = "Ethernet1/0";
+ private static final PortNumber INTF3_PORT = PortNumber.portNumber(0);
+ private static final String INTF3_NAME = "GigabitEthernet2/0";
+ private static final PortNumber INTF4_PORT = PortNumber.portNumber(0);
+ private static final String INTF4_NAME = "Serial3/0";
+ private static final PortNumber INTF5_PORT = PortNumber.portNumber(0);
+ private static final String INTF5_NAME = "POS4/0";
+ private static final PortNumber INTF6_PORT = PortNumber.portNumber(0);
+ private static final String INTF6_NAME = "Fddi5/0";
+ private static final Port.Type COPPER = Port.Type.COPPER;
+ private static final Port.Type FIBER = Port.Type.FIBER;
+ private static final long CONNECTION_SPEED_ETHERNET = 100000;
+ private static final long CONNECTION_SPEED_SERIAL = 1544;
+ private static final long CONNECTION_SPEED_POS = 9952000;
+ private static final long CONNECTION_SPEED_FDDI = 100000;
+ private static final boolean IS_ENABLED = true;
+ private static final boolean IS_NOT_ENABLED = false;
+ private static final String SHOW_VERSION = "/testShowVersion.xml";
+ private static final String SHOW_INTFS = "/testShowInterfaces.xml";
+ private static final String SW = "IOS C3560E 15.0(2)EJ";
+ private static final String HW = "SM-X-ES3-24-P";
+ private static final String MFR = "Cisco";
+ private static final String SN = "FOC18401Z3R";
+ private static final ProviderId PROVIDERID = new ProviderId("of", "foo");
+ private static final DeviceId DEVICE = deviceId("of:foo");
+ private static final ChassisId CID = new ChassisId();
+
+ @Test
+ public void controllersVersion() {
+ InputStream streamOrig = getClass().getResourceAsStream(SHOW_VERSION);
+ String version = new Scanner(streamOrig, "UTF-8").useDelimiter("\\Z").next();
+ version = version.substring(version.indexOf('\n') + 1);
+ String[] actualDetails = TextBlockParserCisco.parseCiscoIosDeviceDetails(version);
+
+ assertEquals("Information could not be retrieved",
+ getExpectedInfo(), actualInfo(actualDetails));
+ }
+
+ @Test
+ public void controllersIntfs() {
+ InputStream streamOrig = getClass().getResourceAsStream(SHOW_INTFS);
+ String rpcReply = new Scanner(streamOrig, "UTF-8").useDelimiter("\\Z").next();
+ List<PortDescription> actualIntfs = TextBlockParserCisco.parseCiscoIosPorts(rpcReply);
+ assertEquals("Information could not be retrieved",
+ getExpectedIntfs(), actualIntfs);
+ }
+
+ private DefaultDevice getExpectedInfo() {
+ return new DefaultDevice(PROVIDERID, DEVICE, SWITCH, MFR, HW, SW, SN, CID);
+ }
+
+ private DefaultDevice actualInfo(String[] actualDetails) {
+
+ return new DefaultDevice(PROVIDERID, DEVICE, SWITCH, actualDetails[0],
+ actualDetails[1], actualDetails[2],
+ actualDetails[3], CID);
+ }
+
+ private List<PortDescription> getExpectedIntfs() {
+ DefaultAnnotations.Builder int1Annotations = DefaultAnnotations.builder()
+ .set(AnnotationKeys.PORT_NAME, INTF1_NAME);
+ DefaultAnnotations.Builder int2Annotations = DefaultAnnotations.builder()
+ .set(AnnotationKeys.PORT_NAME, INTF2_NAME);
+ DefaultAnnotations.Builder int3Annotations = DefaultAnnotations.builder()
+ .set(AnnotationKeys.PORT_NAME, INTF3_NAME);
+ DefaultAnnotations.Builder int4Annotations = DefaultAnnotations.builder()
+ .set(AnnotationKeys.PORT_NAME, INTF4_NAME);
+ DefaultAnnotations.Builder int5Annotations = DefaultAnnotations.builder()
+ .set(AnnotationKeys.PORT_NAME, INTF5_NAME);
+ DefaultAnnotations.Builder int6Annotations = DefaultAnnotations.builder()
+ .set(AnnotationKeys.PORT_NAME, INTF6_NAME);
+
+ List<PortDescription> intfs = new ArrayList<>();
+ intfs.add(new DefaultPortDescription(INTF1_PORT, IS_ENABLED, COPPER, CONNECTION_SPEED_ETHERNET,
+ int1Annotations.build()));
+ intfs.add(new DefaultPortDescription(INTF2_PORT, IS_NOT_ENABLED, COPPER, CONNECTION_SPEED_ETHERNET,
+ int2Annotations.build()));
+ intfs.add(new DefaultPortDescription(INTF3_PORT, IS_NOT_ENABLED, COPPER, CONNECTION_SPEED_ETHERNET,
+ int3Annotations.build()));
+ intfs.add(new DefaultPortDescription(INTF4_PORT, IS_ENABLED, COPPER, CONNECTION_SPEED_SERIAL,
+ int4Annotations.build()));
+ intfs.add(new DefaultPortDescription(INTF5_PORT, IS_ENABLED, FIBER, CONNECTION_SPEED_POS,
+ int5Annotations.build()));
+ intfs.add(new DefaultPortDescription(INTF6_PORT, IS_ENABLED, FIBER, CONNECTION_SPEED_FDDI,
+ int6Annotations.build()));
+ return intfs;
+ }
+
+}
diff --git a/drivers/cisco/netconf/src/test/java/org/onosproject/drivers/cisco/XmlParserCiscoTest.java b/drivers/cisco/netconf/src/test/java/org/onosproject/drivers/cisco/XmlParserCiscoTest.java
new file mode 100644
index 0000000..f9eaf7f
--- /dev/null
+++ b/drivers/cisco/netconf/src/test/java/org/onosproject/drivers/cisco/XmlParserCiscoTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2016-present 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.drivers.cisco;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.junit.Test;
+import org.onlab.packet.VlanId;
+import org.onosproject.drivers.utilities.XmlConfigParser;
+import org.onosproject.net.device.DefaultDeviceInterfaceDescription;
+import org.onosproject.net.device.DeviceInterfaceDescription;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the parser for Netconf XML configurations and replies from Cisco devices.
+ */
+public class XmlParserCiscoTest {
+
+ private static final String INTF_NAME_1 = "GigabitEthernet0/1";
+ private static final String INTF_NAME_2 = "GigabitEthernet0/2";
+ private static final String INTF_NAME_3 = "GigabitEthernet0/3";
+ private static final String INTF_NAME_4 = "GigabitEthernet0/4";
+ private static final String INTF_NAME_5 = "GigabitEthernet0/5";
+ private static final VlanId ACCESS_VLAN = VlanId.vlanId((short) 100);
+ private static final VlanId TRUNK_VLAN_1 = VlanId.vlanId((short) 200);
+ private static final VlanId TRUNK_VLAN_2 = VlanId.vlanId((short) 201);
+ private static final VlanId TRUNK_VLAN_3 = VlanId.vlanId((short) 300);
+ private static final VlanId TRUNK_VLAN_4 = VlanId.vlanId((short) 301);
+ private static final VlanId TRUNK_VLAN_5 = VlanId.vlanId((short) 302);
+ private static final short NO_RATE_LIMIT = -1;
+ private static final short RATE_LIMIT_1 = 75;
+ private static final short RATE_LIMIT_2 = 50;
+ private static final boolean NO_LIMIT = false;
+ private static final boolean WITH_LIMIT = true;
+ private static final String CONFIG_XML_FILE = "/testGetConfig.xml";
+
+ @Test
+ public void controllersConfig() {
+ InputStream streamOrig = getClass().getResourceAsStream(CONFIG_XML_FILE);
+ HierarchicalConfiguration cfgOrig = XmlConfigParser.loadXml(streamOrig);
+ List<DeviceInterfaceDescription> actualIntfs =
+ XmlParserCisco.getInterfacesFromConfig(cfgOrig);
+ assertEquals("Interfaces were not retrieved from configuration",
+ getExpectedIntfs(), actualIntfs);
+ }
+
+ private List<DeviceInterfaceDescription> getExpectedIntfs() {
+ List<DeviceInterfaceDescription> intfs = new ArrayList<>();
+ intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_1,
+ DeviceInterfaceDescription.Mode.NORMAL,
+ Lists.newArrayList(),
+ NO_LIMIT,
+ NO_RATE_LIMIT));
+
+ List<VlanId> accessList = new ArrayList<>();
+ accessList.add(ACCESS_VLAN);
+ intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_2,
+ DeviceInterfaceDescription.Mode.ACCESS,
+ accessList,
+ NO_LIMIT,
+ NO_RATE_LIMIT));
+
+ List<VlanId> trunkList1 = new ArrayList<>();
+ trunkList1.add(TRUNK_VLAN_1);
+ trunkList1.add(TRUNK_VLAN_2);
+ intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_3,
+ DeviceInterfaceDescription.Mode.TRUNK,
+ trunkList1,
+ NO_LIMIT,
+ NO_RATE_LIMIT));
+
+ intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_4,
+ DeviceInterfaceDescription.Mode.NORMAL,
+ Lists.newArrayList(),
+ WITH_LIMIT,
+ RATE_LIMIT_1));
+
+ List<VlanId> trunkList2 = new ArrayList<>();
+ trunkList2.add(TRUNK_VLAN_3);
+ trunkList2.add(TRUNK_VLAN_4);
+ trunkList2.add(TRUNK_VLAN_5);
+ intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_5,
+ DeviceInterfaceDescription.Mode.TRUNK,
+ trunkList2,
+ WITH_LIMIT,
+ RATE_LIMIT_2));
+ return intfs;
+ }
+}
\ No newline at end of file
diff --git a/drivers/cisco/netconf/src/test/resources/CiscoIosInterfaces.xml b/drivers/cisco/netconf/src/test/resources/CiscoIosInterfaces.xml
new file mode 100644
index 0000000..2519de2
--- /dev/null
+++ b/drivers/cisco/netconf/src/test/resources/CiscoIosInterfaces.xml
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?><rpc-reply message-id="7" xmlns="urn:ietf:params:netconf:base:1.0"><data><cli-oper-data-block><item><show>interfaces</show><response>
+FastEthernet0/0 is up, line protocol is up
+ Hardware is i82543 (Livengood), address is ca00.12b5.0008 (bia ca00.12b5.0008)
+ Internet address is 192.168.1.20/24
+ MTU 1500 bytes, BW 100000 Kbit/sec, DLY 100 usec,
+ reliability 255/255, txload 1/255, rxload 1/255
+ Encapsulation ARPA, loopback not set
+ Keepalive set (10 sec)
+ Full-duplex, 100Mb/s, 100BaseTX/FX
+ ARP type: ARPA, ARP Timeout 04:00:00
+ Last input 00:00:00, output 00:00:00, output hang never
+ Last clearing of "show interface" counters never
+ Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
+ Queueing strategy: fifo
+ Output queue: 0/40 (size/max)
+ 5 minute input rate 2000 bits/sec, 1 packets/sec
+ 5 minute output rate 0 bits/sec, 0 packets/sec
+ 3589 packets input, 681498 bytes
+ Received 2459 broadcasts, 0 runts, 0 giants, 0 throttles
+ 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
+ 0 watchdog
+ 0 input packets with dribble condition detected
+ 2518 packets output, 242991 bytes, 0 underruns
+ 0 output errors, 0 collisions, 2 interface resets
+ 149 unknown protocol drops
+ 0 babbles, 0 late collision, 0 deferred
+ 0 lost carrier, 0 no carrier
+ 0 output buffer failures, 0 output buffers swapped out
+Ethernet1/0 is administratively down, line protocol is down
+ Hardware is i82543 (Livengood), address is ca00.12b5.0006 (bia ca00.12b5.0006)
+ MTU 1500 bytes, BW 100000 Kbit/sec, DLY 100 usec,
+ reliability 255/255, txload 1/255, rxload 1/255
+ Encapsulation ARPA, loopback not set
+ Keepalive set (10 sec)
+ Full-duplex, 100Mb/s, 100BaseTX/FX
+ ARP type: ARPA, ARP Timeout 04:00:00
+ Last input never, output never, output hang never
+ Last clearing of "show interface" counters never
+ Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
+ Queueing strategy: fifo
+ Output queue: 0/40 (size/max)
+ 5 minute input rate 0 bits/sec, 0 packets/sec
+ 5 minute output rate 0 bits/sec, 0 packets/sec
+ 0 packets input, 0 bytes
+ Received 0 broadcasts, 0 runts, 0 giants, 0 throttles
+ 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
+ 0 watchdog
+ 0 input packets with dribble condition detected
+ 0 packets output, 0 bytes, 0 underruns
+ 0 output errors, 0 collisions, 0 interface resets
+ 0 unknown protocol drops
+ 0 babbles, 0 late collision, 0 deferred
+ 0 lost carrier, 0 no carrier
+ 0 output buffer failures, 0 output buffers swapped out
+GigabitEthernet2/0 is administratively down, line protocol is down
+ Hardware is i82543 (Livengood), address is ca00.12b5.0006 (bia ca00.12b5.0006)
+ MTU 1500 bytes, BW 100000 Kbit/sec, DLY 100 usec,
+ reliability 255/255, txload 1/255, rxload 1/255
+ Encapsulation ARPA, loopback not set
+ Keepalive set (10 sec)
+ Full-duplex, 100Mb/s, 100BaseTX/FX
+ ARP type: ARPA, ARP Timeout 04:00:00
+ Last input never, output never, output hang never
+ Last clearing of "show interface" counters never
+ Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
+ Queueing strategy: fifo
+ Output queue: 0/40 (size/max)
+ 5 minute input rate 0 bits/sec, 0 packets/sec
+ 5 minute output rate 0 bits/sec, 0 packets/sec
+ 0 packets input, 0 bytes
+ Received 0 broadcasts, 0 runts, 0 giants, 0 throttles
+ 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
+ 0 watchdog
+ 0 input packets with dribble condition detected
+ 0 packets output, 0 bytes, 0 underruns
+ 0 output errors, 0 collisions, 0 interface resets
+ 0 unknown protocol drops
+ 0 babbles, 0 late collision, 0 deferred
+ 0 lost carrier, 0 no carrier
+ 0 output buffer failures, 0 output buffers swapped out
+Serial3/0 is up, line protocol is up
+ Hardware is MCI Serial
+ Internet address is 192.168.10.203, subnet mask is 255.255.255.0
+ MTU 1500 bytes, BW 1544 Kbit/sec, DLY 20000 usec, rely 255/255, load 1/255
+ Encapsulation HDLC, loopback not set, keepalive set (10 sec)
+ Last input 0:00:07, output 0:00:00, output hang never
+ Output queue 0/40, 0 drops; input queue 0/75, 0 drops
+ 5 minute input rate 0 bits/sec, 0 packets/sec
+ 5 minute output rate 0 bits/sec, 0 packets/sec
+ 16263 packets input, 1347238 bytes, 0 no buffer
+ Received 13983 broadcasts, 0 runts, 0 giants
+ 2 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 2 abort
+ 1 carrier transitions
+ 22146 packets output, 2383680 bytes, 0 underruns
+ 0 output errors, 0 collisions, 2 interface resets, 0 restarts
+POS4/0 is up, line protocol is up
+ Hardware is Packet over SONET
+ Internet address is 10.41.41.2/24
+ MTU 4470 bytes, BW 9952000 Kbit/sec, DLY 100 usec, rely 255/255, load 1/255
+ Encapsulation HDLC, crc 32, loopback not set
+ Keepalive not set
+ Scramble enabled
+ Last input 00:00:59, output 00:00:11, output hang never
+ Last clearing of "show interface" counters 00:00:14
+ Queueing strategy: fifo
+ Output queue 0/40, 0 drops; input queue 0/75, 0 drops
+ Available Bandwidth 9582482 kilobits/sec
+ 5 minute input rate 0 bits/sec, 0 packets/sec
+ 5 minute output rate 0 bits/sec, 0 packets/sec
+ 0 packets input, 0 bytes, 0 no buffer
+ Received 0 broadcasts, 0 runts, 0 giants, 0 throttles
+ 0 parity
+ 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
+ 1 packets output, 314 bytes, 0 underruns
+ 0 output errors, 0 applique, 0 interface resets
+ 0 output buffer failures, 0 output buffers swapped out
+ 0 carrier transitions
+Fddi5/0 is up, line protocol is up
+ Hardware is cxBus Fddi, address is 0000.0c02.adf1 (bia 0000.0c02.adf1)
+ Internet address is 10.108.33.14, subnet mask is 255.255.255.0
+ MTU 4470 bytes, BW 100000 Kbit/sec, DLY 100 usec, rely 255/255, load 1/255
+ Encapsulation SNAP, loopback not set, keepalive not set
+ ARP type: SNAP, ARP Timeout 4:00:00
+ Phy-A state is active, neighbor is B, cmt signal bits 008/20C, status ILS
+ Phy-B state is active, neighbor is A, cmt signal bits 20C/008, status ILS
+ ECM is in, CFM is thru, RMT is ring_op
+ Token rotation 5000 usec, ring operational 21:32:34
+ Upstream neighbor 0000.0c02.ba83, downstream neighbor 0000.0c02.ba83
+ Last input 0:00:05, output 0:00:00, output hang never
+ Last clearing of “show interface” counters 0:59:10
+ Output queue 0/40, 0 drops; input queue 0/75, 0 drops
+ 5 minute input rate 69000 bits/sec, 44 packets/sec
+ 5 minute output rate 0 bits/sec, 1 packets/sec
+ 113157 packets input, 21622582 bytes, 0 no buffer
+ Received 276 broadcasts, 0 runts, 0 giants
+ 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
+ 4740 packets output, 487346 bytes, 0 underruns
+ 0 output errors, 0 collisions, 0 interface resets, 0 restarts
+ 0 transitions, 2 traces, 3 claims, 2 beacons</response></item></cli-oper-data-block></data></rpc-reply>]]>]]>
\ No newline at end of file
diff --git a/drivers/cisco/netconf/src/test/resources/testGetConfig.xml b/drivers/cisco/netconf/src/test/resources/testGetConfig.xml
new file mode 100644
index 0000000..349a032
--- /dev/null
+++ b/drivers/cisco/netconf/src/test/resources/testGetConfig.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2016-present 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.
+ -->
+ <rpc-reply message-id="101" xmlns="urn:ietf:params:netconf:base:1.0">
+ <data><xml-config-data><Device-Configuration xmlns="urn:cisco:xml-pi">
+ <version><Param>15.0</Param></version>
+ <service operation="delete" ><pad/></service>
+ <service><timestamps><debug><datetime><msec/></datetime></debug></timestamps></service>
+ <service><timestamps><log><datetime><msec/></datetime></log></timestamps></service>
+ <service operation="delete" ><password-encryption/></service>
+ <hostname><SystemNetworkName>switch02</SystemNetworkName></hostname>
+ <boot-start-marker></boot-start-marker>
+ <boot-end-marker></boot-end-marker>
+ <system><mtu><routing><MTUSizeBytes>1500</MTUSizeBytes></routing></mtu></system>
+ <mls><qos/></mls>
+ <cts operation="delete" ><server><test><all><enable/></all></test></server></cts>
+ <X-Interface>cts server test all idle-time 0</X-Interface>
+ <X-Interface>cts server test all deadtime 0</X-Interface>
+ <spanning-tree><mode><pvst/></mode></spanning-tree>
+ <spanning-tree><extend><system-id/></extend></spanning-tree>
+ <vlan><internal><allocation><policy><ascending/></policy></allocation></internal></vlan>
+ <lldp><run/></lldp>
+ <interface><Param>GigabitEthernet0/1</Param>
+ <ConfigIf-Configuration>
+ </ConfigIf-Configuration>
+ </interface>
+ <interface><Param>GigabitEthernet0/2</Param>
+ <ConfigIf-Configuration>
+ <switchport><access><vlan><VLANIDVLANPortAccessMode>100</VLANIDVLANPortAccessMode></vlan></access></switchport>
+ </ConfigIf-Configuration>
+ </interface>
+ <interface><Param>GigabitEthernet0/3</Param>
+ <ConfigIf-Configuration>
+ <switchport><trunk><encapsulation><dot1q/></encapsulation></trunk></switchport>
+ <switchport><trunk><allowed><vlan><VLANIDsAllowedVLANsPortTrunkingMode>200,201</VLANIDsAllowedVLANsPortTrunkingMode></vlan></allowed></trunk></switchport>
+ <switchport><mode><trunk/></mode></switchport>
+ </ConfigIf-Configuration>
+ </interface>
+ <interface><Param>GigabitEthernet0/4</Param>
+ <ConfigIf-Configuration>
+ <srr-queue><bandwidth><limit><EnterBandwidthLimitInterfaceAsPercentage>75</EnterBandwidthLimitInterfaceAsPercentage></limit></bandwidth></srr-queue>
+ </ConfigIf-Configuration>
+ </interface>
+ <interface><Param>GigabitEthernet0/5</Param>
+ <ConfigIf-Configuration>
+ <switchport><trunk><encapsulation><dot1q/></encapsulation></trunk></switchport>
+ <switchport><trunk><allowed><vlan><VLANIDsAllowedVLANsPortTrunkingMode>300-302</VLANIDsAllowedVLANsPortTrunkingMode></vlan></allowed></trunk></switchport>
+ <switchport><mode><trunk/></mode></switchport>
+ <srr-queue><bandwidth><limit><EnterBandwidthLimitInterfaceAsPercentage>50</EnterBandwidthLimitInterfaceAsPercentage></limit></bandwidth></srr-queue>
+ </ConfigIf-Configuration>
+ </interface>
+ <ip><http><server/></http></ip>
+ <ip><http><secure-server/></http></ip>
+ <netconf><max-sessions><MaxNETCONFSessions>5</MaxNETCONFSessions></max-sessions></netconf>
+ <netconf><lock-time><MaxNETCONFConfigLockTimeSeconds>120</MaxNETCONFConfigLockTimeSeconds></lock-time></netconf>
+ <netconf><ssh/></netconf>
+ <end></end>
+</Device-Configuration></xml-config-data></data></rpc-reply>
diff --git a/drivers/cisco/netconf/src/test/resources/testShowInterfaces.xml b/drivers/cisco/netconf/src/test/resources/testShowInterfaces.xml
new file mode 100644
index 0000000..b6c5400
--- /dev/null
+++ b/drivers/cisco/netconf/src/test/resources/testShowInterfaces.xml
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?><rpc-reply message-id="7" xmlns="urn:ietf:params:netconf:base:1.0"><data><cli-oper-data-block><item><show>interfaces</show><response>
+FastEthernet0/0 is up, line protocol is up
+ Hardware is i82543 (Livengood), address is ca00.12b5.0008 (bia ca00.12b5.0008)
+ Internet address is 192.168.1.20/24
+ MTU 1500 bytes, BW 100000 Kbit/sec, DLY 100 usec,
+ reliability 255/255, txload 1/255, rxload 1/255
+ Encapsulation ARPA, loopback not set
+ Keepalive set (10 sec)
+ Full-duplex, 100Mb/s, 100BaseTX/FX
+ ARP type: ARPA, ARP Timeout 04:00:00
+ Last input 00:00:00, output 00:00:00, output hang never
+ Last clearing of "show interface" counters never
+ Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
+ Queueing strategy: fifo
+ Output queue: 0/40 (size/max)
+ 5 minute input rate 2000 bits/sec, 1 packets/sec
+ 5 minute output rate 0 bits/sec, 0 packets/sec
+ 3589 packets input, 681498 bytes
+ Received 2459 broadcasts, 0 runts, 0 giants, 0 throttles
+ 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
+ 0 watchdog
+ 0 input packets with dribble condition detected
+ 2518 packets output, 242991 bytes, 0 underruns
+ 0 output errors, 0 collisions, 2 interface resets
+ 149 unknown protocol drops
+ 0 babbles, 0 late collision, 0 deferred
+ 0 lost carrier, 0 no carrier
+ 0 output buffer failures, 0 output buffers swapped out
+Ethernet1/0 is administratively down, line protocol is down
+ Hardware is i82543 (Livengood), address is ca00.12b5.0006 (bia ca00.12b5.0006)
+ MTU 1500 bytes, BW 100000 Kbit/sec, DLY 100 usec,
+ reliability 255/255, txload 1/255, rxload 1/255
+ Encapsulation ARPA, loopback not set
+ Keepalive set (10 sec)
+ Full-duplex, 100Mb/s, 100BaseTX/FX
+ ARP type: ARPA, ARP Timeout 04:00:00
+ Last input never, output never, output hang never
+ Last clearing of "show interface" counters never
+ Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
+ Queueing strategy: fifo
+ Output queue: 0/40 (size/max)
+ 5 minute input rate 0 bits/sec, 0 packets/sec
+ 5 minute output rate 0 bits/sec, 0 packets/sec
+ 0 packets input, 0 bytes
+ Received 0 broadcasts, 0 runts, 0 giants, 0 throttles
+ 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
+ 0 watchdog
+ 0 input packets with dribble condition detected
+ 0 packets output, 0 bytes, 0 underruns
+ 0 output errors, 0 collisions, 0 interface resets
+ 0 unknown protocol drops
+ 0 babbles, 0 late collision, 0 deferred
+ 0 lost carrier, 0 no carrier
+ 0 output buffer failures, 0 output buffers swapped out
+GigabitEthernet2/0 is administratively down, line protocol is down
+ Hardware is i82543 (Livengood), address is ca00.12b5.0006 (bia ca00.12b5.0006)
+ MTU 1500 bytes, BW 100000 Kbit/sec, DLY 100 usec,
+ reliability 255/255, txload 1/255, rxload 1/255
+ Encapsulation ARPA, loopback not set
+ Keepalive set (10 sec)
+ Full-duplex, 100Mb/s, 100BaseTX/FX
+ ARP type: ARPA, ARP Timeout 04:00:00
+ Last input never, output never, output hang never
+ Last clearing of "show interface" counters never
+ Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
+ Queueing strategy: fifo
+ Output queue: 0/40 (size/max)
+ 5 minute input rate 0 bits/sec, 0 packets/sec
+ 5 minute output rate 0 bits/sec, 0 packets/sec
+ 0 packets input, 0 bytes
+ Received 0 broadcasts, 0 runts, 0 giants, 0 throttles
+ 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
+ 0 watchdog
+ 0 input packets with dribble condition detected
+ 0 packets output, 0 bytes, 0 underruns
+ 0 output errors, 0 collisions, 0 interface resets
+ 0 unknown protocol drops
+ 0 babbles, 0 late collision, 0 deferred
+ 0 lost carrier, 0 no carrier
+ 0 output buffer failures, 0 output buffers swapped out
+Serial3/0 is up, line protocol is up
+ Hardware is MCI Serial
+ Internet address is 192.168.10.203, subnet mask is 255.255.255.0
+ MTU 1500 bytes, BW 1544 Kbit/sec, DLY 20000 usec, rely 255/255, load 1/255
+ Encapsulation HDLC, loopback not set, keepalive set (10 sec)
+ Last input 0:00:07, output 0:00:00, output hang never
+ Output queue 0/40, 0 drops; input queue 0/75, 0 drops
+ 5 minute input rate 0 bits/sec, 0 packets/sec
+ 5 minute output rate 0 bits/sec, 0 packets/sec
+ 16263 packets input, 1347238 bytes, 0 no buffer
+ Received 13983 broadcasts, 0 runts, 0 giants
+ 2 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 2 abort
+ 1 carrier transitions
+ 22146 packets output, 2383680 bytes, 0 underruns
+ 0 output errors, 0 collisions, 2 interface resets, 0 restarts
+POS4/0 is up, line protocol is up
+ Hardware is Packet over SONET
+ Internet address is 10.41.41.2/24
+ MTU 4470 bytes, BW 9952000 Kbit/sec, DLY 100 usec, rely 255/255, load 1/255
+ Encapsulation HDLC, crc 32, loopback not set
+ Keepalive not set
+ Scramble enabled
+ Last input 00:00:59, output 00:00:11, output hang never
+ Last clearing of "show interface" counters 00:00:14
+ Queueing strategy: fifo
+ Output queue 0/40, 0 drops; input queue 0/75, 0 drops
+ Available Bandwidth 9582482 kilobits/sec
+ 5 minute input rate 0 bits/sec, 0 packets/sec
+ 5 minute output rate 0 bits/sec, 0 packets/sec
+ 0 packets input, 0 bytes, 0 no buffer
+ Received 0 broadcasts, 0 runts, 0 giants, 0 throttles
+ 0 parity
+ 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
+ 1 packets output, 314 bytes, 0 underruns
+ 0 output errors, 0 applique, 0 interface resets
+ 0 output buffer failures, 0 output buffers swapped out
+ 0 carrier transitions
+Fddi5/0 is up, line protocol is up
+ Hardware is cxBus Fddi, address is 0000.0c02.adf1 (bia 0000.0c02.adf1)
+ Internet address is 10.108.33.14, subnet mask is 255.255.255.0
+ MTU 4470 bytes, BW 100000 Kbit/sec, DLY 100 usec, rely 255/255, load 1/255
+ Encapsulation SNAP, loopback not set, keepalive not set
+ ARP type: SNAP, ARP Timeout 4:00:00
+ Phy-A state is active, neighbor is B, cmt signal bits 008/20C, status ILS
+ Phy-B state is active, neighbor is A, cmt signal bits 20C/008, status ILS
+ ECM is in, CFM is thru, RMT is ring_op
+ Token rotation 5000 usec, ring operational 21:32:34
+ Upstream neighbor 0000.0c02.ba83, downstream neighbor 0000.0c02.ba83
+ Last input 0:00:05, output 0:00:00, output hang never
+ Last clearing of “show interface” counters 0:59:10
+ Output queue 0/40, 0 drops; input queue 0/75, 0 drops
+ 5 minute input rate 69000 bits/sec, 44 packets/sec
+ 5 minute output rate 0 bits/sec, 1 packets/sec
+ 113157 packets input, 21622582 bytes, 0 no buffer
+ Received 276 broadcasts, 0 runts, 0 giants
+ 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
+ 4740 packets output, 487346 bytes, 0 underruns
+ 0 output errors, 0 collisions, 0 interface resets, 0 restarts
+ 0 transitions, 2 traces, 3 claims, 2 beacons</response></item></cli-oper-data-block></data></rpc-reply>]]>]]>
\ No newline at end of file
diff --git a/drivers/cisco/netconf/src/test/resources/testShowVersion.xml b/drivers/cisco/netconf/src/test/resources/testShowVersion.xml
new file mode 100644
index 0000000..bfa2210
--- /dev/null
+++ b/drivers/cisco/netconf/src/test/resources/testShowVersion.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?><rpc-reply message-id="7" xmlns="urn:ietf:params:netconf:base:1.0"><data><cli-oper-data-block><item><show>hardware</show><response>
+ Cisco IOS Software, C3560E Software (C3560E-UNIVERSALK9-M), Version 15.0(2)EJ, RELEASE SOFTWARE (fc1)
+ Technical Support: http://www.cisco.com/techsupport
+ Copyright (c) 1986-2013 by Cisco Systems, Inc.
+ Compiled Fri 13-Sep-13 12:09 by prod_rel_team
+ ROM: Bootstrap program is C3560E boot loader
+ BOOTLDR: C3560E Boot Loader (C3560X-HBOOT-M) Version 15.0(2r)EJ1, RELEASE SOFTWARE (fc1)
+ switch01 uptime is 1 week, 3 days, 21 hours, 39 minutes
+ System returned to ROM by power-on
+ System restarted at 08:15:31 UTC Thu Apr 14 2016
+ System image file is "flash:/c3560e-universalk9-mz.150-2.EJ.bin"
+ This product contains cryptographic features and is subject to United
+ States and local country laws governing import, export, transfer and
+ use. Delivery of Cisco cryptographic products does not imply
+ third-party authority to import, export, distribute or use encryption.
+ Importers, exporters, distributors and users are responsible for
+ compliance with U.S. and local country laws. By using this product you
+ agree to comply with applicable laws and regulations. If you are unable
+ to comply with U.S. and local laws, return this product immediately.
+ A summary of U.S. laws governing Cisco cryptographic products may be found at:
+ http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
+ If you require further assistance please contact us by sending email to
+ export@cisco.com.
+ License Level: lanbase
+ License Type: Permanent
+ Next reload license Level: lanbase
+ cisco SM-X-ES3-24-P (PowerPC405) processor with 262144K bytes of memory.
+ Processor board ID FOC18401Z3R
+ Last reset from power-on
+ 2 Virtual Ethernet interfaces
+ 26 Gigabit Ethernet interfaces
+ The password-recovery mechanism is enabled.
+ 512K bytes of flash-simulated non-volatile configuration memory.
+ Base ethernet MAC Address : 68:99:CD:AA:2F:80
+ Model number : SM-X-ES3-24-P
+ System serial number : FOC18401Z3R
+ Hardware Board Revision Number : 0x00
+ Switch Ports Model SW Version SW Image
+ ------ ----- ----- ---------- ----------
+ * 1 26 SM-X-ES3-24-P 15.0(2)EJ C3560E-UNIVERSALK9-M
+</response></item></cli-oper-data-block></data></rpc-reply>]]>]]>