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.PortConvertor;
25 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor;
26 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
27 import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService;
28 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
29 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutputBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsInput;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsOutput;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllNodeConnectorStatisticsInput;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllNodeConnectorStatisticsOutput;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutputBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsInput;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsOutput;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowTableStatisticsInput;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowTableStatisticsOutput;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetNodeConnectorStatisticsInput;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetNodeConnectorStatisticsOutput;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
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.AddGroupOutputBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutputBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutputBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutputBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutputBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutputBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutputBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutputBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutputBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutputBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Group;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Meter;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
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.PortModInput;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;
157 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;
158 //import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.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.util.concurrent.Futures;
190 * RPC implementation of MD-switch
192 public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
194 private static final Logger LOG = org.slf4j.LoggerFactory
195 .getLogger(ModelDrivenSwitchImpl.class);
196 private final NodeId nodeId;
197 private final IMessageDispatchService messageService ;
198 private short version = 0;
200 protected ModelDrivenSwitchImpl(NodeId nodeId,
201 InstanceIdentifier<Node> identifier, SessionContext context) {
202 super(identifier, context);
203 this.nodeId = nodeId;
204 messageService = sessionContext.getMessageDispatchService() ;
205 version = context.getPrimaryConductor().getVersion();
210 public Future<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
211 // Convert the AddFlowInput to FlowModInput
212 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input, version);
213 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
214 barrierInput.setVersion(version);
216 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
217 // the request can be routed through any connection to the switch
219 SwitchConnectionDistinguisher cookie = null ;
220 if (input.isBarrier()) {
221 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
224 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
225 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
227 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
230 rpcResultFromOFLib = resultFromOFLib.get();
231 } catch( Exception ex ) {
232 LOG.error( " Error while getting result for AddFlow RPC" + ex.getMessage());
235 UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult() ;
237 AddFlowOutputBuilder addFlowOutput = new AddFlowOutputBuilder() ;
238 addFlowOutput.setTransactionId(updateFlowOutput.getTransactionId()) ;
239 AddFlowOutput result = addFlowOutput.build();
241 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
242 RpcResult<AddFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
244 LOG.debug("Returning the Add Flow RPC result to MD-SAL");
245 return Futures.immediateFuture(rpcResult);
249 public Future<RpcResult<AddGroupOutput>> addGroup(AddGroupInput input) {
250 // Convert the AddGroupInput to GroupModInput
251 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input, version);
254 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
255 // the request can be routed through any connection to the switch
257 SwitchConnectionDistinguisher cookie = null ;
259 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
260 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
262 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
265 rpcResultFromOFLib = resultFromOFLib.get();
266 } catch( Exception ex ) {
267 LOG.error( " Error while getting result for AddGroup RPC" + ex.getMessage());
270 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult() ;
272 AddGroupOutputBuilder addGroupOutput = new AddGroupOutputBuilder() ;
273 addGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()) ;
274 AddGroupOutput result = addGroupOutput.build();
276 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
277 RpcResult<AddGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
279 LOG.debug("Returning the Add Group RPC result to MD-SAL");
280 return Futures.immediateFuture(rpcResult);
284 public Future<RpcResult<AddMeterOutput>> addMeter(AddMeterInput input) {
285 // Convert the AddMeterInput to MeterModInput
286 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 (input.isBarrier()) {
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 // TODO Auto-generated method stub
435 private FlowModInputBuilder toFlowModInputBuilder(Flow source) {
436 FlowModInputBuilder target = new FlowModInputBuilder();
437 target.setCookie(source.getCookie());
438 target.setIdleTimeout(source.getIdleTimeout());
439 target.setHardTimeout(source.getHardTimeout());
440 target.setMatch(toMatch(source.getMatch()));
445 private Match toMatch(
446 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
447 MatchBuilder target = new MatchBuilder();
449 target.setMatchEntries(toMatchEntries(match));
454 private List<MatchEntries> toMatchEntries(
455 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
456 List<MatchEntries> entries = new ArrayList<>();
462 public Future<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
463 // Convert the UpdateFlowInput to FlowModInput
464 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input.getUpdatedFlow(), version);
465 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
466 barrierInput.setVersion(version);
467 // Call the RPC method on MessageDispatchService
469 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
470 // the request can be routed through any connection to the switch
472 SwitchConnectionDistinguisher cookie = null ;
473 if (input.getUpdatedFlow().isBarrier()) {
474 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
477 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
478 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
480 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
483 rpcResultFromOFLib = resultFromOFLib.get();
484 } catch( Exception ex ) {
485 LOG.error( " Error while getting result for UpdateFlow RPC" + ex.getMessage());
488 UpdateFlowOutput updateFlowOutputOFLib = rpcResultFromOFLib.getResult() ;
490 UpdateFlowOutputBuilder updateFlowOutput = new UpdateFlowOutputBuilder() ;
491 updateFlowOutput.setTransactionId(updateFlowOutputOFLib.getTransactionId()) ;
492 UpdateFlowOutput result = updateFlowOutput.build();
494 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
495 RpcResult<UpdateFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
497 LOG.debug("Returning the Update Flow RPC result to MD-SAL");
498 return Futures.immediateFuture(rpcResult);
502 public Future<RpcResult<UpdateGroupOutput>> updateGroup(
503 UpdateGroupInput input) {
504 // Convert the UpdateGroupInput to GroupModInput
505 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input.getUpdatedGroup(), version);
508 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
509 // the request can be routed through any connection to the switch
511 SwitchConnectionDistinguisher cookie = null ;
513 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
514 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
516 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
519 rpcResultFromOFLib = resultFromOFLib.get();
520 } catch( Exception ex ) {
521 LOG.error( " Error while getting result for updateGroup RPC" + ex.getMessage());
524 UpdateGroupOutput updateGroupOutputOFLib = rpcResultFromOFLib.getResult() ;
526 UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder() ;
527 updateGroupOutput.setTransactionId(updateGroupOutputOFLib.getTransactionId()) ;
528 UpdateGroupOutput result = updateGroupOutput.build();
530 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
531 RpcResult<UpdateGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
533 LOG.debug("Returning the Update Group RPC result to MD-SAL");
534 return Futures.immediateFuture(rpcResult);
538 public Future<RpcResult<UpdateMeterOutput>> updateMeter(
539 UpdateMeterInput input) {
540 // Convert the UpdateMeterInput to MeterModInput
541 MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input.getUpdatedMeter(), version);
544 // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
545 // the request can be routed through any connection to the switch
547 SwitchConnectionDistinguisher cookie = null ;
549 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
550 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ;
552 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null ;
555 rpcResultFromOFLib = resultFromOFLib.get();
556 } catch( Exception ex ) {
557 LOG.error( " Error while getting result for UpdateMeter RPC" + ex.getMessage());
560 UpdateMeterOutput updateMeterOutputFromOFLib = rpcResultFromOFLib.getResult() ;
562 UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder() ;
563 updateMeterOutput.setTransactionId(updateMeterOutputFromOFLib.getTransactionId()) ;
564 UpdateMeterOutput result = updateMeterOutput.build();
566 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
567 RpcResult<UpdateMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
569 LOG.debug("Returning the Update Meter RPC result to MD-SAL");
570 return Futures.immediateFuture(rpcResult);
574 public NodeId getNodeId() {
579 * Methods for requesting statistics from switch
582 public Future<RpcResult<GetAllGroupStatisticsOutput>> getAllGroupStatistics(GetAllGroupStatisticsInput input) {
584 //Generate xid to associate it with the request
585 Long xid = this.getSessionContext().getNextXid();
587 LOG.debug("Prepare statistics request for all the groups - Transaction id - {}",xid);
589 // Create multipart request header
590 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
591 mprInput.setType(MultipartType.OFPMPGROUP);
592 mprInput.setVersion(version);
593 mprInput.setXid(xid);
594 mprInput.setFlags(new MultipartRequestFlags(false));
596 // Create multipart request body for fetch all the group stats
597 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
598 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
599 mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(Group.OFPGALL.getIntValue())));
600 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
602 //Set request body to main multipart request
603 mprInput.setMultipartRequestBody(caseBuilder.build());
605 //Send the request, no cookies associated, use any connection
606 LOG.debug("Send group statistics request to the switch :{}",mprGroupBuild);
607 this.messageService.multipartRequest(mprInput.build(), null);
609 // Prepare rpc return output. Set xid and send it back.
610 LOG.debug("Return results and transaction id back to caller");
611 GetAllGroupStatisticsOutputBuilder output = new GetAllGroupStatisticsOutputBuilder();
612 output.setTransactionId(generateTransactionId(xid));
613 output.setGroupStats(null);
615 Collection<RpcError> errors = Collections.emptyList();
616 RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
617 return Futures.immediateFuture(rpcResult);
622 public Future<RpcResult<GetGroupDescriptionOutput>> getGroupDescription(GetGroupDescriptionInput input) {
624 //Generate xid to associate it with the request
625 Long xid = this.getSessionContext().getNextXid();
627 LOG.debug("Prepare group description statistics request - Transaction id - {}",xid);
629 // Create multipart request header
630 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
631 mprInput.setType(MultipartType.OFPMPGROUPDESC);
632 mprInput.setVersion(version);
633 mprInput.setXid(xid);
634 mprInput.setFlags(new MultipartRequestFlags(false));
636 // Create multipart request body for fetch all the group description stats
637 MultipartRequestGroupDescCaseBuilder mprGroupDescBuild = new MultipartRequestGroupDescCaseBuilder();
639 //Set request body to main multipart request
640 mprInput.setMultipartRequestBody(mprGroupDescBuild.build());
642 //Send the request, no cookies associated, use any connection
643 LOG.debug("Send group desciption statistics request to switch : {}",mprGroupDescBuild);
644 this.messageService.multipartRequest(mprInput.build(), null);
646 // Prepare rpc return output. Set xid and send it back.
647 LOG.debug("Return results and transaction id back to caller");
648 GetGroupDescriptionOutputBuilder output = new GetGroupDescriptionOutputBuilder();
649 output.setTransactionId(generateTransactionId(xid));
650 output.setGroupDescStats(null);
652 Collection<RpcError> errors = Collections.emptyList();
653 RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
654 return Futures.immediateFuture(rpcResult);
659 public Future<RpcResult<GetGroupFeaturesOutput>> getGroupFeatures(GetGroupFeaturesInput input) {
661 //Generate xid to associate it with the request
662 Long xid = this.getSessionContext().getNextXid();
664 LOG.debug("Prepare group features statistics request - Transaction id - {}",xid);
666 // Create multipart request header
667 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
668 mprInput.setType(MultipartType.OFPMPGROUPFEATURES);
669 mprInput.setVersion(version);
670 mprInput.setXid(xid);
671 mprInput.setFlags(new MultipartRequestFlags(false));
673 // Create multipart request body for fetch all the group description stats
674 MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild = new MultipartRequestGroupFeaturesCaseBuilder();
676 //Set request body to main multipart request
677 mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
679 //Send the request, no cookies associated, use any connection
680 LOG.debug("Send group features statistics request :{}",mprGroupFeaturesBuild);
681 this.messageService.multipartRequest(mprInput.build(), null);
683 // Prepare rpc return output. Set xid and send it back.
684 LOG.debug("Return results and transaction id back to caller");
685 GetGroupFeaturesOutputBuilder output = new GetGroupFeaturesOutputBuilder();
686 output.setTransactionId(generateTransactionId(xid));
688 Collection<RpcError> errors = Collections.emptyList();
689 RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
690 return Futures.immediateFuture(rpcResult);
694 public Future<RpcResult<GetGroupStatisticsOutput>> getGroupStatistics(GetGroupStatisticsInput input) {
696 //Generate xid to associate it with the request
697 Long xid = this.getSessionContext().getNextXid();
699 LOG.debug("Prepare statistics request for node {} group ({}) - Transaction id - {}",input.getNode(),input.getGroupId(),xid);
701 // Create multipart request header
702 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
703 mprInput.setType(MultipartType.OFPMPGROUP);
704 mprInput.setVersion(version);
705 mprInput.setXid(xid);
706 mprInput.setFlags(new MultipartRequestFlags(false));
708 // Create multipart request body for fetch all the group stats
709 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
710 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
711 mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
712 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
714 //Set request body to main multipart request
715 mprInput.setMultipartRequestBody(caseBuilder.build());
717 //Send the request, no cookies associated, use any connection
718 LOG.debug("Send group statistics request :{}",mprGroupBuild);
719 this.messageService.multipartRequest(mprInput.build(), null);
721 // Prepare rpc return output. Set xid and send it back.
722 LOG.debug("Return results and transaction id back to caller");
723 GetGroupStatisticsOutputBuilder output = new GetGroupStatisticsOutputBuilder();
724 output.setTransactionId(generateTransactionId(xid));
725 output.setGroupStats(null);
727 Collection<RpcError> errors = Collections.emptyList();
728 RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
729 return Futures.immediateFuture(rpcResult);
733 public Future<RpcResult<GetAllMeterConfigStatisticsOutput>> getAllMeterConfigStatistics(
734 GetAllMeterConfigStatisticsInput input) {
736 //Generate xid to associate it with the request
737 Long xid = this.getSessionContext().getNextXid();
739 LOG.debug("Prepare config request for all the meters - Transaction id - {}",xid);
741 // Create multipart request header
742 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
743 mprInput.setType(MultipartType.OFPMPMETERCONFIG);
744 mprInput.setVersion(version);
745 mprInput.setXid(xid);
746 mprInput.setFlags(new MultipartRequestFlags(false));
748 // Create multipart request body for fetch all the meter stats
749 MultipartRequestMeterConfigCaseBuilder caseBuilder = new MultipartRequestMeterConfigCaseBuilder();
750 MultipartRequestMeterConfigBuilder mprMeterConfigBuild = new MultipartRequestMeterConfigBuilder();
751 mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
752 caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
754 //Set request body to main multipart request
755 mprInput.setMultipartRequestBody(caseBuilder.build());
757 //Send the request, no cookies associated, use any connection
758 LOG.debug("Send meter statistics request :{}",mprMeterConfigBuild);
759 this.messageService.multipartRequest(mprInput.build(), null);
761 // Prepare rpc return output. Set xid and send it back.
762 LOG.debug("Return results and transaction id back to caller");
763 GetAllMeterConfigStatisticsOutputBuilder output = new GetAllMeterConfigStatisticsOutputBuilder();
764 output.setTransactionId(generateTransactionId(xid));
765 output.setMeterConfigStats(null);
767 Collection<RpcError> errors = Collections.emptyList();
768 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
769 return Futures.immediateFuture(rpcResult);
773 public Future<RpcResult<GetAllMeterStatisticsOutput>> getAllMeterStatistics(GetAllMeterStatisticsInput input) {
775 //Generate xid to associate it with the request
776 Long xid = this.getSessionContext().getNextXid();
778 LOG.debug("Prepare statistics request for all the meters - Transaction id - {}",xid);
780 // Create multipart request header
781 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
782 mprInput.setType(MultipartType.OFPMPMETER);
783 mprInput.setVersion(version);
784 mprInput.setXid(xid);
785 mprInput.setFlags(new MultipartRequestFlags(false));
787 // Create multipart request body for fetch all the meter stats
788 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
789 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
790 mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
791 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
793 //Set request body to main multipart request
794 mprInput.setMultipartRequestBody(caseBuilder.build());
796 //Send the request, no cookies associated, use any connection
797 LOG.debug("Send meter statistics request :{}",mprMeterBuild);
798 this.messageService.multipartRequest(mprInput.build(), null);
800 // Prepare rpc return output. Set xid and send it back.
801 LOG.debug("Return results and transaction id back to caller");
802 GetAllMeterStatisticsOutputBuilder output = new GetAllMeterStatisticsOutputBuilder();
803 output.setTransactionId(generateTransactionId(xid));
804 output.setMeterStats(null);
806 Collection<RpcError> errors = Collections.emptyList();
807 RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
808 return Futures.immediateFuture(rpcResult);
812 public Future<RpcResult<GetMeterFeaturesOutput>> getMeterFeatures(GetMeterFeaturesInput input) {
814 //Generate xid to associate it with the request
815 Long xid = this.getSessionContext().getNextXid();
817 LOG.debug("Prepare features statistics request for all the meters - Transaction id - {}",xid);
819 // Create multipart request header
820 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
821 mprInput.setType(MultipartType.OFPMPMETERFEATURES);
822 mprInput.setVersion(version);
823 mprInput.setXid(xid);
824 mprInput.setFlags(new MultipartRequestFlags(false));
826 // Create multipart request body for fetch all the group description stats
827 MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild = new MultipartRequestMeterFeaturesCaseBuilder();
829 //Set request body to main multipart request
830 mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
832 //Send the request, no cookies associated, use any connection
833 LOG.debug("Send meter features statistics request :{}",mprMeterFeaturesBuild);
834 this.messageService.multipartRequest(mprInput.build(), null);
836 // Prepare rpc return output. Set xid and send it back.
837 LOG.debug("Return results and transaction id back to caller");
838 GetMeterFeaturesOutputBuilder output = new GetMeterFeaturesOutputBuilder();
839 output.setTransactionId(generateTransactionId(xid));
841 Collection<RpcError> errors = Collections.emptyList();
842 RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
843 return Futures.immediateFuture(rpcResult);
847 public Future<RpcResult<GetMeterStatisticsOutput>> getMeterStatistics(GetMeterStatisticsInput input) {
848 //Generate xid to associate it with the request
849 Long xid = this.getSessionContext().getNextXid();
851 LOG.debug("Preprae statistics request for Meter ({}) - Transaction id - {}",input.getMeterId().getValue(),xid);
853 // Create multipart request header
854 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
855 mprInput.setType(MultipartType.OFPMPMETER);
856 mprInput.setVersion(version);
857 mprInput.setXid(xid);
858 mprInput.setFlags(new MultipartRequestFlags(false));
860 // Create multipart request body for fetch all the meter stats
861 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
862 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
863 //Select specific meter
864 mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
865 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
867 //Set request body to main multipart request
868 mprInput.setMultipartRequestBody(caseBuilder.build());
870 //Send the request, no cookies associated, use any connection
871 LOG.debug("Send meter statistics request :{}",mprMeterBuild);
872 this.messageService.multipartRequest(mprInput.build(), null);
874 // Prepare rpc return output. Set xid and send it back.
875 LOG.debug("Return results and transaction id back to caller");
876 GetMeterStatisticsOutputBuilder output = new GetMeterStatisticsOutputBuilder();
877 output.setTransactionId(generateTransactionId(xid));
878 output.setMeterStats(null);
880 Collection<RpcError> errors = Collections.emptyList();
881 RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
882 return Futures.immediateFuture(rpcResult);
886 public Future<RpcResult<GetAllPortsStatisticsOutput>> getAllPortsStatistics(GetAllPortsStatisticsInput arg0) {
888 //Generate xid to associate it with the request
889 Long xid = this.getSessionContext().getNextXid();
891 LOG.info("Prepare port statistics request for all ports of node {} - TrasactionId - {}",arg0.getNode().getValue(),xid);
893 // Create multipart request header
894 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
895 mprInput.setType(MultipartType.OFPMPPORTSTATS);
896 mprInput.setVersion(version);
897 mprInput.setXid(xid);
898 mprInput.setFlags(new MultipartRequestFlags(false));
900 // Create multipart request body to fetch stats for all the port of the node
901 MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
902 MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
904 mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
905 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
907 //Set request body to main multipart request
908 mprInput.setMultipartRequestBody(caseBuilder.build());
910 //Send the request, no cookies associated, use any connection
911 LOG.debug("Send port statistics request :{}",mprPortStatsBuilder.build().toString());
912 this.messageService.multipartRequest(mprInput.build(), null);
914 // Prepare rpc return output. Set xid and send it back.
915 GetAllPortsStatisticsOutputBuilder output = new GetAllPortsStatisticsOutputBuilder();
916 output.setTransactionId(generateTransactionId(xid));
918 Collection<RpcError> errors = Collections.emptyList();
919 RpcResult<GetAllPortsStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
920 return Futures.immediateFuture(rpcResult);
924 public Future<RpcResult<GetPortStatisticsOutput>> getPortStatistics(GetPortStatisticsInput arg0) {
925 //Generate xid to associate it with the request
926 Long xid = this.getSessionContext().getNextXid();
928 LOG.info("Prepare port statistics request for port {} of node {} - TrasactionId - {}",arg0.getNodeConnectorId(), arg0.getNode().getValue(),xid);
930 // Create multipart request header
931 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
932 mprInput.setType(MultipartType.OFPMPPORTSTATS);
933 mprInput.setVersion(version);
934 mprInput.setXid(xid);
935 mprInput.setFlags(new MultipartRequestFlags(false));
937 // Create multipart request body to fetch stats for all the port of the node
938 MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
939 MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
942 mprPortStatsBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
943 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
945 //Set request body to main multipart request
946 mprInput.setMultipartRequestBody(caseBuilder.build());
948 //Send the request, no cookies associated, use any connection
949 LOG.debug("Send port statistics request :{}",mprPortStatsBuilder.build().toString());
950 this.messageService.multipartRequest(mprInput.build(), null);
952 // Prepare rpc return output. Set xid and send it back.
953 GetPortStatisticsOutputBuilder output = new GetPortStatisticsOutputBuilder();
954 output.setTransactionId(generateTransactionId(xid));
956 Collection<RpcError> errors = Collections.emptyList();
957 RpcResult<GetPortStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
958 return Futures.immediateFuture(rpcResult);
961 private TransactionId generateTransactionId(Long xid){
962 String stringXid =xid.toString();
963 BigInteger bigIntXid = new BigInteger( stringXid );
964 return new TransactionId(bigIntXid);
969 public Future<RpcResult<GetPortOutput>> getPort() {
970 // TODO Auto-generated method stub
976 public Future<RpcResult<UpdatePortOutput>> updatePort(UpdatePortInput input) {
977 PortModInput ofPortModInput = null ;
978 RpcResult<UpdatePortOutput> rpcResultFromOFLib = null ;
981 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
982 // the request can be routed through any connection to the switch
984 SwitchConnectionDistinguisher cookie = null ;
986 // NSF sends a list of port and the ModelDrivenSwitch will
987 // send one port at a time towards the switch ( mutiple RPCs calls)
988 List<Port> inputPorts = input.getUpdatedPort().getPort().getPort() ;
990 // Get the Xid. The same Xid has to be sent in all the RPCs
991 Long Xid = sessionContext.getNextXid();
993 for( Port inputPort : inputPorts) {
995 // Convert the UpdateGroupInput to GroupModInput
996 ofPortModInput = PortConvertor.toPortModInput(inputPort, version) ;
998 // Insert the Xid ( transaction Id) before calling the RPC on the OFLibrary
1000 PortModInputBuilder mdInput = new PortModInputBuilder();
1001 mdInput.setXid(Xid);
1002 mdInput.setVersion(ofPortModInput.getVersion()) ;
1003 mdInput.setPortNo(ofPortModInput.getPortNo()) ;
1004 mdInput.setMaskV10(ofPortModInput.getMaskV10()) ;
1005 mdInput.setMask(ofPortModInput.getMask()) ;
1006 mdInput.setHwAddress(ofPortModInput.getHwAddress());
1007 mdInput.setConfigV10(ofPortModInput.getConfigV10()) ;
1008 mdInput.setConfig(ofPortModInput.getConfig()) ;
1009 mdInput.setAdvertiseV10(ofPortModInput.getAdvertiseV10()) ;
1010 mdInput.setAdvertise(ofPortModInput.getAdvertise()) ;
1012 LOG.debug("Calling the PortMod RPC method on MessageDispatchService");
1013 Future<RpcResult<UpdatePortOutput>> resultFromOFLib = messageService.portMod(ofPortModInput, cookie) ;
1016 rpcResultFromOFLib = resultFromOFLib.get();
1017 } catch( Exception ex ) {
1018 LOG.error( " Error while getting result for updatePort RPC" + ex.getMessage());
1021 // The Future response value for all the RPCs except the last one is ignored
1024 //Extract the Xid only from the Future for the last RPC and
1025 // send it back to the NSF
1026 UpdatePortOutput updatePortOutputOFLib = rpcResultFromOFLib.getResult() ;
1028 UpdatePortOutputBuilder updatePortOutput = new UpdatePortOutputBuilder() ;
1029 updatePortOutput.setTransactionId(updatePortOutputOFLib.getTransactionId()) ;
1030 UpdatePortOutput result = updatePortOutput.build();
1032 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
1033 RpcResult<UpdatePortOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
1035 LOG.debug("Returning the Update Group RPC result to MD-SAL");
1036 return Futures.immediateFuture(rpcResult);
1041 public Future<RpcResult<UpdateTableOutput>> updateTable(
1042 UpdateTableInput input) {
1044 // Get the Xid. The same Xid has to be sent in all the Multipart requests
1045 Long xid = this.getSessionContext().getNextXid();
1047 LOG.debug("Prepare the Multipart Table Mod requests for Transaction Id {} ",xid);
1049 // Create multipart request header
1050 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1051 mprInput.setType(MultipartType.OFPMPTABLEFEATURES);
1052 mprInput.setVersion((short)0x04);
1053 mprInput.setXid(xid);
1055 //Convert the list of all MD-SAL table feature object into OF library object
1056 List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input.getUpdatedTable()) ;
1059 MultipartRequestTableFeaturesCaseBuilder caseRequest = new MultipartRequestTableFeaturesCaseBuilder();
1060 MultipartRequestTableFeaturesBuilder tableFeaturesRequest = new MultipartRequestTableFeaturesBuilder();
1062 mprInput.setFlags(new MultipartRequestFlags(true));
1064 tableFeaturesRequest.setTableFeatures(ofTableFeatureList) ;
1066 //Set request body to main multipart request
1067 caseRequest.setMultipartRequestTableFeatures(tableFeaturesRequest.build());
1068 mprInput.setMultipartRequestBody(caseRequest.build());
1070 //Send the request, no cookies associated, use any connection
1071 LOG.debug("Send Table Feature request :{}",ofTableFeatureList);
1072 this.messageService.multipartRequest(mprInput.build(), null);
1075 //Extract the Xid only from the Future for the last RPC and
1076 // send it back to the NSF
1077 LOG.debug("Returning the result and transaction id to NSF");
1078 LOG.debug("Return results and transaction id back to caller");
1079 UpdateTableOutputBuilder output = new UpdateTableOutputBuilder();
1080 output.setTransactionId(generateTransactionId(xid));
1082 Collection<RpcError> errors = Collections.emptyList();
1083 RpcResult<UpdateTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1084 return Futures.immediateFuture(rpcResult);
1088 public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
1089 GetAllFlowStatisticsFromFlowTableInput arg0) {
1091 //Generate xid to associate it with the request
1092 Long xid = this.getSessionContext().getNextXid();
1094 LOG.debug("Prepare statistics request to get flow stats for switch tables {} - Transaction id - {}"
1095 ,arg0.getTableId().getValue(),xid);
1097 // Create multipart request header
1098 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1099 mprInput.setType(MultipartType.OFPMPFLOW);
1100 mprInput.setVersion(version);
1101 mprInput.setXid(xid);
1102 mprInput.setFlags(new MultipartRequestFlags(false));
1104 // Create multipart request body for fetch all the group stats
1105 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder ();
1106 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1107 mprFlowRequestBuilder.setTableId(arg0.getTableId().getValue());
1108 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1109 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1110 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1111 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1113 if(version == OFConstants.OFP_VERSION_1_0){
1114 LOG.info("Target node is running openflow version 1.0");
1115 FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true);
1116 mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
1118 if(version == OFConstants.OFP_VERSION_1_3){
1119 LOG.info("Target node is running openflow version 1.3+");
1120 mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
1124 //Set request body to main multipart request
1125 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1126 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1128 //Send the request, no cookies associated, use any connection
1129 LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
1130 this.messageService.multipartRequest(mprInput.build(), null);
1132 // Prepare rpc return output. Set xid and send it back.
1133 LOG.debug("Return results and transaction id back to caller");
1134 GetAllFlowStatisticsFromFlowTableOutputBuilder output =
1135 new GetAllFlowStatisticsFromFlowTableOutputBuilder();
1136 output.setTransactionId(generateTransactionId(xid));
1137 output.setFlowAndStatisticsMapList(null);
1139 Collection<RpcError> errors = Collections.emptyList();
1140 RpcResult<GetAllFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1141 return Futures.immediateFuture(rpcResult);
1145 public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
1146 GetAllFlowsStatisticsFromAllFlowTablesInput arg0) {
1148 //Generate xid to associate it with the request
1149 Long xid = this.getSessionContext().getNextXid();
1151 LOG.info("Prepare statistics request to get flow stats of all switch tables - Transaction id - {}",xid);
1153 // Create multipart request header
1154 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1155 mprInput.setType(MultipartType.OFPMPFLOW);
1156 mprInput.setVersion(version);
1157 mprInput.setXid(xid);
1158 mprInput.setFlags(new MultipartRequestFlags(false));
1160 // Create multipart request body for fetch all the group stats
1161 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1162 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1163 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
1164 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1165 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1166 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1167 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1168 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1170 //TODO: repeating code
1171 if(version == OFConstants.OFP_VERSION_1_0){
1172 FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true);
1173 mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
1175 if(version == OFConstants.OFP_VERSION_1_3){
1176 mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
1178 //Set request body to main multipart request
1179 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1180 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1182 //Send the request, no cookies associated, use any connection
1183 LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
1184 this.messageService.multipartRequest(mprInput.build(), null);
1186 // Prepare rpc return output. Set xid and send it back.
1187 GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder output =
1188 new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder();
1189 output.setTransactionId(generateTransactionId(xid));
1190 output.setFlowAndStatisticsMapList(null);
1192 Collection<RpcError> errors = Collections.emptyList();
1193 RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1194 return Futures.immediateFuture(rpcResult);
1199 public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
1200 GetFlowStatisticsFromFlowTableInput arg0) {
1201 //Generate xid to associate it with the request
1202 Long xid = this.getSessionContext().getNextXid();
1204 LOG.info("Prepare statistics request to get stats for flow {} for switch tables {} - Transaction id - {}"
1205 ,arg0.getMatch().toString(),arg0.getTableId(),xid);
1207 // Create multipart request header
1208 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1209 mprInput.setType(MultipartType.OFPMPFLOW);
1210 mprInput.setVersion(version);
1211 mprInput.setXid(xid);
1212 mprInput.setFlags(new MultipartRequestFlags(false));
1214 // Create multipart request body for fetch all the group stats
1215 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1216 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1217 mprFlowRequestBuilder.setTableId(arg0.getTableId());
1218 mprFlowRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1219 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1220 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1221 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1223 // convert and inject match
1224 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprFlowRequestBuilder);
1225 //TODO: repeating code
1226 if(version == OFConstants.OFP_VERSION_1_3){
1227 mprFlowRequestBuilder.setCookie(arg0.getCookie());
1228 mprFlowRequestBuilder.setCookieMask(arg0.getCookieMask());
1229 mprFlowRequestBuilder.setOutGroup(arg0.getOutGroup());
1232 //Set request body to main multipart request
1233 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1234 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1236 //Send the request, no cookies associated, use any connection
1237 LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
1238 this.messageService.multipartRequest(mprInput.build(), null);
1240 // Prepare rpc return output. Set xid and send it back.
1241 GetFlowStatisticsFromFlowTableOutputBuilder output =
1242 new GetFlowStatisticsFromFlowTableOutputBuilder();
1243 output.setTransactionId(generateTransactionId(xid));
1244 output.setFlowAndStatisticsMapList(null);
1246 Collection<RpcError> errors = Collections.emptyList();
1247 RpcResult<GetFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1248 return Futures.immediateFuture(rpcResult);
1252 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
1253 GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput arg0) {
1254 //Generate xid to associate it with the request
1255 Long xid = this.getSessionContext().getNextXid();
1257 LOG.info("Prepare aggregate flow statistics request to get aggregate flow stats for all the flow installed on switch table {} - Transaction id - {}"
1258 ,arg0.getTableId().getValue(),xid);
1260 // Create multipart request header
1261 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1262 mprInput.setType(MultipartType.OFPMPAGGREGATE);
1263 mprInput.setVersion(version);
1264 mprInput.setXid(xid);
1265 mprInput.setFlags(new MultipartRequestFlags(false));
1267 // Create multipart request body for fetch all the group stats
1268 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder ();
1269 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1270 mprAggregateRequestBuilder.setTableId(arg0.getTableId().getValue());
1271 mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1272 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1273 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1274 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1276 //TODO: repeating code
1277 if(version == OFConstants.OFP_VERSION_1_0){
1278 FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true);
1279 mprAggregateRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
1281 if(version == OFConstants.OFP_VERSION_1_3){
1282 mprAggregateRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
1286 //Set request body to main multipart request
1287 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1288 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1290 //Send the request, no cookies associated, use any connection
1291 LOG.debug("Send request to the switch :{}",multipartRequestAggregateCaseBuilder.build().toString());
1292 this.messageService.multipartRequest(mprInput.build(), null);
1294 // Prepare rpc return output. Set xid and send it back.
1295 GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder output =
1296 new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder();
1297 output.setTransactionId(generateTransactionId(xid));
1299 Collection<RpcError> errors = Collections.emptyList();
1300 RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1301 return Futures.immediateFuture(rpcResult);
1305 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
1306 GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput arg0) {
1308 //Generate xid to associate it with the request
1309 Long xid = this.getSessionContext().getNextXid();
1311 LOG.debug("Prepare agregate statistics request to get aggregate stats for flows matching {} and installed in flow tables {} - Transaction id - {}"
1312 ,arg0.getMatch().toString(),arg0.getTableId(),xid);
1314 // Create multipart request header
1315 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1316 mprInput.setType(MultipartType.OFPMPAGGREGATE);
1317 mprInput.setVersion(version);
1318 mprInput.setXid(xid);
1319 mprInput.setFlags(new MultipartRequestFlags(false));
1321 // Create multipart request body for fetch all the group stats
1322 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder ();
1323 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1324 mprAggregateRequestBuilder.setTableId(arg0.getTableId());
1325 mprAggregateRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1326 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1327 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1328 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1331 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprAggregateRequestBuilder);
1332 //TODO: repeating code
1333 if(version == OFConstants.OFP_VERSION_1_3){
1334 mprAggregateRequestBuilder.setCookie(arg0.getCookie());
1335 mprAggregateRequestBuilder.setCookieMask(arg0.getCookieMask());
1336 mprAggregateRequestBuilder.setOutGroup(arg0.getOutGroup());
1339 //Set request body to main multipart request
1340 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1341 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1343 //Send the request, no cookies associated, use any connection
1344 LOG.debug("Send request to the switch :{}",multipartRequestAggregateCaseBuilder.build().toString());
1345 this.messageService.multipartRequest(mprInput.build(), null);
1347 // Prepare rpc return output. Set xid and send it back.
1348 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder output =
1349 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
1350 output.setTransactionId(generateTransactionId(xid));
1352 Collection<RpcError> errors = Collections.emptyList();
1353 RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1354 return Futures.immediateFuture(rpcResult);
1358 public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(GetFlowTablesStatisticsInput arg0) {
1359 //Generate xid to associate it with the request
1360 Long xid = this.getSessionContext().getNextXid();
1362 LOG.info("Prepare flow table statistics request to get flow table stats for all tables " +
1363 "from node {}- Transaction id - {}",arg0.getNode(),xid);
1365 // Create multipart request header
1366 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1367 mprInput.setType(MultipartType.OFPMPTABLE);
1368 mprInput.setVersion(version);
1369 mprInput.setXid(xid);
1370 mprInput.setFlags(new MultipartRequestFlags(false));
1372 // Create multipart request body for fetch all the group stats
1373 MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder ();
1374 MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
1375 multipartRequestTableBuilder.setEmpty(true);
1376 multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
1378 //Set request body to main multipart request
1379 mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
1381 //Send the request, no cookies associated, use any connection
1382 LOG.debug("Send request to the switch :{}",multipartRequestTableCaseBuilder.build().toString());
1383 this.messageService.multipartRequest(mprInput.build(), null);
1385 // Prepare rpc return output. Set xid and send it back.
1386 GetFlowTablesStatisticsOutputBuilder output = new GetFlowTablesStatisticsOutputBuilder();
1387 output.setTransactionId(generateTransactionId(xid));
1389 Collection<RpcError> errors = Collections.emptyList();
1390 RpcResult<GetFlowTablesStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1391 return Futures.immediateFuture(rpcResult);
1395 public Future<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> getAllQueuesStatisticsFromAllPorts(
1396 GetAllQueuesStatisticsFromAllPortsInput arg0) {
1397 //Generate xid to associate it with the request
1398 Long xid = this.getSessionContext().getNextXid();
1400 LOG.info("Prepare queue statistics request to collect stats for all queues attached to all the ports of node {} - TrasactionId - {}",arg0.getNode().getValue(),xid);
1402 // Create multipart request header
1403 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1404 mprInput.setType(MultipartType.OFPMPQUEUE);
1405 mprInput.setVersion(version);
1406 mprInput.setXid(xid);
1407 mprInput.setFlags(new MultipartRequestFlags(false));
1409 // Create multipart request body to fetch stats for all the port of the node
1410 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1411 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1413 mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
1414 //Select all the ports
1415 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1417 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1419 //Set request body to main multipart request
1420 mprInput.setMultipartRequestBody(caseBuilder.build());
1422 //Send the request, no cookies associated, use any connection
1423 LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString());
1424 this.messageService.multipartRequest(mprInput.build(), null);
1426 // Prepare rpc return output. Set xid and send it back.
1427 GetAllQueuesStatisticsFromAllPortsOutputBuilder output = new GetAllQueuesStatisticsFromAllPortsOutputBuilder();
1428 output.setTransactionId(generateTransactionId(xid));
1429 output.setQueueIdAndStatisticsMap(null);
1431 Collection<RpcError> errors = Collections.emptyList();
1432 RpcResult<GetAllQueuesStatisticsFromAllPortsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1433 return Futures.immediateFuture(rpcResult);
1437 public Future<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> getAllQueuesStatisticsFromGivenPort(
1438 GetAllQueuesStatisticsFromGivenPortInput arg0) {
1439 //Generate xid to associate it with the request
1440 Long xid = this.getSessionContext().getNextXid();
1442 LOG.info("Prepare queue statistics request to collect stats for " +
1443 "all queues attached to given port {} of node {} - TrasactionId - {}",arg0.getNodeConnectorId().toString(),arg0.getNode().getValue(),xid);
1445 // Create multipart request header
1446 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1447 mprInput.setType(MultipartType.OFPMPQUEUE);
1448 mprInput.setVersion(version);
1449 mprInput.setXid(xid);
1450 mprInput.setFlags(new MultipartRequestFlags(false));
1452 // Create multipart request body to fetch stats for all the port of the node
1453 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1454 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1456 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1457 //Select specific port
1458 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1460 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1462 //Set request body to main multipart request
1463 mprInput.setMultipartRequestBody(caseBuilder.build());
1465 //Send the request, no cookies associated, use any connection
1466 LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString());
1467 this.messageService.multipartRequest(mprInput.build(), null);
1469 // Prepare rpc return output. Set xid and send it back.
1470 GetAllQueuesStatisticsFromGivenPortOutputBuilder output = new GetAllQueuesStatisticsFromGivenPortOutputBuilder();
1471 output.setTransactionId(generateTransactionId(xid));
1472 output.setQueueIdAndStatisticsMap(null);
1474 Collection<RpcError> errors = Collections.emptyList();
1475 RpcResult<GetAllQueuesStatisticsFromGivenPortOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1476 return Futures.immediateFuture(rpcResult);
1480 public Future<RpcResult<GetQueueStatisticsFromGivenPortOutput>> getQueueStatisticsFromGivenPort(
1481 GetQueueStatisticsFromGivenPortInput arg0) {
1482 //Generate xid to associate it with the request
1483 Long xid = this.getSessionContext().getNextXid();
1485 LOG.info("Prepare queue statistics request to collect stats for " +
1486 "given queue attached to given port {} of node {} - TrasactionId - {}",arg0.getQueueId().toString(),arg0.getNodeConnectorId().toString(),arg0.getNode().getValue(),xid);
1488 // Create multipart request header
1489 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1490 mprInput.setType(MultipartType.OFPMPQUEUE);
1491 mprInput.setVersion(version);
1492 mprInput.setXid(xid);
1493 mprInput.setFlags(new MultipartRequestFlags(false));
1495 // Create multipart request body to fetch stats for all the port of the node
1496 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1497 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1498 //Select specific queue
1499 mprQueueBuilder.setQueueId(arg0.getQueueId().getValue());
1500 //Select specific port
1501 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1503 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1505 //Set request body to main multipart request
1506 mprInput.setMultipartRequestBody(caseBuilder.build());
1508 //Send the request, no cookies associated, use any connection
1509 LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString());
1510 this.messageService.multipartRequest(mprInput.build(), null);
1512 // Prepare rpc return output. Set xid and send it back.
1513 GetQueueStatisticsFromGivenPortOutputBuilder output = new GetQueueStatisticsFromGivenPortOutputBuilder();
1514 output.setTransactionId(generateTransactionId(xid));
1515 output.setQueueIdAndStatisticsMap(null);
1517 Collection<RpcError> errors = Collections.emptyList();
1518 RpcResult<GetQueueStatisticsFromGivenPortOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1519 return Futures.immediateFuture(rpcResult);
1523 public Future<RpcResult<GetAllFlowStatisticsOutput>> getAllFlowStatistics(GetAllFlowStatisticsInput arg0) {
1524 //TODO: Depricated, need to clean it up. Sal-Compatibility layes is dependent on it.
1525 // Once sal-compatibility layer is fixed this rpc call can be removed from yang file
1530 public Future<RpcResult<GetAllNodeConnectorStatisticsOutput>> getAllNodeConnectorStatistics(
1531 GetAllNodeConnectorStatisticsInput arg0) {
1532 // TODO Auto-generated method stub
1537 public Future<RpcResult<GetFlowStatisticsOutput>> getFlowStatistics(GetFlowStatisticsInput arg0) {
1538 //TODO: Depricated, need to clean it up. Sal-Compatibility layes is dependent on it.
1539 // Once sal-compatibility layer is fixed this rpc call can be removed from yang file
1544 public Future<RpcResult<GetFlowTableStatisticsOutput>> getFlowTableStatistics(GetFlowTableStatisticsInput arg0) {
1545 // TODO Auto-generated method stub
1550 public Future<RpcResult<GetNodeConnectorStatisticsOutput>> getNodeConnectorStatistics(
1551 GetNodeConnectorStatisticsInput arg0) {
1552 // TODO Auto-generated method stub