2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.openflow.md.core.sal;
10 import java.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.Collections;
14 import java.util.List;
15 import java.util.concurrent.Future;
16 import java.util.concurrent.TimeUnit;
18 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
19 import org.opendaylight.controller.sal.common.util.Rpcs;
20 import org.opendaylight.openflowjava.protocol.api.util.BinContent;
21 import org.opendaylight.openflowplugin.openflow.md.OFConstants;
22 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
23 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
24 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor;
25 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
26 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor;
27 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
28 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor;
29 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
30 import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService;
31 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
32 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
33 import org.opendaylight.openflowplugin.openflow.md.core.session.TransactionKey;
34 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
35 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutputBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutputBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupAddedBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemovedBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdatedBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutputBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutputBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutputBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutputBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutputBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterAddedBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemovedBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdatedBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutputBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutputBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutputBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutputBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Group;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Meter;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.MatchBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;
154 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;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutputBuilder;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInput;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutputBuilder;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInput;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutput;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutputBuilder;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutputBuilder;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInput;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutputBuilder;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInput;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutputBuilder;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder;
177 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
178 import org.opendaylight.yangtools.yang.common.RpcError;
179 import org.opendaylight.yangtools.yang.common.RpcResult;
180 import org.slf4j.Logger;
182 import com.google.common.base.Objects;
183 import com.google.common.util.concurrent.Futures;
184 import com.google.common.util.concurrent.JdkFutureAdapters;
187 * RPC implementation of MD-switch
189 public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
191 private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(ModelDrivenSwitchImpl.class);
192 private final NodeId nodeId;
193 private final IMessageDispatchService messageService;
194 private short version = 0;
195 private final SessionContext session;
196 NotificationProviderService rpcNotificationProviderService;
197 private OFRpcTaskHelper rpcTaskHelper;
199 // TODO:read timeout from configSubsystem
200 protected long maxTimeout = 1000;
201 protected TimeUnit maxTimeoutUnit = TimeUnit.MILLISECONDS;
203 protected ModelDrivenSwitchImpl(final NodeId nodeId, final InstanceIdentifier<Node> identifier, final SessionContext context) {
204 super(identifier, context);
205 this.nodeId = nodeId;
206 messageService = sessionContext.getMessageDispatchService();
207 version = context.getPrimaryConductor().getVersion();
208 this.session = context;
209 rpcNotificationProviderService = OFSessionUtil.getSessionManager().getNotificationProviderService();
210 rpcTaskHelper = new OFRpcTaskHelper(messageService, context, rpcNotificationProviderService);
214 public Future<RpcResult<AddFlowOutput>> addFlow(final AddFlowInput input) {
215 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
216 // use primary connection
217 SwitchConnectionDistinguisher cookie = null;
219 OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> task =
220 OFRpcTaskFactory.createAddFlowTask(maxTimeout, maxTimeoutUnit, rpcTaskHelper);
221 rpcTaskHelper.initTask(task, input, cookie);
222 OFSessionUtil.getSessionManager().getRpcPool().submit(task);
224 return Futures.transform(JdkFutureAdapters.listenInPoolThread(task.getResult()),
225 OFRpcFutureResultTransformFactory.createForAddFlowOutput());
230 public Future<RpcResult<AddGroupOutput>> addGroup(final AddGroupInput input) {
231 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
234 // use primary connection
235 SwitchConnectionDistinguisher cookie = null;
237 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
238 xId = session.getNextXid();
239 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
240 barrierInput.setVersion(version);
241 barrierInput.setXid(xId);
242 @SuppressWarnings("unused")
243 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
246 // Convert the AddGroupInput to GroupModInput
247 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(input, version, this.getSessionContext()
248 .getFeatures().getDatapathId());
249 xId = session.getNextXid();
250 ofGroupModInput.setXid(xId);
252 if (null != rpcNotificationProviderService) {
253 GroupAddedBuilder groupMod = new GroupAddedBuilder(
254 (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group) input);
255 groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
256 groupMod.setGroupRef(input.getGroupRef());
257 rpcNotificationProviderService.publish(groupMod.build());
260 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput.build(), cookie);
261 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null;
264 rpcResultFromOFLib = resultFromOFLib.get();
265 } catch (Exception ex) {
266 LOG.error(" Error while getting result for AddGroup RPC" + ex.getMessage());
269 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult();
271 AddGroupOutputBuilder addGroupOutput = new AddGroupOutputBuilder();
272 addGroupOutput.setTransactionId(updateGroupOutput.getTransactionId());
273 AddGroupOutput result = addGroupOutput.build();
275 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
276 RpcResult<AddGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
278 LOG.debug("Returning the Add Group RPC result to MD-SAL");
279 return Futures.immediateFuture(rpcResult);
283 public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
284 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
286 // For Meter provisioning, the SwitchConnectionDistinguisher is set to
288 // the request can be routed through any connection to the switch
290 SwitchConnectionDistinguisher cookie = null;
291 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
292 xId = session.getNextXid();
293 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
294 barrierInput.setVersion(version);
295 barrierInput.setXid(xId);
296 @SuppressWarnings("unused")
297 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
300 // Convert the AddMeterInput to MeterModInput
301 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
302 xId = session.getNextXid();
303 ofMeterModInput.setXid(xId);
305 if (null != rpcNotificationProviderService) {
306 MeterAddedBuilder meterMod = new MeterAddedBuilder(
307 (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter) input);
308 meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
309 meterMod.setMeterRef(input.getMeterRef());
310 rpcNotificationProviderService.publish(meterMod.build());
313 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput.build(), cookie);
315 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null;
318 rpcResultFromOFLib = resultFromOFLib.get();
319 } catch (Exception ex) {
320 LOG.error(" Error while getting result for AddMeter RPC" + ex.getMessage());
323 UpdateMeterOutput updateMeterOutput = rpcResultFromOFLib.getResult();
325 AddMeterOutputBuilder addMeterOutput = new AddMeterOutputBuilder();
326 addMeterOutput.setTransactionId(updateMeterOutput.getTransactionId());
327 AddMeterOutput result = addMeterOutput.build();
329 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
330 RpcResult<AddMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
332 LOG.debug("Returning the Add Meter RPC result to MD-SAL");
333 return Futures.immediateFuture(rpcResult);
337 public Future<RpcResult<RemoveFlowOutput>> removeFlow(final RemoveFlowInput input) {
338 LOG.debug("Calling the removeFlow RPC method on MessageDispatchService");
340 // For Flow provisioning, the SwitchConnectionDistinguisher is set to
342 // the request can be routed through any connection to the switch
344 SwitchConnectionDistinguisher cookie = null;
345 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
346 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
347 xId = session.getNextXid();
348 barrierInput.setXid(xId);
349 barrierInput.setVersion(version);
350 @SuppressWarnings("unused")
351 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
354 // Convert the RemoveFlowInput to FlowModInput
355 FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(input, version, this.getSessionContext()
356 .getFeatures().getDatapathId());
357 xId = session.getNextXid();
358 ofFlowModInput.setXid(xId);
360 if (null != rpcNotificationProviderService) {
361 FlowRemovedBuilder removeFlow = new FlowRemovedBuilder(
362 (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) input);
363 removeFlow.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
364 removeFlow.setFlowRef(input.getFlowRef());
365 rpcNotificationProviderService.publish(removeFlow.build());
368 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput.build(), cookie);
370 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null;
373 rpcResultFromOFLib = resultFromOFLib.get();
374 } catch (Exception ex) {
375 LOG.error(" Error while getting result for remove Flow RPC" + ex.getMessage());
378 UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult();
380 RemoveFlowOutputBuilder removeFlowOutput = new RemoveFlowOutputBuilder();
381 removeFlowOutput.setTransactionId(updateFlowOutput.getTransactionId());
382 RemoveFlowOutput result = removeFlowOutput.build();
384 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
385 RpcResult<RemoveFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
387 LOG.debug("Returning the Remove Flow RPC result to MD-SAL");
388 return Futures.immediateFuture(rpcResult);
392 public Future<RpcResult<RemoveGroupOutput>> removeGroup(final RemoveGroupInput input) {
393 LOG.debug("Calling the Remove Group RPC method on MessageDispatchService");
396 // For Flow provisioning, the SwitchConnectionDistinguisher is set to
398 // the request can be routed through any connection to the switch
400 SwitchConnectionDistinguisher cookie = null;
401 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
402 xId = session.getNextXid();
403 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
404 barrierInput.setVersion(version);
405 barrierInput.setXid(xId);
406 @SuppressWarnings("unused")
407 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
410 // Convert the RemoveGroupInput to GroupModInput
411 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(input, version, this.getSessionContext()
412 .getFeatures().getDatapathId());
413 xId = session.getNextXid();
414 ofGroupModInput.setXid(xId);
416 if (null != rpcNotificationProviderService) {
417 GroupRemovedBuilder groupMod = new GroupRemovedBuilder(
418 (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group) input);
419 groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
420 groupMod.setGroupRef(input.getGroupRef());
421 rpcNotificationProviderService.publish(groupMod.build());
424 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput.build(), cookie);
426 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null;
429 rpcResultFromOFLib = resultFromOFLib.get();
430 } catch (Exception ex) {
431 LOG.error(" Error while getting result for RemoveGroup RPC" + ex.getMessage());
434 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult();
436 RemoveGroupOutputBuilder removeGroupOutput = new RemoveGroupOutputBuilder();
437 removeGroupOutput.setTransactionId(updateGroupOutput.getTransactionId());
438 RemoveGroupOutput result = removeGroupOutput.build();
440 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
441 RpcResult<RemoveGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
443 LOG.debug("Returning the Remove Group RPC result to MD-SAL");
444 return Futures.immediateFuture(rpcResult);
448 public Future<RpcResult<RemoveMeterOutput>> removeMeter(final RemoveMeterInput input) {
449 LOG.debug("Calling the Remove MeterMod RPC method on MessageDispatchService");
452 // For Meter provisioning, the SwitchConnectionDistinguisher is set to
454 // the request can be routed through any connection to the switch
455 SwitchConnectionDistinguisher cookie = null;
456 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
457 xId = session.getNextXid();
458 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
459 barrierInput.setVersion(version);
460 barrierInput.setXid(xId);
461 @SuppressWarnings("unused")
462 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
465 // Convert the RemoveMeterInput to MeterModInput
466 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
467 xId = session.getNextXid();
468 ofMeterModInput.setXid(xId);
470 if (null != rpcNotificationProviderService) {
471 MeterRemovedBuilder meterMod = new MeterRemovedBuilder(
472 (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter) input);
473 meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
474 meterMod.setMeterRef(input.getMeterRef());
475 rpcNotificationProviderService.publish(meterMod.build());
478 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput.build(), cookie);
480 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null;
483 rpcResultFromOFLib = resultFromOFLib.get();
484 } catch (Exception ex) {
485 LOG.error(" Error while getting result for RemoveMeter RPC" + ex.getMessage());
488 UpdateMeterOutput updatemeterOutput = rpcResultFromOFLib.getResult();
490 RemoveMeterOutputBuilder removeMeterOutput = new RemoveMeterOutputBuilder();
491 removeMeterOutput.setTransactionId(updatemeterOutput.getTransactionId());
492 RemoveMeterOutput result = removeMeterOutput.build();
494 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
495 RpcResult<RemoveMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
497 LOG.debug("Returning the Remove Meter RPC result to MD-SAL");
498 return Futures.immediateFuture(rpcResult);
502 public Future<RpcResult<Void>> transmitPacket(final TransmitPacketInput input) {
503 LOG.debug("TransmitPacket - {}", input);
504 // Convert TransmitPacket to PacketOutInput
505 PacketOutInput message = PacketOutConvertor.toPacketOutInput(input, version, sessionContext.getNextXid(),
506 sessionContext.getFeatures().getDatapathId());
508 // TODO VD NULL for yet - find how to translate cookie from
509 // TransmitPacketInput
510 // SwitchConnectionDistinguisher cookie = ( "what is need to do" )
511 // input.getCookie();
512 SwitchConnectionDistinguisher cookie = null;
514 LOG.debug("Calling the transmitPacket RPC method");
515 return messageService.packetOut(message, cookie);
518 private FlowModInputBuilder toFlowModInputBuilder(final Flow source) {
519 FlowModInputBuilder target = new FlowModInputBuilder();
520 target.setCookie(source.getCookie().getValue());
521 target.setIdleTimeout(source.getIdleTimeout());
522 target.setHardTimeout(source.getHardTimeout());
523 target.setMatch(toMatch(source.getMatch()));
528 private Match toMatch(final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
529 MatchBuilder target = new MatchBuilder();
531 target.setMatchEntries(toMatchEntries(match));
536 private List<MatchEntries> toMatchEntries(
537 final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
538 List<MatchEntries> entries = new ArrayList<>();
544 public Future<RpcResult<UpdateFlowOutput>> updateFlow(final UpdateFlowInput input) {
545 LOG.debug("Calling the updateFlow RPC method on MessageDispatchService");
547 // use primary connection
548 SwitchConnectionDistinguisher cookie = null;
550 OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> task =
551 OFRpcTaskFactory.createUpdateFlowTask(maxTimeout, maxTimeoutUnit, rpcTaskHelper);
552 rpcTaskHelper.initTask(task, input, cookie);
553 OFSessionUtil.getSessionManager().getRpcPool().submit(task);
555 return task.getResult();
559 public Future<RpcResult<UpdateGroupOutput>> updateGroup(final UpdateGroupInput input) {
560 LOG.debug("Calling the update Group Mod RPC method on MessageDispatchService");
563 // For Flow provisioning, the SwitchConnectionDistinguisher is set to
565 // the request can be routed through any connection to the switch
567 SwitchConnectionDistinguisher cookie = null;
568 if (Objects.firstNonNull(input.getUpdatedGroup().isBarrier(), Boolean.FALSE)) {
569 xId = session.getNextXid();
570 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
571 barrierInput.setVersion(version);
572 barrierInput.setXid(xId);
573 @SuppressWarnings("unused")
574 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
577 // Convert the UpdateGroupInput to GroupModInput
578 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(input.getUpdatedGroup(), version, this
579 .getSessionContext().getFeatures().getDatapathId());
580 xId = session.getNextXid();
581 ofGroupModInput.setXid(xId);
583 if (null != rpcNotificationProviderService) {
584 GroupUpdatedBuilder groupMod = new GroupUpdatedBuilder(input.getUpdatedGroup());
585 groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
586 groupMod.setGroupRef(input.getGroupRef());
587 rpcNotificationProviderService.publish(groupMod.build());
590 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput.build(), cookie);
592 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null;
595 rpcResultFromOFLib = resultFromOFLib.get();
596 } catch (Exception ex) {
597 LOG.error(" Error while getting result for updateGroup RPC" + ex.getMessage());
600 UpdateGroupOutput updateGroupOutputOFLib = rpcResultFromOFLib.getResult();
602 UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder();
603 updateGroupOutput.setTransactionId(updateGroupOutputOFLib.getTransactionId());
604 UpdateGroupOutput result = updateGroupOutput.build();
606 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
607 RpcResult<UpdateGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
609 LOG.debug("Returning the Update Group RPC result to MD-SAL");
610 return Futures.immediateFuture(rpcResult);
614 public Future<RpcResult<UpdateMeterOutput>> updateMeter(final UpdateMeterInput input) {
615 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
618 // For Meter provisioning, the SwitchConnectionDistinguisher is set to
620 // the request can be routed through any connection to the switch
621 SwitchConnectionDistinguisher cookie = null;
622 if (Objects.firstNonNull(input.getUpdatedMeter().isBarrier(), Boolean.FALSE)) {
623 xId = session.getNextXid();
624 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
625 barrierInput.setVersion(version);
626 barrierInput.setXid(xId);
627 @SuppressWarnings("unused")
628 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
631 // Convert the UpdateMeterInput to MeterModInput
632 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input.getUpdatedMeter(), version);
633 xId = session.getNextXid();
634 ofMeterModInput.setXid(xId);
636 if (null != rpcNotificationProviderService) {
637 MeterUpdatedBuilder meterMod = new MeterUpdatedBuilder(input.getUpdatedMeter());
638 meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
639 meterMod.setMeterRef(input.getMeterRef());
640 rpcNotificationProviderService.publish(meterMod.build());
643 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput.build(), cookie);
645 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null;
648 rpcResultFromOFLib = resultFromOFLib.get();
649 } catch (Exception ex) {
650 LOG.error(" Error while getting result for UpdateMeter RPC" + ex.getMessage());
653 UpdateMeterOutput updateMeterOutputFromOFLib = rpcResultFromOFLib.getResult();
655 UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder();
656 updateMeterOutput.setTransactionId(updateMeterOutputFromOFLib.getTransactionId());
657 UpdateMeterOutput result = updateMeterOutput.build();
659 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
660 RpcResult<UpdateMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
662 LOG.debug("Returning the Update Meter RPC result to MD-SAL");
663 return Futures.immediateFuture(rpcResult);
667 public NodeId getNodeId() {
672 * Methods for requesting statistics from switch
675 public Future<RpcResult<GetAllGroupStatisticsOutput>> getAllGroupStatistics(final GetAllGroupStatisticsInput input) {
677 GetAllGroupStatisticsOutputBuilder output = new GetAllGroupStatisticsOutputBuilder();
678 Collection<RpcError> errors = Collections.emptyList();
680 if (version == OFConstants.OFP_VERSION_1_0) {
681 output.setTransactionId(null);
682 output.setGroupStats(null);
684 RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
685 return Futures.immediateFuture(rpcResult);
687 // Generate xid to associate it with the request
688 Long xid = this.getSessionContext().getNextXid();
690 LOG.debug("Prepare statistics request for all the groups - Transaction id - {}", xid);
692 // Create multipart request header
693 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
694 mprInput.setType(MultipartType.OFPMPGROUP);
695 mprInput.setVersion(version);
696 mprInput.setXid(xid);
697 mprInput.setFlags(new MultipartRequestFlags(false));
699 // Create multipart request body for fetch all the group stats
700 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
701 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
702 mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(Group.OFPGALL.getIntValue())));
703 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
705 // Set request body to main multipart request
706 mprInput.setMultipartRequestBody(caseBuilder.build());
708 // Send the request, no cookies associated, use any connection
709 LOG.debug("Send group statistics request to the switch :{}", mprGroupBuild);
710 this.messageService.multipartRequest(mprInput.build(), null);
712 // Prepare rpc return output. Set xid and send it back.
713 LOG.debug("Return results and transaction id back to caller");
714 output.setTransactionId(generateTransactionId(xid));
715 output.setGroupStats(null);
717 RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
718 return Futures.immediateFuture(rpcResult);
723 public Future<RpcResult<GetGroupDescriptionOutput>> getGroupDescription(final GetGroupDescriptionInput input) {
725 GetGroupDescriptionOutputBuilder output = new GetGroupDescriptionOutputBuilder();
726 Collection<RpcError> errors = Collections.emptyList();
728 if (version == OFConstants.OFP_VERSION_1_0) {
729 output.setTransactionId(null);
730 output.setGroupDescStats(null);
732 RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
733 return Futures.immediateFuture(rpcResult);
735 // Generate xid to associate it with the request
736 Long xid = this.getSessionContext().getNextXid();
738 LOG.debug("Prepare group description statistics request - Transaction id - {}", xid);
740 // Create multipart request header
741 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
742 mprInput.setType(MultipartType.OFPMPGROUPDESC);
743 mprInput.setVersion(version);
744 mprInput.setXid(xid);
745 mprInput.setFlags(new MultipartRequestFlags(false));
747 // Create multipart request body for fetch all the group description
749 MultipartRequestGroupDescCaseBuilder mprGroupDescBuild = new MultipartRequestGroupDescCaseBuilder();
751 // Set request body to main multipart request
752 mprInput.setMultipartRequestBody(mprGroupDescBuild.build());
754 // Send the request, no cookies associated, use any connection
755 LOG.debug("Send group desciption statistics request to switch : {}", mprGroupDescBuild);
756 this.messageService.multipartRequest(mprInput.build(), null);
758 // Prepare rpc return output. Set xid and send it back.
759 LOG.debug("Return results and transaction id back to caller");
760 output.setTransactionId(generateTransactionId(xid));
761 output.setGroupDescStats(null);
763 RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
764 return Futures.immediateFuture(rpcResult);
769 public Future<RpcResult<GetGroupFeaturesOutput>> getGroupFeatures(final GetGroupFeaturesInput input) {
771 GetGroupFeaturesOutputBuilder output = new GetGroupFeaturesOutputBuilder();
772 Collection<RpcError> errors = Collections.emptyList();
774 if (version == OFConstants.OFP_VERSION_1_0) {
775 output.setTransactionId(null);
777 RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
778 return Futures.immediateFuture(rpcResult);
780 // Generate xid to associate it with the request
781 Long xid = this.getSessionContext().getNextXid();
783 LOG.debug("Prepare group features statistics request - Transaction id - {}", xid);
785 // Create multipart request header
786 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
787 mprInput.setType(MultipartType.OFPMPGROUPFEATURES);
788 mprInput.setVersion(version);
789 mprInput.setXid(xid);
790 mprInput.setFlags(new MultipartRequestFlags(false));
792 // Create multipart request body for fetch all the group description
794 MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild = new MultipartRequestGroupFeaturesCaseBuilder();
796 // Set request body to main multipart request
797 mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
799 // Send the request, no cookies associated, use any connection
800 LOG.debug("Send group features statistics request :{}", mprGroupFeaturesBuild);
801 this.messageService.multipartRequest(mprInput.build(), null);
803 // Prepare rpc return output. Set xid and send it back.
804 LOG.debug("Return results and transaction id back to caller");
805 output.setTransactionId(generateTransactionId(xid));
807 RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
808 return Futures.immediateFuture(rpcResult);
812 public Future<RpcResult<GetGroupStatisticsOutput>> getGroupStatistics(final GetGroupStatisticsInput input) {
814 GetGroupStatisticsOutputBuilder output = new GetGroupStatisticsOutputBuilder();
815 Collection<RpcError> errors = Collections.emptyList();
817 if (version == OFConstants.OFP_VERSION_1_0) {
818 output.setTransactionId(null);
819 output.setGroupStats(null);
821 RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
822 return Futures.immediateFuture(rpcResult);
824 // Generate xid to associate it with the request
825 Long xid = this.getSessionContext().getNextXid();
827 LOG.debug("Prepare statistics request for node {} group ({}) - Transaction id - {}", input.getNode(),
828 input.getGroupId(), xid);
830 // Create multipart request header
831 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
832 mprInput.setType(MultipartType.OFPMPGROUP);
833 mprInput.setVersion(version);
834 mprInput.setXid(xid);
835 mprInput.setFlags(new MultipartRequestFlags(false));
837 // Create multipart request body for fetch all the group stats
838 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
839 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
840 mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
841 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
843 // Set request body to main multipart request
844 mprInput.setMultipartRequestBody(caseBuilder.build());
846 // Send the request, no cookies associated, use any connection
847 LOG.debug("Send group statistics request :{}", mprGroupBuild);
848 this.messageService.multipartRequest(mprInput.build(), null);
850 // Prepare rpc return output. Set xid and send it back.
851 LOG.debug("Return results and transaction id back to caller");
852 output.setTransactionId(generateTransactionId(xid));
853 output.setGroupStats(null);
855 RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
856 return Futures.immediateFuture(rpcResult);
860 public Future<RpcResult<GetAllMeterConfigStatisticsOutput>> getAllMeterConfigStatistics(
861 final GetAllMeterConfigStatisticsInput input) {
863 GetAllMeterConfigStatisticsOutputBuilder output = new GetAllMeterConfigStatisticsOutputBuilder();
864 Collection<RpcError> errors = Collections.emptyList();
866 if (version == OFConstants.OFP_VERSION_1_0) {
867 output.setTransactionId(null);
868 output.setMeterConfigStats(null);
870 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
871 return Futures.immediateFuture(rpcResult);
874 // Generate xid to associate it with the request
875 Long xid = this.getSessionContext().getNextXid();
877 LOG.debug("Prepare config request for all the meters - Transaction id - {}", xid);
879 // Create multipart request header
880 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
881 mprInput.setType(MultipartType.OFPMPMETERCONFIG);
882 mprInput.setVersion(version);
883 mprInput.setXid(xid);
884 mprInput.setFlags(new MultipartRequestFlags(false));
886 // Create multipart request body for fetch all the meter stats
887 MultipartRequestMeterConfigCaseBuilder caseBuilder = new MultipartRequestMeterConfigCaseBuilder();
888 MultipartRequestMeterConfigBuilder mprMeterConfigBuild = new MultipartRequestMeterConfigBuilder();
889 mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
890 caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
892 // Set request body to main multipart request
893 mprInput.setMultipartRequestBody(caseBuilder.build());
895 // Send the request, no cookies associated, use any connection
896 LOG.debug("Send meter statistics request :{}", mprMeterConfigBuild);
897 this.messageService.multipartRequest(mprInput.build(), null);
899 // Prepare rpc return output. Set xid and send it back.
900 LOG.debug("Return results and transaction id back to caller");
901 output.setTransactionId(generateTransactionId(xid));
902 output.setMeterConfigStats(null);
904 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
905 return Futures.immediateFuture(rpcResult);
909 public Future<RpcResult<GetAllMeterStatisticsOutput>> getAllMeterStatistics(final GetAllMeterStatisticsInput input) {
911 GetAllMeterStatisticsOutputBuilder output = new GetAllMeterStatisticsOutputBuilder();
912 Collection<RpcError> errors = Collections.emptyList();
914 if (version == OFConstants.OFP_VERSION_1_0) {
915 output.setTransactionId(null);
916 output.setMeterStats(null);
918 RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
919 return Futures.immediateFuture(rpcResult);
921 // Generate xid to associate it with the request
922 Long xid = this.getSessionContext().getNextXid();
924 LOG.debug("Prepare statistics request for all the meters - Transaction id - {}", xid);
926 // Create multipart request header
927 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
928 mprInput.setType(MultipartType.OFPMPMETER);
929 mprInput.setVersion(version);
930 mprInput.setXid(xid);
931 mprInput.setFlags(new MultipartRequestFlags(false));
933 // Create multipart request body for fetch all the meter stats
934 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
935 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
936 mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
937 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
939 // Set request body to main multipart request
940 mprInput.setMultipartRequestBody(caseBuilder.build());
942 // Send the request, no cookies associated, use any connection
943 LOG.debug("Send meter statistics request :{}", mprMeterBuild);
944 this.messageService.multipartRequest(mprInput.build(), null);
946 // Prepare rpc return output. Set xid and send it back.
947 LOG.debug("Return results and transaction id back to caller");
948 output.setTransactionId(generateTransactionId(xid));
949 output.setMeterStats(null);
951 RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
952 return Futures.immediateFuture(rpcResult);
956 public Future<RpcResult<GetMeterFeaturesOutput>> getMeterFeatures(final GetMeterFeaturesInput input) {
958 GetMeterFeaturesOutputBuilder output = new GetMeterFeaturesOutputBuilder();
959 Collection<RpcError> errors = Collections.emptyList();
961 if (version == OFConstants.OFP_VERSION_1_0) {
962 output.setTransactionId(null);
964 RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
965 return Futures.immediateFuture(rpcResult);
967 // Generate xid to associate it with the request
968 Long xid = this.getSessionContext().getNextXid();
970 LOG.debug("Prepare features statistics request for all the meters - Transaction id - {}", xid);
972 // Create multipart request header
973 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
974 mprInput.setType(MultipartType.OFPMPMETERFEATURES);
975 mprInput.setVersion(version);
976 mprInput.setXid(xid);
977 mprInput.setFlags(new MultipartRequestFlags(false));
979 // Create multipart request body for fetch all the group description
981 MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild = new MultipartRequestMeterFeaturesCaseBuilder();
983 // Set request body to main multipart request
984 mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
986 // Send the request, no cookies associated, use any connection
987 LOG.debug("Send meter features statistics request :{}", mprMeterFeaturesBuild);
988 this.messageService.multipartRequest(mprInput.build(), null);
990 // Prepare rpc return output. Set xid and send it back.
991 LOG.debug("Return results and transaction id back to caller");
992 output.setTransactionId(generateTransactionId(xid));
994 RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
995 return Futures.immediateFuture(rpcResult);
999 public Future<RpcResult<GetMeterStatisticsOutput>> getMeterStatistics(final GetMeterStatisticsInput input) {
1001 GetMeterStatisticsOutputBuilder output = new GetMeterStatisticsOutputBuilder();
1002 Collection<RpcError> errors = Collections.emptyList();
1004 if (version == OFConstants.OFP_VERSION_1_0) {
1005 output.setTransactionId(null);
1006 output.setMeterStats(null);
1008 RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1009 return Futures.immediateFuture(rpcResult);
1012 // Generate xid to associate it with the request
1013 Long xid = this.getSessionContext().getNextXid();
1015 LOG.debug("Preprae statistics request for Meter ({}) - Transaction id - {}", input.getMeterId().getValue(), xid);
1017 // Create multipart request header
1018 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1019 mprInput.setType(MultipartType.OFPMPMETER);
1020 mprInput.setVersion(version);
1021 mprInput.setXid(xid);
1022 mprInput.setFlags(new MultipartRequestFlags(false));
1024 // Create multipart request body for fetch all the meter stats
1025 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
1026 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
1027 // Select specific meter
1028 mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
1029 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
1031 // Set request body to main multipart request
1032 mprInput.setMultipartRequestBody(caseBuilder.build());
1034 // Send the request, no cookies associated, use any connection
1035 LOG.debug("Send meter statistics request :{}", mprMeterBuild);
1036 this.messageService.multipartRequest(mprInput.build(), null);
1038 // Prepare rpc return output. Set xid and send it back.
1039 LOG.debug("Return results and transaction id back to caller");
1040 output.setTransactionId(generateTransactionId(xid));
1041 output.setMeterStats(null);
1043 RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1044 return Futures.immediateFuture(rpcResult);
1048 public Future<RpcResult<GetAllNodeConnectorsStatisticsOutput>> getAllNodeConnectorsStatistics(
1049 final GetAllNodeConnectorsStatisticsInput arg0) {
1051 // Generate xid to associate it with the request
1052 Long xid = this.getSessionContext().getNextXid();
1054 LOG.debug("Prepare port statistics request for all ports of node {} - TrasactionId - {}", arg0.getNode()
1057 // Create multipart request header
1058 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1059 mprInput.setType(MultipartType.OFPMPPORTSTATS);
1060 mprInput.setVersion(version);
1061 mprInput.setXid(xid);
1062 mprInput.setFlags(new MultipartRequestFlags(false));
1064 // Create multipart request body to fetch stats for all the port of the
1066 MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
1067 MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
1069 mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
1070 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1072 // Set request body to main multipart request
1073 mprInput.setMultipartRequestBody(caseBuilder.build());
1075 // Send the request, no cookies associated, use any connection
1076 LOG.debug("Send port statistics request :{}", mprPortStatsBuilder.build().toString());
1077 this.messageService.multipartRequest(mprInput.build(), null);
1079 // Prepare rpc return output. Set xid and send it back.
1080 GetAllNodeConnectorsStatisticsOutputBuilder output = new GetAllNodeConnectorsStatisticsOutputBuilder();
1081 output.setTransactionId(generateTransactionId(xid));
1083 Collection<RpcError> errors = Collections.emptyList();
1084 RpcResult<GetAllNodeConnectorsStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1085 return Futures.immediateFuture(rpcResult);
1089 public Future<RpcResult<GetNodeConnectorStatisticsOutput>> getNodeConnectorStatistics(
1090 final GetNodeConnectorStatisticsInput arg0) {
1091 // Generate xid to associate it with the request
1092 Long xid = this.getSessionContext().getNextXid();
1094 LOG.debug("Prepare port statistics request for port {} of node {} - TrasactionId - {}",
1095 arg0.getNodeConnectorId(), arg0.getNode().getValue(), xid);
1097 // Create multipart request header
1098 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1099 mprInput.setType(MultipartType.OFPMPPORTSTATS);
1100 mprInput.setVersion(version);
1101 mprInput.setXid(xid);
1102 mprInput.setFlags(new MultipartRequestFlags(false));
1104 // Create multipart request body to fetch stats for all the port of the
1106 MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
1107 MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
1109 // Set specific port
1111 .setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1112 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1114 // Set request body to main multipart request
1115 mprInput.setMultipartRequestBody(caseBuilder.build());
1117 // Send the request, no cookies associated, use any connection
1118 LOG.debug("Send port statistics request :{}", mprPortStatsBuilder.build().toString());
1119 this.messageService.multipartRequest(mprInput.build(), null);
1121 // Prepare rpc return output. Set xid and send it back.
1122 GetNodeConnectorStatisticsOutputBuilder output = new GetNodeConnectorStatisticsOutputBuilder();
1123 output.setTransactionId(generateTransactionId(xid));
1125 Collection<RpcError> errors = Collections.emptyList();
1126 RpcResult<GetNodeConnectorStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1127 return Futures.immediateFuture(rpcResult);
1130 private TransactionId generateTransactionId(final Long xid) {
1131 String stringXid = xid.toString();
1132 BigInteger bigIntXid = new BigInteger(stringXid);
1133 return new TransactionId(bigIntXid);
1138 public Future<RpcResult<UpdatePortOutput>> updatePort(final UpdatePortInput input) {
1139 PortModInput ofPortModInput = null;
1140 RpcResult<UpdatePortOutput> rpcResultFromOFLib = null;
1142 // For Flow provisioning, the SwitchConnectionDistinguisher is set to
1144 // the request can be routed through any connection to the switch
1146 SwitchConnectionDistinguisher cookie = null;
1148 // NSF sends a list of port and the ModelDrivenSwitch will
1149 // send one port at a time towards the switch ( mutiple RPCs calls)
1150 List<Port> inputPorts = input.getUpdatedPort().getPort().getPort();
1152 // Get the Xid. The same Xid has to be sent in all the RPCs
1153 Long Xid = sessionContext.getNextXid();
1155 for (Port inputPort : inputPorts) {
1157 // Convert the UpdateGroupInput to GroupModInput
1158 ofPortModInput = PortConvertor.toPortModInput(inputPort, version);
1160 // Insert the Xid ( transaction Id) before calling the RPC on the
1163 PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
1164 mdInput.setXid(Xid);
1166 LOG.debug("Calling the PortMod RPC method on MessageDispatchService");
1167 Future<RpcResult<UpdatePortOutput>> resultFromOFLib = messageService.portMod(mdInput.build(), cookie);
1170 rpcResultFromOFLib = resultFromOFLib.get();
1171 } catch (Exception ex) {
1172 LOG.error(" Error while getting result for updatePort RPC" + ex.getMessage());
1175 // The Future response value for all the RPCs except the last one is
1179 // Extract the Xid only from the Future for the last RPC and
1180 // send it back to the NSF
1181 UpdatePortOutput updatePortOutputOFLib = rpcResultFromOFLib.getResult();
1183 UpdatePortOutputBuilder updatePortOutput = new UpdatePortOutputBuilder();
1184 updatePortOutput.setTransactionId(updatePortOutputOFLib.getTransactionId());
1185 UpdatePortOutput result = updatePortOutput.build();
1187 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
1188 RpcResult<UpdatePortOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
1190 LOG.debug("Returning the Update Group RPC result to MD-SAL");
1191 return Futures.immediateFuture(rpcResult);
1196 public Future<RpcResult<UpdateTableOutput>> updateTable(final UpdateTableInput input) {
1198 // Get the Xid. The same Xid has to be sent in all the Multipart
1200 Long xid = this.getSessionContext().getNextXid();
1202 LOG.debug("Prepare the Multipart Table Mod requests for Transaction Id {} ", xid);
1204 // Create multipart request header
1205 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1206 mprInput.setType(MultipartType.OFPMPTABLEFEATURES);
1207 mprInput.setVersion((short) 0x04);
1208 mprInput.setXid(xid);
1210 // Convert the list of all MD-SAL table feature object into OF library
1212 List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input.getUpdatedTable());
1214 MultipartRequestTableFeaturesCaseBuilder caseRequest = new MultipartRequestTableFeaturesCaseBuilder();
1215 MultipartRequestTableFeaturesBuilder tableFeaturesRequest = new MultipartRequestTableFeaturesBuilder();
1217 mprInput.setFlags(new MultipartRequestFlags(false));
1219 tableFeaturesRequest.setTableFeatures(ofTableFeatureList);
1221 // Set request body to main multipart request
1222 caseRequest.setMultipartRequestTableFeatures(tableFeaturesRequest.build());
1223 mprInput.setMultipartRequestBody(caseRequest.build());
1225 // Send the request, no cookies associated, use any connection
1226 LOG.debug("Send Table Feature request :{}", ofTableFeatureList);
1227 this.messageService.multipartRequest(mprInput.build(), null);
1229 // Extract the Xid only from the Future for the last RPC and
1230 // send it back to the NSF
1231 LOG.debug("Returning the result and transaction id to NSF");
1232 LOG.debug("Return results and transaction id back to caller");
1233 UpdateTableOutputBuilder output = new UpdateTableOutputBuilder();
1234 output.setTransactionId(generateTransactionId(xid));
1236 Collection<RpcError> errors = Collections.emptyList();
1237 RpcResult<UpdateTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1238 return Futures.immediateFuture(rpcResult);
1242 public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
1243 final GetAllFlowStatisticsFromFlowTableInput arg0) {
1245 // Generate xid to associate it with the request
1246 Long xid = this.getSessionContext().getNextXid();
1248 LOG.debug("Prepare statistics request to get flow stats for switch tables {} - Transaction id - {}", arg0
1249 .getTableId().getValue(), xid);
1251 // Create multipart request header
1252 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1253 mprInput.setType(MultipartType.OFPMPFLOW);
1254 mprInput.setVersion(version);
1255 mprInput.setXid(xid);
1256 mprInput.setFlags(new MultipartRequestFlags(false));
1258 // Create multipart request body for fetch all the group stats
1259 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1260 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1261 mprFlowRequestBuilder.setTableId(arg0.getTableId().getValue());
1262 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1263 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1264 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1265 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1266 FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
1268 // Set request body to main multipart request
1269 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1270 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1272 // Send the request, no cookies associated, use any connection
1273 LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder);
1274 this.messageService.multipartRequest(mprInput.build(), null);
1276 // Prepare rpc return output. Set xid and send it back.
1277 LOG.debug("Return results and transaction id back to caller");
1278 GetAllFlowStatisticsFromFlowTableOutputBuilder output = new GetAllFlowStatisticsFromFlowTableOutputBuilder();
1279 output.setTransactionId(generateTransactionId(xid));
1280 output.setFlowAndStatisticsMapList(null);
1282 Collection<RpcError> errors = Collections.emptyList();
1283 RpcResult<GetAllFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1284 return Futures.immediateFuture(rpcResult);
1288 public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
1289 final GetAllFlowsStatisticsFromAllFlowTablesInput arg0) {
1291 // Generate xid to associate it with the request
1292 Long xid = this.getSessionContext().getNextXid();
1294 LOG.debug("Prepare statistics request to get flow stats of all switch tables - Transaction id - {}", xid);
1296 // Create multipart request header
1297 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1298 mprInput.setType(MultipartType.OFPMPFLOW);
1299 mprInput.setVersion(version);
1300 mprInput.setXid(xid);
1301 mprInput.setFlags(new MultipartRequestFlags(false));
1303 // Create multipart request body for fetch all the group stats
1304 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1305 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1306 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
1307 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1308 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1309 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1310 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1311 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1313 FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
1315 // Set request body to main multipart request
1316 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1317 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1319 // Send the request, no cookies associated, use any connection
1320 LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder);
1321 this.messageService.multipartRequest(mprInput.build(), null);
1323 // Prepare rpc return output. Set xid and send it back.
1324 GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder output = new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder();
1325 output.setTransactionId(generateTransactionId(xid));
1326 output.setFlowAndStatisticsMapList(null);
1328 Collection<RpcError> errors = Collections.emptyList();
1329 RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(),
1331 return Futures.immediateFuture(rpcResult);
1336 public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
1337 final GetFlowStatisticsFromFlowTableInput arg0) {
1338 // Generate xid to associate it with the request
1339 Long xid = this.getSessionContext().getNextXid();
1341 LOG.debug("Prepare statistics request to get stats for flow {} for switch tables {} - Transaction id - {}",
1342 arg0.getMatch().toString(), arg0.getTableId(), xid);
1344 // Create multipart request header
1345 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1346 mprInput.setType(MultipartType.OFPMPFLOW);
1347 mprInput.setVersion(version);
1348 mprInput.setXid(xid);
1349 mprInput.setFlags(new MultipartRequestFlags(false));
1351 // Create multipart request body for fetch all the group stats
1352 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1353 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1354 mprFlowRequestBuilder.setTableId(arg0.getTableId());
1356 if (arg0.getOutPort() != null)
1357 mprFlowRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1359 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1361 if (arg0.getOutGroup() != null)
1362 mprFlowRequestBuilder.setOutGroup(arg0.getOutGroup());
1364 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1366 if (arg0.getCookie() != null)
1367 mprFlowRequestBuilder.setCookie(arg0.getCookie().getValue());
1369 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1371 if (arg0.getCookieMask() != null)
1372 mprFlowRequestBuilder.setCookieMask(arg0.getCookieMask().getValue());
1374 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1376 // convert and inject match
1377 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprFlowRequestBuilder,
1378 this.getSessionContext().getFeatures().getDatapathId());
1380 // Set request body to main multipart request
1381 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1382 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1384 // Send the request, no cookies associated, use any connection
1385 LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder);
1386 this.messageService.multipartRequest(mprInput.build(), null);
1388 // Prepare rpc return output. Set xid and send it back.
1389 GetFlowStatisticsFromFlowTableOutputBuilder output = new GetFlowStatisticsFromFlowTableOutputBuilder();
1390 output.setTransactionId(generateTransactionId(xid));
1391 output.setFlowAndStatisticsMapList(null);
1393 Collection<RpcError> errors = Collections.emptyList();
1394 RpcResult<GetFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1395 return Futures.immediateFuture(rpcResult);
1399 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
1400 final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput arg0) {
1401 // Generate xid to associate it with the request
1402 Long xid = this.getSessionContext().getNextXid();
1405 "Prepare aggregate flow statistics request to get aggregate flow stats for all the flow installed on switch table {} - Transaction id - {}",
1406 arg0.getTableId().getValue(), xid);
1408 // Create multipart request header
1409 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1410 mprInput.setType(MultipartType.OFPMPAGGREGATE);
1411 mprInput.setVersion(version);
1412 mprInput.setXid(xid);
1413 mprInput.setFlags(new MultipartRequestFlags(false));
1415 // Create multipart request body for fetch all the group stats
1416 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1417 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1418 mprAggregateRequestBuilder.setTableId(arg0.getTableId().getValue());
1419 mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1420 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1421 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1422 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1424 FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder);
1426 // Set request body to main multipart request
1427 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1428 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1430 // Send the request, no cookies associated, use any connection
1431 LOG.debug("Send request to the switch :{}", multipartRequestAggregateCaseBuilder.build().toString());
1432 this.messageService.multipartRequest(mprInput.build(), null);
1434 // Prepare rpc return output. Set xid and send it back.
1435 GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder output = new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder();
1436 output.setTransactionId(generateTransactionId(xid));
1438 Collection<RpcError> errors = Collections.emptyList();
1439 RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> rpcResult = Rpcs.getRpcResult(true,
1440 output.build(), errors);
1441 return Futures.immediateFuture(rpcResult);
1445 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
1446 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput arg0) {
1448 // Generate xid to associate it with the request
1449 Long xid = this.getSessionContext().getNextXid();
1452 "Prepare aggregate statistics request to get aggregate stats for flows matching {} and installed in flow tables {} - Transaction id - {}",
1453 arg0.getMatch().toString(), arg0.getTableId(), xid);
1455 // Create multipart request header
1456 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1457 mprInput.setType(MultipartType.OFPMPAGGREGATE);
1458 mprInput.setVersion(version);
1459 mprInput.setXid(xid);
1460 mprInput.setFlags(new MultipartRequestFlags(false));
1462 // Create multipart request body for fetch all the group stats
1463 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1464 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1465 mprAggregateRequestBuilder.setTableId(arg0.getTableId());
1466 mprAggregateRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1467 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1468 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1469 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1471 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprAggregateRequestBuilder,
1472 this.getSessionContext().getFeatures().getDatapathId());
1473 // TODO: repeating code
1474 if (version == OFConstants.OFP_VERSION_1_3) {
1475 mprAggregateRequestBuilder.setCookie(arg0.getCookie().getValue());
1476 mprAggregateRequestBuilder.setCookieMask(arg0.getCookieMask().getValue());
1477 mprAggregateRequestBuilder.setOutGroup(arg0.getOutGroup());
1480 // Set request body to main multipart request
1481 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1482 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1484 // Send the request, no cookies associated, use any connection
1485 LOG.debug("Send request to the switch :{}", multipartRequestAggregateCaseBuilder.build().toString());
1486 this.messageService.multipartRequest(mprInput.build(), null);
1488 // Prepare rpc return output. Set xid and send it back.
1489 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder output = new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
1490 output.setTransactionId(generateTransactionId(xid));
1492 Collection<RpcError> errors = Collections.emptyList();
1493 RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult = Rpcs.getRpcResult(true,
1494 output.build(), errors);
1495 return Futures.immediateFuture(rpcResult);
1499 public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(final GetFlowTablesStatisticsInput arg0) {
1500 // Generate xid to associate it with the request
1501 Long xid = this.getSessionContext().getNextXid();
1503 LOG.debug("Prepare flow table statistics request to get flow table stats for all tables "
1504 + "from node {}- Transaction id - {}", arg0.getNode(), xid);
1506 // Create multipart request header
1507 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1508 mprInput.setType(MultipartType.OFPMPTABLE);
1509 mprInput.setVersion(version);
1510 mprInput.setXid(xid);
1511 mprInput.setFlags(new MultipartRequestFlags(false));
1513 // Create multipart request body for fetch all the group stats
1514 MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
1515 MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
1516 multipartRequestTableBuilder.setEmpty(true);
1517 multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
1519 // Set request body to main multipart request
1520 mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
1522 // Send the request, no cookies associated, use any connection
1523 LOG.debug("Send request to the switch :{}", multipartRequestTableCaseBuilder.build().toString());
1524 this.messageService.multipartRequest(mprInput.build(), null);
1526 // Prepare rpc return output. Set xid and send it back.
1527 GetFlowTablesStatisticsOutputBuilder output = new GetFlowTablesStatisticsOutputBuilder();
1528 output.setTransactionId(generateTransactionId(xid));
1530 Collection<RpcError> errors = Collections.emptyList();
1531 RpcResult<GetFlowTablesStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1532 return Futures.immediateFuture(rpcResult);
1536 public Future<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> getAllQueuesStatisticsFromAllPorts(
1537 final GetAllQueuesStatisticsFromAllPortsInput arg0) {
1538 // Generate xid to associate it with the request
1539 Long xid = this.getSessionContext().getNextXid();
1542 "Prepare queue statistics request to collect stats for all queues attached to all the ports of node {} - TrasactionId - {}",
1543 arg0.getNode().getValue(), xid);
1545 // Create multipart request header
1546 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1547 mprInput.setType(MultipartType.OFPMPQUEUE);
1548 mprInput.setVersion(version);
1549 mprInput.setXid(xid);
1550 mprInput.setFlags(new MultipartRequestFlags(false));
1552 // Create multipart request body to fetch stats for all the port of the
1554 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1555 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1557 mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
1558 // Select all the ports
1559 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1561 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1563 // Set request body to main multipart request
1564 mprInput.setMultipartRequestBody(caseBuilder.build());
1566 // Send the request, no cookies associated, use any connection
1567 LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString());
1568 this.messageService.multipartRequest(mprInput.build(), null);
1570 // Prepare rpc return output. Set xid and send it back.
1571 GetAllQueuesStatisticsFromAllPortsOutputBuilder output = new GetAllQueuesStatisticsFromAllPortsOutputBuilder();
1572 output.setTransactionId(generateTransactionId(xid));
1573 output.setQueueIdAndStatisticsMap(null);
1575 Collection<RpcError> errors = Collections.emptyList();
1576 RpcResult<GetAllQueuesStatisticsFromAllPortsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1577 return Futures.immediateFuture(rpcResult);
1581 public Future<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> getAllQueuesStatisticsFromGivenPort(
1582 final GetAllQueuesStatisticsFromGivenPortInput arg0) {
1583 // Generate xid to associate it with the request
1584 Long xid = this.getSessionContext().getNextXid();
1586 LOG.debug("Prepare queue statistics request to collect stats for "
1587 + "all queues attached to given port {} of node {} - TrasactionId - {}", arg0.getNodeConnectorId()
1588 .toString(), arg0.getNode().getValue(), xid);
1590 // Create multipart request header
1591 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1592 mprInput.setType(MultipartType.OFPMPQUEUE);
1593 mprInput.setVersion(version);
1594 mprInput.setXid(xid);
1595 mprInput.setFlags(new MultipartRequestFlags(false));
1597 // Create multipart request body to fetch stats for all the port of the
1599 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1600 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1601 // Select all queues
1602 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1603 // Select specific port
1604 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1606 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1608 // Set request body to main multipart request
1609 mprInput.setMultipartRequestBody(caseBuilder.build());
1611 // Send the request, no cookies associated, use any connection
1612 LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString());
1613 this.messageService.multipartRequest(mprInput.build(), null);
1615 // Prepare rpc return output. Set xid and send it back.
1616 GetAllQueuesStatisticsFromGivenPortOutputBuilder output = new GetAllQueuesStatisticsFromGivenPortOutputBuilder();
1617 output.setTransactionId(generateTransactionId(xid));
1618 output.setQueueIdAndStatisticsMap(null);
1620 Collection<RpcError> errors = Collections.emptyList();
1621 RpcResult<GetAllQueuesStatisticsFromGivenPortOutput> rpcResult = Rpcs
1622 .getRpcResult(true, output.build(), errors);
1623 return Futures.immediateFuture(rpcResult);
1627 public Future<RpcResult<GetQueueStatisticsFromGivenPortOutput>> getQueueStatisticsFromGivenPort(
1628 final GetQueueStatisticsFromGivenPortInput arg0) {
1629 // Generate xid to associate it with the request
1630 Long xid = this.getSessionContext().getNextXid();
1632 LOG.debug("Prepare queue statistics request to collect stats for "
1633 + "given queue attached to given port {} of node {} - TrasactionId - {}", arg0.getQueueId().toString(),
1634 arg0.getNodeConnectorId().toString(), arg0.getNode().getValue(), xid);
1636 // Create multipart request header
1637 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1638 mprInput.setType(MultipartType.OFPMPQUEUE);
1639 mprInput.setVersion(version);
1640 mprInput.setXid(xid);
1641 mprInput.setFlags(new MultipartRequestFlags(false));
1643 // Create multipart request body to fetch stats for all the port of the
1645 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1646 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1647 // Select specific queue
1648 mprQueueBuilder.setQueueId(arg0.getQueueId().getValue());
1649 // Select specific port
1650 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1652 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1654 // Set request body to main multipart request
1655 mprInput.setMultipartRequestBody(caseBuilder.build());
1657 // Send the request, no cookies associated, use any connection
1658 LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString());
1659 this.messageService.multipartRequest(mprInput.build(), null);
1661 // Prepare rpc return output. Set xid and send it back.
1662 GetQueueStatisticsFromGivenPortOutputBuilder output = new GetQueueStatisticsFromGivenPortOutputBuilder();
1663 output.setTransactionId(generateTransactionId(xid));
1664 output.setQueueIdAndStatisticsMap(null);
1666 Collection<RpcError> errors = Collections.emptyList();
1667 RpcResult<GetQueueStatisticsFromGivenPortOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1668 return Futures.immediateFuture(rpcResult);
1675 * @param messageService
1676 * @return barrier result
1678 public static Future<RpcResult<BarrierOutput>> sendBarrier(
1679 SwitchConnectionDistinguisher cookie, SessionContext session,
1680 IMessageDispatchService messageService) {
1681 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
1682 barrierInput.setVersion(session.getFeatures().getVersion());
1683 barrierInput.setXid(session.getNextXid());
1684 return messageService.barrier(barrierInput.build(), cookie);