/* * Copyright (c) 2015 Hewlett-Packard Enterprise and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match; import com.google.common.base.Optional; import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava; import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava; import org.opendaylight.openflowplugin.extension.api.ExtensionAugment; import org.opendaylight.openflowplugin.extension.api.path.MatchPath; import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketInBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemovedBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtZoneGrouping; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtZoneKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.zone.grouping.NxmNxCtZone; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.zone.grouping.NxmNxCtZoneBuilder; import org.opendaylight.yangtools.yang.binding.Augmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.zone.grouping.CtZoneValuesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValue; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValueBuilder; /** * @author Aswin Suryanarayanan. */ public class CtZoneConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> { /* * (non-Javadoc) * * @see * org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava#convert * (org.opendaylight.yangtools.yang.binding.DataContainer, * org.opendaylight.openflowplugin.extension.api.path.AugmentationPath) */ @Override public ExtensionAugment<? extends Augmentation<Extension>> convert(MatchEntry input, MatchPath path) { CtZoneCaseValue ctZoneCaseValue = ((CtZoneCaseValue) input.getMatchEntryValue()); NxmNxCtZoneBuilder ctZoneBuilder = new NxmNxCtZoneBuilder(); ctZoneBuilder.setCtZone(ctZoneCaseValue.getCtZoneValues().getCtZone()); return resolveAugmentation(ctZoneBuilder.build(), path, NxmNxCtZoneKey.class); } /* * (non-Javadoc) * * @see * org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava#convert * (org * .opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general * .rev140714.general.extension.grouping.Extension) */ @Override public MatchEntry convert(Extension extension) { Optional<NxmNxCtZoneGrouping> matchGrouping = MatchUtil.ctZoneResolver.getExtension(extension); if (!matchGrouping.isPresent()) { throw new CodecPreconditionException(extension); } CtZoneCaseValueBuilder ctZoneCaseValueBuilder = new CtZoneCaseValueBuilder(); CtZoneValuesBuilder ctZoneValuesBuilder = new CtZoneValuesBuilder(); ctZoneValuesBuilder.setCtZone(matchGrouping.get().getNxmNxCtZone().getCtZone()); ctZoneCaseValueBuilder.setCtZoneValues(ctZoneValuesBuilder.build()); MatchEntryBuilder ofMatch = MatchUtil .createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn .opendaylight.openflowjava.nx.match.rev140421.NxmNxCtZone.class, Nxm1Class.class, ctZoneCaseValueBuilder.build()); return ofMatch.build(); } private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(NxmNxCtZone value, MatchPath path, Class<? extends ExtensionKey> key) { switch (path) { case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH: return new ExtensionAugment<>(NxAugMatchNotifUpdateFlowStats.class, new NxAugMatchNotifUpdateFlowStatsBuilder().setNxmNxCtZone(value).build(), key); case RPCFLOWSSTATISTICS_FLOWANDSTATISTICSMAPLIST_MATCH: return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class, new NxAugMatchRpcGetFlowStatsBuilder().setNxmNxCtZone(value).build(), key); case PACKETRECEIVED_MATCH: return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder() .setNxmNxCtZone(value).build(), key); case SWITCHFLOWREMOVED_MATCH: return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class, new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmNxCtZone(value).build(), key); default: throw new CodecPreconditionException(path); } } }