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 { ...@@ -58,6 +58,7 @@ public class NetconfDevice {
58 } 58 }
59 59
60 private static final int DEFAULT_SSH_PORT = 22; 60 private static final int DEFAULT_SSH_PORT = 22;
61 + private static final int DEFAULT_CON_TIMEOUT = 0;
61 private static final String XML_CAPABILITY_KEY = "capability"; 62 private static final String XML_CAPABILITY_KEY = "capability";
62 private static final int EVENTINTERVAL = 2000; 63 private static final int EVENTINTERVAL = 2000;
63 private static final int CONNECTION_CHECK_INTERVAL = 3; 64 private static final int CONNECTION_CHECK_INTERVAL = 3;
...@@ -69,6 +70,7 @@ public class NetconfDevice { ...@@ -69,6 +70,7 @@ public class NetconfDevice {
69 70
70 private String sshHost; 71 private String sshHost;
71 private int sshPort = DEFAULT_SSH_PORT; 72 private int sshPort = DEFAULT_SSH_PORT;
73 + private int connectTimeout = DEFAULT_CON_TIMEOUT;
72 private String username; 74 private String username;
73 private String password; 75 private String password;
74 private boolean reachable = false; 76 private boolean reachable = false;
...@@ -97,7 +99,7 @@ public class NetconfDevice { ...@@ -97,7 +99,7 @@ public class NetconfDevice {
97 public void init() throws Exception { 99 public void init() throws Exception {
98 try { 100 try {
99 if (sshConnection == null) { 101 if (sshConnection == null) {
100 - sshConnection = new SSHConnection(sshHost, sshPort); 102 + sshConnection = new SSHConnection(sshHost, sshPort, connectTimeout);
101 sshConnection.authenticateWithPassword(username, password); 103 sshConnection.authenticateWithPassword(username, password);
102 } 104 }
103 // Send hello message to retrieve capabilities. 105 // Send hello message to retrieve capabilities.
...@@ -293,4 +295,8 @@ public class NetconfDevice { ...@@ -293,4 +295,8 @@ public class NetconfDevice {
293 public boolean isActive() { 295 public boolean isActive() {
294 return deviceState == DeviceState.ACTIVE ? true : false; 296 return deviceState == DeviceState.ACTIVE ? true : false;
295 } 297 }
298 +
299 + public void setConnectTimeout(int connectTimeout) {
300 + this.connectTimeout = connectTimeout;
301 + }
296 } 302 }
......
...@@ -21,6 +21,8 @@ import static org.onlab.util.Tools.get; ...@@ -21,6 +21,8 @@ import static org.onlab.util.Tools.get;
21 import static org.onlab.util.Tools.groupedThreads; 21 import static org.onlab.util.Tools.groupedThreads;
22 import static org.slf4j.LoggerFactory.getLogger; 22 import static org.slf4j.LoggerFactory.getLogger;
23 23
24 +import java.io.IOException;
25 +import java.net.SocketTimeoutException;
24 import java.net.URI; 26 import java.net.URI;
25 import java.net.URISyntaxException; 27 import java.net.URISyntaxException;
26 import java.util.Dictionary; 28 import java.util.Dictionary;
...@@ -329,6 +331,12 @@ public class NetconfDeviceProvider extends AbstractProvider ...@@ -329,6 +331,12 @@ public class NetconfDeviceProvider extends AbstractProvider
329 log.error("Syntax Error while creating URI for the device: " 331 log.error("Syntax Error while creating URI for the device: "
330 + device.deviceInfo() 332 + device.deviceInfo()
331 + " couldn't persist the device onto the store", e); 333 + " couldn't persist the device onto the store", e);
334 + } catch (SocketTimeoutException e) {
335 + log.error("Error while setting connection for the device: "
336 + + device.deviceInfo(), e);
337 + } catch (IOException e) {
338 + log.error("Error while setting connection for the device: "
339 + + device.deviceInfo(), e);
332 } catch (Exception e) { 340 } catch (Exception e) {
333 log.error("Error while initializing session for the device: " 341 log.error("Error while initializing session for the device: "
334 + device.deviceInfo(), e); 342 + device.deviceInfo(), e);
......
...@@ -22,6 +22,7 @@ import static org.onlab.util.Tools.delay; ...@@ -22,6 +22,7 @@ import static org.onlab.util.Tools.delay;
22 import static org.slf4j.LoggerFactory.getLogger; 22 import static org.slf4j.LoggerFactory.getLogger;
23 23
24 import java.io.IOException; 24 import java.io.IOException;
25 +import java.net.SocketTimeoutException;
25 import java.net.URI; 26 import java.net.URI;
26 import java.net.URISyntaxException; 27 import java.net.URISyntaxException;
27 import java.util.Collection; 28 import java.util.Collection;
...@@ -34,7 +35,6 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -34,7 +35,6 @@ import java.util.concurrent.ConcurrentHashMap;
34 import org.easymock.EasyMock; 35 import org.easymock.EasyMock;
35 import org.junit.After; 36 import org.junit.After;
36 import org.junit.Before; 37 import org.junit.Before;
37 -import org.junit.Ignore;
38 import org.junit.Test; 38 import org.junit.Test;
39 import org.onlab.packet.ChassisId; 39 import org.onlab.packet.ChassisId;
40 import org.onosproject.cfg.ComponentConfigService; 40 import org.onosproject.cfg.ComponentConfigService;
...@@ -179,15 +179,12 @@ public class NetconfDeviceProviderTest { ...@@ -179,15 +179,12 @@ public class NetconfDeviceProviderTest {
179 return dictionary; 179 return dictionary;
180 } 180 }
181 181
182 - @Ignore 182 + @Test(expected = SocketTimeoutException.class)
183 - @Test(expected = IOException.class) 183 + public void testSSHAuthentication() throws JNCException, IOException {
184 - public void testSSHAuthentication() throws IOException, JNCException { 184 + NetconfDevice netconfDevice = new NetconfDevice("10.18.14.19", 22,
185 - TestDeviceCreator objForTestDev = new TestDeviceCreator( 185 + "cisco", "cisco");
186 - new NetconfDevice( 186 + netconfDevice.setConnectTimeout(1000);
187 - "10.18.14.19", 187 + TestDeviceCreator objForTestDev = new TestDeviceCreator(netconfDevice,
188 - 22,
189 - "cisco",
190 - "cisco"),
191 true); 188 true);
192 objForTestDev.run(); 189 objForTestDev.run();
193 } 190 }
...@@ -344,7 +341,8 @@ public class NetconfDeviceProviderTest { ...@@ -344,7 +341,8 @@ public class NetconfDeviceProviderTest {
344 * Initialize Netconf Device object, and notify core saying device 341 * Initialize Netconf Device object, and notify core saying device
345 * connected. 342 * connected.
346 */ 343 */
347 - private void advertiseDevices() throws JNCException, IOException { 344 + private void advertiseDevices()
345 + throws JNCException, IOException, SocketTimeoutException {
348 try { 346 try {
349 if (device == null) { 347 if (device == null) {
350 log.warn("The Request Netconf Device is null, cannot proceed further"); 348 log.warn("The Request Netconf Device is null, cannot proceed further");
...@@ -372,6 +370,8 @@ public class NetconfDeviceProviderTest { ...@@ -372,6 +370,8 @@ public class NetconfDeviceProviderTest {
372 + " couldn't persist the device onto the store", e); 370 + " couldn't persist the device onto the store", e);
373 } catch (JNCException e) { 371 } catch (JNCException e) {
374 throw e; 372 throw e;
373 + } catch (SocketTimeoutException e) {
374 + throw e;
375 } catch (IOException e) { 375 } catch (IOException e) {
376 throw e; 376 throw e;
377 } catch (Exception e) { 377 } catch (Exception e) {
......