BUG-1952 Flow update rpc
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / OFRpcTaskFactory.java
index 720b072e4a9658854c4d452fe95983f66dae92da..0bc2b67bbef5d0d7dc93ba7a8abb6023dcca670d 100644 (file)
@@ -7,17 +7,17 @@
  */
 package org.opendaylight.openflowplugin.openflow.md.core.sal;
 
-import java.math.BigInteger;
-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;
 
-import org.opendaylight.controller.sal.common.util.RpcErrors;
-import org.opendaylight.controller.sal.common.util.Rpcs;
 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.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 +26,9 @@ 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.openflowplugin.api.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;
@@ -158,21 +159,24 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.Upd
 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 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 java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Future;
 
 /**
  *
  */
 public abstract class OFRpcTaskFactory {
+    protected static final Logger logger = LoggerFactory.getLogger(OFRpcTaskFactory.class);
 
     /**
      * @param taskContext 
@@ -181,7 +185,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) {
@@ -195,17 +199,16 @@ public abstract class OFRpcTaskFactory {
                     OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateFlowOutput>>) result), barrierErrors);
                 } else {
                     // Convert the AddFlowInput to FlowModInput
-                    FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(getInput(), 
+                    List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(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(), createFlowAddedNotification(xId, getInput()));
+
+                    logger.debug("Number of flows to push to switch: {}", ofFlowModInputs.size());
+
+                    result = chainFlowMods(ofFlowModInputs, 0, getTaskContext(), getCookie());
+
+                    OFRpcTaskUtil.hookFutureNotification(this, result,
+                        getRpcNotificationProviderService(),
+                        createFlowAddedNotification(getInput()));
                 }
                 return result;
             }
@@ -214,16 +217,62 @@ public abstract class OFRpcTaskFactory {
     }
 
     /**
-     * @param xId
+     * Recursive helper method for {@link OFRpcTaskFactory#createAddFlowTask()}
+     * and {@link OFRpcTaskFactory#createUpdateFlowTask()} to chain results
+     * of multiple flowmods.
+     * The next flowmod gets executed if the earlier one is successful.
+     * All the flowmods should have the same xid, in-order to cross-reference
+     * the notification
+     */
+    protected static ListenableFuture<RpcResult<UpdateFlowOutput>> chainFlowMods(
+        final List<FlowModInputBuilder> ofFlowModInputs, final int index,
+        final OFRpcTaskContext taskContext, final SwitchConnectionDistinguisher cookie) {
+
+        Future<RpcResult<UpdateFlowOutput>> resultFromOFLib =
+            createResultForFlowMod(taskContext, ofFlowModInputs.get(index), cookie);
+
+        ListenableFuture<RpcResult<UpdateFlowOutput>> result  = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+        if(ofFlowModInputs.size() > index + 1) {
+            // there are more flowmods to chain
+            return Futures.transform(result,
+                new AsyncFunction<RpcResult<UpdateFlowOutput>, RpcResult<UpdateFlowOutput>>() {
+                    @Override
+                    public ListenableFuture<RpcResult<UpdateFlowOutput>> apply(RpcResult<UpdateFlowOutput> input) throws Exception {
+                        if (input.isSuccessful()) {
+                            return chainFlowMods(ofFlowModInputs, index + 1, taskContext, cookie);
+                        } else {
+                            logger.warn("Flowmod failed. Any chained flowmods are ignored. xid:{}",
+                                ofFlowModInputs.get(index).getXid());
+                            return Futures.immediateFuture(input);
+                        }
+                    }
+                }
+            );
+        } else {
+            return result;
+        }
+    }
+
+    private static Future<RpcResult<UpdateFlowOutput>> createResultForFlowMod(
+        OFRpcTaskContext taskContext, FlowModInputBuilder flowModInput,
+        SwitchConnectionDistinguisher cookie) {
+        flowModInput.setXid(taskContext.getSession().getNextXid());
+        return taskContext.getMessageService().flowMod(flowModInput.build(), cookie);
+    }
+
+
+    /**
+     * @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();
             }
@@ -252,31 +301,36 @@ public abstract class OFRpcTaskFactory {
                     OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateFlowOutput>>) result), barrierErrors);
 
                 } else {
-                    Flow flow = null;
-                    Long xId = getSession().getNextXid();
                     boolean updatedFlow = (getInput().getUpdatedFlow().getMatch().equals(getInput().getOriginalFlow().getMatch())) &&
                             (getInput().getUpdatedFlow().getPriority().equals(getInput().getOriginalFlow().getPriority()));
 
+                    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(),
-                                getVersion(),getSession().getFeatures().getDatapathId());
-                        ofFlowRemoveInput.setXid(xId);
-                        Future<RpcResult<UpdateFlowOutput>> resultFromOFLibRemove = getMessageService().
-                                flowMod(ofFlowRemoveInput.build(), getCookie());
-                        
-                        result = Futures.transform(JdkFutureAdapters.listenInPoolThread(resultFromOFLibRemove),
-                                          decodeRemoveFlowAndCreateFlow(taskContext, getCookie()));
+                        List<FlowModInputBuilder> ofFlowRemoveInput = FlowConvertor.toFlowModInputs(removeflow.build(),
+                            getVersion(),getSession().getFeatures().getDatapathId());
+                        // 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 {
-                        //update flow
-                        flow = getInput().getUpdatedFlow();
-                        result = JdkFutureAdapters.listenInPoolThread(createResultForAddFlow(
-                                                              taskContext, flow, getCookie()));
+                        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());
+
+                    
                     OFRpcTaskUtil.hookFutureNotification(this, result,
-                            getRpcNotificationProviderService(), createFlowUpdatedNotification(xId, getInput()));
+                        getRpcNotificationProviderService(),
+                        createFlowUpdatedNotification(getInput()));
                 }
                 return result;
             }
@@ -284,59 +338,18 @@ public abstract class OFRpcTaskFactory {
         return task;
     }
     
-    /**
-     * Helper method for {@link OFRpcTaskFactory#createUpdateFlowTask()}. Decides whether flow 
-     * removing ends successfully and if yes, it performs adding of new flow. 
-     * 
-     * @param taskContext
-     * @param cookie
-     * @return asyncFunction
-     */
-    protected static AsyncFunction<RpcResult<UpdateFlowOutput>, RpcResult<UpdateFlowOutput>> 
-            decodeRemoveFlowAndCreateFlow(final OFRpcTaskContext taskContext, final SwitchConnectionDistinguisher cookie) { 
-        return new AsyncFunction<RpcResult<UpdateFlowOutput>, RpcResult<UpdateFlowOutput>>() {
-            @Override
-            public ListenableFuture<RpcResult<UpdateFlowOutput>> apply(
-                    RpcResult<UpdateFlowOutput> input) throws Exception {
-                if(input.isSuccessful()) {
-                    return JdkFutureAdapters.listenInPoolThread(createResultForAddFlow(taskContext, null, cookie));
-                } else {
-                    return Futures.immediateFuture(input);
-                }            
-            }
-        };
-    }
-    
-    /**
-     * Helper method for {@link OFRpcTaskFactory#createUpdateFlowTask()}. It performs adding of new flow. 
-     * 
-     * @param taskContext
-     * @param flow
-     * @param cookie
-     * @return future
-     */
-    protected static Future<RpcResult<UpdateFlowOutput>> createResultForAddFlow(OFRpcTaskContext taskContext, 
-                                                                              Flow flow, 
-                                                                              SwitchConnectionDistinguisher cookie) {
-        FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(flow, 
-                                             taskContext.getSession().getFeatures().getVersion(),
-                                             taskContext.getSession().getFeatures().getDatapathId());
-        ofFlowModInput.setXid(taskContext.getSession().getFeatures().getXid());
-        return taskContext.getMessageService().flowMod(ofFlowModInput.build(), cookie);
-    }
-    
+
     /**
      * @param xId
      * @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();
             }
@@ -374,7 +387,7 @@ public abstract class OFRpcTaskFactory {
                     result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
                     
                     OFRpcTaskUtil.hookFutureNotification(this, result, 
-                            getRpcNotificationProviderService(), createGroupAddedNotification(xId, getInput()));
+                            getRpcNotificationProviderService(), createGroupAddedNotification(getInput()));
                 }
 
                 return result;
@@ -386,17 +399,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();
             }
@@ -433,7 +445,7 @@ public abstract class OFRpcTaskFactory {
                     result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
                     
                     OFRpcTaskUtil.hookFutureNotification(this, result, 
-                            getRpcNotificationProviderService(), createMeterAddedNotification(xId, getInput()));
+                            getRpcNotificationProviderService(), createMeterAddedNotification(getInput()));
                 }
 
                 return result;
@@ -445,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();
             }
@@ -494,7 +505,7 @@ public abstract class OFRpcTaskFactory {
                     result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
                     
                     OFRpcTaskUtil.hookFutureNotification(this, result, 
-                            getRpcNotificationProviderService(), createGroupUpdatedNotification(xId, getInput()));
+                            getRpcNotificationProviderService(), createGroupUpdatedNotification(getInput()));
                 }
                 return result;
             }
@@ -503,17 +514,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();
             }
@@ -551,7 +561,7 @@ public abstract class OFRpcTaskFactory {
                     result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
                     
                     OFRpcTaskUtil.hookFutureNotification(this, result,
-                            getRpcNotificationProviderService(), createMeterUpdatedNotification(xId, getInput()));
+                            getRpcNotificationProviderService(), createMeterUpdatedNotification(getInput()));
                 }
                 return result;
             }
@@ -560,17 +570,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();
             }
@@ -609,7 +618,7 @@ public abstract class OFRpcTaskFactory {
                     result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
                     
                     OFRpcTaskUtil.hookFutureNotification(this, result, 
-                            getRpcNotificationProviderService(), createFlowRemovedNotification(xId, getInput()));
+                            getRpcNotificationProviderService(), createFlowRemovedNotification(getInput()));
                 }
 
                 return result;
@@ -620,16 +629,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();
             }
@@ -668,7 +677,7 @@ public abstract class OFRpcTaskFactory {
                     result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
                     
                     OFRpcTaskUtil.hookFutureNotification(this, result, 
-                            getRpcNotificationProviderService(), createGroupRemovedNotification(xId, getInput()));
+                            getRpcNotificationProviderService(), createGroupRemovedNotification(getInput()));
                 }
 
                 return result;
@@ -679,17 +688,16 @@ public abstract class OFRpcTaskFactory {
     }
     
     /**
-     * @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();
             }
@@ -726,7 +734,7 @@ public abstract class OFRpcTaskFactory {
                     result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
                     
                     OFRpcTaskUtil.hookFutureNotification(this, result, 
-                            getRpcNotificationProviderService(), createMeterRemovedNotification(xId, getInput()));
+                            getRpcNotificationProviderService(), createMeterRemovedNotification(getInput()));
                 }
 
                 return result;
@@ -738,17 +746,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();
             }
@@ -772,9 +779,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 {   
@@ -837,9 +843,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();
@@ -886,9 +891,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();
@@ -935,9 +939,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();
@@ -988,9 +991,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();
@@ -1045,9 +1047,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();
@@ -1102,9 +1103,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();
@@ -1153,9 +1153,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();
@@ -1816,17 +1815,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());
         }
     }