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.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
19 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
20 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor;
21 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
22 import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService;
23 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutputBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutputBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutputBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutputBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutputBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutputBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutputBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutputBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutputBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Group;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Meter;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
98 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
99 import org.opendaylight.yangtools.yang.common.RpcError;
100 import org.opendaylight.yangtools.yang.common.RpcResult;
101 import org.slf4j.Logger;
103 import com.google.common.util.concurrent.Futures;
106 * RPC implementation of MD-switch
108 public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
110 private static final Logger LOG = org.slf4j.LoggerFactory
111 .getLogger(ModelDrivenSwitchImpl.class);
112 private final NodeId nodeId;
113 private final IMessageDispatchService messageService ;
114 private short version = 0;
116 protected ModelDrivenSwitchImpl(NodeId nodeId,
117 InstanceIdentifier<Node> identifier, SessionContext context) {
118 super(identifier, context);
119 this.nodeId = nodeId;
120 messageService = sessionContext.getMessageDispatchService() ;
121 version = context.getPrimaryConductor().getVersion();
125 public Future<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
126 // Convert the AddFlowInput to FlowModInput
127 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input, version);
129 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
130 // the request can be routed through any connection to the switch
132 SwitchConnectionDistinguisher cookie = null ;
134 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
135 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
137 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
140 rpcResultFromOFLib = resultFromOFLib.get();
141 } catch( Exception ex ) {
142 LOG.error( " Error while getting result for AddFlow RPC" + ex.getMessage());
145 UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult() ;
147 AddFlowOutputBuilder addFlowOutput = new AddFlowOutputBuilder() ;
148 addFlowOutput.setTransactionId(updateFlowOutput.getTransactionId()) ;
149 AddFlowOutput result = addFlowOutput.build();
151 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
152 RpcResult<AddFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
154 LOG.debug("Returning the Add Flow RPC result to MD-SAL");
155 return Futures.immediateFuture(rpcResult);
159 public Future<RpcResult<AddGroupOutput>> addGroup(AddGroupInput input) {
160 // Convert the AddGroupInput to GroupModInput
161 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input, version);
164 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
165 // the request can be routed through any connection to the switch
167 SwitchConnectionDistinguisher cookie = null ;
169 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
170 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
172 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
175 rpcResultFromOFLib = resultFromOFLib.get();
176 } catch( Exception ex ) {
177 LOG.error( " Error while getting result for AddGroup RPC" + ex.getMessage());
180 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult() ;
182 AddGroupOutputBuilder addGroupOutput = new AddGroupOutputBuilder() ;
183 addGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()) ;
184 AddGroupOutput result = addGroupOutput.build();
186 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
187 RpcResult<AddGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
189 LOG.debug("Returning the Add Group RPC result to MD-SAL");
190 return Futures.immediateFuture(rpcResult);
194 public Future<RpcResult<AddMeterOutput>> addMeter(AddMeterInput input) {
195 // Convert the AddMeterInput to MeterModInput
196 MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
199 // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
200 // the request can be routed through any connection to the switch
202 SwitchConnectionDistinguisher cookie = null ;
204 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
205 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ;
207 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null ;
210 rpcResultFromOFLib = resultFromOFLib.get();
211 } catch( Exception ex ) {
212 LOG.error( " Error while getting result for AddMeter RPC" + ex.getMessage());
215 UpdateMeterOutput updateMeterOutput = rpcResultFromOFLib.getResult() ;
217 AddMeterOutputBuilder addMeterOutput = new AddMeterOutputBuilder() ;
218 addMeterOutput.setTransactionId(updateMeterOutput.getTransactionId()) ;
219 AddMeterOutput result = addMeterOutput.build();
221 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
222 RpcResult<AddMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
224 LOG.debug("Returning the Add Meter RPC result to MD-SAL");
225 return Futures.immediateFuture(rpcResult);
229 public Future<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
230 // Convert the RemoveFlowInput to FlowModInput
231 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input, version);
234 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
235 // the request can be routed through any connection to the switch
237 SwitchConnectionDistinguisher cookie = null ;
239 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
240 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
242 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
245 rpcResultFromOFLib = resultFromOFLib.get();
246 } catch( Exception ex ) {
247 LOG.error( " Error while getting result for remove Flow RPC" + ex.getMessage());
250 UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult() ;
252 RemoveFlowOutputBuilder removeFlowOutput = new RemoveFlowOutputBuilder() ;
253 removeFlowOutput.setTransactionId(updateFlowOutput.getTransactionId()) ;
254 RemoveFlowOutput result = removeFlowOutput.build();
256 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
257 RpcResult<RemoveFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
259 LOG.debug("Returning the Remove Flow RPC result to MD-SAL");
260 return Futures.immediateFuture(rpcResult);
264 public Future<RpcResult<RemoveGroupOutput>> removeGroup(
265 RemoveGroupInput input) {
266 // Convert the RemoveGroupInput to GroupModInput
267 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input.getUpdatedGroup(), version);
270 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
271 // the request can be routed through any connection to the switch
273 SwitchConnectionDistinguisher cookie = null ;
275 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
276 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
278 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
281 rpcResultFromOFLib = resultFromOFLib.get();
282 } catch( Exception ex ) {
283 LOG.error( " Error while getting result for RemoveGroup RPC" + ex.getMessage());
286 UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult() ;
288 RemoveGroupOutputBuilder removeGroupOutput = new RemoveGroupOutputBuilder() ;
289 removeGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()) ;
290 RemoveGroupOutput result = removeGroupOutput.build();
292 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
293 RpcResult<RemoveGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
295 LOG.debug("Returning the Remove Group RPC result to MD-SAL");
296 return Futures.immediateFuture(rpcResult);
300 public Future<RpcResult<RemoveMeterOutput>> removeMeter(
301 RemoveMeterInput input) {
302 // Convert the RemoveMeterInput to MeterModInput
303 MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
306 // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
307 // the request can be routed through any connection to the switch
309 SwitchConnectionDistinguisher cookie = null ;
311 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
312 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ;
314 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null ;
317 rpcResultFromOFLib = resultFromOFLib.get();
318 } catch( Exception ex ) {
319 LOG.error( " Error while getting result for RemoveMeter RPC" + ex.getMessage());
322 UpdateMeterOutput updatemeterOutput = rpcResultFromOFLib.getResult() ;
324 RemoveMeterOutputBuilder removeMeterOutput = new RemoveMeterOutputBuilder() ;
325 removeMeterOutput.setTransactionId(updatemeterOutput.getTransactionId()) ;
326 RemoveMeterOutput result = removeMeterOutput.build();
328 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
329 RpcResult<RemoveMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
331 LOG.debug("Returning the Remove Meter RPC result to MD-SAL");
332 return Futures.immediateFuture(rpcResult);
336 public Future<RpcResult<Void>> transmitPacket(TransmitPacketInput input) {
337 // TODO Auto-generated method stub
341 private FlowModInputBuilder toFlowModInputBuilder(Flow source) {
342 FlowModInputBuilder target = new FlowModInputBuilder();
343 target.setCookie(source.getCookie());
344 target.setIdleTimeout(source.getIdleTimeout());
345 target.setHardTimeout(source.getHardTimeout());
346 target.setMatch(toMatch(source.getMatch()));
351 private Match toMatch(
352 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
353 MatchBuilder target = new MatchBuilder();
355 target.setMatchEntries(toMatchEntries(match));
360 private List<MatchEntries> toMatchEntries(
361 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
362 List<MatchEntries> entries = new ArrayList<>();
368 public Future<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
369 // Convert the UpdateFlowInput to FlowModInput
370 FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input.getUpdatedFlow(), version);
372 // Call the RPC method on MessageDispatchService
374 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
375 // the request can be routed through any connection to the switch
377 SwitchConnectionDistinguisher cookie = null ;
379 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
380 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ;
382 RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null ;
385 rpcResultFromOFLib = resultFromOFLib.get();
386 } catch( Exception ex ) {
387 LOG.error( " Error while getting result for UpdateFlow RPC" + ex.getMessage());
390 UpdateFlowOutput updateFlowOutputOFLib = rpcResultFromOFLib.getResult() ;
392 UpdateFlowOutputBuilder updateFlowOutput = new UpdateFlowOutputBuilder() ;
393 updateFlowOutput.setTransactionId(updateFlowOutputOFLib.getTransactionId()) ;
394 UpdateFlowOutput result = updateFlowOutput.build();
396 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
397 RpcResult<UpdateFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
399 LOG.debug("Returning the Update Flow RPC result to MD-SAL");
400 return Futures.immediateFuture(rpcResult);
404 public Future<RpcResult<UpdateGroupOutput>> updateGroup(
405 UpdateGroupInput input) {
406 // Convert the UpdateGroupInput to GroupModInput
407 GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input.getUpdatedGroup(), version);
410 // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so
411 // the request can be routed through any connection to the switch
413 SwitchConnectionDistinguisher cookie = null ;
415 LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
416 Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ;
418 RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null ;
421 rpcResultFromOFLib = resultFromOFLib.get();
422 } catch( Exception ex ) {
423 LOG.error( " Error while getting result for updateGroup RPC" + ex.getMessage());
426 UpdateGroupOutput updateGroupOutputOFLib = rpcResultFromOFLib.getResult() ;
428 UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder() ;
429 updateGroupOutput.setTransactionId(updateGroupOutputOFLib.getTransactionId()) ;
430 UpdateGroupOutput result = updateGroupOutput.build();
432 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
433 RpcResult<UpdateGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
435 LOG.debug("Returning the Update Group RPC result to MD-SAL");
436 return Futures.immediateFuture(rpcResult);
440 public Future<RpcResult<UpdateMeterOutput>> updateMeter(
441 UpdateMeterInput input) {
442 // Convert the UpdateMeterInput to MeterModInput
443 MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input.getUpdatedMeter(), version);
446 // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so
447 // the request can be routed through any connection to the switch
449 SwitchConnectionDistinguisher cookie = null ;
451 LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
452 Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ;
454 RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null ;
457 rpcResultFromOFLib = resultFromOFLib.get();
458 } catch( Exception ex ) {
459 LOG.error( " Error while getting result for UpdateMeter RPC" + ex.getMessage());
462 UpdateMeterOutput updateMeterOutputFromOFLib = rpcResultFromOFLib.getResult() ;
464 UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder() ;
465 updateMeterOutput.setTransactionId(updateMeterOutputFromOFLib.getTransactionId()) ;
466 UpdateMeterOutput result = updateMeterOutput.build();
468 Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
469 RpcResult<UpdateMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
471 LOG.debug("Returning the Update Meter RPC result to MD-SAL");
472 return Futures.immediateFuture(rpcResult);
476 public NodeId getNodeId() {
481 * Methods for requesting statistics from switch
484 public Future<RpcResult<GetAllGroupStatisticsOutput>> getAllGroupStatistics(GetAllGroupStatisticsInput input) {
486 //Generate xid to associate it with the request
487 Long xid = this.getSessionContext().getNextXid();
489 LOG.debug("Prepare statistics request for all the groups - Transaction id - {}",xid);
491 // Create multipart request header
492 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
493 mprInput.setType(MultipartType.OFPMPGROUP);
494 mprInput.setVersion((short)0x04);
495 mprInput.setXid(xid);
496 mprInput.setFlags(new MultipartRequestFlags(false));
498 // Create multipart request body for fetch all the group stats
499 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
500 mprGroupBuild.setGroupId((long) Group.OFPGALL.getIntValue());
502 //Set request body to main multipart request
503 mprInput.setMultipartRequestBody(mprGroupBuild.build());
505 //Send the request, no cookies associated, use any connection
506 LOG.debug("Send group statistics request to the switch :{}",mprGroupBuild);
507 this.messageService.multipartRequest(mprInput.build(), null);
509 // Prepare rpc return output. Set xid and send it back.
510 LOG.debug("Return results and transaction id back to caller");
511 GetAllGroupStatisticsOutputBuilder output = new GetAllGroupStatisticsOutputBuilder();
512 output.setTransactionId(generateTransactionId(xid));
513 output.setGroupStats(null);
515 Collection<RpcError> errors = Collections.emptyList();
516 RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
517 return Futures.immediateFuture(rpcResult);
522 public Future<RpcResult<GetGroupDescriptionOutput>> getGroupDescription(GetGroupDescriptionInput input) {
524 //Generate xid to associate it with the request
525 Long xid = this.getSessionContext().getNextXid();
527 LOG.debug("Prepare group description statistics request - Transaction id - {}",xid);
529 // Create multipart request header
530 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
531 mprInput.setType(MultipartType.OFPMPGROUPDESC);
532 mprInput.setVersion((short)0x04);
533 mprInput.setXid(xid);
534 mprInput.setFlags(new MultipartRequestFlags(false));
536 // Create multipart request body for fetch all the group description stats
537 MultipartRequestGroupDescBuilder mprGroupDescBuild = new MultipartRequestGroupDescBuilder();
539 //Set request body to main multipart request
540 mprInput.setMultipartRequestBody(mprGroupDescBuild.build());
542 //Send the request, no cookies associated, use any connection
543 LOG.debug("Send group desciption statistics request to switch : {}",mprGroupDescBuild);
544 this.messageService.multipartRequest(mprInput.build(), null);
546 // Prepare rpc return output. Set xid and send it back.
547 LOG.debug("Return results and transaction id back to caller");
548 GetGroupDescriptionOutputBuilder output = new GetGroupDescriptionOutputBuilder();
549 output.setTransactionId(generateTransactionId(xid));
550 output.setGroupDescStats(null);
552 Collection<RpcError> errors = Collections.emptyList();
553 RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
554 return Futures.immediateFuture(rpcResult);
559 public Future<RpcResult<GetGroupFeaturesOutput>> getGroupFeatures(GetGroupFeaturesInput input) {
561 //Generate xid to associate it with the request
562 Long xid = this.getSessionContext().getNextXid();
564 LOG.debug("Prepare group features statistics request - Transaction id - {}",xid);
566 // Create multipart request header
567 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
568 mprInput.setType(MultipartType.OFPMPGROUPFEATURES);
569 mprInput.setVersion((short)0x04);
570 mprInput.setXid(xid);
571 mprInput.setFlags(new MultipartRequestFlags(false));
573 // Create multipart request body for fetch all the group description stats
574 MultipartRequestGroupFeaturesBuilder mprGroupFeaturesBuild = new MultipartRequestGroupFeaturesBuilder();
576 //Set request body to main multipart request
577 mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
579 //Send the request, no cookies associated, use any connection
580 LOG.debug("Send group features statistics request :{}",mprGroupFeaturesBuild);
581 this.messageService.multipartRequest(mprInput.build(), null);
583 // Prepare rpc return output. Set xid and send it back.
584 LOG.debug("Return results and transaction id back to caller");
585 GetGroupFeaturesOutputBuilder output = new GetGroupFeaturesOutputBuilder();
586 output.setTransactionId(generateTransactionId(xid));
588 Collection<RpcError> errors = Collections.emptyList();
589 RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
590 return Futures.immediateFuture(rpcResult);
594 public Future<RpcResult<GetGroupStatisticsOutput>> getGroupStatistics(GetGroupStatisticsInput input) {
596 //Generate xid to associate it with the request
597 Long xid = this.getSessionContext().getNextXid();
599 LOG.debug("Prepare statistics request for group ({}) - Transaction id - {}",input.getId().toString(),xid);
601 // Create multipart request header
602 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
603 mprInput.setType(MultipartType.OFPMPGROUP);
604 mprInput.setVersion((short)0x04);
605 mprInput.setXid(xid);
606 mprInput.setFlags(new MultipartRequestFlags(false));
608 // Create multipart request body for fetch all the group stats
609 MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
610 mprGroupBuild.setGroupId(input.getGroupId().getValue());
612 //Set request body to main multipart request
613 mprInput.setMultipartRequestBody(mprGroupBuild.build());
615 //Send the request, no cookies associated, use any connection
616 LOG.debug("Send group statistics request :{}",mprGroupBuild);
617 this.messageService.multipartRequest(mprInput.build(), null);
619 // Prepare rpc return output. Set xid and send it back.
620 LOG.debug("Return results and transaction id back to caller");
621 GetGroupStatisticsOutputBuilder output = new GetGroupStatisticsOutputBuilder();
622 output.setTransactionId(generateTransactionId(xid));
623 output.setGroupStats(null);
625 Collection<RpcError> errors = Collections.emptyList();
626 RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
627 return Futures.immediateFuture(rpcResult);
631 public Future<RpcResult<GetAllMeterConfigStatisticsOutput>> getAllMeterConfigStatistics(
632 GetAllMeterConfigStatisticsInput input) {
634 //Generate xid to associate it with the request
635 Long xid = this.getSessionContext().getNextXid();
637 LOG.debug("Prepare config request for all the meters - Transaction id - {}",xid);
639 // Create multipart request header
640 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
641 mprInput.setType(MultipartType.OFPMPMETERCONFIG);
642 mprInput.setVersion((short)0x04);
643 mprInput.setXid(xid);
644 mprInput.setFlags(new MultipartRequestFlags(false));
646 // Create multipart request body for fetch all the meter stats
647 MultipartRequestMeterConfigBuilder mprMeterConfigBuild = new MultipartRequestMeterConfigBuilder();
648 mprMeterConfigBuild.setMeterId((long) Meter.OFPMALL.getIntValue());
650 //Set request body to main multipart request
651 mprInput.setMultipartRequestBody(mprMeterConfigBuild.build());
653 //Send the request, no cookies associated, use any connection
654 LOG.debug("Send meter statistics request :{}",mprMeterConfigBuild);
655 this.messageService.multipartRequest(mprInput.build(), null);
657 // Prepare rpc return output. Set xid and send it back.
658 LOG.debug("Return results and transaction id back to caller");
659 GetAllMeterConfigStatisticsOutputBuilder output = new GetAllMeterConfigStatisticsOutputBuilder();
660 output.setTransactionId(generateTransactionId(xid));
661 output.setMeterConfigStats(null);
663 Collection<RpcError> errors = Collections.emptyList();
664 RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
665 return Futures.immediateFuture(rpcResult);
669 public Future<RpcResult<GetAllMeterStatisticsOutput>> getAllMeterStatistics(GetAllMeterStatisticsInput input) {
671 //Generate xid to associate it with the request
672 Long xid = this.getSessionContext().getNextXid();
674 LOG.debug("Prepare statistics request for all the meters - Transaction id - {}",xid);
676 // Create multipart request header
677 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
678 mprInput.setType(MultipartType.OFPMPMETER);
679 mprInput.setVersion((short)0x04);
680 mprInput.setXid(xid);
681 mprInput.setFlags(new MultipartRequestFlags(false));
683 // Create multipart request body for fetch all the meter stats
684 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
685 mprMeterBuild.setMeterId((long) Meter.OFPMALL.getIntValue());
687 //Set request body to main multipart request
688 mprInput.setMultipartRequestBody(mprMeterBuild.build());
690 //Send the request, no cookies associated, use any connection
691 LOG.debug("Send meter statistics request :{}",mprMeterBuild);
692 this.messageService.multipartRequest(mprInput.build(), null);
694 // Prepare rpc return output. Set xid and send it back.
695 LOG.debug("Return results and transaction id back to caller");
696 GetAllMeterStatisticsOutputBuilder output = new GetAllMeterStatisticsOutputBuilder();
697 output.setTransactionId(generateTransactionId(xid));
698 output.setMeterStats(null);
700 Collection<RpcError> errors = Collections.emptyList();
701 RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
702 return Futures.immediateFuture(rpcResult);
706 public Future<RpcResult<GetMeterFeaturesOutput>> getMeterFeatures(GetMeterFeaturesInput input) {
708 //Generate xid to associate it with the request
709 Long xid = this.getSessionContext().getNextXid();
711 LOG.debug("Prepare features statistics request for all the meters - Transaction id - {}",xid);
713 // Create multipart request header
714 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
715 mprInput.setType(MultipartType.OFPMPMETERFEATURES);
716 mprInput.setVersion((short)0x04);
717 mprInput.setXid(xid);
718 mprInput.setFlags(new MultipartRequestFlags(false));
720 // Create multipart request body for fetch all the group description stats
721 MultipartRequestMeterFeaturesBuilder mprMeterFeaturesBuild = new MultipartRequestMeterFeaturesBuilder();
723 //Set request body to main multipart request
724 mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
726 //Send the request, no cookies associated, use any connection
727 LOG.debug("Send meter features statistics request :{}",mprMeterFeaturesBuild);
728 this.messageService.multipartRequest(mprInput.build(), null);
730 // Prepare rpc return output. Set xid and send it back.
731 LOG.debug("Return results and transaction id back to caller");
732 GetMeterFeaturesOutputBuilder output = new GetMeterFeaturesOutputBuilder();
733 output.setTransactionId(generateTransactionId(xid));
735 Collection<RpcError> errors = Collections.emptyList();
736 RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
737 return Futures.immediateFuture(rpcResult);
741 public Future<RpcResult<GetMeterStatisticsOutput>> getMeterStatistics(GetMeterStatisticsInput input) {
742 //Generate xid to associate it with the request
743 Long xid = this.getSessionContext().getNextXid();
745 LOG.debug("Preprae statistics request for Meter ({}) - Transaction id - {}",input.getMeterId().getValue(),xid);
747 // Create multipart request header
748 MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
749 mprInput.setType(MultipartType.OFPMPMETER);
750 mprInput.setVersion((short)0x04);
751 mprInput.setXid(xid);
752 mprInput.setFlags(new MultipartRequestFlags(false));
754 // Create multipart request body for fetch all the meter stats
755 MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
756 //Select specific meter
757 mprMeterBuild.setMeterId(input.getMeterId().getValue());
759 //Set request body to main multipart request
760 mprInput.setMultipartRequestBody(mprMeterBuild.build());
762 //Send the request, no cookies associated, use any connection
763 LOG.debug("Send meter statistics request :{}",mprMeterBuild);
764 this.messageService.multipartRequest(mprInput.build(), null);
766 // Prepare rpc return output. Set xid and send it back.
767 LOG.debug("Return results and transaction id back to caller");
768 GetMeterStatisticsOutputBuilder output = new GetMeterStatisticsOutputBuilder();
769 output.setTransactionId(generateTransactionId(xid));
770 output.setMeterStats(null);
772 Collection<RpcError> errors = Collections.emptyList();
773 RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
774 return Futures.immediateFuture(rpcResult);
777 private TransactionId generateTransactionId(Long xid){
778 String stringXid =xid.toString();
779 BigInteger bigIntXid = new BigInteger( stringXid );
780 return new TransactionId(bigIntXid);