[ONOS-6529] Add Cisco REST device drivers

Change-Id: I97de0a7d326492a90d1541e5c028255f0b735aa0
diff --git a/drivers/cisco/rest/BUCK b/drivers/cisco/rest/BUCK
new file mode 100644
index 0000000..b4c5b11
--- /dev/null
+++ b/drivers/cisco/rest/BUCK
@@ -0,0 +1,35 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:javax.ws.rs-api',
+    '//incubator/api:onos-incubator-api',
+    '//utils/rest:onlab-rest',
+    '//drivers/utilities:onos-drivers-utilities',
+    '//protocols/rest/api:onos-protocols-rest-api',
+]
+
+TEST_DEPS = [
+    '//lib:TEST_ADAPTERS',
+    '//core/api:onos-api-tests',
+]
+
+BUNDLES = [
+    ':onos-drivers-cisco-rest',
+    '//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.rest',
+    title = 'Cisco REST device drivers',
+    category = 'Drivers',
+    url = 'http://onosproject.org',
+    description = 'ONOS Cisco REST device drivers application.',
+    included_bundles = BUNDLES,
+    required_apps = [ 'org.onosproject.restsb' ],
+)
diff --git a/drivers/cisco/rest/features.xml b/drivers/cisco/rest/features.xml
new file mode 100644
index 0000000..bc52359
--- /dev/null
+++ b/drivers/cisco/rest/features.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+  ~ 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.
+  -->
+<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}/${project.artifactId}/${project.version}</bundle>
+
+        <bundle>mvn:${project.groupId}/onos-drivers-utilities/${project.version}</bundle>
+        <bundle>mvn:${project.groupId}/onos-restsb-api/${project.version}</bundle>
+    </feature>
+</features>
diff --git a/drivers/cisco/rest/pom.xml b/drivers/cisco/rest/pom.xml
new file mode 100644
index 0000000..6fb2ebf
--- /dev/null
+++ b/drivers/cisco/rest/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-rest</artifactId>
+    <packaging>bundle</packaging>
+
+    <description>Cisco REST device drivers</description>
+
+    <properties>
+        <onos.app.name>org.onosproject.drivers.cisco.rest</onos.app.name>
+        <onos.app.origin>ON.Lab</onos.app.origin>
+        <onos.app.category>Drivers</onos.app.category>
+        <onos.app.title>Cisco REST Device Drivers</onos.app.title>
+        <onos.app.url>http://onosproject.org</onos.app.url>
+        <onos.app.requires>
+            org.onosproject.restsb
+        </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-restsb-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/drivers/cisco/rest/src/main/java/org/onosproject/drivers/cisco/rest/CiscoNxosDeviceDescription.java b/drivers/cisco/rest/src/main/java/org/onosproject/drivers/cisco/rest/CiscoNxosDeviceDescription.java
new file mode 100644
index 0000000..92a9b7f
--- /dev/null
+++ b/drivers/cisco/rest/src/main/java/org/onosproject/drivers/cisco/rest/CiscoNxosDeviceDescription.java
@@ -0,0 +1,155 @@
+/*
+ * 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.
+ */
+
+package org.onosproject.drivers.cisco.rest;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Lists;
+import org.onlab.packet.ChassisId;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.device.DefaultDeviceDescription;
+import org.onosproject.net.device.DefaultPortDescription;
+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.net.driver.DriverHandler;
+import org.onosproject.protocol.rest.RestSBController;
+import org.slf4j.Logger;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Discovers device information from a Cisco NXOS device.
+ */
+public class CiscoNxosDeviceDescription extends AbstractHandlerBehaviour
+        implements DeviceDescriptionDiscovery {
+    private final Logger log = getLogger(getClass());
+
+    private static final String UNKNOWN = "unknown";
+
+    private static final String SHOW_INTERFACES_CMD = "show interface";
+    private static final String SHOW_VERSION_CMD = "show version";
+
+    private static final String MANUFACTURER = "manufacturer";
+    private static final String CHASSIS_ID = "chassis_id";
+    private static final String KICKSTART_VER = "kickstart_ver_str";
+    private static final String ROW_INTERFACE = "ROW_interface";
+    private static final String INTERFACE = "interface";
+    private static final String ETH = "Eth";
+    private static final String ETHERNET = "Ethernet";
+    private static final String STATE = "state";
+    private static final String UP = "up";
+    private static final String ETH_BW = "eth_bw";
+    private static final String SLASH = "/";
+    private static final String ZERO = "0";
+    private static final int ONE_THOUSAND = 1000;
+
+
+    @Override
+    public DeviceDescription discoverDeviceDetails() {
+        DriverHandler handler = handler();
+        RestSBController controller = checkNotNull(handler.get(RestSBController.class));
+        DeviceId deviceId = handler.data().deviceId();
+
+        ArrayList<String> cmd = new ArrayList<>();
+        cmd.add(SHOW_VERSION_CMD);
+
+        String req = NxApiRequest.generate(cmd, NxApiRequest.CommandType.CLI);
+
+        String response = NxApiRequest.post(controller, deviceId, req);
+
+        String mrf = UNKNOWN;
+        String hwVer = UNKNOWN;
+        String swVer = UNKNOWN;
+        String serialNum = UNKNOWN;
+
+        try {
+            ObjectMapper om = new ObjectMapper();
+            JsonNode json = om.readTree(response);
+
+            JsonNode body = json.findValue("body");
+            if (body != null) {
+                mrf = body.get(MANUFACTURER).asText();
+                hwVer = body.get(CHASSIS_ID).asText();
+                swVer = body.get(KICKSTART_VER).asText();
+            }
+        } catch (IOException e) {
+            log.error("Failed to to retrieve Device Information {}", e);
+        }
+
+        DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
+        Device device = deviceService.getDevice(deviceId);
+        return new DefaultDeviceDescription(device.id().uri(), Device.Type.SWITCH,
+                mrf, hwVer, swVer, serialNum,
+                new ChassisId(), (SparseAnnotations) device.annotations());
+    }
+
+    @Override
+    public List<PortDescription> discoverPortDetails() {
+        DriverHandler handler = handler();
+        RestSBController controller = checkNotNull(handler.get(RestSBController.class));
+        DeviceId deviceId = handler.data().deviceId();
+
+        ArrayList<String> cmd = new ArrayList<>();
+        cmd.add(SHOW_INTERFACES_CMD);
+
+        String req = NxApiRequest.generate(cmd, NxApiRequest.CommandType.CLI);
+
+        String response = NxApiRequest.post(controller, deviceId, req);
+
+        // parse interface information from response
+        List<PortDescription> ports = Lists.newArrayList();
+        try {
+            ObjectMapper om = new ObjectMapper();
+            JsonNode json = om.readTree(response);
+
+            JsonNode interfaces = json.findValue(ROW_INTERFACE);
+            if (interfaces != null) {
+                interfaces.forEach(itf -> {
+                    String ifName = itf.get(INTERFACE).asText();
+                    if (ifName.startsWith(ETH)) {
+                        String ifNum = ifName.substring(ETHERNET.length()).replace(SLASH, ZERO);
+                        boolean state = itf.get(STATE).asText().equals(UP);
+                        long portSpeed = itf.get(ETH_BW).asLong() / ONE_THOUSAND; //in Mbps
+                        DefaultAnnotations.Builder annotations = DefaultAnnotations.builder()
+                                .set(AnnotationKeys.PORT_NAME, ifName);
+                        PortDescription desc = new DefaultPortDescription(PortNumber.portNumber(ifNum), state,
+                                Port.Type.FIBER, portSpeed, annotations.build());
+                        ports.add(desc);
+                    }
+                });
+            }
+        } catch (IOException e) {
+            log.error("Failed to to retrieve Interfaces {}", e);
+        }
+
+        return ports;
+    }
+}
diff --git a/drivers/cisco/rest/src/main/java/org/onosproject/drivers/cisco/rest/CiscoRestDriversLoader.java b/drivers/cisco/rest/src/main/java/org/onosproject/drivers/cisco/rest/CiscoRestDriversLoader.java
new file mode 100644
index 0000000..7450a90
--- /dev/null
+++ b/drivers/cisco/rest/src/main/java/org/onosproject/drivers/cisco/rest/CiscoRestDriversLoader.java
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+package org.onosproject.drivers.cisco.rest;
+
+import org.apache.felix.scr.annotations.Component;
+import org.onosproject.net.driver.AbstractDriverLoader;
+
+/**
+ * Loader for Cisco REST device drivers.
+ */
+@Component(immediate = true)
+public class CiscoRestDriversLoader extends AbstractDriverLoader {
+    public CiscoRestDriversLoader() {
+        super("/cisco-rest-drivers.xml");
+    }
+}
diff --git a/drivers/cisco/rest/src/main/java/org/onosproject/drivers/cisco/rest/NxApiRequest.java b/drivers/cisco/rest/src/main/java/org/onosproject/drivers/cisco/rest/NxApiRequest.java
new file mode 100644
index 0000000..79a1d58
--- /dev/null
+++ b/drivers/cisco/rest/src/main/java/org/onosproject/drivers/cisco/rest/NxApiRequest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.
+ */
+
+package org.onosproject.drivers.cisco.rest;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.stream.IntStream;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.protocol.rest.RestSBController;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import javax.ws.rs.core.MediaType;
+
+/**
+ * Generate json-rpc request for Cisco NX-API.
+ */
+public final class NxApiRequest {
+    public enum CommandType {
+        /**
+         * Command outputs are in JSON format.
+         */
+        CLI,
+        /**
+         * Command outputs are in raw ASCII text.
+         */
+        CLI_ASCII,
+    }
+
+    private static final String CMD = "cmd";
+    private static final String VERSION = "version";
+    private static final String JSONRPC = "jsonrpc";
+    private static final String TWO_POINT_ZERO = "2.0";
+    private static final String METHOD = "method";
+    private static final String CLI = "cli";
+    private static final String CLI_ASCII = "cli_ascii";
+    private static final String PARAMS = "params";
+    private static final String ID = "id";
+    private static final int ONE = 1;
+
+    private static final String API_URI = "/ins";
+    private static final String APP_JSON_RPC = "application/json-rpc";
+
+    private NxApiRequest() {
+    }
+
+    /**
+     * Generates a NX-API request message to execute on the Cisco NXOS device.
+     * @param commands list of commands to execute
+     * @param type response message format
+     * @return the NX-API request string
+     */
+    public static String generate(List<String> commands, CommandType type) {
+        ObjectMapper om = new ObjectMapper();
+        ArrayNode aryNode = om.createArrayNode();
+
+        if (commands == null) {
+            return aryNode.toString();
+        }
+
+        IntStream.range(0, commands.size()).forEach(idx -> {
+            ObjectNode parm = om.createObjectNode();
+            parm.put(CMD, commands.get(idx));
+            parm.put(VERSION, ONE);
+
+            ObjectNode node = om.createObjectNode();
+            node.put(JSONRPC, TWO_POINT_ZERO);
+            switch (type) {
+                case CLI_ASCII:
+                    node.put(METHOD, CLI_ASCII);
+                    break;
+                case CLI:
+                default:
+                    node.put(METHOD, CLI);
+                    break;
+            }
+
+            node.set(PARAMS, parm);
+            node.put(ID, idx + 1);
+
+            aryNode.add(node);
+        });
+
+        return aryNode.toString();
+    }
+
+    /**
+     * Sends NX-API request message to the device.
+     * @param controller RestSBController for Cisco REST device
+     * @param deviceId DeviceId for Cisco REST device
+     * @param request NX-API request string
+     * @return the response string
+     */
+    public static String post(RestSBController controller, DeviceId deviceId, String request) {
+        InputStream stream = new ByteArrayInputStream(request.getBytes(StandardCharsets.UTF_8));
+        String response = controller.post(deviceId, API_URI, stream,
+                MediaType.valueOf(APP_JSON_RPC), String.class);
+
+        return response;
+    }
+}
diff --git a/drivers/cisco/rest/src/main/java/org/onosproject/drivers/cisco/rest/package-info.java b/drivers/cisco/rest/src/main/java/org/onosproject/drivers/cisco/rest/package-info.java
new file mode 100644
index 0000000..80840f4
--- /dev/null
+++ b/drivers/cisco/rest/src/main/java/org/onosproject/drivers/cisco/rest/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Package for Cisco REST device drivers.
+ */
+package org.onosproject.drivers.cisco.rest;
\ No newline at end of file
diff --git a/drivers/cisco/rest/src/main/resources/cisco-rest-drivers.xml b/drivers/cisco/rest/src/main/resources/cisco-rest-drivers.xml
new file mode 100644
index 0000000..9b8abdf
--- /dev/null
+++ b/drivers/cisco/rest/src/main/resources/cisco-rest-drivers.xml
@@ -0,0 +1,22 @@
+<?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.
+  -->
+<drivers>
+    <driver name="cisco-rest" manufacturer="Cisco" hwVersion="" swVersion="NXOS">
+        <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
+                   impl="org.onosproject.drivers.cisco.rest.CiscoNxosDeviceDescription"/>
+    </driver>
+</drivers>
diff --git a/drivers/cisco/rest/src/test/java/org/onosproject/drivers/cisco/rest/CiscoRestDriversLoaderTest.java b/drivers/cisco/rest/src/test/java/org/onosproject/drivers/cisco/rest/CiscoRestDriversLoaderTest.java
new file mode 100644
index 0000000..838e437
--- /dev/null
+++ b/drivers/cisco/rest/src/test/java/org/onosproject/drivers/cisco/rest/CiscoRestDriversLoaderTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+package org.onosproject.drivers.cisco.rest;
+
+import org.junit.Before;
+import org.onosproject.net.driver.AbstractDriverLoaderTest;
+
+
+/**
+ * Cisco REST drivers loader test.
+ */
+public class CiscoRestDriversLoaderTest extends AbstractDriverLoaderTest {
+
+    @Before
+    public void setUp() {
+        loader = new CiscoRestDriversLoader();
+    }
+}
diff --git a/drivers/cisco/rest/src/test/java/org/onosproject/drivers/cisco/rest/NxApiRequestTest.java b/drivers/cisco/rest/src/test/java/org/onosproject/drivers/cisco/rest/NxApiRequestTest.java
new file mode 100644
index 0000000..4ef61da
--- /dev/null
+++ b/drivers/cisco/rest/src/test/java/org/onosproject/drivers/cisco/rest/NxApiRequestTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+
+package org.onosproject.drivers.cisco.rest;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests Cisco NX-API request message generator for Cisco NXOS devices.
+ */
+public class NxApiRequestTest {
+    public static final String REQ_FILE1 = "/testNxApiRequest1.json";
+    public static final String REQ_FILE2 = "/testNxApiRequest2.json";
+
+    @Test
+    public void oneRequestTest() throws IOException {
+        InputStream streamOrig = getClass().getResourceAsStream(REQ_FILE1);
+        ObjectMapper om = new ObjectMapper();
+        JsonNode node1 = om.readTree(streamOrig);
+
+        ArrayList<String> cmds = new ArrayList<>();
+        cmds.add("show interface");
+
+        JsonNode node2 = om.readTree(NxApiRequest.generate(cmds, NxApiRequest.CommandType.CLI));
+
+        assertEquals(node1.toString(), node2.toString());
+    }
+
+    @Test
+    public void manyRequestsTest() throws IOException {
+        InputStream streamOrig = getClass().getResourceAsStream(REQ_FILE2);
+        ObjectMapper om = new ObjectMapper();
+        JsonNode node1 = om.readTree(streamOrig);
+
+        ArrayList<String> cmds = new ArrayList<>();
+        cmds.add("show interface");
+        cmds.add("show ver");
+
+        JsonNode node2 = om.readTree(NxApiRequest.generate(cmds, NxApiRequest.CommandType.CLI));
+
+        assertEquals(node1.toString(), node2.toString());
+    }
+}
diff --git a/drivers/cisco/rest/src/test/resources/testNxApiRequest1.json b/drivers/cisco/rest/src/test/resources/testNxApiRequest1.json
new file mode 100644
index 0000000..84335fe
--- /dev/null
+++ b/drivers/cisco/rest/src/test/resources/testNxApiRequest1.json
@@ -0,0 +1,11 @@
+[
+  {
+    "jsonrpc": "2.0",
+    "method": "cli",
+    "params": {
+      "cmd": "show interface",
+      "version": 1
+    },
+    "id": 1
+  }
+]
\ No newline at end of file
diff --git a/drivers/cisco/rest/src/test/resources/testNxApiRequest2.json b/drivers/cisco/rest/src/test/resources/testNxApiRequest2.json
new file mode 100644
index 0000000..687e4c6
--- /dev/null
+++ b/drivers/cisco/rest/src/test/resources/testNxApiRequest2.json
@@ -0,0 +1,20 @@
+[
+  {
+    "jsonrpc": "2.0",
+    "method": "cli",
+    "params": {
+      "cmd": "show interface",
+      "version": 1
+    },
+    "id": 1
+  },
+  {
+    "jsonrpc": "2.0",
+    "method": "cli",
+    "params": {
+      "cmd": "show ver",
+      "version": 1
+    },
+    "id": 2
+  }
+]
\ No newline at end of file