1 package org.opendaylight.controller.sal.compability
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.FlowUpdated
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowListener
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService
15 import org.opendaylight.yangtools.yang.common.RpcResult
16 import org.slf4j.LoggerFactory
18 import static org.opendaylight.controller.sal.compability.MDFlowMapping.*
20 import static extension org.opendaylight.controller.sal.compability.NodeMapping.*
21 import static extension org.opendaylight.controller.sal.compability.ToSalConversionsUtils.*
23 class FlowProgrammerAdapter implements IPluginInFlowProgrammerService, SalFlowListener {
25 private static val LOG = LoggerFactory.getLogger(FlowProgrammerAdapter);
28 private SalFlowService delegate;
31 private IPluginOutFlowProgrammerService flowProgrammerPublisher;
33 override addFlow(Node node, Flow flow) {
34 val input = addFlowInput(node, flow);
35 val future = delegate.addFlow(input);
37 val result = future.get();
38 return toStatus(result); // how get status from result? conversion?
39 } catch (Exception e) {
40 return processException(e);
44 override modifyFlow(Node node, Flow oldFlow, Flow newFlow) {
45 val input = updateFlowInput(node, oldFlow, newFlow);
46 val future = delegate.updateFlow(input);
48 val result = future.get();
49 return toStatus(result);
50 } catch (Exception e) {
51 return processException(e);
55 override removeFlow(Node node, Flow flow) {
56 val input = removeFlowInput(node, flow);
57 val future = delegate.removeFlow(input);
60 val result = future.get();
61 return toStatus(result);
62 } catch (Exception e) {
63 return processException(e);
67 override addFlowAsync(Node node, Flow flow, long rid) {
68 val input = addFlowInput(node, flow);
69 delegate.addFlow(input);
70 return new Status(StatusCode.SUCCESS);
73 override modifyFlowAsync(Node node, Flow oldFlow, Flow newFlow, long rid) {
74 val input = updateFlowInput(node, oldFlow, newFlow);
75 delegate.updateFlow(input);
76 return new Status(StatusCode.SUCCESS);
79 override removeFlowAsync(Node node, Flow flow, long rid) {
80 val input = removeFlowInput(node, flow);
81 delegate.removeFlow(input);
82 return new Status(StatusCode.SUCCESS);
85 override removeAllFlows(Node node) {
86 throw new UnsupportedOperationException("Not present in MD-SAL");
89 override syncSendBarrierMessage(Node node) {
91 // FIXME: Update YANG model
95 override asyncSendBarrierMessage(Node node) {
97 // FIXME: Update YANG model
101 public static def toStatus(RpcResult<Void> result) {
102 if (result.isSuccessful()) {
103 return new Status(StatusCode.SUCCESS);
105 return new Status(StatusCode.INTERNALERROR);
109 private static dispatch def Status processException(InterruptedException e) {
110 LOG.error("Interruption occured during processing flow",e);
111 return new Status(StatusCode.INTERNALERROR);
114 private static dispatch def Status processException(ExecutionException e) {
115 LOG.error("Execution exception occured during processing flow",e.cause);
116 return new Status(StatusCode.INTERNALERROR);
119 private static dispatch def Status processException(Exception e) {
120 throw new RuntimeException(e);
123 override onFlowAdded(FlowAdded notification) {
124 // NOOP : Not supported by AD SAL
127 override onFlowRemoved(FlowRemoved notification) {
128 flowProgrammerPublisher.flowRemoved(notification.node.toADNode,notification.toFlow());
131 override onFlowUpdated(FlowUpdated notification) {
132 // NOOP : Not supported by AD SAL