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();
209 public Future<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
210 // Convert the AddFlowInput to FlowModInput
211 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input, version);
212 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
213 barrierInput.setVersion(version);
215 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
216 // the request can be routed through any connection to the switch
218 SwitchConnectionDistinguisher cookie = null ;
219 if (input.isBarrier()) {
220 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
223 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
224 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
226 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
229 rpcResultFromOFLib = resultFromOFLib.get();
230 } catch( Exception ex ) {
231 LOG.error( " Error while getting result for AddFlow RPC" + ex.getMessage());
234 UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult() ;
236 AddFlowOutputBuilder addFlowOutput = new AddFlowOutputBuilder() ;
237 addFlowOutput.setTransactionId(updateFlowOutput.getTransactionId()) ;
238 AddFlowOutput result = addFlowOutput.build();
240 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
241 RpcResult<AddFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
243 LOG.debug("Returning the Add Flow RPC result to MD-SAL");
244 return Futures.immediateFuture(rpcResult);
248 public Future<RpcResult<AddGroupOutput>> addGroup(AddGroupInput input) {
249 // Convert the AddGroupInput to GroupModInput
250 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input, version);
253 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
254 // the request can be routed through any connection to the switch
256 SwitchConnectionDistinguisher cookie = null ;
258 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
259 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
261 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
264 rpcResultFromOFLib = resultFromOFLib.get();
265 } catch( Exception ex ) {
266 LOG.error( " Error while getting result for AddGroup RPC" + ex.getMessage());
269 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult() ;
271 AddGroupOutputBuilder addGroupOutput = new AddGroupOutputBuilder() ;
272 addGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()) ;
273 AddGroupOutput result = addGroupOutput.build();
275 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
276 RpcResult<AddGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
278 LOG.debug("Returning the Add Group RPC result to MD-SAL");
279 return Futures.immediateFuture(rpcResult);
283 public Future<RpcResult<AddMeterOutput>> addMeter(AddMeterInput input) {
284 // Convert the AddMeterInput to MeterModInput
285 MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
288 // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
289 // the request can be routed through any connection to the switch
291 SwitchConnectionDistinguisher cookie = null ;
293 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
294 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ;
296 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null ;
299 rpcResultFromOFLib = resultFromOFLib.get();
300 } catch( Exception ex ) {
301 LOG.error( " Error while getting result for AddMeter RPC" + ex.getMessage());
304 UpdateMeterOutput updateMeterOutput = rpcResultFromOFLib.getResult() ;
306 AddMeterOutputBuilder addMeterOutput = new AddMeterOutputBuilder() ;
307 addMeterOutput.setTransactionId(updateMeterOutput.getTransactionId()) ;
308 AddMeterOutput result = addMeterOutput.build();
310 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
311 RpcResult<AddMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
313 LOG.debug("Returning the Add Meter RPC result to MD-SAL");
314 return Futures.immediateFuture(rpcResult);
318 public Future<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
319 // Convert the RemoveFlowInput to FlowModInput
320 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input, version);
321 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
322 barrierInput.setVersion(version);
324 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
325 // the request can be routed through any connection to the switch
327 SwitchConnectionDistinguisher cookie = null ;
328 if (input.isBarrier()) {
329 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
332 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
333 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
335 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
338 rpcResultFromOFLib = resultFromOFLib.get();
339 } catch( Exception ex ) {
340 LOG.error( " Error while getting result for remove Flow RPC" + ex.getMessage());
343 UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult() ;
345 RemoveFlowOutputBuilder removeFlowOutput = new RemoveFlowOutputBuilder() ;
346 removeFlowOutput.setTransactionId(updateFlowOutput.getTransactionId()) ;
347 RemoveFlowOutput result = removeFlowOutput.build();
349 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
350 RpcResult<RemoveFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
352 LOG.debug("Returning the Remove Flow RPC result to MD-SAL");
353 return Futures.immediateFuture(rpcResult);
357 public Future<RpcResult<RemoveGroupOutput>> removeGroup(
358 RemoveGroupInput input) {
359 // Convert the RemoveGroupInput to GroupModInput
360 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input, version);
363 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
364 // the request can be routed through any connection to the switch
366 SwitchConnectionDistinguisher cookie = null ;
368 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
369 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
371 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
374 rpcResultFromOFLib = resultFromOFLib.get();
375 } catch( Exception ex ) {
376 LOG.error( " Error while getting result for RemoveGroup RPC" + ex.getMessage());
379 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult() ;
381 RemoveGroupOutputBuilder removeGroupOutput = new RemoveGroupOutputBuilder() ;
382 removeGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()) ;
383 RemoveGroupOutput result = removeGroupOutput.build();
385 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
386 RpcResult<RemoveGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
388 LOG.debug("Returning the Remove Group RPC result to MD-SAL");
389 return Futures.immediateFuture(rpcResult);
393 public Future<RpcResult<RemoveMeterOutput>> removeMeter(
394 RemoveMeterInput input) {
395 // Convert the RemoveMeterInput to MeterModInput
396 MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
399 // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
400 // the request can be routed through any connection to the switch
402 SwitchConnectionDistinguisher cookie = null ;
404 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
405 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ;
407 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null ;
410 rpcResultFromOFLib = resultFromOFLib.get();
411 } catch( Exception ex ) {
412 LOG.error( " Error while getting result for RemoveMeter RPC" + ex.getMessage());
415 UpdateMeterOutput updatemeterOutput = rpcResultFromOFLib.getResult() ;
417 RemoveMeterOutputBuilder removeMeterOutput = new RemoveMeterOutputBuilder() ;
418 removeMeterOutput.setTransactionId(updatemeterOutput.getTransactionId()) ;
419 RemoveMeterOutput result = removeMeterOutput.build();
421 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
422 RpcResult<RemoveMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
424 LOG.debug("Returning the Remove Meter RPC result to MD-SAL");
425 return Futures.immediateFuture(rpcResult);
429 public Future<RpcResult<Void>> transmitPacket(TransmitPacketInput input) {
430 // TODO Auto-generated method stub
434 private FlowModInputBuilder toFlowModInputBuilder(Flow source) {
435 FlowModInputBuilder target = new FlowModInputBuilder();
436 target.setCookie(source.getCookie());
437 target.setIdleTimeout(source.getIdleTimeout());
438 target.setHardTimeout(source.getHardTimeout());
439 target.setMatch(toMatch(source.getMatch()));
444 private Match toMatch(
445 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
446 MatchBuilder target = new MatchBuilder();
448 target.setMatchEntries(toMatchEntries(match));
453 private List<MatchEntries> toMatchEntries(
454 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
455 List<MatchEntries> entries = new ArrayList<>();
461 public Future<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
462 // Convert the UpdateFlowInput to FlowModInput
463 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input.getUpdatedFlow(), version);
464 BarrierInputBuilder barrierInput = new BarrierInputBuilder();
465 barrierInput.setVersion(version);
466 // Call the RPC method on MessageDispatchService
468 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
469 // the request can be routed through any connection to the switch
471 SwitchConnectionDistinguisher cookie = null ;
472 if (input.getUpdatedFlow().isBarrier()) {
473 Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
476 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
477 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
479 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
482 rpcResultFromOFLib = resultFromOFLib.get();
483 } catch( Exception ex ) {
484 LOG.error( " Error while getting result for UpdateFlow RPC" + ex.getMessage());
487 UpdateFlowOutput updateFlowOutputOFLib = rpcResultFromOFLib.getResult() ;
489 UpdateFlowOutputBuilder updateFlowOutput = new UpdateFlowOutputBuilder() ;
490 updateFlowOutput.setTransactionId(updateFlowOutputOFLib.getTransactionId()) ;
491 UpdateFlowOutput result = updateFlowOutput.build();
493 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
494 RpcResult<UpdateFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
496 LOG.debug("Returning the Update Flow RPC result to MD-SAL");
497 return Futures.immediateFuture(rpcResult);
501 public Future<RpcResult<UpdateGroupOutput>> updateGroup(
502 UpdateGroupInput input) {
503 // Convert the UpdateGroupInput to GroupModInput
504 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input.getUpdatedGroup(), version);
507 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
508 // the request can be routed through any connection to the switch
510 SwitchConnectionDistinguisher cookie = null ;
512 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
513 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
515 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
518 rpcResultFromOFLib = resultFromOFLib.get();
519 } catch( Exception ex ) {
520 LOG.error( " Error while getting result for updateGroup RPC" + ex.getMessage());
523 UpdateGroupOutput updateGroupOutputOFLib = rpcResultFromOFLib.getResult() ;
525 UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder() ;
526 updateGroupOutput.setTransactionId(updateGroupOutputOFLib.getTransactionId()) ;
527 UpdateGroupOutput result = updateGroupOutput.build();
529 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
530 RpcResult<UpdateGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
532 LOG.debug("Returning the Update Group RPC result to MD-SAL");
533 return Futures.immediateFuture(rpcResult);
537 public Future<RpcResult<UpdateMeterOutput>> updateMeter(
538 UpdateMeterInput input) {
539 // Convert the UpdateMeterInput to MeterModInput
540 MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input.getUpdatedMeter(), version);
543 // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
544 // the request can be routed through any connection to the switch
546 SwitchConnectionDistinguisher cookie = null ;
548 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
549 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ;
551 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null ;
554 rpcResultFromOFLib = resultFromOFLib.get();
555 } catch( Exception ex ) {
556 LOG.error( " Error while getting result for UpdateMeter RPC" + ex.getMessage());
559 UpdateMeterOutput updateMeterOutputFromOFLib = rpcResultFromOFLib.getResult() ;
561 UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder() ;
562 updateMeterOutput.setTransactionId(updateMeterOutputFromOFLib.getTransactionId()) ;
563 UpdateMeterOutput result = updateMeterOutput.build();
565 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
566 RpcResult<UpdateMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
568 LOG.debug("Returning the Update Meter RPC result to MD-SAL");
569 return Futures.immediateFuture(rpcResult);
573 public NodeId getNodeId() {
578 * Methods for requesting statistics from switch
581 public Future<RpcResult<GetAllGroupStatisticsOutput>> getAllGroupStatistics(GetAllGroupStatisticsInput input) {
583 //Generate xid to associate it with the request
584 Long xid = this.getSessionContext().getNextXid();
586 LOG.debug("Prepare statistics request for all the groups - Transaction id - {}",xid);
588 // Create multipart request header
589 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
590 mprInput.setType(MultipartType.OFPMPGROUP);
591 mprInput.setVersion(version);
592 mprInput.setXid(xid);
593 mprInput.setFlags(new MultipartRequestFlags(false));
595 // Create multipart request body for fetch all the group stats
596 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
597 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
598 mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(Group.OFPGALL.getIntValue())));
599 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
601 //Set request body to main multipart request
602 mprInput.setMultipartRequestBody(caseBuilder.build());
604 //Send the request, no cookies associated, use any connection
605 LOG.debug("Send group statistics request to the switch :{}",mprGroupBuild);
606 this.messageService.multipartRequest(mprInput.build(), null);
608 // Prepare rpc return output. Set xid and send it back.
609 LOG.debug("Return results and transaction id back to caller");
610 GetAllGroupStatisticsOutputBuilder output = new GetAllGroupStatisticsOutputBuilder();
611 output.setTransactionId(generateTransactionId(xid));
612 output.setGroupStats(null);
614 Collection<RpcError> errors = Collections.emptyList();
615 RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
616 return Futures.immediateFuture(rpcResult);
621 public Future<RpcResult<GetGroupDescriptionOutput>> getGroupDescription(GetGroupDescriptionInput input) {
623 //Generate xid to associate it with the request
624 Long xid = this.getSessionContext().getNextXid();
626 LOG.debug("Prepare group description statistics request - Transaction id - {}",xid);
628 // Create multipart request header
629 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
630 mprInput.setType(MultipartType.OFPMPGROUPDESC);
631 mprInput.setVersion(version);
632 mprInput.setXid(xid);
633 mprInput.setFlags(new MultipartRequestFlags(false));
635 // Create multipart request body for fetch all the group description stats
636 MultipartRequestGroupDescCaseBuilder mprGroupDescBuild = new MultipartRequestGroupDescCaseBuilder();
638 //Set request body to main multipart request
639 mprInput.setMultipartRequestBody(mprGroupDescBuild.build());
641 //Send the request, no cookies associated, use any connection
642 LOG.debug("Send group desciption statistics request to switch : {}",mprGroupDescBuild);
643 this.messageService.multipartRequest(mprInput.build(), null);
645 // Prepare rpc return output. Set xid and send it back.
646 LOG.debug("Return results and transaction id back to caller");
647 GetGroupDescriptionOutputBuilder output = new GetGroupDescriptionOutputBuilder();
648 output.setTransactionId(generateTransactionId(xid));
649 output.setGroupDescStats(null);
651 Collection<RpcError> errors = Collections.emptyList();
652 RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
653 return Futures.immediateFuture(rpcResult);
658 public Future<RpcResult<GetGroupFeaturesOutput>> getGroupFeatures(GetGroupFeaturesInput input) {
660 //Generate xid to associate it with the request
661 Long xid = this.getSessionContext().getNextXid();
663 LOG.debug("Prepare group features statistics request - Transaction id - {}",xid);
665 // Create multipart request header
666 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
667 mprInput.setType(MultipartType.OFPMPGROUPFEATURES);
668 mprInput.setVersion(version);
669 mprInput.setXid(xid);
670 mprInput.setFlags(new MultipartRequestFlags(false));
672 // Create multipart request body for fetch all the group description stats
673 MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild = new MultipartRequestGroupFeaturesCaseBuilder();
675 //Set request body to main multipart request
676 mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
678 //Send the request, no cookies associated, use any connection
679 LOG.debug("Send group features statistics request :{}",mprGroupFeaturesBuild);
680 this.messageService.multipartRequest(mprInput.build(), null);
682 // Prepare rpc return output. Set xid and send it back.
683 LOG.debug("Return results and transaction id back to caller");
684 GetGroupFeaturesOutputBuilder output = new GetGroupFeaturesOutputBuilder();
685 output.setTransactionId(generateTransactionId(xid));
687 Collection<RpcError> errors = Collections.emptyList();
688 RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
689 return Futures.immediateFuture(rpcResult);
693 public Future<RpcResult<GetGroupStatisticsOutput>> getGroupStatistics(GetGroupStatisticsInput input) {
695 //Generate xid to associate it with the request
696 Long xid = this.getSessionContext().getNextXid();
698 LOG.debug("Prepare statistics request for node {} group ({}) - Transaction id - {}",input.getNode(),input.getGroupId(),xid);
700 // Create multipart request header
701 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
702 mprInput.setType(MultipartType.OFPMPGROUP);
703 mprInput.setVersion(version);
704 mprInput.setXid(xid);
705 mprInput.setFlags(new MultipartRequestFlags(false));
707 // Create multipart request body for fetch all the group stats
708 MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
709 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
710 mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
711 caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
713 //Set request body to main multipart request
714 mprInput.setMultipartRequestBody(caseBuilder.build());
716 //Send the request, no cookies associated, use any connection
717 LOG.debug("Send group statistics request :{}",mprGroupBuild);
718 this.messageService.multipartRequest(mprInput.build(), null);
720 // Prepare rpc return output. Set xid and send it back.
721 LOG.debug("Return results and transaction id back to caller");
722 GetGroupStatisticsOutputBuilder output = new GetGroupStatisticsOutputBuilder();
723 output.setTransactionId(generateTransactionId(xid));
724 output.setGroupStats(null);
726 Collection<RpcError> errors = Collections.emptyList();
727 RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
728 return Futures.immediateFuture(rpcResult);
732 public Future<RpcResult<GetAllMeterConfigStatisticsOutput>> getAllMeterConfigStatistics(
733 GetAllMeterConfigStatisticsInput input) {
735 //Generate xid to associate it with the request
736 Long xid = this.getSessionContext().getNextXid();
738 LOG.debug("Prepare config request for all the meters - Transaction id - {}",xid);
740 // Create multipart request header
741 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
742 mprInput.setType(MultipartType.OFPMPMETERCONFIG);
743 mprInput.setVersion(version);
744 mprInput.setXid(xid);
745 mprInput.setFlags(new MultipartRequestFlags(false));
747 // Create multipart request body for fetch all the meter stats
748 MultipartRequestMeterConfigCaseBuilder caseBuilder = new MultipartRequestMeterConfigCaseBuilder();
749 MultipartRequestMeterConfigBuilder mprMeterConfigBuild = new MultipartRequestMeterConfigBuilder();
750 mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
751 caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
753 //Set request body to main multipart request
754 mprInput.setMultipartRequestBody(caseBuilder.build());
756 //Send the request, no cookies associated, use any connection
757 LOG.debug("Send meter statistics request :{}",mprMeterConfigBuild);
758 this.messageService.multipartRequest(mprInput.build(), null);
760 // Prepare rpc return output. Set xid and send it back.
761 LOG.debug("Return results and transaction id back to caller");
762 GetAllMeterConfigStatisticsOutputBuilder output = new GetAllMeterConfigStatisticsOutputBuilder();
763 output.setTransactionId(generateTransactionId(xid));
764 output.setMeterConfigStats(null);
766 Collection<RpcError> errors = Collections.emptyList();
767 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
768 return Futures.immediateFuture(rpcResult);
772 public Future<RpcResult<GetAllMeterStatisticsOutput>> getAllMeterStatistics(GetAllMeterStatisticsInput input) {
774 //Generate xid to associate it with the request
775 Long xid = this.getSessionContext().getNextXid();
777 LOG.debug("Prepare statistics request for all the meters - Transaction id - {}",xid);
779 // Create multipart request header
780 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
781 mprInput.setType(MultipartType.OFPMPMETER);
782 mprInput.setVersion(version);
783 mprInput.setXid(xid);
784 mprInput.setFlags(new MultipartRequestFlags(false));
786 // Create multipart request body for fetch all the meter stats
787 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
788 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
789 mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
790 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
792 //Set request body to main multipart request
793 mprInput.setMultipartRequestBody(caseBuilder.build());
795 //Send the request, no cookies associated, use any connection
796 LOG.debug("Send meter statistics request :{}",mprMeterBuild);
797 this.messageService.multipartRequest(mprInput.build(), null);
799 // Prepare rpc return output. Set xid and send it back.
800 LOG.debug("Return results and transaction id back to caller");
801 GetAllMeterStatisticsOutputBuilder output = new GetAllMeterStatisticsOutputBuilder();
802 output.setTransactionId(generateTransactionId(xid));
803 output.setMeterStats(null);
805 Collection<RpcError> errors = Collections.emptyList();
806 RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
807 return Futures.immediateFuture(rpcResult);
811 public Future<RpcResult<GetMeterFeaturesOutput>> getMeterFeatures(GetMeterFeaturesInput input) {
813 //Generate xid to associate it with the request
814 Long xid = this.getSessionContext().getNextXid();
816 LOG.debug("Prepare features statistics request for all the meters - Transaction id - {}",xid);
818 // Create multipart request header
819 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
820 mprInput.setType(MultipartType.OFPMPMETERFEATURES);
821 mprInput.setVersion(version);
822 mprInput.setXid(xid);
823 mprInput.setFlags(new MultipartRequestFlags(false));
825 // Create multipart request body for fetch all the group description stats
826 MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild = new MultipartRequestMeterFeaturesCaseBuilder();
828 //Set request body to main multipart request
829 mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
831 //Send the request, no cookies associated, use any connection
832 LOG.debug("Send meter features statistics request :{}",mprMeterFeaturesBuild);
833 this.messageService.multipartRequest(mprInput.build(), null);
835 // Prepare rpc return output. Set xid and send it back.
836 LOG.debug("Return results and transaction id back to caller");
837 GetMeterFeaturesOutputBuilder output = new GetMeterFeaturesOutputBuilder();
838 output.setTransactionId(generateTransactionId(xid));
840 Collection<RpcError> errors = Collections.emptyList();
841 RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
842 return Futures.immediateFuture(rpcResult);
846 public Future<RpcResult<GetMeterStatisticsOutput>> getMeterStatistics(GetMeterStatisticsInput input) {
847 //Generate xid to associate it with the request
848 Long xid = this.getSessionContext().getNextXid();
850 LOG.debug("Preprae statistics request for Meter ({}) - Transaction id - {}",input.getMeterId().getValue(),xid);
852 // Create multipart request header
853 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
854 mprInput.setType(MultipartType.OFPMPMETER);
855 mprInput.setVersion(version);
856 mprInput.setXid(xid);
857 mprInput.setFlags(new MultipartRequestFlags(false));
859 // Create multipart request body for fetch all the meter stats
860 MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
861 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
862 //Select specific meter
863 mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
864 caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
866 //Set request body to main multipart request
867 mprInput.setMultipartRequestBody(caseBuilder.build());
869 //Send the request, no cookies associated, use any connection
870 LOG.debug("Send meter statistics request :{}",mprMeterBuild);
871 this.messageService.multipartRequest(mprInput.build(), null);
873 // Prepare rpc return output. Set xid and send it back.
874 LOG.debug("Return results and transaction id back to caller");
875 GetMeterStatisticsOutputBuilder output = new GetMeterStatisticsOutputBuilder();
876 output.setTransactionId(generateTransactionId(xid));
877 output.setMeterStats(null);
879 Collection<RpcError> errors = Collections.emptyList();
880 RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
881 return Futures.immediateFuture(rpcResult);
885 public Future<RpcResult<GetAllPortsStatisticsOutput>> getAllPortsStatistics(GetAllPortsStatisticsInput arg0) {
887 //Generate xid to associate it with the request
888 Long xid = this.getSessionContext().getNextXid();
890 LOG.info("Prepare port statistics request for all ports of node {} - TrasactionId - {}",arg0.getNode().getValue(),xid);
892 // Create multipart request header
893 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
894 mprInput.setType(MultipartType.OFPMPPORTSTATS);
895 mprInput.setVersion(version);
896 mprInput.setXid(xid);
897 mprInput.setFlags(new MultipartRequestFlags(false));
899 // Create multipart request body to fetch stats for all the port of the node
900 MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
901 MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
903 mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
904 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
906 //Set request body to main multipart request
907 mprInput.setMultipartRequestBody(caseBuilder.build());
909 //Send the request, no cookies associated, use any connection
910 LOG.debug("Send port statistics request :{}",mprPortStatsBuilder.build().toString());
911 this.messageService.multipartRequest(mprInput.build(), null);
913 // Prepare rpc return output. Set xid and send it back.
914 GetAllPortsStatisticsOutputBuilder output = new GetAllPortsStatisticsOutputBuilder();
915 output.setTransactionId(generateTransactionId(xid));
917 Collection<RpcError> errors = Collections.emptyList();
918 RpcResult<GetAllPortsStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
919 return Futures.immediateFuture(rpcResult);
923 public Future<RpcResult<GetPortStatisticsOutput>> getPortStatistics(GetPortStatisticsInput arg0) {
924 //Generate xid to associate it with the request
925 Long xid = this.getSessionContext().getNextXid();
927 LOG.info("Prepare port statistics request for port {} of node {} - TrasactionId - {}",arg0.getNodeConnectorId(), arg0.getNode().getValue(),xid);
929 // Create multipart request header
930 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
931 mprInput.setType(MultipartType.OFPMPPORTSTATS);
932 mprInput.setVersion(version);
933 mprInput.setXid(xid);
934 mprInput.setFlags(new MultipartRequestFlags(false));
936 // Create multipart request body to fetch stats for all the port of the node
937 MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
938 MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
941 mprPortStatsBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
942 caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
944 //Set request body to main multipart request
945 mprInput.setMultipartRequestBody(caseBuilder.build());
947 //Send the request, no cookies associated, use any connection
948 LOG.debug("Send port statistics request :{}",mprPortStatsBuilder.build().toString());
949 this.messageService.multipartRequest(mprInput.build(), null);
951 // Prepare rpc return output. Set xid and send it back.
952 GetPortStatisticsOutputBuilder output = new GetPortStatisticsOutputBuilder();
953 output.setTransactionId(generateTransactionId(xid));
955 Collection<RpcError> errors = Collections.emptyList();
956 RpcResult<GetPortStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
957 return Futures.immediateFuture(rpcResult);
960 private TransactionId generateTransactionId(Long xid){
961 String stringXid =xid.toString();
962 BigInteger bigIntXid = new BigInteger( stringXid );
963 return new TransactionId(bigIntXid);
968 public Future<RpcResult<GetPortOutput>> getPort() {
969 // TODO Auto-generated method stub
975 public Future<RpcResult<UpdatePortOutput>> updatePort(UpdatePortInput input) {
976 PortModInput ofPortModInput = null ;
977 RpcResult<UpdatePortOutput> rpcResultFromOFLib = null ;
980 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
981 // the request can be routed through any connection to the switch
983 SwitchConnectionDistinguisher cookie = null ;
985 // NSF sends a list of port and the ModelDrivenSwitch will
986 // send one port at a time towards the switch ( mutiple RPCs calls)
987 List<Port> inputPorts = input.getUpdatedPort().getPort().getPort() ;
989 // Get the Xid. The same Xid has to be sent in all the RPCs
990 Long Xid = sessionContext.getNextXid();
992 for( Port inputPort : inputPorts) {
994 // Convert the UpdateGroupInput to GroupModInput
995 ofPortModInput = PortConvertor.toPortModInput(inputPort, version) ;
997 // Insert the Xid ( transaction Id) before calling the RPC on the OFLibrary
999 PortModInputBuilder mdInput = new PortModInputBuilder();
1000 mdInput.setXid(Xid);
1001 mdInput.setVersion(ofPortModInput.getVersion()) ;
1002 mdInput.setPortNo(ofPortModInput.getPortNo()) ;
1003 mdInput.setMaskV10(ofPortModInput.getMaskV10()) ;
1004 mdInput.setMask(ofPortModInput.getMask()) ;
1005 mdInput.setHwAddress(ofPortModInput.getHwAddress());
1006 mdInput.setConfigV10(ofPortModInput.getConfigV10()) ;
1007 mdInput.setConfig(ofPortModInput.getConfig()) ;
1008 mdInput.setAdvertiseV10(ofPortModInput.getAdvertiseV10()) ;
1009 mdInput.setAdvertise(ofPortModInput.getAdvertise()) ;
1011 LOG.debug("Calling the PortMod RPC method on MessageDispatchService");
1012 Future<RpcResult<UpdatePortOutput>> resultFromOFLib = messageService.portMod(ofPortModInput, cookie) ;
1015 rpcResultFromOFLib = resultFromOFLib.get();
1016 } catch( Exception ex ) {
1017 LOG.error( " Error while getting result for updatePort RPC" + ex.getMessage());
1020 // The Future response value for all the RPCs except the last one is ignored
1023 //Extract the Xid only from the Future for the last RPC and
1024 // send it back to the NSF
1025 UpdatePortOutput updatePortOutputOFLib = rpcResultFromOFLib.getResult() ;
1027 UpdatePortOutputBuilder updatePortOutput = new UpdatePortOutputBuilder() ;
1028 updatePortOutput.setTransactionId(updatePortOutputOFLib.getTransactionId()) ;
1029 UpdatePortOutput result = updatePortOutput.build();
1031 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
1032 RpcResult<UpdatePortOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
1034 LOG.debug("Returning the Update Group RPC result to MD-SAL");
1035 return Futures.immediateFuture(rpcResult);
1040 public Future<RpcResult<UpdateTableOutput>> updateTable(
1041 UpdateTableInput input) {
1043 // Get the Xid. The same Xid has to be sent in all the Multipart requests
1044 Long xid = this.getSessionContext().getNextXid();
1046 LOG.debug("Prepare the Multipart Table Mod requests for Transaction Id {} ",xid);
1048 // Create multipart request header
1049 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1050 mprInput.setType(MultipartType.OFPMPTABLEFEATURES);
1051 mprInput.setVersion((short)0x04);
1052 mprInput.setXid(xid);
1054 //Convert the list of all MD-SAL table feature object into OF library object
1055 List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input.getUpdatedTable()) ;
1056 int totalNoOfTableFeatureEntry = ofTableFeatureList.size();
1058 MultipartRequestTableFeaturesCaseBuilder caseRequest = new MultipartRequestTableFeaturesCaseBuilder();
1059 MultipartRequestTableFeaturesBuilder tableFeaturesRequest = new MultipartRequestTableFeaturesBuilder();
1061 // Slice the multipart request based on the configuration parameter, which is the no. of TableFeatureList element
1062 // to be put in one multipart message. Default is 5
1063 // This parameter must be set based on switch's Buffer capacity
1065 List<TableFeatures> tmpOfTableFeatureList = null ;
1066 String tableFeatureListCount = System.getProperty( "of.tableFeaturesCountPerMultipart", "5") ;
1067 int noOfEntriesInMPR = Integer.parseInt(tableFeatureListCount) ;
1070 while(totalNoOfTableFeatureEntry-index > 0 ) {
1071 if( (totalNoOfTableFeatureEntry-index) > noOfEntriesInMPR ) {
1072 mprInput.setFlags(new MultipartRequestFlags(true));
1073 tmpOfTableFeatureList = ofTableFeatureList.subList(index, index + noOfEntriesInMPR);
1076 // Last multipart request
1077 mprInput.setFlags(new MultipartRequestFlags(false));
1078 tmpOfTableFeatureList = ofTableFeatureList.subList(index, totalNoOfTableFeatureEntry );
1081 tableFeaturesRequest.setTableFeatures(tmpOfTableFeatureList) ;
1082 //Set request body to main multipart request
1083 caseRequest.setMultipartRequestTableFeatures(tableFeaturesRequest.build());
1084 mprInput.setMultipartRequestBody(caseRequest.build());
1086 //Send the request, no cookies associated, use any connection
1087 LOG.debug("Send Table Feature request :{}",tmpOfTableFeatureList);
1088 this.messageService.multipartRequest(mprInput.build(), null);
1089 index += noOfEntriesInMPR ;
1090 tmpOfTableFeatureList = null ; // To avoid any corrupt data
1093 //Extract the Xid only from the Future for the last RPC and
1094 // send it back to the NSF
1095 LOG.debug("Returning the result and transaction id to NSF");
1096 LOG.debug("Return results and transaction id back to caller");
1097 UpdateTableOutputBuilder output = new UpdateTableOutputBuilder();
1098 output.setTransactionId(generateTransactionId(xid));
1100 Collection<RpcError> errors = Collections.emptyList();
1101 RpcResult<UpdateTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1102 return Futures.immediateFuture(rpcResult);
1106 public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
1107 GetAllFlowStatisticsFromFlowTableInput arg0) {
1109 //Generate xid to associate it with the request
1110 Long xid = this.getSessionContext().getNextXid();
1112 LOG.debug("Prepare statistics request to get flow stats for switch tables {} - Transaction id - {}"
1113 ,arg0.getTableId().getValue(),xid);
1115 // Create multipart request header
1116 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1117 mprInput.setType(MultipartType.OFPMPFLOW);
1118 mprInput.setVersion(version);
1119 mprInput.setXid(xid);
1120 mprInput.setFlags(new MultipartRequestFlags(false));
1122 // Create multipart request body for fetch all the group stats
1123 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder ();
1124 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1125 mprFlowRequestBuilder.setTableId(arg0.getTableId().getValue());
1126 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1127 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1128 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1129 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1131 if(version == OFConstants.OFP_VERSION_1_0){
1132 LOG.info("Target node is running openflow version 1.0");
1133 FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true);
1134 mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
1136 if(version == OFConstants.OFP_VERSION_1_3){
1137 LOG.info("Target node is running openflow version 1.3+");
1138 mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
1142 //Set request body to main multipart request
1143 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1144 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1146 //Send the request, no cookies associated, use any connection
1147 LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
1148 this.messageService.multipartRequest(mprInput.build(), null);
1150 // Prepare rpc return output. Set xid and send it back.
1151 LOG.debug("Return results and transaction id back to caller");
1152 GetAllFlowStatisticsFromFlowTableOutputBuilder output =
1153 new GetAllFlowStatisticsFromFlowTableOutputBuilder();
1154 output.setTransactionId(generateTransactionId(xid));
1155 output.setFlowAndStatisticsMapList(null);
1157 Collection<RpcError> errors = Collections.emptyList();
1158 RpcResult<GetAllFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1159 return Futures.immediateFuture(rpcResult);
1163 public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
1164 GetAllFlowsStatisticsFromAllFlowTablesInput arg0) {
1166 //Generate xid to associate it with the request
1167 Long xid = this.getSessionContext().getNextXid();
1169 LOG.info("Prepare statistics request to get flow stats of all switch tables - Transaction id - {}",xid);
1171 // Create multipart request header
1172 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1173 mprInput.setType(MultipartType.OFPMPFLOW);
1174 mprInput.setVersion(version);
1175 mprInput.setXid(xid);
1176 mprInput.setFlags(new MultipartRequestFlags(false));
1178 // Create multipart request body for fetch all the group stats
1179 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1180 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1181 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
1182 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1183 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1184 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1185 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1186 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1188 //TODO: repeating code
1189 if(version == OFConstants.OFP_VERSION_1_0){
1190 FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true);
1191 mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
1193 if(version == OFConstants.OFP_VERSION_1_3){
1194 mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
1196 //Set request body to main multipart request
1197 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1198 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1200 //Send the request, no cookies associated, use any connection
1201 LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
1202 this.messageService.multipartRequest(mprInput.build(), null);
1204 // Prepare rpc return output. Set xid and send it back.
1205 GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder output =
1206 new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder();
1207 output.setTransactionId(generateTransactionId(xid));
1208 output.setFlowAndStatisticsMapList(null);
1210 Collection<RpcError> errors = Collections.emptyList();
1211 RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1212 return Futures.immediateFuture(rpcResult);
1217 public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
1218 GetFlowStatisticsFromFlowTableInput arg0) {
1219 //Generate xid to associate it with the request
1220 Long xid = this.getSessionContext().getNextXid();
1222 LOG.info("Prepare statistics request to get stats for flow {} for switch tables {} - Transaction id - {}"
1223 ,arg0.getMatch().toString(),arg0.getTableId(),xid);
1225 // Create multipart request header
1226 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1227 mprInput.setType(MultipartType.OFPMPFLOW);
1228 mprInput.setVersion(version);
1229 mprInput.setXid(xid);
1230 mprInput.setFlags(new MultipartRequestFlags(false));
1232 // Create multipart request body for fetch all the group stats
1233 MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1234 MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1235 mprFlowRequestBuilder.setTableId(arg0.getTableId());
1236 mprFlowRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1237 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1238 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1239 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1241 // convert and inject match
1242 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprFlowRequestBuilder);
1243 //TODO: repeating code
1244 if(version == OFConstants.OFP_VERSION_1_3){
1245 mprFlowRequestBuilder.setCookie(arg0.getCookie());
1246 mprFlowRequestBuilder.setCookieMask(arg0.getCookieMask());
1247 mprFlowRequestBuilder.setOutGroup(arg0.getOutGroup());
1250 //Set request body to main multipart request
1251 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1252 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1254 //Send the request, no cookies associated, use any connection
1255 LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder);
1256 this.messageService.multipartRequest(mprInput.build(), null);
1258 // Prepare rpc return output. Set xid and send it back.
1259 GetFlowStatisticsFromFlowTableOutputBuilder output =
1260 new GetFlowStatisticsFromFlowTableOutputBuilder();
1261 output.setTransactionId(generateTransactionId(xid));
1262 output.setFlowAndStatisticsMapList(null);
1264 Collection<RpcError> errors = Collections.emptyList();
1265 RpcResult<GetFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1266 return Futures.immediateFuture(rpcResult);
1270 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
1271 GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput arg0) {
1272 //Generate xid to associate it with the request
1273 Long xid = this.getSessionContext().getNextXid();
1275 LOG.info("Prepare aggregate flow statistics request to get aggregate flow stats for all the flow installed on switch table {} - Transaction id - {}"
1276 ,arg0.getTableId().getValue(),xid);
1278 // Create multipart request header
1279 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1280 mprInput.setType(MultipartType.OFPMPAGGREGATE);
1281 mprInput.setVersion(version);
1282 mprInput.setXid(xid);
1283 mprInput.setFlags(new MultipartRequestFlags(false));
1285 // Create multipart request body for fetch all the group stats
1286 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder ();
1287 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1288 mprAggregateRequestBuilder.setTableId(arg0.getTableId().getValue());
1289 mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1290 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1291 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1292 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1294 //TODO: repeating code
1295 if(version == OFConstants.OFP_VERSION_1_0){
1296 FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true);
1297 mprAggregateRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build());
1299 if(version == OFConstants.OFP_VERSION_1_3){
1300 mprAggregateRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build());
1304 //Set request body to main multipart request
1305 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1306 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1308 //Send the request, no cookies associated, use any connection
1309 LOG.debug("Send request to the switch :{}",multipartRequestAggregateCaseBuilder.build().toString());
1310 this.messageService.multipartRequest(mprInput.build(), null);
1312 // Prepare rpc return output. Set xid and send it back.
1313 GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder output =
1314 new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder();
1315 output.setTransactionId(generateTransactionId(xid));
1317 Collection<RpcError> errors = Collections.emptyList();
1318 RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1319 return Futures.immediateFuture(rpcResult);
1323 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
1324 GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput arg0) {
1326 //Generate xid to associate it with the request
1327 Long xid = this.getSessionContext().getNextXid();
1329 LOG.debug("Prepare agregate statistics request to get aggregate stats for flows matching {} and installed in flow tables {} - Transaction id - {}"
1330 ,arg0.getMatch().toString(),arg0.getTableId(),xid);
1332 // Create multipart request header
1333 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1334 mprInput.setType(MultipartType.OFPMPAGGREGATE);
1335 mprInput.setVersion(version);
1336 mprInput.setXid(xid);
1337 mprInput.setFlags(new MultipartRequestFlags(false));
1339 // Create multipart request body for fetch all the group stats
1340 MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder ();
1341 MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1342 mprAggregateRequestBuilder.setTableId(arg0.getTableId());
1343 mprAggregateRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1344 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1345 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1346 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1349 MatchReactor.getInstance().convert(arg0.getMatch(), version, mprAggregateRequestBuilder);
1350 //TODO: repeating code
1351 if(version == OFConstants.OFP_VERSION_1_3){
1352 mprAggregateRequestBuilder.setCookie(arg0.getCookie());
1353 mprAggregateRequestBuilder.setCookieMask(arg0.getCookieMask());
1354 mprAggregateRequestBuilder.setOutGroup(arg0.getOutGroup());
1357 //Set request body to main multipart request
1358 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1359 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1361 //Send the request, no cookies associated, use any connection
1362 LOG.debug("Send request to the switch :{}",multipartRequestAggregateCaseBuilder.build().toString());
1363 this.messageService.multipartRequest(mprInput.build(), null);
1365 // Prepare rpc return output. Set xid and send it back.
1366 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder output =
1367 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
1368 output.setTransactionId(generateTransactionId(xid));
1370 Collection<RpcError> errors = Collections.emptyList();
1371 RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1372 return Futures.immediateFuture(rpcResult);
1376 public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(GetFlowTablesStatisticsInput arg0) {
1377 //Generate xid to associate it with the request
1378 Long xid = this.getSessionContext().getNextXid();
1380 LOG.info("Prepare flow table statistics request to get flow table stats for all tables " +
1381 "from node {}- Transaction id - {}",arg0.getNode(),xid);
1383 // Create multipart request header
1384 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1385 mprInput.setType(MultipartType.OFPMPTABLE);
1386 mprInput.setVersion(version);
1387 mprInput.setXid(xid);
1388 mprInput.setFlags(new MultipartRequestFlags(false));
1390 // Create multipart request body for fetch all the group stats
1391 MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder ();
1392 MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
1393 multipartRequestTableBuilder.setEmpty(true);
1394 multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
1396 //Set request body to main multipart request
1397 mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
1399 //Send the request, no cookies associated, use any connection
1400 LOG.debug("Send request to the switch :{}",multipartRequestTableCaseBuilder.build().toString());
1401 this.messageService.multipartRequest(mprInput.build(), null);
1403 // Prepare rpc return output. Set xid and send it back.
1404 GetFlowTablesStatisticsOutputBuilder output = new GetFlowTablesStatisticsOutputBuilder();
1405 output.setTransactionId(generateTransactionId(xid));
1407 Collection<RpcError> errors = Collections.emptyList();
1408 RpcResult<GetFlowTablesStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1409 return Futures.immediateFuture(rpcResult);
1413 public Future<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> getAllQueuesStatisticsFromAllPorts(
1414 GetAllQueuesStatisticsFromAllPortsInput arg0) {
1415 //Generate xid to associate it with the request
1416 Long xid = this.getSessionContext().getNextXid();
1418 LOG.info("Prepare queue statistics request to collect stats for all queues attached to all the ports of node {} - TrasactionId - {}",arg0.getNode().getValue(),xid);
1420 // Create multipart request header
1421 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1422 mprInput.setType(MultipartType.OFPMPQUEUE);
1423 mprInput.setVersion(version);
1424 mprInput.setXid(xid);
1425 mprInput.setFlags(new MultipartRequestFlags(false));
1427 // Create multipart request body to fetch stats for all the port of the node
1428 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1429 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1431 mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
1432 //Select all the ports
1433 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1435 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1437 //Set request body to main multipart request
1438 mprInput.setMultipartRequestBody(caseBuilder.build());
1440 //Send the request, no cookies associated, use any connection
1441 LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString());
1442 this.messageService.multipartRequest(mprInput.build(), null);
1444 // Prepare rpc return output. Set xid and send it back.
1445 GetAllQueuesStatisticsFromAllPortsOutputBuilder output = new GetAllQueuesStatisticsFromAllPortsOutputBuilder();
1446 output.setTransactionId(generateTransactionId(xid));
1447 output.setQueueIdAndStatisticsMap(null);
1449 Collection<RpcError> errors = Collections.emptyList();
1450 RpcResult<GetAllQueuesStatisticsFromAllPortsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1451 return Futures.immediateFuture(rpcResult);
1455 public Future<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> getAllQueuesStatisticsFromGivenPort(
1456 GetAllQueuesStatisticsFromGivenPortInput arg0) {
1457 //Generate xid to associate it with the request
1458 Long xid = this.getSessionContext().getNextXid();
1460 LOG.info("Prepare queue statistics request to collect stats for " +
1461 "all queues attached to given port {} of node {} - TrasactionId - {}",arg0.getNodeConnectorId().toString(),arg0.getNode().getValue(),xid);
1463 // Create multipart request header
1464 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1465 mprInput.setType(MultipartType.OFPMPQUEUE);
1466 mprInput.setVersion(version);
1467 mprInput.setXid(xid);
1468 mprInput.setFlags(new MultipartRequestFlags(false));
1470 // Create multipart request body to fetch stats for all the port of the node
1471 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1472 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1474 mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1475 //Select specific port
1476 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1478 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1480 //Set request body to main multipart request
1481 mprInput.setMultipartRequestBody(caseBuilder.build());
1483 //Send the request, no cookies associated, use any connection
1484 LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString());
1485 this.messageService.multipartRequest(mprInput.build(), null);
1487 // Prepare rpc return output. Set xid and send it back.
1488 GetAllQueuesStatisticsFromGivenPortOutputBuilder output = new GetAllQueuesStatisticsFromGivenPortOutputBuilder();
1489 output.setTransactionId(generateTransactionId(xid));
1490 output.setQueueIdAndStatisticsMap(null);
1492 Collection<RpcError> errors = Collections.emptyList();
1493 RpcResult<GetAllQueuesStatisticsFromGivenPortOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1494 return Futures.immediateFuture(rpcResult);
1498 public Future<RpcResult<GetQueueStatisticsFromGivenPortOutput>> getQueueStatisticsFromGivenPort(
1499 GetQueueStatisticsFromGivenPortInput arg0) {
1500 //Generate xid to associate it with the request
1501 Long xid = this.getSessionContext().getNextXid();
1503 LOG.info("Prepare queue statistics request to collect stats for " +
1504 "given queue attached to given port {} of node {} - TrasactionId - {}",arg0.getQueueId().toString(),arg0.getNodeConnectorId().toString(),arg0.getNode().getValue(),xid);
1506 // Create multipart request header
1507 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1508 mprInput.setType(MultipartType.OFPMPQUEUE);
1509 mprInput.setVersion(version);
1510 mprInput.setXid(xid);
1511 mprInput.setFlags(new MultipartRequestFlags(false));
1513 // Create multipart request body to fetch stats for all the port of the node
1514 MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1515 MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1516 //Select specific queue
1517 mprQueueBuilder.setQueueId(arg0.getQueueId().getValue());
1518 //Select specific port
1519 mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1521 caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1523 //Set request body to main multipart request
1524 mprInput.setMultipartRequestBody(caseBuilder.build());
1526 //Send the request, no cookies associated, use any connection
1527 LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString());
1528 this.messageService.multipartRequest(mprInput.build(), null);
1530 // Prepare rpc return output. Set xid and send it back.
1531 GetQueueStatisticsFromGivenPortOutputBuilder output = new GetQueueStatisticsFromGivenPortOutputBuilder();
1532 output.setTransactionId(generateTransactionId(xid));
1533 output.setQueueIdAndStatisticsMap(null);
1535 Collection<RpcError> errors = Collections.emptyList();
1536 RpcResult<GetQueueStatisticsFromGivenPortOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1537 return Futures.immediateFuture(rpcResult);
1541 public Future<RpcResult<GetAllFlowStatisticsOutput>> getAllFlowStatistics(GetAllFlowStatisticsInput arg0) {
1542 //TODO: Depricated, need to clean it up. Sal-Compatibility layes is dependent on it.
1543 // Once sal-compatibility layer is fixed this rpc call can be removed from yang file
1548 public Future<RpcResult<GetAllNodeConnectorStatisticsOutput>> getAllNodeConnectorStatistics(
1549 GetAllNodeConnectorStatisticsInput arg0) {
1550 // TODO Auto-generated method stub
1555 public Future<RpcResult<GetFlowStatisticsOutput>> getFlowStatistics(GetFlowStatisticsInput arg0) {
1556 //TODO: Depricated, need to clean it up. Sal-Compatibility layes is dependent on it.
1557 // Once sal-compatibility layer is fixed this rpc call can be removed from yang file
1562 public Future<RpcResult<GetFlowTableStatisticsOutput>> getFlowTableStatistics(GetFlowTableStatisticsInput arg0) {
1563 // TODO Auto-generated method stub
1568 public Future<RpcResult<GetNodeConnectorStatisticsOutput>> getNodeConnectorStatistics(
1569 GetNodeConnectorStatisticsInput arg0) {
1570 // TODO Auto-generated method stub