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.AddFlowInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class FlowServiceAdapter implements SalFlowService, IFlowProgrammerListener {
27 private static final Logger LOG = LoggerFactory.getLogger(FlowServiceAdapter.class);
29 private IFlowProgrammerService delegate;
31 private NotificationProviderService publish;
34 public void flowRemoved(Node node, Flow flow) {
35 FlowRemovedBuilder flowRemovedBuilder = new FlowRemovedBuilder();
36 flowRemovedBuilder.setNode(NodeMapping.toNodeRef(node));
37 publish.publish(flowRemovedBuilder.build());
41 public void flowErrorReported(Node node, long rid, Object err) {
42 // TODO Auto-generated method stub
47 public Future<RpcResult<Void>> addFlow(AddFlowInput input) {
49 Flow flow = ToSalConversionsUtils.toFlow(input);
50 Node node = NodeMapping.toADNode(input.getNode());
51 Status status = delegate.addFlowAsync(node, flow);
52 Void rpcResultType = null;
53 return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
54 } catch (ConstructionException e) {
55 LOG.error(e.getMessage());
61 public Future<RpcResult<Void>> removeFlow(RemoveFlowInput input) {
63 Flow flow = ToSalConversionsUtils.toFlow(input);
64 Node node = NodeMapping.toADNode(input.getNode());
65 Status status = delegate.removeFlowAsync(node, flow);
66 Void rpcResultType = null;
67 return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
68 } catch (ConstructionException e) {
69 LOG.error(e.getMessage());
75 public Future<RpcResult<Void>> updateFlow(UpdateFlowInput input) {
77 Node node = NodeMapping.toADNode(input.getNode());
78 Flow originalFlow = ToSalConversionsUtils.toFlow(input.getOriginalFlow());
79 Flow updatedFlow = ToSalConversionsUtils.toFlow(input.getUpdatedFlow());
80 Status status = delegate.modifyFlowAsync(node, originalFlow, updatedFlow);
81 Void rpcResultType = null;
82 return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
83 } catch (ConstructionException e) {
84 LOG.error(e.getMessage());