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