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