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 session.getbulkTransactionCache().put(new TransactionKey(xId), input);
261 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput.build(), cookie);
262 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null;
265 rpcResultFromOFLib = resultFromOFLib.get();
266 } catch (Exception ex) {
267 LOG.error(" Error while getting result for AddGroup RPC" + ex.getMessage());
270 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult();
272 AddGroupOutputBuilder addGroupOutput = new AddGroupOutputBuilder();
273 addGroupOutput.setTransactionId(updateGroupOutput.getTransactionId());
274 AddGroupOutput result = addGroupOutput.build();
276 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
277 RpcResult<AddGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
279 LOG.debug("Returning the Add Group RPC result to MD-SAL");
280 return Futures.immediateFuture(rpcResult);
284 public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
285 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
287 // For Meter provisioning, the SwitchConnectionDistinguisher is set to
289 // the request can be routed through any connection to the switch
291 SwitchConnectionDistinguisher cookie = null;
292 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
293 xId = session.getNextXid();
294 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
295 barrierInput.setVersion(version);
296 barrierInput.setXid(xId);
297 @SuppressWarnings("unused")
298 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
301 // Convert the AddMeterInput to MeterModInput
302 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
303 xId = session.getNextXid();
304 ofMeterModInput.setXid(xId);
306 if (null != rpcNotificationProviderService) {
307 MeterAddedBuilder meterMod = new MeterAddedBuilder(
308 (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter) input);
309 meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
310 meterMod.setMeterRef(input.getMeterRef());
311 rpcNotificationProviderService.publish(meterMod.build());
314 session.getbulkTransactionCache().put(new TransactionKey(xId), input);
315 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput.build(), cookie);
317 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null;
320 rpcResultFromOFLib = resultFromOFLib.get();
321 } catch (Exception ex) {
322 LOG.error(" Error while getting result for AddMeter RPC" + ex.getMessage());
325 UpdateMeterOutput updateMeterOutput = rpcResultFromOFLib.getResult();
327 AddMeterOutputBuilder addMeterOutput = new AddMeterOutputBuilder();
328 addMeterOutput.setTransactionId(updateMeterOutput.getTransactionId());
329 AddMeterOutput result = addMeterOutput.build();
331 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
332 RpcResult<AddMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
334 LOG.debug("Returning the Add Meter RPC result to MD-SAL");
335 return Futures.immediateFuture(rpcResult);
339 public Future<RpcResult<RemoveFlowOutput>> removeFlow(final RemoveFlowInput input) {
340 LOG.debug("Calling the removeFlow RPC method on MessageDispatchService");
342 // For Flow provisioning, the SwitchConnectionDistinguisher is set to
344 // the request can be routed through any connection to the switch
346 SwitchConnectionDistinguisher cookie = null;
347 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
348 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
349 xId = session.getNextXid();
350 barrierInput.setXid(xId);
351 barrierInput.setVersion(version);
352 @SuppressWarnings("unused")
353 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
356 // Convert the RemoveFlowInput to FlowModInput
357 FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(input, version, this.getSessionContext()
358 .getFeatures().getDatapathId());
359 xId = session.getNextXid();
360 ofFlowModInput.setXid(xId);
362 if (null != rpcNotificationProviderService) {
363 FlowRemovedBuilder removeFlow = new FlowRemovedBuilder(
364 (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) input);
365 removeFlow.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
366 removeFlow.setFlowRef(input.getFlowRef());
367 rpcNotificationProviderService.publish(removeFlow.build());
370 session.getbulkTransactionCache().put(new TransactionKey(xId), input);
371 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput.build(), cookie);
373 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null;
376 rpcResultFromOFLib = resultFromOFLib.get();
377 } catch (Exception ex) {
378 LOG.error(" Error while getting result for remove Flow RPC" + ex.getMessage());
381 UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult();
383 RemoveFlowOutputBuilder removeFlowOutput = new RemoveFlowOutputBuilder();
384 removeFlowOutput.setTransactionId(updateFlowOutput.getTransactionId());
385 RemoveFlowOutput result = removeFlowOutput.build();
387 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
388 RpcResult<RemoveFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
390 LOG.debug("Returning the Remove Flow RPC result to MD-SAL");
391 return Futures.immediateFuture(rpcResult);
395 public Future<RpcResult<RemoveGroupOutput>> removeGroup(final RemoveGroupInput input) {
396 LOG.debug("Calling the Remove Group RPC method on MessageDispatchService");
399 // For Flow provisioning, the SwitchConnectionDistinguisher is set to
401 // the request can be routed through any connection to the switch
403 SwitchConnectionDistinguisher cookie = null;
404 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
405 xId = session.getNextXid();
406 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
407 barrierInput.setVersion(version);
408 barrierInput.setXid(xId);
409 @SuppressWarnings("unused")
410 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
413 // Convert the RemoveGroupInput to GroupModInput
414 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(input, version, this.getSessionContext()
415 .getFeatures().getDatapathId());
416 xId = session.getNextXid();
417 ofGroupModInput.setXid(xId);
419 if (null != rpcNotificationProviderService) {
420 GroupRemovedBuilder groupMod = new GroupRemovedBuilder(
421 (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group) input);
422 groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
423 groupMod.setGroupRef(input.getGroupRef());
424 rpcNotificationProviderService.publish(groupMod.build());
427 session.getbulkTransactionCache().put(new TransactionKey(xId), input);
428 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput.build(), cookie);
430 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null;
433 rpcResultFromOFLib = resultFromOFLib.get();
434 } catch (Exception ex) {
435 LOG.error(" Error while getting result for RemoveGroup RPC" + ex.getMessage());
438 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult();
440 RemoveGroupOutputBuilder removeGroupOutput = new RemoveGroupOutputBuilder();
441 removeGroupOutput.setTransactionId(updateGroupOutput.getTransactionId());
442 RemoveGroupOutput result = removeGroupOutput.build();
444 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
445 RpcResult<RemoveGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
447 LOG.debug("Returning the Remove Group RPC result to MD-SAL");
448 return Futures.immediateFuture(rpcResult);
452 public Future<RpcResult<RemoveMeterOutput>> removeMeter(final RemoveMeterInput input) {
453 LOG.debug("Calling the Remove MeterMod RPC method on MessageDispatchService");
456 // For Meter provisioning, the SwitchConnectionDistinguisher is set to
458 // the request can be routed through any connection to the switch
459 SwitchConnectionDistinguisher cookie = null;
460 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
461 xId = session.getNextXid();
462 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
463 barrierInput.setVersion(version);
464 barrierInput.setXid(xId);
465 @SuppressWarnings("unused")
466 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
469 // Convert the RemoveMeterInput to MeterModInput
470 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
471 xId = session.getNextXid();
472 ofMeterModInput.setXid(xId);
474 if (null != rpcNotificationProviderService) {
475 MeterRemovedBuilder meterMod = new MeterRemovedBuilder(
476 (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter) input);
477 meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
478 meterMod.setMeterRef(input.getMeterRef());
479 rpcNotificationProviderService.publish(meterMod.build());
482 session.getbulkTransactionCache().put(new TransactionKey(xId), input);
483 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput.build(), cookie);
485 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null;
488 rpcResultFromOFLib = resultFromOFLib.get();
489 } catch (Exception ex) {
490 LOG.error(" Error while getting result for RemoveMeter RPC" + ex.getMessage());
493 UpdateMeterOutput updatemeterOutput = rpcResultFromOFLib.getResult();
495 RemoveMeterOutputBuilder removeMeterOutput = new RemoveMeterOutputBuilder();
496 removeMeterOutput.setTransactionId(updatemeterOutput.getTransactionId());
497 RemoveMeterOutput result = removeMeterOutput.build();
499 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
500 RpcResult<RemoveMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
502 LOG.debug("Returning the Remove Meter RPC result to MD-SAL");
503 return Futures.immediateFuture(rpcResult);
507 public Future<RpcResult<Void>> transmitPacket(final TransmitPacketInput input) {
508 LOG.debug("TransmitPacket - {}", input);
509 // Convert TransmitPacket to PacketOutInput
510 PacketOutInput message = PacketOutConvertor.toPacketOutInput(input, version, sessionContext.getNextXid(),
511 sessionContext.getFeatures().getDatapathId());
513 // TODO VD NULL for yet - find how to translate cookie from
514 // TransmitPacketInput
515 // SwitchConnectionDistinguisher cookie = ( "what is need to do" )
516 // input.getCookie();
517 SwitchConnectionDistinguisher cookie = null;
519 LOG.debug("Calling the transmitPacket RPC method");
520 return messageService.packetOut(message, cookie);
523 private FlowModInputBuilder toFlowModInputBuilder(final Flow source) {
524 FlowModInputBuilder target = new FlowModInputBuilder();
525 target.setCookie(source.getCookie().getValue());
526 target.setIdleTimeout(source.getIdleTimeout());
527 target.setHardTimeout(source.getHardTimeout());
528 target.setMatch(toMatch(source.getMatch()));
533 private Match toMatch(final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
534 MatchBuilder target = new MatchBuilder();
536 target.setMatchEntries(toMatchEntries(match));
541 private List<MatchEntries> toMatchEntries(
542 final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
543 List<MatchEntries> entries = new ArrayList<>();
549 public Future<RpcResult<UpdateFlowOutput>> updateFlow(final UpdateFlowInput input) {
550 LOG.debug("Calling the updateFlow RPC method on MessageDispatchService");
552 // use primary connection
553 SwitchConnectionDistinguisher cookie = null;
555 OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> task =
556 OFRpcTaskFactory.createUpdateFlowTask(maxTimeout, maxTimeoutUnit, rpcTaskHelper);
557 rpcTaskHelper.initTask(task, input, cookie);
558 OFSessionUtil.getSessionManager().getRpcPool().submit(task);
560 return task.getResult();
564 public Future<RpcResult<UpdateGroupOutput>> updateGroup(final UpdateGroupInput input) {
565 LOG.debug("Calling the update Group Mod RPC method on MessageDispatchService");
568 // For Flow provisioning, the SwitchConnectionDistinguisher is set to
570 // the request can be routed through any connection to the switch
572 SwitchConnectionDistinguisher cookie = null;
573 if (Objects.firstNonNull(input.getUpdatedGroup().isBarrier(), Boolean.FALSE)) {
574 xId = session.getNextXid();
575 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
576 barrierInput.setVersion(version);
577 barrierInput.setXid(xId);
578 @SuppressWarnings("unused")
579 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
582 // Convert the UpdateGroupInput to GroupModInput
583 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(input.getUpdatedGroup(), version, this
584 .getSessionContext().getFeatures().getDatapathId());
585 xId = session.getNextXid();
586 ofGroupModInput.setXid(xId);
588 if (null != rpcNotificationProviderService) {
589 GroupUpdatedBuilder groupMod = new GroupUpdatedBuilder(input.getUpdatedGroup());
590 groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
591 groupMod.setGroupRef(input.getGroupRef());
592 rpcNotificationProviderService.publish(groupMod.build());
595 session.getbulkTransactionCache().put(new TransactionKey(xId), input);
596 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput.build(), cookie);
598 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null;
601 rpcResultFromOFLib = resultFromOFLib.get();
602 } catch (Exception ex) {
603 LOG.error(" Error while getting result for updateGroup RPC" + ex.getMessage());
606 UpdateGroupOutput updateGroupOutputOFLib = rpcResultFromOFLib.getResult();
608 UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder();
609 updateGroupOutput.setTransactionId(updateGroupOutputOFLib.getTransactionId());
610 UpdateGroupOutput result = updateGroupOutput.build();
612 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
613 RpcResult<UpdateGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
615 LOG.debug("Returning the Update Group RPC result to MD-SAL");
616 return Futures.immediateFuture(rpcResult);
620 public Future<RpcResult<UpdateMeterOutput>> updateMeter(final UpdateMeterInput input) {
621 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
624 // For Meter provisioning, the SwitchConnectionDistinguisher is set to
626 // the request can be routed through any connection to the switch
627 SwitchConnectionDistinguisher cookie = null;
628 if (Objects.firstNonNull(input.getUpdatedMeter().isBarrier(), Boolean.FALSE)) {
629 xId = session.getNextXid();
630 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
631 barrierInput.setVersion(version);
632 barrierInput.setXid(xId);
633 @SuppressWarnings("unused")
634 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
637 // Convert the UpdateMeterInput to MeterModInput
638 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input.getUpdatedMeter(), version);
639 xId = session.getNextXid();
640 ofMeterModInput.setXid(xId);
642 if (null != rpcNotificationProviderService) {
643 MeterUpdatedBuilder meterMod = new MeterUpdatedBuilder(input.getUpdatedMeter());
644 meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
645 meterMod.setMeterRef(input.getMeterRef());
646 rpcNotificationProviderService.publish(meterMod.build());
649 session.getbulkTransactionCache().put(new TransactionKey(xId), input);
650 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput.build(), cookie);
652 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null;
655 rpcResultFromOFLib = resultFromOFLib.get();
656 } catch (Exception ex) {
657 LOG.error(" Error while getting result for UpdateMeter RPC" + ex.getMessage());
660 UpdateMeterOutput updateMeterOutputFromOFLib = rpcResultFromOFLib.getResult();
662 UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder();
663 updateMeterOutput.setTransactionId(updateMeterOutputFromOFLib.getTransactionId());
664 UpdateMeterOutput result = updateMeterOutput.build();
666 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
667 RpcResult<UpdateMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
669 LOG.debug("Returning the Update Meter RPC result to MD-SAL");
670 return Futures.immediateFuture(rpcResult);
674 public NodeId getNodeId() {
679 * Methods for requesting statistics from switch
682 public Future<RpcResult<GetAllGroupStatisticsOutput>> getAllGroupStatistics(final GetAllGroupStatisticsInput input) {
684 GetAllGroupStatisticsOutputBuilder output = new GetAllGroupStatisticsOutputBuilder();
685 Collection<RpcError> errors = Collections.emptyList();
687 if (version == OFConstants.OFP_VERSION_1_0) {
688 output.setTransactionId(null);
689 output.setGroupStats(null);
691 RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
692 return Futures.immediateFuture(rpcResult);
694 // Generate xid to associate it with the request
695 Long xid = this.getSessionContext().getNextXid();
697 LOG.debug("Prepare statistics request for all the groups - Transaction id - {}", xid);
699 // Create multipart request header
700 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
701 mprInput.setType(MultipartType.OFPMPGROUP);
702 mprInput.setVersion(version);
703 mprInput.setXid(xid);
704 mprInput.setFlags(new MultipartRequestFlags(false));
706 // Create multipart request body for fetch all the group stats
707 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
708 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
709 mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(Group.OFPGALL.getIntValue())));
710 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
712 // Set request body to main multipart request
713 mprInput.setMultipartRequestBody(caseBuilder.build());
715 // Send the request, no cookies associated, use any connection
716 LOG.debug("Send group statistics request to the switch :{}", mprGroupBuild);
717 this.messageService.multipartRequest(mprInput.build(), null);
719 // Prepare rpc return output. Set xid and send it back.
720 LOG.debug("Return results and transaction id back to caller");
721 output.setTransactionId(generateTransactionId(xid));
722 output.setGroupStats(null);
724 RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
725 return Futures.immediateFuture(rpcResult);
730 public Future<RpcResult<GetGroupDescriptionOutput>> getGroupDescription(final GetGroupDescriptionInput input) {
732 GetGroupDescriptionOutputBuilder output = new GetGroupDescriptionOutputBuilder();
733 Collection<RpcError> errors = Collections.emptyList();
735 if (version == OFConstants.OFP_VERSION_1_0) {
736 output.setTransactionId(null);
737 output.setGroupDescStats(null);
739 RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
740 return Futures.immediateFuture(rpcResult);
742 // Generate xid to associate it with the request
743 Long xid = this.getSessionContext().getNextXid();
745 LOG.debug("Prepare group description statistics request - Transaction id - {}", xid);
747 // Create multipart request header
748 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
749 mprInput.setType(MultipartType.OFPMPGROUPDESC);
750 mprInput.setVersion(version);
751 mprInput.setXid(xid);
752 mprInput.setFlags(new MultipartRequestFlags(false));
754 // Create multipart request body for fetch all the group description
756 MultipartRequestGroupDescCaseBuilder mprGroupDescBuild = new MultipartRequestGroupDescCaseBuilder();
758 // Set request body to main multipart request
759 mprInput.setMultipartRequestBody(mprGroupDescBuild.build());
761 // Send the request, no cookies associated, use any connection
762 LOG.debug("Send group desciption statistics request to switch : {}", mprGroupDescBuild);
763 this.messageService.multipartRequest(mprInput.build(), null);
765 // Prepare rpc return output. Set xid and send it back.
766 LOG.debug("Return results and transaction id back to caller");
767 output.setTransactionId(generateTransactionId(xid));
768 output.setGroupDescStats(null);
770 RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
771 return Futures.immediateFuture(rpcResult);
776 public Future<RpcResult<GetGroupFeaturesOutput>> getGroupFeatures(final GetGroupFeaturesInput input) {
778 GetGroupFeaturesOutputBuilder output = new GetGroupFeaturesOutputBuilder();
779 Collection<RpcError> errors = Collections.emptyList();
781 if (version == OFConstants.OFP_VERSION_1_0) {
782 output.setTransactionId(null);
784 RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
785 return Futures.immediateFuture(rpcResult);
787 // Generate xid to associate it with the request
788 Long xid = this.getSessionContext().getNextXid();
790 LOG.debug("Prepare group features statistics request - Transaction id - {}", xid);
792 // Create multipart request header
793 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
794 mprInput.setType(MultipartType.OFPMPGROUPFEATURES);
795 mprInput.setVersion(version);
796 mprInput.setXid(xid);
797 mprInput.setFlags(new MultipartRequestFlags(false));
799 // Create multipart request body for fetch all the group description
801 MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild = new MultipartRequestGroupFeaturesCaseBuilder();
803 // Set request body to main multipart request
804 mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
806 // Send the request, no cookies associated, use any connection
807 LOG.debug("Send group features statistics request :{}", mprGroupFeaturesBuild);
808 this.messageService.multipartRequest(mprInput.build(), null);
810 // Prepare rpc return output. Set xid and send it back.
811 LOG.debug("Return results and transaction id back to caller");
812 output.setTransactionId(generateTransactionId(xid));
814 RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
815 return Futures.immediateFuture(rpcResult);
819 public Future<RpcResult<GetGroupStatisticsOutput>> getGroupStatistics(final GetGroupStatisticsInput input) {
821 GetGroupStatisticsOutputBuilder output = new GetGroupStatisticsOutputBuilder();
822 Collection<RpcError> errors = Collections.emptyList();
824 if (version == OFConstants.OFP_VERSION_1_0) {
825 output.setTransactionId(null);
826 output.setGroupStats(null);
828 RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
829 return Futures.immediateFuture(rpcResult);
831 // Generate xid to associate it with the request
832 Long xid = this.getSessionContext().getNextXid();
834 LOG.debug("Prepare statistics request for node {} group ({}) - Transaction id - {}", input.getNode(),
835 input.getGroupId(), xid);
837 // Create multipart request header
838 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
839 mprInput.setType(MultipartType.OFPMPGROUP);
840 mprInput.setVersion(version);
841 mprInput.setXid(xid);
842 mprInput.setFlags(new MultipartRequestFlags(false));
844 // Create multipart request body for fetch all the group stats
845 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
846 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
847 mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
848 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
850 // Set request body to main multipart request
851 mprInput.setMultipartRequestBody(caseBuilder.build());
853 // Send the request, no cookies associated, use any connection
854 LOG.debug("Send group statistics request :{}", mprGroupBuild);
855 this.messageService.multipartRequest(mprInput.build(), null);
857 // Prepare rpc return output. Set xid and send it back.
858 LOG.debug("Return results and transaction id back to caller");
859 output.setTransactionId(generateTransactionId(xid));
860 output.setGroupStats(null);
862 RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
863 return Futures.immediateFuture(rpcResult);
867 public Future<RpcResult<GetAllMeterConfigStatisticsOutput>> getAllMeterConfigStatistics(
868 final GetAllMeterConfigStatisticsInput input) {
870 GetAllMeterConfigStatisticsOutputBuilder output = new GetAllMeterConfigStatisticsOutputBuilder();
871 Collection<RpcError> errors = Collections.emptyList();
873 if (version == OFConstants.OFP_VERSION_1_0) {
874 output.setTransactionId(null);
875 output.setMeterConfigStats(null);
877 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
878 return Futures.immediateFuture(rpcResult);
881 // Generate xid to associate it with the request
882 Long xid = this.getSessionContext().getNextXid();
884 LOG.debug("Prepare config request for all the meters - Transaction id - {}", xid);
886 // Create multipart request header
887 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
888 mprInput.setType(MultipartType.OFPMPMETERCONFIG);
889 mprInput.setVersion(version);
890 mprInput.setXid(xid);
891 mprInput.setFlags(new MultipartRequestFlags(false));
893 // Create multipart request body for fetch all the meter stats
894 MultipartRequestMeterConfigCaseBuilder caseBuilder = new MultipartRequestMeterConfigCaseBuilder();
895 MultipartRequestMeterConfigBuilder mprMeterConfigBuild = new MultipartRequestMeterConfigBuilder();
896 mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
897 caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
899 // Set request body to main multipart request
900 mprInput.setMultipartRequestBody(caseBuilder.build());
902 // Send the request, no cookies associated, use any connection
903 LOG.debug("Send meter statistics request :{}", mprMeterConfigBuild);
904 this.messageService.multipartRequest(mprInput.build(), null);
906 // Prepare rpc return output. Set xid and send it back.
907 LOG.debug("Return results and transaction id back to caller");
908 output.setTransactionId(generateTransactionId(xid));
909 output.setMeterConfigStats(null);
911 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
912 return Futures.immediateFuture(rpcResult);
916 public Future<RpcResult<GetAllMeterStatisticsOutput>> getAllMeterStatistics(final GetAllMeterStatisticsInput input) {
918 GetAllMeterStatisticsOutputBuilder output = new GetAllMeterStatisticsOutputBuilder();
919 Collection<RpcError> errors = Collections.emptyList();
921 if (version == OFConstants.OFP_VERSION_1_0) {
922 output.setTransactionId(null);
923 output.setMeterStats(null);
925 RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
926 return Futures.immediateFuture(rpcResult);
928 // Generate xid to associate it with the request
929 Long xid = this.getSessionContext().getNextXid();
931 LOG.debug("Prepare statistics request for all the meters - Transaction id - {}", xid);
933 // Create multipart request header
934 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
935 mprInput.setType(MultipartType.OFPMPMETER);
936 mprInput.setVersion(version);
937 mprInput.setXid(xid);
938 mprInput.setFlags(new MultipartRequestFlags(false));
940 // Create multipart request body for fetch all the meter stats
941 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
942 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
943 mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
944 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
946 // Set request body to main multipart request
947 mprInput.setMultipartRequestBody(caseBuilder.build());
949 // Send the request, no cookies associated, use any connection
950 LOG.debug("Send meter statistics request :{}", mprMeterBuild);
951 this.messageService.multipartRequest(mprInput.build(), null);
953 // Prepare rpc return output. Set xid and send it back.
954 LOG.debug("Return results and transaction id back to caller");
955 output.setTransactionId(generateTransactionId(xid));
956 output.setMeterStats(null);
958 RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
959 return Futures.immediateFuture(rpcResult);
963 public Future<RpcResult<GetMeterFeaturesOutput>> getMeterFeatures(final GetMeterFeaturesInput input) {
965 GetMeterFeaturesOutputBuilder output = new GetMeterFeaturesOutputBuilder();
966 Collection<RpcError> errors = Collections.emptyList();
968 if (version == OFConstants.OFP_VERSION_1_0) {
969 output.setTransactionId(null);
971 RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
972 return Futures.immediateFuture(rpcResult);
974 // Generate xid to associate it with the request
975 Long xid = this.getSessionContext().getNextXid();
977 LOG.debug("Prepare features statistics request for all the meters - Transaction id - {}", xid);
979 // Create multipart request header
980 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
981 mprInput.setType(MultipartType.OFPMPMETERFEATURES);
982 mprInput.setVersion(version);
983 mprInput.setXid(xid);
984 mprInput.setFlags(new MultipartRequestFlags(false));
986 // Create multipart request body for fetch all the group description
988 MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild = new MultipartRequestMeterFeaturesCaseBuilder();
990 // Set request body to main multipart request
991 mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
993 // Send the request, no cookies associated, use any connection
994 LOG.debug("Send meter features statistics request :{}", mprMeterFeaturesBuild);
995 this.messageService.multipartRequest(mprInput.build(), null);
997 // Prepare rpc return output. Set xid and send it back.
998 LOG.debug("Return results and transaction id back to caller");
999 output.setTransactionId(generateTransactionId(xid));
1001 RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1002 return Futures.immediateFuture(rpcResult);
1006 public Future<RpcResult<GetMeterStatisticsOutput>> getMeterStatistics(final GetMeterStatisticsInput input) {
1008 GetMeterStatisticsOutputBuilder output = new GetMeterStatisticsOutputBuilder();
1009 Collection<RpcError> errors = Collections.emptyList();
1011 if (version == OFConstants.OFP_VERSION_1_0) {
1012 output.setTransactionId(null);
1013 output.setMeterStats(null);
1015 RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1016 return Futures.immediateFuture(rpcResult);
1019 // Generate xid to associate it with the request
1020 Long xid = this.getSessionContext().getNextXid();
1022 LOG.debug("Preprae statistics request for Meter ({}) - Transaction id - {}", input.getMeterId().getValue(), xid);
1024 // Create multipart request header
1025 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1026 mprInput.setType(MultipartType.OFPMPMETER);
1027 mprInput.setVersion(version);
1028 mprInput.setXid(xid);
1029 mprInput.setFlags(new MultipartRequestFlags(false));
1031 // Create multipart request body for fetch all the meter stats
1032 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
1033 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
1034 // Select specific meter
1035 mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
1036 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
1038 // Set request body to main multipart request
1039 mprInput.setMultipartRequestBody(caseBuilder.build());
1041 // Send the request, no cookies associated, use any connection
1042 LOG.debug("Send meter statistics request :{}", mprMeterBuild);
1043 this.messageService.multipartRequest(mprInput.build(), null);
1045 // Prepare rpc return output. Set xid and send it back.
1046 LOG.debug("Return results and transaction id back to caller");
1047 output.setTransactionId(generateTransactionId(xid));
1048 output.setMeterStats(null);
1050 RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1051 return Futures.immediateFuture(rpcResult);
1055 public Future<RpcResult<GetAllNodeConnectorsStatisticsOutput>> getAllNodeConnectorsStatistics(
1056 final GetAllNodeConnectorsStatisticsInput arg0) {
1058 // Generate xid to associate it with the request
1059 Long xid = this.getSessionContext().getNextXid();
1061 LOG.debug("Prepare port statistics request for all ports of node {} - TrasactionId - {}", arg0.getNode()
1064 // Create multipart request header
1065 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1066 mprInput.setType(MultipartType.OFPMPPORTSTATS);
1067 mprInput.setVersion(version);
1068 mprInput.setXid(xid);
1069 mprInput.setFlags(new MultipartRequestFlags(false));
1071 // Create multipart request body to fetch stats for all the port of the
1073 MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
1074 MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
1076 mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
1077 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1079 // Set request body to main multipart request
1080 mprInput.setMultipartRequestBody(caseBuilder.build());
1082 // Send the request, no cookies associated, use any connection
1083 LOG.debug("Send port statistics request :{}", mprPortStatsBuilder.build().toString());
1084 this.messageService.multipartRequest(mprInput.build(), null);
1086 // Prepare rpc return output. Set xid and send it back.
1087 GetAllNodeConnectorsStatisticsOutputBuilder output = new GetAllNodeConnectorsStatisticsOutputBuilder();
1088 output.setTransactionId(generateTransactionId(xid));
1090 Collection<RpcError> errors = Collections.emptyList();
1091 RpcResult<GetAllNodeConnectorsStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1092 return Futures.immediateFuture(rpcResult);
1096 public Future<RpcResult<GetNodeConnectorStatisticsOutput>> getNodeConnectorStatistics(
1097 final GetNodeConnectorStatisticsInput arg0) {
1098 // Generate xid to associate it with the request
1099 Long xid = this.getSessionContext().getNextXid();
1101 LOG.debug("Prepare port statistics request for port {} of node {} - TrasactionId - {}",
1102 arg0.getNodeConnectorId(), arg0.getNode().getValue(), xid);
1104 // Create multipart request header
1105 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1106 mprInput.setType(MultipartType.OFPMPPORTSTATS);
1107 mprInput.setVersion(version);
1108 mprInput.setXid(xid);
1109 mprInput.setFlags(new MultipartRequestFlags(false));
1111 // Create multipart request body to fetch stats for all the port of the
1113 MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
1114 MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
1116 // Set specific port
1118 .setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1119 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1121 // Set request body to main multipart request
1122 mprInput.setMultipartRequestBody(caseBuilder.build());
1124 // Send the request, no cookies associated, use any connection
1125 LOG.debug("Send port statistics request :{}", mprPortStatsBuilder.build().toString());
1126 this.messageService.multipartRequest(mprInput.build(), null);
1128 // Prepare rpc return output. Set xid and send it back.
1129 GetNodeConnectorStatisticsOutputBuilder output = new GetNodeConnectorStatisticsOutputBuilder();
1130 output.setTransactionId(generateTransactionId(xid));
1132 Collection<RpcError> errors = Collections.emptyList();
1133 RpcResult<GetNodeConnectorStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1134 return Futures.immediateFuture(rpcResult);
1137 private TransactionId generateTransactionId(final Long xid) {
1138 String stringXid = xid.toString();
1139 BigInteger bigIntXid = new BigInteger(stringXid);
1140 return new TransactionId(bigIntXid);
1145 public Future<RpcResult<UpdatePortOutput>> updatePort(final UpdatePortInput input) {
1146 PortModInput ofPortModInput = null;
1147 RpcResult<UpdatePortOutput> rpcResultFromOFLib = null;
1149 // For Flow provisioning, the SwitchConnectionDistinguisher is set to
1151 // the request can be routed through any connection to the switch
1153 SwitchConnectionDistinguisher cookie = null;
1155 // NSF sends a list of port and the ModelDrivenSwitch will
1156 // send one port at a time towards the switch ( mutiple RPCs calls)
1157 List<Port> inputPorts = input.getUpdatedPort().getPort().getPort();
1159 // Get the Xid. The same Xid has to be sent in all the RPCs
1160 Long Xid = sessionContext.getNextXid();
1162 for (Port inputPort : inputPorts) {
1164 // Convert the UpdateGroupInput to GroupModInput
1165 ofPortModInput = PortConvertor.toPortModInput(inputPort, version);
1167 // Insert the Xid ( transaction Id) before calling the RPC on the
1170 PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
1171 mdInput.setXid(Xid);
1173 LOG.debug("Calling the PortMod RPC method on MessageDispatchService");
1174 Future<RpcResult<UpdatePortOutput>> resultFromOFLib = messageService.portMod(mdInput.build(), cookie);
1177 rpcResultFromOFLib = resultFromOFLib.get();
1178 } catch (Exception ex) {
1179 LOG.error(" Error while getting result for updatePort RPC" + ex.getMessage());
1182 // The Future response value for all the RPCs except the last one is
1186 // Extract the Xid only from the Future for the last RPC and
1187 // send it back to the NSF
1188 UpdatePortOutput updatePortOutputOFLib = rpcResultFromOFLib.getResult();
1190 UpdatePortOutputBuilder updatePortOutput = new UpdatePortOutputBuilder();
1191 updatePortOutput.setTransactionId(updatePortOutputOFLib.getTransactionId());
1192 UpdatePortOutput result = updatePortOutput.build();
1194 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
1195 RpcResult<UpdatePortOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
1197 LOG.debug("Returning the Update Group RPC result to MD-SAL");
1198 return Futures.immediateFuture(rpcResult);
1203 public Future<RpcResult<UpdateTableOutput>> updateTable(final UpdateTableInput input) {
1205 // Get the Xid. The same Xid has to be sent in all the Multipart
1207 Long xid = this.getSessionContext().getNextXid();
1209 LOG.debug("Prepare the Multipart Table Mod requests for Transaction Id {} ", xid);
1211 // Create multipart request header
1212 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1213 mprInput.setType(MultipartType.OFPMPTABLEFEATURES);
1214 mprInput.setVersion((short) 0x04);
1215 mprInput.setXid(xid);
1217 // Convert the list of all MD-SAL table feature object into OF library
1219 List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input.getUpdatedTable());
1221 MultipartRequestTableFeaturesCaseBuilder caseRequest = new MultipartRequestTableFeaturesCaseBuilder();
1222 MultipartRequestTableFeaturesBuilder tableFeaturesRequest = new MultipartRequestTableFeaturesBuilder();
1224 mprInput.setFlags(new MultipartRequestFlags(false));
1226 tableFeaturesRequest.setTableFeatures(ofTableFeatureList);
1228 // Set request body to main multipart request
1229 caseRequest.setMultipartRequestTableFeatures(tableFeaturesRequest.build());
1230 mprInput.setMultipartRequestBody(caseRequest.build());
1232 // Send the request, no cookies associated, use any connection
1233 LOG.debug("Send Table Feature request :{}", ofTableFeatureList);
1234 this.messageService.multipartRequest(mprInput.build(), null);
1236 // Extract the Xid only from the Future for the last RPC and
1237 // send it back to the NSF
1238 LOG.debug("Returning the result and transaction id to NSF");
1239 LOG.debug("Return results and transaction id back to caller");
1240 UpdateTableOutputBuilder output = new UpdateTableOutputBuilder();
1241 output.setTransactionId(generateTransactionId(xid));
1243 Collection<RpcError> errors = Collections.emptyList();
1244 RpcResult<UpdateTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1245 return Futures.immediateFuture(rpcResult);
1249 public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
1250 final GetAllFlowStatisticsFromFlowTableInput arg0) {
1252 // Generate xid to associate it with the request
1253 Long xid = this.getSessionContext().getNextXid();
1255 LOG.debug("Prepare statistics request to get flow stats for switch tables {} - Transaction id - {}", arg0
1256 .getTableId().getValue(), xid);
1258 // Create multipart request header
1259 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1260 mprInput.setType(MultipartType.OFPMPFLOW);
1261 mprInput.setVersion(version);
1262 mprInput.setXid(xid);
1263 mprInput.setFlags(new MultipartRequestFlags(false));
1265 // Create multipart request body for fetch all the group stats
1266 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1267 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1268 mprFlowRequestBuilder.setTableId(arg0.getTableId().getValue());
1269 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1270 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1271 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1272 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1273 FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
1275 // Set request body to main multipart request
1276 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1277 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1279 // Send the request, no cookies associated, use any connection
1280 LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder);
1281 this.messageService.multipartRequest(mprInput.build(), null);
1283 // Prepare rpc return output. Set xid and send it back.
1284 LOG.debug("Return results and transaction id back to caller");
1285 GetAllFlowStatisticsFromFlowTableOutputBuilder output = new GetAllFlowStatisticsFromFlowTableOutputBuilder();
1286 output.setTransactionId(generateTransactionId(xid));
1287 output.setFlowAndStatisticsMapList(null);
1289 Collection<RpcError> errors = Collections.emptyList();
1290 RpcResult<GetAllFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1291 return Futures.immediateFuture(rpcResult);
1295 public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
1296 final GetAllFlowsStatisticsFromAllFlowTablesInput arg0) {
1298 // Generate xid to associate it with the request
1299 Long xid = this.getSessionContext().getNextXid();
1301 LOG.debug("Prepare statistics request to get flow stats of all switch tables - Transaction id - {}", xid);
1303 // Create multipart request header
1304 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1305 mprInput.setType(MultipartType.OFPMPFLOW);
1306 mprInput.setVersion(version);
1307 mprInput.setXid(xid);
1308 mprInput.setFlags(new MultipartRequestFlags(false));
1310 // Create multipart request body for fetch all the group stats
1311 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1312 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1313 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
1314 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1315 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1316 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1317 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1318 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1320 FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
1322 // Set request body to main multipart request
1323 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1324 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1326 // Send the request, no cookies associated, use any connection
1327 LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder);
1328 this.messageService.multipartRequest(mprInput.build(), null);
1330 // Prepare rpc return output. Set xid and send it back.
1331 GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder output = new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder();
1332 output.setTransactionId(generateTransactionId(xid));
1333 output.setFlowAndStatisticsMapList(null);
1335 Collection<RpcError> errors = Collections.emptyList();
1336 RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(),
1338 return Futures.immediateFuture(rpcResult);
1343 public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
1344 final GetFlowStatisticsFromFlowTableInput arg0) {
1345 // Generate xid to associate it with the request
1346 Long xid = this.getSessionContext().getNextXid();
1348 LOG.debug("Prepare statistics request to get stats for flow {} for switch tables {} - Transaction id - {}",
1349 arg0.getMatch().toString(), arg0.getTableId(), xid);
1351 // Create multipart request header
1352 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1353 mprInput.setType(MultipartType.OFPMPFLOW);
1354 mprInput.setVersion(version);
1355 mprInput.setXid(xid);
1356 mprInput.setFlags(new MultipartRequestFlags(false));
1358 // Create multipart request body for fetch all the group stats
1359 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1360 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1361 mprFlowRequestBuilder.setTableId(arg0.getTableId());
1363 if (arg0.getOutPort() != null)
1364 mprFlowRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1366 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1368 if (arg0.getOutGroup() != null)
1369 mprFlowRequestBuilder.setOutGroup(arg0.getOutGroup());
1371 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1373 if (arg0.getCookie() != null)
1374 mprFlowRequestBuilder.setCookie(arg0.getCookie().getValue());
1376 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1378 if (arg0.getCookieMask() != null)
1379 mprFlowRequestBuilder.setCookieMask(arg0.getCookieMask().getValue());
1381 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1383 // convert and inject match
1384 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprFlowRequestBuilder,
1385 this.getSessionContext().getFeatures().getDatapathId());
1387 // Set request body to main multipart request
1388 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1389 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1391 // Send the request, no cookies associated, use any connection
1392 LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder);
1393 this.messageService.multipartRequest(mprInput.build(), null);
1395 // Prepare rpc return output. Set xid and send it back.
1396 GetFlowStatisticsFromFlowTableOutputBuilder output = new GetFlowStatisticsFromFlowTableOutputBuilder();
1397 output.setTransactionId(generateTransactionId(xid));
1398 output.setFlowAndStatisticsMapList(null);
1400 Collection<RpcError> errors = Collections.emptyList();
1401 RpcResult<GetFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1402 return Futures.immediateFuture(rpcResult);
1406 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
1407 final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput arg0) {
1408 // Generate xid to associate it with the request
1409 Long xid = this.getSessionContext().getNextXid();
1412 "Prepare aggregate flow statistics request to get aggregate flow stats for all the flow installed on switch table {} - Transaction id - {}",
1413 arg0.getTableId().getValue(), xid);
1415 // Create multipart request header
1416 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1417 mprInput.setType(MultipartType.OFPMPAGGREGATE);
1418 mprInput.setVersion(version);
1419 mprInput.setXid(xid);
1420 mprInput.setFlags(new MultipartRequestFlags(false));
1422 // Create multipart request body for fetch all the group stats
1423 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1424 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1425 mprAggregateRequestBuilder.setTableId(arg0.getTableId().getValue());
1426 mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1427 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1428 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1429 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1431 FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder);
1433 // Set request body to main multipart request
1434 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1435 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1437 // Send the request, no cookies associated, use any connection
1438 LOG.debug("Send request to the switch :{}", multipartRequestAggregateCaseBuilder.build().toString());
1439 this.messageService.multipartRequest(mprInput.build(), null);
1441 // Prepare rpc return output. Set xid and send it back.
1442 GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder output = new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder();
1443 output.setTransactionId(generateTransactionId(xid));
1445 Collection<RpcError> errors = Collections.emptyList();
1446 RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> rpcResult = Rpcs.getRpcResult(true,
1447 output.build(), errors);
1448 return Futures.immediateFuture(rpcResult);
1452 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
1453 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput arg0) {
1455 // Generate xid to associate it with the request
1456 Long xid = this.getSessionContext().getNextXid();
1459 "Prepare aggregate statistics request to get aggregate stats for flows matching {} and installed in flow tables {} - Transaction id - {}",
1460 arg0.getMatch().toString(), arg0.getTableId(), xid);
1462 // Create multipart request header
1463 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1464 mprInput.setType(MultipartType.OFPMPAGGREGATE);
1465 mprInput.setVersion(version);
1466 mprInput.setXid(xid);
1467 mprInput.setFlags(new MultipartRequestFlags(false));
1469 // Create multipart request body for fetch all the group stats
1470 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1471 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1472 mprAggregateRequestBuilder.setTableId(arg0.getTableId());
1473 mprAggregateRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1474 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1475 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1476 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1478 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprAggregateRequestBuilder,
1479 this.getSessionContext().getFeatures().getDatapathId());
1480 // TODO: repeating code
1481 if (version == OFConstants.OFP_VERSION_1_3) {
1482 mprAggregateRequestBuilder.setCookie(arg0.getCookie().getValue());
1483 mprAggregateRequestBuilder.setCookieMask(arg0.getCookieMask().getValue());
1484 mprAggregateRequestBuilder.setOutGroup(arg0.getOutGroup());
1487 // Set request body to main multipart request
1488 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1489 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1491 // Send the request, no cookies associated, use any connection
1492 LOG.debug("Send request to the switch :{}", multipartRequestAggregateCaseBuilder.build().toString());
1493 this.messageService.multipartRequest(mprInput.build(), null);
1495 // Prepare rpc return output. Set xid and send it back.
1496 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder output = new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
1497 output.setTransactionId(generateTransactionId(xid));
1499 Collection<RpcError> errors = Collections.emptyList();
1500 RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult = Rpcs.getRpcResult(true,
1501 output.build(), errors);
1502 return Futures.immediateFuture(rpcResult);
1506 public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(final GetFlowTablesStatisticsInput arg0) {
1507 // Generate xid to associate it with the request
1508 Long xid = this.getSessionContext().getNextXid();
1510 LOG.debug("Prepare flow table statistics request to get flow table stats for all tables "
1511 + "from node {}- Transaction id - {}", arg0.getNode(), xid);
1513 // Create multipart request header
1514 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1515 mprInput.setType(MultipartType.OFPMPTABLE);
1516 mprInput.setVersion(version);
1517 mprInput.setXid(xid);
1518 mprInput.setFlags(new MultipartRequestFlags(false));
1520 // Create multipart request body for fetch all the group stats
1521 MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
1522 MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
1523 multipartRequestTableBuilder.setEmpty(true);
1524 multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
1526 // Set request body to main multipart request
1527 mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
1529 // Send the request, no cookies associated, use any connection
1530 LOG.debug("Send request to the switch :{}", multipartRequestTableCaseBuilder.build().toString());
1531 this.messageService.multipartRequest(mprInput.build(), null);
1533 // Prepare rpc return output. Set xid and send it back.
1534 GetFlowTablesStatisticsOutputBuilder output = new GetFlowTablesStatisticsOutputBuilder();
1535 output.setTransactionId(generateTransactionId(xid));
1537 Collection<RpcError> errors = Collections.emptyList();
1538 RpcResult<GetFlowTablesStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1539 return Futures.immediateFuture(rpcResult);
1543 public Future<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> getAllQueuesStatisticsFromAllPorts(
1544 final GetAllQueuesStatisticsFromAllPortsInput arg0) {
1545 // Generate xid to associate it with the request
1546 Long xid = this.getSessionContext().getNextXid();
1549 "Prepare queue statistics request to collect stats for all queues attached to all the ports of node {} - TrasactionId - {}",
1550 arg0.getNode().getValue(), xid);
1552 // Create multipart request header
1553 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1554 mprInput.setType(MultipartType.OFPMPQUEUE);
1555 mprInput.setVersion(version);
1556 mprInput.setXid(xid);
1557 mprInput.setFlags(new MultipartRequestFlags(false));
1559 // Create multipart request body to fetch stats for all the port of the
1561 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1562 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1564 mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
1565 // Select all the ports
1566 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1568 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1570 // Set request body to main multipart request
1571 mprInput.setMultipartRequestBody(caseBuilder.build());
1573 // Send the request, no cookies associated, use any connection
1574 LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString());
1575 this.messageService.multipartRequest(mprInput.build(), null);
1577 // Prepare rpc return output. Set xid and send it back.
1578 GetAllQueuesStatisticsFromAllPortsOutputBuilder output = new GetAllQueuesStatisticsFromAllPortsOutputBuilder();
1579 output.setTransactionId(generateTransactionId(xid));
1580 output.setQueueIdAndStatisticsMap(null);
1582 Collection<RpcError> errors = Collections.emptyList();
1583 RpcResult<GetAllQueuesStatisticsFromAllPortsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1584 return Futures.immediateFuture(rpcResult);
1588 public Future<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> getAllQueuesStatisticsFromGivenPort(
1589 final GetAllQueuesStatisticsFromGivenPortInput arg0) {
1590 // Generate xid to associate it with the request
1591 Long xid = this.getSessionContext().getNextXid();
1593 LOG.debug("Prepare queue statistics request to collect stats for "
1594 + "all queues attached to given port {} of node {} - TrasactionId - {}", arg0.getNodeConnectorId()
1595 .toString(), arg0.getNode().getValue(), xid);
1597 // Create multipart request header
1598 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1599 mprInput.setType(MultipartType.OFPMPQUEUE);
1600 mprInput.setVersion(version);
1601 mprInput.setXid(xid);
1602 mprInput.setFlags(new MultipartRequestFlags(false));
1604 // Create multipart request body to fetch stats for all the port of the
1606 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1607 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1608 // Select all queues
1609 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1610 // Select specific port
1611 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1613 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1615 // Set request body to main multipart request
1616 mprInput.setMultipartRequestBody(caseBuilder.build());
1618 // Send the request, no cookies associated, use any connection
1619 LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString());
1620 this.messageService.multipartRequest(mprInput.build(), null);
1622 // Prepare rpc return output. Set xid and send it back.
1623 GetAllQueuesStatisticsFromGivenPortOutputBuilder output = new GetAllQueuesStatisticsFromGivenPortOutputBuilder();
1624 output.setTransactionId(generateTransactionId(xid));
1625 output.setQueueIdAndStatisticsMap(null);
1627 Collection<RpcError> errors = Collections.emptyList();
1628 RpcResult<GetAllQueuesStatisticsFromGivenPortOutput> rpcResult = Rpcs
1629 .getRpcResult(true, output.build(), errors);
1630 return Futures.immediateFuture(rpcResult);
1634 public Future<RpcResult<GetQueueStatisticsFromGivenPortOutput>> getQueueStatisticsFromGivenPort(
1635 final GetQueueStatisticsFromGivenPortInput arg0) {
1636 // Generate xid to associate it with the request
1637 Long xid = this.getSessionContext().getNextXid();
1639 LOG.debug("Prepare queue statistics request to collect stats for "
1640 + "given queue attached to given port {} of node {} - TrasactionId - {}", arg0.getQueueId().toString(),
1641 arg0.getNodeConnectorId().toString(), arg0.getNode().getValue(), xid);
1643 // Create multipart request header
1644 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1645 mprInput.setType(MultipartType.OFPMPQUEUE);
1646 mprInput.setVersion(version);
1647 mprInput.setXid(xid);
1648 mprInput.setFlags(new MultipartRequestFlags(false));
1650 // Create multipart request body to fetch stats for all the port of the
1652 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1653 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1654 // Select specific queue
1655 mprQueueBuilder.setQueueId(arg0.getQueueId().getValue());
1656 // Select specific port
1657 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1659 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1661 // Set request body to main multipart request
1662 mprInput.setMultipartRequestBody(caseBuilder.build());
1664 // Send the request, no cookies associated, use any connection
1665 LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString());
1666 this.messageService.multipartRequest(mprInput.build(), null);
1668 // Prepare rpc return output. Set xid and send it back.
1669 GetQueueStatisticsFromGivenPortOutputBuilder output = new GetQueueStatisticsFromGivenPortOutputBuilder();
1670 output.setTransactionId(generateTransactionId(xid));
1671 output.setQueueIdAndStatisticsMap(null);
1673 Collection<RpcError> errors = Collections.emptyList();
1674 RpcResult<GetQueueStatisticsFromGivenPortOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1675 return Futures.immediateFuture(rpcResult);
1682 * @param messageService
1683 * @return barrier result
1685 public static Future<RpcResult<BarrierOutput>> sendBarrier(
1686 SwitchConnectionDistinguisher cookie, SessionContext session,
1687 IMessageDispatchService messageService) {
1688 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
1689 barrierInput.setVersion(session.getFeatures().getVersion());
1690 barrierInput.setXid(session.getNextXid());
1691 return messageService.barrier(barrierInput.build(), cookie);