2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
3 * Copyright (c) 2024 PANTHEON.tech, s.r.o.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.impl.services.sal;
11 import com.google.common.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.MoreExecutors;
15 import org.opendaylight.openflowplugin.api.openflow.FlowGroupStatus;
16 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
17 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
18 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
19 import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
20 import org.opendaylight.openflowplugin.impl.util.ErrorUtil;
21 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlow;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
28 import org.opendaylight.yangtools.yang.common.RpcResult;
29 import org.opendaylight.yangtools.yang.common.Uint8;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public final class RemoveFlowImpl extends AbstractFlowRpc<RemoveFlowOutput> implements RemoveFlow {
34 private static final Logger LOG = LoggerFactory.getLogger(RemoveFlowImpl.class);
36 public RemoveFlowImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
37 final ConvertorExecutor convertorExecutor) {
38 super(requestContextStack, deviceContext, convertorExecutor, RemoveFlowOutput.class);
42 public ListenableFuture<RpcResult<RemoveFlowOutput>> invoke(final RemoveFlowInput input) {
43 final var future = single.canUseSingleLayerSerialization() ? single.handleServiceCall(input)
44 : multi.processFlowModInputBuilders(multi.toFlowModInputs(input));
46 Futures.addCallback(future, new RemoveFlowCallback(input), MoreExecutors.directExecutor());
50 private final class RemoveFlowCallback implements FutureCallback<RpcResult<RemoveFlowOutput>> {
51 private static final Uint8 OFPTT_ALL = Uint8.MAX_VALUE;
53 private final RemoveFlowInput input;
55 private RemoveFlowCallback(final RemoveFlowInput input) {
60 public void onSuccess(final RpcResult<RemoveFlowOutput> result) {
61 if (result.isSuccessful()) {
62 if (LOG.isDebugEnabled()) {
63 LOG.debug("Flow remove finished without error for flow={}", input);
65 final DeviceFlowRegistry flowRegistry = deviceContext.getDeviceFlowRegistry();
66 if (input.getTableId() != null && !input.getTableId().equals(OFPTT_ALL)) {
68 FlowRegistryKeyFactory.create(deviceContext.getDeviceInfo().getVersion(), input);
69 flowRegistry.addMark(flowRegistryKey);
71 final FlowRef flowRef = input.getFlowRef();
72 if (flowRef != null) {
73 final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class).getId();
74 flowRegistry.appendHistoryFlow(flowId, input.getTableId(), FlowGroupStatus.REMOVED);
77 flowRegistry.clearFlowRegistry();
79 } else if (LOG.isDebugEnabled()) {
80 LOG.debug("Flow remove failed for flow={}, errors={}", input,
81 ErrorUtil.errorsToString(result.getErrors()));
86 public void onFailure(final Throwable throwable) {
87 LOG.warn("Service call for removing flow={} failed", input, throwable);