2 * Copyright (c) 2013-2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.openflow.md.core.sal;
10 import java.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.concurrent.Future;
15 import org.opendaylight.openflowjava.protocol.api.util.BinContent;
16 import org.opendaylight.openflowplugin.api.OFConstants;
17 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
18 import org.opendaylight.openflowplugin.api.openflow.md.core.sal.NotificationComposer;
19 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
20 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
21 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor;
22 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
23 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
24 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor;
25 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
26 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
27 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdatedBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
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.rev150304.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.module.config.rev141015.SetConfigInput;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutput;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutputBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;
145 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;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInput;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutputBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInput;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutput;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutputBuilder;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutputBuilder;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInput;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutputBuilder;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInput;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutputBuilder;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder;
166 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
167 import org.opendaylight.yangtools.yang.common.RpcResult;
168 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
169 import org.slf4j.Logger;
170 import org.slf4j.LoggerFactory;
172 import com.google.common.util.concurrent.AsyncFunction;
173 import com.google.common.util.concurrent.FutureCallback;
174 import com.google.common.util.concurrent.Futures;
175 import com.google.common.util.concurrent.JdkFutureAdapters;
176 import com.google.common.util.concurrent.ListenableFuture;
177 import com.google.common.util.concurrent.SettableFuture;
182 public abstract class OFRpcTaskFactory {
183 protected static final Logger LOG = LoggerFactory.getLogger(OFRpcTaskFactory.class);
185 private OFRpcTaskFactory() {
186 // hiding implicit constructor
193 * @return UpdateFlow task
195 public static OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> createAddFlowTask(
196 OFRpcTaskContext taskContext, AddFlowInput input,
197 SwitchConnectionDistinguisher cookie) {
199 class OFRpcTaskImpl extends OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> {
201 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddFlowInput input) {
202 super(taskContext, cookie, input);
206 public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
207 ListenableFuture<RpcResult<UpdateFlowOutput>> result = SettableFuture.create();
209 // Convert the AddFlowInput to FlowModInput
210 List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput(),
211 getVersion(), getSession().getFeatures().getDatapathId());
212 LOG.debug("Number of flows to push to switch: {}", ofFlowModInputs.size());
213 result = chainFlowMods(ofFlowModInputs, 0, getTaskContext(), getCookie());
214 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
215 OFRpcTaskUtil.hookFutureNotification(this, result,
216 getRpcNotificationProviderService(),
217 createFlowAddedNotification(getInput()));
222 public Boolean isBarrier() {
223 return getInput().isBarrier();
227 return new OFRpcTaskImpl(taskContext, cookie, input);
231 * Recursive helper method for {@link OFRpcTaskFactory#createAddFlowTask()}
232 * and {@link OFRpcTaskFactory#createUpdateFlowTask()} to chain results
233 * of multiple flowmods.
234 * The next flowmod gets executed if the earlier one is successful.
235 * All the flowmods should have the same xid, in-order to cross-reference
238 protected static ListenableFuture<RpcResult<UpdateFlowOutput>> chainFlowMods(
239 final List<FlowModInputBuilder> ofFlowModInputs, final int index,
240 final OFRpcTaskContext taskContext, final SwitchConnectionDistinguisher cookie) {
242 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib =
243 createResultForFlowMod(taskContext, ofFlowModInputs.get(index), cookie);
245 ListenableFuture<RpcResult<UpdateFlowOutput>> result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
247 if (ofFlowModInputs.size() > index + 1) {
248 // there are more flowmods to chain
249 return Futures.transform(result,
250 new AsyncFunction<RpcResult<UpdateFlowOutput>, RpcResult<UpdateFlowOutput>>() {
252 public ListenableFuture<RpcResult<UpdateFlowOutput>> apply(RpcResult<UpdateFlowOutput> input) throws Exception {
253 if (input.isSuccessful()) {
254 return chainFlowMods(ofFlowModInputs, index + 1, taskContext, cookie);
256 LOG.warn("Flowmod failed. Any chained flowmods are ignored. xid:{}",
257 ofFlowModInputs.get(index).getXid());
258 return Futures.immediateFuture(input);
268 private static Future<RpcResult<UpdateFlowOutput>> createResultForFlowMod(
269 OFRpcTaskContext taskContext, FlowModInputBuilder flowModInput,
270 SwitchConnectionDistinguisher cookie) {
271 flowModInput.setXid(taskContext.getSession().getNextXid());
272 return taskContext.getMessageService().flowMod(flowModInput.build(), cookie);
280 protected static NotificationComposer<FlowAdded> createFlowAddedNotification(
281 final AddFlowInput input) {
282 return new NotificationComposer<FlowAdded>() {
284 public FlowAdded compose(TransactionId tXid) {
285 FlowAddedBuilder newFlow = new FlowAddedBuilder((Flow) input);
286 newFlow.setTransactionId(tXid);
287 newFlow.setFlowRef(input.getFlowRef());
288 return newFlow.build();
297 * @return UpdateFlow task
299 public static OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> createUpdateFlowTask(
300 final OFRpcTaskContext taskContext, UpdateFlowInput input,
301 SwitchConnectionDistinguisher cookie) {
303 class OFRpcTaskImpl extends OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> {
305 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
306 UpdateFlowInput input) {
307 super(taskContext, cookie, input);
311 public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
312 ListenableFuture<RpcResult<UpdateFlowOutput>> result = null;
314 UpdateFlowInput in = getInput();
315 UpdatedFlow updated = in.getUpdatedFlow();
316 OriginalFlow original = in.getOriginalFlow();
317 Short version = getVersion();
319 List<FlowModInputBuilder> allFlowMods = new ArrayList<>();
320 List<FlowModInputBuilder> ofFlowModInputs;
322 if (!FlowCreatorUtil.canModifyFlow(original, updated, version)) {
323 // We would need to remove original and add updated.
326 RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(original);
327 List<FlowModInputBuilder> ofFlowRemoveInput = FlowConvertor.toFlowModInputs(removeflow.build(),
328 version, getSession().getFeatures().getDatapathId());
329 // remove flow should be the first
330 allFlowMods.addAll(ofFlowRemoveInput);
331 AddFlowInputBuilder addFlowInputBuilder = new AddFlowInputBuilder(updated);
332 ofFlowModInputs = FlowConvertor.toFlowModInputs(addFlowInputBuilder.build(),
333 version, getSession().getFeatures().getDatapathId());
335 ofFlowModInputs = FlowConvertor.toFlowModInputs(updated,
336 version, getSession().getFeatures().getDatapathId());
339 allFlowMods.addAll(ofFlowModInputs);
340 LOG.debug("Number of flows to push to switch: {}", allFlowMods.size());
341 result = chainFlowMods(allFlowMods, 0, getTaskContext(), getCookie());
343 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
344 OFRpcTaskUtil.hookFutureNotification(this, result,
345 getRpcNotificationProviderService(),
346 createFlowUpdatedNotification(in));
351 public Boolean isBarrier() {
352 return getInput().getUpdatedFlow().isBarrier();
355 return new OFRpcTaskImpl(taskContext, cookie, input);
364 protected static NotificationComposer<FlowUpdated> createFlowUpdatedNotification(final UpdateFlowInput input) {
365 return new NotificationComposer<FlowUpdated>() {
367 public FlowUpdated compose(TransactionId tXid) {
368 FlowUpdatedBuilder updFlow = new FlowUpdatedBuilder(input.getUpdatedFlow());
369 updFlow.setTransactionId(tXid);
370 updFlow.setFlowRef(input.getFlowRef());
371 return updFlow.build();
380 * @return update group task
382 public static OFRpcTask<AddGroupInput, RpcResult<UpdateGroupOutput>> createAddGroupTask(
383 final OFRpcTaskContext taskContext, AddGroupInput input,
384 final SwitchConnectionDistinguisher cookie) {
385 class OFRpcTaskImpl extends OFRpcTask<AddGroupInput, RpcResult<UpdateGroupOutput>> {
387 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddGroupInput input) {
388 super(taskContext, cookie, input);
392 public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
393 ListenableFuture<RpcResult<UpdateGroupOutput>> result = SettableFuture.create();
395 // Convert the AddGroupInput to GroupModInput
396 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(),
397 getVersion(), getSession().getFeatures().getDatapathId());
398 final Long xId = getSession().getNextXid();
399 ofGroupModInput.setXid(xId);
401 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
402 .groupMod(ofGroupModInput.build(), getCookie());
403 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
405 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
406 OFRpcTaskUtil.hookFutureNotification(this, result,
407 getRpcNotificationProviderService(), createGroupAddedNotification(getInput()));
413 public Boolean isBarrier() {
414 return getInput().isBarrier();
418 return new OFRpcTaskImpl(taskContext, cookie, input);
426 protected static NotificationComposer<GroupAdded> createGroupAddedNotification(
427 final AddGroupInput input) {
428 return new NotificationComposer<GroupAdded>() {
430 public GroupAdded compose(TransactionId tXid) {
431 GroupAddedBuilder groupMod = new GroupAddedBuilder((Group) input);
432 groupMod.setTransactionId(tXid);
433 groupMod.setGroupRef(input.getGroupRef());
434 return groupMod.build();
443 * @return update meter task
445 public static OFRpcTask<AddMeterInput, RpcResult<UpdateMeterOutput>> createAddMeterTask(
446 OFRpcTaskContext taskContext, AddMeterInput input,
447 SwitchConnectionDistinguisher cookie) {
448 class OFRpcTaskImpl extends OFRpcTask<AddMeterInput, RpcResult<UpdateMeterOutput>> {
450 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddMeterInput input) {
451 super(taskContext, cookie, input);
455 public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
456 ListenableFuture<RpcResult<UpdateMeterOutput>> result = SettableFuture.create();
458 // Convert the AddGroupInput to GroupModInput
459 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput(), getVersion());
460 final Long xId = getSession().getNextXid();
461 ofMeterModInput.setXid(xId);
463 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
464 .meterMod(ofMeterModInput.build(), getCookie());
465 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
467 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
468 OFRpcTaskUtil.hookFutureNotification(this, result,
469 getRpcNotificationProviderService(), createMeterAddedNotification(getInput()));
475 public Boolean isBarrier() {
476 return getInput().isBarrier();
480 return new OFRpcTaskImpl(taskContext, cookie, input);
487 protected static NotificationComposer<MeterAdded> createMeterAddedNotification(
488 final AddMeterInput input) {
489 return new NotificationComposer<MeterAdded>() {
491 public MeterAdded compose(TransactionId tXid) {
492 MeterAddedBuilder meterMod = new MeterAddedBuilder((Meter) input);
493 meterMod.setTransactionId(tXid);
494 meterMod.setMeterRef(input.getMeterRef());
495 return meterMod.build();
504 * @return UpdateFlow task
506 public static OFRpcTask<UpdateGroupInput, RpcResult<UpdateGroupOutput>> createUpdateGroupTask(
507 OFRpcTaskContext taskContext, UpdateGroupInput input,
508 SwitchConnectionDistinguisher cookie) {
509 class OFRpcTaskImpl extends OFRpcTask<UpdateGroupInput, RpcResult<UpdateGroupOutput>> {
511 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
512 UpdateGroupInput input) {
513 super(taskContext, cookie, input);
517 public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
518 ListenableFuture<RpcResult<UpdateGroupOutput>> result = null;
520 // Convert the UpdateGroupInput to GroupModInput
521 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(
522 getInput().getUpdatedGroup(), getVersion(),
523 getSession().getFeatures().getDatapathId());
524 final Long xId = getSession().getNextXid();
525 ofGroupModInput.setXid(xId);
527 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib =
528 getMessageService().groupMod(ofGroupModInput.build(), getCookie());
529 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
531 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
532 OFRpcTaskUtil.hookFutureNotification(this, result,
533 getRpcNotificationProviderService(), createGroupUpdatedNotification(getInput()));
539 return new OFRpcTaskImpl(taskContext, cookie, input);
546 protected static NotificationComposer<GroupUpdated> createGroupUpdatedNotification(
547 final UpdateGroupInput input) {
548 return new NotificationComposer<GroupUpdated>() {
550 public GroupUpdated compose(TransactionId tXid) {
551 GroupUpdatedBuilder groupMod = new GroupUpdatedBuilder(input.getUpdatedGroup());
552 groupMod.setTransactionId(tXid);
553 groupMod.setGroupRef(input.getGroupRef());
554 return groupMod.build();
563 * @return update meter task
565 public static OFRpcTask<UpdateMeterInput, RpcResult<UpdateMeterOutput>> createUpdateMeterTask(
566 OFRpcTaskContext taskContext, UpdateMeterInput input,
567 SwitchConnectionDistinguisher cookie) {
568 class OFRpcTaskImpl extends OFRpcTask<UpdateMeterInput, RpcResult<UpdateMeterOutput>> {
570 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
571 UpdateMeterInput input) {
572 super(taskContext, cookie, input);
576 public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
577 ListenableFuture<RpcResult<UpdateMeterOutput>> result = null;
579 // Convert the UpdateMeterInput to MeterModInput
580 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(
581 getInput().getUpdatedMeter(), getVersion());
582 final Long xId = getSession().getNextXid();
583 ofMeterModInput.setXid(xId);
585 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib =
586 getMessageService().meterMod(ofMeterModInput.build(), getCookie());
587 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
589 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
590 OFRpcTaskUtil.hookFutureNotification(this, result,
591 getRpcNotificationProviderService(), createMeterUpdatedNotification(getInput()));
596 return new OFRpcTaskImpl(taskContext, cookie, input);
603 protected static NotificationComposer<MeterUpdated> createMeterUpdatedNotification(
604 final UpdateMeterInput input) {
605 return new NotificationComposer<MeterUpdated>() {
607 public MeterUpdated compose(TransactionId tXid) {
608 MeterUpdatedBuilder meterMod = new MeterUpdatedBuilder(input.getUpdatedMeter());
609 meterMod.setTransactionId(tXid);
610 meterMod.setMeterRef(input.getMeterRef());
611 return meterMod.build();
623 public static OFRpcTask<RemoveFlowInput, RpcResult<UpdateFlowOutput>> createRemoveFlowTask(
624 OFRpcTaskContext taskContext, RemoveFlowInput input,
625 SwitchConnectionDistinguisher cookie) {
626 class OFRpcTaskImpl extends OFRpcTask<RemoveFlowInput, RpcResult<UpdateFlowOutput>> {
628 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
629 RemoveFlowInput input) {
630 super(taskContext, cookie, input);
634 public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
635 ListenableFuture<RpcResult<UpdateFlowOutput>> result = SettableFuture.create();
637 // Convert the AddFlowInput to FlowModInput
638 FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(getInput(),
639 getVersion(), getSession().getFeatures().getDatapathId());
640 final Long xId = getSession().getNextXid();
641 ofFlowModInput.setXid(xId);
643 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib =
644 getMessageService().flowMod(ofFlowModInput.build(), getCookie());
645 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
647 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
648 OFRpcTaskUtil.hookFutureNotification(this, result,
649 getRpcNotificationProviderService(), createFlowRemovedNotification(getInput()));
655 return new OFRpcTaskImpl(taskContext, cookie, input);
662 protected static NotificationComposer<FlowRemoved> createFlowRemovedNotification(
663 final RemoveFlowInput input) {
664 return new NotificationComposer<FlowRemoved>() {
666 public FlowRemoved compose(TransactionId tXid) {
667 FlowRemovedBuilder removedFlow = new FlowRemovedBuilder((Flow) input);
668 removedFlow.setTransactionId(tXid);
669 removedFlow.setFlowRef(input.getFlowRef());
670 return removedFlow.build();
682 public static OFRpcTask<RemoveGroupInput, RpcResult<UpdateGroupOutput>> createRemoveGroupTask(
683 final OFRpcTaskContext taskContext, RemoveGroupInput input,
684 final SwitchConnectionDistinguisher cookie) {
685 class OFRpcTaskImpl extends OFRpcTask<RemoveGroupInput, RpcResult<UpdateGroupOutput>> {
687 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
688 RemoveGroupInput input) {
689 super(taskContext, cookie, input);
693 public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
694 ListenableFuture<RpcResult<UpdateGroupOutput>> result = SettableFuture.create();
696 // Convert the AddGroupInput to GroupModInput
697 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(),
698 getVersion(), getSession().getFeatures().getDatapathId());
699 final Long xId = getSession().getNextXid();
700 ofGroupModInput.setXid(xId);
702 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
703 .groupMod(ofGroupModInput.build(), getCookie());
704 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
706 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
707 OFRpcTaskUtil.hookFutureNotification(this, result,
708 getRpcNotificationProviderService(), createGroupRemovedNotification(getInput()));
714 return new OFRpcTaskImpl(taskContext, cookie, input);
721 protected static NotificationComposer<GroupRemoved> createGroupRemovedNotification(
722 final RemoveGroupInput input) {
723 return new NotificationComposer<GroupRemoved>() {
725 public GroupRemoved compose(TransactionId tXid) {
726 GroupRemovedBuilder removedGroup = new GroupRemovedBuilder((Group) input);
727 removedGroup.setTransactionId(tXid);
728 removedGroup.setGroupRef(input.getGroupRef());
729 return removedGroup.build();
740 public static OFRpcTask<RemoveMeterInput, RpcResult<UpdateMeterOutput>> createRemoveMeterTask(
741 OFRpcTaskContext taskContext, RemoveMeterInput input,
742 SwitchConnectionDistinguisher cookie) {
744 class OFRpcTaskImpl extends OFRpcTask<RemoveMeterInput, RpcResult<UpdateMeterOutput>> {
746 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
747 RemoveMeterInput input) {
748 super(taskContext, cookie, input);
752 public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
753 ListenableFuture<RpcResult<UpdateMeterOutput>> result = SettableFuture.create();
755 // Convert the AddGroupInput to GroupModInput
756 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput(), getVersion());
757 final Long xId = getSession().getNextXid();
758 ofMeterModInput.setXid(xId);
760 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
761 .meterMod(ofMeterModInput.build(), getCookie());
762 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
764 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
765 OFRpcTaskUtil.hookFutureNotification(this, result,
766 getRpcNotificationProviderService(), createMeterRemovedNotification(getInput()));
772 return new OFRpcTaskImpl(taskContext, cookie, input);
780 protected static NotificationComposer<MeterRemoved> createMeterRemovedNotification(
781 final RemoveMeterInput input) {
782 return new NotificationComposer<MeterRemoved>() {
784 public MeterRemoved compose(TransactionId tXid) {
785 MeterRemovedBuilder meterRemoved = new MeterRemovedBuilder((Meter) input);
786 meterRemoved.setTransactionId(tXid);
787 meterRemoved.setMeterRef(input.getMeterRef());
788 return meterRemoved.build();
799 public static OFRpcTask<GetAllGroupStatisticsInput, RpcResult<GetAllGroupStatisticsOutput>> createGetAllGroupStatisticsTask(
800 final OFRpcTaskContext taskContext, GetAllGroupStatisticsInput input,
801 SwitchConnectionDistinguisher cookie) {
803 class OFRpcTaskImpl extends OFRpcTask<GetAllGroupStatisticsInput, RpcResult<GetAllGroupStatisticsOutput>> {
805 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
806 GetAllGroupStatisticsInput input) {
807 super(taskContext, cookie, input);
811 public ListenableFuture<RpcResult<GetAllGroupStatisticsOutput>> call() {
812 final SettableFuture<RpcResult<GetAllGroupStatisticsOutput>> result = SettableFuture.create();
814 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
815 RpcResult<GetAllGroupStatisticsOutput> rpcResult = RpcResultBuilder.success(
816 new GetAllGroupStatisticsOutputBuilder().build()).build();
818 return Futures.immediateFuture(rpcResult);
821 // Generate xid to associate it with the request
822 final Long xid = taskContext.getSession().getNextXid();
824 // Create multipart request body for fetch all the group stats
825 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
826 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
827 mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(
828 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731
829 .Group.OFPGALL.getIntValue())));
830 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
832 // Create multipart request header
833 MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPGROUP,
836 // Set request body to main multipart request
837 mprInput.setMultipartRequestBody(caseBuilder.build());
839 // Send the request, no cookies associated, use any connection
841 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
842 .multipartRequest(mprInput.build(), getCookie());
843 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
845 Futures.addCallback(resultLib, new ResultCallback<GetAllGroupStatisticsOutput>(result) {
847 public GetAllGroupStatisticsOutput createResult() {
848 GetAllGroupStatisticsOutputBuilder groupStatBuilder = new GetAllGroupStatisticsOutputBuilder()
849 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
850 return groupStatBuilder.build();
859 return new OFRpcTaskImpl(taskContext, cookie, input);
868 public static OFRpcTask<GetGroupDescriptionInput, RpcResult<GetGroupDescriptionOutput>> createGetGroupDescriptionTask(
869 final OFRpcTaskContext taskContext, GetGroupDescriptionInput input,
870 SwitchConnectionDistinguisher cookie) {
871 class OFRpcTaskImpl extends OFRpcTask<GetGroupDescriptionInput, RpcResult<GetGroupDescriptionOutput>> {
873 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
874 GetGroupDescriptionInput input) {
875 super(taskContext, cookie, input);
879 public ListenableFuture<RpcResult<GetGroupDescriptionOutput>> call()
881 final SettableFuture<RpcResult<GetGroupDescriptionOutput>> result = SettableFuture.create();
883 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
884 RpcResult<GetGroupDescriptionOutput> rpcResult = RpcResultBuilder.success(
885 new GetGroupDescriptionOutputBuilder().build()).build();
886 return Futures.immediateFuture(rpcResult);
888 final Long xid = taskContext.getSession().getNextXid();
890 MultipartRequestGroupDescCaseBuilder mprGroupDescCaseBuild =
891 new MultipartRequestGroupDescCaseBuilder();
892 MultipartRequestInputBuilder mprInput =
893 createMultipartHeader(MultipartType.OFPMPGROUPDESC, taskContext, xid);
894 mprInput.setMultipartRequestBody(mprGroupDescCaseBuild.build());
895 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
896 .multipartRequest(mprInput.build(), getCookie());
897 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
899 Futures.addCallback(resultLib, new ResultCallback<GetGroupDescriptionOutput>(result) {
901 public GetGroupDescriptionOutput createResult() {
902 GetGroupDescriptionOutputBuilder groupStatBuilder = new GetGroupDescriptionOutputBuilder()
903 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
904 return groupStatBuilder.build();
912 return new OFRpcTaskImpl(taskContext, cookie, input);
921 public static OFRpcTask<GetGroupFeaturesInput, RpcResult<GetGroupFeaturesOutput>> createGetGroupFeaturesTask(
922 final OFRpcTaskContext taskContext, GetGroupFeaturesInput input,
923 SwitchConnectionDistinguisher cookie) {
924 class OFRpcTaskImpl extends OFRpcTask<GetGroupFeaturesInput, RpcResult<GetGroupFeaturesOutput>> {
926 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
927 GetGroupFeaturesInput input) {
928 super(taskContext, cookie, input);
929 // TODO Auto-generated constructor stub
933 public ListenableFuture<RpcResult<GetGroupFeaturesOutput>> call()
935 final SettableFuture<RpcResult<GetGroupFeaturesOutput>> result = SettableFuture.create();
937 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
938 RpcResult<GetGroupFeaturesOutput> rpcResult = RpcResultBuilder.success(
939 new GetGroupFeaturesOutputBuilder().build()).build();
940 return Futures.immediateFuture(rpcResult);
942 final Long xid = taskContext.getSession().getNextXid();
944 MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild =
945 new MultipartRequestGroupFeaturesCaseBuilder();
946 MultipartRequestInputBuilder mprInput =
947 createMultipartHeader(MultipartType.OFPMPGROUPFEATURES, taskContext, xid);
948 mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
949 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
950 .multipartRequest(mprInput.build(), getCookie());
951 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
953 Futures.addCallback(resultLib, new ResultCallback<GetGroupFeaturesOutput>(result) {
955 public GetGroupFeaturesOutput createResult() {
956 GetGroupFeaturesOutputBuilder groupFeatureBuilder = new GetGroupFeaturesOutputBuilder()
957 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
958 return groupFeatureBuilder.build();
966 return new OFRpcTaskImpl(taskContext, cookie, input);
975 public static OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>> createGetGroupStatisticsTask(
976 final OFRpcTaskContext taskContext, final GetGroupStatisticsInput input,
977 SwitchConnectionDistinguisher cookie) {
979 class OFRpcTaskImpl extends OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>> {
981 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
982 GetGroupStatisticsInput input) {
983 super(taskContext, cookie, input);
987 public ListenableFuture<RpcResult<GetGroupStatisticsOutput>> call()
989 final SettableFuture<RpcResult<GetGroupStatisticsOutput>> result = SettableFuture.create();
991 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
992 RpcResult<GetGroupStatisticsOutput> rpcResult = RpcResultBuilder.success(
993 new GetGroupStatisticsOutputBuilder().build()).build();
994 return Futures.immediateFuture(rpcResult);
996 final Long xid = taskContext.getSession().getNextXid();
998 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
999 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
1000 mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
1001 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
1003 MultipartRequestInputBuilder mprInput =
1004 createMultipartHeader(MultipartType.OFPMPGROUP, taskContext, xid);
1005 mprInput.setMultipartRequestBody(caseBuilder.build());
1006 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1007 .multipartRequest(mprInput.build(), getCookie());
1008 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1010 Futures.addCallback(resultLib, new ResultCallback<GetGroupStatisticsOutput>(result) {
1012 public GetGroupStatisticsOutput createResult() {
1013 GetGroupStatisticsOutputBuilder groupStatisticsBuilder =
1014 new GetGroupStatisticsOutputBuilder()
1015 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1016 return groupStatisticsBuilder.build();
1024 return new OFRpcTaskImpl(taskContext, cookie, input);
1028 * @param taskContext
1033 public static OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>> createGetAllMeterConfigStatisticsTask(
1034 final OFRpcTaskContext taskContext, final GetAllMeterConfigStatisticsInput input,
1035 SwitchConnectionDistinguisher cookie) {
1036 class OFRpcTaskImpl extends OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>> {
1038 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1039 GetAllMeterConfigStatisticsInput input) {
1040 super(taskContext, cookie, input);
1044 public ListenableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> call()
1046 final SettableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> result = SettableFuture.create();
1048 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1049 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = RpcResultBuilder.success(
1050 new GetAllMeterConfigStatisticsOutputBuilder().build()).build();
1051 return Futures.immediateFuture(rpcResult);
1053 final Long xid = taskContext.getSession().getNextXid();
1055 MultipartRequestMeterConfigCaseBuilder caseBuilder =
1056 new MultipartRequestMeterConfigCaseBuilder();
1057 MultipartRequestMeterConfigBuilder mprMeterConfigBuild =
1058 new MultipartRequestMeterConfigBuilder();
1059 mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(
1060 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common
1061 .types.rev130731.Meter.OFPMALL.getIntValue())));
1062 caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
1064 MultipartRequestInputBuilder mprInput =
1065 createMultipartHeader(MultipartType.OFPMPMETERCONFIG, taskContext, xid);
1066 mprInput.setMultipartRequestBody(caseBuilder.build());
1067 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1068 .multipartRequest(mprInput.build(), getCookie());
1069 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1071 Futures.addCallback(resultLib, new ResultCallback<GetAllMeterConfigStatisticsOutput>(result) {
1073 public GetAllMeterConfigStatisticsOutput createResult() {
1074 GetAllMeterConfigStatisticsOutputBuilder allMeterConfStatBuilder =
1075 new GetAllMeterConfigStatisticsOutputBuilder()
1076 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1077 return allMeterConfStatBuilder.build();
1085 return new OFRpcTaskImpl(taskContext, cookie, input);
1089 * @param taskContext
1094 public static OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>> createGetAllMeterStatisticsTask(
1095 final OFRpcTaskContext taskContext, final GetAllMeterStatisticsInput input,
1096 SwitchConnectionDistinguisher cookie) {
1097 class OFRpcTaskImpl extends OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>> {
1099 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1100 GetAllMeterStatisticsInput input) {
1101 super(taskContext, cookie, input);
1102 // TODO Auto-generated constructor stub
1106 public ListenableFuture<RpcResult<GetAllMeterStatisticsOutput>> call()
1108 final SettableFuture<RpcResult<GetAllMeterStatisticsOutput>> result = SettableFuture.create();
1110 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1111 RpcResult<GetAllMeterStatisticsOutput> rpcResult = RpcResultBuilder.success(
1112 new GetAllMeterStatisticsOutputBuilder().build()).build();
1113 return Futures.immediateFuture(rpcResult);
1115 final Long xid = taskContext.getSession().getNextXid();
1117 MultipartRequestMeterCaseBuilder caseBuilder =
1118 new MultipartRequestMeterCaseBuilder();
1119 MultipartRequestMeterBuilder mprMeterBuild =
1120 new MultipartRequestMeterBuilder();
1121 mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(
1122 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common
1123 .types.rev130731.Meter.OFPMALL.getIntValue())));
1124 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
1126 MultipartRequestInputBuilder mprInput =
1127 createMultipartHeader(MultipartType.OFPMPMETER, taskContext, xid);
1128 mprInput.setMultipartRequestBody(caseBuilder.build());
1129 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1130 .multipartRequest(mprInput.build(), getCookie());
1131 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1133 Futures.addCallback(resultLib, new ResultCallback<GetAllMeterStatisticsOutput>(result) {
1135 public GetAllMeterStatisticsOutput createResult() {
1136 GetAllMeterStatisticsOutputBuilder allMeterStatBuilder =
1137 new GetAllMeterStatisticsOutputBuilder()
1138 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1139 return allMeterStatBuilder.build();
1147 return new OFRpcTaskImpl(taskContext, cookie, input);
1151 * @param taskContext
1156 public static OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>> createGetMeterFeaturesTask(
1157 final OFRpcTaskContext taskContext, final GetMeterFeaturesInput input,
1158 SwitchConnectionDistinguisher cookie) {
1160 class OFRpcTaskImpl extends OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>> {
1162 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1163 GetMeterFeaturesInput input) {
1164 super(taskContext, cookie, input);
1168 public ListenableFuture<RpcResult<GetMeterFeaturesOutput>> call()
1170 final SettableFuture<RpcResult<GetMeterFeaturesOutput>> result = SettableFuture.create();
1172 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1173 RpcResult<GetMeterFeaturesOutput> rpcResult = RpcResultBuilder.success(
1174 new GetMeterFeaturesOutputBuilder().build()).build();
1175 return Futures.immediateFuture(rpcResult);
1177 final Long xid = taskContext.getSession().getNextXid();
1179 MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild =
1180 new MultipartRequestMeterFeaturesCaseBuilder();
1182 MultipartRequestInputBuilder mprInput =
1183 createMultipartHeader(MultipartType.OFPMPMETERFEATURES, taskContext, xid);
1184 mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
1185 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1186 .multipartRequest(mprInput.build(), getCookie());
1187 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1189 Futures.addCallback(resultLib, new ResultCallback<GetMeterFeaturesOutput>(result) {
1191 public GetMeterFeaturesOutput createResult() {
1192 GetMeterFeaturesOutputBuilder meterFeaturesBuilder =
1193 new GetMeterFeaturesOutputBuilder()
1194 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1195 return meterFeaturesBuilder.build();
1203 return new OFRpcTaskImpl(taskContext, cookie, input);
1207 * @param taskContext
1212 public static OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>> createGetMeterStatisticsTask(
1213 final OFRpcTaskContext taskContext, final GetMeterStatisticsInput input,
1214 SwitchConnectionDistinguisher cookie) {
1216 class OFRpcTaskImpl extends OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>> {
1218 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1219 GetMeterStatisticsInput input) {
1220 super(taskContext, cookie, input);
1224 public ListenableFuture<RpcResult<GetMeterStatisticsOutput>> call()
1226 final SettableFuture<RpcResult<GetMeterStatisticsOutput>> result = SettableFuture.create();
1228 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1229 RpcResult<GetMeterStatisticsOutput> rpcResult = RpcResultBuilder.success(
1230 new GetMeterStatisticsOutputBuilder().build()).build();
1231 return Futures.immediateFuture(rpcResult);
1233 final Long xid = taskContext.getSession().getNextXid();
1235 MultipartRequestMeterCaseBuilder caseBuilder =
1236 new MultipartRequestMeterCaseBuilder();
1237 MultipartRequestMeterBuilder mprMeterBuild =
1238 new MultipartRequestMeterBuilder();
1239 mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
1240 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
1242 MultipartRequestInputBuilder mprInput =
1243 createMultipartHeader(MultipartType.OFPMPMETER, taskContext, xid);
1244 mprInput.setMultipartRequestBody(caseBuilder.build());
1245 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1246 .multipartRequest(mprInput.build(), getCookie());
1247 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1249 Futures.addCallback(resultLib, new ResultCallback<GetMeterStatisticsOutput>(result) {
1251 public GetMeterStatisticsOutput createResult() {
1252 GetMeterStatisticsOutputBuilder meterStatBuilder =
1253 new GetMeterStatisticsOutputBuilder()
1254 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1255 return meterStatBuilder.build();
1263 return new OFRpcTaskImpl(taskContext, cookie, input);
1267 * @param taskContext
1272 public static OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>>
1273 createGetAllNodeConnectorsStatisticsTask(
1274 final OFRpcTaskContext taskContext, final GetAllNodeConnectorsStatisticsInput input,
1275 SwitchConnectionDistinguisher cookie) {
1276 class OFRpcTaskImpl extends OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>> {
1278 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1279 GetAllNodeConnectorsStatisticsInput input) {
1280 super(taskContext, cookie, input);
1284 public ListenableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> call()
1286 final SettableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> result = SettableFuture.create();
1288 final Long xid = taskContext.getSession().getNextXid();
1290 MultipartRequestPortStatsCaseBuilder caseBuilder =
1291 new MultipartRequestPortStatsCaseBuilder();
1292 MultipartRequestPortStatsBuilder mprPortStatsBuilder =
1293 new MultipartRequestPortStatsBuilder();
1295 mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
1296 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1298 MultipartRequestInputBuilder mprInput =
1299 createMultipartHeader(MultipartType.OFPMPPORTSTATS, taskContext, xid);
1300 mprInput.setMultipartRequestBody(caseBuilder.build());
1301 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1302 .multipartRequest(mprInput.build(), getCookie());
1303 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1305 Futures.addCallback(resultLib, new ResultCallback<GetAllNodeConnectorsStatisticsOutput>(result) {
1307 public GetAllNodeConnectorsStatisticsOutput createResult() {
1308 GetAllNodeConnectorsStatisticsOutputBuilder allNodeConnectorStatBuilder =
1309 new GetAllNodeConnectorsStatisticsOutputBuilder()
1310 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1311 return allNodeConnectorStatBuilder.build();
1318 return new OFRpcTaskImpl(taskContext, cookie, input);
1322 * @param taskContext
1327 public static OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>>
1328 createGetNodeConnectorStatisticsTask(
1329 final OFRpcTaskContext taskContext, final GetNodeConnectorStatisticsInput input,
1330 SwitchConnectionDistinguisher cookie) {
1331 class OFRpcTaskImpl extends OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>> {
1333 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1334 GetNodeConnectorStatisticsInput input) {
1335 super(taskContext, cookie, input);
1339 public ListenableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> call()
1341 final SettableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> result = SettableFuture.create();
1343 final Long xid = taskContext.getSession().getNextXid();
1345 MultipartRequestPortStatsCaseBuilder caseBuilder =
1346 new MultipartRequestPortStatsCaseBuilder();
1347 MultipartRequestPortStatsBuilder mprPortStatsBuilder =
1348 new MultipartRequestPortStatsBuilder();
1349 // Set specific port
1351 .setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
1352 OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
1353 input.getNodeConnectorId()));
1354 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1356 MultipartRequestInputBuilder mprInput =
1357 createMultipartHeader(MultipartType.OFPMPPORTSTATS, taskContext, xid);
1358 mprInput.setMultipartRequestBody(caseBuilder.build());
1359 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1360 .multipartRequest(mprInput.build(), getCookie());
1361 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1363 Futures.addCallback(resultLib, new ResultCallback<GetNodeConnectorStatisticsOutput>(result) {
1365 public GetNodeConnectorStatisticsOutput createResult() {
1366 GetNodeConnectorStatisticsOutputBuilder allNodeConnectorStatBuilder =
1367 new GetNodeConnectorStatisticsOutputBuilder()
1368 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1369 return allNodeConnectorStatBuilder.build();
1376 return new OFRpcTaskImpl(taskContext, cookie, input);
1380 * @param taskContext
1385 public static OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>>
1386 createGetAllFlowStatisticsFromFlowTableTask(
1387 final OFRpcTaskContext taskContext,
1388 final GetAllFlowStatisticsFromFlowTableInput input,
1389 SwitchConnectionDistinguisher cookie) {
1390 class OFRpcTaskImpl extends OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> {
1392 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1393 GetAllFlowStatisticsFromFlowTableInput input) {
1394 super(taskContext, cookie, input);
1398 public ListenableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> call() throws Exception {
1399 final SettableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> result = SettableFuture.create();
1401 final Long xid = taskContext.getSession().getNextXid();
1403 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1404 mprFlowRequestBuilder.setTableId(input.getTableId().getValue());
1405 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1406 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1407 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1408 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1409 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1410 .getPrimaryConductor().getVersion(), mprFlowRequestBuilder);
1412 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1413 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1415 MultipartRequestInputBuilder mprInput =
1416 createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid);
1417 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1418 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1419 .multipartRequest(mprInput.build(), getCookie());
1420 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1422 Futures.addCallback(resultLib, new ResultCallback<GetAllFlowStatisticsFromFlowTableOutput>(result) {
1424 public GetAllFlowStatisticsFromFlowTableOutput createResult() {
1425 GetAllFlowStatisticsFromFlowTableOutputBuilder allFlowStatsFromFlowTableBuilder =
1426 new GetAllFlowStatisticsFromFlowTableOutputBuilder()
1427 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1428 return allFlowStatsFromFlowTableBuilder.build();
1435 return new OFRpcTaskImpl(taskContext, cookie, input);
1439 * @param taskContext
1444 public static OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput, RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>>
1445 createGetAllFlowsStatisticsFromAllFlowTablesTask(
1446 final OFRpcTaskContext taskContext,
1447 final GetAllFlowsStatisticsFromAllFlowTablesInput input,
1448 SwitchConnectionDistinguisher cookie) {
1449 class OFRpcTaskImpl extends OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput,
1450 RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> {
1452 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1453 GetAllFlowsStatisticsFromAllFlowTablesInput input) {
1454 super(taskContext, cookie, input);
1458 public ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> call() throws Exception {
1459 final SettableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> result = SettableFuture.create();
1461 final Long xid = taskContext.getSession().getNextXid();
1463 // Create multipart request body for fetch all the group stats
1464 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder =
1465 new MultipartRequestFlowCaseBuilder();
1466 MultipartRequestFlowBuilder mprFlowRequestBuilder =
1467 new MultipartRequestFlowBuilder();
1468 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
1469 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1470 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1471 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1472 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1473 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1474 .getPrimaryConductor().getVersion(), mprFlowRequestBuilder);
1476 MultipartRequestInputBuilder mprInput =
1477 createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid);
1478 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1479 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1480 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1481 .multipartRequest(mprInput.build(), getCookie());
1482 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1484 Futures.addCallback(resultLib, new ResultCallback<GetAllFlowsStatisticsFromAllFlowTablesOutput>(result) {
1486 public GetAllFlowsStatisticsFromAllFlowTablesOutput createResult() {
1487 GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder allFlowStatsFromAllFlowTableBuilder =
1488 new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder()
1489 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1490 return allFlowStatsFromAllFlowTableBuilder.build();
1497 return new OFRpcTaskImpl(taskContext, cookie, input);
1501 * @param taskContext
1506 public static OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>>
1507 createGetFlowStatisticsFromFlowTableTask(
1508 final OFRpcTaskContext taskContext,
1509 final GetFlowStatisticsFromFlowTableInput input, SwitchConnectionDistinguisher cookie) {
1511 class OFRpcTaskImpl extends OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>> {
1513 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1514 GetFlowStatisticsFromFlowTableInput input) {
1515 super(taskContext, cookie, input);
1519 public ListenableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> call() throws Exception {
1520 final SettableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> result = SettableFuture.create();
1522 final Long xid = taskContext.getSession().getNextXid();
1524 // Create multipart request body for fetch all the group stats
1525 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1526 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1527 mprFlowRequestBuilder.setTableId(input.getTableId());
1529 if (input.getOutPort() != null) {
1530 mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue());
1532 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1535 if (input.getOutGroup() != null) {
1536 mprFlowRequestBuilder.setOutGroup(input.getOutGroup());
1538 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1541 if (input.getCookie() != null) {
1542 mprFlowRequestBuilder.setCookie(input.getCookie().getValue());
1544 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1547 if (input.getCookieMask() != null) {
1548 mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue());
1550 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1553 // convert and inject match
1554 MatchReactor.getInstance().convert(input.getMatch(), taskContext.getSession()
1555 .getPrimaryConductor().getVersion(), mprFlowRequestBuilder,
1556 taskContext.getSession().getFeatures().getDatapathId());
1558 // Set request body to main multipart request
1559 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1560 MultipartRequestInputBuilder mprInput =
1561 createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid);
1562 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1563 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1564 .multipartRequest(mprInput.build(), getCookie());
1565 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1567 Futures.addCallback(resultLib, new ResultCallback<GetFlowStatisticsFromFlowTableOutput>(result) {
1569 public GetFlowStatisticsFromFlowTableOutput createResult() {
1570 GetFlowStatisticsFromFlowTableOutputBuilder flowStatsFromFlowTableBuilder =
1571 new GetFlowStatisticsFromFlowTableOutputBuilder()
1572 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1573 return flowStatsFromFlowTableBuilder.build();
1580 return new OFRpcTaskImpl(taskContext, cookie, input);
1584 * @param taskContext
1589 public static OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>>
1590 createGetAggregateFlowStatisticsFromFlowTableForAllFlowsTask(
1591 final OFRpcTaskContext taskContext,
1592 final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input, SwitchConnectionDistinguisher cookie) {
1593 class OFRpcTaskImpl extends OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> {
1595 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1596 GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
1597 super(taskContext, cookie, input);
1601 public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> call() throws Exception {
1602 final SettableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> result = SettableFuture.create();
1604 final Long xid = taskContext.getSession().getNextXid();
1606 // Create multipart request body for fetch all the group stats
1607 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1608 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1609 mprAggregateRequestBuilder.setTableId(input.getTableId().getValue());
1610 mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1611 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1612 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1613 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1615 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1616 .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder);
1618 // Set request body to main multipart request
1619 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1620 MultipartRequestInputBuilder mprInput =
1621 createMultipartHeader(MultipartType.OFPMPAGGREGATE, taskContext, xid);
1622 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1623 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1624 .multipartRequest(mprInput.build(), getCookie());
1625 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1627 Futures.addCallback(resultLib, new ResultCallback<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>(result) {
1629 public GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput createResult() {
1630 GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder flowStatsFromFlowTableBuilder =
1631 new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder()
1632 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1633 return flowStatsFromFlowTableBuilder.build();
1640 return new OFRpcTaskImpl(taskContext, cookie, input);
1644 * @param taskContext
1649 public static OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>
1650 createGetAggregateFlowStatisticsFromFlowTableForGivenMatchTask(
1651 final OFRpcTaskContext taskContext,
1652 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input, SwitchConnectionDistinguisher cookie) {
1653 class OFRpcTaskImpl extends OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> {
1655 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1656 GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
1657 super(taskContext, cookie, input);
1661 public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> call() throws Exception {
1662 final SettableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> result = SettableFuture.create();
1664 final Long xid = taskContext.getSession().getNextXid();
1666 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1667 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1668 mprAggregateRequestBuilder.setTableId(input.getTableId());
1669 mprAggregateRequestBuilder.setOutPort(input.getOutPort().longValue());
1670 // TODO: repeating code
1671 if (taskContext.getSession().getPrimaryConductor().getVersion() ==
1672 OFConstants.OFP_VERSION_1_3) {
1673 mprAggregateRequestBuilder.setCookie(input.getCookie().getValue());
1674 mprAggregateRequestBuilder.setCookieMask(input.getCookieMask().getValue());
1675 mprAggregateRequestBuilder.setOutGroup(input.getOutGroup());
1677 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1678 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1679 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1682 MatchReactor.getInstance().convert(input.getMatch(), taskContext.getSession()
1683 .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder,
1684 taskContext.getSession().getFeatures().getDatapathId());
1686 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1687 .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder);
1689 // Set request body to main multipart request
1690 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1691 MultipartRequestInputBuilder mprInput =
1692 createMultipartHeader(MultipartType.OFPMPAGGREGATE, taskContext, xid);
1693 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1694 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1695 .multipartRequest(mprInput.build(), getCookie());
1696 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1698 Futures.addCallback(resultLib, new ResultCallback<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>(result) {
1700 public GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput createResult() {
1701 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder aggregFlowStatsFromFlowTableBuilder =
1702 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder()
1703 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1704 return aggregFlowStatsFromFlowTableBuilder.build();
1711 return new OFRpcTaskImpl(taskContext, cookie, input);
1715 * @param taskContext
1720 public static OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>> createGetFlowTablesStatisticsTask(
1721 final OFRpcTaskContext taskContext, final GetFlowTablesStatisticsInput input, SwitchConnectionDistinguisher cookie) {
1723 class OFRpcTaskImpl extends OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>> {
1725 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1726 GetFlowTablesStatisticsInput input) {
1727 super(taskContext, cookie, input);
1731 public ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>> call() throws Exception {
1732 final SettableFuture<RpcResult<GetFlowTablesStatisticsOutput>> result = SettableFuture.create();
1734 final Long xid = taskContext.getSession().getNextXid();
1736 // Create multipart request body for fetch all the group stats
1737 MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
1738 MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
1739 multipartRequestTableBuilder.setEmpty(true);
1740 multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
1742 // Set request body to main multipart request
1743 MultipartRequestInputBuilder mprInput =
1744 createMultipartHeader(MultipartType.OFPMPTABLE, taskContext, xid);
1745 mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
1746 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1747 .multipartRequest(mprInput.build(), getCookie());
1748 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1750 Futures.addCallback(resultLib, new ResultCallback<GetFlowTablesStatisticsOutput>(result) {
1752 public GetFlowTablesStatisticsOutput createResult() {
1753 GetFlowTablesStatisticsOutputBuilder flowTableStatsBuilder =
1754 new GetFlowTablesStatisticsOutputBuilder()
1755 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1756 return flowTableStatsBuilder.build();
1763 return new OFRpcTaskImpl(taskContext, cookie, input);
1767 * @param taskContext
1772 public static OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> createGetAllQueuesStatisticsFromAllPortsTask(
1773 final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromAllPortsInput input, SwitchConnectionDistinguisher cookie) {
1775 class OFRpcTaskImpl extends OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> {
1777 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1778 GetAllQueuesStatisticsFromAllPortsInput input) {
1779 super(taskContext, cookie, input);
1783 public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> call() throws Exception {
1784 final SettableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> result = SettableFuture.create();
1786 final Long xid = taskContext.getSession().getNextXid();
1788 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1789 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1791 mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
1792 // Select all the ports
1793 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1794 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1796 // Set request body to main multipart request
1797 MultipartRequestInputBuilder mprInput =
1798 createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid);
1799 mprInput.setMultipartRequestBody(caseBuilder.build());
1800 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1801 .multipartRequest(mprInput.build(), getCookie());
1802 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1804 Futures.addCallback(resultLib, new ResultCallback<GetAllQueuesStatisticsFromAllPortsOutput>(result) {
1806 public GetAllQueuesStatisticsFromAllPortsOutput createResult() {
1807 GetAllQueuesStatisticsFromAllPortsOutputBuilder allQueueStatsBuilder =
1808 new GetAllQueuesStatisticsFromAllPortsOutputBuilder()
1809 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1810 return allQueueStatsBuilder.build();
1817 return new OFRpcTaskImpl(taskContext, cookie, input);
1821 * @param taskContext
1826 public static OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> createGetAllQueuesStatisticsFromGivenPortTask(
1827 final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromGivenPortInput input, SwitchConnectionDistinguisher cookie) {
1829 class OFRpcTaskImpl extends OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> {
1831 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1832 GetAllQueuesStatisticsFromGivenPortInput input) {
1833 super(taskContext, cookie, input);
1837 public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> call() throws Exception {
1838 final SettableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> result = SettableFuture.create();
1840 final Long xid = taskContext.getSession().getNextXid();
1842 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1843 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1844 // Select all queues
1845 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1846 // Select specific port
1847 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
1848 OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
1849 input.getNodeConnectorId()));
1850 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1852 // Set request body to main multipart request
1853 MultipartRequestInputBuilder mprInput =
1854 createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid);
1855 mprInput.setMultipartRequestBody(caseBuilder.build());
1856 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1857 .multipartRequest(mprInput.build(), getCookie());
1858 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1860 Futures.addCallback(resultLib, new ResultCallback<GetAllQueuesStatisticsFromGivenPortOutput>(result) {
1862 public GetAllQueuesStatisticsFromGivenPortOutput createResult() {
1863 GetAllQueuesStatisticsFromGivenPortOutputBuilder allQueueStatsBuilder =
1864 new GetAllQueuesStatisticsFromGivenPortOutputBuilder()
1865 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1866 return allQueueStatsBuilder.build();
1873 return new OFRpcTaskImpl(taskContext, cookie, input);
1877 * @param taskContext
1882 public static OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>> createGetQueueStatisticsFromGivenPortTask(
1883 final OFRpcTaskContext taskContext, final GetQueueStatisticsFromGivenPortInput input, SwitchConnectionDistinguisher cookie) {
1885 class OFRpcTaskImpl extends OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>> {
1887 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1888 GetQueueStatisticsFromGivenPortInput input) {
1889 super(taskContext, cookie, input);
1893 public ListenableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> call() throws Exception {
1894 final SettableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> result = SettableFuture.create();
1896 final Long xid = taskContext.getSession().getNextXid();
1898 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1899 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1900 // Select specific queue
1901 mprQueueBuilder.setQueueId(input.getQueueId().getValue());
1902 // Select specific port
1903 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
1904 OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
1905 input.getNodeConnectorId()));
1906 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1908 // Set request body to main multipart request
1909 MultipartRequestInputBuilder mprInput =
1910 createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid);
1911 mprInput.setMultipartRequestBody(caseBuilder.build());
1912 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1913 .multipartRequest(mprInput.build(), getCookie());
1914 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1916 Futures.addCallback(resultLib, new ResultCallback<GetQueueStatisticsFromGivenPortOutput>(result) {
1918 public GetQueueStatisticsFromGivenPortOutput createResult() {
1919 GetQueueStatisticsFromGivenPortOutputBuilder queueStatsFromPortBuilder =
1920 new GetQueueStatisticsFromGivenPortOutputBuilder()
1921 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1922 return queueStatsFromPortBuilder.build();
1929 return new OFRpcTaskImpl(taskContext, cookie, input);
1932 static MultipartRequestInputBuilder createMultipartHeader(MultipartType multipart,
1933 OFRpcTaskContext taskContext, Long xid) {
1934 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1935 mprInput.setType(multipart);
1936 mprInput.setVersion(taskContext.getSession().getPrimaryConductor().getVersion());
1937 mprInput.setXid(xid);
1938 mprInput.setFlags(new MultipartRequestFlags(false));
1942 private abstract static class ResultCallback<T> implements FutureCallback<RpcResult<Void>> {
1944 private SettableFuture<RpcResult<T>> result;
1949 public ResultCallback(SettableFuture<RpcResult<T>> result) {
1950 this.result = result;
1953 public abstract T createResult();
1956 public void onSuccess(RpcResult<Void> resultArg) {
1957 result.set(RpcResultBuilder.success(createResult()).build());
1961 public void onFailure(Throwable t) {
1962 result.set(RpcResultBuilder.<T>failed().withWarning(
1964 OFConstants.ERROR_TAG_TIMEOUT,
1965 "something wrong happened",
1966 OFConstants.APPLICATION_TAG,
1972 * @param taskContext
1977 public static OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>> createUpdatePortTask(
1978 final OFRpcTaskContext taskContext, final UpdatePortInput input,
1979 final SwitchConnectionDistinguisher cookie) {
1981 class OFRpcTaskImpl extends OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>> {
1983 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1984 UpdatePortInput input) {
1985 super(taskContext, cookie, input);
1989 public ListenableFuture<RpcResult<UpdatePortOutput>> call() {
1990 ListenableFuture<RpcResult<UpdatePortOutput>> result = SettableFuture.create();
1991 final Long xid = taskContext.getSession().getNextXid();
1992 Port inputPort = input.getUpdatedPort().getPort().getPort().get(0);
1994 PortModInput ofPortModInput = PortConvertor.toPortModInput(inputPort,
1995 taskContext.getSession().getPrimaryConductor().getVersion());
1997 PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
1998 mdInput.setXid(xid);
2000 Future<RpcResult<UpdatePortOutput>> resultFromOFLib = getMessageService()
2001 .portMod(mdInput.build(), cookie);
2002 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
2008 return new OFRpcTaskImpl(taskContext, cookie, input);
2012 * @param taskContext
2017 public static OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>> createUpdateTableTask(
2018 final OFRpcTaskContext taskContext, final UpdateTableInput input,
2019 final SwitchConnectionDistinguisher cookie) {
2021 class OFRpcTaskImpl extends OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>> {
2023 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
2024 UpdateTableInput input) {
2025 super(taskContext, cookie, input);
2029 public ListenableFuture<RpcResult<UpdateTableOutput>> call() {
2030 final SettableFuture<RpcResult<UpdateTableOutput>> result = SettableFuture.create();
2032 final Long xid = taskContext.getSession().getNextXid();
2034 MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder();
2035 MultipartRequestTableFeaturesBuilder requestBuilder = new MultipartRequestTableFeaturesBuilder();
2036 List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor
2037 .toTableFeaturesRequest(input.getUpdatedTable());
2038 requestBuilder.setTableFeatures(ofTableFeatureList);
2039 caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build());
2041 // Set request body to main multipart request
2042 MultipartRequestInputBuilder mprInput =
2043 createMultipartHeader(MultipartType.OFPMPTABLEFEATURES, taskContext, xid);
2044 mprInput.setMultipartRequestBody(caseBuilder.build());
2046 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
2047 .multipartRequest(mprInput.build(), getCookie());
2048 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
2050 Futures.addCallback(resultLib, new ResultCallback<UpdateTableOutput>(result) {
2052 public UpdateTableOutput createResult() {
2053 UpdateTableOutputBuilder queueStatsFromPortBuilder =
2054 new UpdateTableOutputBuilder()
2055 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
2056 return queueStatsFromPortBuilder.build();
2063 return new OFRpcTaskImpl(taskContext, cookie, input);
2066 public static OFRpcTask<SetConfigInput, RpcResult<SetConfigOutput>> createSetNodeConfigTask(final OFRpcTaskContext taskContext,
2067 final SetConfigInput input,
2068 final SwitchConnectionDistinguisher cookie) {
2069 class OFRpcTaskImpl extends OFRpcTask<SetConfigInput, RpcResult<SetConfigOutput>> {
2071 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
2072 SetConfigInput input) {
2073 super(taskContext, cookie, input);
2077 public ListenableFuture<RpcResult<SetConfigOutput>> call() throws Exception {
2079 final SettableFuture<RpcResult<SetConfigOutput>> result = SettableFuture.create();
2080 final Long xid = taskContext.getSession().getNextXid();
2082 SetConfigInputBuilder builder = new SetConfigInputBuilder();
2083 SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag());
2084 builder.setXid(xid);
2085 builder.setFlags(flag);
2086 builder.setMissSendLen(input.getMissSearchLength());
2087 builder.setVersion(getVersion());
2088 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(taskContext.getSession().getPrimaryConductor().getConnectionAdapter().setConfig(builder.build()));
2089 Futures.addCallback(resultLib, new ResultCallback<SetConfigOutput>(result) {
2091 public SetConfigOutput createResult() {
2092 SetConfigOutputBuilder setConfigOutputBuilder = new SetConfigOutputBuilder();
2093 setConfigOutputBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
2094 return setConfigOutputBuilder.build();
2101 return new OFRpcTaskImpl(taskContext, cookie, input);