60df8aabf3be101c6d405f0502a45a9d540f32ca
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / OFRpcTaskFactory.java
1 /**
2  * Copyright (c) 2013, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.openflow.md.core.sal;
9
10 import com.google.common.base.Optional;
11 import com.google.common.util.concurrent.AsyncFunction;
12 import com.google.common.util.concurrent.CheckedFuture;
13 import com.google.common.util.concurrent.FutureCallback;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.JdkFutureAdapters;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import com.google.common.util.concurrent.SettableFuture;
18 import java.math.BigInteger;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.concurrent.Future;
22 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
23 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
24 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
25 import org.opendaylight.openflowjava.protocol.api.util.BinContent;
26 import org.opendaylight.openflowplugin.api.OFConstants;
27 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
28 import org.opendaylight.openflowplugin.api.openflow.md.core.sal.NotificationComposer;
29 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
30 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
31 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor;
32 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
33 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
34 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor;
35 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
36 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
37 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowHashIdMapping;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.nodes.node.table.FlowHashIdMap;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.nodes.node.table.FlowHashIdMapKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdatedBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutputBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutputBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupAdded;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupAddedBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemoved;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemovedBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdated;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdatedBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutputBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutputBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutputBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutputBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterAdded;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterAddedBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemoved;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemovedBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdated;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdatedBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutputBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutputBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutputBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutput;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutputBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInput;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutputBuilder;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInput;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutput;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutputBuilder;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutputBuilder;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInput;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutputBuilder;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInput;
177 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput;
178 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutputBuilder;
179 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
180 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
181 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder;
182 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
183 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
184 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
185 import org.opendaylight.yangtools.yang.common.RpcResult;
186 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
187 import org.slf4j.Logger;
188 import org.slf4j.LoggerFactory;
189
190 /**
191  *
192  */
193 public abstract class OFRpcTaskFactory {
194     protected static final Logger LOG = LoggerFactory.getLogger(OFRpcTaskFactory.class);
195
196     private OFRpcTaskFactory() {
197         // hiding implicit constructor
198     }
199
200     /**
201      * @param taskContext task context
202      * @param input flow object input
203      * @param cookie switch connection distinguisher cookie value
204      * @return UpdateFlow task
205      */
206     public static OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> createAddFlowTask(
207             OFRpcTaskContext taskContext, AddFlowInput input,
208             SwitchConnectionDistinguisher cookie) {
209
210         class OFRpcTaskImpl extends OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> {
211
212             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddFlowInput input) {
213                 super(taskContext, cookie, input);
214             }
215
216             @Override
217             public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
218                 ListenableFuture<RpcResult<UpdateFlowOutput>> result = SettableFuture.create();
219
220                 // Convert the AddFlowInput to FlowModInput
221                 List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput(),
222                         getVersion(), getSession().getFeatures().getDatapathId());
223                 LOG.debug("Number of flows to push to switch: {}", ofFlowModInputs.size());
224                 result = chainFlowMods(ofFlowModInputs, 0, getTaskContext(), getCookie());
225                 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
226                 OFRpcTaskUtil.hookFutureNotification(this, result,
227                         getRpcNotificationProviderService(),
228                         createFlowAddedNotification(getInput()));
229                 return result;
230             }
231
232             @Override
233             public Boolean isBarrier() {
234                 return getInput().isBarrier();
235             }
236         }
237
238         return new OFRpcTaskImpl(taskContext, cookie, input);
239     }
240
241     /**
242      * Recursive helper method for {@link OFRpcTaskFactory#createAddFlowTask(OFRpcTaskContext, AddFlowInput, SwitchConnectionDistinguisher)}
243      * and {@link OFRpcTaskFactory#createUpdateFlowTask(OFRpcTaskContext, UpdateFlowInput, SwitchConnectionDistinguisher, ReadWriteTransaction)} to chain results
244      * of multiple flowmods.
245      * The next flowmod gets executed if the earlier one is successful.
246      * All the flowmods should have the same xid, in-order to cross-reference
247      * the notification
248      * @param taskContext task context
249      * @param ofFlowModInputs list of flow mod as input
250      * @param index  starting index
251      * @param cookie switch connection distinguisher
252      * @return listenable future with update flow output
253      *
254      */
255     protected static ListenableFuture<RpcResult<UpdateFlowOutput>> chainFlowMods(
256             final List<FlowModInputBuilder> ofFlowModInputs, final int index,
257             final OFRpcTaskContext taskContext, final SwitchConnectionDistinguisher cookie) {
258
259         Future<RpcResult<UpdateFlowOutput>> resultFromOFLib =
260                 createResultForFlowMod(taskContext, ofFlowModInputs.get(index), cookie);
261
262         ListenableFuture<RpcResult<UpdateFlowOutput>> result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
263
264         if (ofFlowModInputs.size() > index + 1) {
265             // there are more flowmods to chain
266             return Futures.transform(result,
267                     new AsyncFunction<RpcResult<UpdateFlowOutput>, RpcResult<UpdateFlowOutput>>() {
268                         @Override
269                         public ListenableFuture<RpcResult<UpdateFlowOutput>> apply(RpcResult<UpdateFlowOutput> input) throws Exception {
270                             if (input.isSuccessful()) {
271                                 return chainFlowMods(ofFlowModInputs, index + 1, taskContext, cookie);
272                             } else {
273                                 LOG.warn("Flowmod failed. Any chained flowmods are ignored. xid:{}",
274                                         ofFlowModInputs.get(index).getXid());
275                                 return Futures.immediateFuture(input);
276                             }
277                         }
278                     }
279             );
280         } else {
281             return result;
282         }
283     }
284
285     private static Future<RpcResult<UpdateFlowOutput>> createResultForFlowMod(
286             OFRpcTaskContext taskContext, FlowModInputBuilder flowModInput,
287             SwitchConnectionDistinguisher cookie) {
288         flowModInput.setXid(taskContext.getSession().getNextXid());
289         return taskContext.getMessageService().flowMod(flowModInput.build(), cookie);
290     }
291
292
293     /**
294      * @param input flow input
295      * @return flow added notification
296      */
297     protected static NotificationComposer<FlowAdded> createFlowAddedNotification(
298             final AddFlowInput input) {
299         return new NotificationComposer<FlowAdded>() {
300             @Override
301             public FlowAdded compose(TransactionId tXid) {
302                 FlowAddedBuilder newFlow = new FlowAddedBuilder((Flow) input);
303                 newFlow.setTransactionId(tXid);
304                 newFlow.setFlowRef(input.getFlowRef());
305                 return newFlow.build();
306             }
307         };
308     }
309
310     /**
311      * @param taskContext task context
312      * @param input update flow input
313      * @param cookie switch connection distinguisher cookie value
314      * @param rwTx  read write transaction
315      * @return UpdateFlow task
316      */
317     public static OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> createUpdateFlowTask(
318             final OFRpcTaskContext taskContext, UpdateFlowInput input,
319             SwitchConnectionDistinguisher cookie, final ReadWriteTransaction rwTx) {
320
321         class OFRpcTaskImpl extends OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> {
322             final ReadWriteTransaction rwTx;
323             InstanceIdentifier<Table> iiToTable = null;
324             String flowId = null;
325             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
326                     final UpdateFlowInput in, final ReadWriteTransaction rwTx) {
327                 super(taskContext, cookie, in);
328                 final FlowRef flowRef = in.getFlowRef();
329                 if (flowRef != null) {
330                     InstanceIdentifier<Flow> iiToFlow = (InstanceIdentifier<Flow>)(flowRef.getValue());
331                     iiToTable = flowRef.getValue().firstIdentifierOf(Table.class);
332                     FlowKey flowKey = iiToFlow.firstKeyOf(
333                             org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow.class, FlowKey.class);
334                     if (flowKey != null) {
335                         flowId = flowKey.getId().getValue();
336                     }
337                 }
338                 this.rwTx = rwTx;
339             }
340
341             @Override
342             public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
343                 ListenableFuture<RpcResult<UpdateFlowOutput>> result = null;
344
345                 UpdateFlowInput in = getInput();
346                 UpdatedFlow updated = in.getUpdatedFlow();
347                 OriginalFlow original = in.getOriginalFlow();
348                 Short version = getVersion();
349
350                 List<FlowModInputBuilder> allFlowMods = new ArrayList<>();
351                 List<FlowModInputBuilder> ofFlowModInputs;
352
353                 if (!FlowCreatorUtil.canModifyFlow(original, updated, version)) {
354                     // We would need to remove original and add updated.
355
356                     //remove flow
357                     RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(original);
358                     List<FlowModInputBuilder> ofFlowRemoveInput = FlowConvertor.toFlowModInputs(removeflow.build(),
359                             version, getSession().getFeatures().getDatapathId());
360                     // remove flow should be the first
361                     allFlowMods.addAll(ofFlowRemoveInput);
362                     AddFlowInputBuilder addFlowInputBuilder = new AddFlowInputBuilder(updated);
363                     ofFlowModInputs = FlowConvertor.toFlowModInputs(addFlowInputBuilder.build(),
364                             version, getSession().getFeatures().getDatapathId());
365                 } else {
366                     ofFlowModInputs = FlowConvertor.toFlowModInputs(updated,
367                             version, getSession().getFeatures().getDatapathId());
368                 }
369
370                 //deleting flow hash value from operational DS
371                 if (flowId != null) {
372                     CheckedFuture<Optional<FlowHashIdMapping>, ReadFailedException> hashDeletionFuture
373                         = readFlowHashIdMappingFromOperationalDS(rwTx);
374                     Futures.addCallback(hashDeletionFuture, new FutureCallback<Optional<FlowHashIdMapping>>() {
375                         @Override
376                         public void onSuccess(Optional<FlowHashIdMapping> optFlowHashIdMapping) {
377                           FlowHashIdMapKey flowHashIdMapKeyToDelete = null;
378                           if (optFlowHashIdMapping.isPresent()) {
379                               FlowHashIdMapping flowHashIdMapping = optFlowHashIdMapping.get();
380                               for (FlowHashIdMap flowHashId : flowHashIdMapping.getFlowHashIdMap()) {
381                                   if (flowHashId.getFlowId().getValue().equals(flowId)) {
382                                       flowHashIdMapKeyToDelete = flowHashId.getKey();
383                                       break;
384                                   }
385                               }
386                           }
387                           if (flowHashIdMapKeyToDelete != null) {
388                               final KeyedInstanceIdentifier<FlowHashIdMap, FlowHashIdMapKey> iiToFlowHashIdToDelete = iiToTable
389                                     .augmentation(FlowHashIdMapping.class).child(FlowHashIdMap.class, flowHashIdMapKeyToDelete);
390                               rwTx.delete(LogicalDatastoreType.OPERATIONAL, iiToFlowHashIdToDelete);
391                               rwTx.submit();
392                           }
393                         }
394
395                         @Override
396                         public void onFailure(Throwable t) {
397                             LOG.debug("Reading flow-hash-id map from operational DS wasn't successful");
398                         }
399                     });
400
401                 }
402
403                 allFlowMods.addAll(ofFlowModInputs);
404                 LOG.debug("Number of flows to push to switch: {}", allFlowMods.size());
405                 result = chainFlowMods(allFlowMods, 0, getTaskContext(), getCookie());
406
407                 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
408                 OFRpcTaskUtil.hookFutureNotification(this, result,
409                         getRpcNotificationProviderService(),
410                         createFlowUpdatedNotification(in));
411
412                 return result;
413             }
414
415
416             CheckedFuture<Optional<FlowHashIdMapping>, ReadFailedException> readFlowHashIdMappingFromOperationalDS(final ReadWriteTransaction rwTx) {
417                 InstanceIdentifier<FlowHashIdMapping> iiToFlowHashIdMapping = iiToTable
418                         .augmentation(FlowHashIdMapping.class);
419                     return rwTx.read(LogicalDatastoreType.OPERATIONAL, iiToFlowHashIdMapping);
420             }
421
422             @Override
423             public Boolean isBarrier() {
424                 return getInput().getUpdatedFlow().isBarrier();
425             }
426         }
427         return new OFRpcTaskImpl(taskContext, cookie, input, rwTx);
428     }
429
430
431     /**
432      * @param input update flow input
433      * @return flow update notification
434      */
435     protected static NotificationComposer<FlowUpdated> createFlowUpdatedNotification(final UpdateFlowInput input) {
436         return new NotificationComposer<FlowUpdated>() {
437             @Override
438             public FlowUpdated compose(TransactionId tXid) {
439                 FlowUpdatedBuilder updFlow = new FlowUpdatedBuilder(input.getUpdatedFlow());
440                 updFlow.setTransactionId(tXid);
441                 updFlow.setFlowRef(input.getFlowRef());
442                 return updFlow.build();
443             }
444         };
445     }
446
447     /**
448      * @param taskContext taks context
449      * @param input group update input
450      * @param cookie switch connection distinguisher cookie value
451      * @return update group task
452      */
453     public static OFRpcTask<AddGroupInput, RpcResult<UpdateGroupOutput>> createAddGroupTask(
454             final OFRpcTaskContext taskContext, AddGroupInput input,
455             final SwitchConnectionDistinguisher cookie) {
456         class OFRpcTaskImpl extends OFRpcTask<AddGroupInput, RpcResult<UpdateGroupOutput>> {
457
458             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddGroupInput input) {
459                 super(taskContext, cookie, input);
460             }
461
462             @Override
463             public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
464                 ListenableFuture<RpcResult<UpdateGroupOutput>> result = SettableFuture.create();
465
466                 // Convert the AddGroupInput to GroupModInput
467                 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(),
468                         getVersion(), getSession().getFeatures().getDatapathId());
469                 final Long xId = getSession().getNextXid();
470                 ofGroupModInput.setXid(xId);
471
472                 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
473                         .groupMod(ofGroupModInput.build(), getCookie());
474                 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
475
476                 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
477                 OFRpcTaskUtil.hookFutureNotification(this, result,
478                         getRpcNotificationProviderService(), createGroupAddedNotification(getInput()));
479
480                 return result;
481             }
482
483             @Override
484             public Boolean isBarrier() {
485                 return getInput().isBarrier();
486             }
487         };
488
489         return new OFRpcTaskImpl(taskContext, cookie, input);
490     }
491
492
493     /**
494      * @param input group add input
495      * @return group added notification
496      */
497     protected static NotificationComposer<GroupAdded> createGroupAddedNotification(
498             final AddGroupInput input) {
499         return new NotificationComposer<GroupAdded>() {
500             @Override
501             public GroupAdded compose(TransactionId tXid) {
502                 GroupAddedBuilder groupMod = new GroupAddedBuilder((Group) input);
503                 groupMod.setTransactionId(tXid);
504                 groupMod.setGroupRef(input.getGroupRef());
505                 return groupMod.build();
506             }
507         };
508     }
509
510     /**
511      * @param taskContext task context
512      * @param input meter add input
513      * @param cookie switch connection distinguisher
514      * @return update meter task
515      */
516     public static OFRpcTask<AddMeterInput, RpcResult<UpdateMeterOutput>> createAddMeterTask(
517             OFRpcTaskContext taskContext, AddMeterInput input,
518             SwitchConnectionDistinguisher cookie) {
519         class OFRpcTaskImpl extends OFRpcTask<AddMeterInput, RpcResult<UpdateMeterOutput>> {
520
521             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddMeterInput input) {
522                 super(taskContext, cookie, input);
523             }
524
525             @Override
526             public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
527                 ListenableFuture<RpcResult<UpdateMeterOutput>> result = SettableFuture.create();
528
529                 // Convert the AddGroupInput to GroupModInput
530                 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput(), getVersion());
531                 final Long xId = getSession().getNextXid();
532                 ofMeterModInput.setXid(xId);
533
534                 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
535                         .meterMod(ofMeterModInput.build(), getCookie());
536                 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
537
538                 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
539                 OFRpcTaskUtil.hookFutureNotification(this, result,
540                         getRpcNotificationProviderService(), createMeterAddedNotification(getInput()));
541
542                 return result;
543             }
544
545             @Override
546             public Boolean isBarrier() {
547                 return getInput().isBarrier();
548             }
549         };
550
551         return new OFRpcTaskImpl(taskContext, cookie, input);
552     }
553
554     /**
555      * @param input add meter input
556      * @return meter added notification composer
557      */
558     protected static NotificationComposer<MeterAdded> createMeterAddedNotification(
559             final AddMeterInput input) {
560         return new NotificationComposer<MeterAdded>() {
561             @Override
562             public MeterAdded compose(TransactionId tXid) {
563                 MeterAddedBuilder meterMod = new MeterAddedBuilder((Meter) input);
564                 meterMod.setTransactionId(tXid);
565                 meterMod.setMeterRef(input.getMeterRef());
566                 return meterMod.build();
567             }
568         };
569     }
570
571     /**
572      * @param taskContext task context
573      * @param input update group output
574      * @param cookie switch connection distinguisher cookie value
575      * @return UpdateFlow task
576      */
577     public static OFRpcTask<UpdateGroupInput, RpcResult<UpdateGroupOutput>> createUpdateGroupTask(
578             OFRpcTaskContext taskContext, UpdateGroupInput input,
579             SwitchConnectionDistinguisher cookie) {
580         class OFRpcTaskImpl extends OFRpcTask<UpdateGroupInput, RpcResult<UpdateGroupOutput>> {
581
582             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
583                     UpdateGroupInput input) {
584                 super(taskContext, cookie, input);
585             }
586
587             @Override
588             public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
589                 ListenableFuture<RpcResult<UpdateGroupOutput>> result = null;
590
591                 // Convert the UpdateGroupInput to GroupModInput
592                 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(
593                         getInput().getUpdatedGroup(), getVersion(),
594                         getSession().getFeatures().getDatapathId());
595                 final Long xId = getSession().getNextXid();
596                 ofGroupModInput.setXid(xId);
597
598                 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib =
599                         getMessageService().groupMod(ofGroupModInput.build(), getCookie());
600                 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
601
602                 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
603                 OFRpcTaskUtil.hookFutureNotification(this, result,
604                         getRpcNotificationProviderService(), createGroupUpdatedNotification(getInput()));
605
606                 return result;
607             }
608
609             @Override
610             public Boolean isBarrier() {
611                 return getInput().getUpdatedGroup().isBarrier();
612             }
613         }
614
615         return new OFRpcTaskImpl(taskContext, cookie, input);
616     }
617
618     /**
619      * @param input group update input
620      * @return group updated notification composer
621      */
622     protected static NotificationComposer<GroupUpdated> createGroupUpdatedNotification(
623             final UpdateGroupInput input) {
624         return new NotificationComposer<GroupUpdated>() {
625             @Override
626             public GroupUpdated compose(TransactionId tXid) {
627                 GroupUpdatedBuilder groupMod = new GroupUpdatedBuilder(input.getUpdatedGroup());
628                 groupMod.setTransactionId(tXid);
629                 groupMod.setGroupRef(input.getGroupRef());
630                 return groupMod.build();
631             }
632         };
633     }
634
635     /**
636      * @param taskContext task context
637      * @param input update meter input
638      * @param cookie switch connection distinguisher cookie value
639      * @return update meter task
640      */
641     public static OFRpcTask<UpdateMeterInput, RpcResult<UpdateMeterOutput>> createUpdateMeterTask(
642             OFRpcTaskContext taskContext, UpdateMeterInput input,
643             SwitchConnectionDistinguisher cookie) {
644         class OFRpcTaskImpl extends OFRpcTask<UpdateMeterInput, RpcResult<UpdateMeterOutput>> {
645
646             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
647                     UpdateMeterInput input) {
648                 super(taskContext, cookie, input);
649             }
650
651             @Override
652             public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
653                 ListenableFuture<RpcResult<UpdateMeterOutput>> result = null;
654
655                 // Convert the UpdateMeterInput to MeterModInput
656                 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(
657                         getInput().getUpdatedMeter(), getVersion());
658                 final Long xId = getSession().getNextXid();
659                 ofMeterModInput.setXid(xId);
660
661                 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib =
662                         getMessageService().meterMod(ofMeterModInput.build(), getCookie());
663                 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
664
665                 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
666                 OFRpcTaskUtil.hookFutureNotification(this, result,
667                         getRpcNotificationProviderService(), createMeterUpdatedNotification(getInput()));
668                 return result;
669             }
670
671             @Override
672             public Boolean isBarrier() {
673                 return getInput().getUpdatedMeter().isBarrier();
674             }
675         }
676
677         return new OFRpcTaskImpl(taskContext, cookie, input);
678     }
679
680     /**
681      * @param input meter update input
682      * @return meter updated notification
683      */
684     protected static NotificationComposer<MeterUpdated> createMeterUpdatedNotification(
685             final UpdateMeterInput input) {
686         return new NotificationComposer<MeterUpdated>() {
687             @Override
688             public MeterUpdated compose(TransactionId tXid) {
689                 MeterUpdatedBuilder meterMod = new MeterUpdatedBuilder(input.getUpdatedMeter());
690                 meterMod.setTransactionId(tXid);
691                 meterMod.setMeterRef(input.getMeterRef());
692                 return meterMod.build();
693             }
694         };
695     }
696
697
698     /**
699      * @param taskContext task context
700      * @param input update flow input
701      * @param cookie switch connection distinguisher cookie value
702      * @return task remove flow task
703      */
704     public static OFRpcTask<RemoveFlowInput, RpcResult<UpdateFlowOutput>> createRemoveFlowTask(
705             OFRpcTaskContext taskContext, RemoveFlowInput input,
706             SwitchConnectionDistinguisher cookie) {
707         class OFRpcTaskImpl extends OFRpcTask<RemoveFlowInput, RpcResult<UpdateFlowOutput>> {
708
709             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
710                     RemoveFlowInput input) {
711                 super(taskContext, cookie, input);
712             }
713
714             @Override
715             public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
716                 ListenableFuture<RpcResult<UpdateFlowOutput>> result = SettableFuture.create();
717
718                 // Convert the AddFlowInput to FlowModInput
719                 List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput(),
720                         getVersion(), getSession().getFeatures().getDatapathId());
721
722                 result = chainFlowMods(ofFlowModInputs, 0, getTaskContext(), getCookie());
723                 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
724
725                 OFRpcTaskUtil.hookFutureNotification(this, result,
726                         getRpcNotificationProviderService(),
727                         createFlowRemovedNotification(getInput()));
728                 return result;
729             }
730
731             @Override
732             public Boolean isBarrier() {
733                 return getInput().isBarrier();
734             }
735         }
736
737         return new OFRpcTaskImpl(taskContext, cookie, input);
738     }
739
740     /**
741      * @param input remove flow input
742      * @return flow removed notification
743      */
744     protected static NotificationComposer<FlowRemoved> createFlowRemovedNotification(
745             final RemoveFlowInput input) {
746         return new NotificationComposer<FlowRemoved>() {
747             @Override
748             public FlowRemoved compose(TransactionId tXid) {
749                 FlowRemovedBuilder removedFlow = new FlowRemovedBuilder((Flow) input);
750                 removedFlow.setTransactionId(tXid);
751                 removedFlow.setFlowRef(input.getFlowRef());
752                 return removedFlow.build();
753             }
754         };
755     }
756
757
758     /**
759      * @param taskContext task context
760      * @param input remove group input
761      * @param cookie switch connection distinguisher cookie value
762      * @return task remove group task
763      */
764     public static OFRpcTask<RemoveGroupInput, RpcResult<UpdateGroupOutput>> createRemoveGroupTask(
765             final OFRpcTaskContext taskContext, RemoveGroupInput input,
766             final SwitchConnectionDistinguisher cookie) {
767         class OFRpcTaskImpl extends OFRpcTask<RemoveGroupInput, RpcResult<UpdateGroupOutput>> {
768
769             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
770                     RemoveGroupInput input) {
771                 super(taskContext, cookie, input);
772             }
773
774             @Override
775             public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
776                 ListenableFuture<RpcResult<UpdateGroupOutput>> result = SettableFuture.create();
777
778                 // Convert the AddGroupInput to GroupModInput
779                 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(),
780                         getVersion(), getSession().getFeatures().getDatapathId());
781                 final Long xId = getSession().getNextXid();
782                 ofGroupModInput.setXid(xId);
783
784                 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
785                         .groupMod(ofGroupModInput.build(), getCookie());
786                 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
787
788                 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
789                 OFRpcTaskUtil.hookFutureNotification(this, result,
790                         getRpcNotificationProviderService(), createGroupRemovedNotification(getInput()));
791
792                 return result;
793             }
794
795             @Override
796             public Boolean isBarrier() {
797                 return getInput().isBarrier();
798             }
799         }
800
801         return new OFRpcTaskImpl(taskContext, cookie, input);
802     }
803
804     /**
805      * @param input group remove input
806      * @return group removed notification
807      */
808     protected static NotificationComposer<GroupRemoved> createGroupRemovedNotification(
809             final RemoveGroupInput input) {
810         return new NotificationComposer<GroupRemoved>() {
811             @Override
812             public GroupRemoved compose(TransactionId tXid) {
813                 GroupRemovedBuilder removedGroup = new GroupRemovedBuilder((Group) input);
814                 removedGroup.setTransactionId(tXid);
815                 removedGroup.setGroupRef(input.getGroupRef());
816                 return removedGroup.build();
817             }
818         };
819     }
820
821     /**
822      * @param taskContext task context
823      * @param input meter removed input
824      * @param cookie switch connection distinguisher cookie value
825      * @return task meter remove task
826      */
827     public static OFRpcTask<RemoveMeterInput, RpcResult<UpdateMeterOutput>> createRemoveMeterTask(
828             OFRpcTaskContext taskContext, RemoveMeterInput input,
829             SwitchConnectionDistinguisher cookie) {
830
831         class OFRpcTaskImpl extends OFRpcTask<RemoveMeterInput, RpcResult<UpdateMeterOutput>> {
832
833             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
834                     RemoveMeterInput input) {
835                 super(taskContext, cookie, input);
836             }
837
838             @Override
839             public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
840                 ListenableFuture<RpcResult<UpdateMeterOutput>> result = SettableFuture.create();
841
842                 // Convert the AddGroupInput to GroupModInput
843                 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput(), getVersion());
844                 final Long xId = getSession().getNextXid();
845                 ofMeterModInput.setXid(xId);
846
847                 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
848                         .meterMod(ofMeterModInput.build(), getCookie());
849                 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
850
851                 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
852                 OFRpcTaskUtil.hookFutureNotification(this, result,
853                         getRpcNotificationProviderService(), createMeterRemovedNotification(getInput()));
854
855                 return result;
856             }
857
858             @Override
859             public Boolean isBarrier() {
860                 return getInput().isBarrier();
861             }
862         }
863
864         return new OFRpcTaskImpl(taskContext, cookie, input);
865
866     }
867
868     /**
869      * @param input remove meter input
870      * @return meter removed notification composer
871      */
872     protected static NotificationComposer<MeterRemoved> createMeterRemovedNotification(
873             final RemoveMeterInput input) {
874         return new NotificationComposer<MeterRemoved>() {
875             @Override
876             public MeterRemoved compose(TransactionId tXid) {
877                 MeterRemovedBuilder meterRemoved = new MeterRemovedBuilder((Meter) input);
878                 meterRemoved.setTransactionId(tXid);
879                 meterRemoved.setMeterRef(input.getMeterRef());
880                 return meterRemoved.build();
881             }
882         };
883     }
884
885     /**
886      * @param taskContext task context
887      * @param input get all statistics input
888      * @param cookie switch connection distinguisher cookie value
889      * @return task get all group statistics task
890      */
891     public static OFRpcTask<GetAllGroupStatisticsInput, RpcResult<GetAllGroupStatisticsOutput>> createGetAllGroupStatisticsTask(
892             final OFRpcTaskContext taskContext, GetAllGroupStatisticsInput input,
893             SwitchConnectionDistinguisher cookie) {
894
895         class OFRpcTaskImpl extends OFRpcTask<GetAllGroupStatisticsInput, RpcResult<GetAllGroupStatisticsOutput>> {
896
897             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
898                     GetAllGroupStatisticsInput input) {
899                 super(taskContext, cookie, input);
900             }
901
902             @Override
903             public ListenableFuture<RpcResult<GetAllGroupStatisticsOutput>> call() {
904                 final SettableFuture<RpcResult<GetAllGroupStatisticsOutput>> result = SettableFuture.create();
905
906                 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
907                     RpcResult<GetAllGroupStatisticsOutput> rpcResult = RpcResultBuilder.success(
908                             new GetAllGroupStatisticsOutputBuilder().build()).build();
909
910                     return Futures.immediateFuture(rpcResult);
911                 } else {
912
913                     // Generate xid to associate it with the request
914                     final Long xid = taskContext.getSession().getNextXid();
915
916                     // Create multipart request body for fetch all the group stats
917                     MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
918                     MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
919                     mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(
920                             org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731
921                                     .Group.OFPGALL.getIntValue())));
922                     caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
923
924                     // Create multipart request header
925                     MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPGROUP,
926                             taskContext, xid);
927
928                     // Set request body to main multipart request
929                     mprInput.setMultipartRequestBody(caseBuilder.build());
930
931                     // Send the request, no cookies associated, use any connection
932
933                     Future<RpcResult<Void>> resultFromOFLib = getMessageService()
934                             .multipartRequest(mprInput.build(), getCookie());
935                     ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
936
937                     Futures.addCallback(resultLib, new ResultCallback<GetAllGroupStatisticsOutput>(result) {
938                         @Override
939                         public GetAllGroupStatisticsOutput createResult() {
940                             GetAllGroupStatisticsOutputBuilder groupStatBuilder = new GetAllGroupStatisticsOutputBuilder()
941                                     .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
942                             return groupStatBuilder.build();
943                         }
944                     });
945
946                     return result;
947                 }
948             }
949         }
950
951         return new OFRpcTaskImpl(taskContext, cookie, input);
952     }
953
954     /**
955      * @param taskContext task context
956      * @param input get group description input
957      * @param cookie switch connection distinguisher cookie value
958      * @return task get group description task
959      */
960     public static OFRpcTask<GetGroupDescriptionInput, RpcResult<GetGroupDescriptionOutput>> createGetGroupDescriptionTask(
961             final OFRpcTaskContext taskContext, GetGroupDescriptionInput input,
962             SwitchConnectionDistinguisher cookie) {
963         class OFRpcTaskImpl extends OFRpcTask<GetGroupDescriptionInput, RpcResult<GetGroupDescriptionOutput>> {
964
965             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
966                     GetGroupDescriptionInput input) {
967                 super(taskContext, cookie, input);
968             }
969
970             @Override
971             public ListenableFuture<RpcResult<GetGroupDescriptionOutput>> call()
972                     throws Exception {
973                 final SettableFuture<RpcResult<GetGroupDescriptionOutput>> result = SettableFuture.create();
974
975                 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
976                     RpcResult<GetGroupDescriptionOutput> rpcResult = RpcResultBuilder.success(
977                             new GetGroupDescriptionOutputBuilder().build()).build();
978                     return Futures.immediateFuture(rpcResult);
979                 } else {
980                     final Long xid = taskContext.getSession().getNextXid();
981
982                     MultipartRequestGroupDescCaseBuilder mprGroupDescCaseBuild =
983                             new MultipartRequestGroupDescCaseBuilder();
984                     MultipartRequestInputBuilder mprInput =
985                             createMultipartHeader(MultipartType.OFPMPGROUPDESC, taskContext, xid);
986                     mprInput.setMultipartRequestBody(mprGroupDescCaseBuild.build());
987                     Future<RpcResult<Void>> resultFromOFLib = getMessageService()
988                             .multipartRequest(mprInput.build(), getCookie());
989                     ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
990
991                     Futures.addCallback(resultLib, new ResultCallback<GetGroupDescriptionOutput>(result) {
992                         @Override
993                         public GetGroupDescriptionOutput createResult() {
994                             GetGroupDescriptionOutputBuilder groupStatBuilder = new GetGroupDescriptionOutputBuilder()
995                                     .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
996                             return groupStatBuilder.build();
997                         }
998                     });
999                     return result;
1000                 }
1001             }
1002         }
1003
1004         return new OFRpcTaskImpl(taskContext, cookie, input);
1005     }
1006
1007     /**
1008      * @param taskContext task context
1009      * @param input get group feature input
1010      * @param cookie switch connection distinguisher cookie value
1011      * @return task get group feature task
1012      */
1013     public static OFRpcTask<GetGroupFeaturesInput, RpcResult<GetGroupFeaturesOutput>> createGetGroupFeaturesTask(
1014             final OFRpcTaskContext taskContext, GetGroupFeaturesInput input,
1015             SwitchConnectionDistinguisher cookie) {
1016         class OFRpcTaskImpl extends OFRpcTask<GetGroupFeaturesInput, RpcResult<GetGroupFeaturesOutput>> {
1017
1018             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1019                     GetGroupFeaturesInput input) {
1020                 super(taskContext, cookie, input);
1021                 // TODO Auto-generated constructor stub
1022             }
1023
1024             @Override
1025             public ListenableFuture<RpcResult<GetGroupFeaturesOutput>> call()
1026                     throws Exception {
1027                 final SettableFuture<RpcResult<GetGroupFeaturesOutput>> result = SettableFuture.create();
1028
1029                 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1030                     RpcResult<GetGroupFeaturesOutput> rpcResult = RpcResultBuilder.success(
1031                             new GetGroupFeaturesOutputBuilder().build()).build();
1032                     return Futures.immediateFuture(rpcResult);
1033                 } else {
1034                     final Long xid = taskContext.getSession().getNextXid();
1035
1036                     MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild =
1037                             new MultipartRequestGroupFeaturesCaseBuilder();
1038                     MultipartRequestInputBuilder mprInput =
1039                             createMultipartHeader(MultipartType.OFPMPGROUPFEATURES, taskContext, xid);
1040                     mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
1041                     Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1042                             .multipartRequest(mprInput.build(), getCookie());
1043                     ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1044
1045                     Futures.addCallback(resultLib, new ResultCallback<GetGroupFeaturesOutput>(result) {
1046                         @Override
1047                         public GetGroupFeaturesOutput createResult() {
1048                             GetGroupFeaturesOutputBuilder groupFeatureBuilder = new GetGroupFeaturesOutputBuilder()
1049                                     .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1050                             return groupFeatureBuilder.build();
1051                         }
1052                     });
1053                     return result;
1054                 }
1055             }
1056         }
1057
1058         return new OFRpcTaskImpl(taskContext, cookie, input);
1059     }
1060
1061     /**
1062      * @param taskContext task context
1063      * @param input get group statistics input
1064      * @param cookie switch connection distinguisher cookie value
1065      * @return task get group statistics task
1066      */
1067     public static OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>> createGetGroupStatisticsTask(
1068             final OFRpcTaskContext taskContext, final GetGroupStatisticsInput input,
1069             SwitchConnectionDistinguisher cookie) {
1070
1071         class OFRpcTaskImpl extends OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>> {
1072
1073             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1074                     GetGroupStatisticsInput input) {
1075                 super(taskContext, cookie, input);
1076             }
1077
1078             @Override
1079             public ListenableFuture<RpcResult<GetGroupStatisticsOutput>> call()
1080                     throws Exception {
1081                 final SettableFuture<RpcResult<GetGroupStatisticsOutput>> result = SettableFuture.create();
1082
1083                 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1084                     RpcResult<GetGroupStatisticsOutput> rpcResult = RpcResultBuilder.success(
1085                             new GetGroupStatisticsOutputBuilder().build()).build();
1086                     return Futures.immediateFuture(rpcResult);
1087                 } else {
1088                     final Long xid = taskContext.getSession().getNextXid();
1089
1090                     MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
1091                     MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
1092                     mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
1093                     caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
1094
1095                     MultipartRequestInputBuilder mprInput =
1096                             createMultipartHeader(MultipartType.OFPMPGROUP, taskContext, xid);
1097                     mprInput.setMultipartRequestBody(caseBuilder.build());
1098                     Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1099                             .multipartRequest(mprInput.build(), getCookie());
1100                     ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1101
1102                     Futures.addCallback(resultLib, new ResultCallback<GetGroupStatisticsOutput>(result) {
1103                         @Override
1104                         public GetGroupStatisticsOutput createResult() {
1105                             GetGroupStatisticsOutputBuilder groupStatisticsBuilder =
1106                                     new GetGroupStatisticsOutputBuilder()
1107                                             .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1108                             return groupStatisticsBuilder.build();
1109                         }
1110                     });
1111                     return result;
1112                 }
1113             }
1114         }
1115
1116         return new OFRpcTaskImpl(taskContext, cookie, input);
1117     }
1118
1119     /**
1120      * @param taskContext task context
1121      * @param input get meter config statistics input
1122      * @param cookie switch connection distinguisher cookie value
1123      * @return task get all mtere config statistics task
1124      */
1125     public static OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>> createGetAllMeterConfigStatisticsTask(
1126             final OFRpcTaskContext taskContext, final GetAllMeterConfigStatisticsInput input,
1127             SwitchConnectionDistinguisher cookie) {
1128         class OFRpcTaskImpl extends OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>> {
1129
1130             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1131                     GetAllMeterConfigStatisticsInput input) {
1132                 super(taskContext, cookie, input);
1133             }
1134
1135             @Override
1136             public ListenableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> call()
1137                     throws Exception {
1138                 final SettableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> result = SettableFuture.create();
1139
1140                 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1141                     RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = RpcResultBuilder.success(
1142                             new GetAllMeterConfigStatisticsOutputBuilder().build()).build();
1143                     return Futures.immediateFuture(rpcResult);
1144                 } else {
1145                     final Long xid = taskContext.getSession().getNextXid();
1146
1147                     MultipartRequestMeterConfigCaseBuilder caseBuilder =
1148                             new MultipartRequestMeterConfigCaseBuilder();
1149                     MultipartRequestMeterConfigBuilder mprMeterConfigBuild =
1150                             new MultipartRequestMeterConfigBuilder();
1151                     mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(
1152                             org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common
1153                                     .types.rev130731.Meter.OFPMALL.getIntValue())));
1154                     caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
1155
1156                     MultipartRequestInputBuilder mprInput =
1157                             createMultipartHeader(MultipartType.OFPMPMETERCONFIG, taskContext, xid);
1158                     mprInput.setMultipartRequestBody(caseBuilder.build());
1159                     Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1160                             .multipartRequest(mprInput.build(), getCookie());
1161                     ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1162
1163                     Futures.addCallback(resultLib, new ResultCallback<GetAllMeterConfigStatisticsOutput>(result) {
1164                         @Override
1165                         public GetAllMeterConfigStatisticsOutput createResult() {
1166                             GetAllMeterConfigStatisticsOutputBuilder allMeterConfStatBuilder =
1167                                     new GetAllMeterConfigStatisticsOutputBuilder()
1168                                             .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1169                             return allMeterConfStatBuilder.build();
1170                         }
1171                     });
1172                     return result;
1173                 }
1174             }
1175         }
1176
1177         return new OFRpcTaskImpl(taskContext, cookie, input);
1178     }
1179
1180     /**
1181      * @param taskContext task context
1182      * @param input get all meter statistics input
1183      * @param cookie switch connection distinguisher cookie value
1184      * @return task get all meter statistics task
1185      */
1186     public static OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>> createGetAllMeterStatisticsTask(
1187             final OFRpcTaskContext taskContext, final GetAllMeterStatisticsInput input,
1188             SwitchConnectionDistinguisher cookie) {
1189         class OFRpcTaskImpl extends OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>> {
1190
1191             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1192                     GetAllMeterStatisticsInput input) {
1193                 super(taskContext, cookie, input);
1194                 // TODO Auto-generated constructor stub
1195             }
1196
1197             @Override
1198             public ListenableFuture<RpcResult<GetAllMeterStatisticsOutput>> call()
1199                     throws Exception {
1200                 final SettableFuture<RpcResult<GetAllMeterStatisticsOutput>> result = SettableFuture.create();
1201
1202                 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1203                     RpcResult<GetAllMeterStatisticsOutput> rpcResult = RpcResultBuilder.success(
1204                             new GetAllMeterStatisticsOutputBuilder().build()).build();
1205                     return Futures.immediateFuture(rpcResult);
1206                 } else {
1207                     final Long xid = taskContext.getSession().getNextXid();
1208
1209                     MultipartRequestMeterCaseBuilder caseBuilder =
1210                             new MultipartRequestMeterCaseBuilder();
1211                     MultipartRequestMeterBuilder mprMeterBuild =
1212                             new MultipartRequestMeterBuilder();
1213                     mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(
1214                             org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common
1215                                     .types.rev130731.Meter.OFPMALL.getIntValue())));
1216                     caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
1217
1218                     MultipartRequestInputBuilder mprInput =
1219                             createMultipartHeader(MultipartType.OFPMPMETER, taskContext, xid);
1220                     mprInput.setMultipartRequestBody(caseBuilder.build());
1221                     Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1222                             .multipartRequest(mprInput.build(), getCookie());
1223                     ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1224
1225                     Futures.addCallback(resultLib, new ResultCallback<GetAllMeterStatisticsOutput>(result) {
1226                         @Override
1227                         public GetAllMeterStatisticsOutput createResult() {
1228                             GetAllMeterStatisticsOutputBuilder allMeterStatBuilder =
1229                                     new GetAllMeterStatisticsOutputBuilder()
1230                                             .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1231                             return allMeterStatBuilder.build();
1232                         }
1233                     });
1234                     return result;
1235                 }
1236             }
1237         }
1238
1239         return new OFRpcTaskImpl(taskContext, cookie, input);
1240     }
1241
1242     /**
1243      * @param taskContext task context
1244      * @param input get meter features input
1245      * @param cookie switch connection distinguisher cookie value
1246      * @return task get meter feature task
1247      */
1248     public static OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>> createGetMeterFeaturesTask(
1249             final OFRpcTaskContext taskContext, final GetMeterFeaturesInput input,
1250             SwitchConnectionDistinguisher cookie) {
1251
1252         class OFRpcTaskImpl extends OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>> {
1253
1254             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1255                     GetMeterFeaturesInput input) {
1256                 super(taskContext, cookie, input);
1257             }
1258
1259             @Override
1260             public ListenableFuture<RpcResult<GetMeterFeaturesOutput>> call()
1261                     throws Exception {
1262                 final SettableFuture<RpcResult<GetMeterFeaturesOutput>> result = SettableFuture.create();
1263
1264                 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1265                     RpcResult<GetMeterFeaturesOutput> rpcResult = RpcResultBuilder.success(
1266                             new GetMeterFeaturesOutputBuilder().build()).build();
1267                     return Futures.immediateFuture(rpcResult);
1268                 } else {
1269                     final Long xid = taskContext.getSession().getNextXid();
1270
1271                     MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild =
1272                             new MultipartRequestMeterFeaturesCaseBuilder();
1273
1274                     MultipartRequestInputBuilder mprInput =
1275                             createMultipartHeader(MultipartType.OFPMPMETERFEATURES, taskContext, xid);
1276                     mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
1277                     Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1278                             .multipartRequest(mprInput.build(), getCookie());
1279                     ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1280
1281                     Futures.addCallback(resultLib, new ResultCallback<GetMeterFeaturesOutput>(result) {
1282                         @Override
1283                         public GetMeterFeaturesOutput createResult() {
1284                             GetMeterFeaturesOutputBuilder meterFeaturesBuilder =
1285                                     new GetMeterFeaturesOutputBuilder()
1286                                             .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1287                             return meterFeaturesBuilder.build();
1288                         }
1289                     });
1290                     return result;
1291                 }
1292             }
1293         }
1294
1295         return new OFRpcTaskImpl(taskContext, cookie, input);
1296     }
1297
1298     /**
1299      * @param taskContext task context
1300      * @param input get meter statistics input
1301      * @param cookie switch connection distinguisher cookie value
1302      * @return task get meter statistics task
1303      */
1304     public static OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>> createGetMeterStatisticsTask(
1305             final OFRpcTaskContext taskContext, final GetMeterStatisticsInput input,
1306             SwitchConnectionDistinguisher cookie) {
1307
1308         class OFRpcTaskImpl extends OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>> {
1309
1310             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1311                     GetMeterStatisticsInput input) {
1312                 super(taskContext, cookie, input);
1313             }
1314
1315             @Override
1316             public ListenableFuture<RpcResult<GetMeterStatisticsOutput>> call()
1317                     throws Exception {
1318                 final SettableFuture<RpcResult<GetMeterStatisticsOutput>> result = SettableFuture.create();
1319
1320                 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1321                     RpcResult<GetMeterStatisticsOutput> rpcResult = RpcResultBuilder.success(
1322                             new GetMeterStatisticsOutputBuilder().build()).build();
1323                     return Futures.immediateFuture(rpcResult);
1324                 } else {
1325                     final Long xid = taskContext.getSession().getNextXid();
1326
1327                     MultipartRequestMeterCaseBuilder caseBuilder =
1328                             new MultipartRequestMeterCaseBuilder();
1329                     MultipartRequestMeterBuilder mprMeterBuild =
1330                             new MultipartRequestMeterBuilder();
1331                     mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
1332                     caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
1333
1334                     MultipartRequestInputBuilder mprInput =
1335                             createMultipartHeader(MultipartType.OFPMPMETER, taskContext, xid);
1336                     mprInput.setMultipartRequestBody(caseBuilder.build());
1337                     Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1338                             .multipartRequest(mprInput.build(), getCookie());
1339                     ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1340
1341                     Futures.addCallback(resultLib, new ResultCallback<GetMeterStatisticsOutput>(result) {
1342                         @Override
1343                         public GetMeterStatisticsOutput createResult() {
1344                             GetMeterStatisticsOutputBuilder meterStatBuilder =
1345                                     new GetMeterStatisticsOutputBuilder()
1346                                             .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1347                             return meterStatBuilder.build();
1348                         }
1349                     });
1350                     return result;
1351                 }
1352             }
1353         }
1354
1355         return new OFRpcTaskImpl(taskContext, cookie, input);
1356     }
1357
1358     /**
1359      * @param taskContext task context
1360      * @param input get all node connector statistics input
1361      * @param cookie switch connection distinguisher cookie value
1362      * @return task get all node connector statistics task
1363      */
1364     public static OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>>
1365     createGetAllNodeConnectorsStatisticsTask(
1366             final OFRpcTaskContext taskContext, final GetAllNodeConnectorsStatisticsInput input,
1367             SwitchConnectionDistinguisher cookie) {
1368         class OFRpcTaskImpl extends OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>> {
1369
1370             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1371                     GetAllNodeConnectorsStatisticsInput input) {
1372                 super(taskContext, cookie, input);
1373             }
1374
1375             @Override
1376             public ListenableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> call()
1377                     throws Exception {
1378                 final SettableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> result = SettableFuture.create();
1379
1380                 final Long xid = taskContext.getSession().getNextXid();
1381
1382                 MultipartRequestPortStatsCaseBuilder caseBuilder =
1383                         new MultipartRequestPortStatsCaseBuilder();
1384                 MultipartRequestPortStatsBuilder mprPortStatsBuilder =
1385                         new MultipartRequestPortStatsBuilder();
1386                 // Select all ports
1387                 mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
1388                 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1389
1390                 MultipartRequestInputBuilder mprInput =
1391                         createMultipartHeader(MultipartType.OFPMPPORTSTATS, taskContext, xid);
1392                 mprInput.setMultipartRequestBody(caseBuilder.build());
1393                 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1394                         .multipartRequest(mprInput.build(), getCookie());
1395                 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1396
1397                 Futures.addCallback(resultLib, new ResultCallback<GetAllNodeConnectorsStatisticsOutput>(result) {
1398                     @Override
1399                     public GetAllNodeConnectorsStatisticsOutput createResult() {
1400                         GetAllNodeConnectorsStatisticsOutputBuilder allNodeConnectorStatBuilder =
1401                                 new GetAllNodeConnectorsStatisticsOutputBuilder()
1402                                         .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1403                         return allNodeConnectorStatBuilder.build();
1404                     }
1405                 });
1406                 return result;
1407             }
1408         }
1409
1410         return new OFRpcTaskImpl(taskContext, cookie, input);
1411     }
1412
1413     /**
1414      * @param taskContext task context
1415      * @param input get node connector statistics input
1416      * @param cookie switch connection distinguisher cookie value
1417      * @return task get node connector statistics task
1418      */
1419     public static OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>>
1420     createGetNodeConnectorStatisticsTask(
1421             final OFRpcTaskContext taskContext, final GetNodeConnectorStatisticsInput input,
1422             SwitchConnectionDistinguisher cookie) {
1423         class OFRpcTaskImpl extends OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>> {
1424
1425             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1426                     GetNodeConnectorStatisticsInput input) {
1427                 super(taskContext, cookie, input);
1428             }
1429
1430             @Override
1431             public ListenableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> call()
1432                     throws Exception {
1433                 final SettableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> result = SettableFuture.create();
1434
1435                 final Long xid = taskContext.getSession().getNextXid();
1436
1437                 MultipartRequestPortStatsCaseBuilder caseBuilder =
1438                         new MultipartRequestPortStatsCaseBuilder();
1439                 MultipartRequestPortStatsBuilder mprPortStatsBuilder =
1440                         new MultipartRequestPortStatsBuilder();
1441                 // Set specific port
1442                 mprPortStatsBuilder
1443                         .setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
1444                                 OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
1445                                 input.getNodeConnectorId()));
1446                 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1447
1448                 MultipartRequestInputBuilder mprInput =
1449                         createMultipartHeader(MultipartType.OFPMPPORTSTATS, taskContext, xid);
1450                 mprInput.setMultipartRequestBody(caseBuilder.build());
1451                 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1452                         .multipartRequest(mprInput.build(), getCookie());
1453                 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1454
1455                 Futures.addCallback(resultLib, new ResultCallback<GetNodeConnectorStatisticsOutput>(result) {
1456                     @Override
1457                     public GetNodeConnectorStatisticsOutput createResult() {
1458                         GetNodeConnectorStatisticsOutputBuilder allNodeConnectorStatBuilder =
1459                                 new GetNodeConnectorStatisticsOutputBuilder()
1460                                         .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1461                         return allNodeConnectorStatBuilder.build();
1462                     }
1463                 });
1464                 return result;
1465             }
1466         }
1467
1468         return new OFRpcTaskImpl(taskContext, cookie, input);
1469     }
1470
1471     /**
1472      * @param taskContext task context
1473      * @param input get all flow statistics from flow table
1474      * @param cookie switch connection distinguisher cookie value
1475      * @return task get all flow statistics from flow table task
1476      */
1477     public static OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>>
1478     createGetAllFlowStatisticsFromFlowTableTask(
1479             final OFRpcTaskContext taskContext,
1480             final GetAllFlowStatisticsFromFlowTableInput input,
1481             SwitchConnectionDistinguisher cookie) {
1482         class OFRpcTaskImpl extends OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> {
1483
1484             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1485                     GetAllFlowStatisticsFromFlowTableInput input) {
1486                 super(taskContext, cookie, input);
1487             }
1488
1489             @Override
1490             public ListenableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> call() throws Exception {
1491                 final SettableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> result = SettableFuture.create();
1492
1493                 final Long xid = taskContext.getSession().getNextXid();
1494
1495                 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1496                 mprFlowRequestBuilder.setTableId(input.getTableId().getValue());
1497                 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1498                 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1499                 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1500                 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1501                 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1502                         .getPrimaryConductor().getVersion(), mprFlowRequestBuilder);
1503
1504                 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1505                 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1506
1507                 MultipartRequestInputBuilder mprInput =
1508                         createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid);
1509                 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1510                 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1511                         .multipartRequest(mprInput.build(), getCookie());
1512                 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1513
1514                 Futures.addCallback(resultLib, new ResultCallback<GetAllFlowStatisticsFromFlowTableOutput>(result) {
1515                     @Override
1516                     public GetAllFlowStatisticsFromFlowTableOutput createResult() {
1517                         GetAllFlowStatisticsFromFlowTableOutputBuilder allFlowStatsFromFlowTableBuilder =
1518                                 new GetAllFlowStatisticsFromFlowTableOutputBuilder()
1519                                         .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1520                         return allFlowStatsFromFlowTableBuilder.build();
1521                     }
1522                 });
1523                 return result;
1524             }
1525         }
1526
1527         return new OFRpcTaskImpl(taskContext, cookie, input);
1528     }
1529
1530     /**
1531      * @param taskContext task context
1532      * @param input get all flow statistics from all flow table
1533      * @param cookie switch connection distinguisher cookie value
1534      * @return task get all flow statistics from all flow table task
1535      */
1536     public static OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput, RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>>
1537     createGetAllFlowsStatisticsFromAllFlowTablesTask(
1538             final OFRpcTaskContext taskContext,
1539             final GetAllFlowsStatisticsFromAllFlowTablesInput input,
1540             SwitchConnectionDistinguisher cookie) {
1541         class OFRpcTaskImpl extends OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput,
1542                 RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> {
1543
1544             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1545                     GetAllFlowsStatisticsFromAllFlowTablesInput input) {
1546                 super(taskContext, cookie, input);
1547             }
1548
1549             @Override
1550             public ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> call() throws Exception {
1551                 final SettableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> result = SettableFuture.create();
1552
1553                 final Long xid = taskContext.getSession().getNextXid();
1554
1555                 // Create multipart request body for fetch all the group stats
1556                 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder =
1557                         new MultipartRequestFlowCaseBuilder();
1558                 MultipartRequestFlowBuilder mprFlowRequestBuilder =
1559                         new MultipartRequestFlowBuilder();
1560                 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
1561                 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1562                 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1563                 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1564                 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1565                 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1566                         .getPrimaryConductor().getVersion(), mprFlowRequestBuilder);
1567
1568                 MultipartRequestInputBuilder mprInput =
1569                         createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid);
1570                 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1571                 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1572                 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1573                         .multipartRequest(mprInput.build(), getCookie());
1574                 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1575
1576                 Futures.addCallback(resultLib, new ResultCallback<GetAllFlowsStatisticsFromAllFlowTablesOutput>(result) {
1577                     @Override
1578                     public GetAllFlowsStatisticsFromAllFlowTablesOutput createResult() {
1579                         GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder allFlowStatsFromAllFlowTableBuilder =
1580                                 new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder()
1581                                         .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1582                         return allFlowStatsFromAllFlowTableBuilder.build();
1583                     }
1584                 });
1585                 return result;
1586             }
1587         }
1588
1589         return new OFRpcTaskImpl(taskContext, cookie, input);
1590     }
1591
1592     /**
1593      * @param taskContext task context
1594      * @param input get flow statistics from flow table
1595      * @param cookie switch connection distinguisher cookie value
1596      * @return task get flow statistics from flow table task
1597      */
1598     public static OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>>
1599     createGetFlowStatisticsFromFlowTableTask(
1600             final OFRpcTaskContext taskContext,
1601             final GetFlowStatisticsFromFlowTableInput input, SwitchConnectionDistinguisher cookie) {
1602
1603         class OFRpcTaskImpl extends OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>> {
1604
1605             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1606                     GetFlowStatisticsFromFlowTableInput input) {
1607                 super(taskContext, cookie, input);
1608             }
1609
1610             @Override
1611             public ListenableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> call() throws Exception {
1612                 final SettableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> result = SettableFuture.create();
1613
1614                 final Long xid = taskContext.getSession().getNextXid();
1615
1616                 // Create multipart request body for fetch all the group stats
1617                 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1618                 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1619                 mprFlowRequestBuilder.setTableId(input.getTableId());
1620
1621                 if (input.getOutPort() != null) {
1622                     mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue());
1623                 } else {
1624                     mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1625                 }
1626
1627                 if (input.getOutGroup() != null) {
1628                     mprFlowRequestBuilder.setOutGroup(input.getOutGroup());
1629                 } else {
1630                     mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1631                 }
1632
1633                 if (input.getCookie() != null) {
1634                     mprFlowRequestBuilder.setCookie(input.getCookie().getValue());
1635                 } else {
1636                     mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1637                 }
1638
1639                 if (input.getCookieMask() != null) {
1640                     mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue());
1641                 } else {
1642                     mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1643                 }
1644
1645                 // convert and inject match
1646                 MatchReactor.getInstance().convert(input.getMatch(), taskContext.getSession()
1647                                 .getPrimaryConductor().getVersion(), mprFlowRequestBuilder,
1648                         taskContext.getSession().getFeatures().getDatapathId());
1649
1650                 // Set request body to main multipart request
1651                 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1652                 MultipartRequestInputBuilder mprInput =
1653                         createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid);
1654                 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1655                 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1656                         .multipartRequest(mprInput.build(), getCookie());
1657                 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1658
1659                 Futures.addCallback(resultLib, new ResultCallback<GetFlowStatisticsFromFlowTableOutput>(result) {
1660                     @Override
1661                     public GetFlowStatisticsFromFlowTableOutput createResult() {
1662                         GetFlowStatisticsFromFlowTableOutputBuilder flowStatsFromFlowTableBuilder =
1663                                 new GetFlowStatisticsFromFlowTableOutputBuilder()
1664                                         .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1665                         return flowStatsFromFlowTableBuilder.build();
1666                     }
1667                 });
1668                 return result;
1669             }
1670         }
1671
1672         return new OFRpcTaskImpl(taskContext, cookie, input);
1673     }
1674
1675     /**
1676      * @param taskContext task context
1677      * @param input get aggregate flow statistics from flow table for all flow input
1678      * @param cookie switch connection distinguisher cookie value
1679      * @return task get aggregate flow stats from flow table for all flow task
1680      */
1681     public static OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>>
1682     createGetAggregateFlowStatisticsFromFlowTableForAllFlowsTask(
1683             final OFRpcTaskContext taskContext,
1684             final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input, SwitchConnectionDistinguisher cookie) {
1685         class OFRpcTaskImpl extends OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> {
1686
1687             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1688                     GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
1689                 super(taskContext, cookie, input);
1690             }
1691
1692             @Override
1693             public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> call() throws Exception {
1694                 final SettableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> result = SettableFuture.create();
1695
1696                 final Long xid = taskContext.getSession().getNextXid();
1697
1698                 // Create multipart request body for fetch all the group stats
1699                 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1700                 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1701                 mprAggregateRequestBuilder.setTableId(input.getTableId().getValue());
1702                 mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1703                 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1704                 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1705                 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1706
1707                 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1708                         .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder);
1709
1710                 // Set request body to main multipart request
1711                 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1712                 MultipartRequestInputBuilder mprInput =
1713                         createMultipartHeader(MultipartType.OFPMPAGGREGATE, taskContext, xid);
1714                 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1715                 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1716                         .multipartRequest(mprInput.build(), getCookie());
1717                 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1718
1719                 Futures.addCallback(resultLib, new ResultCallback<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>(result) {
1720                     @Override
1721                     public GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput createResult() {
1722                         GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder flowStatsFromFlowTableBuilder =
1723                                 new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder()
1724                                         .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1725                         return flowStatsFromFlowTableBuilder.build();
1726                     }
1727                 });
1728                 return result;
1729             }
1730         }
1731
1732         return new OFRpcTaskImpl(taskContext, cookie, input);
1733     }
1734
1735     /**
1736      * @param taskContext task context
1737      * @param input aggregate flow statistics input
1738      * @param cookie switch connection distinguisher cookie value
1739      * @return task task to fetch the statistics
1740      */
1741     public static OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>
1742     createGetAggregateFlowStatisticsFromFlowTableForGivenMatchTask(
1743             final OFRpcTaskContext taskContext,
1744             final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input, SwitchConnectionDistinguisher cookie) {
1745         class OFRpcTaskImpl extends OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> {
1746
1747             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1748                     GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
1749                 super(taskContext, cookie, input);
1750             }
1751
1752             @Override
1753             public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> call() throws Exception {
1754                 final SettableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> result = SettableFuture.create();
1755
1756                 final Long xid = taskContext.getSession().getNextXid();
1757
1758                 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1759                 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1760                 mprAggregateRequestBuilder.setTableId(input.getTableId());
1761                 mprAggregateRequestBuilder.setOutPort(input.getOutPort().longValue());
1762                 // TODO: repeating code
1763                 if (taskContext.getSession().getPrimaryConductor().getVersion() ==
1764                         OFConstants.OFP_VERSION_1_3) {
1765                     mprAggregateRequestBuilder.setCookie(input.getCookie().getValue());
1766                     mprAggregateRequestBuilder.setCookieMask(input.getCookieMask().getValue());
1767                     mprAggregateRequestBuilder.setOutGroup(input.getOutGroup());
1768                 } else {
1769                     mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1770                     mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1771                     mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1772                 }
1773
1774                 MatchReactor.getInstance().convert(input.getMatch(), taskContext.getSession()
1775                                 .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder,
1776                         taskContext.getSession().getFeatures().getDatapathId());
1777
1778                 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1779                         .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder);
1780
1781                 // Set request body to main multipart request
1782                 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1783                 MultipartRequestInputBuilder mprInput =
1784                         createMultipartHeader(MultipartType.OFPMPAGGREGATE, taskContext, xid);
1785                 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1786                 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1787                         .multipartRequest(mprInput.build(), getCookie());
1788                 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1789
1790                 Futures.addCallback(resultLib, new ResultCallback<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>(result) {
1791                     @Override
1792                     public GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput createResult() {
1793                         GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder aggregFlowStatsFromFlowTableBuilder =
1794                                 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder()
1795                                         .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1796                         return aggregFlowStatsFromFlowTableBuilder.build();
1797                     }
1798                 });
1799                 return result;
1800             }
1801         }
1802
1803         return new OFRpcTaskImpl(taskContext, cookie, input);
1804     }
1805
1806     /**
1807      * @param taskContext task context
1808      * @param input flow table statistics input
1809      * @param cookie switch connection distinguisher cookie value
1810      * @return task task to fetch table statistics
1811      */
1812     public static OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>> createGetFlowTablesStatisticsTask(
1813             final OFRpcTaskContext taskContext, final GetFlowTablesStatisticsInput input, SwitchConnectionDistinguisher cookie) {
1814
1815         class OFRpcTaskImpl extends OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>> {
1816
1817             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1818                     GetFlowTablesStatisticsInput input) {
1819                 super(taskContext, cookie, input);
1820             }
1821
1822             @Override
1823             public ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>> call() throws Exception {
1824                 final SettableFuture<RpcResult<GetFlowTablesStatisticsOutput>> result = SettableFuture.create();
1825
1826                 final Long xid = taskContext.getSession().getNextXid();
1827
1828                 // Create multipart request body for fetch all the group stats
1829                 MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
1830                 MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
1831                 multipartRequestTableBuilder.setEmpty(true);
1832                 multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
1833
1834                 // Set request body to main multipart request
1835                 MultipartRequestInputBuilder mprInput =
1836                         createMultipartHeader(MultipartType.OFPMPTABLE, taskContext, xid);
1837                 mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
1838                 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1839                         .multipartRequest(mprInput.build(), getCookie());
1840                 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1841
1842                 Futures.addCallback(resultLib, new ResultCallback<GetFlowTablesStatisticsOutput>(result) {
1843                     @Override
1844                     public GetFlowTablesStatisticsOutput createResult() {
1845                         GetFlowTablesStatisticsOutputBuilder flowTableStatsBuilder =
1846                                 new GetFlowTablesStatisticsOutputBuilder()
1847                                         .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1848                         return flowTableStatsBuilder.build();
1849                     }
1850                 });
1851                 return result;
1852             }
1853         }
1854
1855         return new OFRpcTaskImpl(taskContext, cookie, input);
1856     }
1857
1858     /**
1859      * @param taskContext task context
1860      * @param input queue statistics input
1861      * @param cookie switch connection distinguisher cookie value
1862      * @return task task to fetch all queue statistics
1863      */
1864     public static OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> createGetAllQueuesStatisticsFromAllPortsTask(
1865             final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromAllPortsInput input, SwitchConnectionDistinguisher cookie) {
1866
1867         class OFRpcTaskImpl extends OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> {
1868
1869             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1870                     GetAllQueuesStatisticsFromAllPortsInput input) {
1871                 super(taskContext, cookie, input);
1872             }
1873
1874             @Override
1875             public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> call() throws Exception {
1876                 final SettableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> result = SettableFuture.create();
1877
1878                 final Long xid = taskContext.getSession().getNextXid();
1879
1880                 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1881                 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1882                 // Select all ports
1883                 mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
1884                 // Select all the queues
1885                 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
1886                 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1887
1888                 // Set request body to main multipart request
1889                 MultipartRequestInputBuilder mprInput =
1890                         createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid);
1891                 mprInput.setMultipartRequestBody(caseBuilder.build());
1892                 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1893                         .multipartRequest(mprInput.build(), getCookie());
1894                 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1895
1896                 Futures.addCallback(resultLib, new ResultCallback<GetAllQueuesStatisticsFromAllPortsOutput>(result) {
1897                     @Override
1898                     public GetAllQueuesStatisticsFromAllPortsOutput createResult() {
1899                         GetAllQueuesStatisticsFromAllPortsOutputBuilder allQueueStatsBuilder =
1900                                 new GetAllQueuesStatisticsFromAllPortsOutputBuilder()
1901                                         .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1902                         return allQueueStatsBuilder.build();
1903                     }
1904                 });
1905                 return result;
1906             }
1907         }
1908
1909         return new OFRpcTaskImpl(taskContext, cookie, input);
1910     }
1911
1912     /**
1913      * @param taskContext task context
1914      * @param input queue statist from specific port input
1915      * @param cookie switch connection distinguisher cookie value
1916      * @return task task to get queue statistics from specific port
1917      */
1918     public static OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> createGetAllQueuesStatisticsFromGivenPortTask(
1919             final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromGivenPortInput input, SwitchConnectionDistinguisher cookie) {
1920
1921         class OFRpcTaskImpl extends OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> {
1922
1923             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1924                     GetAllQueuesStatisticsFromGivenPortInput input) {
1925                 super(taskContext, cookie, input);
1926             }
1927
1928             @Override
1929             public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> call() throws Exception {
1930                 final SettableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> result = SettableFuture.create();
1931
1932                 final Long xid = taskContext.getSession().getNextXid();
1933
1934                 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1935                 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1936                 // Select all queues
1937                 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
1938                 // Select specific port
1939                 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
1940                         OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
1941                         input.getNodeConnectorId()));
1942                 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1943
1944                 // Set request body to main multipart request
1945                 MultipartRequestInputBuilder mprInput =
1946                         createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid);
1947                 mprInput.setMultipartRequestBody(caseBuilder.build());
1948                 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1949                         .multipartRequest(mprInput.build(), getCookie());
1950                 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1951
1952                 Futures.addCallback(resultLib, new ResultCallback<GetAllQueuesStatisticsFromGivenPortOutput>(result) {
1953                     @Override
1954                     public GetAllQueuesStatisticsFromGivenPortOutput createResult() {
1955                         GetAllQueuesStatisticsFromGivenPortOutputBuilder allQueueStatsBuilder =
1956                                 new GetAllQueuesStatisticsFromGivenPortOutputBuilder()
1957                                         .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1958                         return allQueueStatsBuilder.build();
1959                     }
1960                 });
1961                 return result;
1962             }
1963         }
1964
1965         return new OFRpcTaskImpl(taskContext, cookie, input);
1966     }
1967
1968     /**
1969      * @param taskContext task context
1970      * @param input queue statistics from given port
1971      * @param cookie switch connection distinguisher cookie value
1972      * @return task task to get queue statistics from given port
1973      */
1974     public static OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>> createGetQueueStatisticsFromGivenPortTask(
1975             final OFRpcTaskContext taskContext, final GetQueueStatisticsFromGivenPortInput input, SwitchConnectionDistinguisher cookie) {
1976
1977         class OFRpcTaskImpl extends OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>> {
1978
1979             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1980                     GetQueueStatisticsFromGivenPortInput input) {
1981                 super(taskContext, cookie, input);
1982             }
1983
1984             @Override
1985             public ListenableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> call() throws Exception {
1986                 final SettableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> result = SettableFuture.create();
1987
1988                 final Long xid = taskContext.getSession().getNextXid();
1989
1990                 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1991                 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1992                 // Select specific queue
1993                 mprQueueBuilder.setQueueId(input.getQueueId().getValue());
1994                 // Select specific port
1995                 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
1996                         OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
1997                         input.getNodeConnectorId()));
1998                 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1999
2000                 // Set request body to main multipart request
2001                 MultipartRequestInputBuilder mprInput =
2002                         createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid);
2003                 mprInput.setMultipartRequestBody(caseBuilder.build());
2004                 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
2005                         .multipartRequest(mprInput.build(), getCookie());
2006                 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
2007
2008                 Futures.addCallback(resultLib, new ResultCallback<GetQueueStatisticsFromGivenPortOutput>(result) {
2009                     @Override
2010                     public GetQueueStatisticsFromGivenPortOutput createResult() {
2011                         GetQueueStatisticsFromGivenPortOutputBuilder queueStatsFromPortBuilder =
2012                                 new GetQueueStatisticsFromGivenPortOutputBuilder()
2013                                         .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
2014                         return queueStatsFromPortBuilder.build();
2015                     }
2016                 });
2017                 return result;
2018             }
2019         }
2020
2021         return new OFRpcTaskImpl(taskContext, cookie, input);
2022     }
2023
2024     static MultipartRequestInputBuilder createMultipartHeader(MultipartType multipart,
2025                                                               OFRpcTaskContext taskContext, Long xid) {
2026         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
2027         mprInput.setType(multipart);
2028         mprInput.setVersion(taskContext.getSession().getPrimaryConductor().getVersion());
2029         mprInput.setXid(xid);
2030         mprInput.setFlags(new MultipartRequestFlags(false));
2031         return mprInput;
2032     }
2033
2034     private abstract static class ResultCallback<T> implements FutureCallback<RpcResult<Void>> {
2035
2036         private SettableFuture<RpcResult<T>> result;
2037
2038         /**
2039          * @param result result
2040          */
2041         public ResultCallback(SettableFuture<RpcResult<T>> result) {
2042             this.result = result;
2043         }
2044
2045         public abstract T createResult();
2046
2047         @Override
2048         public void onSuccess(RpcResult<Void> resultArg) {
2049             result.set(RpcResultBuilder.success(createResult()).build());
2050         }
2051
2052         @Override
2053         public void onFailure(Throwable t) {
2054             result.set(RpcResultBuilder.<T>failed().withWarning(
2055                     ErrorType.RPC,
2056                     OFConstants.ERROR_TAG_TIMEOUT,
2057                     "something wrong happened",
2058                     OFConstants.APPLICATION_TAG,
2059                     "", t).build());
2060         }
2061     }
2062
2063     /**
2064      * @param taskContext task context
2065      * @param input update port input
2066      * @param cookie switch connection distinguisher cookie value
2067      * @return task task to update port
2068      */
2069     public static OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>> createUpdatePortTask(
2070             final OFRpcTaskContext taskContext, final UpdatePortInput input,
2071             final SwitchConnectionDistinguisher cookie) {
2072
2073         class OFRpcTaskImpl extends OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>> {
2074
2075             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
2076                     UpdatePortInput input) {
2077                 super(taskContext, cookie, input);
2078             }
2079
2080             @Override
2081             public ListenableFuture<RpcResult<UpdatePortOutput>> call() {
2082                 ListenableFuture<RpcResult<UpdatePortOutput>> result = SettableFuture.create();
2083                 final Long xid = taskContext.getSession().getNextXid();
2084                 Port inputPort = input.getUpdatedPort().getPort().getPort().get(0);
2085
2086                 PortModInput ofPortModInput = PortConvertor.toPortModInput(inputPort,
2087                         taskContext.getSession().getPrimaryConductor().getVersion());
2088
2089                 PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
2090                 mdInput.setXid(xid);
2091
2092                 Future<RpcResult<UpdatePortOutput>> resultFromOFLib = getMessageService()
2093                         .portMod(mdInput.build(), cookie);
2094                 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
2095
2096                 return result;
2097             }
2098         }
2099
2100         return new OFRpcTaskImpl(taskContext, cookie, input);
2101     }
2102
2103     /**
2104      * @param taskContext task context
2105      * @param input update table input
2106      * @param cookie switch connection distinguisher cookie value
2107      * @return task task to udpate table input
2108      */
2109     public static OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>> createUpdateTableTask(
2110             final OFRpcTaskContext taskContext, final UpdateTableInput input,
2111             final SwitchConnectionDistinguisher cookie) {
2112
2113         class OFRpcTaskImpl extends OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>> {
2114
2115             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
2116                     UpdateTableInput input) {
2117                 super(taskContext, cookie, input);
2118             }
2119
2120             @Override
2121             public ListenableFuture<RpcResult<UpdateTableOutput>> call() {
2122                 final SettableFuture<RpcResult<UpdateTableOutput>> result = SettableFuture.create();
2123
2124                 final Long xid = taskContext.getSession().getNextXid();
2125
2126                 MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder();
2127                 MultipartRequestTableFeaturesBuilder requestBuilder = new MultipartRequestTableFeaturesBuilder();
2128                 List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor
2129                         .toTableFeaturesRequest(input.getUpdatedTable());
2130                 requestBuilder.setTableFeatures(ofTableFeatureList);
2131                 caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build());
2132
2133                 // Set request body to main multipart request
2134                 MultipartRequestInputBuilder mprInput =
2135                         createMultipartHeader(MultipartType.OFPMPTABLEFEATURES, taskContext, xid);
2136                 mprInput.setMultipartRequestBody(caseBuilder.build());
2137
2138                 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
2139                         .multipartRequest(mprInput.build(), getCookie());
2140                 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
2141
2142                 Futures.addCallback(resultLib, new ResultCallback<UpdateTableOutput>(result) {
2143                     @Override
2144                     public UpdateTableOutput createResult() {
2145                         UpdateTableOutputBuilder queueStatsFromPortBuilder =
2146                                 new UpdateTableOutputBuilder()
2147                                         .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
2148                         return queueStatsFromPortBuilder.build();
2149                     }
2150                 });
2151                 return result;
2152             }
2153         }
2154
2155         return new OFRpcTaskImpl(taskContext, cookie, input);
2156     }
2157
2158     public static OFRpcTask<SetConfigInput, RpcResult<SetConfigOutput>> createSetNodeConfigTask(final OFRpcTaskContext taskContext,
2159                                                                                                 final SetConfigInput input,
2160                                                                                                 final SwitchConnectionDistinguisher cookie) {
2161         class OFRpcTaskImpl extends OFRpcTask<SetConfigInput, RpcResult<SetConfigOutput>> {
2162
2163             public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
2164                     SetConfigInput input) {
2165                 super(taskContext, cookie, input);
2166             }
2167
2168             @Override
2169             public ListenableFuture<RpcResult<SetConfigOutput>> call() throws Exception {
2170
2171                 final SettableFuture<RpcResult<SetConfigOutput>> result = SettableFuture.create();
2172                 final Long xid = taskContext.getSession().getNextXid();
2173
2174                 SetConfigInputBuilder builder = new SetConfigInputBuilder();
2175                 SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag());
2176                 builder.setXid(xid);
2177                 builder.setFlags(flag);
2178                 builder.setMissSendLen(input.getMissSearchLength());
2179                 builder.setVersion(getVersion());
2180                 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(taskContext.getSession().getPrimaryConductor().getConnectionAdapter().setConfig(builder.build()));
2181                 Futures.addCallback(resultLib, new ResultCallback<SetConfigOutput>(result) {
2182                     @Override
2183                     public SetConfigOutput createResult() {
2184                         SetConfigOutputBuilder setConfigOutputBuilder = new SetConfigOutputBuilder();
2185                         setConfigOutputBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
2186                         return setConfigOutputBuilder.build();
2187                     }
2188                 });
2189                 return result;
2190             }
2191         }
2192
2193         return new OFRpcTaskImpl(taskContext, cookie, input);
2194     }
2195 }