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.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdatedBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
22 import org.opendaylight.yangtools.yang.common.RpcResult;
27 public abstract class OFRpcTaskFactory {
31 * @param maxTimeoutUnit
33 * @return UpdateFlow task
35 public static OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> createAddFlowTask(
36 final long maxTimeout, final TimeUnit maxTimeoutUnit, final OFRpcTaskHelper helper) {
37 OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> task =
38 new OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>>() {
42 helper.rawBarrierSend(maxTimeout, maxTimeoutUnit, getInput().isBarrier(), getCookie(), getResult());
43 if (getResult().isDone()) {
47 // Convert the AddFlowInput to FlowModInput
48 FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(getInput(),
49 getVersion(), getSession().getFeatures().getDatapathId());
50 Long xId = getSession().getNextXid();
51 ofFlowModInput.setXid(xId);
53 if (null != getRpcNotificationProviderService()) {
54 FlowAddedBuilder newFlow = new FlowAddedBuilder(
55 (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) getInput());
56 newFlow.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
57 newFlow.setFlowRef(getInput().getFlowRef());
58 getRpcNotificationProviderService().publish(newFlow.build());
61 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib =
62 getMessageService().flowMod(ofFlowModInput.build(), getCookie());
63 OFRpcTaskHelper.chainFutures(resultFromOFLib, getResult());
71 * @param maxTimeoutUnit
73 * @return UpdateFlow task
75 public static OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> createUpdateFlowTask(
76 final long maxTimeout, final TimeUnit maxTimeoutUnit, final OFRpcTaskHelper helper) {
77 OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> task =
78 new OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>>() {
82 helper.rawBarrierSend(maxTimeout, maxTimeoutUnit, getInput().getUpdatedFlow().isBarrier(), getCookie(), getResult());
83 if (getResult().isDone()) {
87 // Convert the AddFlowInput to FlowModInput
88 FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(getInput().getUpdatedFlow(),
89 getVersion(), getSession().getFeatures().getDatapathId());
90 Long xId = getSession().getNextXid();
91 ofFlowModInput.setXid(xId);
93 if (null != getRpcNotificationProviderService()) {
94 FlowUpdatedBuilder updFlow = new FlowUpdatedBuilder(getInput().getUpdatedFlow());
95 updFlow.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
96 updFlow.setFlowRef(getInput().getFlowRef());
97 getRpcNotificationProviderService().publish(updFlow.build());
100 Future<RpcResult<UpdateFlowOutput>> resultFromOFLib =
101 getMessageService().flowMod(ofFlowModInput.build(), getCookie());
102 OFRpcTaskHelper.chainFutures(resultFromOFLib, getResult());