1 package org.opendaylight.controller.sal.compatibility.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.compatibility.InventoryMapping;
9 import org.opendaylight.controller.sal.compatibility.NodeMapping;
10 import org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils;
11 import org.opendaylight.controller.sal.core.ConstructionException;
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.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class FlowServiceAdapter implements SalFlowService, IFlowProgrammerListener {
29 private static final Logger LOG = LoggerFactory.getLogger(FlowServiceAdapter.class);
31 private IFlowProgrammerService delegate;
33 private NotificationProviderService publish;
36 public void flowRemoved(org.opendaylight.controller.sal.core.Node node, Flow flow) {
37 FlowRemovedBuilder flowRemovedBuilder = new FlowRemovedBuilder();
38 flowRemovedBuilder.setNode(InventoryMapping.toNodeRef(node));
39 publish.publish(flowRemovedBuilder.build());
43 public void flowErrorReported(org.opendaylight.controller.sal.core.Node node, long rid, Object err) {
44 // TODO Auto-generated method stub
49 public Future<RpcResult<Void>> addFlow(AddFlowInput input) {
51 Flow flow = ToSalConversionsUtils.toFlow(input);
52 @SuppressWarnings("unchecked")
53 org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
54 .getNode().getValue());
55 Status status = delegate.addFlowAsync(node, flow);
56 Void rpcResultType = null;
57 return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
61 public Future<RpcResult<Void>> removeFlow(RemoveFlowInput input) {
63 Flow flow = ToSalConversionsUtils.toFlow(input);
64 @SuppressWarnings("unchecked")
65 org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
66 .getNode().getValue());
67 Status status = delegate.removeFlowAsync(node, flow);
68 Void rpcResultType = null;
69 return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
74 public Future<RpcResult<Void>> updateFlow(UpdateFlowInput input) {
75 @SuppressWarnings("unchecked")
76 org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
77 .getNode().getValue());
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));