2 * Copyright (c) 2015 Hewlett-Packard Enterprise 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
9 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
11 import com.google.common.base.Optional;
12 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
13 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
14 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
15 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
16 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
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.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.udp.dst.grouping.UdpDstValuesBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpDstCaseValue;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpDstCaseValueBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketInBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemovedBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchPacketInMessage;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchPacketInMessageBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStatsBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfUdpDstGrouping;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfUdpDstKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.udp.dst.grouping.NxmOfUdpDst;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.udp.dst.grouping.NxmOfUdpDstBuilder;
39 import org.opendaylight.yangtools.yang.binding.Augmentation;
42 * Convert to/from SAL flow model to openflowjava model for UdpDstCase.
44 * @author Aswin Suryanarayanan.
46 public class UdpDstConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
49 public ExtensionAugment<? extends Augmentation<Extension>> convert(MatchEntry input, MatchPath path) {
50 UdpDstCaseValue udpDstCaseValue = (UdpDstCaseValue) input.getMatchEntryValue();
51 NxmOfUdpDstBuilder udpDstBuilder = new NxmOfUdpDstBuilder();
52 udpDstBuilder.setPort(udpDstCaseValue.getUdpDstValues().getPort());
53 udpDstBuilder.setMask(udpDstCaseValue.getUdpDstValues().getMask());
54 return resolveAugmentation(udpDstBuilder.build(), path,
55 NxmOfUdpDstKey.class);
59 public MatchEntry convert(Extension extension) {
60 Optional<NxmOfUdpDstGrouping> matchGrouping = MatchUtil.UDP_DST_RESOLVER.getExtension(extension);
61 if (!matchGrouping.isPresent()) {
62 throw new CodecPreconditionException(extension);
64 UdpDstCaseValueBuilder udpDstCaseValueBuilder = new UdpDstCaseValueBuilder();
65 UdpDstValuesBuilder udpDstValuesBuilder = new UdpDstValuesBuilder();
66 udpDstValuesBuilder.setPort(matchGrouping.get().getNxmOfUdpDst().getPort());
67 udpDstValuesBuilder.setMask(matchGrouping.get().getNxmOfUdpDst().getMask());
68 udpDstCaseValueBuilder.setUdpDstValues(udpDstValuesBuilder.build());
69 MatchEntryBuilder ofMatch = MatchUtil
70 .createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight
71 .openflowjava.nx.match.rev140421.NxmOfUdpDst.class,
72 Nxm0Class.class,udpDstCaseValueBuilder.build());
73 ofMatch.setHasMask(true);
74 return ofMatch.build();
77 private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(NxmOfUdpDst value,
78 MatchPath path, Class<? extends ExtensionKey> key) {
80 case FLOWS_STATISTICS_UPDATE_MATCH:
81 return new ExtensionAugment<>(NxAugMatchNodesNodeTableFlow.class,
82 new NxAugMatchNodesNodeTableFlowBuilder().setNxmOfUdpDst(value).build(), key);
83 case FLOWS_STATISTICS_RPC_MATCH:
84 return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
85 new NxAugMatchRpcGetFlowStatsBuilder().setNxmOfUdpDst(value).build(), key);
86 case PACKET_RECEIVED_MATCH:
87 return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder()
88 .setNxmOfUdpDst(value).build(), key);
89 case SWITCH_FLOW_REMOVED_MATCH:
90 return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
91 new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmOfUdpDst(value).build(), key);
92 case PACKET_IN_MESSAGE_MATCH:
93 return new ExtensionAugment<>(NxAugMatchPacketInMessage.class,
94 new NxAugMatchPacketInMessageBuilder().setNxmOfUdpDst(value).build(), key);
96 throw new CodecPreconditionException(path);