Netconf Device Provider Plugin to discover and monitor NETCONF supported Devices.

Change-Id: I6d32c966fd4e9c3581db8285e2d712b6bffdb65c
diff --git a/features/features.xml b/features/features.xml
index ce35e6d..96376e0 100644
--- a/features/features.xml
+++ b/features/features.xml
@@ -129,5 +129,11 @@
         <bundle>mvn:org.onosproject/onos-core-common/@ONOS-VERSION</bundle>
         <bundle>mvn:org.onosproject/onos-core-trivial/@ONOS-VERSION</bundle>
     </feature>
+	
+    <feature name="onos-netconf" version="@FEATURE-VERSION"
+             description="ONOS Netconf providers">
+        <feature>onos-api</feature>        
+        <bundle>mvn:org.onosproject/onos-netconf-provider-device/@ONOS-VERSION</bundle>        
+    </feature>
 
 </features>
diff --git a/providers/netconf/device/pom.xml b/providers/netconf/device/pom.xml
new file mode 100644
index 0000000..0e3de51
--- /dev/null
+++ b/providers/netconf/device/pom.xml
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2015 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-netconf-providers</artifactId>
+		<version>1.2.0-SNAPSHOT</version>
+		<relativePath>../pom.xml</relativePath>
+	</parent>
+
+	<artifactId>onos-netconf-provider-device</artifactId>
+	<packaging>bundle</packaging>
+
+	<description>ONOS Netconf protocol device provider</description>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-shade-plugin</artifactId>
+				<version>2.3</version>
+				<configuration>
+					<filters>
+						<filter>
+							<artifact>com.tailf:JNC</artifact>
+							<includes>
+								<include>com/tailf/jnc/**</include>
+							</includes>
+						</filter>
+						<filter>
+							<artifact>ch.ethz.ganymed:ganymed-ssh2</artifact>
+							<includes>
+								<include>ch/ethz/ssh2/**</include>
+							</includes>
+						</filter>
+						<filter>
+							<artifact>org.jdom:jdom2</artifact>
+							<includes>
+								<include>org/jdom2/**</include>
+							</includes>
+						</filter>
+					</filters>
+				</configuration>
+				<executions>
+					<execution>
+						<phase>package</phase>
+						<goals>
+							<goal>shade</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-scr-plugin</artifactId>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<configuration>
+                    <instructions>
+                        <Export-Package>
+                            com.tailf.jnc,
+                            ch.ethz.ssh2,
+                            ch.ethz.ssh2.auth,
+                            ch.ethz.ssh2.channel,
+                            ch.ethz.ssh2.crypto,
+                            ch.ethz.ssh2.crypto.cipher,
+                            ch.ethz.ssh2.crypto.dh,
+                            ch.ethz.ssh2.crypto.digest,
+                            ch.ethz.ssh2.log,
+                            ch.ethz.ssh2.packets,
+                            ch.ethz.ssh2.server,
+                            ch.ethz.ssh2.sftp,
+                            ch.ethz.ssh2.signature,
+                            ch.ethz.ssh2.transport,
+                            ch.ethz.ssh2.util,
+							org.jdom2,
+							org.jdom2.input,
+							org.jdom2.output,
+							org.jdom2.adapters,
+							org.jdom2.filter,
+							org.jdom2.internal,
+							org.jdom2.located,
+							org.jdom2.transform,
+							org.jdom2.util,
+							org.jdom2.xpath,
+							org.jdom2.input.sax,
+							org.jdom2.input.stax,
+							org.jdom2.output.support,
+							org.jdom2.xpath.jaxen,
+							org.jdom2.xpath.util
+                        </Export-Package>
+                    </instructions>
+                </configuration>				
+			</plugin>
+			<plugin>
+				<groupId>org.onosproject</groupId>
+				<artifactId>onos-maven-plugin</artifactId>
+			</plugin>
+		</plugins>
+	</build>
+	<dependencies>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.compendium</artifactId>
+		</dependency>
+		 <dependency>
+            <groupId>ch.ethz.ganymed</groupId>
+            <artifactId>ganymed-ssh2</artifactId>
+            <version>262</version>
+        </dependency>
+        <dependency>
+            <!-- TODO: change this appropriately when the official TailF JNC is available -->
+            <groupId>org.onosproject</groupId>
+            <artifactId>jnc</artifactId>
+            <version>1.0</version>
+        </dependency>
+		<dependency>
+			<groupId>org.jdom</groupId>
+			<artifactId>jdom2</artifactId>
+			<version>2.0.5</version>
+		</dependency>
+		<dependency>
+			<groupId>jaxen</groupId>
+			<artifactId>jaxen</artifactId>
+			<version>1.1.4</version>
+			<optional>true</optional>
+		</dependency>
+	</dependencies>
+</project>
diff --git a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDevice.java b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDevice.java
new file mode 100644
index 0000000..c1208fb
--- /dev/null
+++ b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDevice.java
@@ -0,0 +1,312 @@
+/*
+ * Copyright 2015 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.netconf.device.impl;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onlab.util.Tools.delay;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jdom2.Document;
+import org.jdom2.Element;
+import org.jdom2.input.SAXBuilder;
+import org.jdom2.output.Format;
+import org.jdom2.output.XMLOutputter;
+import org.slf4j.Logger;
+
+import com.tailf.jnc.Capabilities;
+import com.tailf.jnc.JNCException;
+import com.tailf.jnc.SSHConnection;
+import com.tailf.jnc.SSHSession;
+
+/**
+ * This is a logical representation of actual NETCONF device, carrying all the
+ * necessary information to connect and execute NETCONF operations.
+ */
+public class NetconfDevice {
+    private static final Logger log = getLogger(NetconfDevice.class);
+
+    /**
+     * The Device State is used to determine whether the device is active or
+     * inactive. This state infomation will help Device Creator to add or delete
+     * the device from the core.
+     */
+    public static enum DeviceState {
+        /* Used to specify Active state of the device */
+        ACTIVE,
+        /* Used to specify In Active state of the device */
+        INACTIVE,
+        /* Used to specify In Valid state of the device */
+        INVALID
+    }
+
+    private static final int DEFAULT_SSH_PORT = 22;
+    private static final String XML_CAPABILITY_KEY = "capability";
+    private static final int EVENTINTERVAL = 2000;
+    private static final int CONNECTION_CHECK_INTERVAL = 3;
+    private static final String INPUT_HELLO_XML_MSG = new StringBuilder(
+                                                                        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
+            .append("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">")
+            .append("<capabilities><capability>urn:ietf:params:netconf:base:1.0</capability>")
+            .append("</capabilities></hello>").toString();
+
+    private String sshHost;
+    private int sshPort = DEFAULT_SSH_PORT;
+    private String username;
+    private String password;
+    private boolean reachable = false;
+
+    private List<String> capabilities = new ArrayList<String>();
+    private SSHConnection sshConnection = null;
+
+    private DeviceState deviceState = DeviceState.INVALID;
+
+    protected NetconfDevice(String sshHost, int sshPort, String username,
+                            String password) {
+        this.username = checkNotNull(username,
+                                     "Netconf Username Cannot be null");
+        this.sshHost = checkNotNull(sshHost, "Netconf Device IP cannot be null");
+        this.sshPort = checkNotNull(sshPort,
+                                    "Netconf Device SSH port cannot be null");
+        this.password = password;
+    }
+
+    /**
+     * This will try to connect to NETCONF device and find all the capabilities.
+     */
+    public void init() throws Exception {
+        try {
+            if (sshConnection == null) {
+                sshConnection = new SSHConnection(sshHost, sshPort);
+                sshConnection.authenticateWithPassword(username, password);
+            }
+            // Send hello message to retrieve capabilities.
+        } catch (IOException e) {
+            NetconfDevice.log
+                    .error("Fatal Error while creating connection to the device: "
+                                   + deviceInfo(), e);
+            throw e;
+        } catch (JNCException e) {
+            NetconfDevice.log.error("Failed to connect to the device: "
+                    + deviceInfo(), e);
+            throw e;
+        }
+
+        hello();
+    }
+
+    private void hello() {
+        SSHSession ssh = null;
+        try {
+            ssh = new SSHSession(sshConnection);
+            String helloRequestXML = INPUT_HELLO_XML_MSG.trim();
+
+            if (NetconfDevice.log.isDebugEnabled()) {
+                NetconfDevice.log
+                        .debug("++++++++++++++++++++++++++++++++++Sending Hello: "
+                                + sshConnection.getGanymedConnection()
+                                        .getHostname()
+                                + "++++++++++++++++++++++++++++++++++");
+                printPrettyXML(helloRequestXML);
+            }
+            ssh.print(helloRequestXML);
+            // ssh.print(endCharSeq);
+            ssh.flush();
+            String xmlResponse = null;
+            int i = CONNECTION_CHECK_INTERVAL;
+            while (!ssh.ready() && i > 0) {
+                delay(EVENTINTERVAL);
+                i--;
+            }
+
+            if (ssh.ready()) {
+                StringBuffer readOne = ssh.readOne();
+                if (readOne == null) {
+                    NetconfDevice.log
+                            .error("The Hello Contains No Capabilites");
+                    throw new JNCException(
+                                           JNCException.SESSION_ERROR,
+                                           "server does not support NETCONF base capability: "
+                                                   + Capabilities.NETCONF_BASE_CAPABILITY);
+                } else {
+                    xmlResponse = readOne.toString().trim();
+
+                    if (NetconfDevice.log.isDebugEnabled()) {
+                        NetconfDevice.log
+                                .debug("++++++++++++++++++++++++++++++++++Reading Capabilities: "
+                                        + sshConnection.getGanymedConnection()
+                                                .getHostname()
+                                        + "++++++++++++++++++++++++++++++++++");
+
+                        printPrettyXML(xmlResponse);
+                    }
+                    processCapabilities(xmlResponse);
+                }
+            }
+            reachable = true;
+        } catch (IOException e) {
+            NetconfDevice.log
+                    .error("Fatal Error while sending Hello Message to the device: "
+                                   + deviceInfo(), e);
+        } catch (JNCException e) {
+            NetconfDevice.log
+                    .error("Fatal Error while sending Hello Message to the device: "
+                                   + deviceInfo(), e);
+        } finally {
+            if (NetconfDevice.log.isDebugEnabled()) {
+                NetconfDevice.log
+                        .debug("Closing the session after successful execution");
+            }
+            ssh.close();
+        }
+    }
+
+    private void processCapabilities(String xmlResponse) throws JNCException {
+        if (xmlResponse.isEmpty()) {
+            NetconfDevice.log.error("The capability response cannot be empty");
+            throw new JNCException(
+                                   JNCException.SESSION_ERROR,
+                                   "server does not support NETCONF base capability: "
+                                           + Capabilities.NETCONF_BASE_CAPABILITY);
+        }
+        try {
+            Document doc = new SAXBuilder()
+                    .build(new StringReader(xmlResponse));
+            Element rootElement = doc.getRootElement();
+            processCapabilities(rootElement);
+        } catch (Exception e) {
+            NetconfDevice.log.error("ERROR while parsing the XML "
+                    + xmlResponse);
+        }
+    }
+
+    private void processCapabilities(Element rootElement) {
+        List<Element> children = rootElement.getChildren();
+        if (children.isEmpty()) {
+            return;
+        }
+        for (Element child : children) {
+
+            if (child.getName().equals(XML_CAPABILITY_KEY)) {
+                capabilities.add(child.getValue());
+            }
+            if (!child.getChildren().isEmpty()) {
+                processCapabilities(child);
+            }
+        }
+    }
+
+    private void printPrettyXML(String xmlstring) {
+        try {
+            Document doc = new SAXBuilder().build(new StringReader(xmlstring));
+            XMLOutputter xmOut = new XMLOutputter(Format.getPrettyFormat());
+            String outputString = xmOut.outputString(doc);
+            if (NetconfDevice.log.isDebugEnabled()) {
+                NetconfDevice.log.debug(outputString);
+            }
+        } catch (Exception e) {
+            NetconfDevice.log.error("ERROR while parsing the XML " + xmlstring,
+                                    e);
+
+        }
+    }
+
+    /**
+     * This would return host IP and host Port, used by this particular Netconf
+     * Device.
+     * @return Device Information.
+     */
+    public String deviceInfo() {
+        return new StringBuilder("host: ").append(sshHost).append(". port: ")
+                .append(sshPort).toString();
+    }
+
+    /**
+     * This will terminate the device connection.
+     */
+    public void disconnect() {
+        sshConnection.close();
+        reachable = false;
+    }
+
+    /**
+     * This will list down all the capabilities supported on the device.
+     * @return Capability list.
+     */
+    public List<String> getCapabilities() {
+        return capabilities;
+    }
+
+    /**
+     * This api is intended to know whether the device is connected or not.
+     * @return true if connected
+     */
+    public boolean isReachable() {
+        return reachable;
+    }
+
+    /**
+     * This will return the IP used connect ssh on the device.
+     * @return Netconf Device IP
+     */
+    public String getSshHost() {
+        return sshHost;
+    }
+
+    /**
+     * This will return the SSH Port used connect the device.
+     * @return SSH Port number
+     */
+    public int getSshPort() {
+        return sshPort;
+    }
+
+    /**
+     * The usename used to connect Netconf Device.
+     * @return Device Username
+     */
+    public String getUsername() {
+        return username;
+    }
+
+    /**
+     * Retrieve current state of the device.
+     * @return Current Device State
+     */
+    public DeviceState getDeviceState() {
+        return deviceState;
+    }
+
+    /**
+     * This is set the state information for the device.
+     * @param deviceState Next Device State
+     */
+    public void setDeviceState(DeviceState deviceState) {
+        this.deviceState = deviceState;
+    }
+
+    /**
+     * Check whether the device is in Active state.
+     * @return true if the device is Active
+     */
+    public boolean isActive() {
+        return deviceState == DeviceState.ACTIVE ? true : false;
+    }
+}
diff --git a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
new file mode 100644
index 0000000..0b2dcc3
--- /dev/null
+++ b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
@@ -0,0 +1,370 @@
+/*
+ * Copyright 2015 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.netconf.device.impl;
+
+import static com.google.common.base.Strings.isNullOrEmpty;
+import static org.onlab.util.Tools.delay;
+import static org.onlab.util.Tools.get;
+import static org.onlab.util.Tools.groupedThreads;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Dictionary;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+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.Modified;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.packet.ChassisId;
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.MastershipRole;
+import org.onosproject.net.device.DefaultDeviceDescription;
+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.DeviceService;
+import org.onosproject.net.provider.AbstractProvider;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.provider.netconf.device.impl.NetconfDevice.DeviceState;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+
+/**
+ * Provider which will try to fetch the details of NETCONF devices from the core
+ * and run a capability discovery on each of the device.
+ */
+@Component(immediate = true)
+public class NetconfDeviceProvider extends AbstractProvider
+        implements DeviceProvider {
+
+    private static final Logger log = getLogger(NetconfDeviceProvider.class);
+
+    private Map<DeviceId, NetconfDevice> netconfDeviceMap = new ConcurrentHashMap<DeviceId, NetconfDevice>();
+
+    private DeviceProviderService providerService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceProviderRegistry providerRegistry;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceService deviceService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected ClusterService clusterService;
+
+    private ExecutorService deviceBuilder = Executors
+            .newFixedThreadPool(1,
+                                groupedThreads("onos/netconf", "device-creator"));
+
+    // Delay between events in ms.
+    private static final int EVENTINTERVAL = 5;
+
+    private static final String SCHEME = "netconf";
+
+    @Property(name = "devConfigs", value = "", label = "Instance-specific configurations")
+    private String devConfigs = null;
+
+    @Property(name = "devPasswords", value = "", label = "Instace-specific password")
+    private String devPasswords = null;
+
+    /**
+     * Creates a provider with the supplier identifier.
+     */
+    public NetconfDeviceProvider() {
+        super(new ProviderId("netconf", "org.onosproject.provider.netconf"));
+    }
+
+    @Activate
+    public void activate(ComponentContext context) {
+        NetconfDeviceProvider.log.info("Netconf Device Provider Started");
+        providerService = providerRegistry.register(this);
+        modified(context);
+    }
+
+    @Deactivate
+    public void deactivate(ComponentContext context) {
+        try {
+            for (Entry<DeviceId, NetconfDevice> deviceEntry : netconfDeviceMap
+                    .entrySet()) {
+                deviceBuilder.submit(new DeviceCreator(deviceEntry.getValue(),
+                                                       false));
+            }
+            deviceBuilder.awaitTermination(1000, TimeUnit.MILLISECONDS);
+        } catch (InterruptedException e) {
+            NetconfDeviceProvider.log.error("Device builder did not terminate");
+        }
+        deviceBuilder.shutdownNow();
+        netconfDeviceMap.clear();
+        providerRegistry.unregister(this);
+        providerService = null;
+        NetconfDeviceProvider.log.info("Stopped");
+    }
+
+    @Modified
+    public void modified(ComponentContext context) {
+        if (context == null) {
+            NetconfDeviceProvider.log.info("No configuration file");
+            return;
+        }
+        Dictionary<?, ?> properties = context.getProperties();
+        String deviceCfgValue = get(properties, "devConfigs");
+        NetconfDeviceProvider.log
+                .info("Getting Device configuration from cfg file: "
+                        + deviceCfgValue);
+        if (!isNullOrEmpty(deviceCfgValue)) {
+            addOrRemoveDevicesConfig(deviceCfgValue);
+        } else {
+            NetconfDeviceProvider.log
+                    .info("Device Configuration value receiviced from the property 'devConfigs': "
+                            + deviceCfgValue + ", is not valid");
+        }
+    }
+
+    private void addOrRemoveDevicesConfig(String deviceConfig) {
+        for (String deviceEntry : deviceConfig.split(",")) {
+            NetconfDevice device = processDeviceEntry(deviceEntry);
+            if (device != null) {
+                NetconfDeviceProvider.log.info("Device Detail: " + "username: "
+                        + device.getUsername() + ", host: "
+                        + device.getSshHost() + ", port: "
+                        + device.getSshPort());
+                if (device.isActive()) {
+                    deviceBuilder.submit(new DeviceCreator(device, true));
+                } else {
+                    deviceBuilder.submit(new DeviceCreator(device, false));
+                }
+            }
+        }
+    }
+
+    private NetconfDevice processDeviceEntry(String deviceEntry) {
+        if (deviceEntry == null) {
+            NetconfDeviceProvider.log
+                    .info("No content for Device Entry, so cannot proceed further.");
+            return null;
+        }
+        NetconfDeviceProvider.log
+                .info("Trying to convert Device Entry String: " + deviceEntry
+                        + " to a Netconf Device Object");
+        NetconfDevice device = null;
+        try {
+            String userInfo = deviceEntry.substring(0, deviceEntry
+                    .lastIndexOf('@'));
+            String hostInfo = deviceEntry.substring(deviceEntry
+                    .lastIndexOf('@') + 1);
+            String[] infoSplit = userInfo.split(":");
+            String username = infoSplit[0];
+            String password = infoSplit[1];
+            infoSplit = hostInfo.split(":");
+            String hostIp = infoSplit[0];
+            Integer hostPort;
+            try {
+                hostPort = Integer.parseInt(infoSplit[1]);
+            } catch (NumberFormatException nfe) {
+                NetconfDeviceProvider.log
+                        .error("Bad Configuration Data: Failed to parse host port number string: "
+                                + infoSplit[1]);
+                throw nfe;
+            }
+            String deviceState = infoSplit[2];
+            if (isNullOrEmpty(username) || isNullOrEmpty(password)
+                    || isNullOrEmpty(hostIp) || hostPort == 0) {
+                NetconfDeviceProvider.log
+                        .warn("Bad Configuration Data: both user and device information parts of Configuration "
+                                + deviceEntry + " should be non-nullable");
+            } else {
+                device = new NetconfDevice(hostIp, hostPort, username, password);
+                if (!isNullOrEmpty(deviceState)) {
+                    if (deviceState.toUpperCase().equals(DeviceState.ACTIVE
+                                                                 .name())) {
+                        device.setDeviceState(DeviceState.ACTIVE);
+                    } else if (deviceState.toUpperCase()
+                            .equals(DeviceState.INACTIVE.name())) {
+                        device.setDeviceState(DeviceState.ACTIVE);
+                    } else {
+                        NetconfDeviceProvider.log
+                                .warn("Device State Information can not be empty, so marking the state as INVALID");
+                        device.setDeviceState(DeviceState.INVALID);
+                    }
+                } else {
+                    NetconfDeviceProvider.log
+                            .warn("The device entry do not specify state information, so marking the state as INVALID");
+                    device.setDeviceState(DeviceState.INVALID);
+                }
+            }
+        } catch (ArrayIndexOutOfBoundsException aie) {
+            NetconfDeviceProvider.log
+                    .error("Error while reading config infromation from the config file: "
+                                   + "The user, host and device state infomation should be "
+                                   + "in the order 'userInfo@hostInfo:deviceState'"
+                                   + deviceEntry, aie);
+        } catch (Exception e) {
+            NetconfDeviceProvider.log
+                    .error("Error while parsing config information for the device entry: "
+                                   + deviceEntry, e);
+        }
+        return device;
+    }
+
+    @Override
+    public void triggerProbe(DeviceId deviceId) {
+        // TODO Auto-generated method stub
+    }
+
+    @Override
+    public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
+
+    }
+
+    @Override
+    public boolean isReachable(DeviceId deviceId) {
+        NetconfDevice netconfDevice = netconfDeviceMap.get(deviceId);
+        if (netconfDevice == null) {
+            NetconfDeviceProvider.log
+                    .warn("BAD REQUEST: the requested device id: "
+                            + deviceId.toString()
+                            + "  is not associated to any NETCONF Device");
+            return false;
+        }
+        return netconfDevice.isReachable();
+    }
+
+    /**
+     * This class is intended to add or remove Configured Netconf Devices.
+     * Functionality relies on 'createFlag' and 'NetconfDevice' content. The
+     * functionality runs as a thread and dependening on the 'createFlag' value
+     * it will create or remove Device entry from the core.
+     */
+    private class DeviceCreator implements Runnable {
+
+        private NetconfDevice device;
+        private boolean createFlag;
+
+        public DeviceCreator(NetconfDevice device, boolean createFlag) {
+            this.device = device;
+            this.createFlag = createFlag;
+        }
+
+        @Override
+        public void run() {
+            if (createFlag && (device.getDeviceState() == DeviceState.ACTIVE)) {
+                NetconfDeviceProvider.log
+                        .info("Trying to create Device Info on ONOS core");
+                advertiseDevices();
+            } else {
+                NetconfDeviceProvider.log
+                        .info("Trying to remove Device Info on ONOS core");
+                removeDevices();
+            }
+        }
+
+        /**
+         * For each Netconf Device, remove the entry from the device store.
+         */
+        private void removeDevices() {
+            if (!device.isReachable()) {
+                log.error("BAD Request: 'Currently device is not discovered, so cannot remove/disconnect the device: "
+                        + device.deviceInfo() + "'");
+                return;
+            }
+            try {
+                DeviceId did = getDeviceId();
+                providerService.deviceDisconnected(did);
+                device.disconnect();
+                delay(EVENTINTERVAL);
+            } catch (URISyntaxException uriSyntaxExcpetion) {
+                NetconfDeviceProvider.log
+                        .error("Syntax Error while creating URI for the device: "
+                                       + device.deviceInfo()
+                                       + " couldn't remove the device from the store",
+                               uriSyntaxExcpetion);
+            }
+        }
+
+        /**
+         * Initialize Netconf Device object, and notify core saying device
+         * connected.
+         */
+        private void advertiseDevices() {
+            try {
+                if (device == null) {
+                    NetconfDeviceProvider.log
+                            .warn("The Request Netconf Device is null, cannot proceed further");
+                    return;
+                }
+                device.init();
+                DeviceId did = getDeviceId();
+                ChassisId cid = new ChassisId();
+                DeviceDescription desc = new DefaultDeviceDescription(
+                                                                      did.uri(),
+                                                                      Device.Type.OTHER,
+                                                                      "", "",
+                                                                      "", "",
+                                                                      cid);
+                if (NetconfDeviceProvider.log.isDebugEnabled()) {
+                    NetconfDeviceProvider.log.debug("Persisting Device"
+                            + did.uri().toString());
+                }
+
+                netconfDeviceMap.put(did, device);
+                providerService.deviceConnected(did, desc);
+                if (NetconfDeviceProvider.log.isDebugEnabled()) {
+                    NetconfDeviceProvider.log
+                            .debug("Done with Device Info Creation on ONOS core. Device Info: "
+                                    + device.deviceInfo()
+                                    + " "
+                                    + did.uri().toString());
+                }
+                delay(EVENTINTERVAL);
+            } catch (URISyntaxException e) {
+                NetconfDeviceProvider.log
+                        .error("Syntax Error while creating URI for the device: "
+                                       + device.deviceInfo()
+                                       + " couldn't persist the device onto the store",
+                               e);
+            } catch (Exception e) {
+                NetconfDeviceProvider.log
+                        .error("Error while initializing session for the device: "
+                                       + device.deviceInfo(), e);
+            }
+        }
+
+        /**
+         * This will build a device id for the device.
+         */
+        private DeviceId getDeviceId() throws URISyntaxException {
+            String additionalSSP = new StringBuilder(device.getUsername())
+                    .append("@").append(device.getSshHost()).append(":")
+                    .append(device.getSshPort()).toString();
+            DeviceId did = DeviceId.deviceId(new URI(SCHEME, additionalSSP,
+                                                     null));
+            return did;
+        }
+    }
+}
diff --git a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/package-info.java b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/package-info.java
new file mode 100644
index 0000000..583aeaa
--- /dev/null
+++ b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015 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 Netconf capability request as a means of infrastructure device discovery.
+ */
+package org.onosproject.provider.netconf.device.impl;
\ No newline at end of file
diff --git a/providers/netconf/pom.xml b/providers/netconf/pom.xml
new file mode 100644
index 0000000..20e98a2
--- /dev/null
+++ b/providers/netconf/pom.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2015 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-providers</artifactId>
+        <version>1.2.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>onos-netconf-providers</artifactId>
+    <packaging>pom</packaging>
+
+    <description>ONOS Netconf protocol adapters</description>
+
+    <modules>
+        <module>device</module>        
+    </modules>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-api</artifactId>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>
diff --git a/providers/pom.xml b/providers/pom.xml
index 70d867e..09d3487 100644
--- a/providers/pom.xml
+++ b/providers/pom.xml
@@ -35,6 +35,7 @@
         <module>openflow</module>
         <module>lldp</module>
         <module>host</module>
+        <module>netconf</module>
         <module>null</module>
     </modules>
 
diff --git a/tools/package/etc/samples/org.onosproject.provider.netconf.device.impl.NetconfDeviceProvider.cfg b/tools/package/etc/samples/org.onosproject.provider.netconf.device.impl.NetconfDeviceProvider.cfg
new file mode 100644
index 0000000..30ed0c2
--- /dev/null
+++ b/tools/package/etc/samples/org.onosproject.provider.netconf.device.impl.NetconfDeviceProvider.cfg
@@ -0,0 +1,11 @@
+#
+# Instance-specific configurations, in this case, the number of 
+# devices per node.
+#
+devConfigs = cisco:cisco@192.168.56.20:2022:inactive,sdn:rocks@192.168.56.30:22:inactive
+
+#
+# Number of ports per device. This is global to all devices
+# on all instances.
+#
+# numPorts = 8