2 * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. 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.extension.vendor.nicira.convertor.match;
10 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
11 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
12 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
13 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
14 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.CtTpDstCaseValue;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.CtTpDstCaseValueBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.tp.dst.grouping.CtTpDstValuesBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketInBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemovedBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchPacketInMessage;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchPacketInMessageBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStatsBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtTpDstKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.tp.dst.grouping.NxmNxCtTpDst;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.tp.dst.grouping.NxmNxCtTpDstBuilder;
35 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 public class CtTpDstConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
40 public MatchEntry convert(final Extension extension) {
41 final var matchGrouping = MatchUtil.CT_TP_DST_RESOLVER.findExtension(extension);
42 if (matchGrouping.isEmpty()) {
43 throw new CodecPreconditionException(extension);
45 return MatchUtil.createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn
46 .opendaylight.openflowjava.nx.match.rev140421.NxmNxCtTpSrc.VALUE,
47 Nxm1Class.VALUE, new CtTpDstCaseValueBuilder()
48 .setCtTpDstValues(new CtTpDstValuesBuilder()
49 .setCtTpDst(matchGrouping.orElseThrow().getNxmNxCtTpDst().getCtTpDst())
56 public ExtensionAugment<? extends Augmentation<Extension>> convert(final MatchEntry input, final MatchPath path) {
57 CtTpDstCaseValue ctTpSrcCaseValue = (CtTpDstCaseValue) input.getMatchEntryValue();
58 NxmNxCtTpDstBuilder ctTpSrcBuilder = new NxmNxCtTpDstBuilder();
59 ctTpSrcBuilder.setCtTpDst(ctTpSrcCaseValue.getCtTpDstValues().getCtTpDst());
60 return resolveAugmentation(ctTpSrcBuilder.build(), path, NxmNxCtTpDstKey.VALUE);
63 private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(final NxmNxCtTpDst value,
64 final MatchPath path, final ExtensionKey key) {
65 return switch (path) {
66 case FLOWS_STATISTICS_UPDATE_MATCH -> new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class,
67 new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxCtTpDst(value).build(), key);
68 case FLOWS_STATISTICS_RPC_MATCH -> new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
69 new NxAugMatchRpcGetFlowStatsBuilder().setNxmNxCtTpDst(value).build(), key);
70 case PACKET_RECEIVED_MATCH -> new ExtensionAugment<>(NxAugMatchNotifPacketIn.class,
71 new NxAugMatchNotifPacketInBuilder().setNxmNxCtTpDst(value).build(), key);
72 case SWITCH_FLOW_REMOVED_MATCH -> new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
73 new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmNxCtTpDst(value).build(), key);
74 case PACKET_IN_MESSAGE_MATCH -> new ExtensionAugment<>(NxAugMatchPacketInMessage.class,
75 new NxAugMatchPacketInMessageBuilder().setNxmNxCtTpDst(value).build(), key);