2 * Copyright (c) 2014 Cisco Systems, Inc. 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
8 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
10 import java.util.Optional;
11 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
12 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
13 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
14 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
15 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
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.openflowjava.nx.match.rev140421.ofj.nxm.of.match.eth.dst.grouping.EthDstValuesBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EthDstCaseValue;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EthDstCaseValueBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketInBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemovedBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchPacketInMessage;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchPacketInMessageBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStatsBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfEthDstGrouping;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfEthDstKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.eth.dst.grouping.NxmOfEthDst;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.eth.dst.grouping.NxmOfEthDstBuilder;
38 import org.opendaylight.yangtools.yang.binding.Augmentation;
41 * Convert to/from SAL flow model to openflowjava model for EthDstCase.
45 public class EthDstConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
48 public ExtensionAugment<? extends Augmentation<Extension>> convert(MatchEntry input, MatchPath path) {
49 EthDstCaseValue ethDstCaseValue = (EthDstCaseValue) input.getMatchEntryValue();
50 return resolveAugmentation(
51 new NxmOfEthDstBuilder().setMacAddress(ethDstCaseValue.getEthDstValues().getMacAddress()).build(), path,
52 NxmOfEthDstKey.class);
56 public MatchEntry convert(Extension extension) {
57 Optional<NxmOfEthDstGrouping> matchGrouping = MatchUtil.ETH_DST_RESOLVER.findExtension(extension);
58 if (!matchGrouping.isPresent()) {
59 throw new CodecPreconditionException(extension);
61 MacAddress macAddress = matchGrouping.get().getNxmOfEthDst().getMacAddress();
62 EthDstCaseValueBuilder ethDstCaseValueBuilder = new EthDstCaseValueBuilder();
63 ethDstCaseValueBuilder.setEthDstValues(new EthDstValuesBuilder()
64 .setMacAddress(macAddress).build());
65 return MatchUtil.createDefaultMatchEntryBuilder(
66 org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfEthDst.class,
67 Nxm0Class.class, ethDstCaseValueBuilder.build()).build();
70 private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(NxmOfEthDst value,
71 MatchPath path, Class<? extends ExtensionKey> key) {
73 case FLOWS_STATISTICS_UPDATE_MATCH:
74 return new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class,
75 new NxAugMatchNodesNodeTableFlowBuilder().setNxmOfEthDst(value).build(), key);
76 case FLOWS_STATISTICS_RPC_MATCH:
77 return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
78 new NxAugMatchRpcGetFlowStatsBuilder().setNxmOfEthDst(value).build(), key);
79 case PACKET_RECEIVED_MATCH:
80 return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder()
81 .setNxmOfEthDst(value).build(), key);
82 case SWITCH_FLOW_REMOVED_MATCH:
83 return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
84 new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmOfEthDst(value).build(), key);
85 case PACKET_IN_MESSAGE_MATCH:
86 return new ExtensionAugment<>(NxAugMatchPacketInMessage.class,
87 new NxAugMatchPacketInMessageBuilder().setNxmOfEthDst(value).build(), key);
89 throw new CodecPreconditionException(path);