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;
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.zone.grouping.CtZoneValuesBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValue;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValueBuilder;
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.NxmNxCtZoneGrouping;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtZoneKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.zone.grouping.NxmNxCtZone;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.zone.grouping.NxmNxCtZoneBuilder;
39 import org.opendaylight.yangtools.yang.binding.Augmentation;
42 * Convert to/from SAL flow model to openflowjava model for CtZoneCase.
44 * @author Aswin Suryanarayanan.
46 public class CtZoneConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
49 public ExtensionAugment<? extends Augmentation<Extension>> convert(MatchEntry input, MatchPath path) {
50 CtZoneCaseValue ctZoneCaseValue = (CtZoneCaseValue) input.getMatchEntryValue();
51 NxmNxCtZoneBuilder ctZoneBuilder = new NxmNxCtZoneBuilder();
52 ctZoneBuilder.setCtZone(ctZoneCaseValue.getCtZoneValues().getCtZone());
53 return resolveAugmentation(ctZoneBuilder.build(), path,
54 NxmNxCtZoneKey.class);
58 public MatchEntry convert(Extension extension) {
59 Optional<NxmNxCtZoneGrouping> matchGrouping = MatchUtil.CT_ZONE_RESOLVER.getExtension(extension);
60 if (!matchGrouping.isPresent()) {
61 throw new CodecPreconditionException(extension);
63 CtZoneCaseValueBuilder ctZoneCaseValueBuilder = new CtZoneCaseValueBuilder();
64 CtZoneValuesBuilder ctZoneValuesBuilder = new CtZoneValuesBuilder();
65 ctZoneValuesBuilder.setCtZone(matchGrouping.get().getNxmNxCtZone().getCtZone());
66 ctZoneCaseValueBuilder.setCtZoneValues(ctZoneValuesBuilder.build());
67 MatchEntryBuilder ofMatch = MatchUtil
68 .createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn
69 .opendaylight.openflowjava.nx.match.rev140421.NxmNxCtZone.class,
70 Nxm1Class.class, ctZoneCaseValueBuilder.build());
71 return ofMatch.build();
74 private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(NxmNxCtZone value,
75 MatchPath path, Class<? extends ExtensionKey> key) {
77 case FLOWS_STATISTICS_UPDATE_MATCH:
78 return new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class,
79 new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxCtZone(value).build(), key);
80 case FLOWS_STATISTICS_RPC_MATCH:
81 return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
82 new NxAugMatchRpcGetFlowStatsBuilder().setNxmNxCtZone(value).build(), key);
83 case PACKET_RECEIVED_MATCH:
84 return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder()
85 .setNxmNxCtZone(value).build(), key);
86 case SWITCH_FLOW_REMOVED_MATCH:
87 return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
88 new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmNxCtZone(value).build(), key);
89 case PACKET_IN_MESSAGE_MATCH:
90 return new ExtensionAugment<>(NxAugMatchPacketInMessage.class,
91 new NxAugMatchPacketInMessageBuilder().setNxmNxCtZone(value).build(), key);
93 throw new CodecPreconditionException(path);