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.NxmNxCtZoneGrouping;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtZoneKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.zone.grouping.NxmNxCtZone;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.zone.grouping.NxmNxCtZoneBuilder;
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.zone.grouping.CtZoneValuesBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValue;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValueBuilder;
42 * @author Aswin Suryanarayanan.
45 public class CtZoneConvertor 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 CtZoneCaseValue ctZoneCaseValue = ((CtZoneCaseValue) input.getMatchEntryValue());
58 NxmNxCtZoneBuilder ctZoneBuilder = new NxmNxCtZoneBuilder();
59 ctZoneBuilder.setCtZone(ctZoneCaseValue.getCtZoneValues().getCtZone());
60 return resolveAugmentation(ctZoneBuilder.build(), path,
61 NxmNxCtZoneKey.class);
68 * org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava#convert
70 * .opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general
71 * .rev140714.general.extension.grouping.Extension)
74 public MatchEntry convert(Extension extension) {
75 Optional<NxmNxCtZoneGrouping> matchGrouping = MatchUtil.ctZoneResolver.getExtension(extension);
76 if (!matchGrouping.isPresent()) {
77 throw new CodecPreconditionException(extension);
79 CtZoneCaseValueBuilder ctZoneCaseValueBuilder = new CtZoneCaseValueBuilder();
80 CtZoneValuesBuilder ctZoneValuesBuilder = new CtZoneValuesBuilder();
81 ctZoneValuesBuilder.setCtZone(matchGrouping.get().getNxmNxCtZone().getCtZone());
82 ctZoneCaseValueBuilder.setCtZoneValues(ctZoneValuesBuilder.build());
83 MatchEntryBuilder ofMatch = MatchUtil
84 .createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn
85 .opendaylight.openflowjava.nx.match.rev140421.NxmNxCtZone.class,
86 Nxm1Class.class, ctZoneCaseValueBuilder.build());
87 return ofMatch.build();
90 private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(NxmNxCtZone value,
91 MatchPath path, Class<? extends ExtensionKey> key) {
93 case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH:
94 return new ExtensionAugment<>(NxAugMatchNotifUpdateFlowStats.class,
95 new NxAugMatchNotifUpdateFlowStatsBuilder().setNxmNxCtZone(value).build(), key);
96 case RPCFLOWSSTATISTICS_FLOWANDSTATISTICSMAPLIST_MATCH:
97 return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
98 new NxAugMatchRpcGetFlowStatsBuilder().setNxmNxCtZone(value).build(), key);
99 case PACKETRECEIVED_MATCH:
100 return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder()
101 .setNxmNxCtZone(value).build(), key);
102 case SWITCHFLOWREMOVED_MATCH:
103 return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
104 new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmNxCtZone(value).build(), key);
106 throw new CodecPreconditionException(path);