2 * Copyright (c) 2015 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.impl.translator;
10 import java.util.Optional;
11 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
12 import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
13 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
14 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.RemovedFlowReason;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved;
21 import org.opendaylight.yangtools.yang.common.Uint8;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Translate {@link FlowRemoved} message to FlowRemoved notification (omit instructions).
28 public class FlowRemovedTranslator implements MessageTranslator
29 <FlowRemoved, org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved> {
30 private final ConvertorExecutor convertorExecutor;
31 private static final Logger LOG = LoggerFactory.getLogger(FlowRemovedTranslator.class);
33 public FlowRemovedTranslator(final ConvertorExecutor convertorExecutor) {
34 this.convertorExecutor = convertorExecutor;
37 protected ConvertorExecutor getConvertorExecutor() {
38 return convertorExecutor;
42 public org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved
43 translate(final FlowRemoved input, final DeviceInfo deviceInfo, final Object connectionDistinguisher) {
44 FlowRemovedBuilder flowRemovedBld = new FlowRemovedBuilder()
45 .setMatch(translateMatch(input, deviceInfo).build())
46 .setCookie(new FlowCookie(input.getCookie()))
47 .setNode(new NodeRef(deviceInfo.getNodeInstanceIdentifier()))
48 .setPriority(input.getPriority())
49 .setTableId(translateTableId(input));
51 if (input.getReason() != null) {
52 flowRemovedBld.setReason(translateReason(input));
55 return flowRemovedBld.build();
58 protected MatchBuilder translateMatch(final FlowRemoved flowRemoved, final DeviceInfo deviceInfo) {
59 final VersionDatapathIdConvertorData datapathIdConvertorData =
60 new VersionDatapathIdConvertorData(deviceInfo.getVersion());
61 datapathIdConvertorData.setDatapathId(deviceInfo.getDatapathId());
63 final Optional<MatchBuilder> matchBuilderOptional = getConvertorExecutor().convert(
64 flowRemoved.getMatch(),
65 datapathIdConvertorData);
67 return matchBuilderOptional.orElse(new MatchBuilder());
71 * Translate the table ID in the FLOW_REMOVED message to SAL table ID.
73 * @param flowRemoved FLOW_REMOVED message.
74 * @return SAL table ID.
76 protected Uint8 translateTableId(final FlowRemoved flowRemoved) {
77 return Uint8.valueOf(flowRemoved.getTableId().getValue());
80 private static RemovedFlowReason translateReason(final FlowRemoved removedFlow) {
81 LOG.debug("--Entering translateReason within FlowRemovedTranslator with reason: {}", removedFlow.getReason());
82 switch (removedFlow.getReason()) {
83 case OFPRRIDLETIMEOUT:
84 return RemovedFlowReason.OFPRRIDLETIMEOUT;
85 case OFPRRHARDTIMEOUT:
86 return RemovedFlowReason.OFPRRHARDTIMEOUT;
88 return RemovedFlowReason.OFPRRDELETE;
89 case OFPRRGROUPDELETE:
90 return RemovedFlowReason.OFPRRGROUPDELETE;
92 LOG.debug("The flow is being deleted for some unknown reason ");
93 return RemovedFlowReason.OFPRRDELETE;