1bdc11b51e33ad2c4c99fd36ee76b038ffe5852d
[netvirt.git] / sfc / classifier / impl / src / main / java / org / opendaylight / netvirt / sfc / classifier / utils / OpenFlow13Utils.java
1 /*
2  * Copyright © 2017 Ericsson, 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.netvirt.sfc.classifier.utils;
9
10 import java.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.PacketTypeMatch;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.PacketTypeMatchBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg2;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.DstChoice;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxNshc1CaseBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxNshc2CaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxNshc4CaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxNsiCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxNspCaseBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxRegCase;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxRegCaseBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIdCaseBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIpv4DstCaseBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.group.buckets.bucket.action.action.NxActionRegLoadNodesNodeGroupBucketsBucketActionsCaseBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.group.buckets.bucket.action.action.NxActionRegMoveNodesNodeGroupBucketsBucketActionsCaseBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionDecapNodesNodeTableFlowApplyActionsCaseBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionEncapNodesNodeTableFlowApplyActionsCaseBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegMoveNodesNodeTableFlowApplyActionsCaseBuilder;
68 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.NxActionResubmitNodesNodeTableFlowWriteActionsCaseBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.decap.grouping.NxDecap;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.decap.grouping.NxDecapBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.encap.grouping.NxEncap;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.encap.grouping.NxEncapBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoad;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoadBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.nx.reg.load.Dst;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.nx.reg.load.DstBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.NxRegMove;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.NxRegMoveBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.SrcBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.resubmit.grouping.NxResubmitBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.SrcChoice;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxNshc4CaseBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxRegCaseBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxTunIdCaseBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNsiKey;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNspKey;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg2Key;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIdKey;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIpv4DstKey;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsi.grouping.NxmNxNsiBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsp.grouping.NxmNxNspBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.reg.grouping.NxmNxReg;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.reg.grouping.NxmNxRegBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.id.grouping.NxmNxTunIdBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.ipv4.dst.grouping.NxmNxTunIpv4DstBuilder;
98
99 public final class OpenFlow13Utils {
100     public static final long ETHERTYPE_NSH = 0x894f;
101     public static final long PACKET_TYPE_NSH = 0x1894f;
102     public static final long PACKET_TYPE_ETH = 0;
103
104     private OpenFlow13Utils() {
105     }
106
107     public static void addMatchTunId(MatchBuilder match, long value) {
108         NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
109                 .setNxmNxTunId(new NxmNxTunIdBuilder().setValue(BigInteger.valueOf(value)).build()).build();
110         addExtension(match, NxmNxTunIdKey.class, am);
111     }
112
113     public static void addMatchTunDstIp(MatchBuilder match, Ipv4Address ipv4Address) {
114         NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
115                 .setNxmNxTunIpv4Dst(new NxmNxTunIpv4DstBuilder().setIpv4Address(ipv4Address).build()).build();
116         addExtension(match, NxmNxTunIpv4DstKey.class, am);
117     }
118
119     public static void addMatchEthNsh(MatchBuilder match) {
120         EtherType etherType = new EtherType(ETHERTYPE_NSH);
121         EthernetType ethernetType = new EthernetTypeBuilder().setType(etherType).build();
122         EthernetMatch ethernetMatch = new EthernetMatchBuilder().setEthernetType(ethernetType).build();
123         match.setEthernetMatch(ethernetMatch);
124     }
125
126     public static void addMatchPacketTypeNsh(MatchBuilder match) {
127         PacketTypeMatch packetTypeMatch = new PacketTypeMatchBuilder().setPacketType(PACKET_TYPE_NSH).build();
128         match.setPacketTypeMatch(packetTypeMatch);
129     }
130
131     public static void addMatchInPort(MatchBuilder match, NodeId nodeId, long inPort) {
132         match.setInPort(new NodeConnectorId(nodeId.getValue() + ":" + inPort));
133     }
134
135     public static void addMatchNsp(MatchBuilder match, long nsp) {
136         NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
137                 .setNxmNxNsp(new NxmNxNspBuilder().setValue(nsp).build()).build();
138         addExtension(match, NxmNxNspKey.class, am);
139     }
140
141     public static void addMatchNsi(MatchBuilder match, short nsi) {
142         NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
143                 .setNxmNxNsi(new NxmNxNsiBuilder().setNsi(nsi).build()).build();
144         addExtension(match, NxmNxNsiKey.class, am);
145     }
146
147     public static void addMatchReg2(MatchBuilder match, long value) {
148         NxmNxReg nxmNxReg = new NxmNxRegBuilder().setReg(NxmNxReg2.class).setValue(value).build();
149         NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxReg(nxmNxReg).build();
150         addExtension(match, NxmNxReg2Key.class, am);
151     }
152
153     private static void addExtension(MatchBuilder match, Class<? extends ExtensionKey> extensionKey,
154                                      NxAugMatchNodesNodeTableFlow am) {
155         GeneralAugMatchNodesNodeTableFlow existingAugmentations = match
156             .augmentation(GeneralAugMatchNodesNodeTableFlow.class);
157         List<ExtensionList> extensions = null;
158         if (existingAugmentations != null) {
159             extensions = existingAugmentations.getExtensionList();
160         }
161         if (extensions == null) {
162             extensions = new ArrayList<>();
163         }
164
165         extensions.add(new ExtensionListBuilder().setExtensionKey(extensionKey)
166             .setExtension(new ExtensionBuilder().addAugmentation(NxAugMatchNodesNodeTableFlow.class, am).build())
167             .build());
168
169         GeneralAugMatchNodesNodeTableFlow generalAugMatchNodesNode = new GeneralAugMatchNodesNodeTableFlowBuilder()
170             .setExtensionList(extensions).build();
171         match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, generalAugMatchNodesNode);
172     }
173
174     public static Action createActionResubmitTable(final short toTable, int order) {
175         return createActionBuilder(order)
176                 .setAction(new NxActionResubmitNodesNodeTableFlowWriteActionsCaseBuilder()
177                         .setNxResubmit(new NxResubmitBuilder()
178                                 .setTable(toTable)
179                                 .build())
180                         .build())
181                 .build();
182     }
183
184     public static Action createActionNxLoadTunIpv4Dst(long value, int order) {
185         ActionBuilder ab = createActionBuilder(order);
186         ab.setAction(nxLoadRegAction(new DstNxTunIpv4DstCaseBuilder().setNxTunIpv4Dst(Boolean.TRUE).build(),
187                 BigInteger.valueOf(value), 0,31, false));
188
189         return ab.build();
190     }
191
192     public static Action createActionNxLoadTunId(long value, int order) {
193         ActionBuilder ab = createActionBuilder(order);
194         ab.setAction(nxLoadRegAction(new DstNxTunIdCaseBuilder().setNxTunId(Boolean.TRUE).build(),
195                 BigInteger.valueOf(value), 0,31, false));
196
197         return ab.build();
198     }
199
200     public static Action createActionNxEncapNsh(int order) {
201         return createActionNxEncap(order, PACKET_TYPE_NSH);
202     }
203
204     public static Action createActionNxEncapEthernet(int order) {
205         return createActionNxEncap(order, PACKET_TYPE_ETH);
206     }
207
208     private static Action createActionNxEncap(int order, long packetType) {
209         NxEncap nxEncap = new NxEncapBuilder().setPacketType(packetType).build();
210         ActionBuilder ab = createActionBuilder(order);
211         ab.setAction(new NxActionEncapNodesNodeTableFlowApplyActionsCaseBuilder().setNxEncap(nxEncap).build());
212         return ab.build();
213     }
214
215     public static Action createActionNxDecap(int order) {
216         NxDecap nxDecap = new NxDecapBuilder().build();
217         ActionBuilder ab = createActionBuilder(order);
218         ab.setAction(new NxActionDecapNodesNodeTableFlowApplyActionsCaseBuilder().setNxDecap(nxDecap).build());
219         return ab.build();
220     }
221
222     public static Action createActionNxMoveTunIdToNsc2Register(int order) {
223         ActionBuilder ab = createActionBuilder(order);
224         ab.setAction(nxMoveRegAction(new SrcNxTunIdCaseBuilder().setNxTunId(Boolean.TRUE).build(), 0, 31,
225             new DstNxNshc2CaseBuilder().setNxNshc2Dst(Boolean.TRUE).build(), 0, 31,
226                 false));
227
228         return ab.build();
229     }
230
231     public static Action createActionNxMoveReg0ToNsc1Register(int order) {
232         ActionBuilder ab = createActionBuilder(order);
233         ab.setAction(nxMoveRegAction(
234                 new SrcNxRegCaseBuilder().setNxReg(NxmNxReg0.class).build(), 0, 31,
235                 new DstNxNshc1CaseBuilder().setNxNshc1Dst(Boolean.TRUE).build(), 0,31,
236                 false));
237
238         return ab.build();
239     }
240
241     public static Action createActionNxMoveReg6ToNsc4Register(int order) {
242         ActionBuilder ab = createActionBuilder(order);
243         ab.setAction(nxMoveRegAction(new SrcNxRegCaseBuilder().setNxReg(NxmNxReg6.class).build(), 0, 31,
244                 new DstNxNshc4CaseBuilder().setNxNshc4Dst(Boolean.TRUE).build(), 0, 31,
245                 false));
246
247         return ab.build();
248     }
249
250     public static Action createActionNxMoveNsc4ToReg6Register(int order) {
251         ActionBuilder ab = createActionBuilder(order);
252         ab.setAction(nxMoveRegAction(new SrcNxNshc4CaseBuilder().setNxNshc4Dst(Boolean.TRUE).build(), 0, 31,
253                 new DstNxRegCaseBuilder().setNxReg(NxmNxReg6.class).build(), 0, 31,
254                 false));
255
256         return ab.build();
257     }
258
259     public static Action createActionNxLoadNspToReg2High(long value, int order) {
260         ActionBuilder ab = createActionBuilder(order);
261         DstNxRegCase dstNxRegCase = new DstNxRegCaseBuilder().setNxReg(NxmNxReg2.class).build();
262         ab.setAction(
263                 // Load NSP to the 3 most significant bytes
264                 nxLoadRegAction(dstNxRegCase, BigInteger.valueOf(value), 8, 31, false));
265         return ab.build();
266     }
267
268     public static Action createActionNxMoveReg2HighToNsp(int order) {
269         ActionBuilder ab = createActionBuilder(order);
270         ab.setAction(nxMoveRegAction(
271                 // Move NSP from the 3 most significant bytes
272                 new SrcNxRegCaseBuilder().setNxReg(NxmNxReg2.class).build(), 8, 31,
273                 new DstNxNspCaseBuilder().setNxNspDst(true).build(), 0, 23,
274                 false));
275
276         return ab.build();
277     }
278
279     public static Action createActionNxLoadNsiToReg2Low(long value, int order) {
280         ActionBuilder ab = createActionBuilder(order);
281         DstNxRegCase dstNxRegCase = new DstNxRegCaseBuilder().setNxReg(NxmNxReg2.class).build();
282         ab.setAction(
283                 // Load NSI to the least significant byte
284                 nxLoadRegAction(dstNxRegCase, BigInteger.valueOf(value), 0, 7, false));
285         return ab.build();
286     }
287
288     public static Action createActionNxMoveReg2LowToNsi(int order) {
289         ActionBuilder ab = createActionBuilder(order);
290         ab.setAction(nxMoveRegAction(
291                 // Move NSI from the least significant byte
292                 new SrcNxRegCaseBuilder().setNxReg(NxmNxReg2.class).build(), 0, 7,
293                 new DstNxNsiCaseBuilder().setNxNsiDst(true).build(), 0, 7,
294                 false));
295
296         return ab.build();
297     }
298
299     public static Action createActionNxLoadReg2(long value, int order) {
300         ActionBuilder ab = createActionBuilder(order);
301         DstNxRegCase dstNxRegCase = new DstNxRegCaseBuilder().setNxReg(NxmNxReg2.class).build();
302         ab.setAction(
303                 nxLoadRegAction(dstNxRegCase, BigInteger.valueOf(value), 0, 31, false));
304         return ab.build();
305     }
306
307
308     private static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nxLoadRegAction(
309             DstChoice dstChoice, BigInteger value, int startOffset, int endOffset, boolean groupBucket) {
310         Dst dst = new DstBuilder().setDstChoice(dstChoice).setStart(startOffset).setEnd(endOffset).build();
311         NxRegLoad regLoad = new NxRegLoadBuilder().setDst(dst).setValue(value).build();
312
313         if (groupBucket) {
314             return new NxActionRegLoadNodesNodeGroupBucketsBucketActionsCaseBuilder().setNxRegLoad(regLoad).build();
315         } else {
316             return new NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder().setNxRegLoad(regLoad).build();
317         }
318     }
319
320     public static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nxMoveRegAction(
321         SrcChoice srcChoice, int srcStartOffset, int srcEndOffset,
322         DstChoice dstChoice, int dstStartOffset, int dstEndOffset,
323         boolean groupBucket) {
324
325         NxRegMove nxRegMove = new NxRegMoveBuilder()
326             .setSrc(new SrcBuilder().setSrcChoice(srcChoice).setStart(srcStartOffset).setEnd(srcEndOffset).build())
327             .setDst(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira
328                 .action.rev140714.nx.action.reg.move.grouping.nx.reg.move.DstBuilder()
329                 .setDstChoice(dstChoice).setStart(dstStartOffset).setEnd(dstEndOffset).build())
330             .build();
331
332         if (groupBucket) {
333             return new NxActionRegMoveNodesNodeGroupBucketsBucketActionsCaseBuilder().setNxRegMove(nxRegMove).build();
334         } else {
335             return new NxActionRegMoveNodesNodeTableFlowApplyActionsCaseBuilder().setNxRegMove(nxRegMove).build();
336         }
337     }
338
339     public static Action createActionOutPort(final String portUri, final int order) {
340         OutputActionBuilder output = new OutputActionBuilder();
341         Uri value = new Uri(portUri);
342         output.setOutputNodeConnector(value);
343         ActionBuilder ab = createActionBuilder(order);
344         ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
345
346         return ab.build();
347     }
348
349     public static ActionBuilder createActionBuilder(int order) {
350         ActionBuilder ab = new ActionBuilder();
351         ab.setOrder(order);
352         ab.withKey(new ActionKey(order));
353
354         return ab;
355     }
356
357     public static InstructionsBuilder wrapActionsIntoApplyActionsInstruction(List<Action> theActions) {
358         // Create an Apply Action
359         ApplyActionsBuilder aab = new ApplyActionsBuilder();
360         aab.setAction(theActions);
361
362         // Wrap our Apply Action in an Instruction
363         InstructionBuilder ib = new InstructionBuilder();
364         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
365         ib.setOrder(0);
366         ib.withKey(new InstructionKey(0));
367
368         // Put our Instruction in a list of Instructions
369         List<Instruction> instructions = new ArrayList<>();
370         instructions.add(ib.build());
371         return new InstructionsBuilder().setInstruction(instructions);
372     }
373
374     public static FlowBuilder createFlowBuilder(final short table, final int priority, final BigInteger cookieValue,
375                                                 final String flowName, final String flowIdStr, MatchBuilder match,
376                                                 InstructionsBuilder isb) {
377         FlowBuilder flow = new FlowBuilder();
378         flow.setId(new FlowId(flowIdStr));
379         flow.withKey(new FlowKey(new FlowId(flowIdStr)));
380         flow.setTableId(table);
381         flow.setFlowName(flowName);
382         flow.setCookie(new FlowCookie(cookieValue));
383         flow.setCookieMask(new FlowCookie(cookieValue));
384         flow.setContainerName(null);
385         flow.setStrict(false);
386         flow.setMatch(match.build());
387         flow.setInstructions(isb.build());
388         flow.setPriority(priority);
389         flow.setHardTimeout(0);
390         flow.setIdleTimeout(0);
391         flow.setFlags(new FlowModFlags(false, false, false, false, false));
392         if (null == flow.isBarrier()) {
393             flow.setBarrier(Boolean.FALSE);
394         }
395
396         return flow;
397     }
398
399     public static InstructionsBuilder appendGotoTableInstruction(InstructionsBuilder isb, short nextTableId) {
400         if (isb.getInstruction() == null) {
401             isb.setInstruction(new ArrayList<>());
402         }
403         isb.getInstruction().add(createGotoTableInstruction(nextTableId, isb.getInstruction().size()));
404         return isb;
405     }
406
407     public static Instruction createGotoTableInstruction(short nextTableId, int order) {
408         GoToTableBuilder gotoIngress = createActionGotoTable(nextTableId);
409
410         return new InstructionBuilder().withKey(new InstructionKey(order)).setOrder(order)
411             .setInstruction(new GoToTableCaseBuilder().setGoToTable(gotoIngress.build()).build()).build();
412     }
413
414     public static GoToTableBuilder createActionGotoTable(final short toTable) {
415         GoToTableBuilder gotoTb = new GoToTableBuilder();
416         gotoTb.setTableId(toTable);
417
418         return gotoTb;
419     }
420
421     public static NxRegLoad createNxLoadReg0(long value) {
422         Dst dst = new DstBuilder()
423                 .setDstChoice(new DstNxRegCaseBuilder().setNxReg(NxmNxReg0.class).build())
424                 .setStart(0)
425                 .setEnd(31)
426                 .build();
427         return new NxRegLoadBuilder()
428                 .setDst(dst)
429                 .setValue(BigInteger.valueOf(value))
430                 .build();
431     }
432
433     public static Action createAction(
434             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, int order) {
435         return new ActionBuilder()
436                 .setOrder(order)
437                 .withKey(new ActionKey(order))
438                 .setAction(action)
439                 .build();
440     }
441 }