[ONOS-5732]  NNI Loopback NETCONF command for FUJITSU OLT

Change-Id: I9bf7a767eef59c8133005f6d6b1ddd26cb072d21
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfig.java
new file mode 100644
index 0000000..5b55e0c
--- /dev/null
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfig.java
@@ -0,0 +1,199 @@
+/*
+ * 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.fujitsu;
+
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.DeviceId;
+import org.onosproject.drivers.fujitsu.behaviour.VoltNniLinkConfig;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.netconf.NetconfController;
+import org.slf4j.Logger;
+
+import java.io.IOException;
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Implementation to get and set parameters available in vOLT
+ * through the Netconf protocol.
+ */
+public class FujitsuVoltNniLinkConfig extends AbstractHandlerBehaviour
+        implements VoltNniLinkConfig {
+
+    private final Logger log = getLogger(FujitsuVoltNniLinkConfig.class);
+    private static final Set<String> NNILINKPARAMS =
+            ImmutableSet.of("loopback-enable");
+    private static final Set<String> ENABLES = ImmutableSet.of("true", "false");
+    private static final String VOLT_PORTS = "volt-ports";
+    private static final String ETH_NNILINK_PORTS = "eth-nnilink-ports";
+    private static final String ETH_NNILINK_PORT = "eth-nnilink-port";
+    private static final String NNILINK_ID = "nnilink-id";
+
+    @Override
+    public String getNniLinks(String target) {
+        DriverHandler handler = handler();
+        NetconfController controller = handler.get(NetconfController.class);
+        MastershipService mastershipService = handler.get(MastershipService.class);
+        DeviceId ncDeviceId = handler.data().deviceId();
+        checkNotNull(controller, "Netconf controller is null");
+        String reply = null;
+
+        if (!mastershipService.isLocalMaster(ncDeviceId)) {
+            log.warn("Not master for {} Use {} to execute command",
+                     ncDeviceId,
+                     mastershipService.getMasterFor(ncDeviceId));
+            return null;
+        }
+
+        try {
+            StringBuilder request = new StringBuilder();
+            request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE)
+                .append(ANGLE_RIGHT + NEW_LINE)
+                .append(buildStartTag(VOLT_PORTS));
+            if (target != null) {
+                int nni;
+                try {
+                    nni = Integer.parseInt(target);
+                    if (nni <= ZERO) {
+                        log.error("Invalid integer for nnilink-id:{}", target);
+                        return null;
+                    }
+                } catch (NumberFormatException e) {
+                    log.error("Non-number input for nnilink-id:{}", target);
+                    return null;
+                }
+                request.append(buildStartTag(ETH_NNILINK_PORTS))
+                    .append(buildStartTag(ETH_NNILINK_PORT))
+                    .append(buildStartTag(NNILINK_ID, false))
+                    .append(target)
+                    .append(buildEndTag(NNILINK_ID))
+                    .append(buildEndTag(ETH_NNILINK_PORT))
+                    .append(buildEndTag(ETH_NNILINK_PORTS));
+            } else {
+                request.append(buildEmptyTag(ETH_NNILINK_PORTS));
+            }
+            request.append(buildEndTag(VOLT_PORTS))
+                .append(VOLT_NE_CLOSE);
+
+            reply = controller.getDevicesMap()
+                        .get(ncDeviceId)
+                        .getSession()
+                        .get(request.toString(), REPORT_ALL);
+        } catch (IOException e) {
+            log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
+        }
+        return reply;
+    }
+
+    @Override
+    public boolean setNniLink(String target) {
+        DriverHandler handler = handler();
+        NetconfController controller = handler.get(NetconfController.class);
+        MastershipService mastershipService = handler.get(MastershipService.class);
+        DeviceId ncDeviceId = handler.data().deviceId();
+        checkNotNull(controller, "Netconf controller is null");
+
+        if (!mastershipService.isLocalMaster(ncDeviceId)) {
+            log.warn("Not master for {} Use {} to execute command",
+                     ncDeviceId,
+                     mastershipService.getMasterFor(ncDeviceId));
+            return false;
+        }
+
+        String[] data = target.split(COLON);
+        if (data.length != THREE) {
+            log.error("Invalid number of arguments {}", target);
+            return false;
+        }
+
+        try {
+            int nni = Integer.parseInt(data[FIRST_PART]);
+            if (nni <= ZERO) {
+                log.error("Invalid integer for nnilink-id:{}", target);
+                return false;
+            }
+        } catch (NumberFormatException e) {
+            log.error("Non-number input for nnilink-id:{}", target);
+            return false;
+        }
+
+        if (!checkSetParam(data[SECOND_PART], data[THIRD_PART])) {
+            log.error("Failed to check input {}", target);
+            return false;
+        }
+
+        try {
+            StringBuilder request = new StringBuilder();
+            request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE)
+                .append(ANGLE_RIGHT + NEW_LINE)
+                .append(buildStartTag(VOLT_PORTS))
+                .append(buildStartTag(ETH_NNILINK_PORTS))
+                .append(buildStartTag(ETH_NNILINK_PORT))
+                .append(buildStartTag(NNILINK_ID, false))
+                .append(data[FIRST_PART])
+                .append(buildEndTag(NNILINK_ID))
+
+                .append(buildStartTag(data[SECOND_PART], false))
+                .append(data[THIRD_PART])
+                .append(buildEndTag(data[SECOND_PART]))
+
+                .append(buildEndTag(ETH_NNILINK_PORT))
+                .append(buildEndTag(ETH_NNILINK_PORTS))
+                .append(buildEndTag(VOLT_PORTS))
+                .append(VOLT_NE_CLOSE);
+
+            controller.getDevicesMap()
+                .get(ncDeviceId)
+                .getSession()
+                .editConfig(RUNNING, null, request.toString());
+        } catch (IOException e) {
+            log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Verifies input string for valid options.
+     *
+     * @param name input data in string
+     * @param value input data in string
+     * @return true/false if the param is valid/invalid
+     */
+    private boolean checkSetParam(String name, String value) {
+        if (!NNILINKPARAMS.contains(name)) {
+            log.error("Unsupported parameter: {}", name);
+            return false;
+        }
+
+        switch (name) {
+            default:
+                if (!ENABLES.contains(value)) {
+                    log.error("Invalid value for Name {} : Value {}.", name, value);
+                    return false;
+                }
+                break;
+        }
+        return true;
+    }
+
+}
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java
index 1d6e145..2f642e3 100644
--- a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java
@@ -54,6 +54,7 @@
             put(ONU_DISCOVERY_MODE, null);
             put(PM_ENABLE, null);
             put(ADMIN_STATE, null);
+            put(LOOPBACK_ENABLE, null);
         }
     };
     private static final String VOLT_PORTS = "volt-ports";
@@ -62,12 +63,15 @@
     private static final String ADMIN_STATE = "admin-state";
     private static final String ONU_DISCOVERY_MODE = "onu-discovery-mode";
     private static final String PM_ENABLE = "pm-enable";
+    private static final String LOOPBACK_ENABLE = "loopback-enable";
     private static final Set<String> ADMINSTATES =
             ImmutableSet.of("enable", "disable");
     private static final Set<String> ONUDISCOVERYMODES =
             ImmutableSet.of("auto", "manual", "disabled");
     private static final Set<String> PMENABLES =
             ImmutableSet.of("true", "false");
+    private static final Set<String> LOOPBACKENABLES =
+            ImmutableSet.of("true", "false");
 
     private static final int ONU_DISCOVERY_INTERVAL_MIN = 1;
     private static final int ONU_DISCOVERY_INTERVAL_MAX = 3600;
@@ -235,11 +239,16 @@
                         return null;
                     }
                     break;
-                default:
+                case PM_ENABLE:
                     if (!validState(PMENABLES, paramName, paramValue)) {
                         return null;
                     }
                     break;
+                default:
+                    if (!validState(LOOPBACKENABLES, paramName, paramValue)) {
+                        return null;
+                    }
+                    break;
             }
         } else {
             int value;
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltNniLinkConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltNniLinkConfig.java
new file mode 100644
index 0000000..2929c13
--- /dev/null
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltNniLinkConfig.java
@@ -0,0 +1,43 @@
+/*
+ * 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.fujitsu.behaviour;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.driver.HandlerBehaviour;
+
+/**
+ * Device behaviour to obtain and set parameters of NNI links in vOLT.
+ */
+@Beta
+public interface VoltNniLinkConfig extends HandlerBehaviour {
+
+    /**
+     * Obtain all ETH NNI links or a specific NNI link in the device.
+     *
+     * @param target input data in string
+     * @return response string
+     */
+    String getNniLinks(String target);
+
+    /**
+     * Set a parameter value of NNI link in the device.
+     *
+     * @param target input data in string
+     * @return true if the operation is successful
+     */
+    boolean setNniLink(String target);
+
+}
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetNniLinksCommand.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetNniLinksCommand.java
new file mode 100644
index 0000000..914e602
--- /dev/null
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetNniLinksCommand.java
@@ -0,0 +1,57 @@
+/*
+ * 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.fujitsu.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.drivers.fujitsu.behaviour.VoltNniLinkConfig;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.net.driver.DriverService;
+
+/**
+ * Gets NNI links in vOLT.
+ */
+@Command(scope = "onos", name = "volt-nnilinks",
+        description = "Gets NNI links in vOLT")
+public class VoltGetNniLinksCommand extends AbstractShellCommand {
+
+    @Argument(index = 0, name = "uri", description = "Device ID",
+            required = true, multiValued = false)
+    String uri = null;
+
+    @Argument(index = 1, name = "target", description = "NNI link ID",
+            required = false, multiValued = false)
+    String target = null;
+
+    private DeviceId deviceId;
+
+    @Override
+    protected void execute() {
+        DriverService service = get(DriverService.class);
+        deviceId = DeviceId.deviceId(uri);
+        DriverHandler h = service.createHandler(deviceId);
+        VoltNniLinkConfig volt = h.behaviour(VoltNniLinkConfig.class);
+        String reply = volt.getNniLinks(target);
+        if (reply != null) {
+            print("%s", reply);
+        } else {
+            print("No reply from %s", deviceId.toString());
+        }
+    }
+
+}
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltSetNniLinkCommand.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltSetNniLinkCommand.java
new file mode 100644
index 0000000..6a04cfe
--- /dev/null
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltSetNniLinkCommand.java
@@ -0,0 +1,54 @@
+/*
+ * 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.fujitsu.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.drivers.fujitsu.behaviour.VoltNniLinkConfig;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.net.driver.DriverService;
+
+/**
+ * Sets a parameter of a NNI link in vOLT.
+ */
+@Command(scope = "onos", name = "volt-setnnilink",
+        description = "Sets a parameter of a NNI link in vOLT")
+public class VoltSetNniLinkCommand extends AbstractShellCommand {
+
+    @Argument(index = 0, name = "uri", description = "Device ID",
+            required = true, multiValued = false)
+    String uri = null;
+
+    @Argument(index = 1, name = "target", description = "NNI link ID:parameter:value",
+            required = true, multiValued = false)
+    String target = null;
+
+    private DeviceId deviceId;
+
+    @Override
+    protected void execute() {
+        DriverService service = get(DriverService.class);
+        deviceId = DeviceId.deviceId(uri);
+        DriverHandler h = service.createHandler(deviceId);
+        VoltNniLinkConfig volt = h.behaviour(VoltNniLinkConfig.class);
+        boolean reply = volt.setNniLink(target);
+        if (!reply) {
+            print("No reply from %s", deviceId.toString());
+        }
+    }
+}
diff --git a/drivers/fujitsu/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/drivers/fujitsu/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index f2a8391..73453b6 100644
--- a/drivers/fujitsu/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/drivers/fujitsu/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -89,6 +89,18 @@
                 <ref component-id="deviceIdCompleter"/>
             </completers>
         </command>
+        <command>
+            <action class="org.onosproject.drivers.fujitsu.cli.VoltGetNniLinksCommand"/>
+            <completers>
+                <ref component-id="deviceIdCompleter"/>
+            </completers>
+        </command>
+        <command>
+            <action class="org.onosproject.drivers.fujitsu.cli.VoltSetNniLinkCommand"/>
+            <completers>
+                <ref component-id="deviceIdCompleter"/>
+            </completers>
+        </command>
     </command-bundle>
 
     <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/>
diff --git a/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml b/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml
index b0dbed6..233560c 100644
--- a/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml
+++ b/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml
@@ -36,6 +36,8 @@
                    impl="org.onosproject.drivers.fujitsu.FujitsuVoltFwdlConfig"/>
         <behaviour api="org.onosproject.drivers.fujitsu.behaviour.VoltNeConfig"
                    impl="org.onosproject.drivers.fujitsu.FujitsuVoltNeConfig"/>
+        <behaviour api="org.onosproject.drivers.fujitsu.behaviour.VoltNniLinkConfig"
+                   impl="org.onosproject.drivers.fujitsu.FujitsuVoltNniLinkConfig"/>
         <behaviour api="org.onosproject.incubator.net.faultmanagement.alarm.AlarmConsumer"
                    impl="org.onosproject.drivers.fujitsu.FujitsuVoltAlarmConsumer"/>
     </driver>
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfigTest.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfigTest.java
new file mode 100644
index 0000000..6326e26
--- /dev/null
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfigTest.java
@@ -0,0 +1,261 @@
+/*
+ * 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.fujitsu;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtilityMock.*;
+
+/**
+ * Unit tests for methods of FujitsuVoltPonLinkConfig.
+ */
+public class FujitsuVoltNniLinkConfigTest {
+
+    private final FujitsuNetconfSessionListenerTest listener = new InternalSessionListenerTest();
+
+    private static final String TEST_VOLT_PORTS = "volt-ports";
+    private static final String TEST_ETH_NNILINK_PORTS = "eth-nnilink-ports";
+    private static final String TEST_ETH_NNILINK_PORT = "eth-nnilink-port";
+    private static final String TEST_NNILINK_ID = "nnilink-id";
+
+    private static final String[] INVALID_GET_TCS = {
+        "a-b-c",
+        "--1",
+        "s-1",
+        "1-1",
+        "1 A",
+        "1*A",
+        "-1",
+    };
+    private static final String[] VALID_GET_TCS = {
+        "1",
+        null,
+    };
+    private static final String[] INVALID_SET_TCS = {
+        "1:loopback-enable:true:1",
+        "-11:loopback-enable:false",
+        "2:loopback:true",
+        "3:loopback-enable:invalid",
+        "1:loopback-uni:8",
+        "-1:loopback-nni:nni",
+        ":loopback-nni:nni",
+    };
+    private static final String[] VALID_SET_TCS = {
+        "1:loopback-enable:true",
+        "2:loopback-enable:false",
+    };
+    private Integer currentKey;
+    private FujitsuNetconfControllerMock controller;
+    private FujitsuDriverHandlerAdapter driverHandler;
+    private FujitsuVoltNniLinkConfig voltConfig;
+
+    @Before
+    public void setUp() throws Exception {
+        controller = new FujitsuNetconfControllerMock();
+        driverHandler = controller.setUp(listener);
+        voltConfig = new FujitsuVoltNniLinkConfig();
+        voltConfig.setHandler(driverHandler);
+    }
+
+    /**
+     * Run to verify handling of invalid input for get operation.
+     */
+    @Test
+    public void testInvalidGetNniLinksInput() throws Exception {
+        String reply;
+        String target;
+
+        for (int i = ZERO; i < INVALID_GET_TCS.length; i++) {
+            target = INVALID_GET_TCS[i];
+            reply = voltConfig.getNniLinks(target);
+            assertNull("Incorrect response for INVALID_GET_TCS", reply);
+        }
+    }
+
+    /**
+     * Run to verify handling of valid input for get operation.
+     */
+    @Test
+    public void testValidGetNniLinksInput() throws Exception {
+        String reply;
+        String target;
+
+        for (int i = ZERO; i < VALID_GET_TCS.length; i++) {
+            target = VALID_GET_TCS[i];
+            currentKey = i;
+            reply = voltConfig.getNniLinks(target);
+            assertNotNull("Incorrect response for VALID_GET_TCS", reply);
+        }
+    }
+
+    /**
+     * Run to verify handling of invalid input for set operation.
+     */
+    @Test
+    public void testInvalidSetNniLinkInput() throws Exception {
+        String target;
+        boolean result;
+
+        for (int i = ZERO; i < INVALID_SET_TCS.length; i++) {
+            target = INVALID_SET_TCS[i];
+            result = voltConfig.setNniLink(target);
+            assertFalse("Incorrect response for INVALID_SET_TCS", result);
+        }
+    }
+
+    /**
+     * Run to verify handling of valid input for set operation.
+     */
+    @Test
+    public void testValidSetNniLinkInput() throws Exception {
+        String target;
+        boolean result;
+
+        for (int i = ZERO; i < VALID_SET_TCS.length; i++) {
+            target = VALID_SET_TCS[i];
+            currentKey = i;
+            result = voltConfig.setNniLink(target);
+            assertTrue("Incorrect response for VALID_SET_TCS", result);
+        }
+    }
+
+    /**
+     * Verifies XML request string by comparing with generated string.
+     *
+     * @param request XML string for set operation
+     * @return true if XML string matches with generated
+     */
+    private boolean verifyGetRequest(String request) {
+        StringBuilder rpc = new StringBuilder();
+        String target = VALID_GET_TCS[currentKey];
+
+        rpc.append(TEST_VOLT_NE_OPEN + TEST_VOLT_NE_NAMESPACE);
+        rpc.append(TEST_ANGLE_RIGHT + TEST_NEW_LINE);
+        rpc.append(startTag(TEST_VOLT_PORTS));
+        if (target != null) {
+            rpc.append(startTag(TEST_ETH_NNILINK_PORTS))
+                .append(startTag(TEST_ETH_NNILINK_PORT))
+                .append(startTag(TEST_NNILINK_ID, false))
+                .append(target)
+                .append(endTag(TEST_NNILINK_ID))
+                .append(endTag(TEST_ETH_NNILINK_PORT))
+                .append(endTag(TEST_ETH_NNILINK_PORTS));
+        } else {
+            rpc.append(emptyTag(TEST_ETH_NNILINK_PORTS));
+        }
+        rpc.append(endTag(TEST_VOLT_PORTS))
+            .append(TEST_VOLT_NE_CLOSE);
+
+        String testRequest = rpc.toString();
+        boolean result = request.equals(testRequest);
+        assertTrue("Does not match with generated string", result);
+        return result;
+    }
+
+    /**
+     * Verifies XML request string by comparing with generated string.
+     *
+     * @param request XML string for set operation
+     * @return true or false
+     */
+    private boolean verifyEditConfigRequest(String request) {
+        StringBuilder rpc = new StringBuilder();
+        String target = VALID_SET_TCS[currentKey];
+        String[] data = target.split(TEST_COLON);
+
+        rpc.append(TEST_VOLT_NE_OPEN + TEST_VOLT_NE_NAMESPACE)
+            .append(TEST_ANGLE_RIGHT + TEST_NEW_LINE)
+            .append(startTag(TEST_VOLT_PORTS))
+            .append(startTag(TEST_ETH_NNILINK_PORTS))
+            .append(startTag(TEST_ETH_NNILINK_PORT))
+            .append(startTag(TEST_NNILINK_ID, false))
+            .append(data[FIRST_PART])
+            .append(endTag(TEST_NNILINK_ID))
+            .append(startTag(data[SECOND_PART], false))
+            .append(data[THIRD_PART])
+            .append(endTag(data[SECOND_PART]))
+            .append(endTag(TEST_ETH_NNILINK_PORT))
+            .append(endTag(TEST_ETH_NNILINK_PORTS))
+            .append(endTag(TEST_VOLT_PORTS))
+            .append(TEST_VOLT_NE_CLOSE);
+
+        String testRequest = rpc.toString();
+        boolean result = request.equals(testRequest);
+        assertTrue("Does not match with generated string", result);
+        return result;
+    }
+
+    /**
+     * Internal listener for device service events.
+     */
+    private class InternalSessionListenerTest implements FujitsuNetconfSessionListenerTest {
+        @Override
+        public boolean verifyEditConfig(String request) {
+            return false;
+        }
+
+        @Override
+        public boolean verifyEditConfig(String target, String mode, String request) {
+            boolean result;
+
+            assertTrue("Incorrect target", target.equals(TEST_RUNNING));
+            assertNull("Incorrect mode", mode);
+
+            request = request.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE);
+            assertTrue("Does not contain:" + TEST_VOLT_NAMESPACE,
+                    request.contains(TEST_VOLT_NAMESPACE));
+            result = verifyEditConfigRequest(request);
+            assertTrue("XML verification failure", result);
+            return result;
+        }
+
+        @Override
+        public boolean verifyGet(String filterSchema, String withDefaultsMode) {
+            boolean result;
+
+            assertTrue("Incorrect withDefaultsMode",
+                    withDefaultsMode.equals(TEST_REPORT_ALL));
+
+            filterSchema = filterSchema.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE);
+            assertTrue("Does not contain:" + TEST_VOLT_NAMESPACE,
+                    filterSchema.contains(TEST_VOLT_NAMESPACE));
+            result = verifyGetRequest(filterSchema);
+            assertTrue("XML verification failure", result);
+            return result;
+        }
+
+        @Override
+        public String buildGetReply() {
+            return null;
+        }
+
+        @Override
+        public boolean verifyWrappedRpc(String request) {
+            return false;
+        }
+
+        @Override
+        public void verifyStartSubscription(String filterSchema) {
+        }
+    }
+
+}