/* * 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.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.state.grouping.CtStateValuesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtStateCaseValue; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtStateCaseValueBuilder; 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.NxmNxCtStateGrouping; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtStateKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.state.grouping.NxmNxCtState; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.state.grouping.NxmNxCtStateBuilder; import org.opendaylight.yangtools.yang.binding.Augmentation; /** * Convert to/from SAL flow model to openflowjava model for CtStateCase. * * @author Aswin Suryanarayanan. */ public class CtStateConvertor implements ConvertorToOFJava, ConvertorFromOFJava { @Override public ExtensionAugment> convert(MatchEntry input, MatchPath path) { CtStateCaseValue ctStateCaseValue = (CtStateCaseValue) input.getMatchEntryValue(); NxmNxCtStateBuilder ctStateBuilder = new NxmNxCtStateBuilder(); ctStateBuilder.setCtState(ctStateCaseValue.getCtStateValues().getCtState()); ctStateBuilder.setMask(ctStateCaseValue.getCtStateValues().getMask()); return resolveAugmentation(ctStateBuilder.build(), path, NxmNxCtStateKey.class); } @Override public MatchEntry convert(Extension extension) { Optional matchGrouping = MatchUtil.CT_STATE_RESOLVER.getExtension(extension); if (!matchGrouping.isPresent()) { throw new CodecPreconditionException(extension); } CtStateCaseValueBuilder ctStateCaseValueBuilder = new CtStateCaseValueBuilder(); CtStateValuesBuilder ctStateValuesBuilder = new CtStateValuesBuilder(); ctStateValuesBuilder.setCtState(matchGrouping.get().getNxmNxCtState().getCtState()); ctStateValuesBuilder.setMask(matchGrouping.get().getNxmNxCtState().getMask()); ctStateCaseValueBuilder.setCtStateValues(ctStateValuesBuilder.build()); MatchEntryBuilder ofMatch = MatchUtil .createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn .opendaylight.openflowjava.nx.match.rev140421.NxmNxCtState.class, Nxm1Class.class, ctStateCaseValueBuilder.build()); ofMatch.setHasMask(true); return ofMatch.build(); } private static ExtensionAugment> resolveAugmentation(NxmNxCtState value, MatchPath path, Class key) { switch (path) { case FLOWS_STATISTICS_UPDATE_MATCH: return new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class, new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxCtState(value).build(), key); case FLOWS_STATISTICS_RPC_MATCH: return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class, new NxAugMatchRpcGetFlowStatsBuilder().setNxmNxCtState(value).build(), key); case PACKET_RECEIVED_MATCH: return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder() .setNxmNxCtState(value).build(), key); case SWITCH_FLOW_REMOVED_MATCH: return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class, new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmNxCtState(value).build(), key); case PACKET_IN_MESSAGE_MATCH: return new ExtensionAugment<>(NxAugMatchPacketInMessage.class, new NxAugMatchPacketInMessageBuilder().setNxmNxCtState(value).build(), key); default: throw new CodecPreconditionException(path); } } }