/* * Copyright (c) 2015 Intel, Inc. 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 java.util.Optional; import org.opendaylight.openflowjava.nx.api.NiciraConstants; 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.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.OfjAugNxExpMatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsh.np.grouping.NshNpValues; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsh.np.grouping.NshNpValuesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.experimenter.id._case.NxExpMatchEntryValue; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.experimenter.id._case.nx.exp.match.entry.value.NshNpCaseValue; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.experimenter.id._case.nx.exp.match.entry.value.NshNpCaseValueBuilder; 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.NxAugMatchNodesNodeTableFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder; 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.NxAugMatchPacketInMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchPacketInMessageBuilder; 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.NxmNxNshNpGrouping; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNshNpKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsh.np.grouping.NxmNxNshNp; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsh.np.grouping.NxmNxNshNpBuilder; import org.opendaylight.yangtools.yang.binding.Augmentation; import org.opendaylight.yangtools.yang.common.Uint8; public class NshNpConvertor implements ConvertorToOFJava, ConvertorFromOFJava { @Override public ExtensionAugment> convert(MatchEntry input, MatchPath path) { ExperimenterIdCase experimenterIdCase = (ExperimenterIdCase) input.getMatchEntryValue(); OfjAugNxExpMatch ofjAugNxExpMatch = experimenterIdCase.augmentation(OfjAugNxExpMatch.class); NshNpCaseValue nshNpCaseValue = (NshNpCaseValue) ofjAugNxExpMatch.getNxExpMatchEntryValue(); NshNpValues nshNpValues = nshNpCaseValue.getNshNpValues(); NxmNxNshNp nxmNxNshNp = new NxmNxNshNpBuilder() .setValue(nshNpValues.getValue()) .build(); return resolveAugmentation( nxmNxNshNp, path, NxmNxNshNpKey.class); } @Override public MatchEntry convert(Extension extension) { Optional matchGrouping = MatchUtil.NSH_NP_RESOLVER.findExtension(extension); if (!matchGrouping.isPresent()) { throw new CodecPreconditionException(extension); } Uint8 value = matchGrouping.get().getNxmNxNshNp().getValue(); return buildMatchEntry(value, null); } public static MatchEntry buildMatchEntry(Uint8 value, Uint8 mask) { NshNpValues nshNpValues = new NshNpValuesBuilder().setValue(value).build(); NxExpMatchEntryValue entryValue = new NshNpCaseValueBuilder().setNshNpValues(nshNpValues).build(); return MatchUtil.createExperimenterMatchEntryBuilder( org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxNshNp.class, NiciraConstants.NX_NSH_VENDOR_ID, entryValue).setHasMask(mask != null).build(); } private static ExtensionAugment> resolveAugmentation( NxmNxNshNp value, MatchPath path, Class key) { switch (path) { case FLOWS_STATISTICS_UPDATE_MATCH: return new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class, new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxNshNp(value).build(), key); case FLOWS_STATISTICS_RPC_MATCH: return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class, new NxAugMatchRpcGetFlowStatsBuilder().setNxmNxNshNp(value).build(), key); case PACKET_RECEIVED_MATCH: return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder().setNxmNxNshNp(value).build(), key); case SWITCH_FLOW_REMOVED_MATCH: return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class, new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmNxNshNp(value).build(), key); case PACKET_IN_MESSAGE_MATCH: return new ExtensionAugment<>(NxAugMatchPacketInMessage.class, new NxAugMatchPacketInMessageBuilder().setNxmNxNshNp(value).build(), key); default: throw new CodecPreconditionException(path); } } }