mirror of
https://github.com/opennetworkinglab/onos.git
synced 2026-05-05 12:16:13 +02:00
Added in a second timeout for netconfConnectTimeout
Change-Id: I17c68730b68f7d0db899753dbcea2a570acba8e3
This commit is contained in:
parent
4d0f89acce
commit
334ad69bb8
@ -60,6 +60,12 @@ import static org.onlab.util.Tools.get;
|
||||
@Component(immediate = true)
|
||||
@Service
|
||||
public class NetconfControllerImpl implements NetconfController {
|
||||
private static final int DEFAULT_CONNECT_TIMEOUT_SECONDS = 5;
|
||||
private static final String PROP_NETCONF_CONNECT_TIMEOUT = "netconfConnectTimeout";
|
||||
@Property(name = PROP_NETCONF_CONNECT_TIMEOUT, intValue = DEFAULT_CONNECT_TIMEOUT_SECONDS,
|
||||
label = "Time (in seconds) to wait for a NETCONF connect.")
|
||||
protected static int netconfConnectTimeout = DEFAULT_CONNECT_TIMEOUT_SECONDS;
|
||||
|
||||
private static final String PROP_NETCONF_REPLY_TIMEOUT = "netconfReplyTimeout";
|
||||
private static final int DEFAULT_REPLY_TIMEOUT_SECONDS = 5;
|
||||
@Property(name = PROP_NETCONF_REPLY_TIMEOUT, intValue = DEFAULT_REPLY_TIMEOUT_SECONDS,
|
||||
@ -103,6 +109,7 @@ public class NetconfControllerImpl implements NetconfController {
|
||||
public void modified(ComponentContext context) {
|
||||
if (context == null) {
|
||||
netconfReplyTimeout = DEFAULT_REPLY_TIMEOUT_SECONDS;
|
||||
netconfConnectTimeout = DEFAULT_CONNECT_TIMEOUT_SECONDS;
|
||||
log.info("No component configuration");
|
||||
return;
|
||||
}
|
||||
@ -110,17 +117,33 @@ public class NetconfControllerImpl implements NetconfController {
|
||||
Dictionary<?, ?> properties = context.getProperties();
|
||||
|
||||
int newNetconfReplyTimeout;
|
||||
int newNetconfConnectTimeout;
|
||||
try {
|
||||
String s = get(properties, PROP_NETCONF_REPLY_TIMEOUT);
|
||||
newNetconfReplyTimeout = isNullOrEmpty(s) ?
|
||||
netconfReplyTimeout : Integer.parseInt(s.trim());
|
||||
|
||||
s = get(properties, PROP_NETCONF_CONNECT_TIMEOUT);
|
||||
newNetconfConnectTimeout = isNullOrEmpty(s) ?
|
||||
netconfConnectTimeout : Integer.parseInt(s.trim());
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("Component configuration had invalid value", e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (newNetconfConnectTimeout < 0) {
|
||||
log.warn("netconfConnectTimeout is invalid - less than 0");
|
||||
return;
|
||||
} else if (newNetconfReplyTimeout <= 0) {
|
||||
log.warn("netconfReplyTimeout is invalid - 0 or less.");
|
||||
return;
|
||||
}
|
||||
|
||||
netconfReplyTimeout = newNetconfReplyTimeout;
|
||||
log.info("Settings: {} = {}", PROP_NETCONF_REPLY_TIMEOUT, netconfReplyTimeout);
|
||||
netconfConnectTimeout = newNetconfConnectTimeout;
|
||||
log.info("Settings: {} = {}, {} = {}",
|
||||
PROP_NETCONF_REPLY_TIMEOUT, netconfReplyTimeout, PROP_NETCONF_CONNECT_TIMEOUT, netconfConnectTimeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -50,8 +50,6 @@ public class NetconfSessionImpl implements NetconfSession {
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(NetconfSessionImpl.class);
|
||||
|
||||
|
||||
private static final int CONNECTION_TIMEOUT = 0;
|
||||
private static final String ENDPATTERN = "]]>]]>";
|
||||
private static final String MESSAGE_ID_STRING = "message-id";
|
||||
private static final String HELLO = "<hello";
|
||||
@ -111,8 +109,10 @@ public class NetconfSessionImpl implements NetconfSession {
|
||||
private void startConnection() throws NetconfException {
|
||||
if (!connectionActive) {
|
||||
netconfConnection = new Connection(deviceInfo.ip().toString(), deviceInfo.port());
|
||||
int connectTimeout = NetconfControllerImpl.netconfConnectTimeout;
|
||||
|
||||
try {
|
||||
netconfConnection.connect(null, CONNECTION_TIMEOUT, 5000);
|
||||
netconfConnection.connect(null, 1000 * connectTimeout, 1000 * connectTimeout);
|
||||
} catch (IOException e) {
|
||||
throw new NetconfException("Cannot open a connection with device" + deviceInfo, e);
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.netconf.ctl;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
@ -138,21 +137,28 @@ public class NetconfControllerImplTest {
|
||||
*/
|
||||
@Test
|
||||
public void testActivate() {
|
||||
assertEquals("Incorrect NetConf session timeout, should be default",
|
||||
5, ctrl.netconfReplyTimeout);
|
||||
assertEquals("Incorrect NetConf connect timeout, should be default",
|
||||
5, ctrl.netconfConnectTimeout);
|
||||
assertEquals("Incorrect NetConf reply timeout, should be default",
|
||||
5, ctrl.netconfReplyTimeout);
|
||||
ctrl.activate(null);
|
||||
assertEquals("Incorrect NetConf session timeout, should be default",
|
||||
5, ctrl.netconfReplyTimeout);
|
||||
}
|
||||
assertEquals("Incorrect NetConf connect timeout, should be default",
|
||||
5, ctrl.netconfConnectTimeout);
|
||||
assertEquals("Incorrect NetConf reply timeout, should be default",
|
||||
5, ctrl.netconfReplyTimeout); }
|
||||
|
||||
/**
|
||||
* Test modification of component configuration.
|
||||
*/
|
||||
@Test
|
||||
public void testModified() {
|
||||
assertEquals("Incorrect NetConf connect timeout, should be default",
|
||||
5, ctrl.netconfConnectTimeout);
|
||||
assertEquals("Incorrect NetConf session timeout, should be default",
|
||||
5, ctrl.netconfReplyTimeout);
|
||||
ctrl.modified(context);
|
||||
assertEquals("Incorrect NetConf connect timeout, should be default",
|
||||
2, ctrl.netconfConnectTimeout);
|
||||
assertEquals("Incorrect NetConf session timeout",
|
||||
1, ctrl.netconfReplyTimeout);
|
||||
}
|
||||
@ -388,7 +394,9 @@ public class NetconfControllerImplTest {
|
||||
|
||||
@Override
|
||||
public Object get(Object key) {
|
||||
if (key.equals("netconfReplyTimeout")) {
|
||||
if (key.equals("netconfConnectTimeout")) {
|
||||
return "2";
|
||||
} else if (key.equals("netconfReplyTimeout")) {
|
||||
return "1";
|
||||
}
|
||||
return null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user