1 package org.opendaylight.controller.sal.compatibility.adsal;
3 import java.math.BigInteger;
4 import java.util.concurrent.Future;
6 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
7 import org.opendaylight.controller.sal.common.util.Futures;
8 import org.opendaylight.controller.sal.common.util.Rpcs;
9 import org.opendaylight.controller.sal.compatibility.InventoryMapping;
10 import org.opendaylight.controller.sal.compatibility.NodeMapping;
11 import org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils;
12 import org.opendaylight.controller.sal.core.ConstructionException;
13 import org.opendaylight.controller.sal.flowprogrammer.Flow;
14 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
15 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
16 import org.opendaylight.controller.sal.utils.Status;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class FlowServiceAdapter implements SalFlowService, IFlowProgrammerListener {
37 private static final Logger LOG = LoggerFactory.getLogger(FlowServiceAdapter.class);
39 private IFlowProgrammerService delegate;
41 private NotificationProviderService publish;
44 public void flowRemoved(org.opendaylight.controller.sal.core.Node node, Flow flow) {
45 FlowRemovedBuilder flowRemovedBuilder = new FlowRemovedBuilder();
46 flowRemovedBuilder.setNode(InventoryMapping.toNodeRef(node));
47 publish.publish(flowRemovedBuilder.build());
51 public void flowErrorReported(org.opendaylight.controller.sal.core.Node node, long rid, Object err) {
52 // TODO Auto-generated method stub
57 public Future<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
59 Flow flow = ToSalConversionsUtils.toFlow(input);
60 @SuppressWarnings("unchecked")
61 org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
62 .getNode().getValue());
63 Status status = delegate.addFlowAsync(node, flow);
64 AddFlowOutputBuilder builder = new AddFlowOutputBuilder();
65 builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
66 AddFlowOutput rpcResultType = builder.build();
67 return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
71 public Future<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
73 Flow flow = ToSalConversionsUtils.toFlow(input);
74 @SuppressWarnings("unchecked")
75 org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
76 .getNode().getValue());
77 Status status = delegate.removeFlowAsync(node, flow);
78 RemoveFlowOutputBuilder builder = new RemoveFlowOutputBuilder();
79 builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
80 RemoveFlowOutput rpcResultType = builder.build();
81 return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
86 public Future<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
87 @SuppressWarnings("unchecked")
88 org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
89 .getNode().getValue());
90 Flow originalFlow = ToSalConversionsUtils.toFlow(input.getOriginalFlow());
91 Flow updatedFlow = ToSalConversionsUtils.toFlow(input.getUpdatedFlow());
92 Status status = delegate.modifyFlowAsync(node, originalFlow, updatedFlow);
93 UpdateFlowOutputBuilder builder = new UpdateFlowOutputBuilder();
94 builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
95 UpdateFlowOutput rpcResultType = builder.build();
96 throw new UnsupportedOperationException("Need to translate AD-SAL status to MD-SAL UpdateFlowOuptut - eaw@cisco.com");
97 // return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));