+ if (flowNode.isPresent()) {
+ LOG.debug("FlowNode present for Datapath ID {}", dpnId);
+ final NodeRef nodeRef = new NodeRef(nodeIdentity.firstIdentifierOf(Node.class));
+
+ final ControlBundleInput closeBundleInput = new ControlBundleInputBuilder().setNode(nodeRef)
+ .setBundleId(bundleIdValue).setFlags(BUNDLE_FLAGS)
+ .setType(BundleControlType.ONFBCTCLOSEREQUEST).build();
+
+ final ControlBundleInput openBundleInput = new ControlBundleInputBuilder().setNode(nodeRef)
+ .setBundleId(bundleIdValue).setFlags(BUNDLE_FLAGS).setType(BundleControlType.ONFBCTOPENREQUEST)
+ .build();
+
+ final ControlBundleInput commitBundleInput = new ControlBundleInputBuilder().setNode(nodeRef)
+ .setBundleId(bundleIdValue).setFlags(BUNDLE_FLAGS)
+ .setType(BundleControlType.ONFBCTCOMMITREQUEST).build();
+
+ final AddBundleMessagesInput addBundleMessagesInput = new AddBundleMessagesInputBuilder()
+ .setNode(nodeRef).setBundleId(bundleIdValue).setFlags(BUNDLE_FLAGS)
+ .setMessages(createMessages(nodeRef, flowNode)).build();
+
+ /* Close previously opened bundle on the openflow switch if any */
+ ListenableFuture<RpcResult<ControlBundleOutput>> closeBundle
+ = salBundleService.controlBundle(closeBundleInput);
+
+ /* Open a new bundle on the switch */
+ ListenableFuture<RpcResult<ControlBundleOutput>> openBundle =
+ Futures.transformAsync(closeBundle,
+ rpcResult -> salBundleService.controlBundle(openBundleInput),
+ MoreExecutors.directExecutor());
+
+ /* Push groups and flows via bundle add messages */
+ ListenableFuture<RpcResult<AddBundleMessagesOutput>> addBundleMessagesFuture
+ = Futures.transformAsync(openBundle, rpcResult -> {
+ if (rpcResult.isSuccessful()) {
+ return salBundleService.addBundleMessages(addBundleMessagesInput);
+ }
+ return Futures.immediateFuture(null);
+ }, MoreExecutors.directExecutor());
+
+ /* Commit the bundle on the openflow switch */
+ ListenableFuture<RpcResult<ControlBundleOutput>> commitBundleFuture
+ = Futures.transformAsync(addBundleMessagesFuture, rpcResult -> {
+ if (rpcResult.isSuccessful()) {
+ return salBundleService.controlBundle(commitBundleInput);
+ }
+ return Futures.immediateFuture(null);
+ }, MoreExecutors.directExecutor());
+
+ /* Bundles not supported for meters */
+ List<Meter> meters = flowNode.get().getMeter() != null ? flowNode.get().getMeter()
+ : Collections.emptyList();
+ Futures.transformAsync(commitBundleFuture,
+ rpcResult -> {
+ if (rpcResult.isSuccessful()) {
+ for (Meter meter : meters) {
+ final KeyedInstanceIdentifier<Meter, MeterKey> meterIdent = nodeIdentity
+ .child(Meter.class, meter.key());
+ provider.getMeterCommiter().add(meterIdent, meter, nodeIdentity);
+ }
+ }
+ return Futures.immediateFuture(null);
+ }, MoreExecutors.directExecutor());
+
+ trans.close();
+ try {
+ if (commitBundleFuture.get().isSuccessful()) {
+ LOG.debug("Completing bundle based reconciliation for device ID:{}", dpnId);
+ return true;
+ } else {
+ return false;
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error while doing bundle based reconciliation for device ID:{}", nodeIdentity);
+ return false;
+ }