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.util.FlowCreatorUtil;
34 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutputBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutputBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemovedBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdatedBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutputBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutputBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutputBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutputBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutputBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemovedBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdatedBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutputBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutputBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutputBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutputBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Group;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Meter;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.MatchBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;
149 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;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutputBuilder;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInput;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutputBuilder;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInput;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutput;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutputBuilder;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutputBuilder;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInput;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutputBuilder;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInput;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutputBuilder;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder;
172 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
173 import org.opendaylight.yangtools.yang.common.RpcError;
174 import org.opendaylight.yangtools.yang.common.RpcResult;
175 import org.slf4j.Logger;
177 import com.google.common.base.Objects;
178 import com.google.common.util.concurrent.Futures;
179 import com.google.common.util.concurrent.JdkFutureAdapters;
180 import com.google.common.util.concurrent.ListenableFuture;
183 * RPC implementation of MD-switch
185 public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
187 private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(ModelDrivenSwitchImpl.class);
188 private final NodeId nodeId;
189 private final IMessageDispatchService messageService;
190 private short version = 0;
191 private NotificationProviderService rpcNotificationProviderService;
192 private OFRpcTaskContext rpcTaskContext;
194 // TODO:read timeout from configSubsystem
195 protected long maxTimeout = 1000;
196 protected TimeUnit maxTimeoutUnit = TimeUnit.MILLISECONDS;
198 protected ModelDrivenSwitchImpl(final NodeId nodeId, final InstanceIdentifier<Node> identifier,
199 final SessionContext sessionContext) {
200 super(identifier, sessionContext);
201 this.nodeId = nodeId;
202 messageService = sessionContext.getMessageDispatchService();
203 version = sessionContext.getPrimaryConductor().getVersion();
204 rpcNotificationProviderService = OFSessionUtil.getSessionManager().getNotificationProviderService();
206 rpcTaskContext = new OFRpcTaskContext();
207 rpcTaskContext.setSession(sessionContext);
208 rpcTaskContext.setMessageService(messageService);
209 rpcTaskContext.setRpcNotificationProviderService(rpcNotificationProviderService);
210 rpcTaskContext.setMaxTimeout(maxTimeout);
211 rpcTaskContext.setMaxTimeoutUnit(maxTimeoutUnit);
212 rpcTaskContext.setRpcPool(OFSessionUtil.getSessionManager().getRpcPool());
216 public Future<RpcResult<AddFlowOutput>> addFlow(final AddFlowInput input) {
217 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
218 // use primary connection
219 SwitchConnectionDistinguisher cookie = null;
221 OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> task =
222 OFRpcTaskFactory.createAddFlowTask(rpcTaskContext, input, cookie);
223 ListenableFuture<RpcResult<UpdateFlowOutput>> result = task.submit();
225 return Futures.transform(JdkFutureAdapters.listenInPoolThread(result),
226 OFRpcFutureResultTransformFactory.createForAddFlowOutput());
231 public Future<RpcResult<AddGroupOutput>> addGroup(final AddGroupInput input) {
232 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
234 // use primary connection
235 SwitchConnectionDistinguisher cookie = null;
237 OFRpcTask<AddGroupInput, RpcResult<UpdateGroupOutput>> task =
238 OFRpcTaskFactory.createAddGroupTask(rpcTaskContext, input, cookie);
239 ListenableFuture<RpcResult<UpdateGroupOutput>> result = task.submit();
241 return Futures.transform(JdkFutureAdapters.listenInPoolThread(result),
242 OFRpcFutureResultTransformFactory.createForAddGroupOutput());
246 public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
247 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
249 // use primary connection
250 SwitchConnectionDistinguisher cookie = null;
252 OFRpcTask<AddMeterInput, RpcResult<UpdateMeterOutput>> task =
253 OFRpcTaskFactory.createAddMeterTask(rpcTaskContext, input, cookie);
254 ListenableFuture<RpcResult<UpdateMeterOutput>> result = task.submit();
256 return Futures.transform(JdkFutureAdapters.listenInPoolThread(result),
257 OFRpcFutureResultTransformFactory.createForAddMeterOutput());
261 public Future<RpcResult<RemoveFlowOutput>> removeFlow(final RemoveFlowInput input) {
262 LOG.debug("Calling the removeFlow RPC method on MessageDispatchService");
264 // For Flow provisioning, the SwitchConnectionDistinguisher is set to
266 // the request can be routed through any connection to the switch
268 SwitchConnectionDistinguisher cookie = null;
269 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
270 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
271 xId = sessionContext.getNextXid();
272 barrierInput.setXid(xId);
273 barrierInput.setVersion(version);
274 @SuppressWarnings("unused")
275 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
278 // Convert the RemoveFlowInput to FlowModInput
279 FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(input, version, sessionContext
280 .getFeatures().getDatapathId());
281 xId = sessionContext.getNextXid();
282 ofFlowModInput.setXid(xId);
284 if (null != rpcNotificationProviderService) {
285 FlowRemovedBuilder removeFlow = new FlowRemovedBuilder(
286 (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) input);
287 removeFlow.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
288 removeFlow.setFlowRef(input.getFlowRef());
289 rpcNotificationProviderService.publish(removeFlow.build());
292 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput.build(), cookie);
294 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null;
297 rpcResultFromOFLib = resultFromOFLib.get();
298 } catch (Exception ex) {
299 LOG.error(" Error while getting result for remove Flow RPC" + ex.getMessage());
302 UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult();
304 RemoveFlowOutputBuilder removeFlowOutput = new RemoveFlowOutputBuilder();
305 removeFlowOutput.setTransactionId(updateFlowOutput.getTransactionId());
306 RemoveFlowOutput result = removeFlowOutput.build();
308 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
309 RpcResult<RemoveFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
311 LOG.debug("Returning the Remove Flow RPC result to MD-SAL");
312 return Futures.immediateFuture(rpcResult);
316 public Future<RpcResult<RemoveGroupOutput>> removeGroup(final RemoveGroupInput input) {
317 LOG.debug("Calling the Remove Group RPC method on MessageDispatchService");
320 // For Flow provisioning, the SwitchConnectionDistinguisher is set to
322 // the request can be routed through any connection to the switch
324 SwitchConnectionDistinguisher cookie = null;
325 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
326 xId = sessionContext.getNextXid();
327 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
328 barrierInput.setVersion(version);
329 barrierInput.setXid(xId);
330 @SuppressWarnings("unused")
331 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
334 // Convert the RemoveGroupInput to GroupModInput
335 GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(input, version, this.getSessionContext()
336 .getFeatures().getDatapathId());
337 xId = sessionContext.getNextXid();
338 ofGroupModInput.setXid(xId);
340 if (null != rpcNotificationProviderService) {
341 GroupRemovedBuilder groupMod = new GroupRemovedBuilder(
342 (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group) input);
343 groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
344 groupMod.setGroupRef(input.getGroupRef());
345 rpcNotificationProviderService.publish(groupMod.build());
348 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput.build(), cookie);
350 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null;
353 rpcResultFromOFLib = resultFromOFLib.get();
354 } catch (Exception ex) {
355 LOG.error(" Error while getting result for RemoveGroup RPC" + ex.getMessage());
358 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult();
360 RemoveGroupOutputBuilder removeGroupOutput = new RemoveGroupOutputBuilder();
361 removeGroupOutput.setTransactionId(updateGroupOutput.getTransactionId());
362 RemoveGroupOutput result = removeGroupOutput.build();
364 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
365 RpcResult<RemoveGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
367 LOG.debug("Returning the Remove Group RPC result to MD-SAL");
368 return Futures.immediateFuture(rpcResult);
372 public Future<RpcResult<RemoveMeterOutput>> removeMeter(final RemoveMeterInput input) {
373 LOG.debug("Calling the Remove MeterMod RPC method on MessageDispatchService");
376 // For Meter provisioning, the SwitchConnectionDistinguisher is set to
378 // the request can be routed through any connection to the switch
379 SwitchConnectionDistinguisher cookie = null;
380 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
381 xId = sessionContext.getNextXid();
382 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
383 barrierInput.setVersion(version);
384 barrierInput.setXid(xId);
385 @SuppressWarnings("unused")
386 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
389 // Convert the RemoveMeterInput to MeterModInput
390 MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
391 xId = sessionContext.getNextXid();
392 ofMeterModInput.setXid(xId);
394 if (null != rpcNotificationProviderService) {
395 MeterRemovedBuilder meterMod = new MeterRemovedBuilder(
396 (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter) input);
397 meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
398 meterMod.setMeterRef(input.getMeterRef());
399 rpcNotificationProviderService.publish(meterMod.build());
402 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput.build(), cookie);
404 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null;
407 rpcResultFromOFLib = resultFromOFLib.get();
408 } catch (Exception ex) {
409 LOG.error(" Error while getting result for RemoveMeter RPC" + ex.getMessage());
412 UpdateMeterOutput updatemeterOutput = rpcResultFromOFLib.getResult();
414 RemoveMeterOutputBuilder removeMeterOutput = new RemoveMeterOutputBuilder();
415 removeMeterOutput.setTransactionId(updatemeterOutput.getTransactionId());
416 RemoveMeterOutput result = removeMeterOutput.build();
418 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
419 RpcResult<RemoveMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
421 LOG.debug("Returning the Remove Meter RPC result to MD-SAL");
422 return Futures.immediateFuture(rpcResult);
426 public Future<RpcResult<Void>> transmitPacket(final TransmitPacketInput input) {
427 LOG.debug("TransmitPacket - {}", input);
428 // Convert TransmitPacket to PacketOutInput
429 PacketOutInput message = PacketOutConvertor.toPacketOutInput(input, version, sessionContext.getNextXid(),
430 sessionContext.getFeatures().getDatapathId());
432 // TODO VD NULL for yet - find how to translate cookie from
433 // TransmitPacketInput
434 // SwitchConnectionDistinguisher cookie = ( "what is need to do" )
435 // input.getCookie();
436 SwitchConnectionDistinguisher cookie = null;
438 LOG.debug("Calling the transmitPacket RPC method");
439 return messageService.packetOut(message, cookie);
442 private FlowModInputBuilder toFlowModInputBuilder(final Flow source) {
443 FlowModInputBuilder target = new FlowModInputBuilder();
444 target.setCookie(source.getCookie().getValue());
445 target.setIdleTimeout(source.getIdleTimeout());
446 target.setHardTimeout(source.getHardTimeout());
447 target.setMatch(toMatch(source.getMatch()));
452 private Match toMatch(final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
453 MatchBuilder target = new MatchBuilder();
455 target.setMatchEntries(toMatchEntries(match));
460 private List<MatchEntries> toMatchEntries(
461 final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
462 List<MatchEntries> entries = new ArrayList<>();
468 public Future<RpcResult<UpdateFlowOutput>> updateFlow(final UpdateFlowInput input) {
469 LOG.debug("Calling the updateFlow RPC method on MessageDispatchService");
471 // use primary connection
472 SwitchConnectionDistinguisher cookie = null;
474 OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> task =
475 OFRpcTaskFactory.createUpdateFlowTask(rpcTaskContext, input, cookie);
476 ListenableFuture<RpcResult<UpdateFlowOutput>> result = task.submit();
482 public Future<RpcResult<UpdateGroupOutput>> updateGroup(final UpdateGroupInput input) {
483 LOG.debug("Calling the update Group Mod RPC method on MessageDispatchService");
485 // use primary connection
486 SwitchConnectionDistinguisher cookie = null;
488 OFRpcTask<UpdateGroupInput, RpcResult<UpdateGroupOutput>> task =
489 OFRpcTaskFactory.createUpdateGroupTask(rpcTaskContext, input, cookie);
490 ListenableFuture<RpcResult<UpdateGroupOutput>> result = task.submit();
496 public Future<RpcResult<UpdateMeterOutput>> updateMeter(final UpdateMeterInput input) {
497 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
499 // use primary connection
500 SwitchConnectionDistinguisher cookie = null;
502 OFRpcTask<UpdateMeterInput, RpcResult<UpdateMeterOutput>> task =
503 OFRpcTaskFactory.createUpdateMeterTask(rpcTaskContext, input, cookie);
504 ListenableFuture<RpcResult<UpdateMeterOutput>> result = task.submit();
510 public NodeId getNodeId() {
515 * Methods for requesting statistics from switch
518 public Future<RpcResult<GetAllGroupStatisticsOutput>> getAllGroupStatistics(final GetAllGroupStatisticsInput input) {
520 GetAllGroupStatisticsOutputBuilder output = new GetAllGroupStatisticsOutputBuilder();
521 Collection<RpcError> errors = Collections.emptyList();
523 if (version == OFConstants.OFP_VERSION_1_0) {
524 output.setTransactionId(null);
525 output.setGroupStats(null);
527 RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
528 return Futures.immediateFuture(rpcResult);
530 // Generate xid to associate it with the request
531 Long xid = this.getSessionContext().getNextXid();
533 LOG.debug("Prepare statistics request for all the groups - Transaction id - {}", xid);
535 // Create multipart request header
536 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
537 mprInput.setType(MultipartType.OFPMPGROUP);
538 mprInput.setVersion(version);
539 mprInput.setXid(xid);
540 mprInput.setFlags(new MultipartRequestFlags(false));
542 // Create multipart request body for fetch all the group stats
543 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
544 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
545 mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(Group.OFPGALL.getIntValue())));
546 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
548 // Set request body to main multipart request
549 mprInput.setMultipartRequestBody(caseBuilder.build());
551 // Send the request, no cookies associated, use any connection
552 LOG.debug("Send group statistics request to the switch :{}", mprGroupBuild);
553 this.messageService.multipartRequest(mprInput.build(), null);
555 // Prepare rpc return output. Set xid and send it back.
556 LOG.debug("Return results and transaction id back to caller");
557 output.setTransactionId(generateTransactionId(xid));
558 output.setGroupStats(null);
560 RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
561 return Futures.immediateFuture(rpcResult);
566 public Future<RpcResult<GetGroupDescriptionOutput>> getGroupDescription(final GetGroupDescriptionInput input) {
568 GetGroupDescriptionOutputBuilder output = new GetGroupDescriptionOutputBuilder();
569 Collection<RpcError> errors = Collections.emptyList();
571 if (version == OFConstants.OFP_VERSION_1_0) {
572 output.setTransactionId(null);
573 output.setGroupDescStats(null);
575 RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
576 return Futures.immediateFuture(rpcResult);
578 // Generate xid to associate it with the request
579 Long xid = this.getSessionContext().getNextXid();
581 LOG.debug("Prepare group description statistics request - Transaction id - {}", xid);
583 // Create multipart request header
584 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
585 mprInput.setType(MultipartType.OFPMPGROUPDESC);
586 mprInput.setVersion(version);
587 mprInput.setXid(xid);
588 mprInput.setFlags(new MultipartRequestFlags(false));
590 // Create multipart request body for fetch all the group description
592 MultipartRequestGroupDescCaseBuilder mprGroupDescBuild = new MultipartRequestGroupDescCaseBuilder();
594 // Set request body to main multipart request
595 mprInput.setMultipartRequestBody(mprGroupDescBuild.build());
597 // Send the request, no cookies associated, use any connection
598 LOG.debug("Send group desciption statistics request to switch : {}", mprGroupDescBuild);
599 this.messageService.multipartRequest(mprInput.build(), null);
601 // Prepare rpc return output. Set xid and send it back.
602 LOG.debug("Return results and transaction id back to caller");
603 output.setTransactionId(generateTransactionId(xid));
604 output.setGroupDescStats(null);
606 RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
607 return Futures.immediateFuture(rpcResult);
612 public Future<RpcResult<GetGroupFeaturesOutput>> getGroupFeatures(final GetGroupFeaturesInput input) {
614 GetGroupFeaturesOutputBuilder output = new GetGroupFeaturesOutputBuilder();
615 Collection<RpcError> errors = Collections.emptyList();
617 if (version == OFConstants.OFP_VERSION_1_0) {
618 output.setTransactionId(null);
620 RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
621 return Futures.immediateFuture(rpcResult);
623 // Generate xid to associate it with the request
624 Long xid = this.getSessionContext().getNextXid();
626 LOG.debug("Prepare group features statistics request - Transaction id - {}", xid);
628 // Create multipart request header
629 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
630 mprInput.setType(MultipartType.OFPMPGROUPFEATURES);
631 mprInput.setVersion(version);
632 mprInput.setXid(xid);
633 mprInput.setFlags(new MultipartRequestFlags(false));
635 // Create multipart request body for fetch all the group description
637 MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild = new MultipartRequestGroupFeaturesCaseBuilder();
639 // Set request body to main multipart request
640 mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
642 // Send the request, no cookies associated, use any connection
643 LOG.debug("Send group features statistics request :{}", mprGroupFeaturesBuild);
644 this.messageService.multipartRequest(mprInput.build(), null);
646 // Prepare rpc return output. Set xid and send it back.
647 LOG.debug("Return results and transaction id back to caller");
648 output.setTransactionId(generateTransactionId(xid));
650 RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
651 return Futures.immediateFuture(rpcResult);
655 public Future<RpcResult<GetGroupStatisticsOutput>> getGroupStatistics(final GetGroupStatisticsInput input) {
657 GetGroupStatisticsOutputBuilder output = new GetGroupStatisticsOutputBuilder();
658 Collection<RpcError> errors = Collections.emptyList();
660 if (version == OFConstants.OFP_VERSION_1_0) {
661 output.setTransactionId(null);
662 output.setGroupStats(null);
664 RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
665 return Futures.immediateFuture(rpcResult);
667 // Generate xid to associate it with the request
668 Long xid = this.getSessionContext().getNextXid();
670 LOG.debug("Prepare statistics request for node {} group ({}) - Transaction id - {}", input.getNode(),
671 input.getGroupId(), xid);
673 // Create multipart request header
674 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
675 mprInput.setType(MultipartType.OFPMPGROUP);
676 mprInput.setVersion(version);
677 mprInput.setXid(xid);
678 mprInput.setFlags(new MultipartRequestFlags(false));
680 // Create multipart request body for fetch all the group stats
681 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
682 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
683 mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
684 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
686 // Set request body to main multipart request
687 mprInput.setMultipartRequestBody(caseBuilder.build());
689 // Send the request, no cookies associated, use any connection
690 LOG.debug("Send group statistics request :{}", mprGroupBuild);
691 this.messageService.multipartRequest(mprInput.build(), null);
693 // Prepare rpc return output. Set xid and send it back.
694 LOG.debug("Return results and transaction id back to caller");
695 output.setTransactionId(generateTransactionId(xid));
696 output.setGroupStats(null);
698 RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
699 return Futures.immediateFuture(rpcResult);
703 public Future<RpcResult<GetAllMeterConfigStatisticsOutput>> getAllMeterConfigStatistics(
704 final GetAllMeterConfigStatisticsInput input) {
706 GetAllMeterConfigStatisticsOutputBuilder output = new GetAllMeterConfigStatisticsOutputBuilder();
707 Collection<RpcError> errors = Collections.emptyList();
709 if (version == OFConstants.OFP_VERSION_1_0) {
710 output.setTransactionId(null);
711 output.setMeterConfigStats(null);
713 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
714 return Futures.immediateFuture(rpcResult);
717 // Generate xid to associate it with the request
718 Long xid = this.getSessionContext().getNextXid();
720 LOG.debug("Prepare config request for all the meters - Transaction id - {}", xid);
722 // Create multipart request header
723 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
724 mprInput.setType(MultipartType.OFPMPMETERCONFIG);
725 mprInput.setVersion(version);
726 mprInput.setXid(xid);
727 mprInput.setFlags(new MultipartRequestFlags(false));
729 // Create multipart request body for fetch all the meter stats
730 MultipartRequestMeterConfigCaseBuilder caseBuilder = new MultipartRequestMeterConfigCaseBuilder();
731 MultipartRequestMeterConfigBuilder mprMeterConfigBuild = new MultipartRequestMeterConfigBuilder();
732 mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
733 caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
735 // Set request body to main multipart request
736 mprInput.setMultipartRequestBody(caseBuilder.build());
738 // Send the request, no cookies associated, use any connection
739 LOG.debug("Send meter statistics request :{}", mprMeterConfigBuild);
740 this.messageService.multipartRequest(mprInput.build(), null);
742 // Prepare rpc return output. Set xid and send it back.
743 LOG.debug("Return results and transaction id back to caller");
744 output.setTransactionId(generateTransactionId(xid));
745 output.setMeterConfigStats(null);
747 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
748 return Futures.immediateFuture(rpcResult);
752 public Future<RpcResult<GetAllMeterStatisticsOutput>> getAllMeterStatistics(final GetAllMeterStatisticsInput input) {
754 GetAllMeterStatisticsOutputBuilder output = new GetAllMeterStatisticsOutputBuilder();
755 Collection<RpcError> errors = Collections.emptyList();
757 if (version == OFConstants.OFP_VERSION_1_0) {
758 output.setTransactionId(null);
759 output.setMeterStats(null);
761 RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
762 return Futures.immediateFuture(rpcResult);
764 // Generate xid to associate it with the request
765 Long xid = this.getSessionContext().getNextXid();
767 LOG.debug("Prepare statistics request for all the meters - Transaction id - {}", xid);
769 // Create multipart request header
770 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
771 mprInput.setType(MultipartType.OFPMPMETER);
772 mprInput.setVersion(version);
773 mprInput.setXid(xid);
774 mprInput.setFlags(new MultipartRequestFlags(false));
776 // Create multipart request body for fetch all the meter stats
777 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
778 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
779 mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
780 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
782 // Set request body to main multipart request
783 mprInput.setMultipartRequestBody(caseBuilder.build());
785 // Send the request, no cookies associated, use any connection
786 LOG.debug("Send meter statistics request :{}", mprMeterBuild);
787 this.messageService.multipartRequest(mprInput.build(), null);
789 // Prepare rpc return output. Set xid and send it back.
790 LOG.debug("Return results and transaction id back to caller");
791 output.setTransactionId(generateTransactionId(xid));
792 output.setMeterStats(null);
794 RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
795 return Futures.immediateFuture(rpcResult);
799 public Future<RpcResult<GetMeterFeaturesOutput>> getMeterFeatures(final GetMeterFeaturesInput input) {
801 GetMeterFeaturesOutputBuilder output = new GetMeterFeaturesOutputBuilder();
802 Collection<RpcError> errors = Collections.emptyList();
804 if (version == OFConstants.OFP_VERSION_1_0) {
805 output.setTransactionId(null);
807 RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
808 return Futures.immediateFuture(rpcResult);
810 // Generate xid to associate it with the request
811 Long xid = this.getSessionContext().getNextXid();
813 LOG.debug("Prepare features statistics request for all the meters - Transaction id - {}", xid);
815 // Create multipart request header
816 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
817 mprInput.setType(MultipartType.OFPMPMETERFEATURES);
818 mprInput.setVersion(version);
819 mprInput.setXid(xid);
820 mprInput.setFlags(new MultipartRequestFlags(false));
822 // Create multipart request body for fetch all the group description
824 MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild = new MultipartRequestMeterFeaturesCaseBuilder();
826 // Set request body to main multipart request
827 mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
829 // Send the request, no cookies associated, use any connection
830 LOG.debug("Send meter features statistics request :{}", mprMeterFeaturesBuild);
831 this.messageService.multipartRequest(mprInput.build(), null);
833 // Prepare rpc return output. Set xid and send it back.
834 LOG.debug("Return results and transaction id back to caller");
835 output.setTransactionId(generateTransactionId(xid));
837 RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
838 return Futures.immediateFuture(rpcResult);
842 public Future<RpcResult<GetMeterStatisticsOutput>> getMeterStatistics(final GetMeterStatisticsInput input) {
844 GetMeterStatisticsOutputBuilder output = new GetMeterStatisticsOutputBuilder();
845 Collection<RpcError> errors = Collections.emptyList();
847 if (version == OFConstants.OFP_VERSION_1_0) {
848 output.setTransactionId(null);
849 output.setMeterStats(null);
851 RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
852 return Futures.immediateFuture(rpcResult);
855 // Generate xid to associate it with the request
856 Long xid = this.getSessionContext().getNextXid();
858 LOG.debug("Preprae statistics request for Meter ({}) - Transaction id - {}", input.getMeterId().getValue(), xid);
860 // Create multipart request header
861 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
862 mprInput.setType(MultipartType.OFPMPMETER);
863 mprInput.setVersion(version);
864 mprInput.setXid(xid);
865 mprInput.setFlags(new MultipartRequestFlags(false));
867 // Create multipart request body for fetch all the meter stats
868 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
869 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
870 // Select specific meter
871 mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
872 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
874 // Set request body to main multipart request
875 mprInput.setMultipartRequestBody(caseBuilder.build());
877 // Send the request, no cookies associated, use any connection
878 LOG.debug("Send meter statistics request :{}", mprMeterBuild);
879 this.messageService.multipartRequest(mprInput.build(), null);
881 // Prepare rpc return output. Set xid and send it back.
882 LOG.debug("Return results and transaction id back to caller");
883 output.setTransactionId(generateTransactionId(xid));
884 output.setMeterStats(null);
886 RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
887 return Futures.immediateFuture(rpcResult);
891 public Future<RpcResult<GetAllNodeConnectorsStatisticsOutput>> getAllNodeConnectorsStatistics(
892 final GetAllNodeConnectorsStatisticsInput arg0) {
894 // Generate xid to associate it with the request
895 Long xid = this.getSessionContext().getNextXid();
897 LOG.debug("Prepare port statistics request for all ports of node {} - TrasactionId - {}", arg0.getNode()
900 // Create multipart request header
901 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
902 mprInput.setType(MultipartType.OFPMPPORTSTATS);
903 mprInput.setVersion(version);
904 mprInput.setXid(xid);
905 mprInput.setFlags(new MultipartRequestFlags(false));
907 // Create multipart request body to fetch stats for all the port of the
909 MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
910 MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
912 mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
913 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
915 // Set request body to main multipart request
916 mprInput.setMultipartRequestBody(caseBuilder.build());
918 // Send the request, no cookies associated, use any connection
919 LOG.debug("Send port statistics request :{}", mprPortStatsBuilder.build().toString());
920 this.messageService.multipartRequest(mprInput.build(), null);
922 // Prepare rpc return output. Set xid and send it back.
923 GetAllNodeConnectorsStatisticsOutputBuilder output = new GetAllNodeConnectorsStatisticsOutputBuilder();
924 output.setTransactionId(generateTransactionId(xid));
926 Collection<RpcError> errors = Collections.emptyList();
927 RpcResult<GetAllNodeConnectorsStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
928 return Futures.immediateFuture(rpcResult);
932 public Future<RpcResult<GetNodeConnectorStatisticsOutput>> getNodeConnectorStatistics(
933 final GetNodeConnectorStatisticsInput arg0) {
934 // Generate xid to associate it with the request
935 Long xid = this.getSessionContext().getNextXid();
937 LOG.debug("Prepare port statistics request for port {} of node {} - TrasactionId - {}",
938 arg0.getNodeConnectorId(), arg0.getNode().getValue(), xid);
940 // Create multipart request header
941 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
942 mprInput.setType(MultipartType.OFPMPPORTSTATS);
943 mprInput.setVersion(version);
944 mprInput.setXid(xid);
945 mprInput.setFlags(new MultipartRequestFlags(false));
947 // Create multipart request body to fetch stats for all the port of the
949 MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
950 MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
954 .setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
955 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
957 // Set request body to main multipart request
958 mprInput.setMultipartRequestBody(caseBuilder.build());
960 // Send the request, no cookies associated, use any connection
961 LOG.debug("Send port statistics request :{}", mprPortStatsBuilder.build().toString());
962 this.messageService.multipartRequest(mprInput.build(), null);
964 // Prepare rpc return output. Set xid and send it back.
965 GetNodeConnectorStatisticsOutputBuilder output = new GetNodeConnectorStatisticsOutputBuilder();
966 output.setTransactionId(generateTransactionId(xid));
968 Collection<RpcError> errors = Collections.emptyList();
969 RpcResult<GetNodeConnectorStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
970 return Futures.immediateFuture(rpcResult);
973 private TransactionId generateTransactionId(final Long xid) {
974 String stringXid = xid.toString();
975 BigInteger bigIntXid = new BigInteger(stringXid);
976 return new TransactionId(bigIntXid);
981 public Future<RpcResult<UpdatePortOutput>> updatePort(final UpdatePortInput input) {
982 PortModInput ofPortModInput = null;
983 RpcResult<UpdatePortOutput> rpcResultFromOFLib = null;
985 // For Flow provisioning, the SwitchConnectionDistinguisher is set to
987 // the request can be routed through any connection to the switch
989 SwitchConnectionDistinguisher cookie = null;
991 // NSF sends a list of port and the ModelDrivenSwitch will
992 // send one port at a time towards the switch ( mutiple RPCs calls)
993 List<Port> inputPorts = input.getUpdatedPort().getPort().getPort();
995 // Get the Xid. The same Xid has to be sent in all the RPCs
996 Long Xid = sessionContext.getNextXid();
998 for (Port inputPort : inputPorts) {
1000 // Convert the UpdateGroupInput to GroupModInput
1001 ofPortModInput = PortConvertor.toPortModInput(inputPort, version);
1003 // Insert the Xid ( transaction Id) before calling the RPC on the
1006 PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
1007 mdInput.setXid(Xid);
1009 LOG.debug("Calling the PortMod RPC method on MessageDispatchService");
1010 Future<RpcResult<UpdatePortOutput>> resultFromOFLib = messageService.portMod(mdInput.build(), cookie);
1013 rpcResultFromOFLib = resultFromOFLib.get();
1014 } catch (Exception ex) {
1015 LOG.error(" Error while getting result for updatePort RPC" + ex.getMessage());
1018 // The Future response value for all the RPCs except the last one is
1022 // Extract the Xid only from the Future for the last RPC and
1023 // send it back to the NSF
1024 UpdatePortOutput updatePortOutputOFLib = rpcResultFromOFLib.getResult();
1026 UpdatePortOutputBuilder updatePortOutput = new UpdatePortOutputBuilder();
1027 updatePortOutput.setTransactionId(updatePortOutputOFLib.getTransactionId());
1028 UpdatePortOutput result = updatePortOutput.build();
1030 Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
1031 RpcResult<UpdatePortOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
1033 LOG.debug("Returning the Update Group RPC result to MD-SAL");
1034 return Futures.immediateFuture(rpcResult);
1039 public Future<RpcResult<UpdateTableOutput>> updateTable(final UpdateTableInput input) {
1041 // Get the Xid. The same Xid has to be sent in all the Multipart
1043 Long xid = this.getSessionContext().getNextXid();
1045 LOG.debug("Prepare the Multipart Table Mod requests for Transaction Id {} ", xid);
1047 // Create multipart request header
1048 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1049 mprInput.setType(MultipartType.OFPMPTABLEFEATURES);
1050 mprInput.setVersion((short) 0x04);
1051 mprInput.setXid(xid);
1053 // Convert the list of all MD-SAL table feature object into OF library
1055 List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input.getUpdatedTable());
1057 MultipartRequestTableFeaturesCaseBuilder caseRequest = new MultipartRequestTableFeaturesCaseBuilder();
1058 MultipartRequestTableFeaturesBuilder tableFeaturesRequest = new MultipartRequestTableFeaturesBuilder();
1060 mprInput.setFlags(new MultipartRequestFlags(false));
1062 tableFeaturesRequest.setTableFeatures(ofTableFeatureList);
1064 // Set request body to main multipart request
1065 caseRequest.setMultipartRequestTableFeatures(tableFeaturesRequest.build());
1066 mprInput.setMultipartRequestBody(caseRequest.build());
1068 // Send the request, no cookies associated, use any connection
1069 LOG.debug("Send Table Feature request :{}", ofTableFeatureList);
1070 this.messageService.multipartRequest(mprInput.build(), null);
1072 // Extract the Xid only from the Future for the last RPC and
1073 // send it back to the NSF
1074 LOG.debug("Returning the result and transaction id to NSF");
1075 LOG.debug("Return results and transaction id back to caller");
1076 UpdateTableOutputBuilder output = new UpdateTableOutputBuilder();
1077 output.setTransactionId(generateTransactionId(xid));
1079 Collection<RpcError> errors = Collections.emptyList();
1080 RpcResult<UpdateTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1081 return Futures.immediateFuture(rpcResult);
1085 public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
1086 final GetAllFlowStatisticsFromFlowTableInput arg0) {
1088 // Generate xid to associate it with the request
1089 Long xid = this.getSessionContext().getNextXid();
1091 LOG.debug("Prepare statistics request to get flow stats for switch tables {} - Transaction id - {}", arg0
1092 .getTableId().getValue(), xid);
1094 // Create multipart request header
1095 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1096 mprInput.setType(MultipartType.OFPMPFLOW);
1097 mprInput.setVersion(version);
1098 mprInput.setXid(xid);
1099 mprInput.setFlags(new MultipartRequestFlags(false));
1101 // Create multipart request body for fetch all the group stats
1102 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1103 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1104 mprFlowRequestBuilder.setTableId(arg0.getTableId().getValue());
1105 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1106 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1107 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1108 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1109 FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
1111 // Set request body to main multipart request
1112 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1113 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1115 // Send the request, no cookies associated, use any connection
1116 LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder);
1117 this.messageService.multipartRequest(mprInput.build(), null);
1119 // Prepare rpc return output. Set xid and send it back.
1120 LOG.debug("Return results and transaction id back to caller");
1121 GetAllFlowStatisticsFromFlowTableOutputBuilder output = new GetAllFlowStatisticsFromFlowTableOutputBuilder();
1122 output.setTransactionId(generateTransactionId(xid));
1123 output.setFlowAndStatisticsMapList(null);
1125 Collection<RpcError> errors = Collections.emptyList();
1126 RpcResult<GetAllFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1127 return Futures.immediateFuture(rpcResult);
1131 public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
1132 final GetAllFlowsStatisticsFromAllFlowTablesInput arg0) {
1134 // Generate xid to associate it with the request
1135 Long xid = this.getSessionContext().getNextXid();
1137 LOG.debug("Prepare statistics request to get flow stats of all switch tables - Transaction id - {}", xid);
1139 // Create multipart request header
1140 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1141 mprInput.setType(MultipartType.OFPMPFLOW);
1142 mprInput.setVersion(version);
1143 mprInput.setXid(xid);
1144 mprInput.setFlags(new MultipartRequestFlags(false));
1146 // Create multipart request body for fetch all the group stats
1147 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1148 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1149 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
1150 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1151 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1152 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1153 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1154 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1156 FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
1158 // Set request body to main multipart request
1159 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1160 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1162 // Send the request, no cookies associated, use any connection
1163 LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder);
1164 this.messageService.multipartRequest(mprInput.build(), null);
1166 // Prepare rpc return output. Set xid and send it back.
1167 GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder output = new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder();
1168 output.setTransactionId(generateTransactionId(xid));
1169 output.setFlowAndStatisticsMapList(null);
1171 Collection<RpcError> errors = Collections.emptyList();
1172 RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(),
1174 return Futures.immediateFuture(rpcResult);
1179 public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
1180 final GetFlowStatisticsFromFlowTableInput arg0) {
1181 // Generate xid to associate it with the request
1182 Long xid = this.getSessionContext().getNextXid();
1184 LOG.debug("Prepare statistics request to get stats for flow {} for switch tables {} - Transaction id - {}",
1185 arg0.getMatch().toString(), arg0.getTableId(), xid);
1187 // Create multipart request header
1188 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1189 mprInput.setType(MultipartType.OFPMPFLOW);
1190 mprInput.setVersion(version);
1191 mprInput.setXid(xid);
1192 mprInput.setFlags(new MultipartRequestFlags(false));
1194 // Create multipart request body for fetch all the group stats
1195 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1196 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1197 mprFlowRequestBuilder.setTableId(arg0.getTableId());
1199 if (arg0.getOutPort() != null)
1200 mprFlowRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1202 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1204 if (arg0.getOutGroup() != null)
1205 mprFlowRequestBuilder.setOutGroup(arg0.getOutGroup());
1207 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1209 if (arg0.getCookie() != null)
1210 mprFlowRequestBuilder.setCookie(arg0.getCookie().getValue());
1212 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1214 if (arg0.getCookieMask() != null)
1215 mprFlowRequestBuilder.setCookieMask(arg0.getCookieMask().getValue());
1217 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1219 // convert and inject match
1220 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprFlowRequestBuilder,
1221 this.getSessionContext().getFeatures().getDatapathId());
1223 // Set request body to main multipart request
1224 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1225 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1227 // Send the request, no cookies associated, use any connection
1228 LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder);
1229 this.messageService.multipartRequest(mprInput.build(), null);
1231 // Prepare rpc return output. Set xid and send it back.
1232 GetFlowStatisticsFromFlowTableOutputBuilder output = new GetFlowStatisticsFromFlowTableOutputBuilder();
1233 output.setTransactionId(generateTransactionId(xid));
1234 output.setFlowAndStatisticsMapList(null);
1236 Collection<RpcError> errors = Collections.emptyList();
1237 RpcResult<GetFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1238 return Futures.immediateFuture(rpcResult);
1242 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
1243 final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput arg0) {
1244 // Generate xid to associate it with the request
1245 Long xid = this.getSessionContext().getNextXid();
1248 "Prepare aggregate flow statistics request to get aggregate flow stats for all the flow installed on switch table {} - Transaction id - {}",
1249 arg0.getTableId().getValue(), xid);
1251 // Create multipart request header
1252 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1253 mprInput.setType(MultipartType.OFPMPAGGREGATE);
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 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1260 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1261 mprAggregateRequestBuilder.setTableId(arg0.getTableId().getValue());
1262 mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1263 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1264 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1265 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1267 FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder);
1269 // Set request body to main multipart request
1270 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1271 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1273 // Send the request, no cookies associated, use any connection
1274 LOG.debug("Send request to the switch :{}", multipartRequestAggregateCaseBuilder.build().toString());
1275 this.messageService.multipartRequest(mprInput.build(), null);
1277 // Prepare rpc return output. Set xid and send it back.
1278 GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder output = new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder();
1279 output.setTransactionId(generateTransactionId(xid));
1281 Collection<RpcError> errors = Collections.emptyList();
1282 RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> rpcResult = Rpcs.getRpcResult(true,
1283 output.build(), errors);
1284 return Futures.immediateFuture(rpcResult);
1288 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
1289 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput arg0) {
1291 // Generate xid to associate it with the request
1292 Long xid = this.getSessionContext().getNextXid();
1295 "Prepare aggregate statistics request to get aggregate stats for flows matching {} and installed in flow tables {} - Transaction id - {}",
1296 arg0.getMatch().toString(), arg0.getTableId(), xid);
1298 // Create multipart request header
1299 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1300 mprInput.setType(MultipartType.OFPMPAGGREGATE);
1301 mprInput.setVersion(version);
1302 mprInput.setXid(xid);
1303 mprInput.setFlags(new MultipartRequestFlags(false));
1305 // Create multipart request body for fetch all the group stats
1306 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1307 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1308 mprAggregateRequestBuilder.setTableId(arg0.getTableId());
1309 mprAggregateRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1310 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1311 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1312 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1314 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprAggregateRequestBuilder,
1315 this.getSessionContext().getFeatures().getDatapathId());
1316 // TODO: repeating code
1317 if (version == OFConstants.OFP_VERSION_1_3) {
1318 mprAggregateRequestBuilder.setCookie(arg0.getCookie().getValue());
1319 mprAggregateRequestBuilder.setCookieMask(arg0.getCookieMask().getValue());
1320 mprAggregateRequestBuilder.setOutGroup(arg0.getOutGroup());
1323 // Set request body to main multipart request
1324 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1325 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1327 // Send the request, no cookies associated, use any connection
1328 LOG.debug("Send request to the switch :{}", multipartRequestAggregateCaseBuilder.build().toString());
1329 this.messageService.multipartRequest(mprInput.build(), null);
1331 // Prepare rpc return output. Set xid and send it back.
1332 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder output = new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
1333 output.setTransactionId(generateTransactionId(xid));
1335 Collection<RpcError> errors = Collections.emptyList();
1336 RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult = Rpcs.getRpcResult(true,
1337 output.build(), errors);
1338 return Futures.immediateFuture(rpcResult);
1342 public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(final GetFlowTablesStatisticsInput arg0) {
1343 // Generate xid to associate it with the request
1344 Long xid = this.getSessionContext().getNextXid();
1346 LOG.debug("Prepare flow table statistics request to get flow table stats for all tables "
1347 + "from node {}- Transaction id - {}", arg0.getNode(), xid);
1349 // Create multipart request header
1350 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1351 mprInput.setType(MultipartType.OFPMPTABLE);
1352 mprInput.setVersion(version);
1353 mprInput.setXid(xid);
1354 mprInput.setFlags(new MultipartRequestFlags(false));
1356 // Create multipart request body for fetch all the group stats
1357 MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
1358 MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
1359 multipartRequestTableBuilder.setEmpty(true);
1360 multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
1362 // Set request body to main multipart request
1363 mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
1365 // Send the request, no cookies associated, use any connection
1366 LOG.debug("Send request to the switch :{}", multipartRequestTableCaseBuilder.build().toString());
1367 this.messageService.multipartRequest(mprInput.build(), null);
1369 // Prepare rpc return output. Set xid and send it back.
1370 GetFlowTablesStatisticsOutputBuilder output = new GetFlowTablesStatisticsOutputBuilder();
1371 output.setTransactionId(generateTransactionId(xid));
1373 Collection<RpcError> errors = Collections.emptyList();
1374 RpcResult<GetFlowTablesStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1375 return Futures.immediateFuture(rpcResult);
1379 public Future<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> getAllQueuesStatisticsFromAllPorts(
1380 final GetAllQueuesStatisticsFromAllPortsInput arg0) {
1381 // Generate xid to associate it with the request
1382 Long xid = this.getSessionContext().getNextXid();
1385 "Prepare queue statistics request to collect stats for all queues attached to all the ports of node {} - TrasactionId - {}",
1386 arg0.getNode().getValue(), xid);
1388 // Create multipart request header
1389 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1390 mprInput.setType(MultipartType.OFPMPQUEUE);
1391 mprInput.setVersion(version);
1392 mprInput.setXid(xid);
1393 mprInput.setFlags(new MultipartRequestFlags(false));
1395 // Create multipart request body to fetch stats for all the port of the
1397 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1398 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1400 mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
1401 // Select all the ports
1402 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1404 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1406 // Set request body to main multipart request
1407 mprInput.setMultipartRequestBody(caseBuilder.build());
1409 // Send the request, no cookies associated, use any connection
1410 LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString());
1411 this.messageService.multipartRequest(mprInput.build(), null);
1413 // Prepare rpc return output. Set xid and send it back.
1414 GetAllQueuesStatisticsFromAllPortsOutputBuilder output = new GetAllQueuesStatisticsFromAllPortsOutputBuilder();
1415 output.setTransactionId(generateTransactionId(xid));
1416 output.setQueueIdAndStatisticsMap(null);
1418 Collection<RpcError> errors = Collections.emptyList();
1419 RpcResult<GetAllQueuesStatisticsFromAllPortsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1420 return Futures.immediateFuture(rpcResult);
1424 public Future<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> getAllQueuesStatisticsFromGivenPort(
1425 final GetAllQueuesStatisticsFromGivenPortInput arg0) {
1426 // Generate xid to associate it with the request
1427 Long xid = this.getSessionContext().getNextXid();
1429 LOG.debug("Prepare queue statistics request to collect stats for "
1430 + "all queues attached to given port {} of node {} - TrasactionId - {}", arg0.getNodeConnectorId()
1431 .toString(), arg0.getNode().getValue(), xid);
1433 // Create multipart request header
1434 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1435 mprInput.setType(MultipartType.OFPMPQUEUE);
1436 mprInput.setVersion(version);
1437 mprInput.setXid(xid);
1438 mprInput.setFlags(new MultipartRequestFlags(false));
1440 // Create multipart request body to fetch stats for all the port of the
1442 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1443 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1444 // Select all queues
1445 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1446 // Select specific port
1447 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1449 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1451 // Set request body to main multipart request
1452 mprInput.setMultipartRequestBody(caseBuilder.build());
1454 // Send the request, no cookies associated, use any connection
1455 LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString());
1456 this.messageService.multipartRequest(mprInput.build(), null);
1458 // Prepare rpc return output. Set xid and send it back.
1459 GetAllQueuesStatisticsFromGivenPortOutputBuilder output = new GetAllQueuesStatisticsFromGivenPortOutputBuilder();
1460 output.setTransactionId(generateTransactionId(xid));
1461 output.setQueueIdAndStatisticsMap(null);
1463 Collection<RpcError> errors = Collections.emptyList();
1464 RpcResult<GetAllQueuesStatisticsFromGivenPortOutput> rpcResult = Rpcs
1465 .getRpcResult(true, output.build(), errors);
1466 return Futures.immediateFuture(rpcResult);
1470 public Future<RpcResult<GetQueueStatisticsFromGivenPortOutput>> getQueueStatisticsFromGivenPort(
1471 final GetQueueStatisticsFromGivenPortInput arg0) {
1472 // Generate xid to associate it with the request
1473 Long xid = this.getSessionContext().getNextXid();
1475 LOG.debug("Prepare queue statistics request to collect stats for "
1476 + "given queue attached to given port {} of node {} - TrasactionId - {}", arg0.getQueueId().toString(),
1477 arg0.getNodeConnectorId().toString(), arg0.getNode().getValue(), xid);
1479 // Create multipart request header
1480 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1481 mprInput.setType(MultipartType.OFPMPQUEUE);
1482 mprInput.setVersion(version);
1483 mprInput.setXid(xid);
1484 mprInput.setFlags(new MultipartRequestFlags(false));
1486 // Create multipart request body to fetch stats for all the port of the
1488 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1489 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1490 // Select specific queue
1491 mprQueueBuilder.setQueueId(arg0.getQueueId().getValue());
1492 // Select specific port
1493 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1495 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1497 // Set request body to main multipart request
1498 mprInput.setMultipartRequestBody(caseBuilder.build());
1500 // Send the request, no cookies associated, use any connection
1501 LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString());
1502 this.messageService.multipartRequest(mprInput.build(), null);
1504 // Prepare rpc return output. Set xid and send it back.
1505 GetQueueStatisticsFromGivenPortOutputBuilder output = new GetQueueStatisticsFromGivenPortOutputBuilder();
1506 output.setTransactionId(generateTransactionId(xid));
1507 output.setQueueIdAndStatisticsMap(null);
1509 Collection<RpcError> errors = Collections.emptyList();
1510 RpcResult<GetQueueStatisticsFromGivenPortOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1511 return Futures.immediateFuture(rpcResult);