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;
17 import org.opendaylight.controller.sal.common.util.Rpcs;
18 import org.opendaylight.openflowjava.protocol.api.util.BinContent;
19 import org.opendaylight.openflowplugin.openflow.md.OFConstants;
20 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
21 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
22 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor;
23 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
24 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor;
25 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
26 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor;
27 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
28 import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService;
29 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
30 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutputBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutputBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutputBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutputBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutputBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutputBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutputBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutputBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutputBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutputBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutputBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Group;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Meter;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;
148 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;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.GetPortOutput;
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;
181 * RPC implementation of MD-switch
183 public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
185 private static final Logger LOG = org.slf4j.LoggerFactory
186 .getLogger(ModelDrivenSwitchImpl.class);
187 private final NodeId nodeId;
188 private final IMessageDispatchService messageService ;
189 private short version = 0;
191 protected ModelDrivenSwitchImpl(NodeId nodeId,
192 InstanceIdentifier<Node> identifier, SessionContext context) {
193 super(identifier, context);
194 this.nodeId = nodeId;
195 messageService = sessionContext.getMessageDispatchService() ;
196 version = context.getPrimaryConductor().getVersion();
201 public Future<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
202 // Convert the AddFlowInput to FlowModInput
203 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input, version);
204 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
205 barrierInput.setVersion(version);
207 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
208 // the request can be routed through any connection to the switch
210 SwitchConnectionDistinguisher cookie = null ;
211 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
212 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
215 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
216 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
218 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
221 rpcResultFromOFLib = resultFromOFLib.get();
222 } catch( Exception ex ) {
223 LOG.error( " Error while getting result for AddFlow RPC" + ex.getMessage());
226 UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult() ;
228 AddFlowOutputBuilder addFlowOutput = new AddFlowOutputBuilder() ;
229 addFlowOutput.setTransactionId(updateFlowOutput.getTransactionId()) ;
230 AddFlowOutput result = addFlowOutput.build();
232 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
233 RpcResult<AddFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
235 LOG.debug("Returning the Add Flow RPC result to MD-SAL");
236 return Futures.immediateFuture(rpcResult);
240 public Future<RpcResult<AddGroupOutput>> addGroup(AddGroupInput input) {
241 // Convert the AddGroupInput to GroupModInput
242 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input, version);
245 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
246 // the request can be routed through any connection to the switch
248 SwitchConnectionDistinguisher cookie = null ;
250 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
251 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
253 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
256 rpcResultFromOFLib = resultFromOFLib.get();
257 } catch( Exception ex ) {
258 LOG.error( " Error while getting result for AddGroup RPC" + ex.getMessage());
261 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult() ;
263 AddGroupOutputBuilder addGroupOutput = new AddGroupOutputBuilder() ;
264 addGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()) ;
265 AddGroupOutput result = addGroupOutput.build();
267 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
268 RpcResult<AddGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
270 LOG.debug("Returning the Add Group RPC result to MD-SAL");
271 return Futures.immediateFuture(rpcResult);
275 public Future<RpcResult<AddMeterOutput>> addMeter(AddMeterInput input) {
276 // Convert the AddMeterInput to MeterModInput
277 MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
279 // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
280 // the request can be routed through any connection to the switch
282 SwitchConnectionDistinguisher cookie = null ;
284 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
285 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ;
287 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null ;
290 rpcResultFromOFLib = resultFromOFLib.get();
291 } catch( Exception ex ) {
292 LOG.error( " Error while getting result for AddMeter RPC" + ex.getMessage());
295 UpdateMeterOutput updateMeterOutput = rpcResultFromOFLib.getResult() ;
297 AddMeterOutputBuilder addMeterOutput = new AddMeterOutputBuilder() ;
298 addMeterOutput.setTransactionId(updateMeterOutput.getTransactionId()) ;
299 AddMeterOutput result = addMeterOutput.build();
301 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
302 RpcResult<AddMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
304 LOG.debug("Returning the Add Meter RPC result to MD-SAL");
305 return Futures.immediateFuture(rpcResult);
309 public Future<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
310 // Convert the RemoveFlowInput to FlowModInput
311 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input, version);
312 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
313 barrierInput.setVersion(version);
315 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
316 // the request can be routed through any connection to the switch
318 SwitchConnectionDistinguisher cookie = null ;
319 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
320 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
323 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
324 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
326 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
329 rpcResultFromOFLib = resultFromOFLib.get();
330 } catch( Exception ex ) {
331 LOG.error( " Error while getting result for remove Flow RPC" + ex.getMessage());
334 UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult() ;
336 RemoveFlowOutputBuilder removeFlowOutput = new RemoveFlowOutputBuilder() ;
337 removeFlowOutput.setTransactionId(updateFlowOutput.getTransactionId()) ;
338 RemoveFlowOutput result = removeFlowOutput.build();
340 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
341 RpcResult<RemoveFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
343 LOG.debug("Returning the Remove Flow RPC result to MD-SAL");
344 return Futures.immediateFuture(rpcResult);
348 public Future<RpcResult<RemoveGroupOutput>> removeGroup(
349 RemoveGroupInput input) {
350 // Convert the RemoveGroupInput to GroupModInput
351 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input, version);
354 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
355 // the request can be routed through any connection to the switch
357 SwitchConnectionDistinguisher cookie = null ;
359 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
360 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
362 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
365 rpcResultFromOFLib = resultFromOFLib.get();
366 } catch( Exception ex ) {
367 LOG.error( " Error while getting result for RemoveGroup RPC" + ex.getMessage());
370 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult() ;
372 RemoveGroupOutputBuilder removeGroupOutput = new RemoveGroupOutputBuilder() ;
373 removeGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()) ;
374 RemoveGroupOutput result = removeGroupOutput.build();
376 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
377 RpcResult<RemoveGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
379 LOG.debug("Returning the Remove Group RPC result to MD-SAL");
380 return Futures.immediateFuture(rpcResult);
384 public Future<RpcResult<RemoveMeterOutput>> removeMeter(
385 RemoveMeterInput input) {
386 // Convert the RemoveMeterInput to MeterModInput
387 MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
390 // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
391 // the request can be routed through any connection to the switch
393 SwitchConnectionDistinguisher cookie = null ;
395 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
396 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ;
398 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null ;
401 rpcResultFromOFLib = resultFromOFLib.get();
402 } catch( Exception ex ) {
403 LOG.error( " Error while getting result for RemoveMeter RPC" + ex.getMessage());
406 UpdateMeterOutput updatemeterOutput = rpcResultFromOFLib.getResult() ;
408 RemoveMeterOutputBuilder removeMeterOutput = new RemoveMeterOutputBuilder() ;
409 removeMeterOutput.setTransactionId(updatemeterOutput.getTransactionId()) ;
410 RemoveMeterOutput result = removeMeterOutput.build();
412 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
413 RpcResult<RemoveMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
415 LOG.debug("Returning the Remove Meter RPC result to MD-SAL");
416 return Futures.immediateFuture(rpcResult);
420 public Future<RpcResult<Void>> transmitPacket(TransmitPacketInput input) {
421 LOG.info("TransmitPacket - {}",input);
422 // Convert TransmitPacket to PacketOutInput
423 PacketOutInput message = PacketOutConvertor.toPacketOutInput(input, version, sessionContext.getNextXid());
425 // TODO VD NULL for yet - find how to translate cookie from TransmitPacketInput
426 // SwitchConnectionDistinguisher cookie = ( "what is need to do" ) input.getCookie();
427 SwitchConnectionDistinguisher cookie = null ;
429 LOG.debug("Calling the transmitPacket RPC method");
430 return messageService.packetOut(message, cookie);
433 private FlowModInputBuilder toFlowModInputBuilder(Flow source) {
434 FlowModInputBuilder target = new FlowModInputBuilder();
435 target.setCookie(source.getCookie());
436 target.setIdleTimeout(source.getIdleTimeout());
437 target.setHardTimeout(source.getHardTimeout());
438 target.setMatch(toMatch(source.getMatch()));
443 private Match toMatch(
444 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
445 MatchBuilder target = new MatchBuilder();
447 target.setMatchEntries(toMatchEntries(match));
452 private List<MatchEntries> toMatchEntries(
453 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
454 List<MatchEntries> entries = new ArrayList<>();
460 public Future<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
461 // Convert the UpdateFlowInput to FlowModInput
462 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input.getUpdatedFlow(), version);
463 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
464 barrierInput.setVersion(version);
465 // Call the RPC method on MessageDispatchService
467 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
468 // the request can be routed through any connection to the switch
470 SwitchConnectionDistinguisher cookie = null ;
471 if (Objects.firstNonNull(input.getUpdatedFlow().isBarrier(), Boolean.FALSE)) {
472 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
475 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
476 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
478 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
481 rpcResultFromOFLib = resultFromOFLib.get();
482 } catch( Exception ex ) {
483 LOG.error( " Error while getting result for UpdateFlow RPC" + ex.getMessage());
486 UpdateFlowOutput updateFlowOutputOFLib = rpcResultFromOFLib.getResult() ;
488 UpdateFlowOutputBuilder updateFlowOutput = new UpdateFlowOutputBuilder() ;
489 updateFlowOutput.setTransactionId(updateFlowOutputOFLib.getTransactionId()) ;
490 UpdateFlowOutput result = updateFlowOutput.build();
492 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
493 RpcResult<UpdateFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
495 LOG.debug("Returning the Update Flow RPC result to MD-SAL");
496 return Futures.immediateFuture(rpcResult);
500 public Future<RpcResult<UpdateGroupOutput>> updateGroup(
501 UpdateGroupInput input) {
502 // Convert the UpdateGroupInput to GroupModInput
503 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input.getUpdatedGroup(), version);
506 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
507 // the request can be routed through any connection to the switch
509 SwitchConnectionDistinguisher cookie = null ;
511 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
512 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
514 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
517 rpcResultFromOFLib = resultFromOFLib.get();
518 } catch( Exception ex ) {
519 LOG.error( " Error while getting result for updateGroup RPC" + ex.getMessage());
522 UpdateGroupOutput updateGroupOutputOFLib = rpcResultFromOFLib.getResult() ;
524 UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder() ;
525 updateGroupOutput.setTransactionId(updateGroupOutputOFLib.getTransactionId()) ;
526 UpdateGroupOutput result = updateGroupOutput.build();
528 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
529 RpcResult<UpdateGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
531 LOG.debug("Returning the Update Group RPC result to MD-SAL");
532 return Futures.immediateFuture(rpcResult);
536 public Future<RpcResult<UpdateMeterOutput>> updateMeter(
537 UpdateMeterInput input) {
538 // Convert the UpdateMeterInput to MeterModInput
539 MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input.getUpdatedMeter(), version);
542 // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
543 // the request can be routed through any connection to the switch
545 SwitchConnectionDistinguisher cookie = null ;
547 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
548 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ;
550 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null ;
553 rpcResultFromOFLib = resultFromOFLib.get();
554 } catch( Exception ex ) {
555 LOG.error( " Error while getting result for UpdateMeter RPC" + ex.getMessage());
558 UpdateMeterOutput updateMeterOutputFromOFLib = rpcResultFromOFLib.getResult() ;
560 UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder() ;
561 updateMeterOutput.setTransactionId(updateMeterOutputFromOFLib.getTransactionId()) ;
562 UpdateMeterOutput result = updateMeterOutput.build();
564 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
565 RpcResult<UpdateMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
567 LOG.debug("Returning the Update Meter RPC result to MD-SAL");
568 return Futures.immediateFuture(rpcResult);
572 public NodeId getNodeId() {
577 * Methods for requesting statistics from switch
580 public Future<RpcResult<GetAllGroupStatisticsOutput>> getAllGroupStatistics(GetAllGroupStatisticsInput input) {
582 //Generate xid to associate it with the request
583 Long xid = this.getSessionContext().getNextXid();
585 LOG.debug("Prepare statistics request for all the groups - Transaction id - {}",xid);
587 // Create multipart request header
588 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
589 mprInput.setType(MultipartType.OFPMPGROUP);
590 mprInput.setVersion(version);
591 mprInput.setXid(xid);
592 mprInput.setFlags(new MultipartRequestFlags(false));
594 // Create multipart request body for fetch all the group stats
595 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
596 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
597 mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(Group.OFPGALL.getIntValue())));
598 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
600 //Set request body to main multipart request
601 mprInput.setMultipartRequestBody(caseBuilder.build());
603 //Send the request, no cookies associated, use any connection
604 LOG.debug("Send group statistics request to the switch :{}",mprGroupBuild);
605 this.messageService.multipartRequest(mprInput.build(), null);
607 // Prepare rpc return output. Set xid and send it back.
608 LOG.debug("Return results and transaction id back to caller");
609 GetAllGroupStatisticsOutputBuilder output = new GetAllGroupStatisticsOutputBuilder();
610 output.setTransactionId(generateTransactionId(xid));
611 output.setGroupStats(null);
613 Collection<RpcError> errors = Collections.emptyList();
614 RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
615 return Futures.immediateFuture(rpcResult);
620 public Future<RpcResult<GetGroupDescriptionOutput>> getGroupDescription(GetGroupDescriptionInput input) {
622 //Generate xid to associate it with the request
623 Long xid = this.getSessionContext().getNextXid();
625 LOG.debug("Prepare group description statistics request - Transaction id - {}",xid);
627 // Create multipart request header
628 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
629 mprInput.setType(MultipartType.OFPMPGROUPDESC);
630 mprInput.setVersion(version);
631 mprInput.setXid(xid);
632 mprInput.setFlags(new MultipartRequestFlags(false));
634 // Create multipart request body for fetch all the group description stats
635 MultipartRequestGroupDescCaseBuilder mprGroupDescBuild = new MultipartRequestGroupDescCaseBuilder();
637 //Set request body to main multipart request
638 mprInput.setMultipartRequestBody(mprGroupDescBuild.build());
640 //Send the request, no cookies associated, use any connection
641 LOG.debug("Send group desciption statistics request to switch : {}",mprGroupDescBuild);
642 this.messageService.multipartRequest(mprInput.build(), null);
644 // Prepare rpc return output. Set xid and send it back.
645 LOG.debug("Return results and transaction id back to caller");
646 GetGroupDescriptionOutputBuilder output = new GetGroupDescriptionOutputBuilder();
647 output.setTransactionId(generateTransactionId(xid));
648 output.setGroupDescStats(null);
650 Collection<RpcError> errors = Collections.emptyList();
651 RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
652 return Futures.immediateFuture(rpcResult);
657 public Future<RpcResult<GetGroupFeaturesOutput>> getGroupFeatures(GetGroupFeaturesInput input) {
659 //Generate xid to associate it with the request
660 Long xid = this.getSessionContext().getNextXid();
662 LOG.debug("Prepare group features statistics request - Transaction id - {}",xid);
664 // Create multipart request header
665 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
666 mprInput.setType(MultipartType.OFPMPGROUPFEATURES);
667 mprInput.setVersion(version);
668 mprInput.setXid(xid);
669 mprInput.setFlags(new MultipartRequestFlags(false));
671 // Create multipart request body for fetch all the group description stats
672 MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild = new MultipartRequestGroupFeaturesCaseBuilder();
674 //Set request body to main multipart request
675 mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
677 //Send the request, no cookies associated, use any connection
678 LOG.debug("Send group features statistics request :{}",mprGroupFeaturesBuild);
679 this.messageService.multipartRequest(mprInput.build(), null);
681 // Prepare rpc return output. Set xid and send it back.
682 LOG.debug("Return results and transaction id back to caller");
683 GetGroupFeaturesOutputBuilder output = new GetGroupFeaturesOutputBuilder();
684 output.setTransactionId(generateTransactionId(xid));
686 Collection<RpcError> errors = Collections.emptyList();
687 RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
688 return Futures.immediateFuture(rpcResult);
692 public Future<RpcResult<GetGroupStatisticsOutput>> getGroupStatistics(GetGroupStatisticsInput input) {
694 //Generate xid to associate it with the request
695 Long xid = this.getSessionContext().getNextXid();
697 LOG.debug("Prepare statistics request for node {} group ({}) - Transaction id - {}",input.getNode(),input.getGroupId(),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(input.getGroupId().getValue()));
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 :{}",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 GetGroupStatisticsOutputBuilder output = new GetGroupStatisticsOutputBuilder();
722 output.setTransactionId(generateTransactionId(xid));
723 output.setGroupStats(null);
725 Collection<RpcError> errors = Collections.emptyList();
726 RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
727 return Futures.immediateFuture(rpcResult);
731 public Future<RpcResult<GetAllMeterConfigStatisticsOutput>> getAllMeterConfigStatistics(
732 GetAllMeterConfigStatisticsInput input) {
734 //Generate xid to associate it with the request
735 Long xid = this.getSessionContext().getNextXid();
737 LOG.debug("Prepare config request for all the meters - Transaction id - {}",xid);
739 // Create multipart request header
740 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
741 mprInput.setType(MultipartType.OFPMPMETERCONFIG);
742 mprInput.setVersion(version);
743 mprInput.setXid(xid);
744 mprInput.setFlags(new MultipartRequestFlags(false));
746 // Create multipart request body for fetch all the meter stats
747 MultipartRequestMeterConfigCaseBuilder caseBuilder = new MultipartRequestMeterConfigCaseBuilder();
748 MultipartRequestMeterConfigBuilder mprMeterConfigBuild = new MultipartRequestMeterConfigBuilder();
749 mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
750 caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
752 //Set request body to main multipart request
753 mprInput.setMultipartRequestBody(caseBuilder.build());
755 //Send the request, no cookies associated, use any connection
756 LOG.debug("Send meter statistics request :{}",mprMeterConfigBuild);
757 this.messageService.multipartRequest(mprInput.build(), null);
759 // Prepare rpc return output. Set xid and send it back.
760 LOG.debug("Return results and transaction id back to caller");
761 GetAllMeterConfigStatisticsOutputBuilder output = new GetAllMeterConfigStatisticsOutputBuilder();
762 output.setTransactionId(generateTransactionId(xid));
763 output.setMeterConfigStats(null);
765 Collection<RpcError> errors = Collections.emptyList();
766 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
767 return Futures.immediateFuture(rpcResult);
771 public Future<RpcResult<GetAllMeterStatisticsOutput>> getAllMeterStatistics(GetAllMeterStatisticsInput input) {
773 //Generate xid to associate it with the request
774 Long xid = this.getSessionContext().getNextXid();
776 LOG.debug("Prepare statistics request for all the meters - Transaction id - {}",xid);
778 // Create multipart request header
779 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
780 mprInput.setType(MultipartType.OFPMPMETER);
781 mprInput.setVersion(version);
782 mprInput.setXid(xid);
783 mprInput.setFlags(new MultipartRequestFlags(false));
785 // Create multipart request body for fetch all the meter stats
786 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
787 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
788 mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
789 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
791 //Set request body to main multipart request
792 mprInput.setMultipartRequestBody(caseBuilder.build());
794 //Send the request, no cookies associated, use any connection
795 LOG.debug("Send meter statistics request :{}",mprMeterBuild);
796 this.messageService.multipartRequest(mprInput.build(), null);
798 // Prepare rpc return output. Set xid and send it back.
799 LOG.debug("Return results and transaction id back to caller");
800 GetAllMeterStatisticsOutputBuilder output = new GetAllMeterStatisticsOutputBuilder();
801 output.setTransactionId(generateTransactionId(xid));
802 output.setMeterStats(null);
804 Collection<RpcError> errors = Collections.emptyList();
805 RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
806 return Futures.immediateFuture(rpcResult);
810 public Future<RpcResult<GetMeterFeaturesOutput>> getMeterFeatures(GetMeterFeaturesInput input) {
812 //Generate xid to associate it with the request
813 Long xid = this.getSessionContext().getNextXid();
815 LOG.debug("Prepare features statistics request for all the meters - Transaction id - {}",xid);
817 // Create multipart request header
818 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
819 mprInput.setType(MultipartType.OFPMPMETERFEATURES);
820 mprInput.setVersion(version);
821 mprInput.setXid(xid);
822 mprInput.setFlags(new MultipartRequestFlags(false));
824 // Create multipart request body for fetch all the group description stats
825 MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild = new MultipartRequestMeterFeaturesCaseBuilder();
827 //Set request body to main multipart request
828 mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
830 //Send the request, no cookies associated, use any connection
831 LOG.debug("Send meter features statistics request :{}",mprMeterFeaturesBuild);
832 this.messageService.multipartRequest(mprInput.build(), null);
834 // Prepare rpc return output. Set xid and send it back.
835 LOG.debug("Return results and transaction id back to caller");
836 GetMeterFeaturesOutputBuilder output = new GetMeterFeaturesOutputBuilder();
837 output.setTransactionId(generateTransactionId(xid));
839 Collection<RpcError> errors = Collections.emptyList();
840 RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
841 return Futures.immediateFuture(rpcResult);
845 public Future<RpcResult<GetMeterStatisticsOutput>> getMeterStatistics(GetMeterStatisticsInput input) {
846 //Generate xid to associate it with the request
847 Long xid = this.getSessionContext().getNextXid();
849 LOG.debug("Preprae statistics request for Meter ({}) - Transaction id - {}",input.getMeterId().getValue(),xid);
851 // Create multipart request header
852 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
853 mprInput.setType(MultipartType.OFPMPMETER);
854 mprInput.setVersion(version);
855 mprInput.setXid(xid);
856 mprInput.setFlags(new MultipartRequestFlags(false));
858 // Create multipart request body for fetch all the meter stats
859 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
860 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
861 //Select specific meter
862 mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
863 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
865 //Set request body to main multipart request
866 mprInput.setMultipartRequestBody(caseBuilder.build());
868 //Send the request, no cookies associated, use any connection
869 LOG.debug("Send meter statistics request :{}",mprMeterBuild);
870 this.messageService.multipartRequest(mprInput.build(), null);
872 // Prepare rpc return output. Set xid and send it back.
873 LOG.debug("Return results and transaction id back to caller");
874 GetMeterStatisticsOutputBuilder output = new GetMeterStatisticsOutputBuilder();
875 output.setTransactionId(generateTransactionId(xid));
876 output.setMeterStats(null);
878 Collection<RpcError> errors = Collections.emptyList();
879 RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
880 return Futures.immediateFuture(rpcResult);
884 public Future<RpcResult<GetAllNodeConnectorsStatisticsOutput>> getAllNodeConnectorsStatistics(GetAllNodeConnectorsStatisticsInput arg0) {
886 //Generate xid to associate it with the request
887 Long xid = this.getSessionContext().getNextXid();
889 LOG.info("Prepare port statistics request for all ports of node {} - TrasactionId - {}",arg0.getNode().getValue(),xid);
891 // Create multipart request header
892 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
893 mprInput.setType(MultipartType.OFPMPPORTSTATS);
894 mprInput.setVersion(version);
895 mprInput.setXid(xid);
896 mprInput.setFlags(new MultipartRequestFlags(false));
898 // Create multipart request body to fetch stats for all the port of the node
899 MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
900 MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
902 mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
903 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
905 //Set request body to main multipart request
906 mprInput.setMultipartRequestBody(caseBuilder.build());
908 //Send the request, no cookies associated, use any connection
909 LOG.debug("Send port statistics request :{}",mprPortStatsBuilder.build().toString());
910 this.messageService.multipartRequest(mprInput.build(), null);
912 // Prepare rpc return output. Set xid and send it back.
913 GetAllNodeConnectorsStatisticsOutputBuilder output = new GetAllNodeConnectorsStatisticsOutputBuilder();
914 output.setTransactionId(generateTransactionId(xid));
916 Collection<RpcError> errors = Collections.emptyList();
917 RpcResult<GetAllNodeConnectorsStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
918 return Futures.immediateFuture(rpcResult);
922 public Future<RpcResult<GetNodeConnectorStatisticsOutput>> getNodeConnectorStatistics(GetNodeConnectorStatisticsInput arg0) {
923 //Generate xid to associate it with the request
924 Long xid = this.getSessionContext().getNextXid();
926 LOG.info("Prepare port statistics request for port {} of node {} - TrasactionId - {}",arg0.getNodeConnectorId(), arg0.getNode().getValue(),xid);
928 // Create multipart request header
929 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
930 mprInput.setType(MultipartType.OFPMPPORTSTATS);
931 mprInput.setVersion(version);
932 mprInput.setXid(xid);
933 mprInput.setFlags(new MultipartRequestFlags(false));
935 // Create multipart request body to fetch stats for all the port of the node
936 MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
937 MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
940 mprPortStatsBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
941 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
943 //Set request body to main multipart request
944 mprInput.setMultipartRequestBody(caseBuilder.build());
946 //Send the request, no cookies associated, use any connection
947 LOG.debug("Send port statistics request :{}",mprPortStatsBuilder.build().toString());
948 this.messageService.multipartRequest(mprInput.build(), null);
950 // Prepare rpc return output. Set xid and send it back.
951 GetNodeConnectorStatisticsOutputBuilder output = new GetNodeConnectorStatisticsOutputBuilder();
952 output.setTransactionId(generateTransactionId(xid));
954 Collection<RpcError> errors = Collections.emptyList();
955 RpcResult<GetNodeConnectorStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
956 return Futures.immediateFuture(rpcResult);
959 private TransactionId generateTransactionId(Long xid){
960 String stringXid =xid.toString();
961 BigInteger bigIntXid = new BigInteger( stringXid );
962 return new TransactionId(bigIntXid);
967 public Future<RpcResult<GetPortOutput>> getPort() {
968 // TODO Auto-generated method stub
974 public Future<RpcResult<UpdatePortOutput>> updatePort(UpdatePortInput input) {
975 PortModInput ofPortModInput = null ;
976 RpcResult<UpdatePortOutput> rpcResultFromOFLib = null ;
979 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
980 // the request can be routed through any connection to the switch
982 SwitchConnectionDistinguisher cookie = null ;
984 // NSF sends a list of port and the ModelDrivenSwitch will
985 // send one port at a time towards the switch ( mutiple RPCs calls)
986 List<Port> inputPorts = input.getUpdatedPort().getPort().getPort() ;
988 // Get the Xid. The same Xid has to be sent in all the RPCs
989 Long Xid = sessionContext.getNextXid();
991 for( Port inputPort : inputPorts) {
993 // Convert the UpdateGroupInput to GroupModInput
994 ofPortModInput = PortConvertor.toPortModInput(inputPort, version) ;
996 // Insert the Xid ( transaction Id) before calling the RPC on the OFLibrary
998 PortModInputBuilder mdInput = new PortModInputBuilder();
1000 mdInput.setVersion(ofPortModInput.getVersion()) ;
1001 mdInput.setPortNo(ofPortModInput.getPortNo()) ;
1002 mdInput.setMaskV10(ofPortModInput.getMaskV10()) ;
1003 mdInput.setMask(ofPortModInput.getMask()) ;
1004 mdInput.setHwAddress(ofPortModInput.getHwAddress());
1005 mdInput.setConfigV10(ofPortModInput.getConfigV10()) ;
1006 mdInput.setConfig(ofPortModInput.getConfig()) ;
1007 mdInput.setAdvertiseV10(ofPortModInput.getAdvertiseV10()) ;
1008 mdInput.setAdvertise(ofPortModInput.getAdvertise()) ;
1010 LOG.debug("Calling the PortMod RPC method on MessageDispatchService");
1011 Future<RpcResult<UpdatePortOutput>> resultFromOFLib = messageService.portMod(ofPortModInput, cookie) ;
1014 rpcResultFromOFLib = resultFromOFLib.get();
1015 } catch( Exception ex ) {
1016 LOG.error( " Error while getting result for updatePort RPC" + ex.getMessage());
1019 // The Future response value for all the RPCs except the last one is ignored
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(
1040 UpdateTableInput input) {
1042 // Get the Xid. The same Xid has to be sent in all the Multipart requests
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 object
1054 List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input.getUpdatedTable()) ;
1057 MultipartRequestTableFeaturesCaseBuilder caseRequest = new MultipartRequestTableFeaturesCaseBuilder();
1058 MultipartRequestTableFeaturesBuilder tableFeaturesRequest = new MultipartRequestTableFeaturesBuilder();
1060 mprInput.setFlags(new MultipartRequestFlags(true));
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);
1073 //Extract the Xid only from the Future for the last RPC and
1074 // send it back to the NSF
1075 LOG.debug("Returning the result and transaction id to NSF");
1076 LOG.debug("Return results and transaction id back to caller");
1077 UpdateTableOutputBuilder output = new UpdateTableOutputBuilder();
1078 output.setTransactionId(generateTransactionId(xid));
1080 Collection<RpcError> errors = Collections.emptyList();
1081 RpcResult<UpdateTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1082 return Futures.immediateFuture(rpcResult);
1086 public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
1087 GetAllFlowStatisticsFromFlowTableInput arg0) {
1089 //Generate xid to associate it with the request
1090 Long xid = this.getSessionContext().getNextXid();
1092 LOG.debug("Prepare statistics request to get flow stats for switch tables {} - Transaction id - {}"
1093 ,arg0.getTableId().getValue(),xid);
1095 // Create multipart request header
1096 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1097 mprInput.setType(MultipartType.OFPMPFLOW);
1098 mprInput.setVersion(version);
1099 mprInput.setXid(xid);
1100 mprInput.setFlags(new MultipartRequestFlags(false));
1102 // Create multipart request body for fetch all the group stats
1103 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder ();
1104 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1105 mprFlowRequestBuilder.setTableId(arg0.getTableId().getValue());
1106 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1107 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1108 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1109 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1111 if(version == OFConstants.OFP_VERSION_1_0){
1112 LOG.info("Target node is running openflow version 1.0");
1113 FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true);
1114 mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
1116 if(version == OFConstants.OFP_VERSION_1_3){
1117 LOG.info("Target node is running openflow version 1.3+");
1118 mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
1122 //Set request body to main multipart request
1123 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1124 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1126 //Send the request, no cookies associated, use any connection
1127 LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
1128 this.messageService.multipartRequest(mprInput.build(), null);
1130 // Prepare rpc return output. Set xid and send it back.
1131 LOG.debug("Return results and transaction id back to caller");
1132 GetAllFlowStatisticsFromFlowTableOutputBuilder output =
1133 new GetAllFlowStatisticsFromFlowTableOutputBuilder();
1134 output.setTransactionId(generateTransactionId(xid));
1135 output.setFlowAndStatisticsMapList(null);
1137 Collection<RpcError> errors = Collections.emptyList();
1138 RpcResult<GetAllFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1139 return Futures.immediateFuture(rpcResult);
1143 public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
1144 GetAllFlowsStatisticsFromAllFlowTablesInput arg0) {
1146 //Generate xid to associate it with the request
1147 Long xid = this.getSessionContext().getNextXid();
1149 LOG.info("Prepare statistics request to get flow stats of all switch tables - Transaction id - {}",xid);
1151 // Create multipart request header
1152 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1153 mprInput.setType(MultipartType.OFPMPFLOW);
1154 mprInput.setVersion(version);
1155 mprInput.setXid(xid);
1156 mprInput.setFlags(new MultipartRequestFlags(false));
1158 // Create multipart request body for fetch all the group stats
1159 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1160 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1161 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
1162 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1163 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1164 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1165 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1166 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1168 //TODO: repeating code
1169 if(version == OFConstants.OFP_VERSION_1_0){
1170 FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true);
1171 mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
1173 if(version == OFConstants.OFP_VERSION_1_3){
1174 mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
1176 //Set request body to main multipart request
1177 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1178 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1180 //Send the request, no cookies associated, use any connection
1181 LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
1182 this.messageService.multipartRequest(mprInput.build(), null);
1184 // Prepare rpc return output. Set xid and send it back.
1185 GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder output =
1186 new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder();
1187 output.setTransactionId(generateTransactionId(xid));
1188 output.setFlowAndStatisticsMapList(null);
1190 Collection<RpcError> errors = Collections.emptyList();
1191 RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1192 return Futures.immediateFuture(rpcResult);
1197 public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
1198 GetFlowStatisticsFromFlowTableInput arg0) {
1199 //Generate xid to associate it with the request
1200 Long xid = this.getSessionContext().getNextXid();
1202 LOG.info("Prepare statistics request to get stats for flow {} for switch tables {} - Transaction id - {}"
1203 ,arg0.getMatch().toString(),arg0.getTableId(),xid);
1205 // Create multipart request header
1206 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1207 mprInput.setType(MultipartType.OFPMPFLOW);
1208 mprInput.setVersion(version);
1209 mprInput.setXid(xid);
1210 mprInput.setFlags(new MultipartRequestFlags(false));
1212 // Create multipart request body for fetch all the group stats
1213 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1214 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1215 mprFlowRequestBuilder.setTableId(arg0.getTableId());
1216 mprFlowRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1217 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1218 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1219 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1221 // convert and inject match
1222 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprFlowRequestBuilder);
1223 //TODO: repeating code
1224 if(version == OFConstants.OFP_VERSION_1_3){
1225 mprFlowRequestBuilder.setCookie(arg0.getCookie());
1226 mprFlowRequestBuilder.setCookieMask(arg0.getCookieMask());
1227 mprFlowRequestBuilder.setOutGroup(arg0.getOutGroup());
1230 //Set request body to main multipart request
1231 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1232 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1234 //Send the request, no cookies associated, use any connection
1235 LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
1236 this.messageService.multipartRequest(mprInput.build(), null);
1238 // Prepare rpc return output. Set xid and send it back.
1239 GetFlowStatisticsFromFlowTableOutputBuilder output =
1240 new GetFlowStatisticsFromFlowTableOutputBuilder();
1241 output.setTransactionId(generateTransactionId(xid));
1242 output.setFlowAndStatisticsMapList(null);
1244 Collection<RpcError> errors = Collections.emptyList();
1245 RpcResult<GetFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1246 return Futures.immediateFuture(rpcResult);
1250 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
1251 GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput arg0) {
1252 //Generate xid to associate it with the request
1253 Long xid = this.getSessionContext().getNextXid();
1255 LOG.info("Prepare aggregate flow statistics request to get aggregate flow stats for all the flow installed on switch table {} - Transaction id - {}"
1256 ,arg0.getTableId().getValue(),xid);
1258 // Create multipart request header
1259 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1260 mprInput.setType(MultipartType.OFPMPAGGREGATE);
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 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder ();
1267 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1268 mprAggregateRequestBuilder.setTableId(arg0.getTableId().getValue());
1269 mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1270 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1271 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1272 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1274 //TODO: repeating code
1275 if(version == OFConstants.OFP_VERSION_1_0){
1276 FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true);
1277 mprAggregateRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
1279 if(version == OFConstants.OFP_VERSION_1_3){
1280 mprAggregateRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
1284 //Set request body to main multipart request
1285 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1286 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1288 //Send the request, no cookies associated, use any connection
1289 LOG.debug("Send request to the switch :{}",multipartRequestAggregateCaseBuilder.build().toString());
1290 this.messageService.multipartRequest(mprInput.build(), null);
1292 // Prepare rpc return output. Set xid and send it back.
1293 GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder output =
1294 new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder();
1295 output.setTransactionId(generateTransactionId(xid));
1297 Collection<RpcError> errors = Collections.emptyList();
1298 RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1299 return Futures.immediateFuture(rpcResult);
1303 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
1304 GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput arg0) {
1306 //Generate xid to associate it with the request
1307 Long xid = this.getSessionContext().getNextXid();
1309 LOG.debug("Prepare aggregate statistics request to get aggregate stats for flows matching {} and installed in flow tables {} - Transaction id - {}"
1310 ,arg0.getMatch().toString(),arg0.getTableId(),xid);
1312 // Create multipart request header
1313 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1314 mprInput.setType(MultipartType.OFPMPAGGREGATE);
1315 mprInput.setVersion(version);
1316 mprInput.setXid(xid);
1317 mprInput.setFlags(new MultipartRequestFlags(false));
1319 // Create multipart request body for fetch all the group stats
1320 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder ();
1321 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1322 mprAggregateRequestBuilder.setTableId(arg0.getTableId());
1323 mprAggregateRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1324 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1325 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1326 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1329 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprAggregateRequestBuilder);
1330 //TODO: repeating code
1331 if(version == OFConstants.OFP_VERSION_1_3){
1332 mprAggregateRequestBuilder.setCookie(arg0.getCookie());
1333 mprAggregateRequestBuilder.setCookieMask(arg0.getCookieMask());
1334 mprAggregateRequestBuilder.setOutGroup(arg0.getOutGroup());
1337 //Set request body to main multipart request
1338 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1339 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1341 //Send the request, no cookies associated, use any connection
1342 LOG.debug("Send request to the switch :{}",multipartRequestAggregateCaseBuilder.build().toString());
1343 this.messageService.multipartRequest(mprInput.build(), null);
1345 // Prepare rpc return output. Set xid and send it back.
1346 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder output =
1347 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
1348 output.setTransactionId(generateTransactionId(xid));
1350 Collection<RpcError> errors = Collections.emptyList();
1351 RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1352 return Futures.immediateFuture(rpcResult);
1356 public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(GetFlowTablesStatisticsInput arg0) {
1357 //Generate xid to associate it with the request
1358 Long xid = this.getSessionContext().getNextXid();
1360 LOG.info("Prepare flow table statistics request to get flow table stats for all tables " +
1361 "from node {}- Transaction id - {}",arg0.getNode(),xid);
1363 // Create multipart request header
1364 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1365 mprInput.setType(MultipartType.OFPMPTABLE);
1366 mprInput.setVersion(version);
1367 mprInput.setXid(xid);
1368 mprInput.setFlags(new MultipartRequestFlags(false));
1370 // Create multipart request body for fetch all the group stats
1371 MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder ();
1372 MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
1373 multipartRequestTableBuilder.setEmpty(true);
1374 multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
1376 //Set request body to main multipart request
1377 mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
1379 //Send the request, no cookies associated, use any connection
1380 LOG.debug("Send request to the switch :{}",multipartRequestTableCaseBuilder.build().toString());
1381 this.messageService.multipartRequest(mprInput.build(), null);
1383 // Prepare rpc return output. Set xid and send it back.
1384 GetFlowTablesStatisticsOutputBuilder output = new GetFlowTablesStatisticsOutputBuilder();
1385 output.setTransactionId(generateTransactionId(xid));
1387 Collection<RpcError> errors = Collections.emptyList();
1388 RpcResult<GetFlowTablesStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1389 return Futures.immediateFuture(rpcResult);
1393 public Future<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> getAllQueuesStatisticsFromAllPorts(
1394 GetAllQueuesStatisticsFromAllPortsInput arg0) {
1395 //Generate xid to associate it with the request
1396 Long xid = this.getSessionContext().getNextXid();
1398 LOG.info("Prepare queue statistics request to collect stats for all queues attached to all the ports of node {} - TrasactionId - {}",arg0.getNode().getValue(),xid);
1400 // Create multipart request header
1401 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1402 mprInput.setType(MultipartType.OFPMPQUEUE);
1403 mprInput.setVersion(version);
1404 mprInput.setXid(xid);
1405 mprInput.setFlags(new MultipartRequestFlags(false));
1407 // Create multipart request body to fetch stats for all the port of the node
1408 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1409 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1411 mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
1412 //Select all the ports
1413 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1415 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1417 //Set request body to main multipart request
1418 mprInput.setMultipartRequestBody(caseBuilder.build());
1420 //Send the request, no cookies associated, use any connection
1421 LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString());
1422 this.messageService.multipartRequest(mprInput.build(), null);
1424 // Prepare rpc return output. Set xid and send it back.
1425 GetAllQueuesStatisticsFromAllPortsOutputBuilder output = new GetAllQueuesStatisticsFromAllPortsOutputBuilder();
1426 output.setTransactionId(generateTransactionId(xid));
1427 output.setQueueIdAndStatisticsMap(null);
1429 Collection<RpcError> errors = Collections.emptyList();
1430 RpcResult<GetAllQueuesStatisticsFromAllPortsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1431 return Futures.immediateFuture(rpcResult);
1435 public Future<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> getAllQueuesStatisticsFromGivenPort(
1436 GetAllQueuesStatisticsFromGivenPortInput arg0) {
1437 //Generate xid to associate it with the request
1438 Long xid = this.getSessionContext().getNextXid();
1440 LOG.info("Prepare queue statistics request to collect stats for " +
1441 "all queues attached to given port {} of node {} - TrasactionId - {}",arg0.getNodeConnectorId().toString(),arg0.getNode().getValue(),xid);
1443 // Create multipart request header
1444 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1445 mprInput.setType(MultipartType.OFPMPQUEUE);
1446 mprInput.setVersion(version);
1447 mprInput.setXid(xid);
1448 mprInput.setFlags(new MultipartRequestFlags(false));
1450 // Create multipart request body to fetch stats for all the port of the node
1451 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1452 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1454 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1455 //Select specific port
1456 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1458 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1460 //Set request body to main multipart request
1461 mprInput.setMultipartRequestBody(caseBuilder.build());
1463 //Send the request, no cookies associated, use any connection
1464 LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString());
1465 this.messageService.multipartRequest(mprInput.build(), null);
1467 // Prepare rpc return output. Set xid and send it back.
1468 GetAllQueuesStatisticsFromGivenPortOutputBuilder output = new GetAllQueuesStatisticsFromGivenPortOutputBuilder();
1469 output.setTransactionId(generateTransactionId(xid));
1470 output.setQueueIdAndStatisticsMap(null);
1472 Collection<RpcError> errors = Collections.emptyList();
1473 RpcResult<GetAllQueuesStatisticsFromGivenPortOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1474 return Futures.immediateFuture(rpcResult);
1478 public Future<RpcResult<GetQueueStatisticsFromGivenPortOutput>> getQueueStatisticsFromGivenPort(
1479 GetQueueStatisticsFromGivenPortInput arg0) {
1480 //Generate xid to associate it with the request
1481 Long xid = this.getSessionContext().getNextXid();
1483 LOG.info("Prepare queue statistics request to collect stats for " +
1484 "given queue attached to given port {} of node {} - TrasactionId - {}",arg0.getQueueId().toString(),arg0.getNodeConnectorId().toString(),arg0.getNode().getValue(),xid);
1486 // Create multipart request header
1487 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1488 mprInput.setType(MultipartType.OFPMPQUEUE);
1489 mprInput.setVersion(version);
1490 mprInput.setXid(xid);
1491 mprInput.setFlags(new MultipartRequestFlags(false));
1493 // Create multipart request body to fetch stats for all the port of the node
1494 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1495 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1496 //Select specific queue
1497 mprQueueBuilder.setQueueId(arg0.getQueueId().getValue());
1498 //Select specific port
1499 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1501 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1503 //Set request body to main multipart request
1504 mprInput.setMultipartRequestBody(caseBuilder.build());
1506 //Send the request, no cookies associated, use any connection
1507 LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString());
1508 this.messageService.multipartRequest(mprInput.build(), null);
1510 // Prepare rpc return output. Set xid and send it back.
1511 GetQueueStatisticsFromGivenPortOutputBuilder output = new GetQueueStatisticsFromGivenPortOutputBuilder();
1512 output.setTransactionId(generateTransactionId(xid));
1513 output.setQueueIdAndStatisticsMap(null);
1515 Collection<RpcError> errors = Collections.emptyList();
1516 RpcResult<GetQueueStatisticsFromGivenPortOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1517 return Futures.immediateFuture(rpcResult);