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.Collections;
21 import java.util.List;
22 import java.util.concurrent.Future;
23 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
25 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
26 import org.opendaylight.openflowjava.protocol.api.util.BinContent;
27 import org.opendaylight.openflowplugin.api.OFConstants;
28 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
29 import org.opendaylight.openflowplugin.api.openflow.md.core.sal.NotificationComposer;
30 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
31 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
32 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
33 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor;
34 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
35 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
36 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
37 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData;
38 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
39 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
40 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowHashIdMapping;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.nodes.node.table.FlowHashIdMap;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.nodes.node.table.FlowHashIdMapKey;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdatedBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutputBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutputBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupAdded;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupAddedBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemoved;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemovedBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdated;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdatedBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutputBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutputBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutputBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutputBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterAdded;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterAddedBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemoved;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemovedBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdated;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdatedBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutputBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutputBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutputBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutput;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutputBuilder;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;
164 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;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInput;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutputBuilder;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInput;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutput;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutputBuilder;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutputBuilder;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInput;
177 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput;
178 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutputBuilder;
179 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInput;
180 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput;
181 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutputBuilder;
182 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
183 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
184 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder;
185 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
186 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
187 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
188 import org.opendaylight.yangtools.yang.common.RpcResult;
189 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
190 import org.slf4j.Logger;
191 import org.slf4j.LoggerFactory;
196 public abstract class OFRpcTaskFactory {
197 protected static final Logger LOG = LoggerFactory.getLogger(OFRpcTaskFactory.class);
199 private OFRpcTaskFactory() {
200 // hiding implicit constructor
204 * @param taskContext task context
205 * @param input flow object input
206 * @param cookie switch connection distinguisher cookie value
207 * @return UpdateFlow task
209 public static OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> createAddFlowTask(
210 OFRpcTaskContext taskContext, AddFlowInput input,
211 SwitchConnectionDistinguisher cookie) {
213 class OFRpcTaskImpl extends OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> {
215 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddFlowInput input) {
216 super(taskContext, cookie, input);
220 public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
221 ListenableFuture<RpcResult<UpdateFlowOutput>> result = SettableFuture.create();
223 // Convert the AddFlowInput to FlowModInput
224 List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput(),
225 getVersion(), getSession().getFeatures().getDatapathId());
226 LOG.debug("Number of flows to push to switch: {}", ofFlowModInputs.size());
227 result = chainFlowMods(ofFlowModInputs, 0, getTaskContext(), getCookie());
228 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
229 OFRpcTaskUtil.hookFutureNotification(this, result,
230 getRpcNotificationProviderService(),
231 createFlowAddedNotification(getInput()));
236 public Boolean isBarrier() {
237 return getInput().isBarrier();
241 return new OFRpcTaskImpl(taskContext, cookie, input);
245 * Recursive helper method for {@link OFRpcTaskFactory#createAddFlowTask(OFRpcTaskContext, AddFlowInput, SwitchConnectionDistinguisher)}
246 * and {@link OFRpcTaskFactory#createUpdateFlowTask(OFRpcTaskContext, UpdateFlowInput, SwitchConnectionDistinguisher, ReadWriteTransaction)} to chain results
247 * of multiple flowmods.
248 * The next flowmod gets executed if the earlier one is successful.
249 * All the flowmods should have the same xid, in-order to cross-reference
251 * @param taskContext task context
252 * @param ofFlowModInputs list of flow mod as input
253 * @param index starting index
254 * @param cookie switch connection distinguisher
255 * @return listenable future with update flow output
258 protected static ListenableFuture<RpcResult<UpdateFlowOutput>> chainFlowMods(
259 final List<FlowModInputBuilder> ofFlowModInputs, final int index,
260 final OFRpcTaskContext taskContext, final SwitchConnectionDistinguisher cookie) {
262 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib =
263 createResultForFlowMod(taskContext, ofFlowModInputs.get(index), cookie);
265 ListenableFuture<RpcResult<UpdateFlowOutput>> result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
267 if (ofFlowModInputs.size() > index + 1) {
268 // there are more flowmods to chain
269 return Futures.transform(result,
270 new AsyncFunction<RpcResult<UpdateFlowOutput>, RpcResult<UpdateFlowOutput>>() {
272 public ListenableFuture<RpcResult<UpdateFlowOutput>> apply(RpcResult<UpdateFlowOutput> input) throws Exception {
273 if (input.isSuccessful()) {
274 return chainFlowMods(ofFlowModInputs, index + 1, taskContext, cookie);
276 LOG.warn("Flowmod failed. Any chained flowmods are ignored. xid:{}",
277 ofFlowModInputs.get(index).getXid());
278 return Futures.immediateFuture(input);
288 private static Future<RpcResult<UpdateFlowOutput>> createResultForFlowMod(
289 OFRpcTaskContext taskContext, FlowModInputBuilder flowModInput,
290 SwitchConnectionDistinguisher cookie) {
291 flowModInput.setXid(taskContext.getSession().getNextXid());
292 return taskContext.getMessageService().flowMod(flowModInput.build(), cookie);
297 * @param input flow input
298 * @return flow added notification
300 protected static NotificationComposer<FlowAdded> createFlowAddedNotification(
301 final AddFlowInput input) {
302 return new NotificationComposer<FlowAdded>() {
304 public FlowAdded compose(TransactionId tXid) {
305 FlowAddedBuilder newFlow = new FlowAddedBuilder((Flow) input);
306 newFlow.setTransactionId(tXid);
307 newFlow.setFlowRef(input.getFlowRef());
308 return newFlow.build();
314 * @param taskContext task context
315 * @param input update flow input
316 * @param cookie switch connection distinguisher cookie value
317 * @param rwTx read write transaction
318 * @return UpdateFlow task
320 public static OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> createUpdateFlowTask(
321 final OFRpcTaskContext taskContext, UpdateFlowInput input,
322 SwitchConnectionDistinguisher cookie, final ReadWriteTransaction rwTx) {
324 class OFRpcTaskImpl extends OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> {
325 final ReadWriteTransaction rwTx;
326 InstanceIdentifier<Table> iiToTable = null;
327 String flowId = null;
328 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
329 final UpdateFlowInput in, final ReadWriteTransaction rwTx) {
330 super(taskContext, cookie, in);
331 final FlowRef flowRef = in.getFlowRef();
332 if (flowRef != null) {
333 InstanceIdentifier<Flow> iiToFlow = (InstanceIdentifier<Flow>)(flowRef.getValue());
334 iiToTable = flowRef.getValue().firstIdentifierOf(Table.class);
335 FlowKey flowKey = iiToFlow.firstKeyOf(
336 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow.class, FlowKey.class);
337 if (flowKey != null) {
338 flowId = flowKey.getId().getValue();
345 public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
346 ListenableFuture<RpcResult<UpdateFlowOutput>> result = null;
348 UpdateFlowInput in = getInput();
349 UpdatedFlow updated = in.getUpdatedFlow();
350 OriginalFlow original = in.getOriginalFlow();
351 Short version = getVersion();
353 List<FlowModInputBuilder> allFlowMods = new ArrayList<>();
354 List<FlowModInputBuilder> ofFlowModInputs;
356 if (!FlowCreatorUtil.canModifyFlow(original, updated, version)) {
357 // We would need to remove original and add updated.
360 RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(original);
361 List<FlowModInputBuilder> ofFlowRemoveInput = FlowConvertor.toFlowModInputs(removeflow.build(),
362 version, getSession().getFeatures().getDatapathId());
363 // remove flow should be the first
364 allFlowMods.addAll(ofFlowRemoveInput);
365 AddFlowInputBuilder addFlowInputBuilder = new AddFlowInputBuilder(updated);
366 ofFlowModInputs = FlowConvertor.toFlowModInputs(addFlowInputBuilder.build(),
367 version, getSession().getFeatures().getDatapathId());
369 ofFlowModInputs = FlowConvertor.toFlowModInputs(updated,
370 version, getSession().getFeatures().getDatapathId());
373 //deleting flow hash value from operational DS
374 if (flowId != null) {
375 CheckedFuture<Optional<FlowHashIdMapping>, ReadFailedException> hashDeletionFuture
376 = readFlowHashIdMappingFromOperationalDS(rwTx);
377 Futures.addCallback(hashDeletionFuture, new FutureCallback<Optional<FlowHashIdMapping>>() {
379 public void onSuccess(Optional<FlowHashIdMapping> optFlowHashIdMapping) {
380 FlowHashIdMapKey flowHashIdMapKeyToDelete = null;
381 if (optFlowHashIdMapping.isPresent()) {
382 FlowHashIdMapping flowHashIdMapping = optFlowHashIdMapping.get();
383 for (FlowHashIdMap flowHashId : flowHashIdMapping.getFlowHashIdMap()) {
384 if (flowHashId.getFlowId().getValue().equals(flowId)) {
385 flowHashIdMapKeyToDelete = flowHashId.getKey();
390 if (flowHashIdMapKeyToDelete != null) {
391 final KeyedInstanceIdentifier<FlowHashIdMap, FlowHashIdMapKey> iiToFlowHashIdToDelete = iiToTable
392 .augmentation(FlowHashIdMapping.class).child(FlowHashIdMap.class, flowHashIdMapKeyToDelete);
393 rwTx.delete(LogicalDatastoreType.OPERATIONAL, iiToFlowHashIdToDelete);
399 public void onFailure(Throwable t) {
400 LOG.debug("Reading flow-hash-id map from operational DS wasn't successful");
406 allFlowMods.addAll(ofFlowModInputs);
407 LOG.debug("Number of flows to push to switch: {}", allFlowMods.size());
408 result = chainFlowMods(allFlowMods, 0, getTaskContext(), getCookie());
410 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
411 OFRpcTaskUtil.hookFutureNotification(this, result,
412 getRpcNotificationProviderService(),
413 createFlowUpdatedNotification(in));
419 CheckedFuture<Optional<FlowHashIdMapping>, ReadFailedException> readFlowHashIdMappingFromOperationalDS(final ReadWriteTransaction rwTx) {
420 InstanceIdentifier<FlowHashIdMapping> iiToFlowHashIdMapping = iiToTable
421 .augmentation(FlowHashIdMapping.class);
422 return rwTx.read(LogicalDatastoreType.OPERATIONAL, iiToFlowHashIdMapping);
426 public Boolean isBarrier() {
427 return getInput().getUpdatedFlow().isBarrier();
430 return new OFRpcTaskImpl(taskContext, cookie, input, rwTx);
435 * @param input update flow input
436 * @return flow update notification
438 protected static NotificationComposer<FlowUpdated> createFlowUpdatedNotification(final UpdateFlowInput input) {
439 return new NotificationComposer<FlowUpdated>() {
441 public FlowUpdated compose(TransactionId tXid) {
442 FlowUpdatedBuilder updFlow = new FlowUpdatedBuilder(input.getUpdatedFlow());
443 updFlow.setTransactionId(tXid);
444 updFlow.setFlowRef(input.getFlowRef());
445 return updFlow.build();
451 * @param taskContext taks context
452 * @param input group update input
453 * @param cookie switch connection distinguisher cookie value
454 * @return update group task
456 public static OFRpcTask<AddGroupInput, RpcResult<UpdateGroupOutput>> createAddGroupTask(
457 final OFRpcTaskContext taskContext, AddGroupInput input,
458 final SwitchConnectionDistinguisher cookie) {
459 class OFRpcTaskImpl extends OFRpcTask<AddGroupInput, RpcResult<UpdateGroupOutput>> {
461 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddGroupInput input) {
462 super(taskContext, cookie, input);
466 public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
467 ListenableFuture<RpcResult<UpdateGroupOutput>> result = SettableFuture.create();
468 final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(getVersion());
469 data.setDatapathId(getSession().getFeatures().getDatapathId());
471 // Convert the AddGroupInput to GroupModInput
472 final java.util.Optional<GroupModInputBuilder> ofGroupModInput = ConvertorManager.getInstance().convert(getInput(), data);
473 final GroupModInputBuilder groupModInputBuilder = ofGroupModInput
474 .orElse(GroupConvertor.defaultResult(getVersion()))
475 .setXid(getSession().getNextXid());
477 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
478 .groupMod(groupModInputBuilder.build(), getCookie());
479 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
480 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
481 OFRpcTaskUtil.hookFutureNotification(this, result,
482 getRpcNotificationProviderService(), createGroupAddedNotification(getInput()));
488 public Boolean isBarrier() {
489 return getInput().isBarrier();
493 return new OFRpcTaskImpl(taskContext, cookie, input);
498 * @param input group add input
499 * @return group added notification
501 protected static NotificationComposer<GroupAdded> createGroupAddedNotification(
502 final AddGroupInput input) {
503 return new NotificationComposer<GroupAdded>() {
505 public GroupAdded compose(TransactionId tXid) {
506 GroupAddedBuilder groupMod = new GroupAddedBuilder((Group) input);
507 groupMod.setTransactionId(tXid);
508 groupMod.setGroupRef(input.getGroupRef());
509 return groupMod.build();
515 * @param taskContext task context
516 * @param input meter add input
517 * @param cookie switch connection distinguisher
518 * @return update meter task
520 public static OFRpcTask<AddMeterInput, RpcResult<UpdateMeterOutput>> createAddMeterTask(
521 OFRpcTaskContext taskContext, AddMeterInput input,
522 SwitchConnectionDistinguisher cookie) {
523 class OFRpcTaskImpl extends OFRpcTask<AddMeterInput, RpcResult<UpdateMeterOutput>> {
525 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddMeterInput input) {
526 super(taskContext, cookie, input);
530 public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
531 ListenableFuture<RpcResult<UpdateMeterOutput>> result = SettableFuture.create();
533 // Convert the AddMeterInput to UpdateMeterOutput
534 final java.util.Optional<MeterModInputBuilder> ofMeterModInput = ConvertorManager
536 .convert(getInput(), new VersionConvertorData(getVersion()));
538 final MeterModInputBuilder meterModInputBuilder = ofMeterModInput
539 .orElse(MeterConvertor.defaultResult(getVersion()))
540 .setXid(getSession().getNextXid());
542 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
543 .meterMod(meterModInputBuilder.build(), getCookie());
544 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
545 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
546 OFRpcTaskUtil.hookFutureNotification(this, result,
547 getRpcNotificationProviderService(), createMeterAddedNotification(getInput()));
553 public Boolean isBarrier() {
554 return getInput().isBarrier();
558 return new OFRpcTaskImpl(taskContext, cookie, input);
562 * @param input add meter input
563 * @return meter added notification composer
565 protected static NotificationComposer<MeterAdded> createMeterAddedNotification(
566 final AddMeterInput input) {
567 return new NotificationComposer<MeterAdded>() {
569 public MeterAdded compose(TransactionId tXid) {
570 MeterAddedBuilder meterMod = new MeterAddedBuilder((Meter) input);
571 meterMod.setTransactionId(tXid);
572 meterMod.setMeterRef(input.getMeterRef());
573 return meterMod.build();
579 * @param taskContext task context
580 * @param input update group output
581 * @param cookie switch connection distinguisher cookie value
582 * @return UpdateFlow task
584 public static OFRpcTask<UpdateGroupInput, RpcResult<UpdateGroupOutput>> createUpdateGroupTask(
585 OFRpcTaskContext taskContext, UpdateGroupInput input,
586 SwitchConnectionDistinguisher cookie) {
587 class OFRpcTaskImpl extends OFRpcTask<UpdateGroupInput, RpcResult<UpdateGroupOutput>> {
589 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
590 UpdateGroupInput input) {
591 super(taskContext, cookie, input);
595 public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
596 ListenableFuture<RpcResult<UpdateGroupOutput>> result = null;
597 final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(getVersion());
598 data.setDatapathId(getSession().getFeatures().getDatapathId());
600 // Convert the UpdateGroupInput to GroupModInput
601 final java.util.Optional<GroupModInputBuilder> ofGroupModInput =
602 ConvertorManager.getInstance().convert(getInput().getUpdatedGroup(), data);
604 final GroupModInputBuilder groupModInputBuilder = ofGroupModInput
605 .orElse(GroupConvertor.defaultResult(getVersion()))
606 .setXid(getSession().getNextXid());
608 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib =
609 getMessageService().groupMod(groupModInputBuilder.build(), getCookie());
610 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
612 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
613 OFRpcTaskUtil.hookFutureNotification(this, result,
614 getRpcNotificationProviderService(), createGroupUpdatedNotification(getInput()));
620 public Boolean isBarrier() {
621 return getInput().getUpdatedGroup().isBarrier();
625 return new OFRpcTaskImpl(taskContext, cookie, input);
629 * @param input group update input
630 * @return group updated notification composer
632 protected static NotificationComposer<GroupUpdated> createGroupUpdatedNotification(
633 final UpdateGroupInput input) {
634 return new NotificationComposer<GroupUpdated>() {
636 public GroupUpdated compose(TransactionId tXid) {
637 GroupUpdatedBuilder groupMod = new GroupUpdatedBuilder(input.getUpdatedGroup());
638 groupMod.setTransactionId(tXid);
639 groupMod.setGroupRef(input.getGroupRef());
640 return groupMod.build();
646 * @param taskContext task context
647 * @param input update meter input
648 * @param cookie switch connection distinguisher cookie value
649 * @return update meter task
651 public static OFRpcTask<UpdateMeterInput, RpcResult<UpdateMeterOutput>> createUpdateMeterTask(
652 OFRpcTaskContext taskContext, UpdateMeterInput input,
653 SwitchConnectionDistinguisher cookie) {
654 class OFRpcTaskImpl extends OFRpcTask<UpdateMeterInput, RpcResult<UpdateMeterOutput>> {
656 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
657 UpdateMeterInput input) {
658 super(taskContext, cookie, input);
662 public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
663 ListenableFuture<RpcResult<UpdateMeterOutput>> result = null;
665 // Convert the UpdateMeterInput to MeterModInput
666 final java.util.Optional<MeterModInputBuilder> ofMeterModInput = ConvertorManager
668 .convert(getInput().getUpdatedMeter(), new VersionConvertorData(getVersion()));
670 final MeterModInputBuilder meterModInputBuilder = ofMeterModInput
671 .orElse(MeterConvertor.defaultResult(getVersion()))
672 .setXid(getSession().getNextXid());
674 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib =
675 getMessageService().meterMod(meterModInputBuilder.build(), getCookie());
676 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
677 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
678 OFRpcTaskUtil.hookFutureNotification(this, result,
679 getRpcNotificationProviderService(), createMeterUpdatedNotification(getInput()));
684 public Boolean isBarrier() {
685 return getInput().getUpdatedMeter().isBarrier();
689 return new OFRpcTaskImpl(taskContext, cookie, input);
693 * @param input meter update input
694 * @return meter updated notification
696 protected static NotificationComposer<MeterUpdated> createMeterUpdatedNotification(
697 final UpdateMeterInput input) {
698 return new NotificationComposer<MeterUpdated>() {
700 public MeterUpdated compose(TransactionId tXid) {
701 MeterUpdatedBuilder meterMod = new MeterUpdatedBuilder(input.getUpdatedMeter());
702 meterMod.setTransactionId(tXid);
703 meterMod.setMeterRef(input.getMeterRef());
704 return meterMod.build();
711 * @param taskContext task context
712 * @param input update flow input
713 * @param cookie switch connection distinguisher cookie value
714 * @return task remove flow task
716 public static OFRpcTask<RemoveFlowInput, RpcResult<UpdateFlowOutput>> createRemoveFlowTask(
717 OFRpcTaskContext taskContext, RemoveFlowInput input,
718 SwitchConnectionDistinguisher cookie) {
719 class OFRpcTaskImpl extends OFRpcTask<RemoveFlowInput, RpcResult<UpdateFlowOutput>> {
721 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
722 RemoveFlowInput input) {
723 super(taskContext, cookie, input);
727 public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
728 ListenableFuture<RpcResult<UpdateFlowOutput>> result = SettableFuture.create();
730 // Convert the AddFlowInput to FlowModInput
731 List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput(),
732 getVersion(), getSession().getFeatures().getDatapathId());
734 result = chainFlowMods(ofFlowModInputs, 0, getTaskContext(), getCookie());
735 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
737 OFRpcTaskUtil.hookFutureNotification(this, result,
738 getRpcNotificationProviderService(),
739 createFlowRemovedNotification(getInput()));
744 public Boolean isBarrier() {
745 return getInput().isBarrier();
749 return new OFRpcTaskImpl(taskContext, cookie, input);
753 * @param input remove flow input
754 * @return flow removed notification
756 protected static NotificationComposer<FlowRemoved> createFlowRemovedNotification(
757 final RemoveFlowInput input) {
758 return new NotificationComposer<FlowRemoved>() {
760 public FlowRemoved compose(TransactionId tXid) {
761 FlowRemovedBuilder removedFlow = new FlowRemovedBuilder((Flow) input);
762 removedFlow.setTransactionId(tXid);
763 removedFlow.setFlowRef(input.getFlowRef());
764 return removedFlow.build();
771 * @param taskContext task context
772 * @param input remove group input
773 * @param cookie switch connection distinguisher cookie value
774 * @return task remove group task
776 public static OFRpcTask<RemoveGroupInput, RpcResult<UpdateGroupOutput>> createRemoveGroupTask(
777 final OFRpcTaskContext taskContext, RemoveGroupInput input,
778 final SwitchConnectionDistinguisher cookie) {
779 class OFRpcTaskImpl extends OFRpcTask<RemoveGroupInput, RpcResult<UpdateGroupOutput>> {
781 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
782 RemoveGroupInput input) {
783 super(taskContext, cookie, input);
787 public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
788 ListenableFuture<RpcResult<UpdateGroupOutput>> result = SettableFuture.create();
789 final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(getVersion());
790 data.setDatapathId(getSession().getFeatures().getDatapathId());
792 // Convert the AddGroupInput to GroupModInput
793 final java.util.Optional<GroupModInputBuilder> ofGroupModInput =
794 ConvertorManager.getInstance().convert(getInput(), data);
796 final GroupModInputBuilder groupModInputBuilder = ofGroupModInput
797 .orElse(GroupConvertor.defaultResult(getVersion()))
798 .setXid(getSession().getNextXid());
800 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
801 .groupMod(groupModInputBuilder.build(), getCookie());
802 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
803 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
804 OFRpcTaskUtil.hookFutureNotification(this, result,
805 getRpcNotificationProviderService(), createGroupRemovedNotification(getInput()));
811 public Boolean isBarrier() {
812 return getInput().isBarrier();
816 return new OFRpcTaskImpl(taskContext, cookie, input);
820 * @param input group remove input
821 * @return group removed notification
823 protected static NotificationComposer<GroupRemoved> createGroupRemovedNotification(
824 final RemoveGroupInput input) {
825 return new NotificationComposer<GroupRemoved>() {
827 public GroupRemoved compose(TransactionId tXid) {
828 GroupRemovedBuilder removedGroup = new GroupRemovedBuilder((Group) input);
829 removedGroup.setTransactionId(tXid);
830 removedGroup.setGroupRef(input.getGroupRef());
831 return removedGroup.build();
837 * @param taskContext task context
838 * @param input meter removed input
839 * @param cookie switch connection distinguisher cookie value
840 * @return task meter remove task
842 public static OFRpcTask<RemoveMeterInput, RpcResult<UpdateMeterOutput>> createRemoveMeterTask(
843 OFRpcTaskContext taskContext, RemoveMeterInput input,
844 SwitchConnectionDistinguisher cookie) {
846 class OFRpcTaskImpl extends OFRpcTask<RemoveMeterInput, RpcResult<UpdateMeterOutput>> {
848 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
849 RemoveMeterInput input) {
850 super(taskContext, cookie, input);
854 public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
855 ListenableFuture<RpcResult<UpdateMeterOutput>> result = SettableFuture.create();
857 // Convert the RemoveMeterInput to UpdateMeterOutput
858 final java.util.Optional<MeterModInputBuilder> ofMeterModInput = ConvertorManager
860 .convert(getInput(), new VersionConvertorData(getVersion()));
862 final MeterModInputBuilder meterModInputBuilder = ofMeterModInput
863 .orElse(MeterConvertor.defaultResult(getVersion()))
864 .setXid(getSession().getNextXid());
866 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
867 .meterMod(meterModInputBuilder.build(), getCookie());
868 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
869 result = OFRpcTaskUtil.chainFutureBarrier(this, result);
870 OFRpcTaskUtil.hookFutureNotification(this, result,
871 getRpcNotificationProviderService(), createMeterRemovedNotification(getInput()));
877 public Boolean isBarrier() {
878 return getInput().isBarrier();
882 return new OFRpcTaskImpl(taskContext, cookie, input);
887 * @param input remove meter input
888 * @return meter removed notification composer
890 protected static NotificationComposer<MeterRemoved> createMeterRemovedNotification(
891 final RemoveMeterInput input) {
892 return new NotificationComposer<MeterRemoved>() {
894 public MeterRemoved compose(TransactionId tXid) {
895 MeterRemovedBuilder meterRemoved = new MeterRemovedBuilder((Meter) input);
896 meterRemoved.setTransactionId(tXid);
897 meterRemoved.setMeterRef(input.getMeterRef());
898 return meterRemoved.build();
904 * @param taskContext task context
905 * @param input get all statistics input
906 * @param cookie switch connection distinguisher cookie value
907 * @return task get all group statistics task
909 public static OFRpcTask<GetAllGroupStatisticsInput, RpcResult<GetAllGroupStatisticsOutput>> createGetAllGroupStatisticsTask(
910 final OFRpcTaskContext taskContext, GetAllGroupStatisticsInput input,
911 SwitchConnectionDistinguisher cookie) {
913 class OFRpcTaskImpl extends OFRpcTask<GetAllGroupStatisticsInput, RpcResult<GetAllGroupStatisticsOutput>> {
915 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
916 GetAllGroupStatisticsInput input) {
917 super(taskContext, cookie, input);
921 public ListenableFuture<RpcResult<GetAllGroupStatisticsOutput>> call() {
922 final SettableFuture<RpcResult<GetAllGroupStatisticsOutput>> result = SettableFuture.create();
924 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
925 RpcResult<GetAllGroupStatisticsOutput> rpcResult = RpcResultBuilder.success(
926 new GetAllGroupStatisticsOutputBuilder().build()).build();
928 return Futures.immediateFuture(rpcResult);
931 // Generate xid to associate it with the request
932 final Long xid = taskContext.getSession().getNextXid();
934 // Create multipart request body for fetch all the group stats
935 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
936 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
937 mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(
938 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731
939 .Group.OFPGALL.getIntValue())));
940 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
942 // Create multipart request header
943 MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPGROUP,
946 // Set request body to main multipart request
947 mprInput.setMultipartRequestBody(caseBuilder.build());
949 // Send the request, no cookies associated, use any connection
951 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
952 .multipartRequest(mprInput.build(), getCookie());
953 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
955 Futures.addCallback(resultLib, new ResultCallback<GetAllGroupStatisticsOutput>(result) {
957 public GetAllGroupStatisticsOutput createResult() {
958 GetAllGroupStatisticsOutputBuilder groupStatBuilder = new GetAllGroupStatisticsOutputBuilder()
959 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
960 return groupStatBuilder.build();
969 return new OFRpcTaskImpl(taskContext, cookie, input);
973 * @param taskContext task context
974 * @param input get group description input
975 * @param cookie switch connection distinguisher cookie value
976 * @return task get group description task
978 public static OFRpcTask<GetGroupDescriptionInput, RpcResult<GetGroupDescriptionOutput>> createGetGroupDescriptionTask(
979 final OFRpcTaskContext taskContext, GetGroupDescriptionInput input,
980 SwitchConnectionDistinguisher cookie) {
981 class OFRpcTaskImpl extends OFRpcTask<GetGroupDescriptionInput, RpcResult<GetGroupDescriptionOutput>> {
983 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
984 GetGroupDescriptionInput input) {
985 super(taskContext, cookie, input);
989 public ListenableFuture<RpcResult<GetGroupDescriptionOutput>> call()
991 final SettableFuture<RpcResult<GetGroupDescriptionOutput>> result = SettableFuture.create();
993 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
994 RpcResult<GetGroupDescriptionOutput> rpcResult = RpcResultBuilder.success(
995 new GetGroupDescriptionOutputBuilder().build()).build();
996 return Futures.immediateFuture(rpcResult);
998 final Long xid = taskContext.getSession().getNextXid();
1000 MultipartRequestGroupDescCaseBuilder mprGroupDescCaseBuild =
1001 new MultipartRequestGroupDescCaseBuilder();
1002 MultipartRequestInputBuilder mprInput =
1003 createMultipartHeader(MultipartType.OFPMPGROUPDESC, taskContext, xid);
1004 mprInput.setMultipartRequestBody(mprGroupDescCaseBuild.build());
1005 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1006 .multipartRequest(mprInput.build(), getCookie());
1007 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1009 Futures.addCallback(resultLib, new ResultCallback<GetGroupDescriptionOutput>(result) {
1011 public GetGroupDescriptionOutput createResult() {
1012 GetGroupDescriptionOutputBuilder groupStatBuilder = new GetGroupDescriptionOutputBuilder()
1013 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1014 return groupStatBuilder.build();
1022 return new OFRpcTaskImpl(taskContext, cookie, input);
1026 * @param taskContext task context
1027 * @param input get group feature input
1028 * @param cookie switch connection distinguisher cookie value
1029 * @return task get group feature task
1031 public static OFRpcTask<GetGroupFeaturesInput, RpcResult<GetGroupFeaturesOutput>> createGetGroupFeaturesTask(
1032 final OFRpcTaskContext taskContext, GetGroupFeaturesInput input,
1033 SwitchConnectionDistinguisher cookie) {
1034 class OFRpcTaskImpl extends OFRpcTask<GetGroupFeaturesInput, RpcResult<GetGroupFeaturesOutput>> {
1036 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1037 GetGroupFeaturesInput input) {
1038 super(taskContext, cookie, input);
1039 // TODO Auto-generated constructor stub
1043 public ListenableFuture<RpcResult<GetGroupFeaturesOutput>> call()
1045 final SettableFuture<RpcResult<GetGroupFeaturesOutput>> result = SettableFuture.create();
1047 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1048 RpcResult<GetGroupFeaturesOutput> rpcResult = RpcResultBuilder.success(
1049 new GetGroupFeaturesOutputBuilder().build()).build();
1050 return Futures.immediateFuture(rpcResult);
1052 final Long xid = taskContext.getSession().getNextXid();
1054 MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild =
1055 new MultipartRequestGroupFeaturesCaseBuilder();
1056 MultipartRequestInputBuilder mprInput =
1057 createMultipartHeader(MultipartType.OFPMPGROUPFEATURES, taskContext, xid);
1058 mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
1059 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1060 .multipartRequest(mprInput.build(), getCookie());
1061 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1063 Futures.addCallback(resultLib, new ResultCallback<GetGroupFeaturesOutput>(result) {
1065 public GetGroupFeaturesOutput createResult() {
1066 GetGroupFeaturesOutputBuilder groupFeatureBuilder = new GetGroupFeaturesOutputBuilder()
1067 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1068 return groupFeatureBuilder.build();
1076 return new OFRpcTaskImpl(taskContext, cookie, input);
1080 * @param taskContext task context
1081 * @param input get group statistics input
1082 * @param cookie switch connection distinguisher cookie value
1083 * @return task get group statistics task
1085 public static OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>> createGetGroupStatisticsTask(
1086 final OFRpcTaskContext taskContext, final GetGroupStatisticsInput input,
1087 SwitchConnectionDistinguisher cookie) {
1089 class OFRpcTaskImpl extends OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>> {
1091 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1092 GetGroupStatisticsInput input) {
1093 super(taskContext, cookie, input);
1097 public ListenableFuture<RpcResult<GetGroupStatisticsOutput>> call()
1099 final SettableFuture<RpcResult<GetGroupStatisticsOutput>> result = SettableFuture.create();
1101 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1102 RpcResult<GetGroupStatisticsOutput> rpcResult = RpcResultBuilder.success(
1103 new GetGroupStatisticsOutputBuilder().build()).build();
1104 return Futures.immediateFuture(rpcResult);
1106 final Long xid = taskContext.getSession().getNextXid();
1108 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
1109 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
1110 mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
1111 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
1113 MultipartRequestInputBuilder mprInput =
1114 createMultipartHeader(MultipartType.OFPMPGROUP, taskContext, xid);
1115 mprInput.setMultipartRequestBody(caseBuilder.build());
1116 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1117 .multipartRequest(mprInput.build(), getCookie());
1118 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1120 Futures.addCallback(resultLib, new ResultCallback<GetGroupStatisticsOutput>(result) {
1122 public GetGroupStatisticsOutput createResult() {
1123 GetGroupStatisticsOutputBuilder groupStatisticsBuilder =
1124 new GetGroupStatisticsOutputBuilder()
1125 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1126 return groupStatisticsBuilder.build();
1134 return new OFRpcTaskImpl(taskContext, cookie, input);
1138 * @param taskContext task context
1139 * @param input get meter config statistics input
1140 * @param cookie switch connection distinguisher cookie value
1141 * @return task get all mtere config statistics task
1143 public static OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>> createGetAllMeterConfigStatisticsTask(
1144 final OFRpcTaskContext taskContext, final GetAllMeterConfigStatisticsInput input,
1145 SwitchConnectionDistinguisher cookie) {
1146 class OFRpcTaskImpl extends OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>> {
1148 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1149 GetAllMeterConfigStatisticsInput input) {
1150 super(taskContext, cookie, input);
1154 public ListenableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> call()
1156 final SettableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> result = SettableFuture.create();
1158 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1159 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = RpcResultBuilder.success(
1160 new GetAllMeterConfigStatisticsOutputBuilder().build()).build();
1161 return Futures.immediateFuture(rpcResult);
1163 final Long xid = taskContext.getSession().getNextXid();
1165 MultipartRequestMeterConfigCaseBuilder caseBuilder =
1166 new MultipartRequestMeterConfigCaseBuilder();
1167 MultipartRequestMeterConfigBuilder mprMeterConfigBuild =
1168 new MultipartRequestMeterConfigBuilder();
1169 mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(
1170 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common
1171 .types.rev130731.Meter.OFPMALL.getIntValue())));
1172 caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
1174 MultipartRequestInputBuilder mprInput =
1175 createMultipartHeader(MultipartType.OFPMPMETERCONFIG, taskContext, xid);
1176 mprInput.setMultipartRequestBody(caseBuilder.build());
1177 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1178 .multipartRequest(mprInput.build(), getCookie());
1179 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1181 Futures.addCallback(resultLib, new ResultCallback<GetAllMeterConfigStatisticsOutput>(result) {
1183 public GetAllMeterConfigStatisticsOutput createResult() {
1184 GetAllMeterConfigStatisticsOutputBuilder allMeterConfStatBuilder =
1185 new GetAllMeterConfigStatisticsOutputBuilder()
1186 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1187 return allMeterConfStatBuilder.build();
1195 return new OFRpcTaskImpl(taskContext, cookie, input);
1199 * @param taskContext task context
1200 * @param input get all meter statistics input
1201 * @param cookie switch connection distinguisher cookie value
1202 * @return task get all meter statistics task
1204 public static OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>> createGetAllMeterStatisticsTask(
1205 final OFRpcTaskContext taskContext, final GetAllMeterStatisticsInput input,
1206 SwitchConnectionDistinguisher cookie) {
1207 class OFRpcTaskImpl extends OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>> {
1209 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1210 GetAllMeterStatisticsInput input) {
1211 super(taskContext, cookie, input);
1212 // TODO Auto-generated constructor stub
1216 public ListenableFuture<RpcResult<GetAllMeterStatisticsOutput>> call()
1218 final SettableFuture<RpcResult<GetAllMeterStatisticsOutput>> result = SettableFuture.create();
1220 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1221 RpcResult<GetAllMeterStatisticsOutput> rpcResult = RpcResultBuilder.success(
1222 new GetAllMeterStatisticsOutputBuilder().build()).build();
1223 return Futures.immediateFuture(rpcResult);
1225 final Long xid = taskContext.getSession().getNextXid();
1227 MultipartRequestMeterCaseBuilder caseBuilder =
1228 new MultipartRequestMeterCaseBuilder();
1229 MultipartRequestMeterBuilder mprMeterBuild =
1230 new MultipartRequestMeterBuilder();
1231 mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(
1232 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common
1233 .types.rev130731.Meter.OFPMALL.getIntValue())));
1234 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
1236 MultipartRequestInputBuilder mprInput =
1237 createMultipartHeader(MultipartType.OFPMPMETER, taskContext, xid);
1238 mprInput.setMultipartRequestBody(caseBuilder.build());
1239 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1240 .multipartRequest(mprInput.build(), getCookie());
1241 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1243 Futures.addCallback(resultLib, new ResultCallback<GetAllMeterStatisticsOutput>(result) {
1245 public GetAllMeterStatisticsOutput createResult() {
1246 GetAllMeterStatisticsOutputBuilder allMeterStatBuilder =
1247 new GetAllMeterStatisticsOutputBuilder()
1248 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1249 return allMeterStatBuilder.build();
1257 return new OFRpcTaskImpl(taskContext, cookie, input);
1261 * @param taskContext task context
1262 * @param input get meter features input
1263 * @param cookie switch connection distinguisher cookie value
1264 * @return task get meter feature task
1266 public static OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>> createGetMeterFeaturesTask(
1267 final OFRpcTaskContext taskContext, final GetMeterFeaturesInput input,
1268 SwitchConnectionDistinguisher cookie) {
1270 class OFRpcTaskImpl extends OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>> {
1272 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1273 GetMeterFeaturesInput input) {
1274 super(taskContext, cookie, input);
1278 public ListenableFuture<RpcResult<GetMeterFeaturesOutput>> call()
1280 final SettableFuture<RpcResult<GetMeterFeaturesOutput>> result = SettableFuture.create();
1282 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1283 RpcResult<GetMeterFeaturesOutput> rpcResult = RpcResultBuilder.success(
1284 new GetMeterFeaturesOutputBuilder().build()).build();
1285 return Futures.immediateFuture(rpcResult);
1287 final Long xid = taskContext.getSession().getNextXid();
1289 MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild =
1290 new MultipartRequestMeterFeaturesCaseBuilder();
1292 MultipartRequestInputBuilder mprInput =
1293 createMultipartHeader(MultipartType.OFPMPMETERFEATURES, taskContext, xid);
1294 mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
1295 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1296 .multipartRequest(mprInput.build(), getCookie());
1297 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1299 Futures.addCallback(resultLib, new ResultCallback<GetMeterFeaturesOutput>(result) {
1301 public GetMeterFeaturesOutput createResult() {
1302 GetMeterFeaturesOutputBuilder meterFeaturesBuilder =
1303 new GetMeterFeaturesOutputBuilder()
1304 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1305 return meterFeaturesBuilder.build();
1313 return new OFRpcTaskImpl(taskContext, cookie, input);
1317 * @param taskContext task context
1318 * @param input get meter statistics input
1319 * @param cookie switch connection distinguisher cookie value
1320 * @return task get meter statistics task
1322 public static OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>> createGetMeterStatisticsTask(
1323 final OFRpcTaskContext taskContext, final GetMeterStatisticsInput input,
1324 SwitchConnectionDistinguisher cookie) {
1326 class OFRpcTaskImpl extends OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>> {
1328 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1329 GetMeterStatisticsInput input) {
1330 super(taskContext, cookie, input);
1334 public ListenableFuture<RpcResult<GetMeterStatisticsOutput>> call()
1336 final SettableFuture<RpcResult<GetMeterStatisticsOutput>> result = SettableFuture.create();
1338 if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
1339 RpcResult<GetMeterStatisticsOutput> rpcResult = RpcResultBuilder.success(
1340 new GetMeterStatisticsOutputBuilder().build()).build();
1341 return Futures.immediateFuture(rpcResult);
1343 final Long xid = taskContext.getSession().getNextXid();
1345 MultipartRequestMeterCaseBuilder caseBuilder =
1346 new MultipartRequestMeterCaseBuilder();
1347 MultipartRequestMeterBuilder mprMeterBuild =
1348 new MultipartRequestMeterBuilder();
1349 mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
1350 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
1352 MultipartRequestInputBuilder mprInput =
1353 createMultipartHeader(MultipartType.OFPMPMETER, taskContext, xid);
1354 mprInput.setMultipartRequestBody(caseBuilder.build());
1355 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1356 .multipartRequest(mprInput.build(), getCookie());
1357 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1359 Futures.addCallback(resultLib, new ResultCallback<GetMeterStatisticsOutput>(result) {
1361 public GetMeterStatisticsOutput createResult() {
1362 GetMeterStatisticsOutputBuilder meterStatBuilder =
1363 new GetMeterStatisticsOutputBuilder()
1364 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1365 return meterStatBuilder.build();
1373 return new OFRpcTaskImpl(taskContext, cookie, input);
1377 * @param taskContext task context
1378 * @param input get all node connector statistics input
1379 * @param cookie switch connection distinguisher cookie value
1380 * @return task get all node connector statistics task
1382 public static OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>>
1383 createGetAllNodeConnectorsStatisticsTask(
1384 final OFRpcTaskContext taskContext, final GetAllNodeConnectorsStatisticsInput input,
1385 SwitchConnectionDistinguisher cookie) {
1386 class OFRpcTaskImpl extends OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>> {
1388 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1389 GetAllNodeConnectorsStatisticsInput input) {
1390 super(taskContext, cookie, input);
1394 public ListenableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> call()
1396 final SettableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> result = SettableFuture.create();
1398 final Long xid = taskContext.getSession().getNextXid();
1400 MultipartRequestPortStatsCaseBuilder caseBuilder =
1401 new MultipartRequestPortStatsCaseBuilder();
1402 MultipartRequestPortStatsBuilder mprPortStatsBuilder =
1403 new MultipartRequestPortStatsBuilder();
1405 mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
1406 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1408 MultipartRequestInputBuilder mprInput =
1409 createMultipartHeader(MultipartType.OFPMPPORTSTATS, taskContext, xid);
1410 mprInput.setMultipartRequestBody(caseBuilder.build());
1411 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1412 .multipartRequest(mprInput.build(), getCookie());
1413 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1415 Futures.addCallback(resultLib, new ResultCallback<GetAllNodeConnectorsStatisticsOutput>(result) {
1417 public GetAllNodeConnectorsStatisticsOutput createResult() {
1418 GetAllNodeConnectorsStatisticsOutputBuilder allNodeConnectorStatBuilder =
1419 new GetAllNodeConnectorsStatisticsOutputBuilder()
1420 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1421 return allNodeConnectorStatBuilder.build();
1428 return new OFRpcTaskImpl(taskContext, cookie, input);
1432 * @param taskContext task context
1433 * @param input get node connector statistics input
1434 * @param cookie switch connection distinguisher cookie value
1435 * @return task get node connector statistics task
1437 public static OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>>
1438 createGetNodeConnectorStatisticsTask(
1439 final OFRpcTaskContext taskContext, final GetNodeConnectorStatisticsInput input,
1440 SwitchConnectionDistinguisher cookie) {
1441 class OFRpcTaskImpl extends OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>> {
1443 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1444 GetNodeConnectorStatisticsInput input) {
1445 super(taskContext, cookie, input);
1449 public ListenableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> call()
1451 final SettableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> result = SettableFuture.create();
1453 final Long xid = taskContext.getSession().getNextXid();
1455 MultipartRequestPortStatsCaseBuilder caseBuilder =
1456 new MultipartRequestPortStatsCaseBuilder();
1457 MultipartRequestPortStatsBuilder mprPortStatsBuilder =
1458 new MultipartRequestPortStatsBuilder();
1459 // Set specific port
1461 .setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
1462 OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
1463 input.getNodeConnectorId()));
1464 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1466 MultipartRequestInputBuilder mprInput =
1467 createMultipartHeader(MultipartType.OFPMPPORTSTATS, taskContext, xid);
1468 mprInput.setMultipartRequestBody(caseBuilder.build());
1469 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1470 .multipartRequest(mprInput.build(), getCookie());
1471 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1473 Futures.addCallback(resultLib, new ResultCallback<GetNodeConnectorStatisticsOutput>(result) {
1475 public GetNodeConnectorStatisticsOutput createResult() {
1476 GetNodeConnectorStatisticsOutputBuilder allNodeConnectorStatBuilder =
1477 new GetNodeConnectorStatisticsOutputBuilder()
1478 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1479 return allNodeConnectorStatBuilder.build();
1486 return new OFRpcTaskImpl(taskContext, cookie, input);
1490 * @param taskContext task context
1491 * @param input get all flow statistics from flow table
1492 * @param cookie switch connection distinguisher cookie value
1493 * @return task get all flow statistics from flow table task
1495 public static OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>>
1496 createGetAllFlowStatisticsFromFlowTableTask(
1497 final OFRpcTaskContext taskContext,
1498 final GetAllFlowStatisticsFromFlowTableInput input,
1499 SwitchConnectionDistinguisher cookie) {
1500 class OFRpcTaskImpl extends OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> {
1502 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1503 GetAllFlowStatisticsFromFlowTableInput input) {
1504 super(taskContext, cookie, input);
1508 public ListenableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> call() throws Exception {
1509 final SettableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> result = SettableFuture.create();
1511 final Long xid = taskContext.getSession().getNextXid();
1513 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1514 mprFlowRequestBuilder.setTableId(input.getTableId().getValue());
1515 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1516 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1517 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1518 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1519 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1520 .getPrimaryConductor().getVersion(), mprFlowRequestBuilder);
1522 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1523 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1525 MultipartRequestInputBuilder mprInput =
1526 createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid);
1527 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1528 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1529 .multipartRequest(mprInput.build(), getCookie());
1530 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1532 Futures.addCallback(resultLib, new ResultCallback<GetAllFlowStatisticsFromFlowTableOutput>(result) {
1534 public GetAllFlowStatisticsFromFlowTableOutput createResult() {
1535 GetAllFlowStatisticsFromFlowTableOutputBuilder allFlowStatsFromFlowTableBuilder =
1536 new GetAllFlowStatisticsFromFlowTableOutputBuilder()
1537 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1538 return allFlowStatsFromFlowTableBuilder.build();
1545 return new OFRpcTaskImpl(taskContext, cookie, input);
1549 * @param taskContext task context
1550 * @param input get all flow statistics from all flow table
1551 * @param cookie switch connection distinguisher cookie value
1552 * @return task get all flow statistics from all flow table task
1554 public static OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput, RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>>
1555 createGetAllFlowsStatisticsFromAllFlowTablesTask(
1556 final OFRpcTaskContext taskContext,
1557 final GetAllFlowsStatisticsFromAllFlowTablesInput input,
1558 SwitchConnectionDistinguisher cookie) {
1559 class OFRpcTaskImpl extends OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput,
1560 RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> {
1562 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1563 GetAllFlowsStatisticsFromAllFlowTablesInput input) {
1564 super(taskContext, cookie, input);
1568 public ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> call() throws Exception {
1569 final SettableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> result = SettableFuture.create();
1571 final Long xid = taskContext.getSession().getNextXid();
1573 // Create multipart request body for fetch all the group stats
1574 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder =
1575 new MultipartRequestFlowCaseBuilder();
1576 MultipartRequestFlowBuilder mprFlowRequestBuilder =
1577 new MultipartRequestFlowBuilder();
1578 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
1579 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1580 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1581 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1582 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1583 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1584 .getPrimaryConductor().getVersion(), mprFlowRequestBuilder);
1586 MultipartRequestInputBuilder mprInput =
1587 createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid);
1588 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1589 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1590 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1591 .multipartRequest(mprInput.build(), getCookie());
1592 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1594 Futures.addCallback(resultLib, new ResultCallback<GetAllFlowsStatisticsFromAllFlowTablesOutput>(result) {
1596 public GetAllFlowsStatisticsFromAllFlowTablesOutput createResult() {
1597 GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder allFlowStatsFromAllFlowTableBuilder =
1598 new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder()
1599 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1600 return allFlowStatsFromAllFlowTableBuilder.build();
1607 return new OFRpcTaskImpl(taskContext, cookie, input);
1611 * @param taskContext task context
1612 * @param input get flow statistics from flow table
1613 * @param cookie switch connection distinguisher cookie value
1614 * @return task get flow statistics from flow table task
1616 public static OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>>
1617 createGetFlowStatisticsFromFlowTableTask(
1618 final OFRpcTaskContext taskContext,
1619 final GetFlowStatisticsFromFlowTableInput input, SwitchConnectionDistinguisher cookie) {
1621 class OFRpcTaskImpl extends OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>> {
1623 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1624 GetFlowStatisticsFromFlowTableInput input) {
1625 super(taskContext, cookie, input);
1629 public ListenableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> call() throws Exception {
1630 final SettableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> result = SettableFuture.create();
1632 final Long xid = taskContext.getSession().getNextXid();
1634 // Create multipart request body for fetch all the group stats
1635 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1636 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1637 mprFlowRequestBuilder.setTableId(input.getTableId());
1639 if (input.getOutPort() != null) {
1640 mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue());
1642 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1645 if (input.getOutGroup() != null) {
1646 mprFlowRequestBuilder.setOutGroup(input.getOutGroup());
1648 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1651 if (input.getCookie() != null) {
1652 mprFlowRequestBuilder.setCookie(input.getCookie().getValue());
1654 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1657 if (input.getCookieMask() != null) {
1658 mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue());
1660 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1663 // convert and inject match
1664 MatchReactor.getInstance().convert(input.getMatch(), taskContext.getSession()
1665 .getPrimaryConductor().getVersion(), mprFlowRequestBuilder);
1667 // Set request body to main multipart request
1668 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1669 MultipartRequestInputBuilder mprInput =
1670 createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid);
1671 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1672 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1673 .multipartRequest(mprInput.build(), getCookie());
1674 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1676 Futures.addCallback(resultLib, new ResultCallback<GetFlowStatisticsFromFlowTableOutput>(result) {
1678 public GetFlowStatisticsFromFlowTableOutput createResult() {
1679 GetFlowStatisticsFromFlowTableOutputBuilder flowStatsFromFlowTableBuilder =
1680 new GetFlowStatisticsFromFlowTableOutputBuilder()
1681 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1682 return flowStatsFromFlowTableBuilder.build();
1689 return new OFRpcTaskImpl(taskContext, cookie, input);
1693 * @param taskContext task context
1694 * @param input get aggregate flow statistics from flow table for all flow input
1695 * @param cookie switch connection distinguisher cookie value
1696 * @return task get aggregate flow stats from flow table for all flow task
1698 public static OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>>
1699 createGetAggregateFlowStatisticsFromFlowTableForAllFlowsTask(
1700 final OFRpcTaskContext taskContext,
1701 final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input, SwitchConnectionDistinguisher cookie) {
1702 class OFRpcTaskImpl extends OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> {
1704 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1705 GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
1706 super(taskContext, cookie, input);
1710 public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> call() throws Exception {
1711 final SettableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> result = SettableFuture.create();
1713 final Long xid = taskContext.getSession().getNextXid();
1715 // Create multipart request body for fetch all the group stats
1716 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1717 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1718 mprAggregateRequestBuilder.setTableId(input.getTableId().getValue());
1719 mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1720 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1721 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1722 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1724 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1725 .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder);
1727 // Set request body to main multipart request
1728 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1729 MultipartRequestInputBuilder mprInput =
1730 createMultipartHeader(MultipartType.OFPMPAGGREGATE, taskContext, xid);
1731 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1732 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1733 .multipartRequest(mprInput.build(), getCookie());
1734 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1736 Futures.addCallback(resultLib, new ResultCallback<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>(result) {
1738 public GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput createResult() {
1739 GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder flowStatsFromFlowTableBuilder =
1740 new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder()
1741 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1742 return flowStatsFromFlowTableBuilder.build();
1749 return new OFRpcTaskImpl(taskContext, cookie, input);
1753 * @param taskContext task context
1754 * @param input aggregate flow statistics input
1755 * @param cookie switch connection distinguisher cookie value
1756 * @return task task to fetch the statistics
1758 public static OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>
1759 createGetAggregateFlowStatisticsFromFlowTableForGivenMatchTask(
1760 final OFRpcTaskContext taskContext,
1761 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input, SwitchConnectionDistinguisher cookie) {
1762 class OFRpcTaskImpl extends OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> {
1764 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1765 GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
1766 super(taskContext, cookie, input);
1770 public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> call() throws Exception {
1771 final SettableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> result = SettableFuture.create();
1773 final Long xid = taskContext.getSession().getNextXid();
1775 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1776 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1777 mprAggregateRequestBuilder.setTableId(input.getTableId());
1778 mprAggregateRequestBuilder.setOutPort(input.getOutPort().longValue());
1779 // TODO: repeating code
1780 if (taskContext.getSession().getPrimaryConductor().getVersion() ==
1781 OFConstants.OFP_VERSION_1_3) {
1782 mprAggregateRequestBuilder.setCookie(input.getCookie().getValue());
1783 mprAggregateRequestBuilder.setCookieMask(input.getCookieMask().getValue());
1784 mprAggregateRequestBuilder.setOutGroup(input.getOutGroup());
1786 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1787 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1788 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1791 MatchReactor.getInstance().convert(input.getMatch(), taskContext.getSession()
1792 .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder);
1794 FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
1795 .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder);
1797 // Set request body to main multipart request
1798 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1799 MultipartRequestInputBuilder mprInput =
1800 createMultipartHeader(MultipartType.OFPMPAGGREGATE, taskContext, xid);
1801 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1802 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1803 .multipartRequest(mprInput.build(), getCookie());
1804 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1806 Futures.addCallback(resultLib, new ResultCallback<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>(result) {
1808 public GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput createResult() {
1809 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder aggregFlowStatsFromFlowTableBuilder =
1810 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder()
1811 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1812 return aggregFlowStatsFromFlowTableBuilder.build();
1819 return new OFRpcTaskImpl(taskContext, cookie, input);
1823 * @param taskContext task context
1824 * @param input flow table statistics input
1825 * @param cookie switch connection distinguisher cookie value
1826 * @return task task to fetch table statistics
1828 public static OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>> createGetFlowTablesStatisticsTask(
1829 final OFRpcTaskContext taskContext, final GetFlowTablesStatisticsInput input, SwitchConnectionDistinguisher cookie) {
1831 class OFRpcTaskImpl extends OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>> {
1833 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1834 GetFlowTablesStatisticsInput input) {
1835 super(taskContext, cookie, input);
1839 public ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>> call() throws Exception {
1840 final SettableFuture<RpcResult<GetFlowTablesStatisticsOutput>> result = SettableFuture.create();
1842 final Long xid = taskContext.getSession().getNextXid();
1844 // Create multipart request body for fetch all the group stats
1845 MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
1846 MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
1847 multipartRequestTableBuilder.setEmpty(true);
1848 multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
1850 // Set request body to main multipart request
1851 MultipartRequestInputBuilder mprInput =
1852 createMultipartHeader(MultipartType.OFPMPTABLE, taskContext, xid);
1853 mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
1854 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1855 .multipartRequest(mprInput.build(), getCookie());
1856 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1858 Futures.addCallback(resultLib, new ResultCallback<GetFlowTablesStatisticsOutput>(result) {
1860 public GetFlowTablesStatisticsOutput createResult() {
1861 GetFlowTablesStatisticsOutputBuilder flowTableStatsBuilder =
1862 new GetFlowTablesStatisticsOutputBuilder()
1863 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1864 return flowTableStatsBuilder.build();
1871 return new OFRpcTaskImpl(taskContext, cookie, input);
1875 * @param taskContext task context
1876 * @param input queue statistics input
1877 * @param cookie switch connection distinguisher cookie value
1878 * @return task task to fetch all queue statistics
1880 public static OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> createGetAllQueuesStatisticsFromAllPortsTask(
1881 final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromAllPortsInput input, SwitchConnectionDistinguisher cookie) {
1883 class OFRpcTaskImpl extends OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> {
1885 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1886 GetAllQueuesStatisticsFromAllPortsInput input) {
1887 super(taskContext, cookie, input);
1891 public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> call() throws Exception {
1892 final SettableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> result = SettableFuture.create();
1894 final Long xid = taskContext.getSession().getNextXid();
1896 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1897 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1899 mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
1900 // Select all the queues
1901 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
1902 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1904 // Set request body to main multipart request
1905 MultipartRequestInputBuilder mprInput =
1906 createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid);
1907 mprInput.setMultipartRequestBody(caseBuilder.build());
1908 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1909 .multipartRequest(mprInput.build(), getCookie());
1910 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1912 Futures.addCallback(resultLib, new ResultCallback<GetAllQueuesStatisticsFromAllPortsOutput>(result) {
1914 public GetAllQueuesStatisticsFromAllPortsOutput createResult() {
1915 GetAllQueuesStatisticsFromAllPortsOutputBuilder allQueueStatsBuilder =
1916 new GetAllQueuesStatisticsFromAllPortsOutputBuilder()
1917 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1918 return allQueueStatsBuilder.build();
1925 return new OFRpcTaskImpl(taskContext, cookie, input);
1929 * @param taskContext task context
1930 * @param input queue statist from specific port input
1931 * @param cookie switch connection distinguisher cookie value
1932 * @return task task to get queue statistics from specific port
1934 public static OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> createGetAllQueuesStatisticsFromGivenPortTask(
1935 final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromGivenPortInput input, SwitchConnectionDistinguisher cookie) {
1937 class OFRpcTaskImpl extends OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> {
1939 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1940 GetAllQueuesStatisticsFromGivenPortInput input) {
1941 super(taskContext, cookie, input);
1945 public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> call() throws Exception {
1946 final SettableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> result = SettableFuture.create();
1948 final Long xid = taskContext.getSession().getNextXid();
1950 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1951 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1952 // Select all queues
1953 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
1954 // Select specific port
1955 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
1956 OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
1957 input.getNodeConnectorId()));
1958 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1960 // Set request body to main multipart request
1961 MultipartRequestInputBuilder mprInput =
1962 createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid);
1963 mprInput.setMultipartRequestBody(caseBuilder.build());
1964 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
1965 .multipartRequest(mprInput.build(), getCookie());
1966 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
1968 Futures.addCallback(resultLib, new ResultCallback<GetAllQueuesStatisticsFromGivenPortOutput>(result) {
1970 public GetAllQueuesStatisticsFromGivenPortOutput createResult() {
1971 GetAllQueuesStatisticsFromGivenPortOutputBuilder allQueueStatsBuilder =
1972 new GetAllQueuesStatisticsFromGivenPortOutputBuilder()
1973 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
1974 return allQueueStatsBuilder.build();
1981 return new OFRpcTaskImpl(taskContext, cookie, input);
1985 * @param taskContext task context
1986 * @param input queue statistics from given port
1987 * @param cookie switch connection distinguisher cookie value
1988 * @return task task to get queue statistics from given port
1990 public static OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>> createGetQueueStatisticsFromGivenPortTask(
1991 final OFRpcTaskContext taskContext, final GetQueueStatisticsFromGivenPortInput input, SwitchConnectionDistinguisher cookie) {
1993 class OFRpcTaskImpl extends OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>> {
1995 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
1996 GetQueueStatisticsFromGivenPortInput input) {
1997 super(taskContext, cookie, input);
2001 public ListenableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> call() throws Exception {
2002 final SettableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> result = SettableFuture.create();
2004 final Long xid = taskContext.getSession().getNextXid();
2006 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
2007 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
2008 // Select specific queue
2009 mprQueueBuilder.setQueueId(input.getQueueId().getValue());
2010 // Select specific port
2011 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
2012 OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
2013 input.getNodeConnectorId()));
2014 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
2016 // Set request body to main multipart request
2017 MultipartRequestInputBuilder mprInput =
2018 createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid);
2019 mprInput.setMultipartRequestBody(caseBuilder.build());
2020 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
2021 .multipartRequest(mprInput.build(), getCookie());
2022 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
2024 Futures.addCallback(resultLib, new ResultCallback<GetQueueStatisticsFromGivenPortOutput>(result) {
2026 public GetQueueStatisticsFromGivenPortOutput createResult() {
2027 GetQueueStatisticsFromGivenPortOutputBuilder queueStatsFromPortBuilder =
2028 new GetQueueStatisticsFromGivenPortOutputBuilder()
2029 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
2030 return queueStatsFromPortBuilder.build();
2037 return new OFRpcTaskImpl(taskContext, cookie, input);
2040 static MultipartRequestInputBuilder createMultipartHeader(MultipartType multipart,
2041 OFRpcTaskContext taskContext, Long xid) {
2042 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
2043 mprInput.setType(multipart);
2044 mprInput.setVersion(taskContext.getSession().getPrimaryConductor().getVersion());
2045 mprInput.setXid(xid);
2046 mprInput.setFlags(new MultipartRequestFlags(false));
2050 private abstract static class ResultCallback<T> implements FutureCallback<RpcResult<Void>> {
2052 private SettableFuture<RpcResult<T>> result;
2055 * @param result result
2057 public ResultCallback(SettableFuture<RpcResult<T>> result) {
2058 this.result = result;
2061 public abstract T createResult();
2064 public void onSuccess(RpcResult<Void> resultArg) {
2065 result.set(RpcResultBuilder.success(createResult()).build());
2069 public void onFailure(Throwable t) {
2070 result.set(RpcResultBuilder.<T>failed().withWarning(
2072 OFConstants.ERROR_TAG_TIMEOUT,
2073 "something wrong happened",
2074 OFConstants.APPLICATION_TAG,
2080 * @param taskContext task context
2081 * @param input update port input
2082 * @param cookie switch connection distinguisher cookie value
2083 * @return task task to update port
2085 public static OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>> createUpdatePortTask(
2086 final OFRpcTaskContext taskContext, final UpdatePortInput input,
2087 final SwitchConnectionDistinguisher cookie) {
2089 class OFRpcTaskImpl extends OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>> {
2091 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
2092 UpdatePortInput input) {
2093 super(taskContext, cookie, input);
2097 public ListenableFuture<RpcResult<UpdatePortOutput>> call() {
2098 ListenableFuture<RpcResult<UpdatePortOutput>> result = SettableFuture.create();
2099 final short version = taskContext.getSession().getPrimaryConductor().getVersion();
2100 final Port inputPort = input.getUpdatedPort().getPort().getPort().get(0);
2102 final java.util.Optional<PortModInput> ofPortModInput = ConvertorManager
2104 .convert(inputPort, new VersionConvertorData(version));
2106 PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput
2107 .orElse(PortConvertor.defaultResult(version)))
2108 .setXid(taskContext.getSession().getNextXid());
2110 Future<RpcResult<UpdatePortOutput>> resultFromOFLib = getMessageService()
2111 .portMod(mdInput.build(), cookie);
2112 result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
2118 return new OFRpcTaskImpl(taskContext, cookie, input);
2122 * @param taskContext task context
2123 * @param input update table input
2124 * @param cookie switch connection distinguisher cookie value
2125 * @return task task to udpate table input
2127 public static OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>> createUpdateTableTask(
2128 final OFRpcTaskContext taskContext, final UpdateTableInput input,
2129 final SwitchConnectionDistinguisher cookie) {
2131 class OFRpcTaskImpl extends OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>> {
2133 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
2134 UpdateTableInput input) {
2135 super(taskContext, cookie, input);
2139 public ListenableFuture<RpcResult<UpdateTableOutput>> call() {
2140 final SettableFuture<RpcResult<UpdateTableOutput>> result = SettableFuture.create();
2142 final Long xid = taskContext.getSession().getNextXid();
2144 MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder();
2145 MultipartRequestTableFeaturesBuilder requestBuilder = new MultipartRequestTableFeaturesBuilder();
2147 final java.util.Optional<List<TableFeatures>> ofTableFeatureList = ConvertorManager.getInstance().convert(input.getUpdatedTable());
2148 requestBuilder.setTableFeatures(ofTableFeatureList.orElse(Collections.emptyList()));
2149 caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build());
2151 // Set request body to main multipart request
2152 MultipartRequestInputBuilder mprInput =
2153 createMultipartHeader(MultipartType.OFPMPTABLEFEATURES, taskContext, xid);
2154 mprInput.setMultipartRequestBody(caseBuilder.build());
2156 Future<RpcResult<Void>> resultFromOFLib = getMessageService()
2157 .multipartRequest(mprInput.build(), getCookie());
2158 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
2160 Futures.addCallback(resultLib, new ResultCallback<UpdateTableOutput>(result) {
2162 public UpdateTableOutput createResult() {
2163 UpdateTableOutputBuilder queueStatsFromPortBuilder =
2164 new UpdateTableOutputBuilder()
2165 .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
2166 return queueStatsFromPortBuilder.build();
2173 return new OFRpcTaskImpl(taskContext, cookie, input);
2176 public static OFRpcTask<SetConfigInput, RpcResult<SetConfigOutput>> createSetNodeConfigTask(final OFRpcTaskContext taskContext,
2177 final SetConfigInput input,
2178 final SwitchConnectionDistinguisher cookie) {
2179 class OFRpcTaskImpl extends OFRpcTask<SetConfigInput, RpcResult<SetConfigOutput>> {
2181 public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
2182 SetConfigInput input) {
2183 super(taskContext, cookie, input);
2187 public ListenableFuture<RpcResult<SetConfigOutput>> call() throws Exception {
2189 final SettableFuture<RpcResult<SetConfigOutput>> result = SettableFuture.create();
2190 final Long xid = taskContext.getSession().getNextXid();
2192 SetConfigInputBuilder builder = new SetConfigInputBuilder();
2193 SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag());
2194 builder.setXid(xid);
2195 builder.setFlags(flag);
2196 builder.setMissSendLen(input.getMissSearchLength());
2197 builder.setVersion(getVersion());
2198 ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(taskContext.getSession().getPrimaryConductor().getConnectionAdapter().setConfig(builder.build()));
2199 Futures.addCallback(resultLib, new ResultCallback<SetConfigOutput>(result) {
2201 public SetConfigOutput createResult() {
2202 SetConfigOutputBuilder setConfigOutputBuilder = new SetConfigOutputBuilder();
2203 setConfigOutputBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
2204 return setConfigOutputBuilder.build();
2211 return new OFRpcTaskImpl(taskContext, cookie, input);