- private boolean isDeviceConnected() {
- return ConnectionContext.CONNECTION_STATE.WORKING.equals(
- deviceContext.getPrimaryConnectionContext().getConnectionState());
- }
-
- @Nullable
- @Override
- public <T> RequestContext<T> createRequestContext() {
- final AbstractRequestContext<T> ret = new AbstractRequestContext<T>(deviceContext.getReservedXid()) {
- @Override
- public void close() {
- }
- };
- return ret;
+ private ListenableFuture<RpcResult<SetRoleOutput>> sendRoleChangeToDevice(final OfpRole newRole) {
+ LOG.debug("Sending new role {} to device {}", newRole, deviceInfo.getNodeId());
+ final Future<RpcResult<SetRoleOutput>> setRoleOutputFuture;
+ final Short version = deviceInfo.getVersion();
+ if (null == version) {
+ LOG.debug("Device version is null");
+ return Futures.immediateFuture(null);
+ }
+ if (version < OFConstants.OFP_VERSION_1_3) {
+ LOG.debug("Device version not support ROLE");
+ return Futures.immediateFuture(null);
+ } else {
+ final SetRoleInput setRoleInput = (new SetRoleInputBuilder()).setControllerRole(newRole)
+ .setNode(new NodeRef(DeviceStateUtil.createNodeInstanceIdentifier(deviceInfo.getNodeId()))).build();
+ setRoleOutputFuture = getSalRoleService().setRole(setRoleInput);
+ final TimerTask timerTask = timeout -> {
+ if (!setRoleOutputFuture.isDone()) {
+ LOG.warn("New role {} was not propagated to device {} during 10 sec", newRole, deviceInfo.getLOGValue());
+ setRoleOutputFuture.cancel(true);
+ }
+ };
+ hashedWheelTimer.newTimeout(timerTask, 10, TimeUnit.SECONDS);
+ }
+ return JdkFutureAdapters.listenInPoolThread(setRoleOutputFuture);