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