Merge "Fix OuputPackage Test"
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTestCommandProvider.java
1 /*
2  * Copyright (c) 2013 Ericsson , Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.test;
10
11 import java.math.BigInteger;
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.concurrent.ExecutionException;
15 import java.util.concurrent.Future;
16
17 import org.eclipse.osgi.framework.console.CommandInterpreter;
18 import org.eclipse.osgi.framework.console.CommandProvider;
19 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
20 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
21 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
22 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.VlanCfi;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodActionCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.HwPathActionCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.LoopbackActionCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCaseBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlTypeActionCaseBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNextHopActionCaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCaseBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCaseBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanCfiActionCaseBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCaseBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.out._case.CopyTtlOutBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.mpls.ttl._case.DecMplsTtlBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.action._case.FloodActionBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.all.action._case.FloodAllActionBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.hw.path.action._case.HwPathActionBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.loopback.action._case.LoopbackActionBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstActionBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.type.action._case.SetDlTypeActionBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.next.hop.action._case.SetNextHopActionBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstActionBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcActionBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.cfi.action._case.SetVlanCfiActionBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.strip.vlan.action._case.StripVlanActionBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.sw.path.action._case.SwPathActionBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.Flows;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.ExperimenterBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
165 import org.opendaylight.yangtools.yang.binding.DataObject;
166 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
167 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
168 import org.opendaylight.yangtools.yang.common.RpcResult;
169 import org.osgi.framework.BundleContext;
170 import org.slf4j.Logger;
171 import org.slf4j.LoggerFactory;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
174
175 public class OpenflowpluginTestCommandProvider implements CommandProvider {
176
177     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestCommandProvider.class);
178
179     private DataBrokerService dataBrokerService;
180     private ProviderContext pc;
181     private final BundleContext ctx;
182     private FlowBuilder testFlow;
183     private NodeBuilder testNode;
184     private final String originalFlowName = "Foo";
185     private final String updatedFlowName = "Bar";
186
187     public OpenflowpluginTestCommandProvider(BundleContext ctx) {
188         this.ctx = ctx;
189     }
190
191     public void onSessionInitiated(ProviderContext session) {
192         pc = session;
193         dataBrokerService = session.getSALService(DataBrokerService.class);
194         ctx.registerService(CommandProvider.class.getName(), this, null);
195         createTestFlow(createTestNode(null), null, null);
196     }
197
198     private NodeBuilder createTestNode(String nodeId) {
199         if (nodeId == null) {
200             nodeId = OpenflowpluginTestActivator.NODE_ID;
201         }
202         NodeRef nodeOne = createNodeRef(nodeId);
203         NodeBuilder builder = new NodeBuilder();
204         builder.setId(new NodeId(nodeId));
205         builder.setKey(new NodeKey(builder.getId()));
206         testNode = builder;
207         return builder;
208     }
209
210     private InstanceIdentifier<Node> nodeBuilderToInstanceId(NodeBuilder node) {
211         return InstanceIdentifier.builder(Nodes.class).child(Node.class, node.getKey()).toInstance();
212     }
213
214     private FlowBuilder createTestFlow(NodeBuilder nodeBuilder, String flowTypeArg, String tableId) {
215
216         FlowBuilder flow = new FlowBuilder();
217         long id = 123;
218
219         String flowType = flowTypeArg;
220         if (flowType == null) {
221             flowType = "f1";
222         }
223
224         switch (flowType) {
225         case "f1":
226             id += 1;
227             flow.setMatch(createMatch1().build());
228             flow.setInstructions(createDecNwTtlInstructions().build());
229             break;
230         case "f2":
231             id += 2;
232             flow.setMatch(createMatch2().build());
233             flow.setInstructions(createDropInstructions().build());
234             break;
235         case "f3":
236             id += 3;
237             flow.setMatch(createMatch3().build());
238             flow.setInstructions(createDropInstructions().build());
239             break;
240         case "f4":
241             id += 4;
242             flow.setMatch(createEthernetMatch().build());
243             flow.setInstructions(createDropInstructions().build());
244             break;
245         case "f5":
246             id += 5;
247             flow.setMatch(createMatch1().build());
248             flow.setInstructions(createAppyActionInstruction().build());
249             break;
250         case "f6":
251             id += 6;
252             flow.setMatch(createMatch1().build());
253             flow.setInstructions(createGotoTableInstructions().build());
254             break;
255         case "f7":
256             id += 7;
257             flow.setMatch(createMatch1().build());
258             flow.setInstructions(createMeterInstructions().build());
259             break;
260         case "f8":
261             id += 8;
262             flow.setMatch(createMatch1().build());
263             flow.setInstructions(createAppyActionInstruction1().build());
264             break;
265         case "f9":
266             id += 9;
267             flow.setMatch(createMatch1().build());
268             flow.setInstructions(createAppyActionInstruction2().build());
269             break;
270         case "f10":
271             id += 10;
272             flow.setMatch(createMatch1().build());
273             flow.setInstructions(createAppyActionInstruction3().build());
274             break;
275         case "f11":
276             id += 11;
277             flow.setMatch(createMatch1().build());
278             flow.setInstructions(createAppyActionInstruction4().build());
279             break;
280         case "f12":
281             id += 12;
282             flow.setMatch(createMatch1().build());
283             flow.setInstructions(createAppyActionInstruction5().build());
284             break;
285         case "f13":
286             id += 13;
287             flow.setMatch(createMatch1().build());
288             flow.setInstructions(createAppyActionInstruction6().build());
289             break;
290         case "f14":
291             id += 14;
292             flow.setMatch(createMatch1().build());
293             flow.setInstructions(createAppyActionInstruction7().build());
294             break;
295         case "f15":
296             id += 15;
297             flow.setMatch(createMatch1().build());
298             flow.setInstructions(createAppyActionInstruction8().build());
299             break;
300         case "f16":
301             id += 16;
302             flow.setMatch(createMatch1().build());
303             flow.setInstructions(createAppyActionInstruction9().build());
304             break;
305         case "f17":
306             id += 17;
307             flow.setMatch(createMatch1().build());
308             flow.setInstructions(createAppyActionInstruction10().build());
309             break;
310         case "f18":
311             id += 18;
312             flow.setMatch(createMatch1().build());
313             flow.setInstructions(createAppyActionInstruction11().build());
314             break;
315         case "f19":
316             id += 19;
317             flow.setMatch(createMatch1().build());
318             flow.setInstructions(createAppyActionInstruction12().build());
319             break;
320         case "f20":
321             id += 20;
322             flow.setMatch(createMatch1().build());
323             flow.setInstructions(createAppyActionInstruction13().build());
324             break;
325         case "f21":
326             id += 21;
327             flow.setMatch(createMatch1().build());
328             flow.setInstructions(createAppyActionInstruction14().build());
329             break;
330         case "f22":
331             id += 22;
332             flow.setMatch(createMatch1().build());
333             flow.setInstructions(createAppyActionInstruction15().build());
334             break;
335         case "f23":
336             id += 23;
337             flow.setMatch(createMatch1().build());
338             flow.setInstructions(createAppyActionInstruction16().build());
339             break;
340         case "f24":
341             id += 24;
342             flow.setMatch(createMatch1().build());
343             flow.setInstructions(createAppyActionInstruction17().build());
344             break;
345         case "f25":
346             id += 25;
347             flow.setMatch(createMatch1().build());
348             flow.setInstructions(createAppyActionInstruction18().build());
349             break;
350         case "f26":
351             id += 26;
352             flow.setMatch(createMatch1().build());
353             flow.setInstructions(createAppyActionInstruction19().build());
354             break;
355         case "f27":
356             id += 27;
357             flow.setMatch(createMatch1().build());
358             flow.setInstructions(createMetadataInstructions().build());
359             break;
360         case "f28":
361             id += 28;
362             flow.setMatch(createMatch1().build());
363             flow.setInstructions(createAppyActionInstruction20().build());
364             break;
365         case "f29":
366             id += 29;
367             flow.setMatch(createMatch1().build());
368             flow.setInstructions(createAppyActionInstruction21().build());
369             break;
370         case "f30":
371             id += 30;
372             flow.setMatch(createMatch1().build());
373             flow.setInstructions(createAppyActionInstruction22().build());
374             break;
375         case "f31":
376             id += 31;
377             flow.setMatch(createMatch1().build());
378             flow.setInstructions(createAppyActionInstruction23().build());
379             break;
380         case "f32":
381             id += 32;
382             flow.setMatch(createMatch1().build());
383             flow.setInstructions(createAppyActionInstruction24().build());
384             break;
385         case "f33":
386             id += 33;
387             flow.setMatch(createMatch1().build());
388             flow.setInstructions(createAppyActionInstruction25().build());
389             break;
390         case "f34":
391             id += 34;
392             flow.setMatch(createMatch1().build());
393             flow.setInstructions(createAppyActionInstruction26().build());
394             break;
395         case "f35":
396             id += 35;
397             flow.setMatch(createMatch1().build());
398             flow.setInstructions(createAppyActionInstruction27().build());
399             break;
400         case "f36":
401             id += 36;
402             flow.setMatch(createMatch1().build());
403             flow.setInstructions(createAppyActionInstruction28().build());
404             break;
405         case "f37":
406             id += 37;
407             flow.setMatch(createMatch1().build());
408             flow.setInstructions(createAppyActionInstruction29().build());
409             break;
410         case "f38":
411             id += 38;
412             flow.setMatch(createMatch1().build());
413             flow.setInstructions(createAppyActionInstruction30().build());
414             break;
415         case "f39":
416             id += 39;
417             flow.setMatch(createMatch1().build());
418             flow.setInstructions(createAppyActionInstruction31().build());
419             break;
420         case "f40":
421             id += 40;
422             flow.setMatch(createMatch1().build());
423             flow.setInstructions(createAppyActionInstruction32().build());
424             break;
425         case "f41":
426             id += 41;
427             flow.setMatch(createMatch1().build());
428             flow.setInstructions(createAppyActionInstruction33().build());
429             break;
430         case "f42":
431             id += 42;
432             flow.setMatch(createMatch1().build());
433             flow.setInstructions(createAppyActionInstruction34().build());
434             break;
435         case "f43":
436             id += 43;
437             flow.setMatch(createICMPv6Match().build());
438             flow.setInstructions(createDecNwTtlInstructions().build());
439             break;
440         case "f44":
441             id += 44;
442             flow.setMatch(createInphyportMatch().build());
443             flow.setInstructions(createDropInstructions().build());
444             break;
445         case "f45":
446             id += 45;
447             flow.setMatch(createMetadataMatch().build());
448             flow.setInstructions(createDropInstructions().build());
449             break;
450         case "f46":
451             id += 46;
452             flow.setMatch(createL3IPv6Match().build());
453             flow.setInstructions(createDecNwTtlInstructions().build());
454             break;
455         case "f47":
456             id += 47;
457             flow.setMatch(createL4SCTPMatch().build());
458             flow.setInstructions(createAppyActionInstruction().build());
459             break;
460         case "f48":
461             id += 48;
462             flow.setMatch(createTunnelIDMatch().build());
463             flow.setInstructions(createGotoTableInstructions().build());
464             break;
465         case "f49":
466             id += 49;
467             flow.setMatch(createVlanMatch().build());
468             flow.setInstructions(createMeterInstructions().build());
469             break;
470         case "f50":
471             id += 50;
472             flow.setMatch(createPbbMatch().build());
473             flow.setInstructions(createMeterInstructions().build());
474             break;
475         case "f51":
476             id += 51;
477             flow.setMatch(createVlanMatch().build());
478             flow.setInstructions(createDropInstructions().build());
479             break;
480         case "f52":
481             id += 52;
482             flow.setMatch(createL4TCPMatch().build());
483             flow.setInstructions(createDropInstructions().build());
484             break;    
485             
486         case "f53":
487             id += 53;
488             flow.setMatch(createL4UDPMatch().build());
489             flow.setInstructions(createDropInstructions().build());
490             break;
491         case "f54":
492             id += 54;
493             flow.setMatch(new MatchBuilder().build());
494             flow.setInstructions(createSentToControllerInstructions().build());
495             break;
496         case "f55":
497             id += 55;
498             flow.setMatch(createToSMatch().build());
499             flow.setInstructions(createDropInstructions().build());
500             break;
501         case "f56":
502             id += 56;
503             flow.setMatch(createToSMatch().build());
504             flow.setInstructions(createOutputInstructions("INPORT", 10).build());
505             break;
506         case "f57":
507             id += 57;
508             flow.setMatch(createToSMatch().build());
509             flow.setInstructions(createOutputInstructions("FLOOD", 20).build());
510             break;
511         case "f58":
512             id += 58;
513             flow.setMatch(createToSMatch().build());
514             flow.setInstructions(createOutputInstructions("ALL", 30).build());
515             break;
516         case "f59":
517             id += 59;
518             flow.setMatch(createToSMatch().build());
519             flow.setInstructions(createOutputInstructions("NORMAL" , 40).build());
520             break;
521         case "f60":
522             id += 60;
523             flow.setMatch(createToSMatch().build());
524             flow.setInstructions(createOutputInstructions("LOCAL" , 50).build());
525             break;
526         case "f61":
527             id += 61;
528             flow.setMatch(createToSMatch().build());
529             flow.setInstructions(createOutputInstructions("TABLE", 60).build());
530             break;
531         case "f62":
532             id += 62;
533             flow.setMatch(createToSMatch().build());
534             flow.setInstructions(createOutputInstructions("NONE" , 70).build());
535             break;
536         case "f63":
537             id += 63;
538             flow.setMatch(createToSMatch().build());
539             flow.setInstructions(createStripVlanInstructions().build());
540             flow.setBarrier(Boolean.TRUE);
541             break;
542         default:
543             LOG.warn("flow type not understood: {}", flowType);
544         }
545
546         FlowKey key = new FlowKey(new FlowId(id));
547         if(null == flow.isBarrier())
548         {
549             flow.setBarrier(Boolean.FALSE);
550         }
551         // flow.setBufferId(new Long(12));
552         BigInteger value = new BigInteger("10", 10);
553         BigInteger outputPort = new BigInteger("65535", 10);
554         flow.setCookie(value);
555         flow.setCookieMask(value);
556         flow.setHardTimeout(0);
557         flow.setIdleTimeout(0);
558         flow.setInstallHw(false);
559         flow.setStrict(false);
560         flow.setContainerName(null);
561         flow.setFlags(new FlowModFlags(false, false, false, false, false));
562         flow.setId(new FlowId(new Long(12)));
563         flow.setTableId(getTableId(tableId));
564         flow.setOutGroup(new Long(2));
565         // set outport to OFPP_NONE (65535) to disable remove restriction for flow
566         flow.setOutPort(outputPort);  
567
568         flow.setKey(key);
569         flow.setPriority(2);
570         flow.setFlowName(originalFlowName + "X" + flowType);
571         testFlow = flow;
572         return flow;
573     }
574     
575     
576     private short getTableId(String tableId)
577     {
578          short table = 2;
579           try
580           {
581             table = Short.parseShort(tableId);
582           }
583           catch(Exception ex)
584           {
585              // ignore exception and continue with default value
586           }
587           
588           return table;
589         
590     }
591
592     /**
593      * @return
594      */
595     private static InstructionsBuilder createDecNwTtlInstructions() {
596         DecNwTtlBuilder ta = new DecNwTtlBuilder();
597         DecNwTtl decNwTtl = ta.build();
598         ActionBuilder ab = new ActionBuilder();
599         ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
600
601         // Add our drop action to a list
602         List<Action> actionList = new ArrayList<Action>();
603         actionList.add(ab.build());
604
605         // Create an Apply Action
606         ApplyActionsBuilder aab = new ApplyActionsBuilder();
607         aab.setAction(actionList);
608
609         // Wrap our Apply Action in an Instruction
610         InstructionBuilder ib = new InstructionBuilder();
611         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
612         ib.setKey(new InstructionKey(0));
613         ib.setOrder(0);
614
615         // Put our Instruction in a list of Instructions
616         InstructionsBuilder isb = new InstructionsBuilder();
617         List<Instruction> instructions = new ArrayList<Instruction>();
618         instructions.add(ib.build());
619         isb.setInstruction(instructions);
620         return isb;
621     }
622
623     /**
624      * @return
625      */
626     private static InstructionsBuilder createMeterInstructions() {
627
628         MeterBuilder aab = new MeterBuilder();
629         aab.setMeterId(new MeterId(new Long(1)));
630
631         InstructionBuilder ib = new InstructionBuilder();
632         ib.setInstruction(new MeterCaseBuilder().setMeter(aab.build()).build());
633
634         // Put our Instruction in a list of Instructions
635         InstructionsBuilder isb = new InstructionsBuilder();
636         List<Instruction> instructions = new ArrayList<Instruction>();
637         instructions.add(ib.build());
638         isb.setInstruction(instructions);
639         return isb;
640     }
641
642     private static InstructionsBuilder createMetadataInstructions() {
643
644         WriteMetadataBuilder aab = new WriteMetadataBuilder();
645         aab.setMetadata(new BigInteger("10", 10));
646         aab.setMetadataMask(new BigInteger("12", 10));
647
648         InstructionBuilder ib = new InstructionBuilder();
649         ib.setInstruction(new WriteMetadataCaseBuilder().setWriteMetadata(aab.build()).build());
650
651         // Put our Instruction in a list of Instructions
652         InstructionsBuilder isb = new InstructionsBuilder();
653         List<Instruction> instructions = new ArrayList<Instruction>();
654         instructions.add(ib.build());
655         isb.setInstruction(instructions);
656         return isb;
657     }
658
659     private static InstructionsBuilder createGotoTableInstructions() {
660
661         GoToTableBuilder aab = new GoToTableBuilder();
662         aab.setTableId((short) 2);
663
664         InstructionBuilder ib = new InstructionBuilder();
665         ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(aab.build()).build());
666
667         // Put our Instruction in a list of Instructions
668         InstructionsBuilder isb = new InstructionsBuilder();
669         List<Instruction> instructions = new ArrayList<Instruction>();
670         instructions.add(ib.build());
671         isb.setInstruction(instructions);
672         return isb;
673     }
674
675     private static InstructionsBuilder createDropInstructions() {
676         DropActionBuilder dab = new DropActionBuilder();
677         DropAction dropAction = dab.build();
678         ActionBuilder ab = new ActionBuilder();
679         ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
680
681         // Add our drop action to a list
682         List<Action> actionList = new ArrayList<Action>();
683         actionList.add(ab.build());
684
685         // Create an Apply Action
686         ApplyActionsBuilder aab = new ApplyActionsBuilder();
687         aab.setAction(actionList);
688
689         // Wrap our Apply Action in an Instruction
690         InstructionBuilder ib = new InstructionBuilder();
691         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
692
693         // Put our Instruction in a list of Instructions
694         InstructionsBuilder isb = new InstructionsBuilder();
695         List<Instruction> instructions = new ArrayList<Instruction>();
696         instructions.add(ib.build());
697         isb.setInstruction(instructions);
698         return isb;
699     }
700
701     private static InstructionsBuilder createAppyActionInstruction() {
702
703         List<Action> actionList = new ArrayList<Action>();
704         ActionBuilder ab = new ActionBuilder();
705         ControllerActionBuilder controller = new ControllerActionBuilder();
706         controller.setMaxLength(5);
707         ab.setAction(new ControllerActionCaseBuilder().setControllerAction(controller.build()).build());
708         actionList.add(ab.build());
709         // Create an Apply Action
710         ApplyActionsBuilder aab = new ApplyActionsBuilder();
711         aab.setAction(actionList);
712
713         // Wrap our Apply Action in an Instruction
714         InstructionBuilder ib = new InstructionBuilder();
715         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
716
717         // Put our Instruction in a list of Instructions
718         InstructionsBuilder isb = new InstructionsBuilder();
719         List<Instruction> instructions = new ArrayList<Instruction>();
720         instructions.add(ib.build());
721         isb.setInstruction(instructions);
722         return isb;
723     }
724
725     private static InstructionsBuilder createAppyActionInstruction1() {
726
727         List<Action> actionList = new ArrayList<Action>();
728         ActionBuilder ab = new ActionBuilder();
729
730         OutputActionBuilder output = new OutputActionBuilder();
731         output.setMaxLength(56);
732         Uri value = new Uri("PCEP");
733         output.setOutputNodeConnector(value);
734         ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
735         actionList.add(ab.build());
736         // Create an Apply Action
737         ApplyActionsBuilder aab = new ApplyActionsBuilder();
738         aab.setAction(actionList);
739
740         // Wrap our Apply Action in an Instruction
741         InstructionBuilder ib = new InstructionBuilder();
742         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
743
744         // Put our Instruction in a list of Instructions
745         InstructionsBuilder isb = new InstructionsBuilder();
746         List<Instruction> instructions = new ArrayList<Instruction>();
747         instructions.add(ib.build());
748         isb.setInstruction(instructions);
749         return isb;
750     }
751     
752     private static InstructionsBuilder createSentToControllerInstructions() {
753         List<Action> actionList = new ArrayList<Action>();
754         ActionBuilder ab = new ActionBuilder();
755
756         OutputActionBuilder output = new OutputActionBuilder();
757         output.setMaxLength(56);
758         Uri value = new Uri("CONTROLLER");
759         output.setOutputNodeConnector(value);
760         ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
761         ab.setOrder(0);
762         ab.setKey(new ActionKey(0));
763         actionList.add(ab.build());
764         // Create an Apply Action
765         ApplyActionsBuilder aab = new ApplyActionsBuilder();
766         aab.setAction(actionList);
767
768         // Wrap our Apply Action in an Instruction
769         InstructionBuilder ib = new InstructionBuilder();
770         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
771         ib.setOrder(0);
772         ib.setKey(new InstructionKey(0));
773
774         // Put our Instruction in a list of Instructions
775         InstructionsBuilder isb = new InstructionsBuilder();
776         List<Instruction> instructions = new ArrayList<Instruction>();
777         instructions.add(ib.build());
778         isb.setInstruction(instructions);
779         return isb;
780     }
781
782     
783     private static InstructionsBuilder createOutputInstructions(String outputType, int outputValue) {
784         List<Action> actionList = new ArrayList<Action>();
785         ActionBuilder ab = new ActionBuilder();
786
787         OutputActionBuilder output = new OutputActionBuilder();
788         output.setMaxLength(outputValue);
789         Uri value = new Uri(outputType);
790         output.setOutputNodeConnector(value);
791         ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
792         ab.setOrder(0);
793         ab.setKey(new ActionKey(0));
794         actionList.add(ab.build());
795         // Create an Apply Action
796         ApplyActionsBuilder aab = new ApplyActionsBuilder();
797         aab.setAction(actionList);
798
799         // Wrap our Apply Action in an Instruction
800         InstructionBuilder ib = new InstructionBuilder();
801         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
802         ib.setOrder(0);
803         ib.setKey(new InstructionKey(0));
804
805         // Put our Instruction in a list of Instructions
806         InstructionsBuilder isb = new InstructionsBuilder();
807         List<Instruction> instructions = new ArrayList<Instruction>();
808         instructions.add(ib.build());
809         isb.setInstruction(instructions);
810         return isb;
811     }
812     
813     private static InstructionsBuilder createStripVlanInstructions() {
814         List<Action> actionList = new ArrayList<Action>();
815         ActionBuilder ab = new ActionBuilder();
816
817         StripVlanActionBuilder stripActionBuilder = new StripVlanActionBuilder();
818         ab.setAction(new StripVlanActionCaseBuilder().setStripVlanAction(stripActionBuilder.build()).build());
819         ab.setOrder(0);
820         ab.setKey(new ActionKey(0));
821         actionList.add(ab.build());
822         // Create an Apply Action
823         ApplyActionsBuilder aab = new ApplyActionsBuilder();
824         aab.setAction(actionList);
825
826         // Wrap our Apply Action in an Instruction
827         InstructionBuilder ib = new InstructionBuilder();
828         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
829         ib.setOrder(0);
830         ib.setKey(new InstructionKey(0));
831
832         // Put our Instruction in a list of Instructions
833         InstructionsBuilder isb = new InstructionsBuilder();
834         List<Instruction> instructions = new ArrayList<Instruction>();
835         instructions.add(ib.build());
836         isb.setInstruction(instructions);
837         return isb;
838     }
839         
840     
841     private static InstructionsBuilder createAppyActionInstruction2() {
842
843         List<Action> actionList = new ArrayList<Action>();
844         ActionBuilder ab = new ActionBuilder();
845
846         PushMplsActionBuilder push = new PushMplsActionBuilder();
847         push.setEthernetType(new Integer(0x8847));
848         ab.setAction(new PushMplsActionCaseBuilder().setPushMplsAction(push.build()).build());
849         actionList.add(ab.build());
850         // Create an Apply Action
851         ApplyActionsBuilder aab = new ApplyActionsBuilder();
852         aab.setAction(actionList);
853
854         // Wrap our Apply Action in an Instruction
855         InstructionBuilder ib = new InstructionBuilder();
856         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
857
858         // Put our Instruction in a list of Instructions
859         InstructionsBuilder isb = new InstructionsBuilder();
860         List<Instruction> instructions = new ArrayList<Instruction>();
861         instructions.add(ib.build());
862         isb.setInstruction(instructions);
863         return isb;
864     }
865
866     private static InstructionsBuilder createAppyActionInstruction3() {
867
868         List<Action> actionList = new ArrayList<Action>();
869         ActionBuilder ab = new ActionBuilder();
870
871         PushPbbActionBuilder pbb = new PushPbbActionBuilder();
872         pbb.setEthernetType(new Integer(0x88E7));
873         ab.setAction(new PushPbbActionCaseBuilder().setPushPbbAction(pbb.build()).build());
874         actionList.add(ab.build());
875         // Create an Apply Action
876         ApplyActionsBuilder aab = new ApplyActionsBuilder();
877         aab.setAction(actionList);
878
879         // Wrap our Apply Action in an Instruction
880         InstructionBuilder ib = new InstructionBuilder();
881         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
882
883         // Put our Instruction in a list of Instructions
884         InstructionsBuilder isb = new InstructionsBuilder();
885         List<Instruction> instructions = new ArrayList<Instruction>();
886         instructions.add(ib.build());
887         isb.setInstruction(instructions);
888         return isb;
889     }
890
891     private static InstructionsBuilder createAppyActionInstruction4() {
892
893         List<Action> actionList = new ArrayList<Action>();
894         ActionBuilder ab = new ActionBuilder();
895
896         PushVlanActionBuilder vlan = new PushVlanActionBuilder();
897         vlan.setEthernetType(new Integer(0x8100));
898         ab.setAction(new PushVlanActionCaseBuilder().setPushVlanAction(vlan.build()).build());
899         actionList.add(ab.build());
900
901         // Create an Apply Action
902         ApplyActionsBuilder aab = new ApplyActionsBuilder();
903         aab.setAction(actionList);
904
905         // Wrap our Apply Action in an Instruction
906         InstructionBuilder ib = new InstructionBuilder();
907         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
908
909         // Put our Instruction in a list of Instructions
910         InstructionsBuilder isb = new InstructionsBuilder();
911         List<Instruction> instructions = new ArrayList<Instruction>();
912         instructions.add(ib.build());
913         isb.setInstruction(instructions);
914         return isb;
915     }
916
917     private static InstructionsBuilder createAppyActionInstruction5() {
918
919         List<Action> actionList = new ArrayList<Action>();
920         ActionBuilder ab = new ActionBuilder();
921
922         SetDlDstActionBuilder setdl = new SetDlDstActionBuilder();
923         setdl.setAddress(new MacAddress("00:05:b9:7c:81:5f"));
924         ab.setAction(new SetDlDstActionCaseBuilder().setSetDlDstAction(setdl.build()).build());
925         actionList.add(ab.build());
926         // Create an Apply Action
927         ApplyActionsBuilder aab = new ApplyActionsBuilder();
928         aab.setAction(actionList);
929
930         // Wrap our Apply Action in an Instruction
931         InstructionBuilder ib = new InstructionBuilder();
932         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
933
934         // Put our Instruction in a list of Instructions
935         InstructionsBuilder isb = new InstructionsBuilder();
936         List<Instruction> instructions = new ArrayList<Instruction>();
937         instructions.add(ib.build());
938         isb.setInstruction(instructions);
939         return isb;
940     }
941
942     private static InstructionsBuilder createAppyActionInstruction6() {
943
944         List<Action> actionList = new ArrayList<Action>();
945         ActionBuilder ab = new ActionBuilder();
946
947         SetDlSrcActionBuilder src = new SetDlSrcActionBuilder();
948         src.setAddress(new MacAddress("00:05:b9:7c:81:5f"));
949         ab.setAction(new SetDlSrcActionCaseBuilder().setSetDlSrcAction(src.build()).build());
950         actionList.add(ab.build());
951
952         // Create an Apply Action
953         ApplyActionsBuilder aab = new ApplyActionsBuilder();
954         aab.setAction(actionList);
955
956         // Wrap our Apply Action in an Instruction
957         InstructionBuilder ib = new InstructionBuilder();
958         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
959
960         // Put our Instruction in a list of Instructions
961         InstructionsBuilder isb = new InstructionsBuilder();
962         List<Instruction> instructions = new ArrayList<Instruction>();
963         instructions.add(ib.build());
964         isb.setInstruction(instructions);
965         return isb;
966     }
967
968     private static InstructionsBuilder createAppyActionInstruction7() {
969
970         List<Action> actionList = new ArrayList<Action>();
971         ActionBuilder ab = new ActionBuilder();
972
973         SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
974         VlanId a = new VlanId(4000);
975         vl.setVlanId(a);
976         ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.build()).build());
977         actionList.add(ab.build());
978         // Create an Apply Action
979         ApplyActionsBuilder aab = new ApplyActionsBuilder();
980         aab.setAction(actionList);
981
982         // Wrap our Apply Action in an Instruction
983         InstructionBuilder ib = new InstructionBuilder();
984         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
985
986         // Put our Instruction in a list of Instructions
987         InstructionsBuilder isb = new InstructionsBuilder();
988         List<Instruction> instructions = new ArrayList<Instruction>();
989         instructions.add(ib.build());
990         isb.setInstruction(instructions);
991         return isb;
992     }
993
994     private static InstructionsBuilder createAppyActionInstruction8() {
995
996         List<Action> actionList = new ArrayList<Action>();
997         ActionBuilder ab = new ActionBuilder();
998
999         SetVlanPcpActionBuilder pcp = new SetVlanPcpActionBuilder();
1000         VlanPcp pcp1 = new VlanPcp((short) 2);
1001         pcp.setVlanPcp(pcp1);
1002         ab.setAction(new SetVlanPcpActionCaseBuilder().setSetVlanPcpAction(pcp.build()).build());
1003         actionList.add(ab.build());
1004         // Create an Apply Action
1005         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1006         aab.setAction(actionList);
1007
1008         // Wrap our Apply Action in an Instruction
1009         InstructionBuilder ib = new InstructionBuilder();
1010         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1011
1012         // Put our Instruction in a list of Instructions
1013         InstructionsBuilder isb = new InstructionsBuilder();
1014         List<Instruction> instructions = new ArrayList<Instruction>();
1015         instructions.add(ib.build());
1016         isb.setInstruction(instructions);
1017         return isb;
1018     }
1019
1020     private static InstructionsBuilder createAppyActionInstruction9() {
1021
1022         List<Action> actionList = new ArrayList<Action>();
1023         ActionBuilder ab = new ActionBuilder();
1024
1025         CopyTtlInBuilder ttlin = new CopyTtlInBuilder();
1026         ab.setAction(new  CopyTtlInCaseBuilder().setCopyTtlIn(ttlin.build()).build());
1027         actionList.add(ab.build());
1028         // Create an Apply Action
1029         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1030         aab.setAction(actionList);
1031
1032         // Wrap our Apply Action in an Instruction
1033         InstructionBuilder ib = new InstructionBuilder();
1034         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1035
1036         // Put our Instruction in a list of Instructions
1037         InstructionsBuilder isb = new InstructionsBuilder();
1038         List<Instruction> instructions = new ArrayList<Instruction>();
1039         instructions.add(ib.build());
1040         isb.setInstruction(instructions);
1041         return isb;
1042     }
1043
1044     private static InstructionsBuilder createAppyActionInstruction10() {
1045
1046         List<Action> actionList = new ArrayList<Action>();
1047         ActionBuilder ab = new ActionBuilder();
1048
1049         CopyTtlOutBuilder ttlout = new CopyTtlOutBuilder();
1050         ab.setAction(new CopyTtlOutCaseBuilder().setCopyTtlOut(ttlout.build()).build());
1051         actionList.add(ab.build());
1052         // Create an Apply Action
1053         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1054         aab.setAction(actionList);
1055
1056         // Wrap our Apply Action in an Instruction
1057         InstructionBuilder ib = new InstructionBuilder();
1058         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1059
1060         // Put our Instruction in a list of Instructions
1061         InstructionsBuilder isb = new InstructionsBuilder();
1062         List<Instruction> instructions = new ArrayList<Instruction>();
1063         instructions.add(ib.build());
1064         isb.setInstruction(instructions);
1065         return isb;
1066     }
1067
1068     private static InstructionsBuilder createAppyActionInstruction11() {
1069
1070         List<Action> actionList = new ArrayList<Action>();
1071         ActionBuilder ab = new ActionBuilder();
1072
1073         DecMplsTtlBuilder mpls = new DecMplsTtlBuilder();
1074         ab.setAction(new DecMplsTtlCaseBuilder().setDecMplsTtl(mpls.build()).build());
1075         actionList.add(ab.build());
1076         // Create an Apply Action
1077         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1078         aab.setAction(actionList);
1079
1080         // Wrap our Apply Action in an Instruction
1081         InstructionBuilder ib = new InstructionBuilder();
1082         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1083
1084         // Put our Instruction in a list of Instructions
1085         InstructionsBuilder isb = new InstructionsBuilder();
1086         List<Instruction> instructions = new ArrayList<Instruction>();
1087         instructions.add(ib.build());
1088         isb.setInstruction(instructions);
1089         return isb;
1090     }
1091
1092     private static InstructionsBuilder createAppyActionInstruction12() {
1093
1094         List<Action> actionList = new ArrayList<Action>();
1095         ActionBuilder ab = new ActionBuilder();
1096
1097         DecNwTtlBuilder nwttl = new DecNwTtlBuilder();
1098         ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(nwttl.build()).build());
1099         actionList.add(ab.build());
1100
1101         // Create an Apply Action
1102         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1103         aab.setAction(actionList);
1104
1105         // Wrap our Apply Action in an Instruction
1106         InstructionBuilder ib = new InstructionBuilder();
1107         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1108
1109         // Put our Instruction in a list of Instructions
1110         InstructionsBuilder isb = new InstructionsBuilder();
1111         List<Instruction> instructions = new ArrayList<Instruction>();
1112         instructions.add(ib.build());
1113         isb.setInstruction(instructions);
1114         return isb;
1115     }
1116
1117     private static InstructionsBuilder createAppyActionInstruction13() {
1118
1119         List<Action> actionList = new ArrayList<Action>();
1120         ActionBuilder ab = new ActionBuilder();
1121
1122         DropActionBuilder drop = new DropActionBuilder();
1123         ab.setAction(new DropActionCaseBuilder().setDropAction(drop.build()).build());
1124         actionList.add(ab.build());
1125
1126         // Create an Apply Action
1127         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1128         aab.setAction(actionList);
1129
1130         // Wrap our Apply Action in an Instruction
1131         InstructionBuilder ib = new InstructionBuilder();
1132         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1133
1134         // Put our Instruction in a list of Instructions
1135         InstructionsBuilder isb = new InstructionsBuilder();
1136         List<Instruction> instructions = new ArrayList<Instruction>();
1137         instructions.add(ib.build());
1138         isb.setInstruction(instructions);
1139         return isb;
1140     }
1141
1142     private static InstructionsBuilder createAppyActionInstruction14() {
1143
1144         List<Action> actionList = new ArrayList<Action>();
1145         ActionBuilder ab = new ActionBuilder();
1146
1147         FloodActionBuilder fld = new FloodActionBuilder();
1148         ab.setAction(new FloodActionCaseBuilder().setFloodAction(fld.build()).build());
1149         actionList.add(ab.build());
1150         // Create an Apply Action
1151         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1152         aab.setAction(actionList);
1153
1154         // Wrap our Apply Action in an Instruction
1155         InstructionBuilder ib = new InstructionBuilder();
1156         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1157
1158         // Put our Instruction in a list of Instructions
1159         InstructionsBuilder isb = new InstructionsBuilder();
1160         List<Instruction> instructions = new ArrayList<Instruction>();
1161         instructions.add(ib.build());
1162         isb.setInstruction(instructions);
1163         return isb;
1164     }
1165
1166     private static InstructionsBuilder createAppyActionInstruction15() {
1167
1168         List<Action> actionList = new ArrayList<Action>();
1169         ActionBuilder ab = new ActionBuilder();
1170
1171         FloodAllActionBuilder fldall = new FloodAllActionBuilder();
1172         ab.setAction(new FloodAllActionCaseBuilder().setFloodAllAction(fldall.build()).build());
1173         actionList.add(ab.build());
1174         // Create an Apply Action
1175         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1176         aab.setAction(actionList);
1177
1178         // Wrap our Apply Action in an Instruction
1179         InstructionBuilder ib = new InstructionBuilder();
1180         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1181
1182         // Put our Instruction in a list of Instructions
1183         InstructionsBuilder isb = new InstructionsBuilder();
1184         List<Instruction> instructions = new ArrayList<Instruction>();
1185         instructions.add(ib.build());
1186         isb.setInstruction(instructions);
1187         return isb;
1188     }
1189
1190     private static InstructionsBuilder createAppyActionInstruction16() {
1191
1192         List<Action> actionList = new ArrayList<Action>();
1193         ActionBuilder ab = new ActionBuilder();
1194
1195         GroupActionBuilder groupActionB = new GroupActionBuilder();
1196         groupActionB.setGroupId(1L);
1197         groupActionB.setGroup("0");
1198         ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
1199         actionList.add(ab.build());
1200
1201         // Create an Apply Action
1202         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1203         aab.setAction(actionList);
1204
1205         // Wrap our Apply Action in an Instruction
1206         InstructionBuilder ib = new InstructionBuilder();
1207         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1208
1209         // Put our Instruction in a list of Instructions
1210         InstructionsBuilder isb = new InstructionsBuilder();
1211         List<Instruction> instructions = new ArrayList<Instruction>();
1212         instructions.add(ib.build());
1213         isb.setInstruction(instructions);
1214         return isb;
1215     }
1216
1217     private static InstructionsBuilder createAppyActionInstruction17() {
1218
1219         List<Action> actionList = new ArrayList<Action>();
1220         ActionBuilder ab = new ActionBuilder();
1221
1222         HwPathActionBuilder hwPathB = new HwPathActionBuilder();
1223         ab.setAction(new HwPathActionCaseBuilder().setHwPathAction(hwPathB.build()).build());
1224         actionList.add(ab.build());
1225         // Create an Apply Action
1226         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1227         aab.setAction(actionList);
1228
1229         // Wrap our Apply Action in an Instruction
1230         InstructionBuilder ib = new InstructionBuilder();
1231         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1232
1233         // Put our Instruction in a list of Instructions
1234         InstructionsBuilder isb = new InstructionsBuilder();
1235         List<Instruction> instructions = new ArrayList<Instruction>();
1236         instructions.add(ib.build());
1237         isb.setInstruction(instructions);
1238         return isb;
1239     }
1240
1241     private static InstructionsBuilder createAppyActionInstruction18() {
1242
1243         List<Action> actionList = new ArrayList<Action>();
1244         ActionBuilder ab = new ActionBuilder();
1245
1246         LoopbackActionBuilder loopbackActionBuilder = new LoopbackActionBuilder();
1247         ab.setAction(new LoopbackActionCaseBuilder().setLoopbackAction(loopbackActionBuilder.build()).build());
1248         actionList.add(ab.build());
1249
1250         // Create an Apply Action
1251         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1252         aab.setAction(actionList);
1253
1254         // Wrap our Apply Action in an Instruction
1255         InstructionBuilder ib = new InstructionBuilder();
1256         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1257
1258         // Put our Instruction in a list of Instructions
1259         InstructionsBuilder isb = new InstructionsBuilder();
1260         List<Instruction> instructions = new ArrayList<Instruction>();
1261         instructions.add(ib.build());
1262         isb.setInstruction(instructions);
1263         return isb;
1264     }
1265
1266     private static InstructionsBuilder createAppyActionInstruction19() {
1267
1268         List<Action> actionList = new ArrayList<Action>();
1269         ActionBuilder ab = new ActionBuilder();
1270
1271         PopMplsActionBuilder popMplsActionBuilder = new PopMplsActionBuilder();
1272         popMplsActionBuilder.setEthernetType(0XB);
1273         ab.setAction(new PopMplsActionCaseBuilder().setPopMplsAction(popMplsActionBuilder.build()).build());
1274         actionList.add(ab.build());
1275         // Create an Apply Action
1276         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1277         aab.setAction(actionList);
1278
1279         // Wrap our Apply Action in an Instruction
1280         InstructionBuilder ib = new InstructionBuilder();
1281         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1282
1283         // Put our Instruction in a list of Instructions
1284         InstructionsBuilder isb = new InstructionsBuilder();
1285         List<Instruction> instructions = new ArrayList<Instruction>();
1286         instructions.add(ib.build());
1287         isb.setInstruction(instructions);
1288         return isb;
1289     }
1290
1291     private static InstructionsBuilder createAppyActionInstruction20() {
1292
1293         List<Action> actionList = new ArrayList<Action>();
1294         ActionBuilder ab = new ActionBuilder();
1295
1296         PopPbbActionBuilder popPbbActionBuilder = new PopPbbActionBuilder();
1297         ab.setAction(new PopPbbActionCaseBuilder().setPopPbbAction(popPbbActionBuilder.build()).build());
1298         actionList.add(ab.build());
1299         // Create an Apply Action
1300         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1301         aab.setAction(actionList);
1302
1303         // Wrap our Apply Action in an Instruction
1304         InstructionBuilder ib = new InstructionBuilder();
1305         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1306
1307         // Put our Instruction in a list of Instructions
1308         InstructionsBuilder isb = new InstructionsBuilder();
1309         List<Instruction> instructions = new ArrayList<Instruction>();
1310         instructions.add(ib.build());
1311         isb.setInstruction(instructions);
1312         return isb;
1313     }
1314
1315     private static InstructionsBuilder createAppyActionInstruction21() {
1316
1317         List<Action> actionList = new ArrayList<Action>();
1318         ActionBuilder ab = new ActionBuilder();
1319
1320         PopVlanActionBuilder popVlanActionBuilder = new PopVlanActionBuilder();
1321         ab.setAction(new PopVlanActionCaseBuilder().setPopVlanAction(popVlanActionBuilder.build()).build());
1322         actionList.add(ab.build());
1323
1324         // Create an Apply Action
1325         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1326         aab.setAction(actionList);
1327
1328         // Wrap our Apply Action in an Instruction
1329         InstructionBuilder ib = new InstructionBuilder();
1330         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1331
1332         // Put our Instruction in a list of Instructions
1333         InstructionsBuilder isb = new InstructionsBuilder();
1334         List<Instruction> instructions = new ArrayList<Instruction>();
1335         instructions.add(ib.build());
1336         isb.setInstruction(instructions);
1337         return isb;
1338     }
1339
1340     private static InstructionsBuilder createAppyActionInstruction22() {
1341
1342         List<Action> actionList = new ArrayList<Action>();
1343         ActionBuilder ab = new ActionBuilder();
1344
1345         SetDlTypeActionBuilder setDlTypeActionBuilder = new SetDlTypeActionBuilder();
1346         setDlTypeActionBuilder.setDlType(new EtherType(8L));
1347         ab.setAction(new SetDlTypeActionCaseBuilder().setSetDlTypeAction(setDlTypeActionBuilder.build()).build());
1348         actionList.add(ab.build());
1349
1350         // Create an Apply Action
1351         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1352         aab.setAction(actionList);
1353
1354         // Wrap our Apply Action in an Instruction
1355         InstructionBuilder ib = new InstructionBuilder();
1356         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1357
1358         // Put our Instruction in a list of Instructions
1359         InstructionsBuilder isb = new InstructionsBuilder();
1360         List<Instruction> instructions = new ArrayList<Instruction>();
1361         instructions.add(ib.build());
1362         isb.setInstruction(instructions);
1363         return isb;
1364     }
1365
1366     private static InstructionsBuilder createAppyActionInstruction23() {
1367
1368         List<Action> actionList = new ArrayList<Action>();
1369         ActionBuilder ab = new ActionBuilder();
1370
1371         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
1372         setFieldBuilder.setInPort(new Long(2));
1373         actionList.add(ab.build());
1374
1375         // Create an Apply Action
1376         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1377         aab.setAction(actionList);
1378
1379         // Wrap our Apply Action in an Instruction
1380         InstructionBuilder ib = new InstructionBuilder();
1381         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1382
1383         // Put our Instruction in a list of Instructions
1384         InstructionsBuilder isb = new InstructionsBuilder();
1385         List<Instruction> instructions = new ArrayList<Instruction>();
1386         instructions.add(ib.build());
1387         isb.setInstruction(instructions);
1388         return isb;
1389     }
1390
1391     private static InstructionsBuilder createAppyActionInstruction24() {
1392
1393         List<Action> actionList = new ArrayList<Action>();
1394         ActionBuilder ab = new ActionBuilder();
1395
1396         SetMplsTtlActionBuilder setMplsTtlActionBuilder = new SetMplsTtlActionBuilder();
1397         setMplsTtlActionBuilder.setMplsTtl((short) 0X1);
1398         ab.setAction(new SetMplsTtlActionCaseBuilder().setSetMplsTtlAction(setMplsTtlActionBuilder.build()).build());
1399         actionList.add(ab.build());
1400
1401         // Create an Apply Action
1402         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1403         aab.setAction(actionList);
1404
1405         // Wrap our Apply Action in an Instruction
1406         InstructionBuilder ib = new InstructionBuilder();
1407         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1408
1409         // Put our Instruction in a list of Instructions
1410         InstructionsBuilder isb = new InstructionsBuilder();
1411         List<Instruction> instructions = new ArrayList<Instruction>();
1412         instructions.add(ib.build());
1413         isb.setInstruction(instructions);
1414         return isb;
1415     }
1416
1417     private static InstructionsBuilder createAppyActionInstruction25() {
1418
1419         List<Action> actionList = new ArrayList<Action>();
1420         ActionBuilder ab = new ActionBuilder();
1421
1422         SetNextHopActionBuilder setNextHopActionBuilder = new SetNextHopActionBuilder();
1423         Ipv4Builder ipnext = new Ipv4Builder();
1424         Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
1425         ipnext.setIpv4Address(prefix);
1426         setNextHopActionBuilder.setAddress(ipnext.build());
1427         ab.setAction(new SetNextHopActionCaseBuilder().setSetNextHopAction(setNextHopActionBuilder.build()).build());
1428         actionList.add(ab.build());
1429
1430         // Create an Apply Action
1431         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1432         aab.setAction(actionList);
1433
1434         // Wrap our Apply Action in an Instruction
1435         InstructionBuilder ib = new InstructionBuilder();
1436         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1437
1438         // Put our Instruction in a list of Instructions
1439         InstructionsBuilder isb = new InstructionsBuilder();
1440         List<Instruction> instructions = new ArrayList<Instruction>();
1441         instructions.add(ib.build());
1442         isb.setInstruction(instructions);
1443         return isb;
1444     }
1445
1446     private static InstructionsBuilder createAppyActionInstruction26() {
1447
1448         List<Action> actionList = new ArrayList<Action>();
1449         ActionBuilder ab = new ActionBuilder();
1450
1451         SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
1452         Ipv4Builder ipdst = new Ipv4Builder();
1453         Ipv4Prefix prefixdst = new Ipv4Prefix("10.0.0.21/24");
1454         ipdst.setIpv4Address(prefixdst);
1455         setNwDstActionBuilder.setAddress(ipdst.build());
1456         ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
1457         actionList.add(ab.build());
1458
1459         // Create an Apply Action
1460         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1461         aab.setAction(actionList);
1462
1463         // Wrap our Apply Action in an Instruction
1464         InstructionBuilder ib = new InstructionBuilder();
1465         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1466
1467         // Put our Instruction in a list of Instructions
1468         InstructionsBuilder isb = new InstructionsBuilder();
1469         List<Instruction> instructions = new ArrayList<Instruction>();
1470         instructions.add(ib.build());
1471         isb.setInstruction(instructions);
1472         return isb;
1473     }
1474
1475     private static InstructionsBuilder createAppyActionInstruction27() {
1476
1477         List<Action> actionList = new ArrayList<Action>();
1478         ActionBuilder ab = new ActionBuilder();
1479
1480         SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
1481         Ipv4Builder ipsrc = new Ipv4Builder();
1482         Ipv4Prefix prefixsrc = new Ipv4Prefix("10.0.23.21/24");
1483         ipsrc.setIpv4Address(prefixsrc);
1484         setNwsrcActionBuilder.setAddress(ipsrc.build());
1485         ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
1486         actionList.add(ab.build());
1487
1488         // Create an Apply Action
1489         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1490         aab.setAction(actionList);
1491
1492         // Wrap our Apply Action in an Instruction
1493         InstructionBuilder ib = new InstructionBuilder();
1494         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1495
1496         // Put our Instruction in a list of Instructions
1497         InstructionsBuilder isb = new InstructionsBuilder();
1498         List<Instruction> instructions = new ArrayList<Instruction>();
1499         instructions.add(ib.build());
1500         isb.setInstruction(instructions);
1501         return isb;
1502     }
1503
1504     private static InstructionsBuilder createAppyActionInstruction28() {
1505
1506         List<Action> actionList = new ArrayList<Action>();
1507         ActionBuilder ab = new ActionBuilder();
1508
1509         SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
1510         setNwTosActionBuilder.setTos(8);
1511         ab.setAction(new SetNwTosActionCaseBuilder().setSetNwTosAction(setNwTosActionBuilder.build()).build());
1512         actionList.add(ab.build());
1513         // Create an Apply Action
1514         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1515         aab.setAction(actionList);
1516
1517         // Wrap our Apply Action in an Instruction
1518         InstructionBuilder ib = new InstructionBuilder();
1519         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1520
1521         // Put our Instruction in a list of Instructions
1522         InstructionsBuilder isb = new InstructionsBuilder();
1523         List<Instruction> instructions = new ArrayList<Instruction>();
1524         instructions.add(ib.build());
1525         isb.setInstruction(instructions);
1526         return isb;
1527     }
1528
1529     private static InstructionsBuilder createAppyActionInstruction29() {
1530
1531         List<Action> actionList = new ArrayList<Action>();
1532         ActionBuilder ab = new ActionBuilder();
1533
1534         SetNwTtlActionBuilder setNwTtlActionBuilder = new SetNwTtlActionBuilder();
1535         setNwTtlActionBuilder.setNwTtl((short) 1);
1536         ab.setAction(new SetNwTtlActionCaseBuilder().setSetNwTtlAction(setNwTtlActionBuilder.build()).build());
1537         actionList.add(ab.build());
1538
1539         // Create an Apply Action
1540         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1541         aab.setAction(actionList);
1542
1543         // Wrap our Apply Action in an Instruction
1544         InstructionBuilder ib = new InstructionBuilder();
1545         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1546
1547         // Put our Instruction in a list of Instructions
1548         InstructionsBuilder isb = new InstructionsBuilder();
1549         List<Instruction> instructions = new ArrayList<Instruction>();
1550         instructions.add(ib.build());
1551         isb.setInstruction(instructions);
1552         return isb;
1553     }
1554
1555     private static InstructionsBuilder createAppyActionInstruction30() {
1556
1557         List<Action> actionList = new ArrayList<Action>();
1558         ActionBuilder ab = new ActionBuilder();
1559
1560         SetQueueActionBuilder setQueueActionBuilder = new SetQueueActionBuilder();
1561         setQueueActionBuilder.setQueueId(1L);
1562         ab.setAction(new  SetQueueActionCaseBuilder().setSetQueueAction(setQueueActionBuilder.build()).build());
1563         actionList.add(ab.build());
1564         // Create an Apply Action
1565         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1566         aab.setAction(actionList);
1567
1568         // Wrap our Apply Action in an Instruction
1569         InstructionBuilder ib = new InstructionBuilder();
1570         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1571
1572         // Put our Instruction in a list of Instructions
1573         InstructionsBuilder isb = new InstructionsBuilder();
1574         List<Instruction> instructions = new ArrayList<Instruction>();
1575         instructions.add(ib.build());
1576         isb.setInstruction(instructions);
1577         return isb;
1578     }
1579
1580     private static InstructionsBuilder createAppyActionInstruction31() {
1581
1582         List<Action> actionList = new ArrayList<Action>();
1583         ActionBuilder ab = new ActionBuilder();
1584
1585         SetTpDstActionBuilder setTpDstActionBuilder = new SetTpDstActionBuilder();
1586         setTpDstActionBuilder.setPort(new PortNumber(109));
1587
1588         ab.setAction(new SetTpDstActionCaseBuilder().setSetTpDstAction(setTpDstActionBuilder.build()).build());
1589         actionList.add(ab.build());
1590         // Create an Apply Action
1591         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1592         aab.setAction(actionList);
1593
1594         // Wrap our Apply Action in an Instruction
1595         InstructionBuilder ib = new InstructionBuilder();
1596         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1597
1598         // Put our Instruction in a list of Instructions
1599         InstructionsBuilder isb = new InstructionsBuilder();
1600         List<Instruction> instructions = new ArrayList<Instruction>();
1601         instructions.add(ib.build());
1602         isb.setInstruction(instructions);
1603         return isb;
1604     }
1605
1606     private static InstructionsBuilder createAppyActionInstruction32() {
1607
1608         List<Action> actionList = new ArrayList<Action>();
1609         ActionBuilder ab = new ActionBuilder();
1610
1611         SetTpSrcActionBuilder setTpSrcActionBuilder = new SetTpSrcActionBuilder();
1612         setTpSrcActionBuilder.setPort(new PortNumber(109));
1613         ab.setAction(new SetTpSrcActionCaseBuilder().setSetTpSrcAction(setTpSrcActionBuilder.build()).build());
1614         actionList.add(ab.build());
1615
1616         // Create an Apply Action
1617         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1618         aab.setAction(actionList);
1619
1620         // Wrap our Apply Action in an Instruction
1621         InstructionBuilder ib = new InstructionBuilder();
1622         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1623
1624         // Put our Instruction in a list of Instructions
1625         InstructionsBuilder isb = new InstructionsBuilder();
1626         List<Instruction> instructions = new ArrayList<Instruction>();
1627         instructions.add(ib.build());
1628         isb.setInstruction(instructions);
1629         return isb;
1630     }
1631
1632     private static InstructionsBuilder createAppyActionInstruction33() {
1633
1634         List<Action> actionList = new ArrayList<Action>();
1635         ActionBuilder ab = new ActionBuilder();
1636
1637         SetVlanCfiActionBuilder setVlanCfiActionBuilder = new SetVlanCfiActionBuilder();
1638         setVlanCfiActionBuilder.setVlanCfi(new VlanCfi(2));
1639         ab.setAction(new SetVlanCfiActionCaseBuilder().setSetVlanCfiAction(setVlanCfiActionBuilder.build()).build());
1640         actionList.add(ab.build());
1641
1642         // Create an Apply Action
1643         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1644         aab.setAction(actionList);
1645
1646         // Wrap our Apply Action in an Instruction
1647         InstructionBuilder ib = new InstructionBuilder();
1648         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1649
1650         // Put our Instruction in a list of Instructions
1651         InstructionsBuilder isb = new InstructionsBuilder();
1652         List<Instruction> instructions = new ArrayList<Instruction>();
1653         instructions.add(ib.build());
1654         isb.setInstruction(instructions);
1655         return isb;
1656     }
1657
1658     private static InstructionsBuilder createAppyActionInstruction34() {
1659
1660         List<Action> actionList = new ArrayList<Action>();
1661         ActionBuilder ab = new ActionBuilder();
1662
1663         SwPathActionBuilder swPathAction = new SwPathActionBuilder();
1664         ab.setAction(new SwPathActionCaseBuilder().setSwPathAction(swPathAction.build()).build());
1665         actionList.add(ab.build());
1666
1667         // Create an Apply Action
1668         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1669         aab.setAction(actionList);
1670
1671         // Wrap our Apply Action in an Instruction
1672         InstructionBuilder ib = new InstructionBuilder();
1673         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1674
1675         // Put our Instruction in a list of Instructions
1676         InstructionsBuilder isb = new InstructionsBuilder();
1677         List<Instruction> instructions = new ArrayList<Instruction>();
1678         instructions.add(ib.build());
1679         isb.setInstruction(instructions);
1680         return isb;
1681     }
1682
1683     /**
1684      * @return
1685      */
1686     private static MatchBuilder createMatch1() {
1687         MatchBuilder match = new MatchBuilder();
1688         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1689         Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
1690         ipv4Match.setIpv4Destination(prefix);
1691         Ipv4Match i4m = ipv4Match.build();
1692         match.setLayer3Match(i4m);
1693
1694         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1695         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1696         ethTypeBuilder.setType(new EtherType(0x0800L));
1697         eth.setEthernetType(ethTypeBuilder.build());
1698         match.setEthernetMatch(eth.build());
1699         return match;
1700     }
1701
1702     /**
1703      * @return
1704      */
1705     private static MatchBuilder createIPv4DstMatch() {
1706         MatchBuilder match = new MatchBuilder();
1707         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1708         Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
1709         ipv4Match.setIpv4Destination(prefix);
1710         Ipv4Match i4m = ipv4Match.build();
1711         match.setLayer3Match(i4m);
1712
1713         return match;
1714     }
1715
1716     /**
1717      * @return
1718      */
1719     private static MatchBuilder createIPv4SrcMatch() {
1720         MatchBuilder match = new MatchBuilder();
1721         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1722         Ipv4Prefix prefix = new Ipv4Prefix("10.20.30.40/24");
1723         ipv4Match.setIpv4Source(prefix);
1724         Ipv4Match i4m = ipv4Match.build();
1725         match.setLayer3Match(i4m);
1726
1727         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1728         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1729         ethTypeBuilder.setType(new EtherType(0x0800L));
1730         eth.setEthernetType(ethTypeBuilder.build());
1731         match.setEthernetMatch(eth.build());
1732         return match;
1733     }
1734
1735     
1736     
1737     /**
1738      * @return
1739      */
1740     private static MatchBuilder createMatch2() {
1741         MatchBuilder match = new MatchBuilder();
1742         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1743         Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1");
1744         ipv4Match.setIpv4Source(prefix);
1745         Ipv4Match i4m = ipv4Match.build();
1746         match.setLayer3Match(i4m);
1747
1748         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1749         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1750         ethTypeBuilder.setType(new EtherType(0x0800L));
1751         eth.setEthernetType(ethTypeBuilder.build());
1752         match.setEthernetMatch(eth.build());
1753         return match;
1754     }
1755
1756     /**
1757      * @return
1758      */
1759     private static MatchBuilder createMatch3() {
1760         MatchBuilder match = new MatchBuilder();
1761         EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
1762         EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
1763         ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
1764         ethernetMatch.setEthernetSource(ethSourceBuilder.build());
1765         match.setEthernetMatch(ethernetMatch.build());
1766
1767         return match;
1768     }
1769     
1770     private static MatchBuilder createInphyportMatch() {
1771         MatchBuilder match = new MatchBuilder();
1772         match.setInPort(202L);
1773         match.setInPhyPort(10122L);
1774         return match;
1775     }
1776
1777     private static MatchBuilder createEthernetMatch() {
1778         MatchBuilder match = new MatchBuilder();
1779
1780         byte[] mask1 = new byte[] { (byte) -1, (byte) -1, 0, 0, 0, 0 };
1781         byte[] mask2 = new byte[] { (byte) -1, (byte) -1, (byte) -1, 0, 0, 0 };
1782
1783         EthernetMatchBuilder ethmatch = new EthernetMatchBuilder(); // ethernettype
1784                                                                     // match
1785         EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
1786         EtherType type = new EtherType(0x0800L);
1787         ethmatch.setEthernetType(ethtype.setType(type).build());
1788
1789         EthernetDestinationBuilder ethdest = new EthernetDestinationBuilder(); // ethernet
1790                                                                                // macaddress
1791                                                                                // match
1792         MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
1793         ethdest.setAddress(macdest);
1794         ethdest.setMask(mask1);
1795
1796         ethmatch.setEthernetDestination(ethdest.build());
1797
1798         EthernetSourceBuilder ethsrc = new EthernetSourceBuilder();
1799         MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
1800         ethsrc.setAddress(macsrc);
1801         ethsrc.setMask(mask2);
1802
1803         ethmatch.setEthernetSource(ethsrc.build());
1804         match.setEthernetMatch(ethmatch.build());
1805         return match;
1806
1807     }
1808
1809     /**
1810      * @return
1811      */
1812
1813     private static MatchBuilder createVlanMatch() {
1814         MatchBuilder match = new MatchBuilder();
1815         VlanMatchBuilder vlanBuilder = new VlanMatchBuilder(); // vlan match
1816         VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
1817         VlanId vlanId = new VlanId(10);
1818         VlanPcp vpcp = new VlanPcp((short) 3);
1819         vlanBuilder.setVlanPcp(vpcp);
1820         vlanIdBuilder.setVlanId(vlanId);
1821         vlanIdBuilder.setVlanIdPresent(true);
1822         vlanBuilder.setVlanId(vlanIdBuilder.build());
1823         match.setVlanMatch(vlanBuilder.build());
1824         return match;
1825     }
1826
1827     /**
1828      * @return
1829      */
1830     private static MatchBuilder createArpMatch() {
1831         MatchBuilder match = new MatchBuilder();
1832
1833         EthernetMatchBuilder ethmatch = new EthernetMatchBuilder();
1834         MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
1835         MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
1836
1837         byte[] mask = new byte[] { (byte) -1, (byte) -1, 0, 0, 0, 0 };
1838         byte[] mask2 = new byte[] { (byte) -1, (byte) -1, (byte) -1, 0, 0, 0 };
1839
1840         EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
1841         EtherType type = new EtherType(0x0806L);
1842         ethmatch.setEthernetType(ethtype.setType(type).build());
1843
1844         Ipv4Prefix dstip = new Ipv4Prefix("200.71.9.52/10"); // ipv4 match
1845         Ipv4Prefix srcip = new Ipv4Prefix("100.1.1.1/8");
1846
1847         ArpMatchBuilder arpmatch = new ArpMatchBuilder(); // arp match
1848         ArpSourceHardwareAddressBuilder arpsrc = new ArpSourceHardwareAddressBuilder();
1849         arpsrc.setAddress(macsrc);
1850         arpsrc.setMask(mask);
1851         ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder();
1852         arpdst.setAddress(macdest);
1853         arpdst.setMask(mask2);
1854         arpmatch.setArpOp(2);
1855         arpmatch.setArpSourceHardwareAddress(arpsrc.build());
1856         arpmatch.setArpTargetHardwareAddress(arpdst.build());
1857         arpmatch.setArpSourceTransportAddress(srcip);
1858         arpmatch.setArpTargetTransportAddress(dstip);
1859
1860         match.setEthernetMatch(ethmatch.build());
1861         match.setLayer3Match(arpmatch.build());
1862
1863         return match;
1864     }
1865
1866     /**
1867      * @return
1868      */
1869     private static MatchBuilder createIPMatch() {
1870         MatchBuilder match = new MatchBuilder();
1871         EthernetMatchBuilder ethmatch = new EthernetMatchBuilder();
1872         EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
1873         EtherType type = new EtherType(0x0800L);
1874         ethmatch.setEthernetType(ethtype.setType(type).build());
1875         match.setEthernetMatch(ethmatch.build());
1876
1877         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
1878         ipmatch.setIpProtocol((short) 1);
1879         Dscp dscp = new Dscp((short) 3);
1880         ipmatch.setIpDscp(dscp);
1881         ipmatch.setIpEcn((short) 2);
1882         match.setIpMatch(ipmatch.build());
1883         return match;
1884     }
1885
1886     /**
1887      * @return
1888      */
1889     private static MatchBuilder createL3IPv4Match() {
1890         MatchBuilder match = new MatchBuilder();
1891
1892         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1893         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1894         ethTypeBuilder.setType(new EtherType(0x0800L));
1895         eth.setEthernetType(ethTypeBuilder.build());
1896         match.setEthernetMatch(eth.build());
1897
1898         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1899         Ipv4Prefix dstip = new Ipv4Prefix("200.71.9.52/10"); // ipv4 match
1900         Ipv4Prefix srcip = new Ipv4Prefix("100.1.1.1/8");
1901         Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
1902         ipv4match.setIpv4Destination(dstip);
1903         ipv4match.setIpv4Source(srcip);
1904         match.setLayer3Match(ipv4match.build());
1905
1906         return match;
1907
1908     }
1909
1910     /**
1911      * @return
1912      */
1913     private static MatchBuilder createL3IPv6Match() {
1914         MatchBuilder match = new MatchBuilder();
1915
1916         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1917         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1918         ethTypeBuilder.setType(new EtherType(0x86ddL));
1919         eth.setEthernetType(ethTypeBuilder.build());
1920         match.setEthernetMatch(eth.build());
1921
1922         Ipv6Prefix dstip6 = new Ipv6Prefix("2002::2/64");
1923         Ipv6Prefix srcip6 = new Ipv6Prefix("2001:0:0:0:0:0:0:1/56");
1924         Ipv6Address ndtarget = new Ipv6Address("2001:db8:0:1:fd97:f9f0:a810:782e");
1925         MacAddress ndsll = new MacAddress("c2:00:54:f5:00:00");
1926         MacAddress ndtll = new MacAddress("00:0c:29:0e:4c:67");
1927         Ipv6ExtHeaderBuilder nextheader = new Ipv6ExtHeaderBuilder();
1928         nextheader.setIpv6Exthdr(58);
1929         Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
1930         Ipv6FlowLabel label = new Ipv6FlowLabel(10028L);
1931         ipv6label.setIpv6Flabel(label);
1932         ipv6label.setFlabelMask(new byte[] { 0, 1, -1, -1 });
1933
1934         Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1935                                                                    // match
1936         icmpv6match.setIcmpv6Type((short) 135);
1937         icmpv6match.setIcmpv6Code((short) 0);
1938         match.setIcmpv6Match(icmpv6match.build());
1939
1940         Ipv6MatchBuilder ipv6match = new Ipv6MatchBuilder();
1941         // ipv6match.setIpv6Source(srcip6);
1942         // ipv6match.setIpv6Destination(dstip6);
1943         // ipv6match.setIpv6ExtHeader(nextheader.build());
1944         ipv6match.setIpv6NdSll(ndsll);
1945         ipv6match.setIpv6NdTll(ndtll);
1946         // ipv6match.setIpv6NdTarget(ndtarget);
1947         ipv6match.setIpv6Label(ipv6label.build());
1948
1949         match.setLayer3Match(ipv6match.build());
1950
1951         return match;
1952     }
1953
1954     /**
1955      * @return
1956      */
1957
1958     private static MatchBuilder createICMPv4Match() {
1959         MatchBuilder match = new MatchBuilder();
1960         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1961         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1962         ethTypeBuilder.setType(new EtherType(0x0800L));
1963         eth.setEthernetType(ethTypeBuilder.build());
1964         match.setEthernetMatch(eth.build());
1965
1966         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
1967         ipmatch.setIpProtocol((short) 1);
1968         match.setIpMatch(ipmatch.build());
1969
1970         Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder(); // icmpv4
1971                                                                    // match
1972         icmpv4match.setIcmpv4Type((short) 8);
1973         icmpv4match.setIcmpv4Code((short) 0);
1974         match.setIcmpv4Match(icmpv4match.build());
1975         return match;
1976     }
1977
1978     /**
1979      * @return
1980      */
1981     private static MatchBuilder createICMPv6Match() {
1982
1983         MatchBuilder match = new MatchBuilder();
1984         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1985         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1986         ethTypeBuilder.setType(new EtherType(0x86ddL));
1987         eth.setEthernetType(ethTypeBuilder.build());
1988         match.setEthernetMatch(eth.build());
1989
1990         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
1991         ipmatch.setIpProtocol((short) 58);
1992         match.setIpMatch(ipmatch.build());
1993
1994         Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1995                                                                    // match
1996         icmpv6match.setIcmpv6Type((short) 135);
1997         icmpv6match.setIcmpv6Code((short) 1);
1998         match.setIcmpv6Match(icmpv6match.build());
1999
2000         return match;
2001     }
2002     
2003     /**
2004      * @return
2005      */
2006     private static MatchBuilder createToSMatch() {
2007         MatchBuilder match = new MatchBuilder();
2008         EthernetMatchBuilder ethmatch = new EthernetMatchBuilder();
2009         EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
2010         EtherType type = new EtherType(0x0800L);
2011         ethmatch.setEthernetType(ethtype.setType(type).build());
2012         match.setEthernetMatch(ethmatch.build());
2013
2014         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
2015         ipmatch.setIpProtocol((short) 6);
2016         Dscp dscp = new Dscp((short) 8);
2017         ipmatch.setIpDscp(dscp);
2018         match.setIpMatch(ipmatch.build());
2019         return match;
2020     }
2021
2022
2023     /**
2024      * @return
2025      */
2026
2027     private static MatchBuilder createL4TCPMatch() {
2028         MatchBuilder match = new MatchBuilder();
2029
2030         EthernetMatchBuilder eth = new EthernetMatchBuilder();
2031         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2032         ethTypeBuilder.setType(new EtherType(0x0800L));
2033         eth.setEthernetType(ethTypeBuilder.build());
2034         match.setEthernetMatch(eth.build());
2035
2036         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
2037         ipmatch.setIpProtocol((short) 6);
2038         match.setIpMatch(ipmatch.build());
2039
2040         PortNumber srcport = new PortNumber(1213);
2041         PortNumber dstport = new PortNumber(646);
2042         TcpMatchBuilder tcpmatch = new TcpMatchBuilder(); // tcp match
2043         tcpmatch.setTcpSourcePort(srcport);
2044         tcpmatch.setTcpDestinationPort(dstport);
2045         match.setLayer4Match(tcpmatch.build());
2046
2047         return match;
2048     }
2049
2050     /**
2051      * @return
2052      */
2053     private static MatchBuilder createL4UDPMatch() {
2054         MatchBuilder match = new MatchBuilder();
2055
2056         EthernetMatchBuilder eth = new EthernetMatchBuilder();
2057         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2058         ethTypeBuilder.setType(new EtherType(0x0800L));
2059         eth.setEthernetType(ethTypeBuilder.build());
2060         match.setEthernetMatch(eth.build());
2061
2062         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
2063         ipmatch.setIpProtocol((short) 17);
2064         match.setIpMatch(ipmatch.build());
2065
2066         PortNumber srcport = new PortNumber(1325);
2067         PortNumber dstport = new PortNumber(42);
2068         UdpMatchBuilder udpmatch = new UdpMatchBuilder(); // udp match
2069         udpmatch.setUdpDestinationPort(dstport);
2070         udpmatch.setUdpSourcePort(srcport);
2071         match.setLayer4Match(udpmatch.build());
2072
2073         return match;
2074     }
2075
2076     /**
2077      * @return
2078      */
2079     private static MatchBuilder createL4SCTPMatch() {
2080         MatchBuilder match = new MatchBuilder();
2081
2082         EthernetMatchBuilder eth = new EthernetMatchBuilder();
2083         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2084         ethTypeBuilder.setType(new EtherType(0x0800L));
2085         eth.setEthernetType(ethTypeBuilder.build());
2086         match.setEthernetMatch(eth.build());
2087
2088         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
2089         ipmatch.setIpProtocol((short) 132);
2090         match.setIpMatch(ipmatch.build());
2091
2092         SctpMatchBuilder sctpmatch = new SctpMatchBuilder();
2093         PortNumber srcport = new PortNumber(1435);
2094         PortNumber dstport = new PortNumber(22);
2095         sctpmatch.setSctpSourcePort(srcport);
2096         sctpmatch.setSctpDestinationPort(dstport);
2097         match.setLayer4Match(sctpmatch.build());
2098
2099         return match;
2100     }
2101
2102     /**
2103      * @return
2104      */
2105     private static MatchBuilder createMetadataMatch() {
2106         MatchBuilder match = new MatchBuilder();
2107         byte[] metamask = new byte[] { (byte) -1, (byte) -1, (byte) -1, 0, 0, 0, (byte) 1, (byte) 1 };
2108         MetadataBuilder metadata = new MetadataBuilder(); // metadata match
2109         metadata.setMetadata(BigInteger.valueOf(500L));
2110         metadata.setMetadataMask(metamask);
2111         match.setMetadata(metadata.build());
2112
2113         return match;
2114     }
2115
2116     /**
2117      * @return
2118      */
2119     private static MatchBuilder createMplsMatch() {
2120         MatchBuilder match = new MatchBuilder();
2121
2122         EthernetMatchBuilder eth = new EthernetMatchBuilder();
2123         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2124         ethTypeBuilder.setType(new EtherType(0x8847L));
2125         eth.setEthernetType(ethTypeBuilder.build());
2126         match.setEthernetMatch(eth.build());
2127
2128         ProtocolMatchFieldsBuilder protomatch = new ProtocolMatchFieldsBuilder(); // mpls
2129         // match
2130         protomatch.setMplsLabel((long) 36008);
2131         protomatch.setMplsTc((short) 4);
2132         protomatch.setMplsBos((short) 1);
2133         match.setProtocolMatchFields(protomatch.build());
2134
2135         return match;
2136
2137     }
2138
2139     /**
2140      * @return
2141      */
2142     private static MatchBuilder createPbbMatch() {
2143         MatchBuilder match = new MatchBuilder();
2144
2145         EthernetMatchBuilder eth = new EthernetMatchBuilder();
2146         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2147         ethTypeBuilder.setType(new EtherType(0x88E7L));
2148         eth.setEthernetType(ethTypeBuilder.build());
2149         match.setEthernetMatch(eth.build());
2150
2151         ProtocolMatchFieldsBuilder protomatch = new ProtocolMatchFieldsBuilder(); // mpls
2152         // match
2153         protomatch.setPbb(new PbbBuilder().setPbbIsid(4L).setPbbMask(new byte[] { 0, 1, 0, 0 }).build());
2154         match.setProtocolMatchFields(protomatch.build());
2155
2156         return match;
2157
2158     }
2159     
2160     /**
2161      * @return
2162      */
2163     private static MatchBuilder createTunnelIDMatch() {
2164         MatchBuilder match = new MatchBuilder();
2165         TunnelBuilder tunnel = new TunnelBuilder(); // tunnel id match
2166         tunnel.setTunnelId(BigInteger.valueOf(10668));
2167         byte[] mask = new byte[] { (byte) -1, (byte) -1, (byte) -1, 0, 0, 0, (byte) 1, (byte) 1 };
2168         tunnel.setTunnelMask(mask);
2169         match.setTunnel(tunnel.build());
2170
2171         return match;
2172     }
2173
2174     public void _removeMDFlow(CommandInterpreter ci) {
2175         DataModification<InstanceIdentifier<?>, DataObject> modification = dataBrokerService.beginTransaction();
2176         NodeBuilder tn = createTestNode(ci.nextArgument());
2177         FlowBuilder tf = createTestFlow(tn, ci.nextArgument(), ci.nextArgument());
2178         InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class)
2179                 .child(Node.class, tn.getKey()).augmentation(FlowCapableNode.class)
2180                 .child(Table.class, new TableKey(tf.getTableId())).child(Flow.class, tf.getKey())
2181                 .build();
2182         modification.removeOperationalData(nodeBuilderToInstanceId(tn));
2183         modification.removeOperationalData(path1);
2184         modification.removeConfigurationData(nodeBuilderToInstanceId(tn));
2185         modification.removeConfigurationData(path1);
2186         Future<RpcResult<TransactionStatus>> commitFuture = modification.commit();
2187         try {
2188             RpcResult<TransactionStatus> result = commitFuture.get();
2189             TransactionStatus status = result.getResult();
2190             ci.println("Status of Flow Data Loaded Transaction: " + status);
2191
2192         } catch (InterruptedException e) {
2193             LOG.error(e.getMessage(), e);
2194         } catch (ExecutionException e) {
2195             LOG.error(e.getMessage(), e);
2196         }
2197     }
2198
2199     public void _addMDFlow(CommandInterpreter ci) {
2200         NodeBuilder tn = createTestNode(ci.nextArgument());
2201         FlowBuilder tf = createTestFlow(tn, ci.nextArgument(), ci.nextArgument());
2202         writeFlow(ci, tf, tn);
2203     }
2204
2205     private void writeFlow(CommandInterpreter ci, FlowBuilder flow, NodeBuilder nodeBuilder) {
2206         DataModification<InstanceIdentifier<?>, DataObject> modification = dataBrokerService.beginTransaction();
2207         InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class)
2208                 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
2209                 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey())
2210                 .build();
2211         modification.putOperationalData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
2212         modification.putOperationalData(path1, flow.build());
2213         modification.putConfigurationData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
2214         modification.putConfigurationData(path1, flow.build());
2215         Future<RpcResult<TransactionStatus>> commitFuture = modification.commit();
2216         try {
2217             RpcResult<TransactionStatus> result = commitFuture.get();
2218             TransactionStatus status = result.getResult();
2219             ci.println("Status of Flow Data Loaded Transaction: " + status);
2220
2221         } catch (InterruptedException e) {
2222             LOG.error(e.getMessage(), e);
2223         } catch (ExecutionException e) {
2224             LOG.error(e.getMessage(), e);
2225         }
2226     }
2227
2228     public void _modifyMDFlow(CommandInterpreter ci) {
2229         NodeBuilder tn = createTestNode(ci.nextArgument());
2230         FlowBuilder tf = createTestFlow(tn, ci.nextArgument(), ci.nextArgument());
2231         tf.setFlowName(updatedFlowName);
2232         writeFlow(ci, tf, tn);
2233         tf.setFlowName(originalFlowName);
2234         writeFlow(ci, tf, tn);
2235     }
2236
2237     private static NodeRef createNodeRef(String string) {
2238         NodeKey key = new NodeKey(new NodeId(string));
2239         InstanceIdentifier<Node> path = InstanceIdentifier.builder().node(Nodes.class).node(Node.class, key)
2240                 .toInstance();
2241
2242         return new NodeRef(path);
2243     }
2244
2245     @Override
2246     public String getHelp() {
2247         return "No help";
2248     }
2249 }