BUG-1997: moving barrier after message
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / OFRpcTaskFactory.java
index 5cbb4f9ea28e5bbe0b1b270e8d48563ed0e07a98..5c5e9de7cc1558805b8699985773c4124c23a5ed 100644 (file)
@@ -7,17 +7,16 @@
  */
 package org.opendaylight.openflowplugin.openflow.md.core.sal;
 
-import com.google.common.util.concurrent.AsyncFunction;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.JdkFutureAdapters;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.SettableFuture;
-import org.opendaylight.controller.sal.common.util.RpcErrors;
-import org.opendaylight.controller.sal.common.util.Rpcs;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Future;
+
 import org.opendaylight.openflowjava.protocol.api.util.BinContent;
-import org.opendaylight.openflowplugin.openflow.md.OFConstants;
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
+import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
+import org.opendaylight.openflowplugin.api.openflow.md.core.sal.NotificationComposer;
+import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
@@ -26,8 +25,8 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeatu
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
-import org.opendaylight.openflowplugin.openflow.md.util.OpenflowVersion;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
@@ -157,25 +156,24 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder;
-import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.Future;
+import com.google.common.util.concurrent.AsyncFunction;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.JdkFutureAdapters;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
 
 /**
  *
  */
 public abstract class OFRpcTaskFactory {
-    private static final Logger logger = LoggerFactory.getLogger(OFRpcTaskFactory.class);
+    protected static final Logger logger = LoggerFactory.getLogger(OFRpcTaskFactory.class);
 
     /**
      * @param taskContext 
@@ -184,7 +182,7 @@ public abstract class OFRpcTaskFactory {
      * @return UpdateFlow task
      */
     public static OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> createAddFlowTask(
-            OFRpcTaskContext taskContext, AddFlowInput input, 
+            OFRpcTaskContext taskContext, AddFlowInput input,
             SwitchConnectionDistinguisher cookie) {
         OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> task = 
                 new OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>>(taskContext, cookie, input) {
@@ -193,26 +191,26 @@ public abstract class OFRpcTaskFactory {
             public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
                 ListenableFuture<RpcResult<UpdateFlowOutput>> result = SettableFuture.create();
                 
-                Collection<RpcError> barrierErrors = OFRpcTaskUtil.manageBarrier(getTaskContext(), getInput().isBarrier(), getCookie());
-                if (!barrierErrors.isEmpty()) {
-                    OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateFlowOutput>>) result), barrierErrors);
-                } else {
-                    // Convert the AddFlowInput to FlowModInput
-                    List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput(),
-                            getVersion(), getSession().getFeatures().getDatapathId());
+                // Convert the AddFlowInput to FlowModInput
+                List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput(),
+                        getVersion(), getSession().getFeatures().getDatapathId());
 
-                    logger.debug("Number of flows to push to switch: {}", ofFlowModInputs.size());
+                logger.debug("Number of flows to push to switch: {}", ofFlowModInputs.size());
 
-                    Long xId = getSession().getNextXid();
+                result = chainFlowMods(ofFlowModInputs, 0, getTaskContext(), getCookie());
 
-                    result = chainFlowMods(ofFlowModInputs, 0, getTaskContext(), getCookie());
-
-                    OFRpcTaskUtil.hookFutureNotification(this, result,
-                        getRpcNotificationProviderService(),
-                        createFlowAddedNotification(xId, getInput()));
-                }
+                
+                result = OFRpcTaskUtil.chainFutureBarrier(this, result);
+                OFRpcTaskUtil.hookFutureNotification(this, result,
+                    getRpcNotificationProviderService(),
+                    createFlowAddedNotification(getInput()));
                 return result;
             }
+            
+            @Override
+            public Boolean isBarrier() {
+                return getInput().isBarrier();
+            }
         };
         return task;
     }
@@ -225,7 +223,7 @@ public abstract class OFRpcTaskFactory {
      * All the flowmods should have the same xid, in-order to cross-reference
      * the notification
      */
-    private static ListenableFuture<RpcResult<UpdateFlowOutput>> chainFlowMods(
+    protected static ListenableFuture<RpcResult<UpdateFlowOutput>> chainFlowMods(
         final List<FlowModInputBuilder> ofFlowModInputs, final int index,
         final OFRpcTaskContext taskContext, final SwitchConnectionDistinguisher cookie) {
 
@@ -244,7 +242,7 @@ public abstract class OFRpcTaskFactory {
                             return chainFlowMods(ofFlowModInputs, index + 1, taskContext, cookie);
                         } else {
                             logger.warn("Flowmod failed. Any chained flowmods are ignored. xid:{}",
-                                taskContext.getSession().getFeatures().getXid());
+                                ofFlowModInputs.get(index).getXid());
                             return Futures.immediateFuture(input);
                         }
                     }
@@ -258,22 +256,22 @@ public abstract class OFRpcTaskFactory {
     private static Future<RpcResult<UpdateFlowOutput>> createResultForFlowMod(
         OFRpcTaskContext taskContext, FlowModInputBuilder flowModInput,
         SwitchConnectionDistinguisher cookie) {
-        flowModInput.setXid(taskContext.getSession().getFeatures().getXid());
+        flowModInput.setXid(taskContext.getSession().getNextXid());
         return taskContext.getMessageService().flowMod(flowModInput.build(), cookie);
     }
 
 
     /**
-     * @param xId
+     * @param input
      * @return
      */
     protected static NotificationComposer<FlowAdded> createFlowAddedNotification(
-            final Long xId, final AddFlowInput input) {
+            final AddFlowInput input) {
         return new NotificationComposer<FlowAdded>() {
             @Override
-            public FlowAdded compose() {
+            public FlowAdded compose(TransactionId tXid) {
                 FlowAddedBuilder newFlow = new FlowAddedBuilder((Flow) input);
-                newFlow.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
+                newFlow.setTransactionId(tXid);
                 newFlow.setFlowRef(input.getFlowRef());
                 return newFlow.build();
             }
@@ -296,42 +294,44 @@ public abstract class OFRpcTaskFactory {
             @Override
             public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
                 ListenableFuture<RpcResult<UpdateFlowOutput>> result = null;
-                Collection<RpcError> barrierErrors = OFRpcTaskUtil.manageBarrier(getTaskContext(), 
-                        getInput().getUpdatedFlow().isBarrier(), getCookie());
-                if (!barrierErrors.isEmpty()) {
-                    OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateFlowOutput>>) result), barrierErrors);
-
-                } else {
-                    Long xId = getSession().getNextXid();
-                    boolean updatedFlow = (getInput().getUpdatedFlow().getMatch().equals(getInput().getOriginalFlow().getMatch())) &&
-                            (getInput().getUpdatedFlow().getPriority().equals(getInput().getOriginalFlow().getPriority()));
+                    
+                boolean updatedFlow = (getInput().getUpdatedFlow().getMatch().equals(getInput().getOriginalFlow().getMatch())) &&
+                        (getInput().getUpdatedFlow().getPriority().equals(getInput().getOriginalFlow().getPriority()));
 
-                    List<FlowModInputBuilder> allFlowMods = new ArrayList<>();
-                    List<FlowModInputBuilder> ofFlowModInputs =
-                        FlowConvertor.toFlowModInputs(getInput().getUpdatedFlow(),
-                            getVersion(), getSession().getFeatures().getDatapathId());
+                List<FlowModInputBuilder> allFlowMods = new ArrayList<>();
+                List<FlowModInputBuilder> ofFlowModInputs;
 
-                    if (updatedFlow == false) {
-                        // if neither match nor priority matches, then we would need to remove the flow and add it
-                        //remove flow
-                        RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(getInput().getOriginalFlow());
-                        FlowModInputBuilder ofFlowRemoveInput = FlowConvertor.toFlowModInput(removeflow.build(),
+                if (updatedFlow == false) {
+                    // if neither match nor priority matches, then we would need to remove the flow and add it
+                    //remove flow
+                    RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(getInput().getOriginalFlow());
+                    List<FlowModInputBuilder> ofFlowRemoveInput = FlowConvertor.toFlowModInputs(removeflow.build(),
                             getVersion(),getSession().getFeatures().getDatapathId());
-                        ofFlowRemoveInput.setXid(xId);
-                        // remove flow should be the first
-                        allFlowMods.add(ofFlowRemoveInput);
-                    }
+                    // remove flow should be the first
+                    allFlowMods.addAll(ofFlowRemoveInput);
+                    AddFlowInputBuilder addFlowInputBuilder = new AddFlowInputBuilder(getInput().getUpdatedFlow());
+                    ofFlowModInputs = FlowConvertor.toFlowModInputs(addFlowInputBuilder.build(),
+                            getVersion(), getSession().getFeatures().getDatapathId());
+                } else {
+                    ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput().getUpdatedFlow(),
+                            getVersion(), getSession().getFeatures().getDatapathId());
+                }
 
-                    allFlowMods.addAll(ofFlowModInputs);
-                    logger.debug("Number of flows to push to switch: {}", allFlowMods.size());
-                    result = chainFlowMods(allFlowMods, 0, getTaskContext(), getCookie());
+                allFlowMods.addAll(ofFlowModInputs);
+                logger.debug("Number of flows to push to switch: {}", allFlowMods.size());
+                result = chainFlowMods(allFlowMods, 0, getTaskContext(), getCookie());
 
-                    OFRpcTaskUtil.hookFutureNotification(this, result,
+                result = OFRpcTaskUtil.chainFutureBarrier(this, result);
+                OFRpcTaskUtil.hookFutureNotification(this, result,
                         getRpcNotificationProviderService(),
-                        createFlowUpdatedNotification(xId, getInput()));
-                }
+                        createFlowUpdatedNotification(getInput()));
                 return result;
             }
+            
+            @Override
+            public Boolean isBarrier() {
+                return getInput().getUpdatedFlow().isBarrier();
+            }
         };
         return task;
     }
@@ -342,13 +342,12 @@ public abstract class OFRpcTaskFactory {
      * @param input
      * @return
      */
-    protected static NotificationComposer<FlowUpdated> createFlowUpdatedNotification(
-            final Long xId, final UpdateFlowInput input) {
+    protected static NotificationComposer<FlowUpdated> createFlowUpdatedNotification(final UpdateFlowInput input) {
         return new NotificationComposer<FlowUpdated>() {
             @Override
-            public FlowUpdated compose() {
+            public FlowUpdated compose(TransactionId tXid) {
                 FlowUpdatedBuilder updFlow = new FlowUpdatedBuilder(input.getUpdatedFlow());
-                updFlow.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
+                updFlow.setTransactionId(tXid);
                 updFlow.setFlowRef(input.getFlowRef());
                 return updFlow.build();
             }
@@ -371,26 +370,27 @@ public abstract class OFRpcTaskFactory {
             public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
                 ListenableFuture<RpcResult<UpdateGroupOutput>> result = SettableFuture.create();
                 
-                Collection<RpcError> barrierErrors = OFRpcTaskUtil.manageBarrier(getTaskContext(), getInput().isBarrier(), getCookie());
-                if (!barrierErrors.isEmpty()) {
-                    OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateGroupOutput>>) result), barrierErrors);
-                } else {
-                    // Convert the AddGroupInput to GroupModInput
-                    GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(), 
-                            getVersion(), getSession().getFeatures().getDatapathId());
-                    final Long xId = getSession().getNextXid();
-                    ofGroupModInput.setXid(xId);
-                    
-                    Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
-                            .groupMod(ofGroupModInput.build(), getCookie());
-                    result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
-                    
-                    OFRpcTaskUtil.hookFutureNotification(this, result, 
-                            getRpcNotificationProviderService(), createGroupAddedNotification(xId, getInput()));
-                }
+                // Convert the AddGroupInput to GroupModInput
+                GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(), 
+                        getVersion(), getSession().getFeatures().getDatapathId());
+                final Long xId = getSession().getNextXid();
+                ofGroupModInput.setXid(xId);
+
+                Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
+                        .groupMod(ofGroupModInput.build(), getCookie());
+                result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+                result = OFRpcTaskUtil.chainFutureBarrier(this, result);
+                OFRpcTaskUtil.hookFutureNotification(this, result, 
+                        getRpcNotificationProviderService(), createGroupAddedNotification(getInput()));
 
                 return result;
             }
+            
+            @Override
+            public Boolean isBarrier() {
+                return getInput().isBarrier();
+            }
         };
         
         return task;
@@ -398,17 +398,16 @@ public abstract class OFRpcTaskFactory {
     
 
     /**
-     * @param xId
      * @param input
      * @return
      */
     protected static NotificationComposer<GroupAdded> createGroupAddedNotification(
-            final Long xId, final AddGroupInput input) {
+            final AddGroupInput input) {
         return new NotificationComposer<GroupAdded>() {
             @Override
-            public GroupAdded compose() {
+            public GroupAdded compose(TransactionId tXid) {
                 GroupAddedBuilder groupMod = new GroupAddedBuilder((Group) input);
-                groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
+                groupMod.setTransactionId(tXid);
                 groupMod.setGroupRef(input.getGroupRef());
                 return groupMod.build();
             }
@@ -431,25 +430,26 @@ public abstract class OFRpcTaskFactory {
             public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
                 ListenableFuture<RpcResult<UpdateMeterOutput>> result = SettableFuture.create();
                 
-                Collection<RpcError> barrierErrors = OFRpcTaskUtil.manageBarrier(getTaskContext(), getInput().isBarrier(), getCookie());
-                if (!barrierErrors.isEmpty()) {
-                    OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateMeterOutput>>) result), barrierErrors);
-                } else {
-                    // Convert the AddGroupInput to GroupModInput
-                    MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput(), getVersion());
-                    final Long xId = getSession().getNextXid();
-                    ofMeterModInput.setXid(xId);
-                    
-                    Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
-                            .meterMod(ofMeterModInput.build(), getCookie());
-                    result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
-                    
-                    OFRpcTaskUtil.hookFutureNotification(this, result, 
-                            getRpcNotificationProviderService(), createMeterAddedNotification(xId, getInput()));
-                }
+                // Convert the AddGroupInput to GroupModInput
+                MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput(), getVersion());
+                final Long xId = getSession().getNextXid();
+                ofMeterModInput.setXid(xId);
+                
+                Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
+                        .meterMod(ofMeterModInput.build(), getCookie());
+                result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+                
+                result = OFRpcTaskUtil.chainFutureBarrier(this, result);
+                OFRpcTaskUtil.hookFutureNotification(this, result, 
+                        getRpcNotificationProviderService(), createMeterAddedNotification(getInput()));
 
                 return result;
             }
+            
+            @Override
+            public Boolean isBarrier() {
+                return getInput().isBarrier();
+            }
         };
         
         return task;
@@ -457,17 +457,16 @@ public abstract class OFRpcTaskFactory {
     }
 
     /**
-     * @param xId
      * @param input
      * @return
      */
     protected static NotificationComposer<MeterAdded> createMeterAddedNotification(
-            final Long xId, final AddMeterInput input) {
+            final AddMeterInput input) {
         return new NotificationComposer<MeterAdded>() {
             @Override
-            public MeterAdded compose() {
+            public MeterAdded compose(TransactionId tXid) {
                 MeterAddedBuilder meterMod = new MeterAddedBuilder((Meter) input);
-                meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
+                meterMod.setTransactionId(tXid);
                 meterMod.setMeterRef(input.getMeterRef());
                 return meterMod.build();
             }
@@ -489,25 +488,22 @@ public abstract class OFRpcTaskFactory {
             @Override
             public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
                 ListenableFuture<RpcResult<UpdateGroupOutput>> result = null;
-                Collection<RpcError> barrierErrors = OFRpcTaskUtil.manageBarrier(getTaskContext(), 
-                        getInput().getUpdatedGroup().isBarrier(), getCookie());
-                if (!barrierErrors.isEmpty()) {
-                    OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateGroupOutput>>) result), barrierErrors);
-                } else {
-                    // Convert the UpdateGroupInput to GroupModInput
-                    GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(
-                            getInput().getUpdatedGroup(), getVersion(),
-                            getSession().getFeatures().getDatapathId());
-                    final Long xId = getSession().getNextXid();
-                    ofGroupModInput.setXid(xId);
-    
-                    Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = 
-                            getMessageService().groupMod(ofGroupModInput.build(), getCookie());
-                    result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
-                    
-                    OFRpcTaskUtil.hookFutureNotification(this, result, 
-                            getRpcNotificationProviderService(), createGroupUpdatedNotification(xId, getInput()));
-                }
+                
+                // Convert the UpdateGroupInput to GroupModInput
+                GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(
+                        getInput().getUpdatedGroup(), getVersion(),
+                        getSession().getFeatures().getDatapathId());
+                final Long xId = getSession().getNextXid();
+                ofGroupModInput.setXid(xId);
+
+                Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = 
+                        getMessageService().groupMod(ofGroupModInput.build(), getCookie());
+                result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+                result = OFRpcTaskUtil.chainFutureBarrier(this, result);
+                OFRpcTaskUtil.hookFutureNotification(this, result, 
+                        getRpcNotificationProviderService(), createGroupUpdatedNotification(getInput()));
+                
                 return result;
             }
         };
@@ -515,17 +511,16 @@ public abstract class OFRpcTaskFactory {
     }
     
     /**
-     * @param xId
      * @param input
      * @return
      */
     protected static NotificationComposer<GroupUpdated> createGroupUpdatedNotification(
-            final Long xId, final UpdateGroupInput input) {
+            final UpdateGroupInput input) {
         return new NotificationComposer<GroupUpdated>() {
             @Override
-            public GroupUpdated compose() {
+            public GroupUpdated compose(TransactionId tXid) {
                 GroupUpdatedBuilder groupMod = new GroupUpdatedBuilder(input.getUpdatedGroup());
-                groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
+                groupMod.setTransactionId(tXid);
                 groupMod.setGroupRef(input.getGroupRef());
                 return groupMod.build();
             }
@@ -547,24 +542,20 @@ public abstract class OFRpcTaskFactory {
             @Override
             public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
                 ListenableFuture<RpcResult<UpdateMeterOutput>> result = null;
-                Collection<RpcError> barrierErrors = OFRpcTaskUtil.manageBarrier(getTaskContext(), 
-                        getInput().getUpdatedMeter().isBarrier(), getCookie());
-                if (!barrierErrors.isEmpty()) {
-                    OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateMeterOutput>>) result), barrierErrors);
-                } else {
-                    // Convert the UpdateMeterInput to MeterModInput
-                    MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(
-                            getInput().getUpdatedMeter(), getVersion());
-                    final Long xId = getSession().getNextXid();
-                    ofMeterModInput.setXid(xId);
-    
-                    Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = 
-                            getMessageService().meterMod(ofMeterModInput.build(), getCookie());
-                    result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
-                    
-                    OFRpcTaskUtil.hookFutureNotification(this, result,
-                            getRpcNotificationProviderService(), createMeterUpdatedNotification(xId, getInput()));
-                }
+
+                // Convert the UpdateMeterInput to MeterModInput
+                MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(
+                        getInput().getUpdatedMeter(), getVersion());
+                final Long xId = getSession().getNextXid();
+                ofMeterModInput.setXid(xId);
+
+                Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = 
+                        getMessageService().meterMod(ofMeterModInput.build(), getCookie());
+                result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+                result = OFRpcTaskUtil.chainFutureBarrier(this, result);
+                OFRpcTaskUtil.hookFutureNotification(this, result,
+                        getRpcNotificationProviderService(), createMeterUpdatedNotification(getInput()));
                 return result;
             }
         };
@@ -572,17 +563,16 @@ public abstract class OFRpcTaskFactory {
     }
     
     /**
-     * @param xId
      * @param input
      * @return
      */
     protected static NotificationComposer<MeterUpdated> createMeterUpdatedNotification(
-            final Long xId, final UpdateMeterInput input) {
+            final UpdateMeterInput input) {
         return new NotificationComposer<MeterUpdated>() {
             @Override
-            public MeterUpdated compose() {
+            public MeterUpdated compose(TransactionId tXid) {
                 MeterUpdatedBuilder meterMod = new MeterUpdatedBuilder(input.getUpdatedMeter());
-                meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
+                meterMod.setTransactionId(tXid);
                 meterMod.setMeterRef(input.getMeterRef());
                 return meterMod.build();
             }
@@ -605,24 +595,20 @@ public abstract class OFRpcTaskFactory {
             @Override
             public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
                 ListenableFuture<RpcResult<UpdateFlowOutput>> result = SettableFuture.create();
-                
-                Collection<RpcError> barrierErrors = OFRpcTaskUtil.manageBarrier(getTaskContext(), getInput().isBarrier(), getCookie());
-                if (!barrierErrors.isEmpty()) {
-                    OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateFlowOutput>>) result), barrierErrors);
-                } else {
-                    // Convert the AddFlowInput to FlowModInput
-                    FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(getInput(), 
-                            getVersion(), getSession().getFeatures().getDatapathId());
-                    final Long xId = getSession().getNextXid();
-                    ofFlowModInput.setXid(xId);
-                    
-                    Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = 
-                            getMessageService().flowMod(ofFlowModInput.build(), getCookie());
-                    result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
-                    
-                    OFRpcTaskUtil.hookFutureNotification(this, result, 
-                            getRpcNotificationProviderService(), createFlowRemovedNotification(xId, getInput()));
-                }
+
+                // Convert the AddFlowInput to FlowModInput
+                FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(getInput(), 
+                        getVersion(), getSession().getFeatures().getDatapathId());
+                final Long xId = getSession().getNextXid();
+                ofFlowModInput.setXid(xId);
+
+                Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = 
+                        getMessageService().flowMod(ofFlowModInput.build(), getCookie());
+                result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+                result = OFRpcTaskUtil.chainFutureBarrier(this, result);
+                OFRpcTaskUtil.hookFutureNotification(this, result, 
+                        getRpcNotificationProviderService(), createFlowRemovedNotification(getInput()));
 
                 return result;
             }
@@ -632,16 +618,16 @@ public abstract class OFRpcTaskFactory {
     }
     
     /**
-     * @param xId
+     * @param input
      * @return
      */
     protected static NotificationComposer<FlowRemoved> createFlowRemovedNotification(
-            final Long xId, final RemoveFlowInput input) {
+            final RemoveFlowInput input) {
         return new NotificationComposer<FlowRemoved>() {
             @Override
-            public FlowRemoved compose() {
+            public FlowRemoved compose(TransactionId tXid) {
                 FlowRemovedBuilder removedFlow = new FlowRemovedBuilder((Flow) input);
-                removedFlow.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
+                removedFlow.setTransactionId(tXid);
                 removedFlow.setFlowRef(input.getFlowRef());
                 return removedFlow.build();
             }
@@ -664,44 +650,39 @@ public abstract class OFRpcTaskFactory {
             @Override
             public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
                 ListenableFuture<RpcResult<UpdateGroupOutput>> result = SettableFuture.create();
-                
-                Collection<RpcError> barrierErrors = OFRpcTaskUtil.manageBarrier(getTaskContext(), getInput().isBarrier(), getCookie());
-                if (!barrierErrors.isEmpty()) {
-                    OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateGroupOutput>>) result), barrierErrors);
-                } else {
-                    // Convert the AddGroupInput to GroupModInput
-                    GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(), 
-                            getVersion(), getSession().getFeatures().getDatapathId());
-                    final Long xId = getSession().getNextXid();
-                    ofGroupModInput.setXid(xId);
-                    
-                    Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
-                            .groupMod(ofGroupModInput.build(), getCookie());
-                    result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
-                    
-                    OFRpcTaskUtil.hookFutureNotification(this, result, 
-                            getRpcNotificationProviderService(), createGroupRemovedNotification(xId, getInput()));
-                }
+
+                // Convert the AddGroupInput to GroupModInput
+                GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(), 
+                        getVersion(), getSession().getFeatures().getDatapathId());
+                final Long xId = getSession().getNextXid();
+                ofGroupModInput.setXid(xId);
+
+                Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
+                        .groupMod(ofGroupModInput.build(), getCookie());
+                result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+                result = OFRpcTaskUtil.chainFutureBarrier(this, result);
+                OFRpcTaskUtil.hookFutureNotification(this, result, 
+                        getRpcNotificationProviderService(), createGroupRemovedNotification(getInput()));
 
                 return result;
             }
         };
-        
+
         return task;
     }
     
     /**
-     * @param xId
      * @param input
      * @return 
      */
     protected static NotificationComposer<GroupRemoved> createGroupRemovedNotification(
-            final Long xId, final RemoveGroupInput input) {
+            final RemoveGroupInput input) {
         return new NotificationComposer<GroupRemoved>() {
             @Override
-            public GroupRemoved compose() {
+            public GroupRemoved compose(TransactionId tXid) {
                 GroupRemovedBuilder removedGroup = new GroupRemovedBuilder((Group) input);
-                removedGroup.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
+                removedGroup.setTransactionId(tXid);
                 removedGroup.setGroupRef(input.getGroupRef());
                 return removedGroup.build();
             }
@@ -723,23 +704,19 @@ public abstract class OFRpcTaskFactory {
             @Override
             public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
                 ListenableFuture<RpcResult<UpdateMeterOutput>> result = SettableFuture.create();
-                
-                Collection<RpcError> barrierErrors = OFRpcTaskUtil.manageBarrier(getTaskContext(), getInput().isBarrier(), getCookie());
-                if (!barrierErrors.isEmpty()) {
-                    OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateMeterOutput>>) result), barrierErrors);
-                } else {
-                    // Convert the AddGroupInput to GroupModInput
-                    MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput(), getVersion());
-                    final Long xId = getSession().getNextXid();
-                    ofMeterModInput.setXid(xId);
-                    
-                    Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
-                            .meterMod(ofMeterModInput.build(), getCookie());
-                    result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
-                    
-                    OFRpcTaskUtil.hookFutureNotification(this, result, 
-                            getRpcNotificationProviderService(), createMeterRemovedNotification(xId, getInput()));
-                }
+
+                // Convert the AddGroupInput to GroupModInput
+                MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput(), getVersion());
+                final Long xId = getSession().getNextXid();
+                ofMeterModInput.setXid(xId);
+
+                Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
+                        .meterMod(ofMeterModInput.build(), getCookie());
+                result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+                result = OFRpcTaskUtil.chainFutureBarrier(this, result);
+                OFRpcTaskUtil.hookFutureNotification(this, result, 
+                        getRpcNotificationProviderService(), createMeterRemovedNotification(getInput()));
 
                 return result;
             }
@@ -750,17 +727,16 @@ public abstract class OFRpcTaskFactory {
     }
     
     /**
-     * @param xId
      * @param input
      * @return
      */
     protected static NotificationComposer<MeterRemoved> createMeterRemovedNotification(
-            final Long xId, final RemoveMeterInput input) {
+            final RemoveMeterInput input) {
         return new NotificationComposer<MeterRemoved>() {
             @Override
-            public MeterRemoved compose() {
+            public MeterRemoved compose(TransactionId tXid) {
                 MeterRemovedBuilder meterRemoved = new MeterRemovedBuilder((Meter) input);
-                meterRemoved.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
+                meterRemoved.setTransactionId(tXid);
                 meterRemoved.setMeterRef(input.getMeterRef());
                 return meterRemoved.build();
             }
@@ -784,9 +760,8 @@ public abstract class OFRpcTaskFactory {
                 final SettableFuture<RpcResult<GetAllGroupStatisticsOutput>> result = SettableFuture.create();
              
                 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
-                    Collection<RpcError> errors = Collections.emptyList();
-                    RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, 
-                            new GetAllGroupStatisticsOutputBuilder().build(), errors);
+                    RpcResult<GetAllGroupStatisticsOutput> rpcResult = RpcResultBuilder.success(
+                            new GetAllGroupStatisticsOutputBuilder().build()).build();
                     
                     return Futures.immediateFuture(rpcResult);
                 } else {   
@@ -849,9 +824,8 @@ public abstract class OFRpcTaskFactory {
                         final SettableFuture<RpcResult<GetGroupDescriptionOutput>> result = SettableFuture.create();
                         
                         if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
-                            Collection<RpcError> errors = Collections.emptyList();
-                            RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, 
-                                    new GetGroupDescriptionOutputBuilder().build(), errors);
+                            RpcResult<GetGroupDescriptionOutput> rpcResult = RpcResultBuilder.success( 
+                                    new GetGroupDescriptionOutputBuilder().build()).build();
                             return Futures.immediateFuture(rpcResult);
                         } else {
                             final Long xid = taskContext.getSession().getNextXid();
@@ -898,9 +872,8 @@ public abstract class OFRpcTaskFactory {
                         final SettableFuture<RpcResult<GetGroupFeaturesOutput>> result = SettableFuture.create();
                         
                         if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
-                            Collection<RpcError> errors = Collections.emptyList();
-                            RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, 
-                                    new GetGroupFeaturesOutputBuilder().build(), errors);
+                            RpcResult<GetGroupFeaturesOutput> rpcResult = RpcResultBuilder.success( 
+                                    new GetGroupFeaturesOutputBuilder().build()).build();
                             return Futures.immediateFuture(rpcResult);
                         } else {
                             final Long xid = taskContext.getSession().getNextXid();
@@ -947,9 +920,8 @@ public abstract class OFRpcTaskFactory {
                         final SettableFuture<RpcResult<GetGroupStatisticsOutput>> result = SettableFuture.create();
                         
                         if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
-                            Collection<RpcError> errors = Collections.emptyList();
-                            RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, 
-                                    new GetGroupStatisticsOutputBuilder().build(), errors);
+                            RpcResult<GetGroupStatisticsOutput> rpcResult = RpcResultBuilder.success(
+                                    new GetGroupStatisticsOutputBuilder().build()).build();
                             return Futures.immediateFuture(rpcResult);
                         } else {
                             final Long xid = taskContext.getSession().getNextXid();
@@ -1000,9 +972,8 @@ public abstract class OFRpcTaskFactory {
                         final SettableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> result = SettableFuture.create();
                         
                         if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
-                            Collection<RpcError> errors = Collections.emptyList();
-                            RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, 
-                                    new GetAllMeterConfigStatisticsOutputBuilder().build(), errors);
+                            RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = RpcResultBuilder.success(
+                                    new GetAllMeterConfigStatisticsOutputBuilder().build()).build();
                             return Futures.immediateFuture(rpcResult);
                         } else {
                             final Long xid = taskContext.getSession().getNextXid();
@@ -1057,9 +1028,8 @@ public abstract class OFRpcTaskFactory {
                         final SettableFuture<RpcResult<GetAllMeterStatisticsOutput>> result = SettableFuture.create();
                         
                         if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
-                            Collection<RpcError> errors = Collections.emptyList();
-                            RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, 
-                                    new GetAllMeterStatisticsOutputBuilder().build(), errors);
+                            RpcResult<GetAllMeterStatisticsOutput> rpcResult = RpcResultBuilder.success(
+                                    new GetAllMeterStatisticsOutputBuilder().build()).build();
                             return Futures.immediateFuture(rpcResult);
                         } else {
                             final Long xid = taskContext.getSession().getNextXid();
@@ -1114,9 +1084,8 @@ public abstract class OFRpcTaskFactory {
                         final SettableFuture<RpcResult<GetMeterFeaturesOutput>> result = SettableFuture.create();
                         
                         if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
-                            Collection<RpcError> errors = Collections.emptyList();
-                            RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, 
-                                    new GetMeterFeaturesOutputBuilder().build(), errors);
+                            RpcResult<GetMeterFeaturesOutput> rpcResult = RpcResultBuilder.success(
+                                    new GetMeterFeaturesOutputBuilder().build()).build();
                             return Futures.immediateFuture(rpcResult);
                         } else {
                             final Long xid = taskContext.getSession().getNextXid();
@@ -1165,9 +1134,8 @@ public abstract class OFRpcTaskFactory {
                         final SettableFuture<RpcResult<GetMeterStatisticsOutput>> result = SettableFuture.create();
                         
                         if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
-                            Collection<RpcError> errors = Collections.emptyList();
-                            RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, 
-                                    new GetMeterStatisticsOutputBuilder().build(), errors);
+                            RpcResult<GetMeterStatisticsOutput> rpcResult = RpcResultBuilder.success(
+                                    new GetMeterStatisticsOutputBuilder().build()).build();
                             return Futures.immediateFuture(rpcResult);
                         } else {
                             final Long xid = taskContext.getSession().getNextXid();
@@ -1828,17 +1796,17 @@ public abstract class OFRpcTaskFactory {
 
         @Override
         public void onSuccess(RpcResult<Void> resultArg) {
-            Collection<RpcError> errors = Collections.emptyList();
-            result.set(Rpcs.getRpcResult(true, createResult(), errors));
+            result.set(RpcResultBuilder.success(createResult()).build());
         }
 
         @Override
         public void onFailure(Throwable t) {
-            result.set(Rpcs.<T>getRpcResult(false, 
-                    Collections.singletonList(RpcErrors.getRpcError(OFConstants.APPLICATION_TAG, 
+            result.set(RpcResultBuilder.<T>failed().withWarning(
+                            ErrorType.RPC,
                             OFConstants.ERROR_TAG_TIMEOUT, 
-                            "something wrong happened", ErrorSeverity.WARNING, "", 
-                            ErrorType.RPC, t))));
+                            "something wrong happened", 
+                            OFConstants.APPLICATION_TAG, 
+                            "", t).build());
         }
     }