2 * Copyright (c) 2014 Cisco Systems, Inc. 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
8 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action;
10 import org.opendaylight.openflowjava.nx.NiciraMatchCodecs;
11 import org.opendaylight.openflowjava.nx.codec.match.NxmHeader;
12 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
13 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
14 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
15 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.NxmNxRegMove;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.OfjAugNxAction;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.OfjAugNxActionBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.move.grouping.ActionRegMove;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.move.grouping.ActionRegMoveBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg2;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg3;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg7;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.NxActionRegMoveGrouping;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.DstChoice;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpShaCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpShaCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpThaCase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpThaCaseBuilder;
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.DstNxTunIdCase;
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.DstNxTunIpv4DstCase;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIpv4DstCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIpv4SrcCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIpv4SrcCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpOpCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpOpCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpSpaCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpSpaCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpTpaCase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpTpaCaseBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfEthDstCase;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfEthDstCaseBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfEthSrcCase;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfEthSrcCaseBuilder;
55 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;
56 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;
57 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;
58 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;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.NxRegMove;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.NxRegMoveBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.Dst;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.DstBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.Src;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.SrcBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.SrcChoice;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxArpShaCase;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxArpShaCaseBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxArpThaCase;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxArpThaCaseBuilder;
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.SrcNxTunIdCase;
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.SrcNxTunIpv4DstCase;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxTunIpv4DstCaseBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxTunIpv4SrcCase;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxTunIpv4SrcCaseBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpOpCase;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpOpCaseBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpSpaCase;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpSpaCaseBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpTpaCase;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpTpaCaseBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfEthDstCase;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfEthDstCaseBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfEthSrcCase;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfEthSrcCaseBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfEthTypeCase;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfEthTypeCaseBuilder;
91 import com.google.common.base.Preconditions;
97 public class RegMoveConvertor implements
98 ConvertorActionToOFJava<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, Action>,
99 ConvertorActionFromOFJava<Action, ActionPath> {
102 public org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action convert(Action input, ActionPath path) {
103 ActionRegMove actionRegMove = input.getAugmentation(OfjAugNxAction.class).getActionRegMove();
104 DstBuilder dstBuilder = new DstBuilder();
105 dstBuilder.setDstChoice(resolveDst(actionRegMove.getDst()));
106 dstBuilder.setStart(actionRegMove.getDstOfs());
107 dstBuilder.setEnd(actionRegMove.getDstOfs() + actionRegMove.getNBits() - 1);
108 SrcBuilder srcBuilder = new SrcBuilder();
109 srcBuilder.setSrcChoice(resolveSrc(actionRegMove.getSrc()));
110 srcBuilder.setStart(actionRegMove.getSrcOfs());
111 srcBuilder.setEnd(actionRegMove.getSrcOfs() + actionRegMove.getNBits() - 1);
112 NxRegMoveBuilder nxRegMoveBuilder = new NxRegMoveBuilder();
113 nxRegMoveBuilder.setDst(dstBuilder.build());
114 nxRegMoveBuilder.setSrc(srcBuilder.build());
115 return resolveAction(nxRegMoveBuilder.build(), path);
118 public static DstChoice resolveDst(long dstValue) {
119 Class<? extends NxmNxReg> potentialDst = resolveReg(dstValue);
120 if (potentialDst != null) {
121 return new DstNxRegCaseBuilder().setNxReg(potentialDst).build();
123 if (dstValue == NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toLong()) {
124 return new DstNxTunIdCaseBuilder().setNxTunId(true).build();
126 if (dstValue == NiciraMatchCodecs.ARP_SHA_CODEC.getHeaderWithoutHasMask().toLong()) {
127 return new DstNxArpShaCaseBuilder().setNxArpSha(true).build();
129 if (dstValue == NiciraMatchCodecs.ARP_THA_CODEC.getHeaderWithoutHasMask().toLong()) {
130 return new DstNxArpThaCaseBuilder().setNxArpTha(true).build();
132 if (dstValue == NiciraMatchCodecs.ARP_OP_CODEC.getHeaderWithoutHasMask().toLong()) {
133 return new DstOfArpOpCaseBuilder().setOfArpOp(true).build();
135 if (dstValue == NiciraMatchCodecs.ARP_SPA_CODEC.getHeaderWithoutHasMask().toLong()) {
136 return new DstOfArpSpaCaseBuilder().setOfArpSpa(true).build();
138 if (dstValue == NiciraMatchCodecs.ARP_TPA_CODEC.getHeaderWithoutHasMask().toLong()) {
139 return new DstOfArpTpaCaseBuilder().setOfArpTpa(true).build();
141 if (dstValue == NiciraMatchCodecs.TUN_IPV4_DST_CODEC.getHeaderWithoutHasMask().toLong()) {
142 return new DstNxTunIpv4DstCaseBuilder().setNxTunIpv4Dst(true).build();
144 if (dstValue == NiciraMatchCodecs.TUN_IPV4_SRC_CODEC.getHeaderWithoutHasMask().toLong()) {
145 return new DstNxTunIpv4SrcCaseBuilder().setNxTunIpv4Src(true).build();
147 if (dstValue == NiciraMatchCodecs.ETH_DST_CODEC.getHeaderWithoutHasMask().toLong()) {
148 return new DstOfEthDstCaseBuilder().setOfEthDst(true).build();
150 if (dstValue == NiciraMatchCodecs.ETH_SRC_CODEC.getHeaderWithoutHasMask().toLong()) {
151 return new DstOfEthSrcCaseBuilder().setOfEthSrc(true).build();
153 throw new CodecPreconditionException("Missing codec for " + new NxmHeader(dstValue));
156 static SrcChoice resolveSrc(long srcValue) {
157 Class<? extends NxmNxReg> potentialSrc = resolveReg(srcValue);
158 if (potentialSrc != null) {
159 return new SrcNxRegCaseBuilder().setNxReg(potentialSrc).build();
161 if (srcValue == NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toLong()) {
162 return new SrcNxTunIdCaseBuilder().setNxTunId(true).build();
164 if (srcValue == NiciraMatchCodecs.ARP_SHA_CODEC.getHeaderWithoutHasMask().toLong()) {
165 return new SrcNxArpShaCaseBuilder().setNxArpSha(true).build();
167 if (srcValue == NiciraMatchCodecs.ARP_THA_CODEC.getHeaderWithoutHasMask().toLong()) {
168 return new SrcNxArpThaCaseBuilder().setNxArpTha(true).build();
170 if (srcValue == NiciraMatchCodecs.ARP_OP_CODEC.getHeaderWithoutHasMask().toLong()) {
171 return new SrcOfArpOpCaseBuilder().setOfArpOp(true).build();
173 if (srcValue == NiciraMatchCodecs.ARP_SPA_CODEC.getHeaderWithoutHasMask().toLong()) {
174 return new SrcOfArpSpaCaseBuilder().setOfArpSpa(true).build();
176 if (srcValue == NiciraMatchCodecs.ARP_TPA_CODEC.getHeaderWithoutHasMask().toLong()) {
177 return new SrcOfArpTpaCaseBuilder().setOfArpTpa(true).build();
179 if (srcValue == NiciraMatchCodecs.TUN_IPV4_DST_CODEC.getHeaderWithoutHasMask().toLong()) {
180 return new SrcNxTunIpv4DstCaseBuilder().setNxTunIpv4Dst(true).build();
182 if (srcValue == NiciraMatchCodecs.TUN_IPV4_SRC_CODEC.getHeaderWithoutHasMask().toLong()) {
183 return new SrcNxTunIpv4SrcCaseBuilder().setNxTunIpv4Src(true).build();
185 if (srcValue == NiciraMatchCodecs.ETH_DST_CODEC.getHeaderWithoutHasMask().toLong()) {
186 return new SrcOfEthDstCaseBuilder().setOfEthDst(true).build();
188 if (srcValue == NiciraMatchCodecs.ETH_SRC_CODEC.getHeaderWithoutHasMask().toLong()) {
189 return new SrcOfEthSrcCaseBuilder().setOfEthSrc(true).build();
191 if (srcValue == NiciraMatchCodecs.ETH_TYPE_CODEC.getHeaderWithoutHasMask().toLong()) {
192 return new SrcOfEthTypeCaseBuilder().setOfEthType(true).build();
194 throw new CodecPreconditionException("Missing codec for " + new NxmHeader(srcValue));
197 private static Class<? extends NxmNxReg> resolveReg(long value) {
198 if (value == NiciraMatchCodecs.REG0_CODEC.getHeaderWithoutHasMask().toLong()) {
199 return NxmNxReg0.class;
201 if (value == NiciraMatchCodecs.REG1_CODEC.getHeaderWithoutHasMask().toLong()) {
202 return NxmNxReg1.class;
204 if (value == NiciraMatchCodecs.REG2_CODEC.getHeaderWithoutHasMask().toLong()) {
205 return NxmNxReg2.class;
207 if (value == NiciraMatchCodecs.REG3_CODEC.getHeaderWithoutHasMask().toLong()) {
208 return NxmNxReg3.class;
210 if (value == NiciraMatchCodecs.REG4_CODEC.getHeaderWithoutHasMask().toLong()) {
211 return NxmNxReg4.class;
213 if (value == NiciraMatchCodecs.REG5_CODEC.getHeaderWithoutHasMask().toLong()) {
214 return NxmNxReg5.class;
216 if (value == NiciraMatchCodecs.REG6_CODEC.getHeaderWithoutHasMask().toLong()) {
217 return NxmNxReg6.class;
219 if (value == NiciraMatchCodecs.REG7_CODEC.getHeaderWithoutHasMask().toLong()) {
220 return NxmNxReg7.class;
225 private static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action resolveAction(
226 NxRegMove value, ActionPath path) {
228 case NODES_NODE_TABLE_FLOW_INSTRUCTIONS_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION_EXTENSIONLIST_EXTENSION:
229 return new NxActionRegMoveNodesNodeTableFlowWriteActionsCaseBuilder().setNxRegMove(value).build();
230 case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION:
231 return new NxActionRegMoveNotifFlowsStatisticsUpdateWriteActionsCaseBuilder().setNxRegMove(value).build();
232 case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION:
233 return new NxActionRegMoveNotifFlowsStatisticsUpdateApplyActionsCaseBuilder().setNxRegMove(value).build();
234 case GROUPDESCSTATSUPDATED_GROUPDESCSTATS_BUCKETS_BUCKET_ACTION:
235 return new NxActionRegMoveNotifGroupDescStatsUpdatedCaseBuilder().setNxRegMove(value).build();
237 throw new CodecPreconditionException(path);
242 public Action convert(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nxActionArg) {
243 Preconditions.checkArgument(nxActionArg instanceof NxActionRegMoveGrouping);
244 NxActionRegMoveGrouping nxAction = (NxActionRegMoveGrouping) nxActionArg;
246 Dst dst = nxAction.getNxRegMove().getDst();
247 Src src = nxAction.getNxRegMove().getSrc();
248 ActionRegMoveBuilder actionRegMoveBuilder = new ActionRegMoveBuilder();
249 actionRegMoveBuilder.setDst(resolveDst(dst.getDstChoice()));
250 actionRegMoveBuilder.setDstOfs(dst.getStart());
251 actionRegMoveBuilder.setSrc(resolveSrc(src.getSrcChoice()));
252 actionRegMoveBuilder.setSrcOfs(src.getStart());
253 actionRegMoveBuilder.setNBits(dst.getEnd() - dst.getStart() + 1);
254 OfjAugNxActionBuilder augNxActionBuilder = new OfjAugNxActionBuilder();
255 augNxActionBuilder.setActionRegMove(actionRegMoveBuilder.build());
256 return ActionUtil.createNiciraAction(augNxActionBuilder.build(), NxmNxRegMove.class);
259 public static long resolveDst(DstChoice dstChoice) {
260 if (dstChoice instanceof DstNxRegCase) {
261 return resolveReg(((DstNxRegCase) dstChoice).getNxReg());
263 if (dstChoice instanceof DstNxTunIdCase) {
264 return NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toLong();
266 if (dstChoice instanceof DstNxArpShaCase) {
267 return NiciraMatchCodecs.ARP_SHA_CODEC.getHeaderWithoutHasMask().toLong();
269 if (dstChoice instanceof DstNxArpThaCase) {
270 return NiciraMatchCodecs.ARP_THA_CODEC.getHeaderWithoutHasMask().toLong();
272 if (dstChoice instanceof DstOfArpOpCase) {
273 return NiciraMatchCodecs.ARP_OP_CODEC.getHeaderWithoutHasMask().toLong();
275 if (dstChoice instanceof DstOfArpSpaCase) {
276 return NiciraMatchCodecs.ARP_SPA_CODEC.getHeaderWithoutHasMask().toLong();
278 if (dstChoice instanceof DstOfArpTpaCase) {
279 return NiciraMatchCodecs.ARP_TPA_CODEC.getHeaderWithoutHasMask().toLong();
281 if (dstChoice instanceof DstNxTunIpv4DstCase) {
282 return NiciraMatchCodecs.TUN_IPV4_DST_CODEC.getHeaderWithoutHasMask().toLong();
284 if (dstChoice instanceof DstNxTunIpv4SrcCase) {
285 return NiciraMatchCodecs.TUN_IPV4_SRC_CODEC.getHeaderWithoutHasMask().toLong();
287 if (dstChoice instanceof DstOfEthDstCase) {
288 return NiciraMatchCodecs.ETH_DST_CODEC.getHeaderWithoutHasMask().toLong();
290 if (dstChoice instanceof DstOfEthSrcCase) {
291 return NiciraMatchCodecs.ETH_SRC_CODEC.getHeaderWithoutHasMask().toLong();
293 throw new CodecPreconditionException("Missing implementation of a case in dst-choice? " + dstChoice.getClass());
296 static long resolveSrc(SrcChoice srcChoice) {
297 if (srcChoice instanceof SrcNxRegCase) {
298 return resolveReg(((SrcNxRegCase) srcChoice).getNxReg());
300 if (srcChoice instanceof SrcNxTunIdCase) {
301 return NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toLong();
303 if (srcChoice instanceof SrcNxArpShaCase) {
304 return NiciraMatchCodecs.ARP_SHA_CODEC.getHeaderWithoutHasMask().toLong();
306 if (srcChoice instanceof SrcNxArpThaCase) {
307 return NiciraMatchCodecs.ARP_THA_CODEC.getHeaderWithoutHasMask().toLong();
309 if (srcChoice instanceof SrcOfArpOpCase) {
310 return NiciraMatchCodecs.ARP_OP_CODEC.getHeaderWithoutHasMask().toLong();
312 if (srcChoice instanceof SrcOfArpSpaCase) {
313 return NiciraMatchCodecs.ARP_SPA_CODEC.getHeaderWithoutHasMask().toLong();
315 if (srcChoice instanceof SrcOfArpTpaCase) {
316 return NiciraMatchCodecs.ARP_TPA_CODEC.getHeaderWithoutHasMask().toLong();
318 if (srcChoice instanceof SrcNxTunIpv4DstCase) {
319 return NiciraMatchCodecs.TUN_IPV4_DST_CODEC.getHeaderWithoutHasMask().toLong();
321 if (srcChoice instanceof SrcNxTunIpv4SrcCase) {
322 return NiciraMatchCodecs.TUN_IPV4_SRC_CODEC.getHeaderWithoutHasMask().toLong();
324 if (srcChoice instanceof SrcOfEthDstCase) {
325 return NiciraMatchCodecs.ETH_DST_CODEC.getHeaderWithoutHasMask().toLong();
327 if (srcChoice instanceof SrcOfEthSrcCase) {
328 return NiciraMatchCodecs.ETH_SRC_CODEC.getHeaderWithoutHasMask().toLong();
330 if (srcChoice instanceof SrcOfEthTypeCase) {
331 return NiciraMatchCodecs.ETH_TYPE_CODEC.getHeaderWithoutHasMask().toLong();
333 throw new CodecPreconditionException("Missing implementation of a case in dst-choice? " + srcChoice.getClass());
336 private static long resolveReg(Class<? extends NxmNxReg> reg) {
337 if (reg.equals(NxmNxReg0.class)) {
338 return NiciraMatchCodecs.REG0_CODEC.getHeaderWithoutHasMask().toLong();
340 if (reg.equals(NxmNxReg1.class)) {
341 return NiciraMatchCodecs.REG1_CODEC.getHeaderWithoutHasMask().toLong();
343 if (reg.equals(NxmNxReg2.class)) {
344 return NiciraMatchCodecs.REG2_CODEC.getHeaderWithoutHasMask().toLong();
346 if (reg.equals(NxmNxReg3.class)) {
347 return NiciraMatchCodecs.REG3_CODEC.getHeaderWithoutHasMask().toLong();
349 if (reg.equals(NxmNxReg4.class)) {
350 return NiciraMatchCodecs.REG4_CODEC.getHeaderWithoutHasMask().toLong();
352 if (reg.equals(NxmNxReg5.class)) {
353 return NiciraMatchCodecs.REG5_CODEC.getHeaderWithoutHasMask().toLong();
355 if (reg.equals(NxmNxReg6.class)) {
356 return NiciraMatchCodecs.REG6_CODEC.getHeaderWithoutHasMask().toLong();
358 if (reg.equals(NxmNxReg7.class)) {
359 return NiciraMatchCodecs.REG7_CODEC.getHeaderWithoutHasMask().toLong();
361 throw new CodecPreconditionException("Missing codec for nxm_nx_reg?" + reg);