PostHandshakeNodeProducer help class
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / main / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / action / RegMoveConvertor.java
1 /**
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  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 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action;
9
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.openflowjava.nx.NiciraMatchCodecs;
12 import org.opendaylight.openflowjava.nx.codec.match.NxmHeader;
13 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
14 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
15 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
16 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionRegMove;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionRegMoveBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.move.grouping.NxActionRegMove;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.move.grouping.NxActionRegMoveBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg2;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg3;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg7;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.NxActionRegMoveGrouping;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.DstChoice;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpShaCase;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpShaCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpThaCase;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpThaCaseBuilder;
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.DstNxTunIdCase;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIdCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpOpCase;
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.DstOfArpSpaCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpSpaCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpTpaCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpTpaCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfEthDstCase;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfEthDstCaseBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfEthSrcCase;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfEthSrcCaseBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flows.statistics.update.flow.and.statistics.map.list.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegMoveNotifFlowsStatisticsUpdateApplyActionsCaseBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flows.statistics.update.flow.and.statistics.map.list.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionRegMoveNotifFlowsStatisticsUpdateWriteActionsCaseBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.group.desc.stats.updated.group.desc.stats.buckets.bucket.action.action.NxActionRegMoveNotifGroupDescStatsUpdatedCaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionRegMoveNodesNodeTableFlowWriteActionsCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.NxRegMove;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.NxRegMoveBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.Dst;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.DstBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.Src;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.SrcBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.SrcChoice;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxArpShaCase;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxArpShaCaseBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxArpThaCase;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxArpThaCaseBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxRegCase;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxRegCaseBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxTunIdCase;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxTunIdCaseBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpOpCase;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpOpCaseBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpSpaCase;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpSpaCaseBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpTpaCase;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpTpaCaseBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfEthDstCase;
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.SrcOfEthSrcCase;
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.SrcOfEthTypeCase;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfEthTypeCaseBuilder;
83
84 /**
85  * @author msunal
86  */
87 public class RegMoveConvertor implements
88         ConvertorActionToOFJava<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, Action>,
89         ConvertorActionFromOFJava<Action, ActionPath> {
90
91     @Override
92     public org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action convert(Action input, ActionPath path) {
93         NxActionRegMove actionRegMove = ((ActionRegMove) input.getActionChoice()).getNxActionRegMove();
94         DstBuilder dstBuilder = new DstBuilder();
95         dstBuilder.setDstChoice(resolveDst(actionRegMove.getDst()));
96         dstBuilder.setStart(actionRegMove.getDstOfs());
97         dstBuilder.setEnd(actionRegMove.getDstOfs() + actionRegMove.getNBits() - 1);
98         SrcBuilder srcBuilder = new SrcBuilder();
99         srcBuilder.setSrcChoice(resolveSrc(actionRegMove.getSrc()));
100         srcBuilder.setStart(actionRegMove.getSrcOfs());
101         srcBuilder.setEnd(actionRegMove.getSrcOfs() + actionRegMove.getNBits() - 1);
102         NxRegMoveBuilder nxRegMoveBuilder = new NxRegMoveBuilder();
103         nxRegMoveBuilder.setDst(dstBuilder.build());
104         nxRegMoveBuilder.setSrc(srcBuilder.build());
105         return resolveAction(nxRegMoveBuilder.build(), path);
106     }
107
108     public static DstChoice resolveDst(long dstValue) {
109         Class<? extends NxmNxReg> potentialDst = resolveReg(dstValue);
110         if (potentialDst != null) {
111             return new DstNxRegCaseBuilder().setNxReg(potentialDst).build();
112         }
113         if (dstValue == NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toLong()) {
114             return new DstNxTunIdCaseBuilder().setNxTunId(true).build();
115         }
116         if (dstValue == NiciraMatchCodecs.ARP_SHA_CODEC.getHeaderWithoutHasMask().toLong()) {
117             return new DstNxArpShaCaseBuilder().setNxArpSha(true).build();
118         }
119         if (dstValue == NiciraMatchCodecs.ARP_THA_CODEC.getHeaderWithoutHasMask().toLong()) {
120             return new DstNxArpThaCaseBuilder().setNxArpTha(true).build();
121         }
122         if (dstValue == NiciraMatchCodecs.ARP_OP_CODEC.getHeaderWithoutHasMask().toLong()) {
123             return new DstOfArpOpCaseBuilder().setOfArpOp(true).build();
124         }
125         if (dstValue == NiciraMatchCodecs.ARP_SPA_CODEC.getHeaderWithoutHasMask().toLong()) {
126             return new DstOfArpSpaCaseBuilder().setOfArpSpa(true).build();
127         }
128         if (dstValue == NiciraMatchCodecs.ARP_TPA_CODEC.getHeaderWithoutHasMask().toLong()) {
129             return new DstOfArpTpaCaseBuilder().setOfArpTpa(true).build();
130         }
131         if (dstValue == NiciraMatchCodecs.ETH_DST_CODEC.getHeaderWithoutHasMask().toLong()) {
132             return new DstOfEthDstCaseBuilder().setOfEthDst(true).build();
133         }
134         if (dstValue == NiciraMatchCodecs.ETH_SRC_CODEC.getHeaderWithoutHasMask().toLong()) {
135             return new DstOfEthSrcCaseBuilder().setOfEthSrc(true).build();
136         }
137         throw new CodecPreconditionException("Missing codec for " + new NxmHeader(dstValue));
138     }
139
140     static SrcChoice resolveSrc(long srcValue) {
141         Class<? extends NxmNxReg> potentialSrc = resolveReg(srcValue);
142         if (potentialSrc != null) {
143             return new SrcNxRegCaseBuilder().setNxReg(potentialSrc).build();
144         }
145         if (srcValue == NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toLong()) {
146             return new SrcNxTunIdCaseBuilder().setNxTunId(true).build();
147         }
148         if (srcValue == NiciraMatchCodecs.ARP_SHA_CODEC.getHeaderWithoutHasMask().toLong()) {
149             return new SrcNxArpShaCaseBuilder().setNxArpSha(true).build();
150         }
151         if (srcValue == NiciraMatchCodecs.ARP_THA_CODEC.getHeaderWithoutHasMask().toLong()) {
152             return new SrcNxArpThaCaseBuilder().setNxArpTha(true).build();
153         }
154         if (srcValue == NiciraMatchCodecs.ARP_OP_CODEC.getHeaderWithoutHasMask().toLong()) {
155             return new SrcOfArpOpCaseBuilder().setOfArpOp(true).build();
156         }
157         if (srcValue == NiciraMatchCodecs.ARP_SPA_CODEC.getHeaderWithoutHasMask().toLong()) {
158             return new SrcOfArpSpaCaseBuilder().setOfArpSpa(true).build();
159         }
160         if (srcValue == NiciraMatchCodecs.ARP_TPA_CODEC.getHeaderWithoutHasMask().toLong()) {
161             return new SrcOfArpTpaCaseBuilder().setOfArpTpa(true).build();
162         }
163         if (srcValue == NiciraMatchCodecs.ETH_DST_CODEC.getHeaderWithoutHasMask().toLong()) {
164             return new SrcOfEthDstCaseBuilder().setOfEthDst(true).build();
165         }
166         if (srcValue == NiciraMatchCodecs.ETH_SRC_CODEC.getHeaderWithoutHasMask().toLong()) {
167             return new SrcOfEthSrcCaseBuilder().setOfEthSrc(true).build();
168         }
169         if (srcValue == NiciraMatchCodecs.ETH_TYPE_CODEC.getHeaderWithoutHasMask().toLong()) {
170             return new SrcOfEthTypeCaseBuilder().setOfEthType(true).build();
171         }
172         throw new CodecPreconditionException("Missing codec for " + new NxmHeader(srcValue));
173     }
174
175     private static Class<? extends NxmNxReg> resolveReg(long value) {
176         if (value == NiciraMatchCodecs.REG0_CODEC.getHeaderWithoutHasMask().toLong()) {
177             return NxmNxReg0.class;
178         }
179         if (value == NiciraMatchCodecs.REG1_CODEC.getHeaderWithoutHasMask().toLong()) {
180             return NxmNxReg1.class;
181         }
182         if (value == NiciraMatchCodecs.REG2_CODEC.getHeaderWithoutHasMask().toLong()) {
183             return NxmNxReg2.class;
184         }
185         if (value == NiciraMatchCodecs.REG3_CODEC.getHeaderWithoutHasMask().toLong()) {
186             return NxmNxReg3.class;
187         }
188         if (value == NiciraMatchCodecs.REG4_CODEC.getHeaderWithoutHasMask().toLong()) {
189             return NxmNxReg4.class;
190         }
191         if (value == NiciraMatchCodecs.REG5_CODEC.getHeaderWithoutHasMask().toLong()) {
192             return NxmNxReg5.class;
193         }
194         if (value == NiciraMatchCodecs.REG6_CODEC.getHeaderWithoutHasMask().toLong()) {
195             return NxmNxReg6.class;
196         }
197         if (value == NiciraMatchCodecs.REG7_CODEC.getHeaderWithoutHasMask().toLong()) {
198             return NxmNxReg7.class;
199         }
200         return null;
201     }
202
203     private static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action resolveAction(
204             NxRegMove value, ActionPath path) {
205         switch (path) {
206             case NODES_NODE_TABLE_FLOW_INSTRUCTIONS_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION_EXTENSIONLIST_EXTENSION:
207                 return new NxActionRegMoveNodesNodeTableFlowWriteActionsCaseBuilder().setNxRegMove(value).build();
208             case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION:
209                 return new NxActionRegMoveNotifFlowsStatisticsUpdateWriteActionsCaseBuilder().setNxRegMove(value).build();
210             case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION:
211                 return new NxActionRegMoveNotifFlowsStatisticsUpdateApplyActionsCaseBuilder().setNxRegMove(value).build();
212             case GROUPDESCSTATSUPDATED_GROUPDESCSTATS_BUCKETS_BUCKET_ACTION:
213                 return new NxActionRegMoveNotifGroupDescStatsUpdatedCaseBuilder().setNxRegMove(value).build();
214             default:
215                 throw new CodecPreconditionException(path);
216         }
217     }
218
219     @Override
220     public Action convert(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nxActionArg) {
221         Preconditions.checkArgument(nxActionArg instanceof NxActionRegMoveGrouping);
222         NxActionRegMoveGrouping nxAction = (NxActionRegMoveGrouping) nxActionArg;
223
224         Dst dst = nxAction.getNxRegMove().getDst();
225         Src src = nxAction.getNxRegMove().getSrc();
226         ActionRegMoveBuilder actionRegMoveBuilder = new ActionRegMoveBuilder();
227         NxActionRegMoveBuilder nxActionRegMove = new NxActionRegMoveBuilder();
228
229         nxActionRegMove.setDst(resolveDst(dst.getDstChoice()));
230         nxActionRegMove.setDstOfs(dst.getStart());
231         nxActionRegMove.setSrc(resolveSrc(src.getSrcChoice()));
232         nxActionRegMove.setSrcOfs(src.getStart());
233         nxActionRegMove.setNBits(dst.getEnd() - dst.getStart() + 1);
234         nxActionRegMove.setExperimenterId(ActionUtil.EXPERIMENTER_ID);
235         actionRegMoveBuilder.setNxActionRegMove(nxActionRegMove.build());
236         return ActionUtil.createAction(actionRegMoveBuilder.build());
237     }
238
239     public static long resolveDst(DstChoice dstChoice) {
240         if (dstChoice instanceof DstNxRegCase) {
241             return resolveReg(((DstNxRegCase) dstChoice).getNxReg());
242         }
243         if (dstChoice instanceof DstNxTunIdCase) {
244             return NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toLong();
245         }
246         if (dstChoice instanceof DstNxArpShaCase) {
247             return NiciraMatchCodecs.ARP_SHA_CODEC.getHeaderWithoutHasMask().toLong();
248         }
249         if (dstChoice instanceof DstNxArpThaCase) {
250             return NiciraMatchCodecs.ARP_THA_CODEC.getHeaderWithoutHasMask().toLong();
251         }
252         if (dstChoice instanceof DstOfArpOpCase) {
253             return NiciraMatchCodecs.ARP_OP_CODEC.getHeaderWithoutHasMask().toLong();
254         }
255         if (dstChoice instanceof DstOfArpSpaCase) {
256             return NiciraMatchCodecs.ARP_SPA_CODEC.getHeaderWithoutHasMask().toLong();
257         }
258         if (dstChoice instanceof DstOfArpTpaCase) {
259             return NiciraMatchCodecs.ARP_TPA_CODEC.getHeaderWithoutHasMask().toLong();
260         }
261         if (dstChoice instanceof DstOfEthDstCase) {
262             return NiciraMatchCodecs.ETH_DST_CODEC.getHeaderWithoutHasMask().toLong();
263         }
264         if (dstChoice instanceof DstOfEthSrcCase) {
265             return NiciraMatchCodecs.ETH_SRC_CODEC.getHeaderWithoutHasMask().toLong();
266         }
267         throw new CodecPreconditionException("Missing implementation of a case in dst-choice? " + dstChoice.getClass());
268     }
269
270     static long resolveSrc(SrcChoice srcChoice) {
271         if (srcChoice instanceof SrcNxRegCase) {
272             return resolveReg(((SrcNxRegCase) srcChoice).getNxReg());
273         }
274         if (srcChoice instanceof SrcNxTunIdCase) {
275             return NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toLong();
276         }
277         if (srcChoice instanceof SrcNxArpShaCase) {
278             return NiciraMatchCodecs.ARP_SHA_CODEC.getHeaderWithoutHasMask().toLong();
279         }
280         if (srcChoice instanceof SrcNxArpThaCase) {
281             return NiciraMatchCodecs.ARP_THA_CODEC.getHeaderWithoutHasMask().toLong();
282         }
283         if (srcChoice instanceof SrcOfArpOpCase) {
284             return NiciraMatchCodecs.ARP_OP_CODEC.getHeaderWithoutHasMask().toLong();
285         }
286         if (srcChoice instanceof SrcOfArpSpaCase) {
287             return NiciraMatchCodecs.ARP_SPA_CODEC.getHeaderWithoutHasMask().toLong();
288         }
289         if (srcChoice instanceof SrcOfArpTpaCase) {
290             return NiciraMatchCodecs.ARP_TPA_CODEC.getHeaderWithoutHasMask().toLong();
291         }
292         if (srcChoice instanceof SrcOfEthDstCase) {
293             return NiciraMatchCodecs.ETH_DST_CODEC.getHeaderWithoutHasMask().toLong();
294         }
295         if (srcChoice instanceof SrcOfEthSrcCase) {
296             return NiciraMatchCodecs.ETH_SRC_CODEC.getHeaderWithoutHasMask().toLong();
297         }
298         if (srcChoice instanceof SrcOfEthTypeCase) {
299             return NiciraMatchCodecs.ETH_TYPE_CODEC.getHeaderWithoutHasMask().toLong();
300         }
301         throw new CodecPreconditionException("Missing implementation of a case in dst-choice? " + srcChoice.getClass());
302     }
303
304     private static long resolveReg(Class<? extends NxmNxReg> reg) {
305         if (reg.equals(NxmNxReg0.class)) {
306             return NiciraMatchCodecs.REG0_CODEC.getHeaderWithoutHasMask().toLong();
307         }
308         if (reg.equals(NxmNxReg1.class)) {
309             return NiciraMatchCodecs.REG1_CODEC.getHeaderWithoutHasMask().toLong();
310         }
311         if (reg.equals(NxmNxReg2.class)) {
312             return NiciraMatchCodecs.REG2_CODEC.getHeaderWithoutHasMask().toLong();
313         }
314         if (reg.equals(NxmNxReg3.class)) {
315             return NiciraMatchCodecs.REG3_CODEC.getHeaderWithoutHasMask().toLong();
316         }
317         if (reg.equals(NxmNxReg4.class)) {
318             return NiciraMatchCodecs.REG4_CODEC.getHeaderWithoutHasMask().toLong();
319         }
320         if (reg.equals(NxmNxReg5.class)) {
321             return NiciraMatchCodecs.REG5_CODEC.getHeaderWithoutHasMask().toLong();
322         }
323         if (reg.equals(NxmNxReg6.class)) {
324             return NiciraMatchCodecs.REG6_CODEC.getHeaderWithoutHasMask().toLong();
325         }
326         if (reg.equals(NxmNxReg7.class)) {
327             return NiciraMatchCodecs.REG7_CODEC.getHeaderWithoutHasMask().toLong();
328         }
329         throw new CodecPreconditionException("Missing codec for nxm_nx_reg?" + reg);
330     }
331
332 }