1 package org.opendaylight.controller.sal.compability.impl;
3 import java.util.concurrent.ExecutionException;
4 import java.util.concurrent.Future;
6 import org.opendaylight.controller.sal.core.Node;
7 import org.opendaylight.controller.sal.flowprogrammer.Flow;
8 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
9 import org.opendaylight.controller.sal.utils.Status;
10 import org.opendaylight.controller.sal.utils.StatusCode;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
15 import org.opendaylight.yangtools.yang.common.RpcResult;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 import static org.opendaylight.controller.sal.compability.FromSalConversionsUtils.*;
21 public class MdSalFlowServiceAdapter implements IPluginInFlowProgrammerService {
23 private static final Logger LOG = LoggerFactory
24 .getLogger(MdSalFlowServiceAdapter.class);
25 private SalFlowService delegate;
27 public SalFlowService getDelegate() {
31 public void setDelegate(SalFlowService delegate) {
32 this.delegate = delegate;
36 // node isn't used in the method
37 public Status addFlow(Node node, Flow flow) {
38 AddFlowInput input = addFlowInput(node, flow);
39 Future<RpcResult<Void>> future = delegate.addFlow(input);
40 RpcResult<Void> result;
42 result = future.get();
43 return toStatus(result); // how get status from result? conversion?
44 } catch (InterruptedException | ExecutionException e) {
45 LOG.error("Flow Add not processed", e);
46 return new Status(StatusCode.INTERNALERROR);
51 // old Flow - what it the purpose?
52 public Status modifyFlow(Node node, Flow oldFlow, Flow newFlow) {
53 UpdateFlowInput input = updateFlowInput(node,oldFlow,newFlow);
54 Future<RpcResult<Void>> future = delegate.updateFlow(input);
55 RpcResult<Void> result;
57 result = future.get();
58 return toStatus(result);
59 } catch (InterruptedException | ExecutionException e) {
60 LOG.error("Flow Modify not processed", e);
61 return new Status(StatusCode.INTERNALERROR);
66 public Status removeFlow(Node node, Flow flow) {
67 RemoveFlowInput input = removeFlowInput(node,flow);
68 Future<RpcResult<Void>> future = delegate.removeFlow(input);
69 RpcResult<Void> result;
71 result = future.get();
72 return toStatus(result);
73 } catch (InterruptedException | ExecutionException e) {
74 LOG.error("Flow Modify not processed", e);
75 return new Status(StatusCode.INTERNALERROR);
80 public Status addFlowAsync(Node node, Flow flow, long rid) {
81 AddFlowInput input = addFlowInput(node, flow);
82 delegate.addFlow(input);
83 return new Status(StatusCode.SUCCESS);
87 public Status modifyFlowAsync(Node node, Flow oldFlow, Flow newFlow,
89 UpdateFlowInput input = updateFlowInput(node,oldFlow,newFlow);
90 delegate.updateFlow(input);
91 return new Status(StatusCode.SUCCESS);
95 public Status removeFlowAsync(Node node, Flow flow, long rid) {
96 RemoveFlowInput input = removeFlowInput(node,flow);
97 delegate.removeFlow(input);
98 return new Status(StatusCode.SUCCESS);
102 public Status removeAllFlows(Node node) {
103 throw new UnsupportedOperationException("Not present in MD-SAL");
107 public Status syncSendBarrierMessage(Node node) {
113 public Status asyncSendBarrierMessage(Node node) {
114 // TODO Auto-generated method stub
118 private Status toStatus(RpcResult<Void> result) {
119 if(result.isSuccessful()) {
120 return new Status(StatusCode.SUCCESS);
122 return new Status(StatusCode.INTERNALERROR);