Sanjay S
Committed by Gerrit Code Review

Added configurable connection timeout for Netconf Server connection.

Change-Id: I40fd1737529e5e864f16119293e46340243118cb
......@@ -58,6 +58,7 @@ public class NetconfDevice {
}
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 @@ public class NetconfDevice {
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 class NetconfDevice {
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 class NetconfDevice {
public boolean isActive() {
return deviceState == DeviceState.ACTIVE ? true : false;
}
public void setConnectTimeout(int connectTimeout) {
this.connectTimeout = connectTimeout;
}
}
......
......@@ -21,6 +21,8 @@ import static org.onlab.util.Tools.get;
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 @@ public class NetconfDeviceProvider extends AbstractProvider
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);
......
......@@ -22,6 +22,7 @@ import static org.onlab.util.Tools.delay;
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 java.util.concurrent.ConcurrentHashMap;
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 @@ public class NetconfDeviceProviderTest {
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 @@ public class NetconfDeviceProviderTest {
* 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 @@ public class NetconfDeviceProviderTest {
+ " 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) {
......