2 * Copyright (c) 2018 SUSE LINUX GmbH. 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.action;
11 import com.google.common.collect.ImmutableMap;
12 import java.math.BigInteger;
14 import org.opendaylight.openflowjava.nx.codec.match.NiciraMatchCodecs;
15 import org.opendaylight.openflowjava.nx.codec.match.NxmHeader;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg2;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg3;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg7;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.DstChoice;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpShaCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpThaCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxIpv6DstCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxIpv6SrcCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxNshFlagsCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxNshTtlCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxNshc1CaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxNshc2CaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxNshc3CaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxNshc4CaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxNsiCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxNspCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxOfInPortCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxRegCase;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxRegCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIdCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIpv4DstCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIpv4SrcCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpOpCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpSpaCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpTpaCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfEthDstCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfEthSrcCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfIcmpTypeCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfIpDstCaseBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfIpSrcCaseBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfMetadataCaseBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfMplsLabelCaseBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.SrcChoice;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxArpShaCaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxArpThaCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxIpv6DstCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxIpv6SrcCaseBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxNshFlagsCaseBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxNshMdtypeCaseBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxNshNpCaseBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxNshTtlCaseBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxNshc1CaseBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxNshc2CaseBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxNshc3CaseBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxNshc4CaseBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxNsiCaseBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxNspCaseBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxOfInPortCaseBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxOfMetadataCaseBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxOfMplsLabelCaseBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxRegCase;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxRegCaseBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxTunIdCaseBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxTunIpv4DstCaseBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxTunIpv4SrcCaseBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpOpCaseBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpSpaCaseBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpTpaCaseBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfEthDstCaseBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfEthSrcCaseBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfEthTypeCaseBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfIpDstCaseBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfIpSrcCaseBuilder;
84 import org.opendaylight.yangtools.yang.binding.DataContainer;
85 import org.opendaylight.yangtools.yang.common.Empty;
88 * A helper class that maps various NXM/OXM header representations to
89 * source/destination choice fields used in some of the openflow actions.
91 public final class FieldChoiceResolver {
93 private FieldChoiceResolver() {
97 private static final Map<Number, SrcChoice> NXMHEADER_TO_SRC_CHOICE;
98 private static final Map<Number, DstChoice> NXMHEADER_TO_DST_CHOICE;
99 private static final Map<Class<? extends DataContainer>, NxmHeader> DST_CHOICE_TYPE_TO_NXMHEADER;
100 private static final Map<Class<? extends DataContainer>, NxmHeader> SRC_CHOICE_TYPE_TO_NXMHEADER;
101 private static final Map<DstChoice, NxmHeader> REG_DST_CHOICE_TO_NXMHEADER;
102 private static final Map<SrcChoice, NxmHeader> REG_SRC_CHOICE_TO_NXMHEADER;
105 final ImmutableMap<SrcChoice, NxmHeader> srcChoiceToNxmheader =
106 new ImmutableMap.Builder<SrcChoice, NxmHeader>()
107 .put(new SrcNxTunIdCaseBuilder().setNxTunId(Empty.getInstance()).build(),
108 NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask())
109 .put(new SrcNxArpShaCaseBuilder().setNxArpSha(Empty.getInstance()).build(),
110 NiciraMatchCodecs.ARP_SHA_CODEC.getHeaderWithoutHasMask())
111 .put(new SrcNxArpThaCaseBuilder().setNxArpTha(Empty.getInstance()).build(),
112 NiciraMatchCodecs.ARP_THA_CODEC.getHeaderWithoutHasMask())
113 .put(new SrcOfArpOpCaseBuilder().setOfArpOp(Empty.getInstance()).build(),
114 NiciraMatchCodecs.ARP_OP_CODEC.getHeaderWithoutHasMask())
115 .put(new SrcOfArpSpaCaseBuilder().setOfArpSpa(Empty.getInstance()).build(),
116 NiciraMatchCodecs.ARP_SPA_CODEC.getHeaderWithoutHasMask())
117 .put(new SrcOfArpTpaCaseBuilder().setOfArpTpa(Empty.getInstance()).build(),
118 NiciraMatchCodecs.ARP_TPA_CODEC.getHeaderWithoutHasMask())
119 .put(new SrcNxOfInPortCaseBuilder().setOfInPort(Empty.getInstance()).build(),
120 NiciraMatchCodecs.NXM_OF_IN_PORT_CODEC.getHeaderWithoutHasMask())
121 .put(new SrcNxOfMetadataCaseBuilder().setOfMetadata(Empty.getInstance()).build(),
122 NiciraMatchCodecs.OXM_OF_METADATA_CODEC.getHeaderWithoutHasMask())
123 .put(new SrcOfEthDstCaseBuilder().setOfEthDst(Empty.getInstance()).build(),
124 NiciraMatchCodecs.ETH_DST_CODEC.getHeaderWithoutHasMask())
125 .put(new SrcOfEthSrcCaseBuilder().setOfEthSrc(Empty.getInstance()).build(),
126 NiciraMatchCodecs.ETH_SRC_CODEC.getHeaderWithoutHasMask())
127 .put(new SrcOfEthTypeCaseBuilder().setOfEthType(Empty.getInstance()).build(),
128 NiciraMatchCodecs.ETH_TYPE_CODEC.getHeaderWithoutHasMask())
129 .put(new SrcNxTunIpv4DstCaseBuilder().setNxTunIpv4Dst(Empty.getInstance()).build(),
130 NiciraMatchCodecs.TUN_IPV4_DST_CODEC.getHeaderWithoutHasMask())
131 .put(new SrcNxTunIpv4SrcCaseBuilder().setNxTunIpv4Src(Empty.getInstance()).build(),
132 NiciraMatchCodecs.TUN_IPV4_SRC_CODEC.getHeaderWithoutHasMask())
133 .put(new SrcNxNspCaseBuilder().setNxNspDst(Empty.getInstance()).build(),
134 NiciraMatchCodecs.NSP_CODEC.getHeaderWithoutHasMask())
135 .put(new SrcNxNsiCaseBuilder().setNxNsiDst(Empty.getInstance()).build(),
136 NiciraMatchCodecs.NSI_CODEC.getHeaderWithoutHasMask())
137 .put(new SrcNxNshc1CaseBuilder().setNxNshc1Dst(Empty.getInstance()).build(),
138 NiciraMatchCodecs.NSC1_CODEC.getHeaderWithoutHasMask())
139 .put(new SrcNxNshc2CaseBuilder().setNxNshc2Dst(Empty.getInstance()).build(),
140 NiciraMatchCodecs.NSC2_CODEC.getHeaderWithoutHasMask())
141 .put(new SrcNxNshc3CaseBuilder().setNxNshc3Dst(Empty.getInstance()).build(),
142 NiciraMatchCodecs.NSC3_CODEC.getHeaderWithoutHasMask())
143 .put(new SrcNxNshc4CaseBuilder().setNxNshc4Dst(Empty.getInstance()).build(),
144 NiciraMatchCodecs.NSC4_CODEC.getHeaderWithoutHasMask())
145 .put(new SrcNxNshFlagsCaseBuilder().setNxNshFlags(Empty.getInstance()).build(),
146 NiciraMatchCodecs.NSH_FLAGS_CODEC.getHeaderWithoutHasMask())
147 .put(new SrcNxNshTtlCaseBuilder().setNxNshTtl(Empty.getInstance()).build(),
148 NiciraMatchCodecs.NSH_TTL_CODEC.getHeaderWithoutHasMask())
149 .put(new SrcNxNshMdtypeCaseBuilder().setNxNshMdtype(Empty.getInstance()).build(),
150 NiciraMatchCodecs.NSH_MDTYPE_CODEC.getHeaderWithoutHasMask())
151 .put(new SrcNxNshNpCaseBuilder().setNxNshNp(Empty.getInstance()).build(),
152 NiciraMatchCodecs.NSH_NP_CODEC.getHeaderWithoutHasMask())
153 .put(new SrcOfIpDstCaseBuilder().setOfIpDst(Empty.getInstance()).build(),
154 NiciraMatchCodecs.IP_DST_CODEC.getHeaderWithoutHasMask())
155 .put(new SrcOfIpSrcCaseBuilder().setOfIpSrc(Empty.getInstance()).build(),
156 NiciraMatchCodecs.IP_SRC_CODEC.getHeaderWithoutHasMask())
157 .put(new SrcNxIpv6SrcCaseBuilder().setNxIpv6Src(Empty.getInstance()).build(),
158 NiciraMatchCodecs.IPV6_SRC_CODEC.getHeaderWithoutHasMask())
159 .put(new SrcNxIpv6DstCaseBuilder().setNxIpv6Dst(Empty.getInstance()).build(),
160 NiciraMatchCodecs.IPV6_DST_CODEC.getHeaderWithoutHasMask())
161 .put(new SrcNxOfMplsLabelCaseBuilder().setOfMplsLabel(Empty.getInstance()).build(),
162 NiciraMatchCodecs.OXM_OF_MPLS_LABEL.getHeaderWithoutHasMask())
163 .put(new SrcNxRegCaseBuilder().setNxReg(NxmNxReg0.class).build(),
164 NiciraMatchCodecs.REG0_CODEC.getHeaderWithoutHasMask())
165 .put(new SrcNxRegCaseBuilder().setNxReg(NxmNxReg1.class).build(),
166 NiciraMatchCodecs.REG1_CODEC.getHeaderWithoutHasMask())
167 .put(new SrcNxRegCaseBuilder().setNxReg(NxmNxReg2.class).build(),
168 NiciraMatchCodecs.REG2_CODEC.getHeaderWithoutHasMask())
169 .put(new SrcNxRegCaseBuilder().setNxReg(NxmNxReg3.class).build(),
170 NiciraMatchCodecs.REG3_CODEC.getHeaderWithoutHasMask())
171 .put(new SrcNxRegCaseBuilder().setNxReg(NxmNxReg4.class).build(),
172 NiciraMatchCodecs.REG4_CODEC.getHeaderWithoutHasMask())
173 .put(new SrcNxRegCaseBuilder().setNxReg(NxmNxReg5.class).build(),
174 NiciraMatchCodecs.REG5_CODEC.getHeaderWithoutHasMask())
175 .put(new SrcNxRegCaseBuilder().setNxReg(NxmNxReg6.class).build(),
176 NiciraMatchCodecs.REG6_CODEC.getHeaderWithoutHasMask())
177 .put(new SrcNxRegCaseBuilder().setNxReg(NxmNxReg7.class).build(),
178 NiciraMatchCodecs.REG7_CODEC.getHeaderWithoutHasMask())
181 final ImmutableMap<DstChoice, NxmHeader> dstChoiceToNxmheader =
182 new ImmutableMap.Builder<DstChoice, NxmHeader>()
183 .put(new DstNxTunIdCaseBuilder().setNxTunId(Empty.getInstance()).build(),
184 NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask())
185 .put(new DstNxArpShaCaseBuilder().setNxArpSha(Empty.getInstance()).build(),
186 NiciraMatchCodecs.ARP_SHA_CODEC.getHeaderWithoutHasMask())
187 .put(new DstNxArpThaCaseBuilder().setNxArpTha(Empty.getInstance()).build(),
188 NiciraMatchCodecs.ARP_THA_CODEC.getHeaderWithoutHasMask())
189 .put(new DstOfArpOpCaseBuilder().setOfArpOp(Empty.getInstance()).build(),
190 NiciraMatchCodecs.ARP_OP_CODEC.getHeaderWithoutHasMask())
191 .put(new DstOfArpSpaCaseBuilder().setOfArpSpa(Empty.getInstance()).build(),
192 NiciraMatchCodecs.ARP_SPA_CODEC.getHeaderWithoutHasMask())
193 .put(new DstOfArpTpaCaseBuilder().setOfArpTpa(Empty.getInstance()).build(),
194 NiciraMatchCodecs.ARP_TPA_CODEC.getHeaderWithoutHasMask())
195 .put(new DstNxOfInPortCaseBuilder().setOfInPort(Empty.getInstance()).build(),
196 NiciraMatchCodecs.NXM_OF_IN_PORT_CODEC.getHeaderWithoutHasMask())
197 .put(new DstOfMetadataCaseBuilder().setOfMetadata(Empty.getInstance()).build(),
198 NiciraMatchCodecs.OXM_OF_METADATA_CODEC.getHeaderWithoutHasMask())
199 .put(new DstOfEthSrcCaseBuilder().setOfEthSrc(Empty.getInstance()).build(),
200 NiciraMatchCodecs.ETH_SRC_CODEC.getHeaderWithoutHasMask())
201 .put(new DstOfEthDstCaseBuilder().setOfEthDst(Empty.getInstance()).build(),
202 NiciraMatchCodecs.ETH_DST_CODEC.getHeaderWithoutHasMask())
203 .put(new DstNxTunIpv4DstCaseBuilder().setNxTunIpv4Dst(Empty.getInstance()).build(),
204 NiciraMatchCodecs.TUN_IPV4_DST_CODEC.getHeaderWithoutHasMask())
205 .put(new DstNxTunIpv4SrcCaseBuilder().setNxTunIpv4Src(Empty.getInstance()).build(),
206 NiciraMatchCodecs.TUN_IPV4_SRC_CODEC.getHeaderWithoutHasMask())
207 .put(new DstNxNspCaseBuilder().setNxNspDst(Empty.getInstance()).build(),
208 NiciraMatchCodecs.NSP_CODEC.getHeaderWithoutHasMask())
209 .put(new DstNxNsiCaseBuilder().setNxNsiDst(Empty.getInstance()).build(),
210 NiciraMatchCodecs.NSI_CODEC.getHeaderWithoutHasMask())
211 .put(new DstNxNshc1CaseBuilder().setNxNshc1Dst(Empty.getInstance()).build(),
212 NiciraMatchCodecs.NSC1_CODEC.getHeaderWithoutHasMask())
213 .put(new DstNxNshc2CaseBuilder().setNxNshc2Dst(Empty.getInstance()).build(),
214 NiciraMatchCodecs.NSC2_CODEC.getHeaderWithoutHasMask())
215 .put(new DstNxNshc3CaseBuilder().setNxNshc3Dst(Empty.getInstance()).build(),
216 NiciraMatchCodecs.NSC3_CODEC.getHeaderWithoutHasMask())
217 .put(new DstNxNshc4CaseBuilder().setNxNshc4Dst(Empty.getInstance()).build(),
218 NiciraMatchCodecs.NSC4_CODEC.getHeaderWithoutHasMask())
219 .put(new DstNxNshFlagsCaseBuilder().setNxNshFlags(Empty.getInstance()).build(),
220 NiciraMatchCodecs.NSH_FLAGS_CODEC.getHeaderWithoutHasMask())
221 .put(new DstNxNshTtlCaseBuilder().setNxNshTtl(Empty.getInstance()).build(),
222 NiciraMatchCodecs.NSH_TTL_CODEC.getHeaderWithoutHasMask())
223 .put(new DstOfIpDstCaseBuilder().setOfIpDst(Empty.getInstance()).build(),
224 NiciraMatchCodecs.IP_DST_CODEC.getHeaderWithoutHasMask())
225 .put(new DstOfIpSrcCaseBuilder().setOfIpSrc(Empty.getInstance()).build(),
226 NiciraMatchCodecs.IP_SRC_CODEC.getHeaderWithoutHasMask())
227 .put(new DstNxIpv6SrcCaseBuilder().setNxIpv6Src(Empty.getInstance()).build(),
228 NiciraMatchCodecs.IPV6_SRC_CODEC.getHeaderWithoutHasMask())
229 .put(new DstNxIpv6DstCaseBuilder().setNxIpv6Dst(Empty.getInstance()).build(),
230 NiciraMatchCodecs.IPV6_DST_CODEC.getHeaderWithoutHasMask())
231 .put(new DstOfMplsLabelCaseBuilder().setOfMplsLabel(Empty.getInstance()).build(),
232 NiciraMatchCodecs.OXM_OF_MPLS_LABEL.getHeaderWithoutHasMask())
233 .put(new DstOfIcmpTypeCaseBuilder().setOfIcmpType(Empty.getInstance()).build(),
234 NiciraMatchCodecs.ICMP_TYPE_CODEC.getHeaderWithoutHasMask())
235 .put(new DstNxRegCaseBuilder().setNxReg(NxmNxReg0.class).build(),
236 NiciraMatchCodecs.REG0_CODEC.getHeaderWithoutHasMask())
237 .put(new DstNxRegCaseBuilder().setNxReg(NxmNxReg1.class).build(),
238 NiciraMatchCodecs.REG1_CODEC.getHeaderWithoutHasMask())
239 .put(new DstNxRegCaseBuilder().setNxReg(NxmNxReg2.class).build(),
240 NiciraMatchCodecs.REG2_CODEC.getHeaderWithoutHasMask())
241 .put(new DstNxRegCaseBuilder().setNxReg(NxmNxReg3.class).build(),
242 NiciraMatchCodecs.REG3_CODEC.getHeaderWithoutHasMask())
243 .put(new DstNxRegCaseBuilder().setNxReg(NxmNxReg4.class).build(),
244 NiciraMatchCodecs.REG4_CODEC.getHeaderWithoutHasMask())
245 .put(new DstNxRegCaseBuilder().setNxReg(NxmNxReg5.class).build(),
246 NiciraMatchCodecs.REG5_CODEC.getHeaderWithoutHasMask())
247 .put(new DstNxRegCaseBuilder().setNxReg(NxmNxReg6.class).build(),
248 NiciraMatchCodecs.REG6_CODEC.getHeaderWithoutHasMask())
249 .put(new DstNxRegCaseBuilder().setNxReg(NxmNxReg7.class).build(),
250 NiciraMatchCodecs.REG7_CODEC.getHeaderWithoutHasMask())
253 ImmutableMap.Builder<Number, SrcChoice> headerToSrcChoiceBuilder = ImmutableMap.builder();
254 ImmutableMap.Builder<Class<? extends DataContainer>, NxmHeader> srcTypeToHeaderBuilder = ImmutableMap.builder();
255 ImmutableMap.Builder<SrcChoice, NxmHeader> regSrcChoiceToHeaderBuilder = ImmutableMap.builder();
256 srcChoiceToNxmheader.forEach((srcChoice, header) -> {
257 headerToSrcChoiceBuilder.put(header.toLong(), srcChoice);
258 headerToSrcChoiceBuilder.put(header.toBigInteger(), srcChoice);
259 if (srcChoice instanceof SrcNxRegCase) {
260 regSrcChoiceToHeaderBuilder.put(srcChoice, header);
262 srcTypeToHeaderBuilder.put(srcChoice.implementedInterface(), header);
265 NXMHEADER_TO_SRC_CHOICE = headerToSrcChoiceBuilder.build();
266 SRC_CHOICE_TYPE_TO_NXMHEADER = srcTypeToHeaderBuilder.build();
267 REG_SRC_CHOICE_TO_NXMHEADER = regSrcChoiceToHeaderBuilder.build();
269 ImmutableMap.Builder<Number, DstChoice> dstToHeaderBuilder = ImmutableMap.builder();
270 ImmutableMap.Builder<Class<? extends DataContainer>, NxmHeader> dstTypeToHeaderBuilder = ImmutableMap.builder();
271 ImmutableMap.Builder<DstChoice, NxmHeader> regDstChoiceToHeaderBuilder = ImmutableMap.builder();
272 dstChoiceToNxmheader.forEach((dstChoice, header) -> {
273 dstToHeaderBuilder.put(header.toLong(), dstChoice);
274 dstToHeaderBuilder.put(header.toBigInteger(), dstChoice);
275 if (dstChoice instanceof DstNxRegCase) {
276 regDstChoiceToHeaderBuilder.put(dstChoice, header);
278 dstTypeToHeaderBuilder.put(dstChoice.implementedInterface(), header);
281 NXMHEADER_TO_DST_CHOICE = dstToHeaderBuilder.build();
282 DST_CHOICE_TYPE_TO_NXMHEADER = dstTypeToHeaderBuilder.build();
283 REG_DST_CHOICE_TO_NXMHEADER = regDstChoiceToHeaderBuilder.build();
287 * Resolves a destination choice field from a {@code Long} representation
288 * of a NXM/OXM header.
290 * @param header the OXM/NXM header.
291 * @return the destination choice.
293 static DstChoice resolveDstChoice(Long header) {
294 return NXMHEADER_TO_DST_CHOICE.get(header);
298 * Resolves a destination choice field from a {@code BigInteger} representation
299 * of a NXM/OXM header.
301 * @param header the OXM/NXM header.
302 * @return the destination choice.
304 static DstChoice resolveDstChoice(BigInteger header) {
305 return NXMHEADER_TO_DST_CHOICE.get(header);
309 * Resolves a source choice field from a {@code Long} representation
310 * of a NXM/OXM header.
312 * @param header the OXM/NXM header.
313 * @return the source choice.
315 static SrcChoice resolveSrcChoice(Long header) {
316 return NXMHEADER_TO_SRC_CHOICE.get(header);
320 * Resolves a source choice field from a {@code BigInteger} representation
321 * of a NXM/OXM header.
323 * @param header the OXM/NXM header.
324 * @return the destination choice.
326 static SrcChoice resolveSrcChoice(BigInteger header) {
327 return NXMHEADER_TO_SRC_CHOICE.get(header);
331 * Resolves a uint32 representation of a non experimenter 4 byte
332 * OXM/NXM header for the field given as {@code dstChoice}.
334 * @param dstChoice the destination choice field.
335 * @return the OXM/NXM header as uint32 {@code Long}.
336 * @throws IllegalArgumentException if the field is experimenter.
338 static Long resolveDstHeaderUint32(DstChoice dstChoice) {
339 NxmHeader nxmHeader = dstChoice instanceof DstNxRegCase
340 ? REG_DST_CHOICE_TO_NXMHEADER.get(dstChoice)
341 : DST_CHOICE_TYPE_TO_NXMHEADER.get(dstChoice.implementedInterface());
342 if (nxmHeader.isExperimenter()) {
343 throw new IllegalArgumentException("Cannot fit experimenter destination choice on a uint32 header");
345 return nxmHeader.toLong();
349 * Resolves a uint64 representation of a possibly experimenter
350 * OXM/NXM header for the field given as {@code dstChoice}.
352 * @param dstChoice the destination choice field.
353 * @return the OXM/NXM header as uint64 {@code BigInteger}.
355 static BigInteger resolveDstHeaderUint64(DstChoice dstChoice) {
356 return dstChoice instanceof DstNxRegCase
357 ? REG_DST_CHOICE_TO_NXMHEADER.get(dstChoice).toBigInteger()
358 : DST_CHOICE_TYPE_TO_NXMHEADER.get(dstChoice.implementedInterface()).toBigInteger();
362 * Resolves a uint32 representation of a non experimenter 4 byte
363 * OXM/NXM header for the field given as {@code srcChoice}.
365 * @param srcChoice the source choice field.
366 * @return the OXM/NXM header as uint32 {@code Long}.
367 * @throws IllegalArgumentException if the field is experimenter.
369 static Long resolveSrcHeaderUint32(SrcChoice srcChoice) {
370 NxmHeader nxmHeader = srcChoice instanceof SrcNxRegCase
371 ? REG_SRC_CHOICE_TO_NXMHEADER.get(srcChoice)
372 : SRC_CHOICE_TYPE_TO_NXMHEADER.get(srcChoice.implementedInterface());
373 if (nxmHeader.isExperimenter()) {
374 throw new IllegalArgumentException("Cannot fit experimenter source choice on a uint32 header");
376 return nxmHeader.toLong();
380 * Resolves a uint64 representation of a possibly experimenter
381 * OXM/NXM header for the field given as {@code srcChoice}.
383 * @param srcChoice the destination choice field.
384 * @return the OXM/NXM header as uint64 {@code BigInteger}.
386 static BigInteger resolveSrcHeaderUint64(SrcChoice srcChoice) {
387 return srcChoice instanceof SrcNxRegCase
388 ? REG_SRC_CHOICE_TO_NXMHEADER.get(srcChoice).toBigInteger()
389 : SRC_CHOICE_TYPE_TO_NXMHEADER.get(srcChoice.implementedInterface()).toBigInteger();
393 * Check if the source choice field is experimenter.
395 * @param srcChoice the source choice field.
396 * @return true if experimenter.
398 static boolean isExperimenter(SrcChoice srcChoice) {
399 return srcChoice instanceof SrcNxRegCase
400 ? REG_SRC_CHOICE_TO_NXMHEADER.get(srcChoice).isExperimenter()
401 : SRC_CHOICE_TYPE_TO_NXMHEADER.get(srcChoice.implementedInterface()).isExperimenter();
405 * Check if the destination choice field is experimenter.
407 * @param dstChoice the destination choice field.
408 * @return true if experimenter.
410 static boolean isExperimenter(DstChoice dstChoice) {
411 return dstChoice instanceof DstNxRegCase
412 ? REG_DST_CHOICE_TO_NXMHEADER.get(dstChoice).isExperimenter()
413 : DST_CHOICE_TYPE_TO_NXMHEADER.get(dstChoice.implementedInterface()).isExperimenter();