Added configurable connection timeout for Netconf Server connection.
Change-Id: I40fd1737529e5e864f16119293e46340243118cb
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
index 7b56b88..440c045 100644
--- 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
@@ -58,6 +58,7 @@
}
private static final int DEFAULT_SSH_PORT = 22;
+ private static final int DEFAULT_CON_TIMEOUT = 0;
private static final String XML_CAPABILITY_KEY = "capability";
private static final int EVENTINTERVAL = 2000;
private static final int CONNECTION_CHECK_INTERVAL = 3;
@@ -69,6 +70,7 @@
private String sshHost;
private int sshPort = DEFAULT_SSH_PORT;
+ private int connectTimeout = DEFAULT_CON_TIMEOUT;
private String username;
private String password;
private boolean reachable = false;
@@ -97,7 +99,7 @@
public void init() throws Exception {
try {
if (sshConnection == null) {
- sshConnection = new SSHConnection(sshHost, sshPort);
+ sshConnection = new SSHConnection(sshHost, sshPort, connectTimeout);
sshConnection.authenticateWithPassword(username, password);
}
// Send hello message to retrieve capabilities.
@@ -293,4 +295,8 @@
public boolean isActive() {
return deviceState == DeviceState.ACTIVE ? true : false;
}
+
+ public void setConnectTimeout(int connectTimeout) {
+ this.connectTimeout = connectTimeout;
+ }
}
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
index e3399f6..9a8c1bd 100644
--- 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
@@ -21,6 +21,8 @@
import static org.onlab.util.Tools.groupedThreads;
import static org.slf4j.LoggerFactory.getLogger;
+import java.io.IOException;
+import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Dictionary;
@@ -329,6 +331,12 @@
log.error("Syntax Error while creating URI for the device: "
+ device.deviceInfo()
+ " couldn't persist the device onto the store", e);
+ } catch (SocketTimeoutException e) {
+ log.error("Error while setting connection for the device: "
+ + device.deviceInfo(), e);
+ } catch (IOException e) {
+ log.error("Error while setting connection for the device: "
+ + device.deviceInfo(), e);
} catch (Exception e) {
log.error("Error while initializing session for the device: "
+ device.deviceInfo(), e);
diff --git a/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTest.java b/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTest.java
index 4fa9644..6bb8082 100644
--- a/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTest.java
+++ b/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTest.java
@@ -22,6 +22,7 @@
import static org.slf4j.LoggerFactory.getLogger;
import java.io.IOException;
+import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
@@ -34,7 +35,6 @@
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.onlab.packet.ChassisId;
import org.onosproject.cfg.ComponentConfigService;
@@ -179,15 +179,12 @@
return dictionary;
}
- @Ignore
- @Test(expected = IOException.class)
- public void testSSHAuthentication() throws IOException, JNCException {
- TestDeviceCreator objForTestDev = new TestDeviceCreator(
- new NetconfDevice(
- "10.18.14.19",
- 22,
- "cisco",
- "cisco"),
+ @Test(expected = SocketTimeoutException.class)
+ public void testSSHAuthentication() throws JNCException, IOException {
+ NetconfDevice netconfDevice = new NetconfDevice("10.18.14.19", 22,
+ "cisco", "cisco");
+ netconfDevice.setConnectTimeout(1000);
+ TestDeviceCreator objForTestDev = new TestDeviceCreator(netconfDevice,
true);
objForTestDev.run();
}
@@ -344,7 +341,8 @@
* Initialize Netconf Device object, and notify core saying device
* connected.
*/
- private void advertiseDevices() throws JNCException, IOException {
+ private void advertiseDevices()
+ throws JNCException, IOException, SocketTimeoutException {
try {
if (device == null) {
log.warn("The Request Netconf Device is null, cannot proceed further");
@@ -372,6 +370,8 @@
+ " couldn't persist the device onto the store", e);
} catch (JNCException e) {
throw e;
+ } catch (SocketTimeoutException e) {
+ throw e;
} catch (IOException e) {
throw e;
} catch (Exception e) {