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
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.CtStateCaseValue;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.CtStateCaseValueBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.state.grouping.CtStateValuesBuilder;
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.NxmNxCtStateGrouping;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtStateKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.state.grouping.NxmNxCtState;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.state.grouping.NxmNxCtStateBuilder;
38 import org.opendaylight.yangtools.yang.binding.Augmentation;
41 * Convert to/from SAL flow model to openflowjava model for CtStateCase.
43 * @author Aswin Suryanarayanan.
45 public class CtStateConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
48 public ExtensionAugment<? extends Augmentation<Extension>> convert(final MatchEntry input, final MatchPath path) {
49 CtStateCaseValue ctStateCaseValue = (CtStateCaseValue) input.getMatchEntryValue();
50 NxmNxCtStateBuilder ctStateBuilder = new NxmNxCtStateBuilder();
51 ctStateBuilder.setCtState(ctStateCaseValue.getCtStateValues().getCtState());
52 ctStateBuilder.setMask(ctStateCaseValue.getCtStateValues().getMask());
53 return resolveAugmentation(ctStateBuilder.build(), path, NxmNxCtStateKey.VALUE);
57 public MatchEntry convert(final Extension extension) {
58 Optional<NxmNxCtStateGrouping> matchGrouping = MatchUtil.CT_STATE_RESOLVER.findExtension(extension);
59 if (!matchGrouping.isPresent()) {
60 throw new CodecPreconditionException(extension);
62 CtStateCaseValueBuilder ctStateCaseValueBuilder = new CtStateCaseValueBuilder();
63 CtStateValuesBuilder ctStateValuesBuilder = new CtStateValuesBuilder();
64 ctStateValuesBuilder.setCtState(matchGrouping.get().getNxmNxCtState().getCtState());
65 ctStateValuesBuilder.setMask(matchGrouping.get().getNxmNxCtState().getMask());
66 ctStateCaseValueBuilder.setCtStateValues(ctStateValuesBuilder.build());
67 MatchEntryBuilder ofMatch = MatchUtil.createDefaultMatchEntryBuilder(
68 org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxCtState.VALUE,
69 Nxm1Class.VALUE, ctStateCaseValueBuilder.build());
70 ofMatch.setHasMask(true);
71 return ofMatch.build();
74 private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(final NxmNxCtState value,
75 final MatchPath path, final ExtensionKey key) {
77 case FLOWS_STATISTICS_UPDATE_MATCH:
78 return new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class,
79 new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxCtState(value).build(), key);
80 case FLOWS_STATISTICS_RPC_MATCH:
81 return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
82 new NxAugMatchRpcGetFlowStatsBuilder().setNxmNxCtState(value).build(), key);
83 case PACKET_RECEIVED_MATCH:
84 return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder()
85 .setNxmNxCtState(value).build(), key);
86 case SWITCH_FLOW_REMOVED_MATCH:
87 return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
88 new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmNxCtState(value).build(), key);
89 case PACKET_IN_MESSAGE_MATCH:
90 return new ExtensionAugment<>(NxAugMatchPacketInMessage.class,
91 new NxAugMatchPacketInMessageBuilder().setNxmNxCtState(value).build(), key);
93 throw new CodecPreconditionException(path);