SouthboundIT: merge the CRUD tests methods
[netvirt.git] / utils / mdsal-openflow / src / main / java / org / opendaylight / ovsdb / utils / mdsal / openflow / InstructionUtils.java
1 /*
2  * Copyright (c) 2013, 2015 Red Hat, 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
9 package org.opendaylight.ovsdb.utils.mdsal.openflow;
10
11 import static org.opendaylight.ovsdb.utils.mdsal.openflow.ActionUtils.dropAction;
12
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstActionBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
70
71 import org.slf4j.Logger;
72 import org.slf4j.LoggerFactory;
73
74 import java.math.BigInteger;
75 import java.util.ArrayList;
76 import java.util.List;
77
78 public class InstructionUtils {
79     private static final Logger LOG = LoggerFactory.getLogger(InstructionUtils.class);
80     private static final int IPV4 = 0x8100;
81     private static final int MAX_LENGTH = 0xffff;
82
83     /**
84      * Create Send to Controller Reserved Port Instruction (packet_in)
85      *
86      * @param nodeName Uri Prefix, containing nodeConnectorType and dpId (aka NodeId)
87      * @param ib Map InstructionBuilder without any instructions
88      * @return ib Map InstructionBuilder with instructions
89      */
90     public static InstructionBuilder createSendToControllerInstructions(String nodeName, InstructionBuilder ib) {
91
92         List<Action> actionList = new ArrayList<>();
93         ActionBuilder ab = new ActionBuilder();
94
95         OutputActionBuilder output = new OutputActionBuilder();
96         output.setMaxLength(MAX_LENGTH);
97         NodeId nodeId = new NodeId(nodeName);
98         output.setOutputNodeConnector(new NodeConnectorId(nodeId.getValue() + ":"
99                 + OutputPortValues.CONTROLLER.toString()));
100         ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
101         ab.setOrder(0);
102         ab.setKey(new ActionKey(0));
103         actionList.add(ab.build());
104
105         // Create an Apply Action
106         ApplyActionsBuilder aab = new ApplyActionsBuilder();
107         aab.setAction(actionList);
108
109         // Wrap our Apply Action in an Instruction
110         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
111
112         return ib;
113     }
114
115     /**
116      * Create NORMAL Reserved Port Instruction (packet_in)
117      *
118      * @param nodeName Uri Prefix, containing nodeConnectorType and dpId (aka NodeId)
119      * @param ib Map InstructionBuilder without any instructions
120      * @return ib Map InstructionBuilder with instructions
121      */
122
123     public static InstructionBuilder createNormalInstructions(String nodeName, InstructionBuilder ib) {
124
125         List<Action> actionList = new ArrayList<>();
126         ActionBuilder ab = new ActionBuilder();
127
128         OutputActionBuilder output = new OutputActionBuilder();
129         NodeId nodeId = new NodeId(nodeName);
130         output.setOutputNodeConnector(new NodeConnectorId(nodeId.getValue() + ":"
131                 + OutputPortValues.NORMAL.toString()));
132         ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
133         ab.setOrder(0);
134         ab.setKey(new ActionKey(0));
135         actionList.add(ab.build());
136
137         // Create an Apply Action
138         ApplyActionsBuilder aab = new ApplyActionsBuilder();
139         aab.setAction(actionList);
140
141         // Wrap our Apply Action in an Instruction
142         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
143
144         return ib;
145     }
146
147     /**
148      * Create Output Port Instruction
149      *
150      * @param ib       Map InstructionBuilder without any instructions
151      * @param dpidLong Long the datapath ID of a switch/node
152      * @param port     Long representing a port on a switch/node
153      * @return ib InstructionBuilder Map with instructions
154      */
155     public static InstructionBuilder createOutputPortInstructions(InstructionBuilder ib, Long dpidLong, Long port) {
156
157         NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
158         LOG.debug("createOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} inPort={} ",
159                 dpidLong, port);
160
161         List<Action> actionList = new ArrayList<>();
162         ActionBuilder ab = new ActionBuilder();
163         OutputActionBuilder oab = new OutputActionBuilder();
164         oab.setOutputNodeConnector(ncid);
165
166         ab.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
167         ab.setOrder(0);
168         ab.setKey(new ActionKey(0));
169         actionList.add(ab.build());
170
171         // Create an Apply Action
172         ApplyActionsBuilder aab = new ApplyActionsBuilder();
173         aab.setAction(actionList);
174         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
175
176         return ib;
177     }
178
179     /**
180      * add Output Port action to Instruction action list.
181      * This is use for flow with single output port actions.
182      * Flow with mutiple output port actions should use createOutputPortInstructions() method.
183      *
184      * @param ib       Map InstructionBuilder without any instructions
185      * @param dpidLong Long the datapath ID of a switch/node
186      * @param port     Long representing a port on a switch/node
187      * @return ib InstructionBuilder Map with instructions
188      */
189     public static InstructionBuilder addOutputPortInstructions(InstructionBuilder ib,
190             Long dpidLong, Long port,
191             List<Instruction> instructions) {
192         NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
193         LOG.debug(
194                 "addOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}",
195                 dpidLong, port, instructions);
196
197         List<Action> actionList = new ArrayList<>();
198         ActionBuilder ab = new ActionBuilder();
199
200         List<Action> existingActions;
201         if (instructions != null) {
202             for (Instruction in : instructions) {
203                 if (in.getInstruction() instanceof ApplyActionsCase) {
204                     existingActions = (((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction());
205                     actionList.addAll(existingActions);
206                 }
207             }
208         }
209
210         /* Create output action for this port*/
211         OutputActionBuilder oab = new OutputActionBuilder();
212         oab.setOutputNodeConnector(ncid);
213         ab.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
214         ab.setOrder(actionList.size());
215         ab.setKey(new ActionKey(actionList.size()));
216         actionList.add(ab.build());
217
218         // Create an Apply Action
219         ApplyActionsBuilder aab = new ApplyActionsBuilder();
220         aab.setAction(actionList);
221         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
222
223         return ib;
224     }
225
226     /**
227      * Remove Output Port from Instruction
228      *
229      * @param ib       Map InstructionBuilder without any instructions
230      * @param dpidLong Long the datapath ID of a switch/node
231      * @param port     Long representing a port on a switch/node
232      * @return ib InstructionBuilder Map with instructions
233      */
234     public static boolean removeOutputPortFromInstructions(InstructionBuilder ib,
235             Long dpidLong, Long port, List<Instruction> instructions) {
236
237         final NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
238         final Uri ncidUri = new Uri(ncid);
239         LOG.debug(
240                 "removeOutputPortFromInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}",
241                 dpidLong, port, instructions);
242
243         List<Action> actionList = new ArrayList<>();
244         ActionBuilder ab;
245
246         // Start of by locating actions that will have port removed, from the existing instructionList
247         //
248         List<Action> existingActions;
249         if (instructions != null) {
250             for (Instruction in : instructions) {
251                 if (in.getInstruction() instanceof ApplyActionsCase) {
252                     existingActions = (((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction());
253                     actionList.addAll(existingActions);
254                     break;
255                 }
256             }
257         }
258
259         int removedActionOrder = 0;
260         boolean isPortDeleted = false;
261         boolean removeFlow = true;
262
263         // Locate specific action that has the port to be removed. Then, take note on its action order
264         // and remove it from list, in addition to flag that it was found.
265         //
266         for (Action action : actionList) {
267             if (action.getAction() instanceof OutputActionCase) {
268                 OutputActionCase opAction = (OutputActionCase) action.getAction();
269                 if (opAction.getOutputAction().getOutputNodeConnector().equals(ncidUri)) {
270                     /* Find the output port in action list and remove */
271                     removedActionOrder = action.getOrder();
272                     actionList.remove(action);
273                     isPortDeleted = true;
274                     break;
275                 }
276             }
277         }
278
279         if (isPortDeleted) {
280             // Iterate through all actions in the modified list and adjust the order of
281             // the actions left behind. With that, all actions that have order higher than
282             // the action removed gets their value decremented by 1. Note that this iteration
283             // visits all entries to account for cases where the list order is not the same
284             // as the action's order.
285             //
286             for (int i = 0; i < actionList.size(); i++) {
287                 Action action = actionList.get(i);
288                 if (action.getOrder() > removedActionOrder) {
289                     /* Shift the action by rebuilding action, using adjusted order */
290                     ab = new ActionBuilder();
291                     ab.setAction(action.getAction());
292                     ab.setOrder(action.getOrder() - 1);
293                     ab.setKey(new ActionKey(action.getOrder() - 1));
294                     Action actionNewOrder = ab.build();
295                     actionList.remove(action);
296                     actionList.add(i, actionNewOrder);
297                 } else if (action.getOrder() == removedActionOrder) {
298                     // Sanity: implementation assumes no two actions have the same order
299                     //
300                     LOG.error("Found action with same order as the action removed for {}, order {} index {}: {}",
301                             ncid, removedActionOrder, i, action);
302                 }
303
304                 // If action refers to a port output, then flow should be preserved.
305                 // We do this, so that if we are only left with non-output port actions,
306                 // we still remove the flow
307                 //
308                 if (action.getAction() instanceof OutputActionCase) {
309                     removeFlow = false;
310                 }
311             }
312         } else {
313             // If port we are asked to delete is not found, this implementation will leave actions
314             // alone and not remove the flow, as long as a remaining OutputActionCase is found.
315             //
316             for (Action action : actionList) {
317                 if (action.getAction() instanceof OutputActionCase) {
318                     removeFlow = false;
319                     break;
320                 }
321             }
322         }
323
324         /* Put new action list in Apply Action instruction */
325         if (!removeFlow) {
326             ApplyActionsBuilder aab = new ApplyActionsBuilder();
327             aab.setAction(actionList);
328             ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
329             LOG.debug("removeOutputPortFromInstructions() : applyAction {}", aab.build());
330             return false;
331         } else {
332             /* if all output ports are removed. Return true to indicate flow remove */
333             return true;
334         }
335     }
336
337     /**
338      * Create Set Vlan ID Instruction - This includes push vlan action, and set field -&gt; vlan vid action
339      *
340      * @param ib     Map InstructionBuilder without any instructions
341      * @param vlanId Integer representing a VLAN ID Integer representing a VLAN ID
342      * @return ib Map InstructionBuilder with instructions
343      */
344     public static InstructionBuilder createSetVlanInstructions(InstructionBuilder ib, VlanId vlanId) {
345
346         List<Action> actionList = new ArrayList<>();
347         ActionBuilder ab = new ActionBuilder();
348
349         /* First we push vlan header */
350         PushVlanActionBuilder vlan = new PushVlanActionBuilder();
351         vlan.setEthernetType(IPV4);
352         ab.setAction(new PushVlanActionCaseBuilder().setPushVlanAction(vlan.build()).build());
353         ab.setOrder(0);
354         actionList.add(ab.build());
355
356         /* Then we set vlan id value as vlanId */
357         SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
358         vl.setVlanId(vlanId);
359         ab = new ActionBuilder();
360         ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.build()).build());
361         ab.setOrder(1);
362         actionList.add(ab.build());
363         // Create an Apply Action
364         ApplyActionsBuilder aab = new ApplyActionsBuilder();
365         aab.setAction(actionList);
366
367         // Wrap our Apply Action in an Instruction
368         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
369
370         return ib;
371     }
372
373     /**
374      * Create Pop Vlan Instruction - this remove vlan header
375      *
376      * @param ib Map InstructionBuilder without any instructions
377      * @return ib Map InstructionBuilder with instructions
378      */
379     public static InstructionBuilder createPopVlanInstructions(InstructionBuilder ib) {
380
381         List<Action> actionList = new ArrayList<>();
382         ActionBuilder ab = new ActionBuilder();
383
384         PopVlanActionBuilder popVlanActionBuilder = new PopVlanActionBuilder();
385         ab.setAction(new PopVlanActionCaseBuilder().setPopVlanAction(popVlanActionBuilder.build()).build());
386         ab.setOrder(0);
387         actionList.add(ab.build());
388
389         // Create an Apply Action
390         ApplyActionsBuilder aab = new ApplyActionsBuilder();
391         aab.setAction(actionList);
392
393         // Wrap our Apply Action in an Instruction
394         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
395
396         return ib;
397     }
398
399     /**
400      * Create Set IPv4 Source Instruction
401      *
402      * @param ib        Map InstructionBuilder without any instructions
403      * @param prefixsrc String containing an IPv4 prefix
404      * @return ib Map InstructionBuilder with instructions
405      */
406     public static InstructionBuilder createNwSrcInstructions(InstructionBuilder ib, Ipv4Prefix prefixsrc) {
407
408         List<Action> actionList = new ArrayList<>();
409         ActionBuilder ab = new ActionBuilder();
410
411         SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
412         Ipv4Builder ipsrc = new Ipv4Builder();
413         ipsrc.setIpv4Address(prefixsrc);
414         setNwsrcActionBuilder.setAddress(ipsrc.build());
415         ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
416         ab.setOrder(0);
417         ab.setKey(new ActionKey(0));
418         actionList.add(ab.build());
419
420         // Create an Apply Action
421         ApplyActionsBuilder aab = new ApplyActionsBuilder();
422         aab.setAction(actionList);
423
424         // Wrap our Apply Action in an Instruction
425         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
426
427         return ib;
428     }
429
430     /**
431      * Create Set IPv4 Destination Instruction
432      *
433      * @param ib        Map InstructionBuilder without any instructions
434      * @param prefixdst String containing an IPv4 prefix
435      * @param extraAction (optional) Additional action to be performed in actionList
436      * @return ib Map InstructionBuilder with instructions
437      */
438     public static InstructionBuilder createNwDstInstructions(InstructionBuilder ib, Ipv4Prefix prefixdst,
439                                                              ActionBuilder extraAction) {
440
441         List<Action> actionList = new ArrayList<>();
442         ActionBuilder ab = new ActionBuilder();
443
444         SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
445         Ipv4Builder ipdst = new Ipv4Builder();
446         ipdst.setIpv4Address(prefixdst);
447         setNwDstActionBuilder.setAddress(ipdst.build());
448         ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
449         ab.setOrder(0);
450         ab.setKey(new ActionKey(0));
451         actionList.add(ab.build());
452
453         if (extraAction != null) {
454             extraAction.setOrder(1);
455             extraAction.setKey(new ActionKey(1));
456             actionList.add(extraAction.build());
457         }
458
459         // Create an Apply Action
460         ApplyActionsBuilder aab = new ApplyActionsBuilder();
461         aab.setAction(actionList);
462
463         // Wrap our Apply Action in an Instruction
464         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
465
466         return ib;
467     }
468
469     /**
470      * Create Drop Instruction
471      *
472      * @param ib Map InstructionBuilder without any instructions
473      * @return ib Map InstructionBuilder with instructions
474      */
475     public static InstructionBuilder createDropInstructions(InstructionBuilder ib) {
476
477         DropActionBuilder dab = new DropActionBuilder();
478         DropAction dropAction = dab.build();
479         ActionBuilder ab = new ActionBuilder();
480         ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
481         ab.setOrder(0);
482         ab.setKey(new ActionKey(0));
483
484         // Add our drop action to a list
485         List<Action> actionList = new ArrayList<>();
486         actionList.add(ab.build());
487
488         // Create an Apply Action
489         ApplyActionsBuilder aab = new ApplyActionsBuilder();
490         aab.setAction(actionList);
491
492         // Wrap our Apply Action in an Instruction
493         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
494
495         return ib;
496     }
497
498     /**
499      * Create GOTO Table Instruction Builder
500      *
501      * @param ib      Map InstructionBuilder without any instructions
502      * @param tableId short representing a flow table ID short representing a flow table ID
503      * @return ib Map InstructionBuilder with instructions
504      */
505     public static InstructionBuilder createGotoTableInstructions(InstructionBuilder ib, short tableId) {
506
507         GoToTableBuilder gttb = new GoToTableBuilder();
508         gttb.setTableId(tableId);
509
510         // Wrap our Apply Action in an InstructionBuilder
511         ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(gttb.build()).build());
512
513         return ib;
514     }
515
516     /**
517      * Create Set Tunnel ID Instruction Builder
518      *
519      * @param ib       Map InstructionBuilder without any instructions
520      * @param tunnelId BigInteger representing a tunnel ID
521      * @return ib Map InstructionBuilder with instructions
522      */
523     public static InstructionBuilder createSetTunnelIdInstructions(InstructionBuilder ib, BigInteger tunnelId) {
524
525         List<Action> actionList = new ArrayList<>();
526         ActionBuilder ab = new ActionBuilder();
527         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
528
529         // Build the Set Tunnel Field Action
530         TunnelBuilder tunnel = new TunnelBuilder();
531         tunnel.setTunnelId(tunnelId);
532         setFieldBuilder.setTunnel(tunnel.build());
533         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
534         ab.setOrder(0);
535         ab.setKey(new ActionKey(0));
536         actionList.add(ab.build());
537
538         ApplyActionsBuilder aab = new ApplyActionsBuilder();
539         aab.setAction(actionList);
540
541         // Wrap the Apply Action in an InstructionBuilder and return
542         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
543
544         return ib;
545     }
546
547     /**
548      * Create Set Source TCP Port Instruction
549      *
550      * @param ib      Map InstructionBuilder without any instructions
551      * @param tcpport Integer representing a source TCP port
552      * @return ib Map InstructionBuilder with instructions
553      */
554     public static InstructionBuilder createSetSrcTCPPort(InstructionBuilder ib, PortNumber tcpport) {
555
556         List<Action> actionList = new ArrayList<>();
557         ActionBuilder ab = new ActionBuilder();
558         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
559
560         // Build the Destination TCP Port
561         PortNumber tcpsrcport = new PortNumber(tcpport);
562         TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
563         tcpmatch.setTcpSourcePort(tcpsrcport);
564
565         setFieldBuilder.setLayer4Match(tcpmatch.build());
566         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
567         ab.setOrder(0);
568         ab.setKey(new ActionKey(0));
569         actionList.add(ab.build());
570
571         ApplyActionsBuilder aab = new ApplyActionsBuilder();
572         aab.setAction(actionList);
573         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
574
575         return ib;
576     }
577
578     /**
579      * Create Set Destination TCP Port Instruction
580      *
581      * @param ib      Map InstructionBuilder without any instructions
582      * @param tcpport Integer representing a source TCP port
583      * @return ib Map InstructionBuilder with instructions
584      */
585     public static InstructionBuilder createSetDstTCPPort(InstructionBuilder ib, PortNumber tcpport) {
586
587         List<Action> actionList = new ArrayList<>();
588         ActionBuilder ab = new ActionBuilder();
589         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
590
591         // Build the Destination TCP Port
592         PortNumber tcpdstport = new PortNumber(tcpport);
593         TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
594         tcpmatch.setTcpDestinationPort(tcpdstport);
595
596         setFieldBuilder.setLayer4Match(tcpmatch.build());
597         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
598         ab.setOrder(0);
599         ab.setKey(new ActionKey(0));
600         actionList.add(ab.build());
601
602         ApplyActionsBuilder aab = new ApplyActionsBuilder();
603         aab.setAction(actionList);
604         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
605
606         return ib;
607     }
608
609     /**
610      * Create Set Source UDP Port Instruction
611      *
612      * @param ib      Map InstructionBuilder without any instructions
613      * @param udpport Integer representing a source UDP port
614      * @return ib Map InstructionBuilder with instructions
615      */
616     public static InstructionBuilder createSetSrcUDPPort(InstructionBuilder ib, PortNumber udpport) {
617
618         List<Action> actionList = new ArrayList<>();
619         ActionBuilder ab = new ActionBuilder();
620         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
621
622         // Build the Destination TCP Port
623         PortNumber udpsrcport = new PortNumber(udpport);
624         UdpMatchBuilder udpmatch = new UdpMatchBuilder();
625         udpmatch.setUdpSourcePort(udpsrcport);
626
627         setFieldBuilder.setLayer4Match(udpmatch.build());
628         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
629         ab.setOrder(0);
630         ab.setKey(new ActionKey(0));
631         actionList.add(ab.build());
632
633         ApplyActionsBuilder aab = new ApplyActionsBuilder();
634         aab.setAction(actionList);
635         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
636
637         return ib;
638     }
639
640     /**
641      * Create Set Destination UDP Port Instruction
642      *
643      * @param ib      Map InstructionBuilder without any instructions
644      * @param udpport Integer representing a destination UDP port
645      * @return ib Map InstructionBuilder with instructions
646      */
647     public static InstructionBuilder createSetDstUDPPort(InstructionBuilder ib, PortNumber udpport) {
648
649         List<Action> actionList = new ArrayList<>();
650         ActionBuilder ab = new ActionBuilder();
651         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
652
653         // Build the Destination TCP Port
654         PortNumber udpdstport = new PortNumber(udpport);
655         UdpMatchBuilder udpmatch = new UdpMatchBuilder();
656         udpmatch.setUdpDestinationPort(udpdstport);
657
658         setFieldBuilder.setLayer4Match(udpmatch.build());
659         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
660         ab.setOrder(0);
661         ab.setKey(new ActionKey(0));
662         actionList.add(ab.build());
663
664         ApplyActionsBuilder aab = new ApplyActionsBuilder();
665         aab.setAction(actionList);
666         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
667
668         return ib;
669     }
670
671     /**
672      * Create Set ICMP Code Instruction
673      *
674      * @param ib   Map InstructionBuilder without any instructions
675      * @param code short repesenting an ICMP code
676      * @return ib Map InstructionBuilder with instructions
677      */
678
679     public static InstructionBuilder createSetIcmpCodeInstruction(InstructionBuilder ib, short code) {
680
681         List<Action> actionList = new ArrayList<>();
682         ActionBuilder ab = new ActionBuilder();
683         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
684         Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
685
686         // Build the ICMPv4 Code Match
687         icmpv4match.setIcmpv4Code(code);
688         setFieldBuilder.setIcmpv4Match(icmpv4match.build());
689
690         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
691         ab.setOrder(0);
692         ab.setKey(new ActionKey(0));
693         actionList.add(ab.build());
694         ApplyActionsBuilder aab = new ApplyActionsBuilder();
695         aab.setAction(actionList);
696
697         // Wrap our Apply Action in an Instruction
698         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
699
700         return ib;
701     }
702
703     /**
704      * Create Set ICMP Code Instruction
705      *
706      * @param ib Map InstructionBuilder without any instructions
707      * @return ib Map InstructionBuilder with instructions
708      */
709     public static InstructionBuilder createSetIcmpTypeInstruction(InstructionBuilder ib, short type) {
710
711         List<Action> actionList = new ArrayList<>();
712         ActionBuilder ab = new ActionBuilder();
713         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
714         Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
715
716         // Build the ICMPv4 Code Match
717         icmpv4match.setIcmpv4Code(type);
718         setFieldBuilder.setIcmpv4Match(icmpv4match.build());
719
720         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
721         ab.setOrder(0);
722         ab.setKey(new ActionKey(0));
723         actionList.add(ab.build());
724         ApplyActionsBuilder aab = new ApplyActionsBuilder();
725         aab.setAction(actionList);
726
727         // Wrap our Apply Action in an Instruction
728         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
729
730         return ib;
731     }
732
733     /**
734      * Create Decrement TTL Instruction
735      *
736      * @param ib Map InstructionBuilder without any instructions
737      * @return ib Map InstructionBuilder with instructions
738      */
739     public static InstructionBuilder createDecNwTtlInstructions(InstructionBuilder ib) {
740         DecNwTtlBuilder decNwTtlBuilder = new DecNwTtlBuilder();
741         DecNwTtl decNwTtl = decNwTtlBuilder.build();
742         ActionBuilder ab = new ActionBuilder();
743         ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
744         ab.setOrder(0);
745         ab.setKey(new ActionKey(0));
746
747         // Add our drop action to a list
748         List<Action> actionList = new ArrayList<>();
749         actionList.add(ab.build());
750
751         // Create an Apply Action
752         ApplyActionsBuilder aab = new ApplyActionsBuilder();
753         aab.setAction(actionList);
754
755         // Wrap our Apply Action in an Instruction
756         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
757
758         return ib;
759     }
760
761     /**
762      * Set ARP_SHA Instructions
763      * @param ib Map InstructionBuilder
764      * @param macsrc the macsrc
765      * @return instructionbuilder with new instructions
766      */
767     public static InstructionBuilder createSrcArpMacInstructions(InstructionBuilder ib, MacAddress macsrc) {
768
769         List<Action> actionList = new ArrayList<>();
770         ActionBuilder ab = new ActionBuilder();
771
772         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
773         ArpMatchBuilder arpmatch = new ArpMatchBuilder();
774         ArpSourceHardwareAddressBuilder arpsrc = new ArpSourceHardwareAddressBuilder();
775         arpsrc.setAddress(macsrc);
776         arpmatch.setArpSourceHardwareAddress(arpsrc.build());
777         setFieldBuilder.setLayer3Match(arpmatch.build());
778         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
779         ab.setOrder(0);
780         ab.setKey(new ActionKey(0));
781         actionList.add(ab.build());
782
783         ApplyActionsBuilder aab = new ApplyActionsBuilder();
784         aab.setAction(actionList);
785         // Wrap our Apply Action in an Instruction
786         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
787
788         return ib;
789     }
790
791     /**
792      * Set ARP_THA Instructions
793      * @param ib Map InstructionBuilder
794      * @param macdst the macdst
795      * @return instructionbuilder with new attributes
796      */
797     public static InstructionBuilder createDstArpMacInstructions(InstructionBuilder ib, MacAddress macdst) {
798
799         List<Action> actionList = new ArrayList<>();
800         ActionBuilder ab = new ActionBuilder();
801         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
802
803         ArpMatchBuilder arpmatch = new ArpMatchBuilder();
804         ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder();
805         arpdst.setAddress(macdst);
806         setFieldBuilder.setLayer3Match(arpmatch.build());
807         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
808         ab.setOrder(0);
809         ab.setKey(new ActionKey(0));
810         actionList.add(ab.build());
811
812         ApplyActionsBuilder aab = new ApplyActionsBuilder();
813         aab.setAction(actionList);
814         // Wrap our Apply Action in an Instruction
815         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
816
817         return ib;
818     }
819
820     /**
821      * Set ARP_TPA Instructions
822      * @param ib Map InstructionBuilder
823      * @param dstiparp the dstiparp
824      * @return instructionbuilder with new attributes
825      */
826     public static InstructionBuilder createDstArpIpInstructions(InstructionBuilder ib, Ipv4Prefix dstiparp) {
827
828         List<Action> actionList = new ArrayList<>();
829         ActionBuilder ab = new ActionBuilder();
830         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
831
832         ArpMatchBuilder arpmatch = new ArpMatchBuilder();
833         arpmatch.setArpTargetTransportAddress(dstiparp);
834         setFieldBuilder.setLayer3Match(arpmatch.build());
835         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
836         ab.setOrder(0);
837         ab.setKey(new ActionKey(0));
838         actionList.add(ab.build());
839
840         ApplyActionsBuilder aab = new ApplyActionsBuilder();
841         aab.setAction(actionList);
842         // Wrap our Apply Action in an Instruction
843         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
844
845         return ib;
846     }
847
848     /**
849      * Set ARP_SPA Instructions
850      * @param ib Map InstructionBuilder
851      * @param srciparp the srciparp
852      * @return instructionbuilder with new attributes
853      */
854     public static InstructionBuilder createSrcArpIpInstructions(InstructionBuilder ib, Ipv4Prefix srciparp) {
855
856         List<Action> actionList = new ArrayList<>();
857         ActionBuilder ab = new ActionBuilder();
858         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
859
860         ArpMatchBuilder arpmatch = new ArpMatchBuilder();
861         arpmatch.setArpSourceTransportAddress(srciparp);
862         setFieldBuilder.setLayer3Match(arpmatch.build());
863         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
864         ab.setOrder(0);
865         ab.setKey(new ActionKey(0));
866         actionList.add(ab.build());
867
868         ApplyActionsBuilder aab = new ApplyActionsBuilder();
869         aab.setAction(actionList);
870         // Wrap our Apply Action in an Instruction
871         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
872
873         return ib;
874     }
875
876     /**
877      * Set the Tunnel EndpointIPv4 Source Address
878      * @param ib Map InstructionBuilder
879      * @param srcIp Ipv4Prefix source IP for the tunnel endpoint (TEP)
880      * @return instructionbuilder with new attributes
881      */
882     public static InstructionBuilder createTunnelIpv4SrcInstructions(InstructionBuilder ib, Ipv4Prefix srcIp) {
883
884         List<Action> actionList = new ArrayList<>();
885         ActionBuilder ab = new ActionBuilder();
886
887         // Build the tunnel endpoint source IPv4 address
888         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
889
890         // Add the new IPv4 object as the tunnel destination
891         TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = new TunnelIpv4MatchBuilder();
892         tunnelIpv4MatchBuilder.setTunnelIpv4Source(srcIp);
893         setFieldBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
894
895         // Add the IPv4 tunnel src to the set_field value
896         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
897         ab.setOrder(0);
898         ab.setKey(new ActionKey(0));
899         actionList.add(ab.build());
900
901         // Resulting action is a per/flow src TEP (set_field:172.16.100.100->tun_src)
902         ApplyActionsBuilder aab = new ApplyActionsBuilder();
903         aab.setAction(actionList);
904         // Wrap our Apply Action in an Instruction
905         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
906
907         return ib;
908     }
909
910     /**
911      * Set the Tunnel EndpointIPv4 Destination Address
912      * @param ib Map InstructionBuilder
913      * @param dstIp Ipv4Prefix destination IP for the tunnel endpoint (TEP)
914      * @return instructionbuilder with new attributes
915      */
916     public static InstructionBuilder createTunnelIpv4DstInstructions(InstructionBuilder ib, Ipv4Prefix dstIp) {
917
918         List<Action> actionList = new ArrayList<>();
919         ActionBuilder ab = new ActionBuilder();
920
921         // Build the tunnel endpoint dst IPv4 address
922         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
923
924         // Add the new IPv4 object as the tunnel destination
925         TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = new TunnelIpv4MatchBuilder();
926         tunnelIpv4MatchBuilder.setTunnelIpv4Destination(dstIp);
927         setFieldBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
928
929         // Add the IPv4 tunnel src to the set_field value
930         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
931         ab.setOrder(0);
932         ab.setKey(new ActionKey(0));
933         actionList.add(ab.build());
934
935         // Resulting action is a per/flow src TEP (set_field:172.16.100.100->tun_src)
936         ApplyActionsBuilder aab = new ApplyActionsBuilder();
937         aab.setAction(actionList);
938         // Wrap our Apply Action in an Instruction
939         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
940
941         return ib;
942     }
943
944     /**
945      * Set IPv4 Source Address Instructions
946      * @param ib Map InstructionBuilder
947      * @param metaData BigInteger representing the OpenFlow metadata
948      * @param metaDataMask  BigInteger representing the OpenFlow metadata mask
949      * @return instructionbuilder with new attributes
950      */
951     public static InstructionBuilder createMetadataInstructions(InstructionBuilder ib, BigInteger metaData, BigInteger metaDataMask) {
952
953         WriteMetadataBuilder aab = new WriteMetadataBuilder();
954         aab.setMetadata(metaData);
955         aab.setMetadataMask(metaDataMask);
956         ib.setInstruction(new WriteMetadataCaseBuilder().setWriteMetadata(aab.build()).build());
957
958         /**
959         *
960         * TODO Determine why the following fails serialization
961         * with a null value. Per the spec it is optional.
962         * The metadata match, the Flowmod works w/o an accompanying mask.
963         *
964         * if (metaDataMask != null) {
965         *    aab.setMetadataMask(metaDataMask);
966         * }
967         *
968         */
969
970         return ib;
971     }
972
973     public static InstructionBuilder createDlSrcInstructions(InstructionBuilder ib, MacAddress macAddress) {
974
975         List<Action> actionList = new ArrayList<>();
976         ActionBuilder ab = new ActionBuilder();
977
978         SetDlSrcActionBuilder dlSrcActionBuilder= new SetDlSrcActionBuilder();
979
980         dlSrcActionBuilder.setAddress(macAddress);
981
982         ab.setAction(new SetDlSrcActionCaseBuilder().setSetDlSrcAction(dlSrcActionBuilder.build()).build());
983         ab.setOrder(0);
984         ab.setKey(new ActionKey(0));
985         actionList.add(ab.build());
986
987
988         // Create an Apply Action
989         ApplyActionsBuilder aab = new ApplyActionsBuilder();
990         aab.setAction(actionList);
991
992         // Wrap our Apply Action in an Instruction
993         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
994
995         return ib;
996     }
997
998     public static InstructionBuilder createDlDstInstructions(InstructionBuilder ib, MacAddress macAddress) {
999
1000         List<Action> actionList = new ArrayList<>();
1001         ActionBuilder ab = new ActionBuilder();
1002
1003         SetDlDstActionBuilder dlDstActionBuilder= new SetDlDstActionBuilder();
1004
1005         dlDstActionBuilder.setAddress(macAddress);
1006
1007         ab.setAction(new SetDlDstActionCaseBuilder().setSetDlDstAction(dlDstActionBuilder.build()).build());
1008         ab.setOrder(0);
1009         ab.setKey(new ActionKey(0));
1010         actionList.add(ab.build());
1011
1012         // Create an Apply Action
1013         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1014         aab.setAction(actionList);
1015
1016         // Wrap our Apply Action in an Instruction
1017         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1018
1019         return ib;
1020     }
1021
1022     public static List<Action>
1023                   actionList(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action... actions) {
1024
1025         List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> alist
1026             = new ArrayList<>();
1027         int count = 0;
1028         for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action : actions) {
1029             alist.add(new ActionBuilder()
1030                 .setOrder(count)
1031                 .setKey(new ActionKey(count))
1032                 .setAction(action)
1033                 .build());
1034             count++;
1035         }
1036         return alist;
1037     }
1038
1039     public static org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction
1040         applyActionIns(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action... actions) {
1041
1042         return new ApplyActionsCaseBuilder()
1043             .setApplyActions(new ApplyActionsBuilder()
1044                 .setAction(actionList(actions))
1045                 .build())
1046             .build();
1047     }
1048
1049     public static Instructions getInstructions(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction... instructions) {
1050         List<Instruction> ins
1051             = new ArrayList<>();
1052         int order = 0;
1053         for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction i : instructions) {
1054             ins.add(new InstructionBuilder()
1055                 .setOrder(order)
1056                 .setKey(new InstructionKey(order))
1057                 .setInstruction(i)
1058                 .build());
1059             order++;
1060         }
1061         return new InstructionsBuilder().setInstruction(ins).build();
1062     }
1063
1064     public static Instructions dropInstructions() {
1065         return getInstructions(applyActionIns(dropAction()));
1066     }
1067
1068     /**
1069      * Get a list of Instructions containing Nicira extensions that can have
1070      * additional OF/OXM instructions added to the returned Instruction list
1071      *
1072      * @param instructions org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instructions
1073      * @return instruction list that additional
1074      */
1075     public static List<Instruction> getInstructionList(
1076             org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction... instructions) {
1077         List<Instruction> ins
1078                 = new ArrayList<>();
1079         int order = 0;
1080         for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction i : instructions) {
1081             ins.add(new InstructionBuilder()
1082                     .setOrder(order++)
1083                     .setInstruction(i)
1084                     .build());
1085         }
1086         return ins;
1087     }
1088 }