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 java.util.Optional;
11 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
12 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
13 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
14 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
15 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.CtTpDstCaseValue;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.CtTpDstCaseValueBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.tp.dst.grouping.CtTpDstValuesBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketInBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemovedBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchPacketInMessage;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchPacketInMessageBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStatsBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtTpDstGrouping;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtTpDstKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.tp.dst.grouping.NxmNxCtTpDst;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.tp.dst.grouping.NxmNxCtTpDstBuilder;
38 import org.opendaylight.yangtools.yang.binding.Augmentation;
40 public class CtTpDstConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
43 public MatchEntry convert(final Extension extension) {
44 Optional<NxmNxCtTpDstGrouping> matchGrouping = MatchUtil.CT_TP_DST_RESOLVER.findExtension(extension);
45 if (!matchGrouping.isPresent()) {
46 throw new CodecPreconditionException(extension);
48 CtTpDstCaseValueBuilder ctTpDstCaseValueBuilder = new CtTpDstCaseValueBuilder();
49 CtTpDstValuesBuilder ctTpDstValuesBuilder = new CtTpDstValuesBuilder();
50 ctTpDstValuesBuilder.setCtTpDst(matchGrouping.get().getNxmNxCtTpDst().getCtTpDst());
51 ctTpDstCaseValueBuilder.setCtTpDstValues(ctTpDstValuesBuilder.build());
52 MatchEntryBuilder ofMatch = MatchUtil
53 .createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn
54 .opendaylight.openflowjava.nx.match.rev140421.NxmNxCtTpSrc.class,
55 Nxm1Class.class, ctTpDstCaseValueBuilder.build());
56 return ofMatch.build();
60 public ExtensionAugment<? extends Augmentation<Extension>> convert(final MatchEntry input, final MatchPath path) {
61 CtTpDstCaseValue ctTpSrcCaseValue = (CtTpDstCaseValue) input.getMatchEntryValue();
62 NxmNxCtTpDstBuilder ctTpSrcBuilder = new NxmNxCtTpDstBuilder();
63 ctTpSrcBuilder.setCtTpDst(ctTpSrcCaseValue.getCtTpDstValues().getCtTpDst());
64 return resolveAugmentation(ctTpSrcBuilder.build(), path,
65 NxmNxCtTpDstKey.class);
68 private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(final NxmNxCtTpDst value,
69 final MatchPath path, final Class<? extends ExtensionKey> key) {
71 case FLOWS_STATISTICS_UPDATE_MATCH:
72 return new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class,
73 new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxCtTpDst(value).build(), key);
74 case FLOWS_STATISTICS_RPC_MATCH:
75 return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
76 new NxAugMatchRpcGetFlowStatsBuilder().setNxmNxCtTpDst(value).build(), key);
77 case PACKET_RECEIVED_MATCH:
78 return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder()
79 .setNxmNxCtTpDst(value).build(), key);
80 case SWITCH_FLOW_REMOVED_MATCH:
81 return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
82 new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmNxCtTpDst(value).build(), key);
83 case PACKET_IN_MESSAGE_MATCH:
84 return new ExtensionAugment<>(NxAugMatchPacketInMessage.class,
85 new NxAugMatchPacketInMessageBuilder().setNxmNxCtTpDst(value).build(), key);
87 throw new CodecPreconditionException(path);