1 package org.opendaylight.controller.sal.compability.adsal;
3 import java.util.concurrent.Future;
5 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
6 import org.opendaylight.controller.sal.common.util.Futures;
7 import org.opendaylight.controller.sal.common.util.Rpcs;
8 import org.opendaylight.controller.sal.compability.NodeMapping;
9 import org.opendaylight.controller.sal.compability.ToSalConversionsUtils;
10 import org.opendaylight.controller.sal.core.ConstructionException;
11 import org.opendaylight.controller.sal.core.Node;
12 import org.opendaylight.controller.sal.flowprogrammer.Flow;
13 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
14 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
15 import org.opendaylight.controller.sal.utils.Status;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.*;
17 import org.opendaylight.yangtools.yang.common.RpcResult;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class FlowServiceAdapter implements SalFlowService, IFlowProgrammerListener {
23 private static final Logger LOG = LoggerFactory.getLogger(FlowServiceAdapter.class);
25 private IFlowProgrammerService delegate;
27 private NotificationProviderService publish;
30 public void flowRemoved(Node node, Flow flow) {
31 FlowRemovedBuilder flowRemovedBuilder = new FlowRemovedBuilder();
32 flowRemovedBuilder.setNode(NodeMapping.toNodeRef(node));
33 publish.publish(flowRemovedBuilder.build());
37 public void flowErrorReported(Node node, long rid, Object err) {
38 // TODO Auto-generated method stub
43 public Future<RpcResult<Void>> addFlow(AddFlowInput input) {
45 Flow flow = ToSalConversionsUtils.toFlow(input);
46 Node node = NodeMapping.toADNode(input.getNode());
47 Status status = delegate.addFlowAsync(node, flow);
48 Void rpcResultType = null;
49 return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
50 } catch (ConstructionException e) {
51 LOG.error(e.getMessage());
57 public Future<RpcResult<Void>> removeFlow(RemoveFlowInput input) {
59 Flow flow = ToSalConversionsUtils.toFlow(input);
60 Node node = NodeMapping.toADNode(input.getNode());
61 Status status = delegate.removeFlowAsync(node, flow);
62 Void rpcResultType = null;
63 return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
64 } catch (ConstructionException e) {
65 LOG.error(e.getMessage());
71 public Future<RpcResult<Void>> updateFlow(UpdateFlowInput input) {
73 Node node = NodeMapping.toADNode(input.getNode());
74 Flow originalFlow = ToSalConversionsUtils.toFlow(input.getOriginalFlow());
75 Flow updatedFlow = ToSalConversionsUtils.toFlow(input.getUpdatedFlow());
76 Status status = delegate.modifyFlowAsync(node, originalFlow, updatedFlow);
77 Void rpcResultType = null;
78 return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
79 } catch (ConstructionException e) {
80 LOG.error(e.getMessage());