*/
package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
-import java.util.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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
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.ofj.aug.nx.match.EthDstCaseValue;
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.NxmOfEthDstGrouping;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfEthDstKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.eth.dst.grouping.NxmOfEthDst;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.eth.dst.grouping.NxmOfEthDstBuilder;
EthDstCaseValue ethDstCaseValue = (EthDstCaseValue) input.getMatchEntryValue();
return resolveAugmentation(
new NxmOfEthDstBuilder().setMacAddress(ethDstCaseValue.getEthDstValues().getMacAddress()).build(), path,
- NxmOfEthDstKey.class);
+ NxmOfEthDstKey.VALUE);
}
@Override
public MatchEntry convert(final Extension extension) {
- Optional<NxmOfEthDstGrouping> matchGrouping = MatchUtil.ETH_DST_RESOLVER.findExtension(extension);
- if (!matchGrouping.isPresent()) {
+ final var matchGrouping = MatchUtil.ETH_DST_RESOLVER.findExtension(extension);
+ if (matchGrouping.isEmpty()) {
throw new CodecPreconditionException(extension);
}
- MacAddress macAddress = matchGrouping.get().getNxmOfEthDst().getMacAddress();
- EthDstCaseValueBuilder ethDstCaseValueBuilder = new EthDstCaseValueBuilder();
- ethDstCaseValueBuilder.setEthDstValues(new EthDstValuesBuilder()
- .setMacAddress(macAddress).build());
return MatchUtil.createDefaultMatchEntryBuilder(
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfEthDst.class,
- Nxm0Class.class, ethDstCaseValueBuilder.build()).build();
+ org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfEthDst.VALUE,
+ Nxm0Class.VALUE,
+ new EthDstCaseValueBuilder()
+ .setEthDstValues(new EthDstValuesBuilder()
+ .setMacAddress(matchGrouping.orElseThrow().getNxmOfEthDst().getMacAddress())
+ .build())
+ .build())
+ .build();
}
private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(final NxmOfEthDst value,
- final MatchPath path, final Class<? extends ExtensionKey> key) {
- switch (path) {
- case FLOWS_STATISTICS_UPDATE_MATCH:
- return new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class,
- new NxAugMatchNodesNodeTableFlowBuilder().setNxmOfEthDst(value).build(), key);
- case FLOWS_STATISTICS_RPC_MATCH:
- return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
- new NxAugMatchRpcGetFlowStatsBuilder().setNxmOfEthDst(value).build(), key);
- case PACKET_RECEIVED_MATCH:
- return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder()
- .setNxmOfEthDst(value).build(), key);
- case SWITCH_FLOW_REMOVED_MATCH:
- return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
- new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmOfEthDst(value).build(), key);
- case PACKET_IN_MESSAGE_MATCH:
- return new ExtensionAugment<>(NxAugMatchPacketInMessage.class,
- new NxAugMatchPacketInMessageBuilder().setNxmOfEthDst(value).build(), key);
- default:
- throw new CodecPreconditionException(path);
- }
+ final MatchPath path, final ExtensionKey key) {
+ return switch (path) {
+ case FLOWS_STATISTICS_UPDATE_MATCH -> new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class,
+ new NxAugMatchNodesNodeTableFlowBuilder().setNxmOfEthDst(value).build(), key);
+ case FLOWS_STATISTICS_RPC_MATCH -> new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
+ new NxAugMatchRpcGetFlowStatsBuilder().setNxmOfEthDst(value).build(), key);
+ case PACKET_RECEIVED_MATCH -> new ExtensionAugment<>(NxAugMatchNotifPacketIn.class,
+ new NxAugMatchNotifPacketInBuilder().setNxmOfEthDst(value).build(), key);
+ case SWITCH_FLOW_REMOVED_MATCH -> new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
+ new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmOfEthDst(value).build(), key);
+ case PACKET_IN_MESSAGE_MATCH -> new ExtensionAugment<>(NxAugMatchPacketInMessage.class,
+ new NxAugMatchPacketInMessageBuilder().setNxmOfEthDst(value).build(), key);
+ };
}
}