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;
11 import java.util.concurrent.Future;
13 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
14 import org.opendaylight.controller.sal.common.util.Futures;
15 import org.opendaylight.controller.sal.common.util.Rpcs;
16 import org.opendaylight.controller.sal.compatibility.InventoryMapping;
17 import org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils;
18 import org.opendaylight.controller.sal.flowprogrammer.Flow;
19 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
20 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
21 import org.opendaylight.controller.sal.utils.Status;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36 import org.opendaylight.yangtools.yang.common.RpcResult;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 public class FlowServiceAdapter implements SalFlowService, IFlowProgrammerListener {
42 private static final Logger LOG = LoggerFactory.getLogger(FlowServiceAdapter.class);
44 private IFlowProgrammerService delegate;
46 private NotificationProviderService publish;
49 public void flowRemoved(org.opendaylight.controller.sal.core.Node node, Flow flow) {
50 FlowRemovedBuilder flowRemovedBuilder = new FlowRemovedBuilder();
51 flowRemovedBuilder.setNode(InventoryMapping.toNodeRef(node));
52 publish.publish(flowRemovedBuilder.build());
56 public void flowErrorReported(org.opendaylight.controller.sal.core.Node node, long rid, Object err) {
57 // TODO Auto-generated method stub
62 public Future<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
64 Flow flow = ToSalConversionsUtils.toFlow(input, null);
65 @SuppressWarnings("unchecked")
66 org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
67 .getNode().getValue());
68 Status status = delegate.addFlowAsync(node, flow);
69 AddFlowOutputBuilder builder = new AddFlowOutputBuilder();
70 builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
71 AddFlowOutput rpcResultType = builder.build();
72 return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
76 public Future<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
78 Flow flow = ToSalConversionsUtils.toFlow(input, null);
79 @SuppressWarnings("unchecked")
80 org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
81 .getNode().getValue());
82 Status status = delegate.removeFlowAsync(node, flow);
83 RemoveFlowOutputBuilder builder = new RemoveFlowOutputBuilder();
84 builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
85 RemoveFlowOutput rpcResultType = builder.build();
86 return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
91 public Future<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
92 @SuppressWarnings("unchecked")
93 org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
94 .getNode().getValue());
95 Flow originalFlow = ToSalConversionsUtils.toFlow(input.getOriginalFlow(), null);
96 Flow updatedFlow = ToSalConversionsUtils.toFlow(input.getUpdatedFlow(), null);
97 Status status = delegate.modifyFlowAsync(node, originalFlow, updatedFlow);
98 UpdateFlowOutputBuilder builder = new UpdateFlowOutputBuilder();
99 builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
100 UpdateFlowOutput rpcResultType = builder.build();
101 throw new UnsupportedOperationException("Need to translate AD-SAL status to MD-SAL UpdateFlowOuptut - eaw@cisco.com");
102 // return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));