- private static void translateAndWriteReply(final MultipartType type, final DeviceContext dContext,
- final InstanceIdentifier<Node> nodeII, final Collection<MultipartReply> result) {
- for (final MultipartReply reply : result) {
- final MultipartReplyBody body = reply.getMultipartReplyBody();
- switch (type) {
- case OFPMPDESC:
- Preconditions.checkArgument(body instanceof MultipartReplyDescCase);
- final MultipartReplyDesc replyDesc = ((MultipartReplyDescCase) body).getMultipartReplyDesc();
- final FlowCapableNode fcNode = NodeStaticReplyTranslatorUtil.nodeDescTranslator(replyDesc);
- final InstanceIdentifier<FlowCapableNode> fNodeII = nodeII.augmentation(FlowCapableNode.class);
- dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, fNodeII, fcNode);
- break;
-
- case OFPMPTABLEFEATURES:
- Preconditions.checkArgument(body instanceof MultipartReplyTableFeaturesCase);
- final MultipartReplyTableFeatures tableFeatures = ((MultipartReplyTableFeaturesCase) body).getMultipartReplyTableFeatures();
- final List<TableFeatures> tables = NodeStaticReplyTranslatorUtil.nodeTableFeatureTranslator(tableFeatures);
- for (final TableFeatures table : tables) {
- final Short tableId = table.getTableId();
- final InstanceIdentifier<Table> tableII = nodeII.augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId));
- dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tableII, new TableBuilder().setId(tableId).setTableFeatures(Collections.singletonList(table)).build());
+ @Override
+ public void setDeviceTerminationPhaseHandler(final DeviceTerminationPhaseHandler handler) {
+ this.deviceTerminPhaseHandler = handler;
+ }
+
+ @Override
+ public void onDeviceDisconnected(final ConnectionContext connectionContext) {
+ LOG.trace("onDeviceDisconnected method call for Node: {}", connectionContext.getNodeId());
+ Preconditions.checkArgument(connectionContext != null);
+ final NodeId nodeId = connectionContext.getNodeId();
+ final DeviceContext deviceCtx = this.deviceContexts.get(nodeId);
+
+ if (null == deviceCtx) {
+ LOG.info("DeviceContext for Node {} was not found. Connection is terminated without OFP context suite.",
+ connectionContext.getNodeId());
+ return;
+ }
+
+ if (!connectionContext.equals(deviceCtx.getPrimaryConnectionContext())) {
+ /* Connection is not PrimaryConnection so try to remove from Auxiliary Connections */
+ deviceCtx.removeAuxiliaryConnectionContext(connectionContext);
+ } else {
+ /* Device is disconnected and so we need to close TxManager */
+ final ListenableFuture<Void> future = deviceCtx.shuttingDownDataStoreTransactions();
+ Futures.addCallback(future, new FutureCallback<Void>() {
+
+ @Override
+ public void onSuccess(final Void result) {
+ LOG.debug("TxChainManager for device {} is closed successful.", deviceCtx.getDeviceState().getNodeId());
+ deviceTerminPhaseHandler.onDeviceContextLevelDown(deviceCtx);
+ }
+
+ @Override
+ public void onFailure(final Throwable t) {
+ LOG.warn("TxChainManager for device {} failed by closing.", deviceCtx.getDeviceState().getNodeId(), t);
+ deviceTerminPhaseHandler.onDeviceContextLevelDown(deviceCtx);
+ }
+ });
+ /* Add timer for Close TxManager because it could fain ind cluster without notification */
+ final TimerTask timerTask = new TimerTask() {
+
+ @Override
+ public void run(final Timeout timeout) throws Exception {
+ if (!future.isDone()) {
+ LOG.info("Shutting down TxChain for node {} not completed during 10 sec. Continue anyway.",
+ deviceCtx.getDeviceState().getNodeId());
+ future.cancel(false);