2 * Copyright (c) 2015 Hewlett-Packard Enterprise 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;
13 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
14 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
15 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
16 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
17 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketInBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemovedBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStatsBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtStateGrouping;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtStateKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.state.grouping.NxmNxCtState;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.state.grouping.NxmNxCtStateBuilder;
35 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.state.grouping.CtStateValuesBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtStateCaseValue;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtStateCaseValueBuilder;
42 * @author Aswin Suryanarayanan.
45 public class CtStateConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
51 * org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava#convert
52 * (org.opendaylight.yangtools.yang.binding.DataContainer,
53 * org.opendaylight.openflowplugin.extension.api.path.AugmentationPath)
56 public ExtensionAugment<? extends Augmentation<Extension>> convert(MatchEntry input, MatchPath path) {
57 CtStateCaseValue ctStateCaseValue = ((CtStateCaseValue) input.getMatchEntryValue());
58 NxmNxCtStateBuilder ctStateBuilder = new NxmNxCtStateBuilder();
59 ctStateBuilder.setCtState(ctStateCaseValue.getCtStateValues().getCtState());
60 ctStateBuilder.setMask(ctStateCaseValue.getCtStateValues().getMask());
61 return resolveAugmentation(ctStateBuilder.build(), path,
62 NxmNxCtStateKey.class);
69 * org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava#convert
71 * .opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general
72 * .rev140714.general.extension.grouping.Extension)
75 public MatchEntry convert(Extension extension) {
76 Optional<NxmNxCtStateGrouping> matchGrouping = MatchUtil.ctStateResolver.getExtension(extension);
77 if (!matchGrouping.isPresent()) {
78 throw new CodecPreconditionException(extension);
80 CtStateCaseValueBuilder ctStateCaseValueBuilder = new CtStateCaseValueBuilder();
81 CtStateValuesBuilder ctStateValuesBuilder = new CtStateValuesBuilder();
82 ctStateValuesBuilder.setCtState(matchGrouping.get().getNxmNxCtState().getCtState());
83 ctStateValuesBuilder.setMask(matchGrouping.get().getNxmNxCtState().getMask());
84 ctStateCaseValueBuilder.setCtStateValues(ctStateValuesBuilder.build());
85 MatchEntryBuilder ofMatch = MatchUtil
86 .createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn
87 .opendaylight.openflowjava.nx.match.rev140421.NxmNxCtState.class,
88 Nxm1Class.class, ctStateCaseValueBuilder.build());
89 ofMatch.setHasMask(true);
90 return ofMatch.build();
93 private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(NxmNxCtState value,
94 MatchPath path, Class<? extends ExtensionKey> key) {
96 case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH:
97 return new ExtensionAugment<>(NxAugMatchNotifUpdateFlowStats.class,
98 new NxAugMatchNotifUpdateFlowStatsBuilder().setNxmNxCtState(value).build(), key);
99 case RPCFLOWSSTATISTICS_FLOWANDSTATISTICSMAPLIST_MATCH:
100 return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
101 new NxAugMatchRpcGetFlowStatsBuilder().setNxmNxCtState(value).build(), key);
102 case PACKETRECEIVED_MATCH:
103 return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder()
104 .setNxmNxCtState(value).build(), key);
105 case SWITCHFLOWREMOVED_MATCH:
106 return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
107 new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmNxCtState(value).build(), key);
109 throw new CodecPreconditionException(path);