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