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.CtTpSrcCaseValue;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.CtTpSrcCaseValueBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.tp.src.grouping.CtTpSrcValuesBuilder;
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.NxmNxCtTpSrcGrouping;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtTpSrcKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.tp.src.grouping.NxmNxCtTpSrc;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.tp.src.grouping.NxmNxCtTpSrcBuilder;
38 import org.opendaylight.yangtools.yang.binding.Augmentation;
40 public class CtTpSrcConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
43 public MatchEntry convert(final Extension extension) {
44 Optional<NxmNxCtTpSrcGrouping> matchGrouping = MatchUtil.CT_TP_SRC_RESOLVER.findExtension(extension);
45 if (!matchGrouping.isPresent()) {
46 throw new CodecPreconditionException(extension);
48 CtTpSrcCaseValueBuilder ctTpSrcCaseValueBuilder = new CtTpSrcCaseValueBuilder();
49 CtTpSrcValuesBuilder ctTpSrcValuesBuilder = new CtTpSrcValuesBuilder();
50 ctTpSrcValuesBuilder.setCtTpSrc(matchGrouping.get().getNxmNxCtTpSrc().getCtTpSrc());
51 ctTpSrcCaseValueBuilder.setCtTpSrcValues(ctTpSrcValuesBuilder.build());
52 MatchEntryBuilder ofMatch = MatchUtil
53 .createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn
54 .opendaylight.openflowjava.nx.match.rev140421.NxmNxCtTpSrc.VALUE,
55 Nxm1Class.VALUE, ctTpSrcCaseValueBuilder.build());
56 return ofMatch.build();
60 public ExtensionAugment<? extends Augmentation<Extension>> convert(final MatchEntry input, final MatchPath path) {
61 CtTpSrcCaseValue ctTpSrcCaseValue = (CtTpSrcCaseValue) input.getMatchEntryValue();
62 NxmNxCtTpSrcBuilder ctTpSrcBuilder = new NxmNxCtTpSrcBuilder();
63 ctTpSrcBuilder.setCtTpSrc(ctTpSrcCaseValue.getCtTpSrcValues().getCtTpSrc());
64 return resolveAugmentation(ctTpSrcBuilder.build(), path, NxmNxCtTpSrcKey.VALUE);
67 private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(final NxmNxCtTpSrc value,
68 final MatchPath path, final ExtensionKey key) {
70 case FLOWS_STATISTICS_UPDATE_MATCH:
71 return new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class,
72 new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxCtTpSrc(value).build(), key);
73 case FLOWS_STATISTICS_RPC_MATCH:
74 return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
75 new NxAugMatchRpcGetFlowStatsBuilder().setNxmNxCtTpSrc(value).build(), key);
76 case PACKET_RECEIVED_MATCH:
77 return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder()
78 .setNxmNxCtTpSrc(value).build(), key);
79 case SWITCH_FLOW_REMOVED_MATCH:
80 return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
81 new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmNxCtTpSrc(value).build(), key);
82 case PACKET_IN_MESSAGE_MATCH:
83 return new ExtensionAugment<>(NxAugMatchPacketInMessage.class,
84 new NxAugMatchPacketInMessageBuilder().setNxmNxCtTpSrc(value).build(), key);
86 throw new CodecPreconditionException(path);