2 * Copyright (c) 2013, 2015 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 com.google.common.base.Optional;
11 import com.google.common.util.concurrent.AsyncFunction;
12 import com.google.common.util.concurrent.CheckedFuture;
13 import com.google.common.util.concurrent.FutureCallback;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.JdkFutureAdapters;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import com.google.common.util.concurrent.SettableFuture;
18 import java.math.BigInteger;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.concurrent.Future;
22 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
23 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
24 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
25 import org.opendaylight.openflowjava.protocol.api.util.BinContent;
26 import org.opendaylight.openflowplugin.api.OFConstants;
27 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
28 import org.opendaylight.openflowplugin.api.openflow.md.core.sal.NotificationComposer;
29 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
30 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
31 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor;
32 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
33 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
34 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor;
35 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
36 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
37 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowHashIdMapping;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.nodes.node.table.FlowHashIdMap;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.nodes.node.table.FlowHashIdMapKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdatedBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutputBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutputBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupAdded;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupAddedBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemoved;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemovedBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdated;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdatedBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutputBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutputBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutputBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutputBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterAdded;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterAddedBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemoved;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemovedBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdated;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdatedBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutputBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutputBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutputBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutput;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutputBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInput;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutputBuilder;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInput;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutput;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutputBuilder;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutputBuilder;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInput;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutputBuilder;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInput;
177 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput;
178 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutputBuilder;
179 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
180 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
181 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder;
182 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
183 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
184 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
185 import org.opendaylight.yangtools.yang.common.RpcResult;
186 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
187 import org.slf4j.Logger;
188 import org.slf4j.LoggerFactory;
193 public abstract class OFRpcTaskFactory {
194 protected static final Logger LOG = LoggerFactory.getLogger(OFRpcTaskFactory.class);
196 private OFRpcTaskFactory() {
197 // hiding implicit constructor
201 * @param taskContext task context
202 * @param input flow object input
203 * @param cookie switch connection distinguisher cookie value
204 * @return UpdateFlow task
206 public static OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> createAddFlowTask(
207 OFRpcTaskContext taskContext, AddFlowInput input,
208 SwitchConnectionDistinguisher cookie) {
210 class OFRpcTaskImpl extends OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> {
212 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddFlowInput input) {
213 super(taskContext, cookie, input);
217 public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
218 ListenableFuture<RpcResult<UpdateFlowOutput>> result = SettableFuture.create();
220 // Convert the AddFlowInput to FlowModInput
221 List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput(),
222 getVersion(), getSession().getFeatures().getDatapathId());
223 LOG.debug("Number of flows to push to switch: {}", ofFlowModInputs.size());
224 result = chainFlowMods(ofFlowModInputs, 0, getTaskContext(), getCookie());
225 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
226 OFRpcTaskUtil.hookFutureNotification(this, result,
227 getRpcNotificationProviderService(),
228 createFlowAddedNotification(getInput()));
233 public Boolean isBarrier() {
234 return getInput().isBarrier();
238 return new OFRpcTaskImpl(taskContext, cookie, input);
242 * Recursive helper method for {@link OFRpcTaskFactory#createAddFlowTask(OFRpcTaskContext, AddFlowInput, SwitchConnectionDistinguisher)}
243 * and {@link OFRpcTaskFactory#createUpdateFlowTask(OFRpcTaskContext, UpdateFlowInput, SwitchConnectionDistinguisher, ReadWriteTransaction)} to chain results
244 * of multiple flowmods.
245 * The next flowmod gets executed if the earlier one is successful.
246 * All the flowmods should have the same xid, in-order to cross-reference
248 * @param taskContext task context
249 * @param ofFlowModInputs list of flow mod as input
250 * @param index starting index
251 * @param cookie switch connection distinguisher
252 * @return listenable future with update flow output
255 protected static ListenableFuture<RpcResult<UpdateFlowOutput>> chainFlowMods(
256 final List<FlowModInputBuilder> ofFlowModInputs, final int index,
257 final OFRpcTaskContext taskContext, final SwitchConnectionDistinguisher cookie) {
259 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib =
260 createResultForFlowMod(taskContext, ofFlowModInputs.get(index), cookie);
262 ListenableFuture<RpcResult<UpdateFlowOutput>> result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
264 if (ofFlowModInputs.size() > index + 1) {
265 // there are more flowmods to chain
266 return Futures.transform(result,
267 new AsyncFunction<RpcResult<UpdateFlowOutput>, RpcResult<UpdateFlowOutput>>() {
269 public ListenableFuture<RpcResult<UpdateFlowOutput>> apply(RpcResult<UpdateFlowOutput> input) throws Exception {
270 if (input.isSuccessful()) {
271 return chainFlowMods(ofFlowModInputs, index + 1, taskContext, cookie);
273 LOG.warn("Flowmod failed. Any chained flowmods are ignored. xid:{}",
274 ofFlowModInputs.get(index).getXid());
275 return Futures.immediateFuture(input);
285 private static Future<RpcResult<UpdateFlowOutput>> createResultForFlowMod(
286 OFRpcTaskContext taskContext, FlowModInputBuilder flowModInput,
287 SwitchConnectionDistinguisher cookie) {
288 flowModInput.setXid(taskContext.getSession().getNextXid());
289 return taskContext.getMessageService().flowMod(flowModInput.build(), cookie);
294 * @param input flow input
295 * @return flow added notification
297 protected static NotificationComposer<FlowAdded> createFlowAddedNotification(
298 final AddFlowInput input) {
299 return new NotificationComposer<FlowAdded>() {
301 public FlowAdded compose(TransactionId tXid) {
302 FlowAddedBuilder newFlow = new FlowAddedBuilder((Flow) input);
303 newFlow.setTransactionId(tXid);
304 newFlow.setFlowRef(input.getFlowRef());
305 return newFlow.build();
311 * @param taskContext task context
312 * @param input update flow input
313 * @param cookie switch connection distinguisher cookie value
314 * @param rwTx read write transaction
315 * @return UpdateFlow task
317 public static OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> createUpdateFlowTask(
318 final OFRpcTaskContext taskContext, UpdateFlowInput input,
319 SwitchConnectionDistinguisher cookie, final ReadWriteTransaction rwTx) {
321 class OFRpcTaskImpl extends OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> {
322 final ReadWriteTransaction rwTx;
323 InstanceIdentifier<Table> iiToTable = null;
324 String flowId = null;
325 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
326 final UpdateFlowInput in, final ReadWriteTransaction rwTx) {
327 super(taskContext, cookie, in);
328 final FlowRef flowRef = in.getFlowRef();
329 if (flowRef != null) {
330 InstanceIdentifier<Flow> iiToFlow = (InstanceIdentifier<Flow>)(flowRef.getValue());
331 iiToTable = flowRef.getValue().firstIdentifierOf(Table.class);
332 FlowKey flowKey = iiToFlow.firstKeyOf(
333 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow.class, FlowKey.class);
334 if (flowKey != null) {
335 flowId = flowKey.getId().getValue();
342 public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
343 ListenableFuture<RpcResult<UpdateFlowOutput>> result = null;
345 UpdateFlowInput in = getInput();
346 UpdatedFlow updated = in.getUpdatedFlow();
347 OriginalFlow original = in.getOriginalFlow();
348 Short version = getVersion();
350 List<FlowModInputBuilder> allFlowMods = new ArrayList<>();
351 List<FlowModInputBuilder> ofFlowModInputs;
353 if (!FlowCreatorUtil.canModifyFlow(original, updated, version)) {
354 // We would need to remove original and add updated.
357 RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(original);
358 List<FlowModInputBuilder> ofFlowRemoveInput = FlowConvertor.toFlowModInputs(removeflow.build(),
359 version, getSession().getFeatures().getDatapathId());
360 // remove flow should be the first
361 allFlowMods.addAll(ofFlowRemoveInput);
362 AddFlowInputBuilder addFlowInputBuilder = new AddFlowInputBuilder(updated);
363 ofFlowModInputs = FlowConvertor.toFlowModInputs(addFlowInputBuilder.build(),
364 version, getSession().getFeatures().getDatapathId());
366 ofFlowModInputs = FlowConvertor.toFlowModInputs(updated,
367 version, getSession().getFeatures().getDatapathId());
370 //deleting flow hash value from operational DS
371 if (flowId != null) {
372 CheckedFuture<Optional<FlowHashIdMapping>, ReadFailedException> hashDeletionFuture
373 = readFlowHashIdMappingFromOperationalDS(rwTx);
374 Futures.addCallback(hashDeletionFuture, new FutureCallback<Optional<FlowHashIdMapping>>() {
376 public void onSuccess(Optional<FlowHashIdMapping> optFlowHashIdMapping) {
377 FlowHashIdMapKey flowHashIdMapKeyToDelete = null;
378 if (optFlowHashIdMapping.isPresent()) {
379 FlowHashIdMapping flowHashIdMapping = optFlowHashIdMapping.get();
380 for (FlowHashIdMap flowHashId : flowHashIdMapping.getFlowHashIdMap()) {
381 if (flowHashId.getFlowId().getValue().equals(flowId)) {
382 flowHashIdMapKeyToDelete = flowHashId.getKey();
387 if (flowHashIdMapKeyToDelete != null) {
388 final KeyedInstanceIdentifier<FlowHashIdMap, FlowHashIdMapKey> iiToFlowHashIdToDelete = iiToTable
389 .augmentation(FlowHashIdMapping.class).child(FlowHashIdMap.class, flowHashIdMapKeyToDelete);
390 rwTx.delete(LogicalDatastoreType.OPERATIONAL, iiToFlowHashIdToDelete);
396 public void onFailure(Throwable t) {
397 LOG.debug("Reading flow-hash-id map from operational DS wasn't successful");
403 allFlowMods.addAll(ofFlowModInputs);
404 LOG.debug("Number of flows to push to switch: {}", allFlowMods.size());
405 result = chainFlowMods(allFlowMods, 0, getTaskContext(), getCookie());
407 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
408 OFRpcTaskUtil.hookFutureNotification(this, result,
409 getRpcNotificationProviderService(),
410 createFlowUpdatedNotification(in));
416 CheckedFuture<Optional<FlowHashIdMapping>, ReadFailedException> readFlowHashIdMappingFromOperationalDS(final ReadWriteTransaction rwTx) {
417 InstanceIdentifier<FlowHashIdMapping> iiToFlowHashIdMapping = iiToTable
418 .augmentation(FlowHashIdMapping.class);
419 return rwTx.read(LogicalDatastoreType.OPERATIONAL, iiToFlowHashIdMapping);
423 public Boolean isBarrier() {
424 return getInput().getUpdatedFlow().isBarrier();
427 return new OFRpcTaskImpl(taskContext, cookie, input, rwTx);
432 * @param input update flow input
433 * @return flow update notification
435 protected static NotificationComposer<FlowUpdated> createFlowUpdatedNotification(final UpdateFlowInput input) {
436 return new NotificationComposer<FlowUpdated>() {
438 public FlowUpdated compose(TransactionId tXid) {
439 FlowUpdatedBuilder updFlow = new FlowUpdatedBuilder(input.getUpdatedFlow());
440 updFlow.setTransactionId(tXid);
441 updFlow.setFlowRef(input.getFlowRef());
442 return updFlow.build();
448 * @param taskContext taks context
449 * @param input group update input
450 * @param cookie switch connection distinguisher cookie value
451 * @return update group task
453 public static OFRpcTask<AddGroupInput, RpcResult<UpdateGroupOutput>> createAddGroupTask(
454 final OFRpcTaskContext taskContext, AddGroupInput input,
455 final SwitchConnectionDistinguisher cookie) {
456 class OFRpcTaskImpl extends OFRpcTask<AddGroupInput, RpcResult<UpdateGroupOutput>> {
458 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddGroupInput input) {
459 super(taskContext, cookie, input);
463 public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
464 ListenableFuture<RpcResult<UpdateGroupOutput>> result = SettableFuture.create();
466 // Convert the AddGroupInput to GroupModInput
467 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(),
468 getVersion(), getSession().getFeatures().getDatapathId());
469 final Long xId = getSession().getNextXid();
470 ofGroupModInput.setXid(xId);
472 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
473 .groupMod(ofGroupModInput.build(), getCookie());
474 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
476 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
477 OFRpcTaskUtil.hookFutureNotification(this, result,
478 getRpcNotificationProviderService(), createGroupAddedNotification(getInput()));
484 public Boolean isBarrier() {
485 return getInput().isBarrier();
489 return new OFRpcTaskImpl(taskContext, cookie, input);
494 * @param input group add input
495 * @return group added notification
497 protected static NotificationComposer<GroupAdded> createGroupAddedNotification(
498 final AddGroupInput input) {
499 return new NotificationComposer<GroupAdded>() {
501 public GroupAdded compose(TransactionId tXid) {
502 GroupAddedBuilder groupMod = new GroupAddedBuilder((Group) input);
503 groupMod.setTransactionId(tXid);
504 groupMod.setGroupRef(input.getGroupRef());
505 return groupMod.build();
511 * @param taskContext task context
512 * @param input meter add input
513 * @param cookie switch connection distinguisher
514 * @return update meter task
516 public static OFRpcTask<AddMeterInput, RpcResult<UpdateMeterOutput>> createAddMeterTask(
517 OFRpcTaskContext taskContext, AddMeterInput input,
518 SwitchConnectionDistinguisher cookie) {
519 class OFRpcTaskImpl extends OFRpcTask<AddMeterInput, RpcResult<UpdateMeterOutput>> {
521 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddMeterInput input) {
522 super(taskContext, cookie, input);
526 public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
527 ListenableFuture<RpcResult<UpdateMeterOutput>> result = SettableFuture.create();
529 // Convert the AddGroupInput to GroupModInput
530 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput(), getVersion());
531 final Long xId = getSession().getNextXid();
532 ofMeterModInput.setXid(xId);
534 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
535 .meterMod(ofMeterModInput.build(), getCookie());
536 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
538 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
539 OFRpcTaskUtil.hookFutureNotification(this, result,
540 getRpcNotificationProviderService(), createMeterAddedNotification(getInput()));
546 public Boolean isBarrier() {
547 return getInput().isBarrier();
551 return new OFRpcTaskImpl(taskContext, cookie, input);
555 * @param input add meter input
556 * @return meter added notification composer
558 protected static NotificationComposer<MeterAdded> createMeterAddedNotification(
559 final AddMeterInput input) {
560 return new NotificationComposer<MeterAdded>() {
562 public MeterAdded compose(TransactionId tXid) {
563 MeterAddedBuilder meterMod = new MeterAddedBuilder((Meter) input);
564 meterMod.setTransactionId(tXid);
565 meterMod.setMeterRef(input.getMeterRef());
566 return meterMod.build();
572 * @param taskContext task context
573 * @param input update group output
574 * @param cookie switch connection distinguisher cookie value
575 * @return UpdateFlow task
577 public static OFRpcTask<UpdateGroupInput, RpcResult<UpdateGroupOutput>> createUpdateGroupTask(
578 OFRpcTaskContext taskContext, UpdateGroupInput input,
579 SwitchConnectionDistinguisher cookie) {
580 class OFRpcTaskImpl extends OFRpcTask<UpdateGroupInput, RpcResult<UpdateGroupOutput>> {
582 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
583 UpdateGroupInput input) {
584 super(taskContext, cookie, input);
588 public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
589 ListenableFuture<RpcResult<UpdateGroupOutput>> result = null;
591 // Convert the UpdateGroupInput to GroupModInput
592 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(
593 getInput().getUpdatedGroup(), getVersion(),
594 getSession().getFeatures().getDatapathId());
595 final Long xId = getSession().getNextXid();
596 ofGroupModInput.setXid(xId);
598 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib =
599 getMessageService().groupMod(ofGroupModInput.build(), getCookie());
600 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
602 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
603 OFRpcTaskUtil.hookFutureNotification(this, result,
604 getRpcNotificationProviderService(), createGroupUpdatedNotification(getInput()));
610 public Boolean isBarrier() {
611 return getInput().getUpdatedGroup().isBarrier();
615 return new OFRpcTaskImpl(taskContext, cookie, input);
619 * @param input group update input
620 * @return group updated notification composer
622 protected static NotificationComposer<GroupUpdated> createGroupUpdatedNotification(
623 final UpdateGroupInput input) {
624 return new NotificationComposer<GroupUpdated>() {
626 public GroupUpdated compose(TransactionId tXid) {
627 GroupUpdatedBuilder groupMod = new GroupUpdatedBuilder(input.getUpdatedGroup());
628 groupMod.setTransactionId(tXid);
629 groupMod.setGroupRef(input.getGroupRef());
630 return groupMod.build();
636 * @param taskContext task context
637 * @param input update meter input
638 * @param cookie switch connection distinguisher cookie value
639 * @return update meter task
641 public static OFRpcTask<UpdateMeterInput, RpcResult<UpdateMeterOutput>> createUpdateMeterTask(
642 OFRpcTaskContext taskContext, UpdateMeterInput input,
643 SwitchConnectionDistinguisher cookie) {
644 class OFRpcTaskImpl extends OFRpcTask<UpdateMeterInput, RpcResult<UpdateMeterOutput>> {
646 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
647 UpdateMeterInput input) {
648 super(taskContext, cookie, input);
652 public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
653 ListenableFuture<RpcResult<UpdateMeterOutput>> result = null;
655 // Convert the UpdateMeterInput to MeterModInput
656 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(
657 getInput().getUpdatedMeter(), getVersion());
658 final Long xId = getSession().getNextXid();
659 ofMeterModInput.setXid(xId);
661 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib =
662 getMessageService().meterMod(ofMeterModInput.build(), getCookie());
663 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
665 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
666 OFRpcTaskUtil.hookFutureNotification(this, result,
667 getRpcNotificationProviderService(), createMeterUpdatedNotification(getInput()));
672 public Boolean isBarrier() {
673 return getInput().getUpdatedMeter().isBarrier();
677 return new OFRpcTaskImpl(taskContext, cookie, input);
681 * @param input meter update input
682 * @return meter updated notification
684 protected static NotificationComposer<MeterUpdated> createMeterUpdatedNotification(
685 final UpdateMeterInput input) {
686 return new NotificationComposer<MeterUpdated>() {
688 public MeterUpdated compose(TransactionId tXid) {
689 MeterUpdatedBuilder meterMod = new MeterUpdatedBuilder(input.getUpdatedMeter());
690 meterMod.setTransactionId(tXid);
691 meterMod.setMeterRef(input.getMeterRef());
692 return meterMod.build();
699 * @param taskContext task context
700 * @param input update flow input
701 * @param cookie switch connection distinguisher cookie value
702 * @return task remove flow task
704 public static OFRpcTask<RemoveFlowInput, RpcResult<UpdateFlowOutput>> createRemoveFlowTask(
705 OFRpcTaskContext taskContext, RemoveFlowInput input,
706 SwitchConnectionDistinguisher cookie) {
707 class OFRpcTaskImpl extends OFRpcTask<RemoveFlowInput, RpcResult<UpdateFlowOutput>> {
709 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
710 RemoveFlowInput input) {
711 super(taskContext, cookie, input);
715 public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
716 ListenableFuture<RpcResult<UpdateFlowOutput>> result = SettableFuture.create();
718 // Convert the AddFlowInput to FlowModInput
719 List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput(),
720 getVersion(), getSession().getFeatures().getDatapathId());
722 result = chainFlowMods(ofFlowModInputs, 0, getTaskContext(), getCookie());
723 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
725 OFRpcTaskUtil.hookFutureNotification(this, result,
726 getRpcNotificationProviderService(),
727 createFlowRemovedNotification(getInput()));
732 public Boolean isBarrier() {
733 return getInput().isBarrier();
737 return new OFRpcTaskImpl(taskContext, cookie, input);
741 * @param input remove flow input
742 * @return flow removed notification
744 protected static NotificationComposer<FlowRemoved> createFlowRemovedNotification(
745 final RemoveFlowInput input) {
746 return new NotificationComposer<FlowRemoved>() {
748 public FlowRemoved compose(TransactionId tXid) {
749 FlowRemovedBuilder removedFlow = new FlowRemovedBuilder((Flow) input);
750 removedFlow.setTransactionId(tXid);
751 removedFlow.setFlowRef(input.getFlowRef());
752 return removedFlow.build();
759 * @param taskContext task context
760 * @param input remove group input
761 * @param cookie switch connection distinguisher cookie value
762 * @return task remove group task
764 public static OFRpcTask<RemoveGroupInput, RpcResult<UpdateGroupOutput>> createRemoveGroupTask(
765 final OFRpcTaskContext taskContext, RemoveGroupInput input,
766 final SwitchConnectionDistinguisher cookie) {
767 class OFRpcTaskImpl extends OFRpcTask<RemoveGroupInput, RpcResult<UpdateGroupOutput>> {
769 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
770 RemoveGroupInput input) {
771 super(taskContext, cookie, input);
775 public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
776 ListenableFuture<RpcResult<UpdateGroupOutput>> result = SettableFuture.create();
778 // Convert the AddGroupInput to GroupModInput
779 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(),
780 getVersion(), getSession().getFeatures().getDatapathId());
781 final Long xId = getSession().getNextXid();
782 ofGroupModInput.setXid(xId);
784 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
785 .groupMod(ofGroupModInput.build(), getCookie());
786 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
788 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
789 OFRpcTaskUtil.hookFutureNotification(this, result,
790 getRpcNotificationProviderService(), createGroupRemovedNotification(getInput()));
796 public Boolean isBarrier() {
797 return getInput().isBarrier();
801 return new OFRpcTaskImpl(taskContext, cookie, input);
805 * @param input group remove input
806 * @return group removed notification
808 protected static NotificationComposer<GroupRemoved> createGroupRemovedNotification(
809 final RemoveGroupInput input) {
810 return new NotificationComposer<GroupRemoved>() {
812 public GroupRemoved compose(TransactionId tXid) {
813 GroupRemovedBuilder removedGroup = new GroupRemovedBuilder((Group) input);
814 removedGroup.setTransactionId(tXid);
815 removedGroup.setGroupRef(input.getGroupRef());
816 return removedGroup.build();
822 * @param taskContext task context
823 * @param input meter removed input
824 * @param cookie switch connection distinguisher cookie value
825 * @return task meter remove task
827 public static OFRpcTask<RemoveMeterInput, RpcResult<UpdateMeterOutput>> createRemoveMeterTask(
828 OFRpcTaskContext taskContext, RemoveMeterInput input,
829 SwitchConnectionDistinguisher cookie) {
831 class OFRpcTaskImpl extends OFRpcTask<RemoveMeterInput, RpcResult<UpdateMeterOutput>> {
833 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
834 RemoveMeterInput input) {
835 super(taskContext, cookie, input);
839 public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
840 ListenableFuture<RpcResult<UpdateMeterOutput>> result = SettableFuture.create();
842 // Convert the AddGroupInput to GroupModInput
843 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput(), getVersion());
844 final Long xId = getSession().getNextXid();
845 ofMeterModInput.setXid(xId);
847 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
848 .meterMod(ofMeterModInput.build(), getCookie());
849 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
851 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
852 OFRpcTaskUtil.hookFutureNotification(this, result,
853 getRpcNotificationProviderService(), createMeterRemovedNotification(getInput()));
859 public Boolean isBarrier() {
860 return getInput().isBarrier();
864 return new OFRpcTaskImpl(taskContext, cookie, input);
869 * @param input remove meter input
870 * @return meter removed notification composer
872 protected static NotificationComposer<MeterRemoved> createMeterRemovedNotification(
873 final RemoveMeterInput input) {
874 return new NotificationComposer<MeterRemoved>() {
876 public MeterRemoved compose(TransactionId tXid) {
877 MeterRemovedBuilder meterRemoved = new MeterRemovedBuilder((Meter) input);
878 meterRemoved.setTransactionId(tXid);
879 meterRemoved.setMeterRef(input.getMeterRef());
880 return meterRemoved.build();
886 * @param taskContext task context
887 * @param input get all statistics input
888 * @param cookie switch connection distinguisher cookie value
889 * @return task get all group statistics task
891 public static OFRpcTask<GetAllGroupStatisticsInput, RpcResult<GetAllGroupStatisticsOutput>> createGetAllGroupStatisticsTask(
892 final OFRpcTaskContext taskContext, GetAllGroupStatisticsInput input,
893 SwitchConnectionDistinguisher cookie) {
895 class OFRpcTaskImpl extends OFRpcTask<GetAllGroupStatisticsInput, RpcResult<GetAllGroupStatisticsOutput>> {
897 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
898 GetAllGroupStatisticsInput input) {
899 super(taskContext, cookie, input);
903 public ListenableFuture<RpcResult<GetAllGroupStatisticsOutput>> call() {
904 final SettableFuture<RpcResult<GetAllGroupStatisticsOutput>> result = SettableFuture.create();
906 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
907 RpcResult<GetAllGroupStatisticsOutput> rpcResult = RpcResultBuilder.success(
908 new GetAllGroupStatisticsOutputBuilder().build()).build();
910 return Futures.immediateFuture(rpcResult);
913 // Generate xid to associate it with the request
914 final Long xid = taskContext.getSession().getNextXid();
916 // Create multipart request body for fetch all the group stats
917 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
918 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
919 mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(
920 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731
921 .Group.OFPGALL.getIntValue())));
922 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
924 // Create multipart request header
925 MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPGROUP,
928 // Set request body to main multipart request
929 mprInput.setMultipartRequestBody(caseBuilder.build());
931 // Send the request, no cookies associated, use any connection
933 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
934 .multipartRequest(mprInput.build(), getCookie());
935 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
937 Futures.addCallback(resultLib, new ResultCallback<GetAllGroupStatisticsOutput>(result) {
939 public GetAllGroupStatisticsOutput createResult() {
940 GetAllGroupStatisticsOutputBuilder groupStatBuilder = new GetAllGroupStatisticsOutputBuilder()
941 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
942 return groupStatBuilder.build();
951 return new OFRpcTaskImpl(taskContext, cookie, input);
955 * @param taskContext task context
956 * @param input get group description input
957 * @param cookie switch connection distinguisher cookie value
958 * @return task get group description task
960 public static OFRpcTask<GetGroupDescriptionInput, RpcResult<GetGroupDescriptionOutput>> createGetGroupDescriptionTask(
961 final OFRpcTaskContext taskContext, GetGroupDescriptionInput input,
962 SwitchConnectionDistinguisher cookie) {
963 class OFRpcTaskImpl extends OFRpcTask<GetGroupDescriptionInput, RpcResult<GetGroupDescriptionOutput>> {
965 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
966 GetGroupDescriptionInput input) {
967 super(taskContext, cookie, input);
971 public ListenableFuture<RpcResult<GetGroupDescriptionOutput>> call()
973 final SettableFuture<RpcResult<GetGroupDescriptionOutput>> result = SettableFuture.create();
975 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
976 RpcResult<GetGroupDescriptionOutput> rpcResult = RpcResultBuilder.success(
977 new GetGroupDescriptionOutputBuilder().build()).build();
978 return Futures.immediateFuture(rpcResult);
980 final Long xid = taskContext.getSession().getNextXid();
982 MultipartRequestGroupDescCaseBuilder mprGroupDescCaseBuild =
983 new MultipartRequestGroupDescCaseBuilder();
984 MultipartRequestInputBuilder mprInput =
985 createMultipartHeader(MultipartType.OFPMPGROUPDESC, taskContext, xid);
986 mprInput.setMultipartRequestBody(mprGroupDescCaseBuild.build());
987 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
988 .multipartRequest(mprInput.build(), getCookie());
989 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
991 Futures.addCallback(resultLib, new ResultCallback<GetGroupDescriptionOutput>(result) {
993 public GetGroupDescriptionOutput createResult() {
994 GetGroupDescriptionOutputBuilder groupStatBuilder = new GetGroupDescriptionOutputBuilder()
995 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
996 return groupStatBuilder.build();
1004 return new OFRpcTaskImpl(taskContext, cookie, input);
1008 * @param taskContext task context
1009 * @param input get group feature input
1010 * @param cookie switch connection distinguisher cookie value
1011 * @return task get group feature task
1013 public static OFRpcTask<GetGroupFeaturesInput, RpcResult<GetGroupFeaturesOutput>> createGetGroupFeaturesTask(
1014 final OFRpcTaskContext taskContext, GetGroupFeaturesInput input,
1015 SwitchConnectionDistinguisher cookie) {
1016 class OFRpcTaskImpl extends OFRpcTask<GetGroupFeaturesInput, RpcResult<GetGroupFeaturesOutput>> {
1018 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1019 GetGroupFeaturesInput input) {
1020 super(taskContext, cookie, input);
1021 // TODO Auto-generated constructor stub
1025 public ListenableFuture<RpcResult<GetGroupFeaturesOutput>> call()
1027 final SettableFuture<RpcResult<GetGroupFeaturesOutput>> result = SettableFuture.create();
1029 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1030 RpcResult<GetGroupFeaturesOutput> rpcResult = RpcResultBuilder.success(
1031 new GetGroupFeaturesOutputBuilder().build()).build();
1032 return Futures.immediateFuture(rpcResult);
1034 final Long xid = taskContext.getSession().getNextXid();
1036 MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild =
1037 new MultipartRequestGroupFeaturesCaseBuilder();
1038 MultipartRequestInputBuilder mprInput =
1039 createMultipartHeader(MultipartType.OFPMPGROUPFEATURES, taskContext, xid);
1040 mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
1041 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1042 .multipartRequest(mprInput.build(), getCookie());
1043 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1045 Futures.addCallback(resultLib, new ResultCallback<GetGroupFeaturesOutput>(result) {
1047 public GetGroupFeaturesOutput createResult() {
1048 GetGroupFeaturesOutputBuilder groupFeatureBuilder = new GetGroupFeaturesOutputBuilder()
1049 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1050 return groupFeatureBuilder.build();
1058 return new OFRpcTaskImpl(taskContext, cookie, input);
1062 * @param taskContext task context
1063 * @param input get group statistics input
1064 * @param cookie switch connection distinguisher cookie value
1065 * @return task get group statistics task
1067 public static OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>> createGetGroupStatisticsTask(
1068 final OFRpcTaskContext taskContext, final GetGroupStatisticsInput input,
1069 SwitchConnectionDistinguisher cookie) {
1071 class OFRpcTaskImpl extends OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>> {
1073 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1074 GetGroupStatisticsInput input) {
1075 super(taskContext, cookie, input);
1079 public ListenableFuture<RpcResult<GetGroupStatisticsOutput>> call()
1081 final SettableFuture<RpcResult<GetGroupStatisticsOutput>> result = SettableFuture.create();
1083 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1084 RpcResult<GetGroupStatisticsOutput> rpcResult = RpcResultBuilder.success(
1085 new GetGroupStatisticsOutputBuilder().build()).build();
1086 return Futures.immediateFuture(rpcResult);
1088 final Long xid = taskContext.getSession().getNextXid();
1090 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
1091 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
1092 mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
1093 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
1095 MultipartRequestInputBuilder mprInput =
1096 createMultipartHeader(MultipartType.OFPMPGROUP, taskContext, xid);
1097 mprInput.setMultipartRequestBody(caseBuilder.build());
1098 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1099 .multipartRequest(mprInput.build(), getCookie());
1100 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1102 Futures.addCallback(resultLib, new ResultCallback<GetGroupStatisticsOutput>(result) {
1104 public GetGroupStatisticsOutput createResult() {
1105 GetGroupStatisticsOutputBuilder groupStatisticsBuilder =
1106 new GetGroupStatisticsOutputBuilder()
1107 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1108 return groupStatisticsBuilder.build();
1116 return new OFRpcTaskImpl(taskContext, cookie, input);
1120 * @param taskContext task context
1121 * @param input get meter config statistics input
1122 * @param cookie switch connection distinguisher cookie value
1123 * @return task get all mtere config statistics task
1125 public static OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>> createGetAllMeterConfigStatisticsTask(
1126 final OFRpcTaskContext taskContext, final GetAllMeterConfigStatisticsInput input,
1127 SwitchConnectionDistinguisher cookie) {
1128 class OFRpcTaskImpl extends OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>> {
1130 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1131 GetAllMeterConfigStatisticsInput input) {
1132 super(taskContext, cookie, input);
1136 public ListenableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> call()
1138 final SettableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> result = SettableFuture.create();
1140 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1141 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = RpcResultBuilder.success(
1142 new GetAllMeterConfigStatisticsOutputBuilder().build()).build();
1143 return Futures.immediateFuture(rpcResult);
1145 final Long xid = taskContext.getSession().getNextXid();
1147 MultipartRequestMeterConfigCaseBuilder caseBuilder =
1148 new MultipartRequestMeterConfigCaseBuilder();
1149 MultipartRequestMeterConfigBuilder mprMeterConfigBuild =
1150 new MultipartRequestMeterConfigBuilder();
1151 mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(
1152 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common
1153 .types.rev130731.Meter.OFPMALL.getIntValue())));
1154 caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
1156 MultipartRequestInputBuilder mprInput =
1157 createMultipartHeader(MultipartType.OFPMPMETERCONFIG, taskContext, xid);
1158 mprInput.setMultipartRequestBody(caseBuilder.build());
1159 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1160 .multipartRequest(mprInput.build(), getCookie());
1161 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1163 Futures.addCallback(resultLib, new ResultCallback<GetAllMeterConfigStatisticsOutput>(result) {
1165 public GetAllMeterConfigStatisticsOutput createResult() {
1166 GetAllMeterConfigStatisticsOutputBuilder allMeterConfStatBuilder =
1167 new GetAllMeterConfigStatisticsOutputBuilder()
1168 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1169 return allMeterConfStatBuilder.build();
1177 return new OFRpcTaskImpl(taskContext, cookie, input);
1181 * @param taskContext task context
1182 * @param input get all meter statistics input
1183 * @param cookie switch connection distinguisher cookie value
1184 * @return task get all meter statistics task
1186 public static OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>> createGetAllMeterStatisticsTask(
1187 final OFRpcTaskContext taskContext, final GetAllMeterStatisticsInput input,
1188 SwitchConnectionDistinguisher cookie) {
1189 class OFRpcTaskImpl extends OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>> {
1191 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1192 GetAllMeterStatisticsInput input) {
1193 super(taskContext, cookie, input);
1194 // TODO Auto-generated constructor stub
1198 public ListenableFuture<RpcResult<GetAllMeterStatisticsOutput>> call()
1200 final SettableFuture<RpcResult<GetAllMeterStatisticsOutput>> result = SettableFuture.create();
1202 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1203 RpcResult<GetAllMeterStatisticsOutput> rpcResult = RpcResultBuilder.success(
1204 new GetAllMeterStatisticsOutputBuilder().build()).build();
1205 return Futures.immediateFuture(rpcResult);
1207 final Long xid = taskContext.getSession().getNextXid();
1209 MultipartRequestMeterCaseBuilder caseBuilder =
1210 new MultipartRequestMeterCaseBuilder();
1211 MultipartRequestMeterBuilder mprMeterBuild =
1212 new MultipartRequestMeterBuilder();
1213 mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(
1214 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common
1215 .types.rev130731.Meter.OFPMALL.getIntValue())));
1216 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
1218 MultipartRequestInputBuilder mprInput =
1219 createMultipartHeader(MultipartType.OFPMPMETER, taskContext, xid);
1220 mprInput.setMultipartRequestBody(caseBuilder.build());
1221 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1222 .multipartRequest(mprInput.build(), getCookie());
1223 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1225 Futures.addCallback(resultLib, new ResultCallback<GetAllMeterStatisticsOutput>(result) {
1227 public GetAllMeterStatisticsOutput createResult() {
1228 GetAllMeterStatisticsOutputBuilder allMeterStatBuilder =
1229 new GetAllMeterStatisticsOutputBuilder()
1230 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1231 return allMeterStatBuilder.build();
1239 return new OFRpcTaskImpl(taskContext, cookie, input);
1243 * @param taskContext task context
1244 * @param input get meter features input
1245 * @param cookie switch connection distinguisher cookie value
1246 * @return task get meter feature task
1248 public static OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>> createGetMeterFeaturesTask(
1249 final OFRpcTaskContext taskContext, final GetMeterFeaturesInput input,
1250 SwitchConnectionDistinguisher cookie) {
1252 class OFRpcTaskImpl extends OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>> {
1254 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1255 GetMeterFeaturesInput input) {
1256 super(taskContext, cookie, input);
1260 public ListenableFuture<RpcResult<GetMeterFeaturesOutput>> call()
1262 final SettableFuture<RpcResult<GetMeterFeaturesOutput>> result = SettableFuture.create();
1264 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1265 RpcResult<GetMeterFeaturesOutput> rpcResult = RpcResultBuilder.success(
1266 new GetMeterFeaturesOutputBuilder().build()).build();
1267 return Futures.immediateFuture(rpcResult);
1269 final Long xid = taskContext.getSession().getNextXid();
1271 MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild =
1272 new MultipartRequestMeterFeaturesCaseBuilder();
1274 MultipartRequestInputBuilder mprInput =
1275 createMultipartHeader(MultipartType.OFPMPMETERFEATURES, taskContext, xid);
1276 mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
1277 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1278 .multipartRequest(mprInput.build(), getCookie());
1279 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1281 Futures.addCallback(resultLib, new ResultCallback<GetMeterFeaturesOutput>(result) {
1283 public GetMeterFeaturesOutput createResult() {
1284 GetMeterFeaturesOutputBuilder meterFeaturesBuilder =
1285 new GetMeterFeaturesOutputBuilder()
1286 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1287 return meterFeaturesBuilder.build();
1295 return new OFRpcTaskImpl(taskContext, cookie, input);
1299 * @param taskContext task context
1300 * @param input get meter statistics input
1301 * @param cookie switch connection distinguisher cookie value
1302 * @return task get meter statistics task
1304 public static OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>> createGetMeterStatisticsTask(
1305 final OFRpcTaskContext taskContext, final GetMeterStatisticsInput input,
1306 SwitchConnectionDistinguisher cookie) {
1308 class OFRpcTaskImpl extends OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>> {
1310 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1311 GetMeterStatisticsInput input) {
1312 super(taskContext, cookie, input);
1316 public ListenableFuture<RpcResult<GetMeterStatisticsOutput>> call()
1318 final SettableFuture<RpcResult<GetMeterStatisticsOutput>> result = SettableFuture.create();
1320 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1321 RpcResult<GetMeterStatisticsOutput> rpcResult = RpcResultBuilder.success(
1322 new GetMeterStatisticsOutputBuilder().build()).build();
1323 return Futures.immediateFuture(rpcResult);
1325 final Long xid = taskContext.getSession().getNextXid();
1327 MultipartRequestMeterCaseBuilder caseBuilder =
1328 new MultipartRequestMeterCaseBuilder();
1329 MultipartRequestMeterBuilder mprMeterBuild =
1330 new MultipartRequestMeterBuilder();
1331 mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
1332 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
1334 MultipartRequestInputBuilder mprInput =
1335 createMultipartHeader(MultipartType.OFPMPMETER, taskContext, xid);
1336 mprInput.setMultipartRequestBody(caseBuilder.build());
1337 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1338 .multipartRequest(mprInput.build(), getCookie());
1339 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1341 Futures.addCallback(resultLib, new ResultCallback<GetMeterStatisticsOutput>(result) {
1343 public GetMeterStatisticsOutput createResult() {
1344 GetMeterStatisticsOutputBuilder meterStatBuilder =
1345 new GetMeterStatisticsOutputBuilder()
1346 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1347 return meterStatBuilder.build();
1355 return new OFRpcTaskImpl(taskContext, cookie, input);
1359 * @param taskContext task context
1360 * @param input get all node connector statistics input
1361 * @param cookie switch connection distinguisher cookie value
1362 * @return task get all node connector statistics task
1364 public static OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>>
1365 createGetAllNodeConnectorsStatisticsTask(
1366 final OFRpcTaskContext taskContext, final GetAllNodeConnectorsStatisticsInput input,
1367 SwitchConnectionDistinguisher cookie) {
1368 class OFRpcTaskImpl extends OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>> {
1370 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1371 GetAllNodeConnectorsStatisticsInput input) {
1372 super(taskContext, cookie, input);
1376 public ListenableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> call()
1378 final SettableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> result = SettableFuture.create();
1380 final Long xid = taskContext.getSession().getNextXid();
1382 MultipartRequestPortStatsCaseBuilder caseBuilder =
1383 new MultipartRequestPortStatsCaseBuilder();
1384 MultipartRequestPortStatsBuilder mprPortStatsBuilder =
1385 new MultipartRequestPortStatsBuilder();
1387 mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
1388 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1390 MultipartRequestInputBuilder mprInput =
1391 createMultipartHeader(MultipartType.OFPMPPORTSTATS, taskContext, xid);
1392 mprInput.setMultipartRequestBody(caseBuilder.build());
1393 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1394 .multipartRequest(mprInput.build(), getCookie());
1395 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1397 Futures.addCallback(resultLib, new ResultCallback<GetAllNodeConnectorsStatisticsOutput>(result) {
1399 public GetAllNodeConnectorsStatisticsOutput createResult() {
1400 GetAllNodeConnectorsStatisticsOutputBuilder allNodeConnectorStatBuilder =
1401 new GetAllNodeConnectorsStatisticsOutputBuilder()
1402 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1403 return allNodeConnectorStatBuilder.build();
1410 return new OFRpcTaskImpl(taskContext, cookie, input);
1414 * @param taskContext task context
1415 * @param input get node connector statistics input
1416 * @param cookie switch connection distinguisher cookie value
1417 * @return task get node connector statistics task
1419 public static OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>>
1420 createGetNodeConnectorStatisticsTask(
1421 final OFRpcTaskContext taskContext, final GetNodeConnectorStatisticsInput input,
1422 SwitchConnectionDistinguisher cookie) {
1423 class OFRpcTaskImpl extends OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>> {
1425 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1426 GetNodeConnectorStatisticsInput input) {
1427 super(taskContext, cookie, input);
1431 public ListenableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> call()
1433 final SettableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> result = SettableFuture.create();
1435 final Long xid = taskContext.getSession().getNextXid();
1437 MultipartRequestPortStatsCaseBuilder caseBuilder =
1438 new MultipartRequestPortStatsCaseBuilder();
1439 MultipartRequestPortStatsBuilder mprPortStatsBuilder =
1440 new MultipartRequestPortStatsBuilder();
1441 // Set specific port
1443 .setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
1444 OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
1445 input.getNodeConnectorId()));
1446 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1448 MultipartRequestInputBuilder mprInput =
1449 createMultipartHeader(MultipartType.OFPMPPORTSTATS, taskContext, xid);
1450 mprInput.setMultipartRequestBody(caseBuilder.build());
1451 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1452 .multipartRequest(mprInput.build(), getCookie());
1453 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1455 Futures.addCallback(resultLib, new ResultCallback<GetNodeConnectorStatisticsOutput>(result) {
1457 public GetNodeConnectorStatisticsOutput createResult() {
1458 GetNodeConnectorStatisticsOutputBuilder allNodeConnectorStatBuilder =
1459 new GetNodeConnectorStatisticsOutputBuilder()
1460 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1461 return allNodeConnectorStatBuilder.build();
1468 return new OFRpcTaskImpl(taskContext, cookie, input);
1472 * @param taskContext task context
1473 * @param input get all flow statistics from flow table
1474 * @param cookie switch connection distinguisher cookie value
1475 * @return task get all flow statistics from flow table task
1477 public static OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>>
1478 createGetAllFlowStatisticsFromFlowTableTask(
1479 final OFRpcTaskContext taskContext,
1480 final GetAllFlowStatisticsFromFlowTableInput input,
1481 SwitchConnectionDistinguisher cookie) {
1482 class OFRpcTaskImpl extends OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> {
1484 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1485 GetAllFlowStatisticsFromFlowTableInput input) {
1486 super(taskContext, cookie, input);
1490 public ListenableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> call() throws Exception {
1491 final SettableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> result = SettableFuture.create();
1493 final Long xid = taskContext.getSession().getNextXid();
1495 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1496 mprFlowRequestBuilder.setTableId(input.getTableId().getValue());
1497 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1498 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1499 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1500 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1501 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1502 .getPrimaryConductor().getVersion(), mprFlowRequestBuilder);
1504 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1505 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1507 MultipartRequestInputBuilder mprInput =
1508 createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid);
1509 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1510 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1511 .multipartRequest(mprInput.build(), getCookie());
1512 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1514 Futures.addCallback(resultLib, new ResultCallback<GetAllFlowStatisticsFromFlowTableOutput>(result) {
1516 public GetAllFlowStatisticsFromFlowTableOutput createResult() {
1517 GetAllFlowStatisticsFromFlowTableOutputBuilder allFlowStatsFromFlowTableBuilder =
1518 new GetAllFlowStatisticsFromFlowTableOutputBuilder()
1519 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1520 return allFlowStatsFromFlowTableBuilder.build();
1527 return new OFRpcTaskImpl(taskContext, cookie, input);
1531 * @param taskContext task context
1532 * @param input get all flow statistics from all flow table
1533 * @param cookie switch connection distinguisher cookie value
1534 * @return task get all flow statistics from all flow table task
1536 public static OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput, RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>>
1537 createGetAllFlowsStatisticsFromAllFlowTablesTask(
1538 final OFRpcTaskContext taskContext,
1539 final GetAllFlowsStatisticsFromAllFlowTablesInput input,
1540 SwitchConnectionDistinguisher cookie) {
1541 class OFRpcTaskImpl extends OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput,
1542 RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> {
1544 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1545 GetAllFlowsStatisticsFromAllFlowTablesInput input) {
1546 super(taskContext, cookie, input);
1550 public ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> call() throws Exception {
1551 final SettableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> result = SettableFuture.create();
1553 final Long xid = taskContext.getSession().getNextXid();
1555 // Create multipart request body for fetch all the group stats
1556 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder =
1557 new MultipartRequestFlowCaseBuilder();
1558 MultipartRequestFlowBuilder mprFlowRequestBuilder =
1559 new MultipartRequestFlowBuilder();
1560 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
1561 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1562 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1563 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1564 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1565 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1566 .getPrimaryConductor().getVersion(), mprFlowRequestBuilder);
1568 MultipartRequestInputBuilder mprInput =
1569 createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid);
1570 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1571 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1572 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1573 .multipartRequest(mprInput.build(), getCookie());
1574 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1576 Futures.addCallback(resultLib, new ResultCallback<GetAllFlowsStatisticsFromAllFlowTablesOutput>(result) {
1578 public GetAllFlowsStatisticsFromAllFlowTablesOutput createResult() {
1579 GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder allFlowStatsFromAllFlowTableBuilder =
1580 new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder()
1581 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1582 return allFlowStatsFromAllFlowTableBuilder.build();
1589 return new OFRpcTaskImpl(taskContext, cookie, input);
1593 * @param taskContext task context
1594 * @param input get flow statistics from flow table
1595 * @param cookie switch connection distinguisher cookie value
1596 * @return task get flow statistics from flow table task
1598 public static OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>>
1599 createGetFlowStatisticsFromFlowTableTask(
1600 final OFRpcTaskContext taskContext,
1601 final GetFlowStatisticsFromFlowTableInput input, SwitchConnectionDistinguisher cookie) {
1603 class OFRpcTaskImpl extends OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>> {
1605 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1606 GetFlowStatisticsFromFlowTableInput input) {
1607 super(taskContext, cookie, input);
1611 public ListenableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> call() throws Exception {
1612 final SettableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> result = SettableFuture.create();
1614 final Long xid = taskContext.getSession().getNextXid();
1616 // Create multipart request body for fetch all the group stats
1617 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1618 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1619 mprFlowRequestBuilder.setTableId(input.getTableId());
1621 if (input.getOutPort() != null) {
1622 mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue());
1624 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1627 if (input.getOutGroup() != null) {
1628 mprFlowRequestBuilder.setOutGroup(input.getOutGroup());
1630 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1633 if (input.getCookie() != null) {
1634 mprFlowRequestBuilder.setCookie(input.getCookie().getValue());
1636 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1639 if (input.getCookieMask() != null) {
1640 mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue());
1642 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1645 // convert and inject match
1646 MatchReactor.getInstance().convert(input.getMatch(), taskContext.getSession()
1647 .getPrimaryConductor().getVersion(), mprFlowRequestBuilder,
1648 taskContext.getSession().getFeatures().getDatapathId());
1650 // Set request body to main multipart request
1651 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1652 MultipartRequestInputBuilder mprInput =
1653 createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid);
1654 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1655 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1656 .multipartRequest(mprInput.build(), getCookie());
1657 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1659 Futures.addCallback(resultLib, new ResultCallback<GetFlowStatisticsFromFlowTableOutput>(result) {
1661 public GetFlowStatisticsFromFlowTableOutput createResult() {
1662 GetFlowStatisticsFromFlowTableOutputBuilder flowStatsFromFlowTableBuilder =
1663 new GetFlowStatisticsFromFlowTableOutputBuilder()
1664 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1665 return flowStatsFromFlowTableBuilder.build();
1672 return new OFRpcTaskImpl(taskContext, cookie, input);
1676 * @param taskContext task context
1677 * @param input get aggregate flow statistics from flow table for all flow input
1678 * @param cookie switch connection distinguisher cookie value
1679 * @return task get aggregate flow stats from flow table for all flow task
1681 public static OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>>
1682 createGetAggregateFlowStatisticsFromFlowTableForAllFlowsTask(
1683 final OFRpcTaskContext taskContext,
1684 final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input, SwitchConnectionDistinguisher cookie) {
1685 class OFRpcTaskImpl extends OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> {
1687 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1688 GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
1689 super(taskContext, cookie, input);
1693 public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> call() throws Exception {
1694 final SettableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> result = SettableFuture.create();
1696 final Long xid = taskContext.getSession().getNextXid();
1698 // Create multipart request body for fetch all the group stats
1699 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1700 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1701 mprAggregateRequestBuilder.setTableId(input.getTableId().getValue());
1702 mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1703 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1704 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1705 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1707 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1708 .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder);
1710 // Set request body to main multipart request
1711 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1712 MultipartRequestInputBuilder mprInput =
1713 createMultipartHeader(MultipartType.OFPMPAGGREGATE, taskContext, xid);
1714 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1715 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1716 .multipartRequest(mprInput.build(), getCookie());
1717 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1719 Futures.addCallback(resultLib, new ResultCallback<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>(result) {
1721 public GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput createResult() {
1722 GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder flowStatsFromFlowTableBuilder =
1723 new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder()
1724 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1725 return flowStatsFromFlowTableBuilder.build();
1732 return new OFRpcTaskImpl(taskContext, cookie, input);
1736 * @param taskContext task context
1737 * @param input aggregate flow statistics input
1738 * @param cookie switch connection distinguisher cookie value
1739 * @return task task to fetch the statistics
1741 public static OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>
1742 createGetAggregateFlowStatisticsFromFlowTableForGivenMatchTask(
1743 final OFRpcTaskContext taskContext,
1744 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input, SwitchConnectionDistinguisher cookie) {
1745 class OFRpcTaskImpl extends OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> {
1747 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1748 GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
1749 super(taskContext, cookie, input);
1753 public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> call() throws Exception {
1754 final SettableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> result = SettableFuture.create();
1756 final Long xid = taskContext.getSession().getNextXid();
1758 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1759 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1760 mprAggregateRequestBuilder.setTableId(input.getTableId());
1761 mprAggregateRequestBuilder.setOutPort(input.getOutPort().longValue());
1762 // TODO: repeating code
1763 if (taskContext.getSession().getPrimaryConductor().getVersion() ==
1764 OFConstants.OFP_VERSION_1_3) {
1765 mprAggregateRequestBuilder.setCookie(input.getCookie().getValue());
1766 mprAggregateRequestBuilder.setCookieMask(input.getCookieMask().getValue());
1767 mprAggregateRequestBuilder.setOutGroup(input.getOutGroup());
1769 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1770 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1771 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1774 MatchReactor.getInstance().convert(input.getMatch(), taskContext.getSession()
1775 .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder,
1776 taskContext.getSession().getFeatures().getDatapathId());
1778 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1779 .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder);
1781 // Set request body to main multipart request
1782 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1783 MultipartRequestInputBuilder mprInput =
1784 createMultipartHeader(MultipartType.OFPMPAGGREGATE, taskContext, xid);
1785 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1786 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1787 .multipartRequest(mprInput.build(), getCookie());
1788 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1790 Futures.addCallback(resultLib, new ResultCallback<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>(result) {
1792 public GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput createResult() {
1793 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder aggregFlowStatsFromFlowTableBuilder =
1794 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder()
1795 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1796 return aggregFlowStatsFromFlowTableBuilder.build();
1803 return new OFRpcTaskImpl(taskContext, cookie, input);
1807 * @param taskContext task context
1808 * @param input flow table statistics input
1809 * @param cookie switch connection distinguisher cookie value
1810 * @return task task to fetch table statistics
1812 public static OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>> createGetFlowTablesStatisticsTask(
1813 final OFRpcTaskContext taskContext, final GetFlowTablesStatisticsInput input, SwitchConnectionDistinguisher cookie) {
1815 class OFRpcTaskImpl extends OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>> {
1817 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1818 GetFlowTablesStatisticsInput input) {
1819 super(taskContext, cookie, input);
1823 public ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>> call() throws Exception {
1824 final SettableFuture<RpcResult<GetFlowTablesStatisticsOutput>> result = SettableFuture.create();
1826 final Long xid = taskContext.getSession().getNextXid();
1828 // Create multipart request body for fetch all the group stats
1829 MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
1830 MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
1831 multipartRequestTableBuilder.setEmpty(true);
1832 multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
1834 // Set request body to main multipart request
1835 MultipartRequestInputBuilder mprInput =
1836 createMultipartHeader(MultipartType.OFPMPTABLE, taskContext, xid);
1837 mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
1838 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1839 .multipartRequest(mprInput.build(), getCookie());
1840 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1842 Futures.addCallback(resultLib, new ResultCallback<GetFlowTablesStatisticsOutput>(result) {
1844 public GetFlowTablesStatisticsOutput createResult() {
1845 GetFlowTablesStatisticsOutputBuilder flowTableStatsBuilder =
1846 new GetFlowTablesStatisticsOutputBuilder()
1847 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1848 return flowTableStatsBuilder.build();
1855 return new OFRpcTaskImpl(taskContext, cookie, input);
1859 * @param taskContext task context
1860 * @param input queue statistics input
1861 * @param cookie switch connection distinguisher cookie value
1862 * @return task task to fetch all queue statistics
1864 public static OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> createGetAllQueuesStatisticsFromAllPortsTask(
1865 final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromAllPortsInput input, SwitchConnectionDistinguisher cookie) {
1867 class OFRpcTaskImpl extends OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> {
1869 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1870 GetAllQueuesStatisticsFromAllPortsInput input) {
1871 super(taskContext, cookie, input);
1875 public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> call() throws Exception {
1876 final SettableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> result = SettableFuture.create();
1878 final Long xid = taskContext.getSession().getNextXid();
1880 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1881 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1883 mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
1884 // Select all the queues
1885 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
1886 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1888 // Set request body to main multipart request
1889 MultipartRequestInputBuilder mprInput =
1890 createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid);
1891 mprInput.setMultipartRequestBody(caseBuilder.build());
1892 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1893 .multipartRequest(mprInput.build(), getCookie());
1894 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1896 Futures.addCallback(resultLib, new ResultCallback<GetAllQueuesStatisticsFromAllPortsOutput>(result) {
1898 public GetAllQueuesStatisticsFromAllPortsOutput createResult() {
1899 GetAllQueuesStatisticsFromAllPortsOutputBuilder allQueueStatsBuilder =
1900 new GetAllQueuesStatisticsFromAllPortsOutputBuilder()
1901 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1902 return allQueueStatsBuilder.build();
1909 return new OFRpcTaskImpl(taskContext, cookie, input);
1913 * @param taskContext task context
1914 * @param input queue statist from specific port input
1915 * @param cookie switch connection distinguisher cookie value
1916 * @return task task to get queue statistics from specific port
1918 public static OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> createGetAllQueuesStatisticsFromGivenPortTask(
1919 final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromGivenPortInput input, SwitchConnectionDistinguisher cookie) {
1921 class OFRpcTaskImpl extends OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> {
1923 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1924 GetAllQueuesStatisticsFromGivenPortInput input) {
1925 super(taskContext, cookie, input);
1929 public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> call() throws Exception {
1930 final SettableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> result = SettableFuture.create();
1932 final Long xid = taskContext.getSession().getNextXid();
1934 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1935 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1936 // Select all queues
1937 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
1938 // Select specific port
1939 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
1940 OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
1941 input.getNodeConnectorId()));
1942 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1944 // Set request body to main multipart request
1945 MultipartRequestInputBuilder mprInput =
1946 createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid);
1947 mprInput.setMultipartRequestBody(caseBuilder.build());
1948 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1949 .multipartRequest(mprInput.build(), getCookie());
1950 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1952 Futures.addCallback(resultLib, new ResultCallback<GetAllQueuesStatisticsFromGivenPortOutput>(result) {
1954 public GetAllQueuesStatisticsFromGivenPortOutput createResult() {
1955 GetAllQueuesStatisticsFromGivenPortOutputBuilder allQueueStatsBuilder =
1956 new GetAllQueuesStatisticsFromGivenPortOutputBuilder()
1957 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1958 return allQueueStatsBuilder.build();
1965 return new OFRpcTaskImpl(taskContext, cookie, input);
1969 * @param taskContext task context
1970 * @param input queue statistics from given port
1971 * @param cookie switch connection distinguisher cookie value
1972 * @return task task to get queue statistics from given port
1974 public static OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>> createGetQueueStatisticsFromGivenPortTask(
1975 final OFRpcTaskContext taskContext, final GetQueueStatisticsFromGivenPortInput input, SwitchConnectionDistinguisher cookie) {
1977 class OFRpcTaskImpl extends OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>> {
1979 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1980 GetQueueStatisticsFromGivenPortInput input) {
1981 super(taskContext, cookie, input);
1985 public ListenableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> call() throws Exception {
1986 final SettableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> result = SettableFuture.create();
1988 final Long xid = taskContext.getSession().getNextXid();
1990 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1991 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1992 // Select specific queue
1993 mprQueueBuilder.setQueueId(input.getQueueId().getValue());
1994 // Select specific port
1995 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
1996 OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
1997 input.getNodeConnectorId()));
1998 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
2000 // Set request body to main multipart request
2001 MultipartRequestInputBuilder mprInput =
2002 createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid);
2003 mprInput.setMultipartRequestBody(caseBuilder.build());
2004 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
2005 .multipartRequest(mprInput.build(), getCookie());
2006 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
2008 Futures.addCallback(resultLib, new ResultCallback<GetQueueStatisticsFromGivenPortOutput>(result) {
2010 public GetQueueStatisticsFromGivenPortOutput createResult() {
2011 GetQueueStatisticsFromGivenPortOutputBuilder queueStatsFromPortBuilder =
2012 new GetQueueStatisticsFromGivenPortOutputBuilder()
2013 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
2014 return queueStatsFromPortBuilder.build();
2021 return new OFRpcTaskImpl(taskContext, cookie, input);
2024 static MultipartRequestInputBuilder createMultipartHeader(MultipartType multipart,
2025 OFRpcTaskContext taskContext, Long xid) {
2026 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
2027 mprInput.setType(multipart);
2028 mprInput.setVersion(taskContext.getSession().getPrimaryConductor().getVersion());
2029 mprInput.setXid(xid);
2030 mprInput.setFlags(new MultipartRequestFlags(false));
2034 private abstract static class ResultCallback<T> implements FutureCallback<RpcResult<Void>> {
2036 private SettableFuture<RpcResult<T>> result;
2039 * @param result result
2041 public ResultCallback(SettableFuture<RpcResult<T>> result) {
2042 this.result = result;
2045 public abstract T createResult();
2048 public void onSuccess(RpcResult<Void> resultArg) {
2049 result.set(RpcResultBuilder.success(createResult()).build());
2053 public void onFailure(Throwable t) {
2054 result.set(RpcResultBuilder.<T>failed().withWarning(
2056 OFConstants.ERROR_TAG_TIMEOUT,
2057 "something wrong happened",
2058 OFConstants.APPLICATION_TAG,
2064 * @param taskContext task context
2065 * @param input update port input
2066 * @param cookie switch connection distinguisher cookie value
2067 * @return task task to update port
2069 public static OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>> createUpdatePortTask(
2070 final OFRpcTaskContext taskContext, final UpdatePortInput input,
2071 final SwitchConnectionDistinguisher cookie) {
2073 class OFRpcTaskImpl extends OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>> {
2075 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
2076 UpdatePortInput input) {
2077 super(taskContext, cookie, input);
2081 public ListenableFuture<RpcResult<UpdatePortOutput>> call() {
2082 ListenableFuture<RpcResult<UpdatePortOutput>> result = SettableFuture.create();
2083 final Long xid = taskContext.getSession().getNextXid();
2084 Port inputPort = input.getUpdatedPort().getPort().getPort().get(0);
2086 PortModInput ofPortModInput = PortConvertor.toPortModInput(inputPort,
2087 taskContext.getSession().getPrimaryConductor().getVersion());
2089 PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
2090 mdInput.setXid(xid);
2092 Future<RpcResult<UpdatePortOutput>> resultFromOFLib = getMessageService()
2093 .portMod(mdInput.build(), cookie);
2094 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
2100 return new OFRpcTaskImpl(taskContext, cookie, input);
2104 * @param taskContext task context
2105 * @param input update table input
2106 * @param cookie switch connection distinguisher cookie value
2107 * @return task task to udpate table input
2109 public static OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>> createUpdateTableTask(
2110 final OFRpcTaskContext taskContext, final UpdateTableInput input,
2111 final SwitchConnectionDistinguisher cookie) {
2113 class OFRpcTaskImpl extends OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>> {
2115 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
2116 UpdateTableInput input) {
2117 super(taskContext, cookie, input);
2121 public ListenableFuture<RpcResult<UpdateTableOutput>> call() {
2122 final SettableFuture<RpcResult<UpdateTableOutput>> result = SettableFuture.create();
2124 final Long xid = taskContext.getSession().getNextXid();
2126 MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder();
2127 MultipartRequestTableFeaturesBuilder requestBuilder = new MultipartRequestTableFeaturesBuilder();
2128 List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor
2129 .toTableFeaturesRequest(input.getUpdatedTable());
2130 requestBuilder.setTableFeatures(ofTableFeatureList);
2131 caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build());
2133 // Set request body to main multipart request
2134 MultipartRequestInputBuilder mprInput =
2135 createMultipartHeader(MultipartType.OFPMPTABLEFEATURES, taskContext, xid);
2136 mprInput.setMultipartRequestBody(caseBuilder.build());
2138 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
2139 .multipartRequest(mprInput.build(), getCookie());
2140 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
2142 Futures.addCallback(resultLib, new ResultCallback<UpdateTableOutput>(result) {
2144 public UpdateTableOutput createResult() {
2145 UpdateTableOutputBuilder queueStatsFromPortBuilder =
2146 new UpdateTableOutputBuilder()
2147 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
2148 return queueStatsFromPortBuilder.build();
2155 return new OFRpcTaskImpl(taskContext, cookie, input);
2158 public static OFRpcTask<SetConfigInput, RpcResult<SetConfigOutput>> createSetNodeConfigTask(final OFRpcTaskContext taskContext,
2159 final SetConfigInput input,
2160 final SwitchConnectionDistinguisher cookie) {
2161 class OFRpcTaskImpl extends OFRpcTask<SetConfigInput, RpcResult<SetConfigOutput>> {
2163 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
2164 SetConfigInput input) {
2165 super(taskContext, cookie, input);
2169 public ListenableFuture<RpcResult<SetConfigOutput>> call() throws Exception {
2171 final SettableFuture<RpcResult<SetConfigOutput>> result = SettableFuture.create();
2172 final Long xid = taskContext.getSession().getNextXid();
2174 SetConfigInputBuilder builder = new SetConfigInputBuilder();
2175 SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag());
2176 builder.setXid(xid);
2177 builder.setFlags(flag);
2178 builder.setMissSendLen(input.getMissSearchLength());
2179 builder.setVersion(getVersion());
2180 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(taskContext.getSession().getPrimaryConductor().getConnectionAdapter().setConfig(builder.build()));
2181 Futures.addCallback(resultLib, new ResultCallback<SetConfigOutput>(result) {
2183 public SetConfigOutput createResult() {
2184 SetConfigOutputBuilder setConfigOutputBuilder = new SetConfigOutputBuilder();
2185 setConfigOutputBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
2186 return setConfigOutputBuilder.build();
2193 return new OFRpcTaskImpl(taskContext, cookie, input);