1 package org.opendaylight.controller.sal.compatibility
3 import java.util.concurrent.ExecutionException
4 import org.opendaylight.controller.sal.core.Node
5 import org.opendaylight.controller.sal.flowprogrammer.Flow
6 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService
7 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService
8 import org.opendaylight.controller.sal.utils.Status
9 import org.opendaylight.controller.sal.utils.StatusCode
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowListener
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService
16 import org.opendaylight.yangtools.yang.common.RpcResult
17 import org.slf4j.LoggerFactory
19 import static org.opendaylight.controller.sal.compatibility.MDFlowMapping.*
21 import static extension org.opendaylight.controller.sal.compatibility.NodeMapping.*
22 import static extension org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils.*
24 class FlowProgrammerAdapter implements IPluginInFlowProgrammerService, SalFlowListener {
26 private static val LOG = LoggerFactory.getLogger(FlowProgrammerAdapter);
29 private SalFlowService delegate;
32 private IPluginOutFlowProgrammerService flowProgrammerPublisher;
34 override addFlow(Node node, Flow flow) {
35 val input = addFlowInput(node, flow);
36 val future = delegate.addFlow(input);
38 val result = future.get();
39 return toStatus(result); // how get status from result? conversion?
40 } catch (Exception e) {
41 return processException(e);
45 override modifyFlow(Node node, Flow oldFlow, Flow newFlow) {
46 val input = updateFlowInput(node, oldFlow, newFlow);
47 val future = delegate.updateFlow(input);
49 val result = future.get();
50 return toStatus(result);
51 } catch (Exception e) {
52 return processException(e);
56 override removeFlow(Node node, Flow flow) {
57 val input = removeFlowInput(node, flow);
58 val future = delegate.removeFlow(input);
61 val result = future.get();
62 return toStatus(result);
63 } catch (Exception e) {
64 return processException(e);
68 override addFlowAsync(Node node, Flow flow, long rid) {
69 val input = addFlowInput(node, flow);
70 delegate.addFlow(input);
71 return new Status(StatusCode.SUCCESS);
74 override modifyFlowAsync(Node node, Flow oldFlow, Flow newFlow, long rid) {
75 val input = updateFlowInput(node, oldFlow, newFlow);
76 delegate.updateFlow(input);
77 return new Status(StatusCode.SUCCESS);
80 override removeFlowAsync(Node node, Flow flow, long rid) {
81 val input = removeFlowInput(node, flow);
82 delegate.removeFlow(input);
83 return new Status(StatusCode.SUCCESS);
86 override removeAllFlows(Node node) {
87 throw new UnsupportedOperationException("Not present in MD-SAL");
90 override syncSendBarrierMessage(Node node) {
92 // FIXME: Update YANG model
96 override asyncSendBarrierMessage(Node node) {
98 // FIXME: Update YANG model
102 public static def toStatus(RpcResult<?> result) {
103 if (result.isSuccessful()) {
104 return new Status(StatusCode.SUCCESS);
106 return new Status(StatusCode.INTERNALERROR);
110 private static dispatch def Status processException(InterruptedException e) {
111 LOG.error("Interruption occured during processing flow",e);
112 return new Status(StatusCode.INTERNALERROR);
115 private static dispatch def Status processException(ExecutionException e) {
116 LOG.error("Execution exception occured during processing flow",e.cause);
117 return new Status(StatusCode.INTERNALERROR);
120 private static dispatch def Status processException(Exception e) {
121 throw new RuntimeException(e);
124 override onFlowAdded(FlowAdded notification) {
125 // NOOP : Not supported by AD SAL
128 override onFlowRemoved(FlowRemoved notification) {
129 flowProgrammerPublisher.flowRemoved(notification.node.toADNode,notification.toFlow());
132 override onFlowUpdated(FlowUpdated notification) {
133 // NOOP : Not supported by AD SAL
136 override onSwitchFlowRemoved(SwitchFlowRemoved notification) {
137 // NOOP : Not supported by AD SAL