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.GetAllFlowStatisticsInput;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsOutput;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllNodeConnectorStatisticsInput;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllNodeConnectorStatisticsOutput;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutputBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsInput;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsOutput;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowTableStatisticsInput;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowTableStatisticsOutput;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetNodeConnectorStatisticsInput;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetNodeConnectorStatisticsOutput;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutputBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutputBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutputBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutputBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutputBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutputBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutputBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutputBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutputBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Group;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Meter;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;
158 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;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.GetPortOutput;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutputBuilder;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllPortsStatisticsInput;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllPortsStatisticsOutput;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllPortsStatisticsOutputBuilder;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetPortStatisticsInput;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetPortStatisticsOutput;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetPortStatisticsOutputBuilder;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutputBuilder;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInput;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutputBuilder;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInput;
177 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput;
178 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutputBuilder;
179 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
180 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
181 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder;
182 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
183 import org.opendaylight.yangtools.yang.common.RpcError;
184 import org.opendaylight.yangtools.yang.common.RpcResult;
185 import org.slf4j.Logger;
187 import com.google.common.base.Objects;
188 import com.google.common.util.concurrent.Futures;
191 * RPC implementation of MD-switch
193 public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
195 private static final Logger LOG = org.slf4j.LoggerFactory
196 .getLogger(ModelDrivenSwitchImpl.class);
197 private final NodeId nodeId;
198 private final IMessageDispatchService messageService ;
199 private short version = 0;
201 protected ModelDrivenSwitchImpl(NodeId nodeId,
202 InstanceIdentifier<Node> identifier, SessionContext context) {
203 super(identifier, context);
204 this.nodeId = nodeId;
205 messageService = sessionContext.getMessageDispatchService() ;
206 version = context.getPrimaryConductor().getVersion();
211 public Future<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
212 // Convert the AddFlowInput to FlowModInput
213 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input, version);
214 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
215 barrierInput.setVersion(version);
217 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
218 // the request can be routed through any connection to the switch
220 SwitchConnectionDistinguisher cookie = null ;
221 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
222 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
225 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
226 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
228 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
231 rpcResultFromOFLib = resultFromOFLib.get();
232 } catch( Exception ex ) {
233 LOG.error( " Error while getting result for AddFlow RPC" + ex.getMessage());
236 UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult() ;
238 AddFlowOutputBuilder addFlowOutput = new AddFlowOutputBuilder() ;
239 addFlowOutput.setTransactionId(updateFlowOutput.getTransactionId()) ;
240 AddFlowOutput result = addFlowOutput.build();
242 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
243 RpcResult<AddFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
245 LOG.debug("Returning the Add Flow RPC result to MD-SAL");
246 return Futures.immediateFuture(rpcResult);
250 public Future<RpcResult<AddGroupOutput>> addGroup(AddGroupInput input) {
251 // Convert the AddGroupInput to GroupModInput
252 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input, version);
255 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
256 // the request can be routed through any connection to the switch
258 SwitchConnectionDistinguisher cookie = null ;
260 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
261 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
263 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
266 rpcResultFromOFLib = resultFromOFLib.get();
267 } catch( Exception ex ) {
268 LOG.error( " Error while getting result for AddGroup RPC" + ex.getMessage());
271 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult() ;
273 AddGroupOutputBuilder addGroupOutput = new AddGroupOutputBuilder() ;
274 addGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()) ;
275 AddGroupOutput result = addGroupOutput.build();
277 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
278 RpcResult<AddGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
280 LOG.debug("Returning the Add Group RPC result to MD-SAL");
281 return Futures.immediateFuture(rpcResult);
285 public Future<RpcResult<AddMeterOutput>> addMeter(AddMeterInput input) {
286 // Convert the AddMeterInput to MeterModInput
287 MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
289 // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
290 // the request can be routed through any connection to the switch
292 SwitchConnectionDistinguisher cookie = null ;
294 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
295 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ;
297 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null ;
300 rpcResultFromOFLib = resultFromOFLib.get();
301 } catch( Exception ex ) {
302 LOG.error( " Error while getting result for AddMeter RPC" + ex.getMessage());
305 UpdateMeterOutput updateMeterOutput = rpcResultFromOFLib.getResult() ;
307 AddMeterOutputBuilder addMeterOutput = new AddMeterOutputBuilder() ;
308 addMeterOutput.setTransactionId(updateMeterOutput.getTransactionId()) ;
309 AddMeterOutput result = addMeterOutput.build();
311 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
312 RpcResult<AddMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
314 LOG.debug("Returning the Add Meter RPC result to MD-SAL");
315 return Futures.immediateFuture(rpcResult);
319 public Future<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
320 // Convert the RemoveFlowInput to FlowModInput
321 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input, version);
322 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
323 barrierInput.setVersion(version);
325 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
326 // the request can be routed through any connection to the switch
328 SwitchConnectionDistinguisher cookie = null ;
329 if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
330 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
333 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
334 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
336 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
339 rpcResultFromOFLib = resultFromOFLib.get();
340 } catch( Exception ex ) {
341 LOG.error( " Error while getting result for remove Flow RPC" + ex.getMessage());
344 UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult() ;
346 RemoveFlowOutputBuilder removeFlowOutput = new RemoveFlowOutputBuilder() ;
347 removeFlowOutput.setTransactionId(updateFlowOutput.getTransactionId()) ;
348 RemoveFlowOutput result = removeFlowOutput.build();
350 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
351 RpcResult<RemoveFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
353 LOG.debug("Returning the Remove Flow RPC result to MD-SAL");
354 return Futures.immediateFuture(rpcResult);
358 public Future<RpcResult<RemoveGroupOutput>> removeGroup(
359 RemoveGroupInput input) {
360 // Convert the RemoveGroupInput to GroupModInput
361 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input, version);
364 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
365 // the request can be routed through any connection to the switch
367 SwitchConnectionDistinguisher cookie = null ;
369 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
370 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
372 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
375 rpcResultFromOFLib = resultFromOFLib.get();
376 } catch( Exception ex ) {
377 LOG.error( " Error while getting result for RemoveGroup RPC" + ex.getMessage());
380 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult() ;
382 RemoveGroupOutputBuilder removeGroupOutput = new RemoveGroupOutputBuilder() ;
383 removeGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()) ;
384 RemoveGroupOutput result = removeGroupOutput.build();
386 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
387 RpcResult<RemoveGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
389 LOG.debug("Returning the Remove Group RPC result to MD-SAL");
390 return Futures.immediateFuture(rpcResult);
394 public Future<RpcResult<RemoveMeterOutput>> removeMeter(
395 RemoveMeterInput input) {
396 // Convert the RemoveMeterInput to MeterModInput
397 MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
400 // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
401 // the request can be routed through any connection to the switch
403 SwitchConnectionDistinguisher cookie = null ;
405 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
406 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ;
408 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null ;
411 rpcResultFromOFLib = resultFromOFLib.get();
412 } catch( Exception ex ) {
413 LOG.error( " Error while getting result for RemoveMeter RPC" + ex.getMessage());
416 UpdateMeterOutput updatemeterOutput = rpcResultFromOFLib.getResult() ;
418 RemoveMeterOutputBuilder removeMeterOutput = new RemoveMeterOutputBuilder() ;
419 removeMeterOutput.setTransactionId(updatemeterOutput.getTransactionId()) ;
420 RemoveMeterOutput result = removeMeterOutput.build();
422 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
423 RpcResult<RemoveMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
425 LOG.debug("Returning the Remove Meter RPC result to MD-SAL");
426 return Futures.immediateFuture(rpcResult);
430 public Future<RpcResult<Void>> transmitPacket(TransmitPacketInput input) {
431 LOG.info("TransmitPacket - {}",input);
432 // Convert TransmitPacket to PacketOutInput
433 PacketOutInput message = PacketOutConvertor.toPacketOutInput(input, version, sessionContext.getNextXid());
435 // TODO VD NULL for yet - find how to translate cookie from TransmitPacketInput
436 // SwitchConnectionDistinguisher cookie = ( "what is need to do" ) input.getCookie();
437 SwitchConnectionDistinguisher cookie = null ;
439 LOG.debug("Calling the transmitPacket RPC method");
440 return messageService.packetOut(message, cookie);
443 private FlowModInputBuilder toFlowModInputBuilder(Flow source) {
444 FlowModInputBuilder target = new FlowModInputBuilder();
445 target.setCookie(source.getCookie());
446 target.setIdleTimeout(source.getIdleTimeout());
447 target.setHardTimeout(source.getHardTimeout());
448 target.setMatch(toMatch(source.getMatch()));
453 private Match toMatch(
454 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
455 MatchBuilder target = new MatchBuilder();
457 target.setMatchEntries(toMatchEntries(match));
462 private List<MatchEntries> toMatchEntries(
463 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
464 List<MatchEntries> entries = new ArrayList<>();
470 public Future<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
471 // Convert the UpdateFlowInput to FlowModInput
472 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input.getUpdatedFlow(), version);
473 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
474 barrierInput.setVersion(version);
475 // Call the RPC method on MessageDispatchService
477 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
478 // the request can be routed through any connection to the switch
480 SwitchConnectionDistinguisher cookie = null ;
481 if (Objects.firstNonNull(input.getUpdatedFlow().isBarrier(), Boolean.FALSE)) {
482 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
485 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
486 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
488 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
491 rpcResultFromOFLib = resultFromOFLib.get();
492 } catch( Exception ex ) {
493 LOG.error( " Error while getting result for UpdateFlow RPC" + ex.getMessage());
496 UpdateFlowOutput updateFlowOutputOFLib = rpcResultFromOFLib.getResult() ;
498 UpdateFlowOutputBuilder updateFlowOutput = new UpdateFlowOutputBuilder() ;
499 updateFlowOutput.setTransactionId(updateFlowOutputOFLib.getTransactionId()) ;
500 UpdateFlowOutput result = updateFlowOutput.build();
502 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
503 RpcResult<UpdateFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
505 LOG.debug("Returning the Update Flow RPC result to MD-SAL");
506 return Futures.immediateFuture(rpcResult);
510 public Future<RpcResult<UpdateGroupOutput>> updateGroup(
511 UpdateGroupInput input) {
512 // Convert the UpdateGroupInput to GroupModInput
513 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input.getUpdatedGroup(), version);
516 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
517 // the request can be routed through any connection to the switch
519 SwitchConnectionDistinguisher cookie = null ;
521 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
522 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
524 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
527 rpcResultFromOFLib = resultFromOFLib.get();
528 } catch( Exception ex ) {
529 LOG.error( " Error while getting result for updateGroup RPC" + ex.getMessage());
532 UpdateGroupOutput updateGroupOutputOFLib = rpcResultFromOFLib.getResult() ;
534 UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder() ;
535 updateGroupOutput.setTransactionId(updateGroupOutputOFLib.getTransactionId()) ;
536 UpdateGroupOutput result = updateGroupOutput.build();
538 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
539 RpcResult<UpdateGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
541 LOG.debug("Returning the Update Group RPC result to MD-SAL");
542 return Futures.immediateFuture(rpcResult);
546 public Future<RpcResult<UpdateMeterOutput>> updateMeter(
547 UpdateMeterInput input) {
548 // Convert the UpdateMeterInput to MeterModInput
549 MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input.getUpdatedMeter(), version);
552 // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
553 // the request can be routed through any connection to the switch
555 SwitchConnectionDistinguisher cookie = null ;
557 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
558 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ;
560 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null ;
563 rpcResultFromOFLib = resultFromOFLib.get();
564 } catch( Exception ex ) {
565 LOG.error( " Error while getting result for UpdateMeter RPC" + ex.getMessage());
568 UpdateMeterOutput updateMeterOutputFromOFLib = rpcResultFromOFLib.getResult() ;
570 UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder() ;
571 updateMeterOutput.setTransactionId(updateMeterOutputFromOFLib.getTransactionId()) ;
572 UpdateMeterOutput result = updateMeterOutput.build();
574 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
575 RpcResult<UpdateMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
577 LOG.debug("Returning the Update Meter RPC result to MD-SAL");
578 return Futures.immediateFuture(rpcResult);
582 public NodeId getNodeId() {
587 * Methods for requesting statistics from switch
590 public Future<RpcResult<GetAllGroupStatisticsOutput>> getAllGroupStatistics(GetAllGroupStatisticsInput input) {
592 //Generate xid to associate it with the request
593 Long xid = this.getSessionContext().getNextXid();
595 LOG.debug("Prepare statistics request for all the groups - Transaction id - {}",xid);
597 // Create multipart request header
598 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
599 mprInput.setType(MultipartType.OFPMPGROUP);
600 mprInput.setVersion(version);
601 mprInput.setXid(xid);
602 mprInput.setFlags(new MultipartRequestFlags(false));
604 // Create multipart request body for fetch all the group stats
605 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
606 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
607 mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(Group.OFPGALL.getIntValue())));
608 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
610 //Set request body to main multipart request
611 mprInput.setMultipartRequestBody(caseBuilder.build());
613 //Send the request, no cookies associated, use any connection
614 LOG.debug("Send group statistics request to the switch :{}",mprGroupBuild);
615 this.messageService.multipartRequest(mprInput.build(), null);
617 // Prepare rpc return output. Set xid and send it back.
618 LOG.debug("Return results and transaction id back to caller");
619 GetAllGroupStatisticsOutputBuilder output = new GetAllGroupStatisticsOutputBuilder();
620 output.setTransactionId(generateTransactionId(xid));
621 output.setGroupStats(null);
623 Collection<RpcError> errors = Collections.emptyList();
624 RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
625 return Futures.immediateFuture(rpcResult);
630 public Future<RpcResult<GetGroupDescriptionOutput>> getGroupDescription(GetGroupDescriptionInput input) {
632 //Generate xid to associate it with the request
633 Long xid = this.getSessionContext().getNextXid();
635 LOG.debug("Prepare group description statistics request - Transaction id - {}",xid);
637 // Create multipart request header
638 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
639 mprInput.setType(MultipartType.OFPMPGROUPDESC);
640 mprInput.setVersion(version);
641 mprInput.setXid(xid);
642 mprInput.setFlags(new MultipartRequestFlags(false));
644 // Create multipart request body for fetch all the group description stats
645 MultipartRequestGroupDescCaseBuilder mprGroupDescBuild = new MultipartRequestGroupDescCaseBuilder();
647 //Set request body to main multipart request
648 mprInput.setMultipartRequestBody(mprGroupDescBuild.build());
650 //Send the request, no cookies associated, use any connection
651 LOG.debug("Send group desciption statistics request to switch : {}",mprGroupDescBuild);
652 this.messageService.multipartRequest(mprInput.build(), null);
654 // Prepare rpc return output. Set xid and send it back.
655 LOG.debug("Return results and transaction id back to caller");
656 GetGroupDescriptionOutputBuilder output = new GetGroupDescriptionOutputBuilder();
657 output.setTransactionId(generateTransactionId(xid));
658 output.setGroupDescStats(null);
660 Collection<RpcError> errors = Collections.emptyList();
661 RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
662 return Futures.immediateFuture(rpcResult);
667 public Future<RpcResult<GetGroupFeaturesOutput>> getGroupFeatures(GetGroupFeaturesInput input) {
669 //Generate xid to associate it with the request
670 Long xid = this.getSessionContext().getNextXid();
672 LOG.debug("Prepare group features statistics request - Transaction id - {}",xid);
674 // Create multipart request header
675 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
676 mprInput.setType(MultipartType.OFPMPGROUPFEATURES);
677 mprInput.setVersion(version);
678 mprInput.setXid(xid);
679 mprInput.setFlags(new MultipartRequestFlags(false));
681 // Create multipart request body for fetch all the group description stats
682 MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild = new MultipartRequestGroupFeaturesCaseBuilder();
684 //Set request body to main multipart request
685 mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
687 //Send the request, no cookies associated, use any connection
688 LOG.debug("Send group features statistics request :{}",mprGroupFeaturesBuild);
689 this.messageService.multipartRequest(mprInput.build(), null);
691 // Prepare rpc return output. Set xid and send it back.
692 LOG.debug("Return results and transaction id back to caller");
693 GetGroupFeaturesOutputBuilder output = new GetGroupFeaturesOutputBuilder();
694 output.setTransactionId(generateTransactionId(xid));
696 Collection<RpcError> errors = Collections.emptyList();
697 RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
698 return Futures.immediateFuture(rpcResult);
702 public Future<RpcResult<GetGroupStatisticsOutput>> getGroupStatistics(GetGroupStatisticsInput input) {
704 //Generate xid to associate it with the request
705 Long xid = this.getSessionContext().getNextXid();
707 LOG.debug("Prepare statistics request for node {} group ({}) - Transaction id - {}",input.getNode(),input.getGroupId(),xid);
709 // Create multipart request header
710 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
711 mprInput.setType(MultipartType.OFPMPGROUP);
712 mprInput.setVersion(version);
713 mprInput.setXid(xid);
714 mprInput.setFlags(new MultipartRequestFlags(false));
716 // Create multipart request body for fetch all the group stats
717 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
718 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
719 mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
720 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
722 //Set request body to main multipart request
723 mprInput.setMultipartRequestBody(caseBuilder.build());
725 //Send the request, no cookies associated, use any connection
726 LOG.debug("Send group statistics request :{}",mprGroupBuild);
727 this.messageService.multipartRequest(mprInput.build(), null);
729 // Prepare rpc return output. Set xid and send it back.
730 LOG.debug("Return results and transaction id back to caller");
731 GetGroupStatisticsOutputBuilder output = new GetGroupStatisticsOutputBuilder();
732 output.setTransactionId(generateTransactionId(xid));
733 output.setGroupStats(null);
735 Collection<RpcError> errors = Collections.emptyList();
736 RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
737 return Futures.immediateFuture(rpcResult);
741 public Future<RpcResult<GetAllMeterConfigStatisticsOutput>> getAllMeterConfigStatistics(
742 GetAllMeterConfigStatisticsInput input) {
744 //Generate xid to associate it with the request
745 Long xid = this.getSessionContext().getNextXid();
747 LOG.debug("Prepare config request for all the meters - Transaction id - {}",xid);
749 // Create multipart request header
750 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
751 mprInput.setType(MultipartType.OFPMPMETERCONFIG);
752 mprInput.setVersion(version);
753 mprInput.setXid(xid);
754 mprInput.setFlags(new MultipartRequestFlags(false));
756 // Create multipart request body for fetch all the meter stats
757 MultipartRequestMeterConfigCaseBuilder caseBuilder = new MultipartRequestMeterConfigCaseBuilder();
758 MultipartRequestMeterConfigBuilder mprMeterConfigBuild = new MultipartRequestMeterConfigBuilder();
759 mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
760 caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
762 //Set request body to main multipart request
763 mprInput.setMultipartRequestBody(caseBuilder.build());
765 //Send the request, no cookies associated, use any connection
766 LOG.debug("Send meter statistics request :{}",mprMeterConfigBuild);
767 this.messageService.multipartRequest(mprInput.build(), null);
769 // Prepare rpc return output. Set xid and send it back.
770 LOG.debug("Return results and transaction id back to caller");
771 GetAllMeterConfigStatisticsOutputBuilder output = new GetAllMeterConfigStatisticsOutputBuilder();
772 output.setTransactionId(generateTransactionId(xid));
773 output.setMeterConfigStats(null);
775 Collection<RpcError> errors = Collections.emptyList();
776 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
777 return Futures.immediateFuture(rpcResult);
781 public Future<RpcResult<GetAllMeterStatisticsOutput>> getAllMeterStatistics(GetAllMeterStatisticsInput input) {
783 //Generate xid to associate it with the request
784 Long xid = this.getSessionContext().getNextXid();
786 LOG.debug("Prepare statistics request for all the meters - Transaction id - {}",xid);
788 // Create multipart request header
789 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
790 mprInput.setType(MultipartType.OFPMPMETER);
791 mprInput.setVersion(version);
792 mprInput.setXid(xid);
793 mprInput.setFlags(new MultipartRequestFlags(false));
795 // Create multipart request body for fetch all the meter stats
796 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
797 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
798 mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
799 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
801 //Set request body to main multipart request
802 mprInput.setMultipartRequestBody(caseBuilder.build());
804 //Send the request, no cookies associated, use any connection
805 LOG.debug("Send meter statistics request :{}",mprMeterBuild);
806 this.messageService.multipartRequest(mprInput.build(), null);
808 // Prepare rpc return output. Set xid and send it back.
809 LOG.debug("Return results and transaction id back to caller");
810 GetAllMeterStatisticsOutputBuilder output = new GetAllMeterStatisticsOutputBuilder();
811 output.setTransactionId(generateTransactionId(xid));
812 output.setMeterStats(null);
814 Collection<RpcError> errors = Collections.emptyList();
815 RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
816 return Futures.immediateFuture(rpcResult);
820 public Future<RpcResult<GetMeterFeaturesOutput>> getMeterFeatures(GetMeterFeaturesInput input) {
822 //Generate xid to associate it with the request
823 Long xid = this.getSessionContext().getNextXid();
825 LOG.debug("Prepare features statistics request for all the meters - Transaction id - {}",xid);
827 // Create multipart request header
828 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
829 mprInput.setType(MultipartType.OFPMPMETERFEATURES);
830 mprInput.setVersion(version);
831 mprInput.setXid(xid);
832 mprInput.setFlags(new MultipartRequestFlags(false));
834 // Create multipart request body for fetch all the group description stats
835 MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild = new MultipartRequestMeterFeaturesCaseBuilder();
837 //Set request body to main multipart request
838 mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
840 //Send the request, no cookies associated, use any connection
841 LOG.debug("Send meter features statistics request :{}",mprMeterFeaturesBuild);
842 this.messageService.multipartRequest(mprInput.build(), null);
844 // Prepare rpc return output. Set xid and send it back.
845 LOG.debug("Return results and transaction id back to caller");
846 GetMeterFeaturesOutputBuilder output = new GetMeterFeaturesOutputBuilder();
847 output.setTransactionId(generateTransactionId(xid));
849 Collection<RpcError> errors = Collections.emptyList();
850 RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
851 return Futures.immediateFuture(rpcResult);
855 public Future<RpcResult<GetMeterStatisticsOutput>> getMeterStatistics(GetMeterStatisticsInput input) {
856 //Generate xid to associate it with the request
857 Long xid = this.getSessionContext().getNextXid();
859 LOG.debug("Preprae statistics request for Meter ({}) - Transaction id - {}",input.getMeterId().getValue(),xid);
861 // Create multipart request header
862 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
863 mprInput.setType(MultipartType.OFPMPMETER);
864 mprInput.setVersion(version);
865 mprInput.setXid(xid);
866 mprInput.setFlags(new MultipartRequestFlags(false));
868 // Create multipart request body for fetch all the meter stats
869 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
870 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
871 //Select specific meter
872 mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
873 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
875 //Set request body to main multipart request
876 mprInput.setMultipartRequestBody(caseBuilder.build());
878 //Send the request, no cookies associated, use any connection
879 LOG.debug("Send meter statistics request :{}",mprMeterBuild);
880 this.messageService.multipartRequest(mprInput.build(), null);
882 // Prepare rpc return output. Set xid and send it back.
883 LOG.debug("Return results and transaction id back to caller");
884 GetMeterStatisticsOutputBuilder output = new GetMeterStatisticsOutputBuilder();
885 output.setTransactionId(generateTransactionId(xid));
886 output.setMeterStats(null);
888 Collection<RpcError> errors = Collections.emptyList();
889 RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
890 return Futures.immediateFuture(rpcResult);
894 public Future<RpcResult<GetAllPortsStatisticsOutput>> getAllPortsStatistics(GetAllPortsStatisticsInput arg0) {
896 //Generate xid to associate it with the request
897 Long xid = this.getSessionContext().getNextXid();
899 LOG.info("Prepare port statistics request for all ports of node {} - TrasactionId - {}",arg0.getNode().getValue(),xid);
901 // Create multipart request header
902 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
903 mprInput.setType(MultipartType.OFPMPPORTSTATS);
904 mprInput.setVersion(version);
905 mprInput.setXid(xid);
906 mprInput.setFlags(new MultipartRequestFlags(false));
908 // Create multipart request body to fetch stats for all the port of the node
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 GetAllPortsStatisticsOutputBuilder output = new GetAllPortsStatisticsOutputBuilder();
924 output.setTransactionId(generateTransactionId(xid));
926 Collection<RpcError> errors = Collections.emptyList();
927 RpcResult<GetAllPortsStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
928 return Futures.immediateFuture(rpcResult);
932 public Future<RpcResult<GetPortStatisticsOutput>> getPortStatistics(GetPortStatisticsInput arg0) {
933 //Generate xid to associate it with the request
934 Long xid = this.getSessionContext().getNextXid();
936 LOG.info("Prepare port statistics request for port {} of node {} - TrasactionId - {}",arg0.getNodeConnectorId(), arg0.getNode().getValue(),xid);
938 // Create multipart request header
939 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
940 mprInput.setType(MultipartType.OFPMPPORTSTATS);
941 mprInput.setVersion(version);
942 mprInput.setXid(xid);
943 mprInput.setFlags(new MultipartRequestFlags(false));
945 // Create multipart request body to fetch stats for all the port of the node
946 MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
947 MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
950 mprPortStatsBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
951 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
953 //Set request body to main multipart request
954 mprInput.setMultipartRequestBody(caseBuilder.build());
956 //Send the request, no cookies associated, use any connection
957 LOG.debug("Send port statistics request :{}",mprPortStatsBuilder.build().toString());
958 this.messageService.multipartRequest(mprInput.build(), null);
960 // Prepare rpc return output. Set xid and send it back.
961 GetPortStatisticsOutputBuilder output = new GetPortStatisticsOutputBuilder();
962 output.setTransactionId(generateTransactionId(xid));
964 Collection<RpcError> errors = Collections.emptyList();
965 RpcResult<GetPortStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
966 return Futures.immediateFuture(rpcResult);
969 private TransactionId generateTransactionId(Long xid){
970 String stringXid =xid.toString();
971 BigInteger bigIntXid = new BigInteger( stringXid );
972 return new TransactionId(bigIntXid);
977 public Future<RpcResult<GetPortOutput>> getPort() {
978 // TODO Auto-generated method stub
984 public Future<RpcResult<UpdatePortOutput>> updatePort(UpdatePortInput input) {
985 PortModInput ofPortModInput = null ;
986 RpcResult<UpdatePortOutput> rpcResultFromOFLib = null ;
989 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
990 // the request can be routed through any connection to the switch
992 SwitchConnectionDistinguisher cookie = null ;
994 // NSF sends a list of port and the ModelDrivenSwitch will
995 // send one port at a time towards the switch ( mutiple RPCs calls)
996 List<Port> inputPorts = input.getUpdatedPort().getPort().getPort() ;
998 // Get the Xid. The same Xid has to be sent in all the RPCs
999 Long Xid = sessionContext.getNextXid();
1001 for( Port inputPort : inputPorts) {
1003 // Convert the UpdateGroupInput to GroupModInput
1004 ofPortModInput = PortConvertor.toPortModInput(inputPort, version) ;
1006 // Insert the Xid ( transaction Id) before calling the RPC on the OFLibrary
1008 PortModInputBuilder mdInput = new PortModInputBuilder();
1009 mdInput.setXid(Xid);
1010 mdInput.setVersion(ofPortModInput.getVersion()) ;
1011 mdInput.setPortNo(ofPortModInput.getPortNo()) ;
1012 mdInput.setMaskV10(ofPortModInput.getMaskV10()) ;
1013 mdInput.setMask(ofPortModInput.getMask()) ;
1014 mdInput.setHwAddress(ofPortModInput.getHwAddress());
1015 mdInput.setConfigV10(ofPortModInput.getConfigV10()) ;
1016 mdInput.setConfig(ofPortModInput.getConfig()) ;
1017 mdInput.setAdvertiseV10(ofPortModInput.getAdvertiseV10()) ;
1018 mdInput.setAdvertise(ofPortModInput.getAdvertise()) ;
1020 LOG.debug("Calling the PortMod RPC method on MessageDispatchService");
1021 Future<RpcResult<UpdatePortOutput>> resultFromOFLib = messageService.portMod(ofPortModInput, cookie) ;
1024 rpcResultFromOFLib = resultFromOFLib.get();
1025 } catch( Exception ex ) {
1026 LOG.error( " Error while getting result for updatePort RPC" + ex.getMessage());
1029 // The Future response value for all the RPCs except the last one is ignored
1032 //Extract the Xid only from the Future for the last RPC and
1033 // send it back to the NSF
1034 UpdatePortOutput updatePortOutputOFLib = rpcResultFromOFLib.getResult() ;
1036 UpdatePortOutputBuilder updatePortOutput = new UpdatePortOutputBuilder() ;
1037 updatePortOutput.setTransactionId(updatePortOutputOFLib.getTransactionId()) ;
1038 UpdatePortOutput result = updatePortOutput.build();
1040 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
1041 RpcResult<UpdatePortOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
1043 LOG.debug("Returning the Update Group RPC result to MD-SAL");
1044 return Futures.immediateFuture(rpcResult);
1049 public Future<RpcResult<UpdateTableOutput>> updateTable(
1050 UpdateTableInput input) {
1052 // Get the Xid. The same Xid has to be sent in all the Multipart requests
1053 Long xid = this.getSessionContext().getNextXid();
1055 LOG.debug("Prepare the Multipart Table Mod requests for Transaction Id {} ",xid);
1057 // Create multipart request header
1058 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1059 mprInput.setType(MultipartType.OFPMPTABLEFEATURES);
1060 mprInput.setVersion((short)0x04);
1061 mprInput.setXid(xid);
1063 //Convert the list of all MD-SAL table feature object into OF library object
1064 List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input.getUpdatedTable()) ;
1067 MultipartRequestTableFeaturesCaseBuilder caseRequest = new MultipartRequestTableFeaturesCaseBuilder();
1068 MultipartRequestTableFeaturesBuilder tableFeaturesRequest = new MultipartRequestTableFeaturesBuilder();
1070 mprInput.setFlags(new MultipartRequestFlags(true));
1072 tableFeaturesRequest.setTableFeatures(ofTableFeatureList) ;
1074 //Set request body to main multipart request
1075 caseRequest.setMultipartRequestTableFeatures(tableFeaturesRequest.build());
1076 mprInput.setMultipartRequestBody(caseRequest.build());
1078 //Send the request, no cookies associated, use any connection
1079 LOG.debug("Send Table Feature request :{}",ofTableFeatureList);
1080 this.messageService.multipartRequest(mprInput.build(), null);
1083 //Extract the Xid only from the Future for the last RPC and
1084 // send it back to the NSF
1085 LOG.debug("Returning the result and transaction id to NSF");
1086 LOG.debug("Return results and transaction id back to caller");
1087 UpdateTableOutputBuilder output = new UpdateTableOutputBuilder();
1088 output.setTransactionId(generateTransactionId(xid));
1090 Collection<RpcError> errors = Collections.emptyList();
1091 RpcResult<UpdateTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1092 return Futures.immediateFuture(rpcResult);
1096 public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
1097 GetAllFlowStatisticsFromFlowTableInput arg0) {
1099 //Generate xid to associate it with the request
1100 Long xid = this.getSessionContext().getNextXid();
1102 LOG.debug("Prepare statistics request to get flow stats for switch tables {} - Transaction id - {}"
1103 ,arg0.getTableId().getValue(),xid);
1105 // Create multipart request header
1106 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1107 mprInput.setType(MultipartType.OFPMPFLOW);
1108 mprInput.setVersion(version);
1109 mprInput.setXid(xid);
1110 mprInput.setFlags(new MultipartRequestFlags(false));
1112 // Create multipart request body for fetch all the group stats
1113 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder ();
1114 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1115 mprFlowRequestBuilder.setTableId(arg0.getTableId().getValue());
1116 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1117 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1118 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1119 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1121 if(version == OFConstants.OFP_VERSION_1_0){
1122 LOG.info("Target node is running openflow version 1.0");
1123 FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true);
1124 mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
1126 if(version == OFConstants.OFP_VERSION_1_3){
1127 LOG.info("Target node is running openflow version 1.3+");
1128 mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
1132 //Set request body to main multipart request
1133 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1134 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1136 //Send the request, no cookies associated, use any connection
1137 LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
1138 this.messageService.multipartRequest(mprInput.build(), null);
1140 // Prepare rpc return output. Set xid and send it back.
1141 LOG.debug("Return results and transaction id back to caller");
1142 GetAllFlowStatisticsFromFlowTableOutputBuilder output =
1143 new GetAllFlowStatisticsFromFlowTableOutputBuilder();
1144 output.setTransactionId(generateTransactionId(xid));
1145 output.setFlowAndStatisticsMapList(null);
1147 Collection<RpcError> errors = Collections.emptyList();
1148 RpcResult<GetAllFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1149 return Futures.immediateFuture(rpcResult);
1153 public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
1154 GetAllFlowsStatisticsFromAllFlowTablesInput arg0) {
1156 //Generate xid to associate it with the request
1157 Long xid = this.getSessionContext().getNextXid();
1159 LOG.info("Prepare statistics request to get flow stats of all switch tables - Transaction id - {}",xid);
1161 // Create multipart request header
1162 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1163 mprInput.setType(MultipartType.OFPMPFLOW);
1164 mprInput.setVersion(version);
1165 mprInput.setXid(xid);
1166 mprInput.setFlags(new MultipartRequestFlags(false));
1168 // Create multipart request body for fetch all the group stats
1169 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1170 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1171 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
1172 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1173 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1174 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1175 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1176 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1178 //TODO: repeating code
1179 if(version == OFConstants.OFP_VERSION_1_0){
1180 FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true);
1181 mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
1183 if(version == OFConstants.OFP_VERSION_1_3){
1184 mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
1186 //Set request body to main multipart request
1187 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1188 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1190 //Send the request, no cookies associated, use any connection
1191 LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
1192 this.messageService.multipartRequest(mprInput.build(), null);
1194 // Prepare rpc return output. Set xid and send it back.
1195 GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder output =
1196 new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder();
1197 output.setTransactionId(generateTransactionId(xid));
1198 output.setFlowAndStatisticsMapList(null);
1200 Collection<RpcError> errors = Collections.emptyList();
1201 RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1202 return Futures.immediateFuture(rpcResult);
1207 public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
1208 GetFlowStatisticsFromFlowTableInput arg0) {
1209 //Generate xid to associate it with the request
1210 Long xid = this.getSessionContext().getNextXid();
1212 LOG.info("Prepare statistics request to get stats for flow {} for switch tables {} - Transaction id - {}"
1213 ,arg0.getMatch().toString(),arg0.getTableId(),xid);
1215 // Create multipart request header
1216 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1217 mprInput.setType(MultipartType.OFPMPFLOW);
1218 mprInput.setVersion(version);
1219 mprInput.setXid(xid);
1220 mprInput.setFlags(new MultipartRequestFlags(false));
1222 // Create multipart request body for fetch all the group stats
1223 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1224 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1225 mprFlowRequestBuilder.setTableId(arg0.getTableId());
1226 mprFlowRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1227 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1228 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1229 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1231 // convert and inject match
1232 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprFlowRequestBuilder);
1233 //TODO: repeating code
1234 if(version == OFConstants.OFP_VERSION_1_3){
1235 mprFlowRequestBuilder.setCookie(arg0.getCookie());
1236 mprFlowRequestBuilder.setCookieMask(arg0.getCookieMask());
1237 mprFlowRequestBuilder.setOutGroup(arg0.getOutGroup());
1240 //Set request body to main multipart request
1241 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1242 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1244 //Send the request, no cookies associated, use any connection
1245 LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
1246 this.messageService.multipartRequest(mprInput.build(), null);
1248 // Prepare rpc return output. Set xid and send it back.
1249 GetFlowStatisticsFromFlowTableOutputBuilder output =
1250 new GetFlowStatisticsFromFlowTableOutputBuilder();
1251 output.setTransactionId(generateTransactionId(xid));
1252 output.setFlowAndStatisticsMapList(null);
1254 Collection<RpcError> errors = Collections.emptyList();
1255 RpcResult<GetFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1256 return Futures.immediateFuture(rpcResult);
1260 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
1261 GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput arg0) {
1262 //Generate xid to associate it with the request
1263 Long xid = this.getSessionContext().getNextXid();
1265 LOG.info("Prepare aggregate flow statistics request to get aggregate flow stats for all the flow installed on switch table {} - Transaction id - {}"
1266 ,arg0.getTableId().getValue(),xid);
1268 // Create multipart request header
1269 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1270 mprInput.setType(MultipartType.OFPMPAGGREGATE);
1271 mprInput.setVersion(version);
1272 mprInput.setXid(xid);
1273 mprInput.setFlags(new MultipartRequestFlags(false));
1275 // Create multipart request body for fetch all the group stats
1276 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder ();
1277 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1278 mprAggregateRequestBuilder.setTableId(arg0.getTableId().getValue());
1279 mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1280 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1281 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1282 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1284 //TODO: repeating code
1285 if(version == OFConstants.OFP_VERSION_1_0){
1286 FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true);
1287 mprAggregateRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
1289 if(version == OFConstants.OFP_VERSION_1_3){
1290 mprAggregateRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
1294 //Set request body to main multipart request
1295 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1296 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1298 //Send the request, no cookies associated, use any connection
1299 LOG.debug("Send request to the switch :{}",multipartRequestAggregateCaseBuilder.build().toString());
1300 this.messageService.multipartRequest(mprInput.build(), null);
1302 // Prepare rpc return output. Set xid and send it back.
1303 GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder output =
1304 new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder();
1305 output.setTransactionId(generateTransactionId(xid));
1307 Collection<RpcError> errors = Collections.emptyList();
1308 RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1309 return Futures.immediateFuture(rpcResult);
1313 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
1314 GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput arg0) {
1316 //Generate xid to associate it with the request
1317 Long xid = this.getSessionContext().getNextXid();
1319 LOG.debug("Prepare agregate statistics request to get aggregate stats for flows matching {} and installed in flow tables {} - Transaction id - {}"
1320 ,arg0.getMatch().toString(),arg0.getTableId(),xid);
1322 // Create multipart request header
1323 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1324 mprInput.setType(MultipartType.OFPMPAGGREGATE);
1325 mprInput.setVersion(version);
1326 mprInput.setXid(xid);
1327 mprInput.setFlags(new MultipartRequestFlags(false));
1329 // Create multipart request body for fetch all the group stats
1330 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder ();
1331 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1332 mprAggregateRequestBuilder.setTableId(arg0.getTableId());
1333 mprAggregateRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1334 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1335 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1336 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1339 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprAggregateRequestBuilder);
1340 //TODO: repeating code
1341 if(version == OFConstants.OFP_VERSION_1_3){
1342 mprAggregateRequestBuilder.setCookie(arg0.getCookie());
1343 mprAggregateRequestBuilder.setCookieMask(arg0.getCookieMask());
1344 mprAggregateRequestBuilder.setOutGroup(arg0.getOutGroup());
1347 //Set request body to main multipart request
1348 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1349 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1351 //Send the request, no cookies associated, use any connection
1352 LOG.debug("Send request to the switch :{}",multipartRequestAggregateCaseBuilder.build().toString());
1353 this.messageService.multipartRequest(mprInput.build(), null);
1355 // Prepare rpc return output. Set xid and send it back.
1356 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder output =
1357 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
1358 output.setTransactionId(generateTransactionId(xid));
1360 Collection<RpcError> errors = Collections.emptyList();
1361 RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1362 return Futures.immediateFuture(rpcResult);
1366 public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(GetFlowTablesStatisticsInput arg0) {
1367 //Generate xid to associate it with the request
1368 Long xid = this.getSessionContext().getNextXid();
1370 LOG.info("Prepare flow table statistics request to get flow table stats for all tables " +
1371 "from node {}- Transaction id - {}",arg0.getNode(),xid);
1373 // Create multipart request header
1374 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1375 mprInput.setType(MultipartType.OFPMPTABLE);
1376 mprInput.setVersion(version);
1377 mprInput.setXid(xid);
1378 mprInput.setFlags(new MultipartRequestFlags(false));
1380 // Create multipart request body for fetch all the group stats
1381 MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder ();
1382 MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
1383 multipartRequestTableBuilder.setEmpty(true);
1384 multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
1386 //Set request body to main multipart request
1387 mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
1389 //Send the request, no cookies associated, use any connection
1390 LOG.debug("Send request to the switch :{}",multipartRequestTableCaseBuilder.build().toString());
1391 this.messageService.multipartRequest(mprInput.build(), null);
1393 // Prepare rpc return output. Set xid and send it back.
1394 GetFlowTablesStatisticsOutputBuilder output = new GetFlowTablesStatisticsOutputBuilder();
1395 output.setTransactionId(generateTransactionId(xid));
1397 Collection<RpcError> errors = Collections.emptyList();
1398 RpcResult<GetFlowTablesStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1399 return Futures.immediateFuture(rpcResult);
1403 public Future<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> getAllQueuesStatisticsFromAllPorts(
1404 GetAllQueuesStatisticsFromAllPortsInput arg0) {
1405 //Generate xid to associate it with the request
1406 Long xid = this.getSessionContext().getNextXid();
1408 LOG.info("Prepare queue statistics request to collect stats for all queues attached to all the ports of node {} - TrasactionId - {}",arg0.getNode().getValue(),xid);
1410 // Create multipart request header
1411 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1412 mprInput.setType(MultipartType.OFPMPQUEUE);
1413 mprInput.setVersion(version);
1414 mprInput.setXid(xid);
1415 mprInput.setFlags(new MultipartRequestFlags(false));
1417 // Create multipart request body to fetch stats for all the port of the node
1418 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1419 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1421 mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
1422 //Select all the ports
1423 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1425 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1427 //Set request body to main multipart request
1428 mprInput.setMultipartRequestBody(caseBuilder.build());
1430 //Send the request, no cookies associated, use any connection
1431 LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString());
1432 this.messageService.multipartRequest(mprInput.build(), null);
1434 // Prepare rpc return output. Set xid and send it back.
1435 GetAllQueuesStatisticsFromAllPortsOutputBuilder output = new GetAllQueuesStatisticsFromAllPortsOutputBuilder();
1436 output.setTransactionId(generateTransactionId(xid));
1437 output.setQueueIdAndStatisticsMap(null);
1439 Collection<RpcError> errors = Collections.emptyList();
1440 RpcResult<GetAllQueuesStatisticsFromAllPortsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1441 return Futures.immediateFuture(rpcResult);
1445 public Future<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> getAllQueuesStatisticsFromGivenPort(
1446 GetAllQueuesStatisticsFromGivenPortInput arg0) {
1447 //Generate xid to associate it with the request
1448 Long xid = this.getSessionContext().getNextXid();
1450 LOG.info("Prepare queue statistics request to collect stats for " +
1451 "all queues attached to given port {} of node {} - TrasactionId - {}",arg0.getNodeConnectorId().toString(),arg0.getNode().getValue(),xid);
1453 // Create multipart request header
1454 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1455 mprInput.setType(MultipartType.OFPMPQUEUE);
1456 mprInput.setVersion(version);
1457 mprInput.setXid(xid);
1458 mprInput.setFlags(new MultipartRequestFlags(false));
1460 // Create multipart request body to fetch stats for all the port of the node
1461 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1462 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1464 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1465 //Select specific port
1466 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1468 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1470 //Set request body to main multipart request
1471 mprInput.setMultipartRequestBody(caseBuilder.build());
1473 //Send the request, no cookies associated, use any connection
1474 LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString());
1475 this.messageService.multipartRequest(mprInput.build(), null);
1477 // Prepare rpc return output. Set xid and send it back.
1478 GetAllQueuesStatisticsFromGivenPortOutputBuilder output = new GetAllQueuesStatisticsFromGivenPortOutputBuilder();
1479 output.setTransactionId(generateTransactionId(xid));
1480 output.setQueueIdAndStatisticsMap(null);
1482 Collection<RpcError> errors = Collections.emptyList();
1483 RpcResult<GetAllQueuesStatisticsFromGivenPortOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1484 return Futures.immediateFuture(rpcResult);
1488 public Future<RpcResult<GetQueueStatisticsFromGivenPortOutput>> getQueueStatisticsFromGivenPort(
1489 GetQueueStatisticsFromGivenPortInput arg0) {
1490 //Generate xid to associate it with the request
1491 Long xid = this.getSessionContext().getNextXid();
1493 LOG.info("Prepare queue statistics request to collect stats for " +
1494 "given queue attached to given port {} of node {} - TrasactionId - {}",arg0.getQueueId().toString(),arg0.getNodeConnectorId().toString(),arg0.getNode().getValue(),xid);
1496 // Create multipart request header
1497 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1498 mprInput.setType(MultipartType.OFPMPQUEUE);
1499 mprInput.setVersion(version);
1500 mprInput.setXid(xid);
1501 mprInput.setFlags(new MultipartRequestFlags(false));
1503 // Create multipart request body to fetch stats for all the port of the node
1504 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1505 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1506 //Select specific queue
1507 mprQueueBuilder.setQueueId(arg0.getQueueId().getValue());
1508 //Select specific port
1509 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1511 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1513 //Set request body to main multipart request
1514 mprInput.setMultipartRequestBody(caseBuilder.build());
1516 //Send the request, no cookies associated, use any connection
1517 LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString());
1518 this.messageService.multipartRequest(mprInput.build(), null);
1520 // Prepare rpc return output. Set xid and send it back.
1521 GetQueueStatisticsFromGivenPortOutputBuilder output = new GetQueueStatisticsFromGivenPortOutputBuilder();
1522 output.setTransactionId(generateTransactionId(xid));
1523 output.setQueueIdAndStatisticsMap(null);
1525 Collection<RpcError> errors = Collections.emptyList();
1526 RpcResult<GetQueueStatisticsFromGivenPortOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1527 return Futures.immediateFuture(rpcResult);
1531 public Future<RpcResult<GetAllFlowStatisticsOutput>> getAllFlowStatistics(GetAllFlowStatisticsInput arg0) {
1532 //TODO: Depricated, need to clean it up. Sal-Compatibility layes is dependent on it.
1533 // Once sal-compatibility layer is fixed this rpc call can be removed from yang file
1538 public Future<RpcResult<GetAllNodeConnectorStatisticsOutput>> getAllNodeConnectorStatistics(
1539 GetAllNodeConnectorStatisticsInput arg0) {
1540 // TODO Auto-generated method stub
1545 public Future<RpcResult<GetFlowStatisticsOutput>> getFlowStatistics(GetFlowStatisticsInput arg0) {
1546 //TODO: Depricated, need to clean it up. Sal-Compatibility layes is dependent on it.
1547 // Once sal-compatibility layer is fixed this rpc call can be removed from yang file
1552 public Future<RpcResult<GetFlowTableStatisticsOutput>> getFlowTableStatistics(GetFlowTableStatisticsInput arg0) {
1553 // TODO Auto-generated method stub
1558 public Future<RpcResult<GetNodeConnectorStatisticsOutput>> getNodeConnectorStatistics(
1559 GetNodeConnectorStatisticsInput arg0) {
1560 // TODO Auto-generated method stub