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