2 * Copyright (c) 2013 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.openflowplugin.openflow.md.core.sal;
10 import java.math.BigInteger;
11 import java.util.concurrent.Future;
12 import java.util.concurrent.TimeUnit;
14 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
15 import org.opendaylight.openflowplugin.openflow.md.core.session.TransactionKey;
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.FlowAddedBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdatedBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
28 public abstract class OFRpcTaskFactory {
32 * @param maxTimeoutUnit
34 * @return UpdateFlow task
36 public static OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> createAddFlowTask(
37 final long maxTimeout, final TimeUnit maxTimeoutUnit, final OFRpcTaskHelper helper) {
38 OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> task =
39 new OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>>() {
43 helper.rawBarrierSend(maxTimeout, maxTimeoutUnit, getInput().isBarrier(), getCookie(), getResult());
44 if (getResult().isDone()) {
48 // Convert the AddFlowInput to FlowModInput
49 FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(getInput(),
50 getVersion(), getSession().getFeatures().getDatapathId());
51 Long xId = getSession().getNextXid();
52 ofFlowModInput.setXid(xId);
54 if (null != getRpcNotificationProviderService()) {
55 FlowAddedBuilder newFlow = new FlowAddedBuilder(
56 (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) getInput());
57 newFlow.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
58 newFlow.setFlowRef(getInput().getFlowRef());
59 getRpcNotificationProviderService().publish(newFlow.build());
62 getSession().getbulkTransactionCache().put(new TransactionKey(xId), getInput());
63 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib =
64 getMessageService().flowMod(ofFlowModInput.build(), getCookie());
65 OFRpcTaskHelper.chainFutures(resultFromOFLib, getResult());
73 * @param maxTimeoutUnit
75 * @return UpdateFlow task
77 public static OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> createUpdateFlowTask(
78 final long maxTimeout, final TimeUnit maxTimeoutUnit, final OFRpcTaskHelper helper) {
79 OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> task =
80 new OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>>() {
84 helper.rawBarrierSend(maxTimeout, maxTimeoutUnit, getInput().getUpdatedFlow().isBarrier(), getCookie(), getResult());
85 if (getResult().isDone()) {
89 // Convert the AddFlowInput to FlowModInput
90 FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(getInput().getUpdatedFlow(),
91 getVersion(), getSession().getFeatures().getDatapathId());
92 Long xId = getSession().getNextXid();
93 ofFlowModInput.setXid(xId);
95 if (null != getRpcNotificationProviderService()) {
96 FlowUpdatedBuilder updFlow = new FlowUpdatedBuilder(getInput().getUpdatedFlow());
97 updFlow.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
98 updFlow.setFlowRef(getInput().getFlowRef());
99 getRpcNotificationProviderService().publish(updFlow.build());
102 getSession().getbulkTransactionCache().put(new TransactionKey(xId), getInput());
103 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib =
104 getMessageService().flowMod(ofFlowModInput.build(), getCookie());
105 OFRpcTaskHelper.chainFutures(resultFromOFLib, getResult());