2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.compatibility.adsal;
10 import java.math.BigInteger;
12 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
13 import org.opendaylight.controller.sal.compatibility.InventoryMapping;
14 import org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils;
15 import org.opendaylight.controller.sal.flowprogrammer.Flow;
16 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
17 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
18 import org.opendaylight.controller.sal.utils.Status;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.opendaylight.yangtools.yang.common.RpcResult;
34 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 import com.google.common.util.concurrent.Futures;
39 import com.google.common.util.concurrent.ListenableFuture;
41 public class FlowServiceAdapter implements SalFlowService, IFlowProgrammerListener {
43 private static final Logger LOG = LoggerFactory.getLogger(FlowServiceAdapter.class);
45 private IFlowProgrammerService delegate;
47 private NotificationProviderService publish;
50 public void flowRemoved(org.opendaylight.controller.sal.core.Node node, Flow flow) {
51 FlowRemovedBuilder flowRemovedBuilder = new FlowRemovedBuilder();
52 flowRemovedBuilder.setNode(InventoryMapping.toNodeRef(node));
53 publish.publish(flowRemovedBuilder.build());
57 public void flowErrorReported(org.opendaylight.controller.sal.core.Node node, long rid, Object err) {
58 // TODO Auto-generated method stub
63 public ListenableFuture<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
65 Flow flow = ToSalConversionsUtils.toFlow(input, null);
66 @SuppressWarnings("unchecked")
67 org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
68 .getNode().getValue());
69 Status status = delegate.addFlowAsync(node, flow);
70 AddFlowOutputBuilder builder = new AddFlowOutputBuilder();
71 builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
72 AddFlowOutput rpcResultType = builder.build();
73 return Futures.immediateFuture(RpcResultBuilder.<AddFlowOutput>status(status.isSuccess())
74 .withResult(rpcResultType).build());
78 public ListenableFuture<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
80 Flow flow = ToSalConversionsUtils.toFlow(input, null);
81 @SuppressWarnings("unchecked")
82 org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
83 .getNode().getValue());
84 Status status = delegate.removeFlowAsync(node, flow);
85 RemoveFlowOutputBuilder builder = new RemoveFlowOutputBuilder();
86 builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
87 RemoveFlowOutput rpcResultType = builder.build();
88 return Futures.immediateFuture(RpcResultBuilder.<RemoveFlowOutput>status(status.isSuccess())
89 .withResult(rpcResultType).build());
94 public ListenableFuture<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
95 @SuppressWarnings("unchecked")
96 org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
97 .getNode().getValue());
98 Flow originalFlow = ToSalConversionsUtils.toFlow(input.getOriginalFlow(), null);
99 Flow updatedFlow = ToSalConversionsUtils.toFlow(input.getUpdatedFlow(), null);
100 Status status = delegate.modifyFlowAsync(node, originalFlow, updatedFlow);
101 UpdateFlowOutputBuilder builder = new UpdateFlowOutputBuilder();
102 builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
103 UpdateFlowOutput rpcResultType = builder.build();
104 throw new UnsupportedOperationException("Need to translate AD-SAL status to MD-SAL UpdateFlowOuptut - eaw@cisco.com");
105 // return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));