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.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotification
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeExperimenterErrorNotification
18 import org.opendaylight.yangtools.yang.common.RpcResult
19 import org.slf4j.LoggerFactory
21 import static org.opendaylight.controller.sal.compatibility.MDFlowMapping.*
23 import static extension org.opendaylight.controller.sal.compatibility.NodeMapping.*
24 import static extension org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils.*
26 class FlowProgrammerAdapter implements IPluginInFlowProgrammerService, SalFlowListener {
28 private static val LOG = LoggerFactory.getLogger(FlowProgrammerAdapter);
31 private SalFlowService delegate;
34 private IPluginOutFlowProgrammerService flowProgrammerPublisher;
36 override addFlow(Node node, Flow flow) {
37 val input = addFlowInput(node, flow);
38 val future = delegate.addFlow(input);
40 val result = future.get();
41 return toStatus(result); // how get status from result? conversion?
42 } catch (Exception e) {
43 return processException(e);
47 override modifyFlow(Node node, Flow oldFlow, Flow newFlow) {
48 val input = updateFlowInput(node, oldFlow, newFlow);
49 val future = delegate.updateFlow(input);
51 val result = future.get();
52 return toStatus(result);
53 } catch (Exception e) {
54 return processException(e);
58 override removeFlow(Node node, Flow flow) {
59 val input = removeFlowInput(node, flow);
60 val future = delegate.removeFlow(input);
63 val result = future.get();
64 return toStatus(result);
65 } catch (Exception e) {
66 return processException(e);
70 override addFlowAsync(Node node, Flow flow, long rid) {
71 val input = addFlowInput(node, flow);
72 delegate.addFlow(input);
73 return new Status(StatusCode.SUCCESS);
76 override modifyFlowAsync(Node node, Flow oldFlow, Flow newFlow, long rid) {
77 val input = updateFlowInput(node, oldFlow, newFlow);
78 delegate.updateFlow(input);
79 return new Status(StatusCode.SUCCESS);
82 override removeFlowAsync(Node node, Flow flow, long rid) {
83 val input = removeFlowInput(node, flow);
84 delegate.removeFlow(input);
85 return new Status(StatusCode.SUCCESS);
88 override removeAllFlows(Node node) {
89 throw new UnsupportedOperationException("Not present in MD-SAL");
92 override syncSendBarrierMessage(Node node) {
94 // FIXME: Update YANG model
98 override asyncSendBarrierMessage(Node node) {
100 // FIXME: Update YANG model
104 public static def toStatus(RpcResult<?> result) {
105 if (result.isSuccessful()) {
106 return new Status(StatusCode.SUCCESS);
108 return new Status(StatusCode.INTERNALERROR);
112 private static dispatch def Status processException(InterruptedException e) {
113 LOG.error("Interruption occured during processing flow",e);
114 return new Status(StatusCode.INTERNALERROR);
117 private static dispatch def Status processException(ExecutionException e) {
118 LOG.error("Execution exception occured during processing flow",e.cause);
119 return new Status(StatusCode.INTERNALERROR);
122 private static dispatch def Status processException(Exception e) {
123 throw new RuntimeException(e);
126 override onFlowAdded(FlowAdded notification) {
127 // NOOP : Not supported by AD SAL
130 override onFlowRemoved(FlowRemoved notification) {
131 flowProgrammerPublisher.flowRemoved(notification.node.toADNode,notification.toFlow());
134 override onFlowUpdated(FlowUpdated notification) {
135 // NOOP : Not supported by AD SAL
138 override onSwitchFlowRemoved(SwitchFlowRemoved notification) {
139 // NOOP : Not supported by AD SAL
142 override onNodeErrorNotification(NodeErrorNotification notification) {
143 // NOOP : Not supported by AD SAL
146 override onNodeExperimenterErrorNotification(
147 NodeExperimenterErrorNotification notification) {
148 // NOOP : Not supported by AD SAL