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