ISIS protocol manual merge from 1.6 due to cherry pick merge conflict

Change-Id: I6c3abf6a83ddaeba76293dc7864fcec88e9b4e7e
diff --git a/providers/isis/topology/BUCK b/providers/isis/topology/BUCK
new file mode 100644
index 0000000..de4e04f
--- /dev/null
+++ b/providers/isis/topology/BUCK
@@ -0,0 +1,14 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//protocols/isis/api:onos-protocols-isis-api',
+    '//protocols/isis/ctl:onos-protocols-isis-ctl',
+]
+
+TEST_DEPS = [
+    '//lib:TEST_ADAPTERS',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+    test_deps = TEST_DEPS,
+)
diff --git a/providers/isis/topology/pom.xml b/providers/isis/topology/pom.xml
new file mode 100644
index 0000000..dc0cad8
--- /dev/null
+++ b/providers/isis/topology/pom.xml
@@ -0,0 +1,42 @@
+<?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.
+  -->
+<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/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.onosproject</groupId>
+        <artifactId>onos-isis-providers</artifactId>
+        <version>1.7.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>onos-isis-provider-topology</artifactId>
+    <packaging>bundle</packaging>
+
+    <description>ONOS ISIS Providers</description>
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/providers/isis/topology/src/main/java/org/onosproject/provider/isis/topology/impl/IsisTopologyProvider.java b/providers/isis/topology/src/main/java/org/onosproject/provider/isis/topology/impl/IsisTopologyProvider.java
new file mode 100755
index 0000000..1ff2c33
--- /dev/null
+++ b/providers/isis/topology/src/main/java/org/onosproject/provider/isis/topology/impl/IsisTopologyProvider.java
@@ -0,0 +1,373 @@
+/*
+ * 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.provider.isis.topology.impl;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.packet.ChassisId;
+import org.onlab.util.Bandwidth;
+import org.onosproject.isis.controller.IsisController;
+import org.onosproject.isis.controller.topology.IsisLink;
+import org.onosproject.isis.controller.topology.IsisLinkListener;
+import org.onosproject.isis.controller.topology.IsisLinkTed;
+import org.onosproject.isis.controller.topology.IsisRouter;
+import org.onosproject.isis.controller.topology.IsisRouterId;
+import org.onosproject.isis.controller.topology.IsisRouterListener;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link;
+import org.onosproject.net.MastershipRole;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.config.basics.BandwidthCapacity;
+import org.onosproject.net.device.DefaultDeviceDescription;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.DeviceDescription;
+import org.onosproject.net.device.DeviceProvider;
+import org.onosproject.net.device.DeviceProviderRegistry;
+import org.onosproject.net.device.DeviceProviderService;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.link.DefaultLinkDescription;
+import org.onosproject.net.link.LinkDescription;
+import org.onosproject.net.link.LinkProvider;
+import org.onosproject.net.link.LinkProviderRegistry;
+import org.onosproject.net.link.LinkProviderService;
+import org.onosproject.net.link.LinkService;
+import org.onosproject.net.provider.AbstractProvider;
+import org.onosproject.net.provider.ProviderId;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Provider which advertises device descriptions to the core.
+ */
+@Component(immediate = true)
+public class IsisTopologyProvider extends AbstractProvider implements DeviceProvider, LinkProvider {
+
+    public static final long PSEUDO_PORT = 0xffffffff;
+    public static final String ADMINISTRATIVEGROUP = "administrativeGroup";
+    public static final String TE_METRIC = "teMetric";
+    public static final String MAXRESERVABLEBANDWIDTH = "maxReservableBandwidth";
+    public static final String ROUTERID = "routerId";
+    public static final String NEIGHBORID = "neighborId";
+    private static final Logger log = getLogger(IsisTopologyProvider.class);
+    // Default values for tunable parameters
+    private static final String UNKNOWN = "unknown";
+    final InternalTopologyProvider listener = new InternalTopologyProvider();
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceProviderRegistry deviceProviderRegistry;
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected LinkProviderRegistry linkProviderRegistry;
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected NetworkConfigService networkConfigService;
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected LinkService linkService;
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected IsisController controller;
+    //This Interface that defines how this provider can interact with the core.
+    private LinkProviderService linkProviderService;
+    // The interface that defines how this Provider can interact with the core
+    private DeviceProviderService deviceProviderService;
+    private HashMap<DeviceId, List<PortDescription>> portMap = new HashMap<>();
+
+    /**
+     * Creates an ISIS device provider.
+     */
+    public IsisTopologyProvider() {
+        super(new ProviderId("l3", "org.onosproject.provider.isis"));
+    }
+
+    @Activate
+    public void activate() {
+        deviceProviderService = deviceProviderRegistry.register(this);
+        linkProviderService = linkProviderRegistry.register(this);
+        controller.addRouterListener(listener);
+        controller.addLinkListener(listener);
+        log.debug("IsisDeviceProvider::activate...!!!!");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        log.debug("IsisDeviceProvider::deactivate...!!!!");
+        deviceProviderRegistry.unregister(this);
+        deviceProviderService = null;
+        linkProviderRegistry.unregister(this);
+        linkProviderService = null;
+        controller.removeRouterListener(listener);
+        controller.removeLinkListener(listener);
+    }
+
+    @Override
+    public void triggerProbe(DeviceId deviceId) {
+        log.debug("IsisDeviceProvider::triggerProbe...!!!!");
+    }
+
+    @Override
+    public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
+        log.debug("IsisDeviceProvider::roleChanged...!!!!");
+    }
+
+    @Override
+    public boolean isReachable(DeviceId deviceId) {
+        log.debug("IsisDeviceProvider::isReachable...!!!!");
+        return true;
+    }
+
+    @Override
+    public void changePortState(DeviceId deviceId, PortNumber portNumber, boolean enable) {
+        log.debug("IsisDeviceProvider::changePortState...!!!!");
+    }
+
+    /**
+     * Builds link description.
+     *
+     * @param isisLink ISIS link instance
+     * @return link description
+     */
+    private LinkDescription buildLinkDes(IsisLink isisLink) {
+        long srcAddress = 0;
+        long dstAddress = 0;
+        boolean localPseduo = false;
+        boolean remotePseduo = false;
+        String localSystemId = isisLink.localSystemId();
+        String remoteSystemId = isisLink.remoteSystemId();
+        //Changing of port numbers
+        if (isisLink.interfaceIp() != null) {
+            //srcAddress = isisLink.interfaceIp().toInt();
+            srcAddress = (long) Long.parseUnsignedLong(Integer.toBinaryString(isisLink.interfaceIp().toInt()), 2);
+        }
+        if (isisLink.neighborIp() != null) {
+            //dstAddress = isisLink.neighborIp().toInt();
+            dstAddress = (long) Long.parseUnsignedLong(Integer.toBinaryString(isisLink.neighborIp().toInt()), 2);
+        }
+        DeviceId srcId = DeviceId.deviceId(IsisRouterId.uri(localSystemId));
+        DeviceId dstId = DeviceId.deviceId(IsisRouterId.uri(remoteSystemId));
+        if (checkIsDis(isisLink.localSystemId())) {
+            localPseduo = true;
+        } else if (checkIsDis(isisLink.remoteSystemId())) {
+            remotePseduo = true;
+        } else {
+            log.debug("IsisDeviceProvider::buildLinkDes : unknown type.!");
+        }
+
+        if (localPseduo && srcAddress == 0) {
+            srcAddress = PSEUDO_PORT;
+        } else if (remotePseduo && dstAddress == 0) {
+            dstAddress = PSEUDO_PORT;
+        }
+
+        ConnectPoint src = new ConnectPoint(srcId, PortNumber.portNumber(srcAddress));
+        ConnectPoint dst = new ConnectPoint(dstId, PortNumber.portNumber(dstAddress));
+        DefaultAnnotations.Builder annotationBuilder = DefaultAnnotations.builder();
+        if (isisLink != null) {
+            annotationBuilder = buildAnnotations(annotationBuilder, isisLink);
+        }
+
+        return new DefaultLinkDescription(src, dst, Link.Type.DIRECT, false, annotationBuilder.build());
+    }
+
+    /**
+     * Return the DIS value from the systemId.
+     *
+     * @param systemId system Id.
+     * @return return true if DIS else false
+     */
+    public static boolean checkIsDis(String systemId) {
+        StringTokenizer stringTokenizer = new StringTokenizer(systemId, "." + "-");
+        int count = 0;
+        while (stringTokenizer.hasMoreTokens()) {
+            String str = stringTokenizer.nextToken();
+            if (count == 3) {
+                int x = Integer.parseInt(str);
+                if (x > 0) {
+                    return true;
+                }
+            }
+            count++;
+        }
+        return false;
+    }
+
+    /**
+     * Builds port description.
+     *
+     * @param deviceId   device ID for the port
+     * @param portNumber port number of the link
+     * @return list of port description
+     */
+    private List<PortDescription> buildPortDescriptions(DeviceId deviceId,
+                                                        PortNumber portNumber) {
+        List<PortDescription> portList;
+        if (portMap.containsKey(deviceId)) {
+            portList = portMap.get(deviceId);
+        } else {
+            portList = new ArrayList<>();
+        }
+        if (portNumber != null) {
+            PortDescription portDescriptions = new DefaultPortDescription(portNumber, true);
+            portList.add(portDescriptions);
+        }
+        portMap.put(deviceId, portList);
+
+        return portList;
+    }
+
+    /**
+     * Builds the annotation details.
+     *
+     * @param annotationBuilder default annotation builder instance
+     * @param isisLink          ISIS link instance
+     * @return annotation builder instance
+     */
+    private DefaultAnnotations.Builder buildAnnotations(DefaultAnnotations.Builder annotationBuilder,
+                                                        IsisLink isisLink) {
+        int administrativeGroup = 0;
+        long teMetric = 0;
+        Bandwidth maxReservableBandwidth = Bandwidth.bps(0);
+        String routerId = null;
+        String neighborId = null;
+
+        //TE Info
+        IsisLinkTed isisLinkTed = isisLink.linkTed();
+        log.info("Ted Information:  {}", isisLinkTed.toString());
+        administrativeGroup = isisLinkTed.administrativeGroup();
+        teMetric = isisLinkTed.teDefaultMetric();
+        maxReservableBandwidth = isisLinkTed.maximumReservableLinkBandwidth();
+        routerId = isisLink.localSystemId();
+        neighborId = isisLink.remoteSystemId();
+        annotationBuilder.set(ADMINISTRATIVEGROUP, String.valueOf(administrativeGroup));
+        annotationBuilder.set(TE_METRIC, String.valueOf(teMetric));
+        annotationBuilder.set(MAXRESERVABLEBANDWIDTH, String.valueOf(maxReservableBandwidth));
+        annotationBuilder.set(ROUTERID, String.valueOf(routerId));
+        annotationBuilder.set(NEIGHBORID, String.valueOf(neighborId));
+        return annotationBuilder;
+    }
+
+    /**
+     * Internal device provider implementation.
+     */
+    private class InternalTopologyProvider implements IsisRouterListener, IsisLinkListener {
+
+        @Override
+        public void routerAdded(IsisRouter isisRouter) {
+            String systemId = isisRouter.systemId();
+            log.info("Added device {}", systemId);
+            DeviceId deviceId = DeviceId.deviceId(IsisRouterId.uri(systemId));
+            Device.Type deviceType = Device.Type.ROUTER;
+            //If our routerType is Dr or Bdr type is PSEUDO
+            if (isisRouter.isDis()) {
+                deviceType = Device.Type.ROUTER;
+            } else {
+                deviceType = Device.Type.VIRTUAL;
+            }
+            ChassisId cId = new ChassisId();
+            DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
+            newBuilder.set(AnnotationKeys.TYPE, "L3");
+            newBuilder.set("RouterId", systemId);
+            DeviceDescription description =
+                    new DefaultDeviceDescription(IsisRouterId.uri(systemId), deviceType, UNKNOWN, UNKNOWN, UNKNOWN,
+                                                 UNKNOWN, cId, newBuilder.build());
+            deviceProviderService.deviceConnected(deviceId, description);
+            System.out.println("Device added: " + systemId);
+        }
+
+        @Override
+        public void routerRemoved(IsisRouter isisRouter) {
+            String systemId = isisRouter.systemId();
+            log.info("Delete device {}", systemId);
+            DeviceId deviceId = DeviceId.deviceId(IsisRouterId.uri(systemId));
+            if (deviceProviderService == null) {
+                return;
+            }
+            deviceProviderService.deviceDisconnected(deviceId);
+            log.info("delete device {}", systemId);
+        }
+
+        @Override
+        public void addLink(IsisLink isisLink) {
+            log.debug("Addlink {}", isisLink.localSystemId());
+
+            LinkDescription linkDes = buildLinkDes(isisLink);
+            //Updating ports of the link
+            //If already link exists, return
+            if (linkService.getLink(linkDes.src(), linkDes.dst()) != null || linkProviderService == null) {
+                return;
+            }
+            ConnectPoint destconnectPoint = linkDes.dst();
+            PortNumber destport = destconnectPoint.port();
+            if (destport.toLong() != 0) {
+                deviceProviderService.updatePorts(linkDes.src().deviceId(),
+                                                  buildPortDescriptions(linkDes.src().deviceId(),
+                                                  linkDes.src().port()));
+                deviceProviderService.updatePorts(linkDes.dst().deviceId(),
+                                                  buildPortDescriptions(linkDes.dst().deviceId(),
+                                                  linkDes.dst().port()));
+                registerBandwidth(linkDes, isisLink);
+                linkProviderService.linkDetected(linkDes);
+                System.out.println("link desc " + linkDes.toString());
+            }
+        }
+
+        @Override
+        public void deleteLink(IsisLink isisLink) {
+            log.debug("Delete link {}", isisLink.localSystemId());
+            if (linkProviderService == null) {
+                return;
+            }
+            LinkDescription linkDes = buildLinkDes(isisLink);
+            linkProviderService.linkVanished(linkDes);
+        }
+
+        /**
+         * Registers the bandwidth for source and destination points.
+         *
+         * @param linkDes  link description instance
+         * @param isisLink ISIS link instance
+         */
+        private void registerBandwidth(LinkDescription linkDes, IsisLink isisLink) {
+            if (isisLink == null) {
+                log.error("Could not able to register bandwidth ");
+                return;
+            }
+            IsisLinkTed isisLinkTed = isisLink.linkTed();
+            Bandwidth maxReservableBw = isisLinkTed.maximumReservableLinkBandwidth();
+            if (maxReservableBw != null) {
+                if (maxReservableBw.compareTo(Bandwidth.bps(0)) == 0) {
+                    return;
+                }
+                //Configure bandwidth for src and dst port
+                BandwidthCapacity config = networkConfigService.addConfig(linkDes.src(), BandwidthCapacity.class);
+                config.capacity(maxReservableBw).apply();
+
+                config = networkConfigService.addConfig(linkDes.dst(), BandwidthCapacity.class);
+                config.capacity(maxReservableBw).apply();
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/providers/isis/topology/src/main/java/org/onosproject/provider/isis/topology/impl/package-info.java b/providers/isis/topology/src/main/java/org/onosproject/provider/isis/topology/impl/package-info.java
new file mode 100644
index 0000000..886a345
--- /dev/null
+++ b/providers/isis/topology/src/main/java/org/onosproject/provider/isis/topology/impl/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.
+ */
+
+/**
+ * Provider that uses ISIS request as a means of infrastructure device discovery.
+ */
+package org.onosproject.provider.isis.topology.impl;
diff --git a/providers/isis/topology/src/test/java/org/onosproject/provider/isis/topology/impl/IsisTopologyProviderTest.java b/providers/isis/topology/src/test/java/org/onosproject/provider/isis/topology/impl/IsisTopologyProviderTest.java
new file mode 100755
index 0000000..fb3acd1
--- /dev/null
+++ b/providers/isis/topology/src/test/java/org/onosproject/provider/isis/topology/impl/IsisTopologyProviderTest.java
@@ -0,0 +1,479 @@
+/*
+ * 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.provider.isis.topology.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.Ip4Address;
+import org.onlab.util.Bandwidth;
+import org.onosproject.isis.controller.IsisController;
+import org.onosproject.isis.controller.IsisProcess;
+import org.onosproject.isis.controller.impl.topology.DefaultIsisLink;
+import org.onosproject.isis.controller.impl.topology.DefaultIsisLinkTed;
+import org.onosproject.isis.controller.impl.topology.DefaultIsisRouter;
+import org.onosproject.isis.controller.topology.IsisLink;
+import org.onosproject.isis.controller.topology.IsisLinkListener;
+import org.onosproject.isis.controller.topology.IsisLinkTed;
+import org.onosproject.isis.controller.topology.IsisRouter;
+import org.onosproject.isis.controller.topology.IsisRouterListener;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link;
+import org.onosproject.net.MastershipRole;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.config.Config;
+import org.onosproject.net.config.ConfigApplyDelegate;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigRegistryAdapter;
+import org.onosproject.net.config.basics.BandwidthCapacity;
+import org.onosproject.net.device.DeviceDescription;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceProvider;
+import org.onosproject.net.device.DeviceProviderRegistry;
+import org.onosproject.net.device.DeviceProviderService;
+import org.onosproject.net.device.DeviceServiceAdapter;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.device.PortStatistics;
+import org.onosproject.net.link.LinkDescription;
+import org.onosproject.net.link.LinkListener;
+import org.onosproject.net.link.LinkProvider;
+import org.onosproject.net.link.LinkProviderRegistry;
+import org.onosproject.net.link.LinkProviderService;
+import org.onosproject.net.link.LinkServiceAdapter;
+import org.onosproject.net.provider.ProviderId;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test cases for ISIS topology provider.
+ */
+public class IsisTopologyProviderTest {
+
+    private final IsisTopologyProvider provider = new IsisTopologyProvider();
+    private final TestDeviceRegistry nodeRegistry = new TestDeviceRegistry();
+    private final TestLinkRegistry linkRegistry = new TestLinkRegistry();
+    private final TestController controller = new TestController();
+    private final TestLinkService linkService = new TestLinkService();
+    private MockNetConfigRegistryAdapter networkConfigService = new MockNetConfigRegistryAdapter();
+
+    @Before
+    public void setUp() throws Exception {
+        provider.deviceProviderRegistry = nodeRegistry;
+        provider.linkProviderRegistry = linkRegistry;
+        provider.networkConfigService = networkConfigService;
+        provider.controller = controller;
+        provider.linkService = linkService;
+        provider.activate();
+        assertNotNull("provider should be registered", nodeRegistry.provider);
+        assertNotNull("listener should be registered", controller.nodeListener);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        provider.deactivate();
+        provider.controller = null;
+        provider.deviceProviderRegistry = null;
+        provider.networkConfigService = null;
+    }
+
+    @Test
+    public void triggerProbe() {
+        DeviceId deviceId = DeviceId.deviceId("2929.2929.2929.00-00");
+        provider.triggerProbe(deviceId);
+    }
+
+    @Test
+    public void roleChanged() {
+        DeviceId deviceId = DeviceId.deviceId("1111.1111.1111.00-00");
+        provider.roleChanged(deviceId, MastershipRole.MASTER);
+    }
+
+    @Test
+    public void changePortState() {
+        DeviceId deviceId = DeviceId.deviceId("2222.2222.2222.00-82");
+        provider.changePortState(deviceId, PortNumber.portNumber(168430087), false);
+    }
+
+    @Test
+    public void isReachable() {
+        DeviceId deviceId = DeviceId.deviceId("1010.1010.1111.00-22");
+        provider.isReachable(deviceId);
+    }
+
+
+    /* Validate node is added to the device validating URI and should get updated properly */
+    @Test
+    public void isisTopologyProviderTestAddDevice1() {
+        int deviceAddCount = 0;
+        IsisRouter isisRouter = new DefaultIsisRouter();
+        isisRouter.setSystemId("2929.2929.2929.00");
+        isisRouter.setNeighborRouterId(Ip4Address.valueOf("10.10.10.1"));
+        isisRouter.setInterfaceId(Ip4Address.valueOf("10.10.10.2"));
+        isisRouter.setDis(false);
+
+        for (IsisRouterListener l : controller.nodeListener) {
+            l.routerAdded(isisRouter);
+            deviceAddCount = nodeRegistry.connected.size();
+            assertTrue(deviceAddCount == 1);
+            l.routerRemoved(isisRouter);
+            deviceAddCount = nodeRegistry.connected.size();
+            assertTrue(deviceAddCount == 0);
+        }
+    }
+
+    @Test
+    public void isisTopologyProviderTestAddDevice2() {
+        int deviceAddCount = 0;
+        IsisRouter isisRouter = new DefaultIsisRouter();
+        isisRouter.setSystemId("7777.7777.7777.00");
+        isisRouter.setNeighborRouterId(Ip4Address.valueOf("10.10.10.1"));
+        isisRouter.setInterfaceId(Ip4Address.valueOf("10.10.10.7"));
+        isisRouter.setDis(false);
+        IsisRouter isisRouter1 = new DefaultIsisRouter();
+        isisRouter1.setSystemId("1111.1111.1111.00");
+        isisRouter1.setNeighborRouterId(Ip4Address.valueOf("10.10.10.7"));
+        isisRouter1.setInterfaceId(Ip4Address.valueOf("10.10.10.1"));
+        isisRouter1.setDis(true);
+        for (IsisRouterListener l : controller.nodeListener) {
+            l.routerAdded(isisRouter);
+            deviceAddCount = nodeRegistry.connected.size();
+            assertTrue(deviceAddCount == 1);
+            l.routerAdded(isisRouter1);
+            deviceAddCount = nodeRegistry.connected.size();
+            assertTrue(deviceAddCount == 2);
+            l.routerRemoved(isisRouter);
+            deviceAddCount = nodeRegistry.connected.size();
+            assertTrue(deviceAddCount == 1);
+        }
+    }
+
+    @Test
+    public void isisTopologyProviderTestAddLink() {
+        int deviceAddCount = 0;
+        IsisRouter isisRouter = new DefaultIsisRouter();
+        isisRouter.setSystemId("7777.7777.7777.00");
+        isisRouter.setNeighborRouterId(Ip4Address.valueOf("10.10.10.1"));
+        isisRouter.setInterfaceId(Ip4Address.valueOf("10.10.10.7"));
+        isisRouter.setDis(false);
+        IsisRouter isisRouter1 = new DefaultIsisRouter();
+        isisRouter1.setSystemId("1111.1111.1111.00");
+        isisRouter1.setNeighborRouterId(Ip4Address.valueOf("10.10.10.7"));
+        isisRouter1.setInterfaceId(Ip4Address.valueOf("10.10.10.1"));
+        isisRouter1.setDis(true);
+        IsisLink isisLink = new DefaultIsisLink();
+        isisLink.setRemoteSystemId("7777.7777.7777.00");
+        isisLink.setLocalSystemId("1111.1111.1111.00");
+        isisLink.setInterfaceIp(Ip4Address.valueOf("10.10.10.1"));
+        isisLink.setNeighborIp(Ip4Address.valueOf("10.10.10.7"));
+        IsisLinkTed isisLinkTed = new DefaultIsisLinkTed();
+        isisLinkTed.setTeDefaultMetric(10);
+        isisLinkTed.setAdministrativeGroup(5);
+        isisLinkTed.setIpv4InterfaceAddress(Ip4Address.valueOf("10.10.10.1"));
+        isisLinkTed.setIpv4NeighborAddress(Ip4Address.valueOf("10.10.10.7"));
+        isisLinkTed.setMaximumLinkBandwidth(Bandwidth.bps(0));
+        isisLinkTed.setMaximumReservableLinkBandwidth(Bandwidth.bps(1.0));
+        List<Bandwidth> unresList = new ArrayList<>();
+        unresList.add(Bandwidth.bps(0.0));
+        unresList.add(Bandwidth.bps(1.0));
+        unresList.add(Bandwidth.bps(2.0));
+        unresList.add(Bandwidth.bps(3.0));
+        isisLinkTed.setUnreservedBandwidth(unresList);
+        isisLink.setLinkTed(isisLinkTed);
+        for (IsisRouterListener l : controller.nodeListener) {
+            l.routerAdded(isisRouter);
+            deviceAddCount = nodeRegistry.connected.size();
+            assertTrue(deviceAddCount == 1);
+            l.routerAdded(isisRouter1);
+            deviceAddCount = nodeRegistry.connected.size();
+            assertTrue(deviceAddCount == 2);
+        }
+        for (IsisLinkListener l : controller.linkListener) {
+            l.addLink(isisLink);
+            l.deleteLink(isisLink);
+
+        }
+    }
+
+
+    /* Class implement device test registry */
+    private class TestDeviceRegistry implements DeviceProviderRegistry {
+        DeviceProvider provider;
+
+        Set<DeviceId> connected = new HashSet<>();
+
+        @Override
+        public DeviceProviderService register(DeviceProvider provider) {
+            this.provider = provider;
+            return new TestProviderService();
+        }
+
+        @Override
+        public void unregister(DeviceProvider provider) {
+        }
+
+        @Override
+        public Set<ProviderId> getProviders() {
+            return null;
+        }
+
+        private class TestProviderService implements DeviceProviderService {
+
+            @Override
+            public DeviceProvider provider() {
+                return null;
+            }
+
+            @Override
+            public void deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) {
+
+                connected.add(deviceId);
+
+            }
+
+
+            @Override
+            public void deviceDisconnected(DeviceId deviceId) {
+
+                connected.remove(deviceId);
+            }
+
+
+            @Override
+            public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) {
+                // TODO Auto-generated method stub
+
+            }
+
+            @Override
+            public void portStatusChanged(DeviceId deviceId, PortDescription portDescription) {
+                // TODO Auto-generated method stub
+
+            }
+
+            @Override
+            public void receivedRoleReply(DeviceId deviceId, MastershipRole requested, MastershipRole response) {
+                // TODO Auto-generated method stub
+
+            }
+
+
+            @Override
+            public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) {
+                // TODO Auto-generated method stub
+
+            }
+        }
+    }
+
+
+
+    private class TestDeviceService extends DeviceServiceAdapter {
+        private DeviceListener listener;
+
+        @Override
+        public void addListener(DeviceListener listener) {
+            this.listener = listener;
+        }
+
+        @Override
+        public Iterable<Device> getDevices() {
+            return Collections.emptyList();
+        }
+    }
+
+    private class TestLinkService extends LinkServiceAdapter {
+        private LinkListener listener;
+
+        @Override
+        public void addListener(LinkListener listener) {
+            this.listener = listener;
+        }
+
+        @Override
+        public Iterable<Link> getLinks() {
+            return Collections.emptyList();
+        }
+    }
+
+    /* Class implement device test registry */
+    private class TestLinkRegistry implements LinkProviderRegistry {
+        LinkProvider provider;
+
+        Set<DeviceId> connected = new HashSet<>();
+
+        @Override
+        public LinkProviderService register(LinkProvider provider) {
+            this.provider = provider;
+            return new TestLinkProviderService();
+        }
+
+        @Override
+        public void unregister(LinkProvider provider) {
+
+        }
+
+        @Override
+        public Set<ProviderId> getProviders() {
+            return null;
+        }
+
+        private class TestLinkProviderService implements LinkProviderService {
+
+            @Override
+            public void linkDetected(LinkDescription linkDescription) {
+
+            }
+
+            @Override
+            public void linkVanished(LinkDescription linkDescription) {
+
+            }
+
+            @Override
+            public void linksVanished(ConnectPoint connectPoint) {
+
+            }
+
+            @Override
+            public void linksVanished(DeviceId deviceId) {
+
+            }
+
+            @Override
+            public LinkProvider provider() {
+                return null;
+            }
+        }
+    }
+
+    /* class implement test controller */
+    private class TestController implements IsisController {
+        protected Set<IsisRouterListener> nodeListener = new CopyOnWriteArraySet<>();
+        protected Set<IsisLinkListener> linkListener = new CopyOnWriteArraySet<>();
+
+        @Override
+        public void addRouterListener(IsisRouterListener nodeListener) {
+            this.nodeListener.add(nodeListener);
+        }
+
+        @Override
+        public void removeRouterListener(IsisRouterListener nodeListener) {
+            this.nodeListener.remove(nodeListener);
+        }
+
+        @Override
+        public void addLinkListener(IsisLinkListener listener) {
+            this.linkListener.add(listener);
+        }
+
+        @Override
+        public void removeLinkListener(IsisLinkListener listener) {
+            this.linkListener.remove(listener);
+        }
+
+        @Override
+        public void updateConfig(JsonNode processesNode) {
+
+        }
+
+        @Override
+        public List<IsisProcess> allConfiguredProcesses() {
+            return null;
+        }
+
+        @Override
+        public Set<IsisRouterListener> listener() {
+            return null;
+        }
+
+        @Override
+        public Set<IsisLinkListener> linkListener() {
+            return null;
+        }
+
+    }
+
+    /* Mock test for device service */
+    private class MockNetConfigRegistryAdapter extends NetworkConfigRegistryAdapter {
+        private ConfigFactory cfgFactory;
+        private Map<ConnectPoint, BandwidthCapacity> classConfig = new HashMap<>();
+
+        @Override
+        public void registerConfigFactory(ConfigFactory configFactory) {
+            cfgFactory = configFactory;
+        }
+
+        @Override
+        public void unregisterConfigFactory(ConfigFactory configFactory) {
+            cfgFactory = null;
+        }
+
+        @Override
+        public <S, C extends Config<S>> C addConfig(S subject, Class<C> configClass) {
+            if (configClass == BandwidthCapacity.class) {
+                BandwidthCapacity devCap = new BandwidthCapacity();
+                classConfig.put((ConnectPoint) subject, devCap);
+
+                JsonNode node = new ObjectNode(new MockJsonNode());
+                ObjectMapper mapper = new ObjectMapper();
+                ConfigApplyDelegate delegate = new InternalApplyDelegate();
+                devCap.init((ConnectPoint) subject, null, node, mapper, delegate);
+                return (C) devCap;
+            }
+
+            return null;
+        }
+
+        @Override
+        public <S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass) {
+            classConfig.remove(subject);
+        }
+
+        @Override
+        public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
+            if (configClass == BandwidthCapacity.class) {
+                return (C) classConfig.get(subject);
+            }
+            return null;
+        }
+
+        private class MockJsonNode extends JsonNodeFactory {
+        }
+
+        // Auxiliary delegate to receive notifications about changes applied to
+        // the network configuration - by the apps.
+        private class InternalApplyDelegate implements ConfigApplyDelegate {
+            @Override
+            public void onApply(Config config) {
+            }
+        }
+    }
+}
\ No newline at end of file