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;
13 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
14 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
15 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
16 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
17 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketInBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemovedBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStatsBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfTcpDstGrouping;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfTcpDstKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.tcp.dst.grouping.NxmOfTcpDst;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.tcp.dst.grouping.NxmOfTcpDstBuilder;
35 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.tcp.dst.grouping.TcpDstValuesBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpDstCaseValue;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpDstCaseValueBuilder;
42 * @author Aswin Suryanarayanan.
44 public class TcpDstConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
50 * org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava#convert
51 * (org.opendaylight.yangtools.yang.binding.DataContainer,
52 * org.opendaylight.openflowplugin.extension.api.path.AugmentationPath)
55 public ExtensionAugment<? extends Augmentation<Extension>> convert(MatchEntry input, MatchPath path) {
56 TcpDstCaseValue tcpDstCaseValue = ((TcpDstCaseValue) input.getMatchEntryValue());
57 NxmOfTcpDstBuilder tcpDstBuilder = new NxmOfTcpDstBuilder();
58 tcpDstBuilder.setPort(tcpDstCaseValue.getTcpDstValues().getPort());
59 tcpDstBuilder.setMask(tcpDstCaseValue.getTcpDstValues().getMask());
60 return resolveAugmentation(tcpDstBuilder.build(), path,
61 NxmOfTcpDstKey.class);
68 * org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava#convert
70 * .opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general
71 * .rev140714.general.extension.grouping.Extension)
74 public MatchEntry convert(Extension extension) {
75 Optional<NxmOfTcpDstGrouping> matchGrouping = MatchUtil.tcpDstResolver.getExtension(extension);
76 if (!matchGrouping.isPresent()) {
77 throw new CodecPreconditionException(extension);
79 TcpDstCaseValueBuilder tcpDstCaseValueBuilder = new TcpDstCaseValueBuilder();
80 TcpDstValuesBuilder tcpDstValuesBuilder = new TcpDstValuesBuilder();
81 tcpDstValuesBuilder.setPort(matchGrouping.get().getNxmOfTcpDst().getPort());
82 tcpDstValuesBuilder.setMask(matchGrouping.get().getNxmOfTcpDst().getMask());
83 tcpDstCaseValueBuilder.setTcpDstValues(tcpDstValuesBuilder.build());
84 MatchEntryBuilder ofMatch = MatchUtil
85 .createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn
86 .opendaylight.openflowjava.nx.match.rev140421.NxmOfTcpDst.class,
87 Nxm0Class.class, tcpDstCaseValueBuilder.build());
88 ofMatch.setHasMask(true);
89 return ofMatch.build();
92 private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(NxmOfTcpDst value,
93 MatchPath path, Class<? extends ExtensionKey> key) {
95 case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH:
96 return new ExtensionAugment<>(NxAugMatchNotifUpdateFlowStats.class,
97 new NxAugMatchNotifUpdateFlowStatsBuilder().setNxmOfTcpDst(value).build(), key);
98 case RPCFLOWSSTATISTICS_FLOWANDSTATISTICSMAPLIST_MATCH:
99 return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
100 new NxAugMatchRpcGetFlowStatsBuilder().setNxmOfTcpDst(value).build(), key);
101 case PACKETRECEIVED_MATCH:
102 return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder()
103 .setNxmOfTcpDst(value).build(), key);
104 case SWITCHFLOWREMOVED_MATCH:
105 return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
106 new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmOfTcpDst(value).build(), key);
108 throw new CodecPreconditionException(path);