Merge "Added a signum to the SetMetaDataMask BigInt constructor"
[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 com.google.common.util.concurrent.CheckedFuture;
12 import com.google.common.util.concurrent.FutureCallback;
13 import com.google.common.util.concurrent.Futures;
14 import java.math.BigInteger;
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.List;
18 import java.util.concurrent.ExecutorService;
19 import java.util.concurrent.Executors;
20 import java.util.concurrent.TimeUnit;
21 import org.eclipse.osgi.framework.console.CommandInterpreter;
22 import org.eclipse.osgi.framework.console.CommandProvider;
23 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
24 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
25 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
26 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
27 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
28 import org.opendaylight.controller.sal.binding.api.NotificationService;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.VlanCfi;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodActionCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.HwPathActionCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.LoopbackActionCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCaseBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlTypeActionCaseBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNextHopActionCaseBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCaseBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCaseBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanCfiActionCaseBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCaseBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.out._case.CopyTtlOutBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.mpls.ttl._case.DecMplsTtlBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.action._case.FloodActionBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.all.action._case.FloodAllActionBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.hw.path.action._case.HwPathActionBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.loopback.action._case.LoopbackActionBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstActionBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.type.action._case.SetDlTypeActionBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.next.hop.action._case.SetNextHopActionBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstActionBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcActionBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.cfi.action._case.SetVlanCfiActionBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.strip.vlan.action._case.StripVlanActionBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.sw.path.action._case.SwPathActionBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowListener;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagMatchBuilder;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
177 import org.opendaylight.yang.gen.v1.urn.opendaylight.node.error.service.rev140410.NodeErrorListener;
178 import org.opendaylight.yangtools.concepts.Registration;
179 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
180 import org.osgi.framework.BundleContext;
181 import org.slf4j.Logger;
182 import org.slf4j.LoggerFactory;
183
184 public class OpenflowpluginTestCommandProvider implements CommandProvider {
185
186     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestCommandProvider.class);
187
188     private DataBroker dataBroker;
189     private ProviderContext pc;
190     private final BundleContext ctx;
191     private FlowBuilder testFlow;
192     private NodeBuilder testNode;
193     private final String originalFlowName = "Foo";
194     private final String updatedFlowName = "Bar";
195     private final SalFlowListener flowEventListener = new FlowEventListenerLoggingImpl();
196     private final NodeErrorListener nodeErrorListener = new NodeErrorListenerLoggingImpl();
197     private static NotificationService notificationService;
198     private Registration listener1Reg;
199     private Registration listener2Reg;
200
201     public OpenflowpluginTestCommandProvider(BundleContext ctx) {
202         this.ctx = ctx;
203     }
204
205     public void onSessionInitiated(ProviderContext session) {
206         pc = session;
207         notificationService = session.getSALService(NotificationService.class);
208         // For switch events
209         listener1Reg = notificationService.registerNotificationListener(flowEventListener);
210         listener2Reg = notificationService.registerNotificationListener(nodeErrorListener);
211         dataBroker = session.getSALService(DataBroker.class);
212         ctx.registerService(CommandProvider.class.getName(), this, null);
213         createTestFlow(createTestNode(null), null, null);
214     }
215
216     private NodeBuilder createTestNode(String nodeId) {
217         if (nodeId == null) {
218             nodeId = OpenflowpluginTestActivator.NODE_ID;
219         }
220         NodeRef nodeOne = createNodeRef(nodeId);
221         NodeBuilder builder = new NodeBuilder();
222         builder.setId(new NodeId(nodeId));
223         builder.setKey(new NodeKey(builder.getId()));
224         testNode = builder;
225         return builder;
226     }
227
228     private InstanceIdentifier<Node> nodeBuilderToInstanceId(NodeBuilder node) {
229         return InstanceIdentifier.create(Nodes.class).child(Node.class, node.getKey());
230     }
231
232     private FlowBuilder createTestFlow(NodeBuilder nodeBuilder, String flowTypeArg, String tableId) {
233
234         FlowBuilder flow = new FlowBuilder();
235         long id = 123;
236
237         String flowType = flowTypeArg;
238         if (flowType == null) {
239             flowType = "f1";
240         }
241
242         flow.setPriority(2);
243
244         switch (flowType) {
245             case "f1":
246                 id += 1;
247                 flow.setMatch(createMatch1().build());
248                 flow.setInstructions(createDecNwTtlInstructions().build());
249                 break;
250             case "f2":
251                 id += 2;
252                 flow.setMatch(createMatch2().build());
253                 flow.setInstructions(createDropInstructions().build());
254                 break;
255             case "f3":
256                 id += 3;
257                 flow.setMatch(createMatch3().build());
258                 flow.setInstructions(createDropInstructions().build());
259                 break;
260             case "f4":
261                 id += 4;
262                 flow.setMatch(createEthernetMatch().build());
263                 flow.setInstructions(createDropInstructions().build());
264                 break;
265             case "f5":
266                 id += 5;
267                 flow.setMatch(createMatch1().build());
268                 flow.setInstructions(createAppyActionInstruction().build());
269                 break;
270             case "f6":
271                 id += 6;
272                 flow.setMatch(createMatch1().build());
273                 flow.setInstructions(createGotoTableInstructions().build());
274                 break;
275             case "f7":
276                 id += 7;
277                 flow.setMatch(createMatch1().build());
278                 flow.setInstructions(createMeterInstructions().build());
279                 break;
280             case "f8":
281                 id += 8;
282                 flow.setMatch(createMatch1().build());
283                 flow.setInstructions(createAppyActionInstruction1().build());
284                 break;
285             case "f9":
286                 id += 9;
287                 flow.setMatch(createMatch1().build());
288                 flow.setInstructions(createAppyActionInstruction2().build());
289                 break;
290             case "f10":
291                 id += 10;
292                 flow.setMatch(createMatch1().build());
293                 flow.setInstructions(createAppyActionInstruction3().build());
294                 break;
295             case "f11":
296                 id += 11;
297                 flow.setMatch(createMatch1().build());
298                 flow.setInstructions(createAppyActionInstruction4().build());
299                 break;
300             case "f12":
301                 id += 12;
302                 flow.setMatch(createMatch1().build());
303                 flow.setInstructions(createAppyActionInstruction5().build());
304                 break;
305             case "f13":
306                 id += 13;
307                 flow.setMatch(createMatch1().build());
308                 flow.setInstructions(createAppyActionInstruction6().build());
309                 break;
310             case "f14":
311                 id += 14;
312                 flow.setMatch(createMatch1().build());
313                 flow.setInstructions(createAppyActionInstruction7().build());
314                 break;
315             case "f15":
316                 id += 15;
317                 flow.setMatch(createMatch1().build());
318                 flow.setInstructions(createAppyActionInstruction8().build());
319                 break;
320             case "f16":
321                 id += 16;
322                 flow.setMatch(createMatch1().build());
323                 flow.setInstructions(createAppyActionInstruction9().build());
324                 break;
325             case "f17":
326                 id += 17;
327                 flow.setMatch(createMatch1().build());
328                 flow.setInstructions(createAppyActionInstruction10().build());
329                 break;
330             case "f18":
331                 id += 18;
332                 flow.setMatch(createMatch1().build());
333                 flow.setInstructions(createAppyActionInstruction11().build());
334                 break;
335             case "f19":
336                 id += 19;
337                 flow.setMatch(createMatch1().build());
338                 flow.setInstructions(createAppyActionInstruction12().build());
339                 break;
340             case "f20":
341                 id += 20;
342                 flow.setMatch(createMatch1().build());
343                 flow.setInstructions(createAppyActionInstruction13().build());
344                 break;
345             case "f21":
346                 id += 21;
347                 flow.setMatch(createMatch1().build());
348                 flow.setInstructions(createAppyActionInstruction14().build());
349                 break;
350             case "f22":
351                 id += 22;
352                 flow.setMatch(createMatch1().build());
353                 flow.setInstructions(createAppyActionInstruction15().build());
354                 break;
355             case "f23":
356                 id += 23;
357                 // f23 can be used as test-case for generating error notification
358                 // if the particular group is not configured - tested
359                 flow.setMatch(createMatch1().build());
360                 flow.setInstructions(createAppyActionInstruction16().build());
361                 break;
362             case "f24":
363                 id += 24;
364                 flow.setMatch(createMatch1().build());
365                 flow.setInstructions(createAppyActionInstruction17().build());
366                 break;
367             case "f25":
368                 id += 25;
369                 flow.setMatch(createMatch1().build());
370                 flow.setInstructions(createAppyActionInstruction18().build());
371                 break;
372             case "f26":
373                 id += 26;
374                 flow.setMatch(createMatch1().build());
375                 flow.setInstructions(createAppyActionInstruction19().build());
376                 break;
377             case "f27":
378                 id += 27;
379                 flow.setMatch(createMatch1().build());
380                 flow.setInstructions(createMetadataInstructions().build());
381                 break;
382             case "f28":
383                 id += 28;
384                 flow.setMatch(createMatch1().build());
385                 flow.setInstructions(createAppyActionInstruction20().build());
386                 break;
387             case "f29":
388                 id += 29;
389                 flow.setMatch(createMatch1().build());
390                 flow.setInstructions(createAppyActionInstruction21().build());
391                 break;
392             case "f30":
393                 id += 30;
394                 flow.setMatch(createMatch1().build());
395                 flow.setInstructions(createAppyActionInstruction22().build());
396                 break;
397             case "f31":
398                 id += 31;
399                 flow.setMatch(createMatch1().build());
400                 flow.setInstructions(createAppyActionInstruction23(nodeBuilder.getId()).build());
401                 break;
402             case "f32":
403                 id += 32;
404                 flow.setMatch(createMatch1().build());
405                 flow.setInstructions(createAppyActionInstruction24().build());
406                 break;
407             case "f33":
408                 id += 33;
409                 flow.setMatch(createMatch1().build());
410                 flow.setInstructions(createAppyActionInstruction25().build());
411                 break;
412             case "f34":
413                 id += 34;
414                 flow.setMatch(createMatch1().build());
415                 flow.setInstructions(createAppyActionInstruction26().build());
416                 break;
417             case "f35":
418                 id += 35;
419                 flow.setMatch(createMatch1().build());
420                 flow.setInstructions(createAppyActionInstruction27().build());
421                 break;
422             case "f36":
423                 id += 36;
424                 flow.setMatch(createMatch1().build());
425                 flow.setInstructions(createAppyActionInstruction28().build());
426                 break;
427             case "f37":
428                 id += 37;
429                 flow.setMatch(createMatch1().build());
430                 flow.setInstructions(createAppyActionInstruction29().build());
431                 break;
432             case "f38":
433                 id += 38;
434                 flow.setMatch(createMatch1().build());
435                 flow.setInstructions(createAppyActionInstruction30().build());
436                 break;
437             case "f39":
438                 id += 39;
439                 flow.setMatch(createMatch1().build());
440                 flow.setInstructions(createAppyActionInstruction31().build());
441                 break;
442             case "f40":
443                 id += 40;
444                 flow.setMatch(createMatch1().build());
445                 flow.setInstructions(createAppyActionInstruction32().build());
446                 break;
447             case "f41":
448                 id += 41;
449                 flow.setMatch(createMatch1().build());
450                 flow.setInstructions(createAppyActionInstruction33().build());
451                 break;
452             case "f42":
453                 id += 42;
454                 flow.setMatch(createMatch1().build());
455                 flow.setInstructions(createAppyActionInstruction34().build());
456                 break;
457             case "f43":
458                 id += 43;
459                 flow.setMatch(createICMPv6Match().build());
460                 flow.setInstructions(createDecNwTtlInstructions().build());
461                 break;
462             case "f44":
463                 id += 44;
464                 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
465                 flow.setInstructions(createDropInstructions().build());
466                 break;
467             case "f45":
468                 id += 45;
469                 flow.setMatch(createMetadataMatch().build());
470                 flow.setInstructions(createDropInstructions().build());
471                 break;
472             case "f46":
473                 id += 46;
474                 flow.setMatch(createL3IPv6Match().build());
475                 flow.setInstructions(createDecNwTtlInstructions().build());
476                 break;
477             case "f47":
478                 id += 47;
479                 flow.setMatch(createL4SCTPMatch().build());
480                 flow.setInstructions(createAppyActionInstruction().build());
481                 break;
482             case "f48":
483                 id += 48;
484                 flow.setMatch(createTunnelIDMatch().build());
485                 flow.setInstructions(createGotoTableInstructions().build());
486                 break;
487             case "f49":
488                 id += 49;
489                 flow.setMatch(createVlanMatch().build());
490                 flow.setInstructions(createMeterInstructions().build());
491                 break;
492             case "f50":
493                 id += 50;
494                 flow.setMatch(createPbbMatch().build());
495                 flow.setInstructions(createMeterInstructions().build());
496                 break;
497             case "f51":
498                 id += 51;
499                 flow.setMatch(createVlanMatch().build());
500                 flow.setInstructions(createDropInstructions().build());
501                 break;
502             case "f52":
503                 id += 52;
504                 flow.setMatch(createL4TCPMatch().build());
505                 flow.setInstructions(createDropInstructions().build());
506                 break;
507
508             case "f53":
509                 id += 53;
510                 flow.setMatch(createL4UDPMatch().build());
511                 flow.setInstructions(createDropInstructions().build());
512                 break;
513             case "f54":
514                 id += 54;
515                 flow.setMatch(new MatchBuilder().build());
516                 flow.setInstructions(createSentToControllerInstructions().build());
517                 flow.setPriority(0);
518                 break;
519             case "f55":
520                 id += 55;
521                 flow.setMatch(createToSMatch().build());
522                 flow.setInstructions(createDropInstructions().build());
523                 break;
524             case "f56":
525                 id += 56;
526                 flow.setMatch(createToSMatch().build());
527                 flow.setInstructions(createOutputInstructions("INPORT", 10).build());
528                 break;
529             case "f57":
530                 id += 57;
531                 flow.setMatch(createToSMatch().build());
532                 flow.setInstructions(createOutputInstructions("FLOOD", 20).build());
533                 break;
534             case "f58":
535                 id += 58;
536                 flow.setMatch(createToSMatch().build());
537                 flow.setInstructions(createOutputInstructions("ALL", 30).build());
538                 break;
539             case "f59":
540                 id += 59;
541                 flow.setMatch(createToSMatch().build());
542                 flow.setInstructions(createOutputInstructions("NORMAL", 40).build());
543                 break;
544             case "f60":
545                 id += 60;
546                 flow.setMatch(createToSMatch().build());
547                 flow.setInstructions(createOutputInstructions("LOCAL", 50).build());
548                 break;
549             case "f61":
550                 id += 61;
551                 flow.setMatch(createToSMatch().build());
552                 flow.setInstructions(createOutputInstructions("TABLE", 60).build());
553                 break;
554             case "f62":
555                 id += 62;
556                 flow.setMatch(createToSMatch().build());
557                 flow.setInstructions(createOutputInstructions("NONE", 70).build());
558                 break;
559             case "f63":
560                 id += 63;
561                 flow.setMatch(createToSMatch().build());
562                 flow.setInstructions(createStripVlanInstructions().build());
563                 flow.setBarrier(Boolean.TRUE);
564                 break;
565             case "f64":
566                 id += 64;
567                 flow.setMatch(createMatch1().build());
568                 flow.setInstructions(createAppyActionInstruction35().build());
569                 break;
570             case "f65":
571                 id += 65;
572                 flow.setMatch(createMatch1().build());
573                 flow.setInstructions(createAppyActionInstruction36().build());
574                 break;
575             case "f66":
576                 id += 66;
577                 flow.setMatch(createMatch1().build());
578                 flow.setInstructions(createAppyActionInstruction37().build());
579                 break;
580             case "f67":
581                 id += 67;
582                 flow.setMatch(createMatch1().build());
583                 flow.setInstructions(createAppyActionInstruction38().build());
584                 break;
585             case "f68":
586                 id += 68;
587                 flow.setMatch(createL4TCPMatch().build());
588                 flow.setInstructions(createAppyActionInstruction39().build());
589                 break;
590             case "f69":
591                 id += 69;
592                 flow.setMatch(createL4UDPMatch().build());
593                 flow.setInstructions(createAppyActionInstruction40().build());
594                 break;
595             case "f70":
596                 id += 70;
597                 flow.setMatch(createL4SCTPMatch().build());
598                 flow.setInstructions(createAppyActionInstruction41().build());
599                 break;
600             case "f71":
601                 id += 71;
602                 flow.setMatch(createICMPv4Match().build());
603                 flow.setInstructions(createAppyActionInstruction42().build());
604                 break;
605             case "f72":
606                 id += 72;
607                 flow.setMatch(createArpMatch().build());
608                 flow.setInstructions(createAppyActionInstruction43().build());
609                 break;
610             case "f73":
611                 id += 73;
612                 flow.setMatch(createL3IPv6Match().build());
613                 flow.setInstructions(createAppyActionInstruction44().build());
614                 break;
615             case "f74":
616                 id += 74;
617                 flow.setMatch(createICMPv6Match().build());
618                 flow.setInstructions(createAppyActionInstruction45().build());
619                 break;
620             case "f75":
621                 id += 75;
622                 flow.setMatch(createMplsMatch().build());
623                 flow.setInstructions(createAppyActionInstruction46().build());
624                 break;
625             case "f76":
626                 id += 76;
627                 flow.setMatch(createPbbMatch().build());
628                 flow.setInstructions(createAppyActionInstruction47().build());
629                 break;
630             case "f77":
631                 id += 77;
632                 flow.setMatch(createTunnelIDMatch().build());
633                 flow.setInstructions(createAppyActionInstruction48().build());
634                 break;
635             case "f78":
636                 id += 78;
637                 flow.setMatch(createMatch33().build());
638                 flow.setInstructions(createDropInstructions().build());
639                 break;
640             case "f79":
641                 id += 79;
642                 flow.setMatch(createICMPv6Match1().build());
643                 flow.setInstructions(createDecNwTtlInstructions().build());
644                 break;
645             case "f80":
646                 id += 80;
647                 flow.setMatch(createVlanMatch().build());
648                 flow.setInstructions(createAppyActionInstruction88().build());
649                 break;
650             case "f81":
651                 id += 81;
652                 flow.setMatch(createLLDPMatch().build());
653                 flow.setInstructions(createSentToControllerInstructions().build());
654                 break;
655             case "f82":
656                 id += 82;
657                 flow.setMatch(createToSMatch().build());
658                 flow.setInstructions(createOutputInstructions().build());
659                 break;
660             case "f83":
661                 id += 83; // Test TCP_Flag Match
662                 flow.setMatch(createTcpFlagMatch().build());
663                 flow.setInstructions(createDropInstructions().build());
664                 break;
665             case "f84":
666                 id += 84;
667                 flow.setMatch(createVlanMatch().build()); // match vlan=10,dl_vlan_pcp=3
668                 flow.setInstructions(createAppyActionInstruction88().build()); // vlan_pcp=4
669                 break;
670             case "f85":
671                 id += 85; // Test Tunnel IPv4 Src (e.g. set_field:172.16.100.200->tun_src)
672                 flow.setMatch(createMatch3().build());
673                 flow.setInstructions(createTunnelIpv4SrcInstructions().build());
674                 break;
675             case "f86":
676                 id += 86; // Test Tunnel IPv4 Dst (e.g. set_field:172.16.100.100->tun_dst)
677                 flow.setMatch(createMatch1().build());
678                 flow.setInstructions(createTunnelIpv4DstInstructions().build());
679                 break;
680             default:
681                 LOG.warn("flow type not understood: {}", flowType);
682         }
683
684         FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
685         if (null == flow.isBarrier()) {
686             flow.setBarrier(Boolean.FALSE);
687         }
688         // flow.setBufferId(new Long(12));
689         BigInteger value = new BigInteger("10", 10);
690         // BigInteger outputPort = new BigInteger("65535", 10);
691         flow.setCookie(new FlowCookie(value));
692         flow.setCookieMask(new FlowCookie(value));
693         flow.setHardTimeout(0);
694         flow.setIdleTimeout(0);
695         flow.setInstallHw(false);
696         flow.setStrict(false);
697         flow.setContainerName(null);
698         flow.setFlags(new FlowModFlags(false, false, false, false, true));
699         flow.setId(new FlowId("12"));
700         flow.setTableId(getTableId(tableId));
701         // commenting setOutGroup and setOutPort, as by default
702         // OFPG_ANY is send
703         // enable setOutGroup and setOutPort to enable output filtering
704         // flow.setOutGroup(new Long(2));
705         // set outport to OFPP_NONE (65535) to disable remove restriction for
706         // flow
707         // flow.setOutPort(outputPort);
708
709         flow.setKey(key);
710         flow.setFlowName(originalFlowName + "X" + flowType);
711         testFlow = flow;
712         return flow;
713     }
714
715
716     private FlowBuilder createTestFlow_perfTest(NodeBuilder nodeBuilder, String flowTypeArg, String tableId, int id) {
717
718         FlowBuilder flow = new FlowBuilder();
719         //long id = 123;
720
721         String flowType = flowTypeArg;
722         if (flowType == null) {
723             flowType = "f1";
724         }
725
726         flow.setPriority(id);
727
728         switch (flowType) {
729             case "f1":
730                 id += 1;
731                 flow.setMatch(createMatch1().build());
732                 flow.setInstructions(createDecNwTtlInstructions().build());
733                 break;
734             default:
735                 LOG.warn("flow type not understood: {}", flowType);
736         }
737
738         FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
739         if (null == flow.isBarrier()) {
740             flow.setBarrier(Boolean.FALSE);
741         }
742         // flow.setBufferId(new Long(12));
743         BigInteger value = new BigInteger("10", 10);
744         // BigInteger outputPort = new BigInteger("65535", 10);
745         flow.setCookie(new FlowCookie(value));
746         flow.setCookieMask(new FlowCookie(value));
747         flow.setHardTimeout(0);
748         flow.setIdleTimeout(0);
749         flow.setInstallHw(false);
750         flow.setStrict(false);
751         flow.setContainerName(null);
752         flow.setFlags(new FlowModFlags(false, false, false, false, true));
753         flow.setId(new FlowId("12"));
754         flow.setTableId(getTableId(tableId));
755         // commenting setOutGroup and setOutPort, as by default
756         // OFPG_ANY is send
757         // enable setOutGroup and setOutPort to enable output filtering
758         // flow.setOutGroup(new Long(2));
759         // set outport to OFPP_NONE (65535) to disable remove restriction for
760         // flow
761         // flow.setOutPort(outputPort);
762
763         flow.setKey(key);
764         flow.setFlowName(originalFlowName + "X" + flowType);
765         testFlow = flow;
766         return flow;
767     }
768
769     private FlowBuilder createtablemiss(NodeBuilder nodeBuilder, String flowTypeArg, String tableId) {
770         FlowBuilder flow = new FlowBuilder();
771         long id = 456;
772         MatchBuilder matchBuilder = new MatchBuilder();
773         flow.setMatch(matchBuilder.build());
774         flow.setInstructions(createSentToControllerInstructions().build());
775         flow.setPriority(0);
776         flow.setTableId((short) 0);
777         FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
778         flow.setKey(key);
779         testFlow = flow;
780         return flow;
781     }
782
783     private short getTableId(String tableId) {
784         short table = 2;
785         try {
786             table = Short.parseShort(tableId);
787         } catch (Exception ex) {
788             // ignore exception and continue with default value
789         }
790
791         return table;
792
793     }
794
795     /**
796      * @return
797      */
798     private static InstructionsBuilder createDecNwTtlInstructions() {
799         DecNwTtlBuilder ta = new DecNwTtlBuilder();
800         DecNwTtl decNwTtl = ta.build();
801         ActionBuilder ab = new ActionBuilder();
802         ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
803         ab.setKey(new ActionKey(0));
804         // Add our drop action to a list
805         List<Action> actionList = new ArrayList<Action>();
806         actionList.add(ab.build());
807
808         // Create an Apply Action
809         ApplyActionsBuilder aab = new ApplyActionsBuilder();
810         aab.setAction(actionList);
811
812         // Wrap our Apply Action in an Instruction
813         InstructionBuilder ib = new InstructionBuilder();
814         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
815         ib.setKey(new InstructionKey(0));
816         ib.setOrder(0);
817
818         // Put our Instruction in a list of Instructions
819         InstructionsBuilder isb = new InstructionsBuilder();
820         List<Instruction> instructions = new ArrayList<Instruction>();
821         instructions.add(ib.build());
822         ib.setKey(new InstructionKey(0));
823         isb.setInstruction(instructions);
824         return isb;
825     }
826
827     /**
828      * @return
829      */
830     private static InstructionsBuilder createMeterInstructions() {
831
832         MeterBuilder aab = new MeterBuilder();
833         aab.setMeterId(new MeterId(new Long(1)));
834
835         InstructionBuilder ib = new InstructionBuilder();
836         ib.setInstruction(new MeterCaseBuilder().setMeter(aab.build()).build());
837
838         // Put our Instruction in a list of Instructions
839         InstructionsBuilder isb = new InstructionsBuilder();
840         List<Instruction> instructions = new ArrayList<Instruction>();
841         ib.setKey(new InstructionKey(0));
842         instructions.add(ib.build());
843         isb.setInstruction(instructions);
844         return isb;
845     }
846
847     private static InstructionsBuilder createMetadataInstructions() {
848
849         WriteMetadataBuilder aab = new WriteMetadataBuilder();
850         aab.setMetadata(new BigInteger("10", 10));
851         aab.setMetadataMask(new BigInteger("12", 10));
852
853         InstructionBuilder ib = new InstructionBuilder();
854         ib.setInstruction(new WriteMetadataCaseBuilder().setWriteMetadata(aab.build()).build());
855
856         // Put our Instruction in a list of Instructions
857         InstructionsBuilder isb = new InstructionsBuilder();
858         List<Instruction> instructions = new ArrayList<Instruction>();
859         ib.setKey(new InstructionKey(0));
860         instructions.add(ib.build());
861         isb.setInstruction(instructions);
862         return isb;
863     }
864
865     private static InstructionsBuilder createGotoTableInstructions() {
866
867         GoToTableBuilder aab = new GoToTableBuilder();
868         aab.setTableId((short) 5);
869
870         InstructionBuilder ib = new InstructionBuilder();
871         ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(aab.build()).build());
872
873         // Put our Instruction in a list of Instructions
874         InstructionsBuilder isb = new InstructionsBuilder();
875         List<Instruction> instructions = new ArrayList<Instruction>();
876         ib.setKey(new InstructionKey(0));
877         instructions.add(ib.build());
878         isb.setInstruction(instructions);
879         return isb;
880     }
881
882     private static InstructionsBuilder createDropInstructions() {
883         DropActionBuilder dab = new DropActionBuilder();
884         DropAction dropAction = dab.build();
885         ActionBuilder ab = new ActionBuilder();
886         ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
887         ab.setKey(new ActionKey(0));
888         // Add our drop action to a list
889         List<Action> actionList = new ArrayList<Action>();
890         actionList.add(ab.build());
891         ab.setKey(new ActionKey(0));
892         // Create an Apply Action
893         ApplyActionsBuilder aab = new ApplyActionsBuilder();
894         aab.setAction(actionList);
895
896         // Wrap our Apply Action in an Instruction
897         InstructionBuilder ib = new InstructionBuilder();
898         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
899
900         // Put our Instruction in a list of Instructions
901         InstructionsBuilder isb = new InstructionsBuilder();
902         List<Instruction> instructions = new ArrayList<Instruction>();
903         ib.setKey(new InstructionKey(0));
904         instructions.add(ib.build());
905         isb.setInstruction(instructions);
906         return isb;
907     }
908
909     private static InstructionsBuilder createAppyActionInstruction() {
910
911         List<Action> actionList = new ArrayList<Action>();
912         ActionBuilder ab = new ActionBuilder();
913         ControllerActionBuilder controller = new ControllerActionBuilder();
914         controller.setMaxLength(5);
915         ab.setAction(new ControllerActionCaseBuilder().setControllerAction(controller.build()).build());
916         ab.setKey(new ActionKey(0));
917         actionList.add(ab.build());
918         // Create an Apply Action
919         ApplyActionsBuilder aab = new ApplyActionsBuilder();
920         aab.setAction(actionList);
921
922         // Wrap our Apply Action in an Instruction
923         InstructionBuilder ib = new InstructionBuilder();
924         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
925
926         // Put our Instruction in a list of Instructions
927         InstructionsBuilder isb = new InstructionsBuilder();
928         List<Instruction> instructions = new ArrayList<Instruction>();
929         ib.setKey(new InstructionKey(0));
930         instructions.add(ib.build());
931         isb.setInstruction(instructions);
932         return isb;
933     }
934
935     private static InstructionsBuilder createAppyActionInstruction1() {
936
937         List<Action> actionList = new ArrayList<Action>();
938         ActionBuilder ab = new ActionBuilder();
939
940         OutputActionBuilder output = new OutputActionBuilder();
941         output.setMaxLength(56);
942         Uri value = new Uri("PCEP");
943         output.setOutputNodeConnector(value);
944         ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
945         ab.setKey(new ActionKey(0));
946         actionList.add(ab.build());
947         // Create an Apply Action
948         ApplyActionsBuilder aab = new ApplyActionsBuilder();
949         aab.setAction(actionList);
950
951         // Wrap our Apply Action in an Instruction
952         InstructionBuilder ib = new InstructionBuilder();
953         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
954
955         // Put our Instruction in a list of Instructions
956         InstructionsBuilder isb = new InstructionsBuilder();
957         List<Instruction> instructions = new ArrayList<Instruction>();
958         ib.setKey(new InstructionKey(0));
959         instructions.add(ib.build());
960         isb.setInstruction(instructions);
961         return isb;
962     }
963
964     private static InstructionsBuilder createOutputInstructions() {
965
966         // test case for Output Port works if the particular port exists
967         // this particular test-case is for Port : 1
968         // tested as (addMDFlow openflow:<dpid> f82)
969         List<Action> actionList = new ArrayList<Action>();
970         ActionBuilder ab = new ActionBuilder();
971         OutputActionBuilder output = new OutputActionBuilder();
972
973         Uri value = new Uri("1");
974         output.setOutputNodeConnector(value);
975         ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
976         ab.setOrder(0);
977         ab.setKey(new ActionKey(0));
978         actionList.add(ab.build());
979         // Create an Apply Action
980         ApplyActionsBuilder aab = new ApplyActionsBuilder();
981         aab.setAction(actionList);
982
983         // Wrap our Apply Action in an Instruction
984         InstructionBuilder ib = new InstructionBuilder();
985         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
986         ib.setOrder(0);
987         ib.setKey(new InstructionKey(0));
988
989         // Put our Instruction in a list of Instructions
990         InstructionsBuilder isb = new InstructionsBuilder();
991         List<Instruction> instructions = new ArrayList<Instruction>();
992         instructions.add(ib.build());
993         isb.setInstruction(instructions);
994         return isb;
995     }
996
997     private static InstructionsBuilder createSentToControllerInstructions() {
998         List<Action> actionList = new ArrayList<Action>();
999         ActionBuilder ab = new ActionBuilder();
1000
1001         OutputActionBuilder output = new OutputActionBuilder();
1002         output.setMaxLength(new Integer(0xffff));
1003         Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
1004         output.setOutputNodeConnector(value);
1005         ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
1006         ab.setOrder(0);
1007         ab.setKey(new ActionKey(0));
1008         actionList.add(ab.build());
1009         // Create an Apply Action
1010         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1011         aab.setAction(actionList);
1012
1013         // Wrap our Apply Action in an Instruction
1014         InstructionBuilder ib = new InstructionBuilder();
1015         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1016         ib.setOrder(0);
1017         ib.setKey(new InstructionKey(0));
1018
1019         // Put our Instruction in a list of Instructions
1020         InstructionsBuilder isb = new InstructionsBuilder();
1021         List<Instruction> instructions = new ArrayList<Instruction>();
1022         instructions.add(ib.build());
1023         isb.setInstruction(instructions);
1024         return isb;
1025     }
1026
1027     private static InstructionsBuilder createOutputInstructions(String outputType, int outputValue) {
1028         List<Action> actionList = new ArrayList<Action>();
1029         ActionBuilder ab = new ActionBuilder();
1030
1031         OutputActionBuilder output = new OutputActionBuilder();
1032         output.setMaxLength(outputValue);
1033         Uri value = new Uri(outputType);
1034         output.setOutputNodeConnector(value);
1035         ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
1036         ab.setOrder(0);
1037         ab.setKey(new ActionKey(0));
1038         actionList.add(ab.build());
1039         // Create an Apply Action
1040         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1041         aab.setAction(actionList);
1042
1043         // Wrap our Apply Action in an Instruction
1044         InstructionBuilder ib = new InstructionBuilder();
1045         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1046         ib.setOrder(0);
1047         ib.setKey(new InstructionKey(0));
1048
1049         // Put our Instruction in a list of Instructions
1050         InstructionsBuilder isb = new InstructionsBuilder();
1051         List<Instruction> instructions = new ArrayList<Instruction>();
1052         instructions.add(ib.build());
1053         isb.setInstruction(instructions);
1054         return isb;
1055     }
1056
1057     private static InstructionsBuilder createStripVlanInstructions() {
1058         List<Action> actionList = new ArrayList<Action>();
1059         ActionBuilder ab = new ActionBuilder();
1060
1061         StripVlanActionBuilder stripActionBuilder = new StripVlanActionBuilder();
1062         ab.setAction(new StripVlanActionCaseBuilder().setStripVlanAction(stripActionBuilder.build()).build());
1063         ab.setOrder(0);
1064         ab.setKey(new ActionKey(0));
1065         actionList.add(ab.build());
1066         // Create an Apply Action
1067         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1068         aab.setAction(actionList);
1069
1070         // Wrap our Apply Action in an Instruction
1071         InstructionBuilder ib = new InstructionBuilder();
1072         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1073         ib.setOrder(0);
1074         ib.setKey(new InstructionKey(0));
1075
1076         // Put our Instruction in a list of Instructions
1077         InstructionsBuilder isb = new InstructionsBuilder();
1078         List<Instruction> instructions = new ArrayList<Instruction>();
1079         instructions.add(ib.build());
1080         isb.setInstruction(instructions);
1081         return isb;
1082     }
1083
1084     private static InstructionsBuilder createAppyActionInstruction2() {
1085
1086         List<Action> actionList = new ArrayList<Action>();
1087         ActionBuilder ab = new ActionBuilder();
1088
1089         PushMplsActionBuilder push = new PushMplsActionBuilder();
1090         push.setEthernetType(new Integer(0x8847));
1091         ab.setAction(new PushMplsActionCaseBuilder().setPushMplsAction(push.build()).build());
1092         ab.setKey(new ActionKey(0));
1093         actionList.add(ab.build());
1094         // Create an Apply Action
1095         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1096         aab.setAction(actionList);
1097
1098         // Wrap our Apply Action in an Instruction
1099         InstructionBuilder ib = new InstructionBuilder();
1100         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1101
1102         // Put our Instruction in a list of Instructions
1103         InstructionsBuilder isb = new InstructionsBuilder();
1104         List<Instruction> instructions = new ArrayList<Instruction>();
1105         ib.setKey(new InstructionKey(0));
1106         instructions.add(ib.build());
1107         isb.setInstruction(instructions);
1108         return isb;
1109     }
1110
1111     private static InstructionsBuilder createAppyActionInstruction3() {
1112
1113         List<Action> actionList = new ArrayList<Action>();
1114         ActionBuilder ab = new ActionBuilder();
1115
1116         PushPbbActionBuilder pbb = new PushPbbActionBuilder();
1117         pbb.setEthernetType(new Integer(0x88E7));
1118         ab.setAction(new PushPbbActionCaseBuilder().setPushPbbAction(pbb.build()).build());
1119         ab.setKey(new ActionKey(0));
1120         actionList.add(ab.build());
1121         // Create an Apply Action
1122         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1123         aab.setAction(actionList);
1124
1125         // Wrap our Apply Action in an Instruction
1126         InstructionBuilder ib = new InstructionBuilder();
1127         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1128
1129         // Put our Instruction in a list of Instructions
1130         InstructionsBuilder isb = new InstructionsBuilder();
1131         List<Instruction> instructions = new ArrayList<Instruction>();
1132         ib.setKey(new InstructionKey(0));
1133         instructions.add(ib.build());
1134         isb.setInstruction(instructions);
1135         return isb;
1136     }
1137
1138     private static InstructionsBuilder createAppyActionInstruction4() {
1139
1140         List<Action> actionList = new ArrayList<Action>();
1141         ActionBuilder ab = new ActionBuilder();
1142
1143         PushVlanActionBuilder vlan = new PushVlanActionBuilder();
1144         vlan.setEthernetType(new Integer(0x8100));
1145         ab.setAction(new PushVlanActionCaseBuilder().setPushVlanAction(vlan.build()).build());
1146         ab.setKey(new ActionKey(0));
1147         actionList.add(ab.build());
1148
1149         // Create an Apply Action
1150         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1151         aab.setAction(actionList);
1152
1153         // Wrap our Apply Action in an Instruction
1154         InstructionBuilder ib = new InstructionBuilder();
1155         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1156
1157         // Put our Instruction in a list of Instructions
1158         InstructionsBuilder isb = new InstructionsBuilder();
1159         List<Instruction> instructions = new ArrayList<Instruction>();
1160         ib.setKey(new InstructionKey(0));
1161         instructions.add(ib.build());
1162         isb.setInstruction(instructions);
1163         return isb;
1164     }
1165
1166     private static InstructionsBuilder createAppyActionInstruction5() {
1167
1168         List<Action> actionList = new ArrayList<Action>();
1169         ActionBuilder ab = new ActionBuilder();
1170
1171         SetDlDstActionBuilder setdl = new SetDlDstActionBuilder();
1172         setdl.setAddress(new MacAddress("00:05:b9:7c:81:5f"));
1173         ab.setAction(new SetDlDstActionCaseBuilder().setSetDlDstAction(setdl.build()).build());
1174         ab.setKey(new ActionKey(0));
1175         actionList.add(ab.build());
1176         // Create an Apply Action
1177         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1178         aab.setAction(actionList);
1179
1180         // Wrap our Apply Action in an Instruction
1181         InstructionBuilder ib = new InstructionBuilder();
1182         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1183
1184         // Put our Instruction in a list of Instructions
1185         InstructionsBuilder isb = new InstructionsBuilder();
1186         List<Instruction> instructions = new ArrayList<Instruction>();
1187         ib.setKey(new InstructionKey(0));
1188         instructions.add(ib.build());
1189         isb.setInstruction(instructions);
1190         return isb;
1191     }
1192
1193     private static InstructionsBuilder createAppyActionInstruction6() {
1194
1195         List<Action> actionList = new ArrayList<Action>();
1196         ActionBuilder ab = new ActionBuilder();
1197
1198         SetDlSrcActionBuilder src = new SetDlSrcActionBuilder();
1199         src.setAddress(new MacAddress("00:05:b9:7c:81:5f"));
1200         ab.setAction(new SetDlSrcActionCaseBuilder().setSetDlSrcAction(src.build()).build());
1201         ab.setKey(new ActionKey(0));
1202         actionList.add(ab.build());
1203
1204         // Create an Apply Action
1205         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1206         aab.setAction(actionList);
1207
1208         // Wrap our Apply Action in an Instruction
1209         InstructionBuilder ib = new InstructionBuilder();
1210         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1211
1212         // Put our Instruction in a list of Instructions
1213         InstructionsBuilder isb = new InstructionsBuilder();
1214         List<Instruction> instructions = new ArrayList<Instruction>();
1215         ib.setKey(new InstructionKey(0));
1216         instructions.add(ib.build());
1217         isb.setInstruction(instructions);
1218         return isb;
1219     }
1220
1221     private static InstructionsBuilder createAppyActionInstruction7() {
1222
1223         List<Action> actionList = new ArrayList<Action>();
1224         ActionBuilder ab = new ActionBuilder();
1225
1226         SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
1227         VlanId a = new VlanId(4000);
1228         vl.setVlanId(a);
1229         ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.build()).build());
1230         ab.setKey(new ActionKey(0));
1231         actionList.add(ab.build());
1232         // Create an Apply Action
1233         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1234         aab.setAction(actionList);
1235
1236         // Wrap our Apply Action in an Instruction
1237         InstructionBuilder ib = new InstructionBuilder();
1238         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1239
1240         // Put our Instruction in a list of Instructions
1241         InstructionsBuilder isb = new InstructionsBuilder();
1242         List<Instruction> instructions = new ArrayList<Instruction>();
1243         ib.setKey(new InstructionKey(0));
1244         instructions.add(ib.build());
1245         isb.setInstruction(instructions);
1246         return isb;
1247     }
1248
1249     private static InstructionsBuilder createAppyActionInstruction8() {
1250
1251         List<Action> actionList = new ArrayList<Action>();
1252         ActionBuilder ab = new ActionBuilder();
1253
1254         SetVlanPcpActionBuilder pcp = new SetVlanPcpActionBuilder();
1255         VlanPcp pcp1 = new VlanPcp((short) 2);
1256         pcp.setVlanPcp(pcp1);
1257         ab.setAction(new SetVlanPcpActionCaseBuilder().setSetVlanPcpAction(pcp.build()).build());
1258         ab.setKey(new ActionKey(0));
1259         actionList.add(ab.build());
1260         // Create an Apply Action
1261         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1262         aab.setAction(actionList);
1263
1264         // Wrap our Apply Action in an Instruction
1265         InstructionBuilder ib = new InstructionBuilder();
1266         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1267
1268         // Put our Instruction in a list of Instructions
1269         InstructionsBuilder isb = new InstructionsBuilder();
1270         List<Instruction> instructions = new ArrayList<Instruction>();
1271         ib.setKey(new InstructionKey(0));
1272         instructions.add(ib.build());
1273         isb.setInstruction(instructions);
1274         return isb;
1275     }
1276
1277     private static InstructionsBuilder createAppyActionInstruction88() {
1278
1279         List<Action> actionList = new ArrayList<Action>();
1280         ActionBuilder ab = new ActionBuilder();
1281
1282         SetVlanPcpActionBuilder pcp = new SetVlanPcpActionBuilder();
1283         // the code point is a 3-bit(0-7) field representing the frame priority level
1284         VlanPcp pcp1 = new VlanPcp((short) 4);
1285         pcp.setVlanPcp(pcp1);
1286         ab.setAction(new SetVlanPcpActionCaseBuilder().setSetVlanPcpAction(pcp.build()).build());
1287         ab.setKey(new ActionKey(0));
1288         actionList.add(ab.build());
1289         // Create an Apply Action
1290         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1291         aab.setAction(actionList);
1292
1293         // Wrap our Apply Action in an Instruction
1294         InstructionBuilder ib = new InstructionBuilder();
1295         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1296
1297         // Put our Instruction in a list of Instructions
1298         InstructionsBuilder isb = new InstructionsBuilder();
1299         List<Instruction> instructions = new ArrayList<Instruction>();
1300         ib.setKey(new InstructionKey(0));
1301         instructions.add(ib.build());
1302         isb.setInstruction(instructions);
1303         return isb;
1304     }
1305
1306     private static InstructionsBuilder createAppyActionInstruction9() {
1307
1308         List<Action> actionList = new ArrayList<Action>();
1309         ActionBuilder ab = new ActionBuilder();
1310
1311         CopyTtlInBuilder ttlin = new CopyTtlInBuilder();
1312         ab.setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(ttlin.build()).build());
1313         ab.setKey(new ActionKey(0));
1314         actionList.add(ab.build());
1315         // Create an Apply Action
1316         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1317         aab.setAction(actionList);
1318
1319         // Wrap our Apply Action in an Instruction
1320         InstructionBuilder ib = new InstructionBuilder();
1321         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1322
1323         // Put our Instruction in a list of Instructions
1324         InstructionsBuilder isb = new InstructionsBuilder();
1325         List<Instruction> instructions = new ArrayList<Instruction>();
1326         ib.setKey(new InstructionKey(0));
1327         instructions.add(ib.build());
1328         isb.setInstruction(instructions);
1329         return isb;
1330     }
1331
1332     private static InstructionsBuilder createAppyActionInstruction10() {
1333
1334         List<Action> actionList = new ArrayList<Action>();
1335         ActionBuilder ab = new ActionBuilder();
1336
1337         CopyTtlOutBuilder ttlout = new CopyTtlOutBuilder();
1338         ab.setAction(new CopyTtlOutCaseBuilder().setCopyTtlOut(ttlout.build()).build());
1339         ab.setKey(new ActionKey(0));
1340         actionList.add(ab.build());
1341         // Create an Apply Action
1342         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1343         aab.setAction(actionList);
1344
1345         // Wrap our Apply Action in an Instruction
1346         InstructionBuilder ib = new InstructionBuilder();
1347         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1348
1349         // Put our Instruction in a list of Instructions
1350         InstructionsBuilder isb = new InstructionsBuilder();
1351         List<Instruction> instructions = new ArrayList<Instruction>();
1352         ib.setKey(new InstructionKey(0));
1353         instructions.add(ib.build());
1354         isb.setInstruction(instructions);
1355         return isb;
1356     }
1357
1358     private static InstructionsBuilder createAppyActionInstruction11() {
1359
1360         List<Action> actionList = new ArrayList<Action>();
1361         ActionBuilder ab = new ActionBuilder();
1362
1363         DecMplsTtlBuilder mpls = new DecMplsTtlBuilder();
1364         ab.setAction(new DecMplsTtlCaseBuilder().setDecMplsTtl(mpls.build()).build());
1365         ab.setKey(new ActionKey(0));
1366         actionList.add(ab.build());
1367         // Create an Apply Action
1368         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1369         aab.setAction(actionList);
1370
1371         // Wrap our Apply Action in an Instruction
1372         InstructionBuilder ib = new InstructionBuilder();
1373         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1374         ib.setKey(new InstructionKey(0));
1375         ib.setOrder(0);
1376
1377         // Put our Instruction in a list of Instruction
1378         InstructionsBuilder isb = new InstructionsBuilder();
1379         List<Instruction> instructions = new ArrayList<Instruction>();
1380         instructions.add(ib.build());
1381         isb.setInstruction(instructions);
1382         return isb;
1383     }
1384
1385     private static InstructionsBuilder createAppyActionInstruction12() {
1386
1387         List<Action> actionList = new ArrayList<Action>();
1388         ActionBuilder ab = new ActionBuilder();
1389
1390         DecNwTtlBuilder nwttl = new DecNwTtlBuilder();
1391         ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(nwttl.build()).build());
1392         ab.setKey(new ActionKey(0));
1393         actionList.add(ab.build());
1394
1395         // Create an Apply Action
1396         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1397         aab.setAction(actionList);
1398
1399         // Wrap our Apply Action in an Instruction
1400         InstructionBuilder ib = new InstructionBuilder();
1401         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1402
1403         // Put our Instruction in a list of Instructions
1404         InstructionsBuilder isb = new InstructionsBuilder();
1405         List<Instruction> instructions = new ArrayList<Instruction>();
1406         ib.setKey(new InstructionKey(0));
1407         instructions.add(ib.build());
1408         isb.setInstruction(instructions);
1409         return isb;
1410     }
1411
1412     private static InstructionsBuilder createAppyActionInstruction13() {
1413
1414         List<Action> actionList = new ArrayList<Action>();
1415         ActionBuilder ab = new ActionBuilder();
1416
1417         DropActionBuilder drop = new DropActionBuilder();
1418         ab.setAction(new DropActionCaseBuilder().setDropAction(drop.build()).build());
1419         ab.setKey(new ActionKey(0));
1420         actionList.add(ab.build());
1421
1422         // Create an Apply Action
1423         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1424         aab.setAction(actionList);
1425
1426         // Wrap our Apply Action in an Instruction
1427         InstructionBuilder ib = new InstructionBuilder();
1428         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1429
1430         // Put our Instruction in a list of Instructions
1431         InstructionsBuilder isb = new InstructionsBuilder();
1432         List<Instruction> instructions = new ArrayList<Instruction>();
1433         ib.setKey(new InstructionKey(0));
1434         instructions.add(ib.build());
1435         isb.setInstruction(instructions);
1436         return isb;
1437     }
1438
1439     private static InstructionsBuilder createAppyActionInstruction14() {
1440
1441         List<Action> actionList = new ArrayList<Action>();
1442         ActionBuilder ab = new ActionBuilder();
1443
1444         FloodActionBuilder fld = new FloodActionBuilder();
1445         ab.setAction(new FloodActionCaseBuilder().setFloodAction(fld.build()).build());
1446         ab.setKey(new ActionKey(0));
1447         actionList.add(ab.build());
1448         // Create an Apply Action
1449         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1450         aab.setAction(actionList);
1451
1452         // Wrap our Apply Action in an Instruction
1453         InstructionBuilder ib = new InstructionBuilder();
1454         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1455
1456         // Put our Instruction in a list of Instructions
1457         InstructionsBuilder isb = new InstructionsBuilder();
1458         List<Instruction> instructions = new ArrayList<Instruction>();
1459         ib.setKey(new InstructionKey(0));
1460         instructions.add(ib.build());
1461         isb.setInstruction(instructions);
1462         return isb;
1463     }
1464
1465     private static InstructionsBuilder createAppyActionInstruction15() {
1466
1467         List<Action> actionList = new ArrayList<Action>();
1468         ActionBuilder ab = new ActionBuilder();
1469
1470         FloodAllActionBuilder fldall = new FloodAllActionBuilder();
1471         ab.setAction(new FloodAllActionCaseBuilder().setFloodAllAction(fldall.build()).build());
1472         ab.setKey(new ActionKey(0));
1473         actionList.add(ab.build());
1474         // Create an Apply Action
1475         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1476         aab.setAction(actionList);
1477
1478         // Wrap our Apply Action in an Instruction
1479         InstructionBuilder ib = new InstructionBuilder();
1480         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1481
1482         // Put our Instruction in a list of Instructions
1483         InstructionsBuilder isb = new InstructionsBuilder();
1484         List<Instruction> instructions = new ArrayList<Instruction>();
1485         ib.setKey(new InstructionKey(0));
1486         instructions.add(ib.build());
1487         isb.setInstruction(instructions);
1488         return isb;
1489     }
1490
1491     private static InstructionsBuilder createAppyActionInstruction16() {
1492
1493         List<Action> actionList = new ArrayList<Action>();
1494         ActionBuilder ab = new ActionBuilder();
1495
1496         GroupActionBuilder groupActionB = new GroupActionBuilder();
1497         groupActionB.setGroupId(1L);
1498         groupActionB.setGroup("0");
1499         ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
1500         ab.setKey(new ActionKey(0));
1501         actionList.add(ab.build());
1502
1503         // Create an Apply Action
1504         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1505         aab.setAction(actionList);
1506
1507         // Wrap our Apply Action in an Instruction
1508         InstructionBuilder ib = new InstructionBuilder();
1509         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1510
1511         // Put our Instruction in a list of Instructions
1512         InstructionsBuilder isb = new InstructionsBuilder();
1513         List<Instruction> instructions = new ArrayList<Instruction>();
1514         ib.setKey(new InstructionKey(0));
1515         instructions.add(ib.build());
1516         isb.setInstruction(instructions);
1517         return isb;
1518     }
1519
1520     private static InstructionsBuilder createAppyActionInstruction17() {
1521
1522         List<Action> actionList = new ArrayList<Action>();
1523         ActionBuilder ab = new ActionBuilder();
1524
1525         HwPathActionBuilder hwPathB = new HwPathActionBuilder();
1526         ab.setAction(new HwPathActionCaseBuilder().setHwPathAction(hwPathB.build()).build());
1527         ab.setKey(new ActionKey(0));
1528         actionList.add(ab.build());
1529         // Create an Apply Action
1530         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1531         aab.setAction(actionList);
1532
1533         // Wrap our Apply Action in an Instruction
1534         InstructionBuilder ib = new InstructionBuilder();
1535         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1536
1537         // Put our Instruction in a list of Instructions
1538         InstructionsBuilder isb = new InstructionsBuilder();
1539         List<Instruction> instructions = new ArrayList<Instruction>();
1540         ib.setKey(new InstructionKey(0));
1541         instructions.add(ib.build());
1542         isb.setInstruction(instructions);
1543         return isb;
1544     }
1545
1546     private static InstructionsBuilder createAppyActionInstruction18() {
1547
1548         List<Action> actionList = new ArrayList<Action>();
1549         ActionBuilder ab = new ActionBuilder();
1550
1551         LoopbackActionBuilder loopbackActionBuilder = new LoopbackActionBuilder();
1552         ab.setAction(new LoopbackActionCaseBuilder().setLoopbackAction(loopbackActionBuilder.build()).build());
1553         ab.setKey(new ActionKey(0));
1554         actionList.add(ab.build());
1555
1556         // Create an Apply Action
1557         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1558         aab.setAction(actionList);
1559
1560         // Wrap our Apply Action in an Instruction
1561         InstructionBuilder ib = new InstructionBuilder();
1562         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1563
1564         // Put our Instruction in a list of Instructions
1565         InstructionsBuilder isb = new InstructionsBuilder();
1566         List<Instruction> instructions = new ArrayList<Instruction>();
1567         ib.setKey(new InstructionKey(0));
1568         instructions.add(ib.build());
1569         isb.setInstruction(instructions);
1570         return isb;
1571     }
1572
1573     private static InstructionsBuilder createAppyActionInstruction19() {
1574
1575         List<Action> actionList = new ArrayList<Action>();
1576         ActionBuilder ab = new ActionBuilder();
1577
1578         PopMplsActionBuilder popMplsActionBuilder = new PopMplsActionBuilder();
1579         popMplsActionBuilder.setEthernetType(0XB);
1580         ab.setAction(new PopMplsActionCaseBuilder().setPopMplsAction(popMplsActionBuilder.build()).build());
1581         ab.setKey(new ActionKey(0));
1582         actionList.add(ab.build());
1583         // Create an Apply Action
1584         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1585         aab.setAction(actionList);
1586
1587         // Wrap our Apply Action in an Instruction
1588         InstructionBuilder ib = new InstructionBuilder();
1589         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1590
1591         // Put our Instruction in a list of Instructions
1592         InstructionsBuilder isb = new InstructionsBuilder();
1593         List<Instruction> instructions = new ArrayList<Instruction>();
1594         ib.setKey(new InstructionKey(0));
1595         instructions.add(ib.build());
1596         isb.setInstruction(instructions);
1597         return isb;
1598     }
1599
1600     private static InstructionsBuilder createAppyActionInstruction20() {
1601
1602         List<Action> actionList = new ArrayList<Action>();
1603         ActionBuilder ab = new ActionBuilder();
1604
1605         PopPbbActionBuilder popPbbActionBuilder = new PopPbbActionBuilder();
1606         ab.setAction(new PopPbbActionCaseBuilder().setPopPbbAction(popPbbActionBuilder.build()).build());
1607         ab.setKey(new ActionKey(0));
1608         actionList.add(ab.build());
1609         // Create an Apply Action
1610         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1611         aab.setAction(actionList);
1612
1613         // Wrap our Apply Action in an Instruction
1614         InstructionBuilder ib = new InstructionBuilder();
1615         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1616
1617         // Put our Instruction in a list of Instructions
1618         InstructionsBuilder isb = new InstructionsBuilder();
1619         List<Instruction> instructions = new ArrayList<Instruction>();
1620         ib.setKey(new InstructionKey(0));
1621         instructions.add(ib.build());
1622         isb.setInstruction(instructions);
1623         return isb;
1624     }
1625
1626     private static InstructionsBuilder createAppyActionInstruction21() {
1627
1628         List<Action> actionList = new ArrayList<Action>();
1629         ActionBuilder ab = new ActionBuilder();
1630
1631         PopVlanActionBuilder popVlanActionBuilder = new PopVlanActionBuilder();
1632         ab.setAction(new PopVlanActionCaseBuilder().setPopVlanAction(popVlanActionBuilder.build()).build());
1633         ab.setKey(new ActionKey(0));
1634         actionList.add(ab.build());
1635
1636         // Create an Apply Action
1637         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1638         aab.setAction(actionList);
1639
1640         // Wrap our Apply Action in an Instruction
1641         InstructionBuilder ib = new InstructionBuilder();
1642         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1643
1644         // Put our Instruction in a list of Instructions
1645         InstructionsBuilder isb = new InstructionsBuilder();
1646         List<Instruction> instructions = new ArrayList<Instruction>();
1647         ib.setKey(new InstructionKey(0));
1648         instructions.add(ib.build());
1649         isb.setInstruction(instructions);
1650         return isb;
1651     }
1652
1653     private static InstructionsBuilder createAppyActionInstruction22() {
1654
1655         List<Action> actionList = new ArrayList<Action>();
1656         ActionBuilder ab = new ActionBuilder();
1657
1658         SetDlTypeActionBuilder setDlTypeActionBuilder = new SetDlTypeActionBuilder();
1659         setDlTypeActionBuilder.setDlType(new EtherType(8L));
1660         ab.setAction(new SetDlTypeActionCaseBuilder().setSetDlTypeAction(setDlTypeActionBuilder.build()).build());
1661         ab.setKey(new ActionKey(0));
1662         actionList.add(ab.build());
1663
1664         // Create an Apply Action
1665         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1666         aab.setAction(actionList);
1667
1668         // Wrap our Apply Action in an Instruction
1669         InstructionBuilder ib = new InstructionBuilder();
1670         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1671
1672         // Put our Instruction in a list of Instructions
1673         InstructionsBuilder isb = new InstructionsBuilder();
1674         List<Instruction> instructions = new ArrayList<Instruction>();
1675         ib.setKey(new InstructionKey(0));
1676         instructions.add(ib.build());
1677         isb.setInstruction(instructions);
1678         return isb;
1679     }
1680
1681     private static InstructionsBuilder createAppyActionInstruction23(NodeId nodeId) {
1682
1683         List<Action> actionList = new ArrayList<Action>();
1684         ActionBuilder ab = new ActionBuilder();
1685
1686         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
1687         setFieldBuilder.setInPort(new NodeConnectorId(nodeId + ":2"));
1688         ab.setKey(new ActionKey(0));
1689         actionList.add(ab.build());
1690
1691         // Create an Apply Action
1692         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1693         aab.setAction(actionList);
1694
1695         // Wrap our Apply Action in an Instruction
1696         InstructionBuilder ib = new InstructionBuilder();
1697         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1698
1699         // Put our Instruction in a list of Instructions
1700         InstructionsBuilder isb = new InstructionsBuilder();
1701         List<Instruction> instructions = new ArrayList<Instruction>();
1702         ib.setKey(new InstructionKey(0));
1703         instructions.add(ib.build());
1704         isb.setInstruction(instructions);
1705         return isb;
1706     }
1707
1708     private static InstructionsBuilder createAppyActionInstruction24() {
1709
1710         List<Action> actionList = new ArrayList<Action>();
1711         ActionBuilder ab = new ActionBuilder();
1712
1713         SetMplsTtlActionBuilder setMplsTtlActionBuilder = new SetMplsTtlActionBuilder();
1714         setMplsTtlActionBuilder.setMplsTtl((short) 0X1);
1715         ab.setAction(new SetMplsTtlActionCaseBuilder().setSetMplsTtlAction(setMplsTtlActionBuilder.build()).build());
1716         ab.setKey(new ActionKey(0));
1717         actionList.add(ab.build());
1718
1719         // Create an Apply Action
1720         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1721         aab.setAction(actionList);
1722
1723         // Wrap our Apply Action in an Instruction
1724         InstructionBuilder ib = new InstructionBuilder();
1725         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1726
1727         // Put our Instruction in a list of Instructions
1728         InstructionsBuilder isb = new InstructionsBuilder();
1729         List<Instruction> instructions = new ArrayList<Instruction>();
1730         ib.setKey(new InstructionKey(0));
1731         instructions.add(ib.build());
1732         isb.setInstruction(instructions);
1733         return isb;
1734     }
1735
1736     private static InstructionsBuilder createAppyActionInstruction25() {
1737
1738         List<Action> actionList = new ArrayList<Action>();
1739         ActionBuilder ab = new ActionBuilder();
1740
1741         SetNextHopActionBuilder setNextHopActionBuilder = new SetNextHopActionBuilder();
1742         Ipv4Builder ipnext = new Ipv4Builder();
1743         Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
1744         ipnext.setIpv4Address(prefix);
1745         setNextHopActionBuilder.setAddress(ipnext.build());
1746         ab.setAction(new SetNextHopActionCaseBuilder().setSetNextHopAction(setNextHopActionBuilder.build()).build());
1747         ab.setKey(new ActionKey(0));
1748         actionList.add(ab.build());
1749
1750         // Create an Apply Action
1751         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1752         aab.setAction(actionList);
1753
1754         // Wrap our Apply Action in an Instruction
1755         InstructionBuilder ib = new InstructionBuilder();
1756         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1757
1758         // Put our Instruction in a list of Instructions
1759         InstructionsBuilder isb = new InstructionsBuilder();
1760         List<Instruction> instructions = new ArrayList<Instruction>();
1761         ib.setKey(new InstructionKey(0));
1762         instructions.add(ib.build());
1763         isb.setInstruction(instructions);
1764         return isb;
1765     }
1766
1767     private static InstructionsBuilder createAppyActionInstruction26() {
1768
1769         List<Action> actionList = new ArrayList<Action>();
1770         ActionBuilder ab = new ActionBuilder();
1771
1772         SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
1773         Ipv4Builder ipdst = new Ipv4Builder();
1774         Ipv4Prefix prefixdst = new Ipv4Prefix("10.0.0.21/24");
1775         ipdst.setIpv4Address(prefixdst);
1776         setNwDstActionBuilder.setAddress(ipdst.build());
1777         ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
1778         ab.setKey(new ActionKey(0));
1779         actionList.add(ab.build());
1780
1781         // Create an Apply Action
1782         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1783         aab.setAction(actionList);
1784
1785         // Wrap our Apply Action in an Instruction
1786         InstructionBuilder ib = new InstructionBuilder();
1787         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1788
1789         // Put our Instruction in a list of Instructions
1790         InstructionsBuilder isb = new InstructionsBuilder();
1791         List<Instruction> instructions = new ArrayList<Instruction>();
1792         ib.setKey(new InstructionKey(0));
1793         instructions.add(ib.build());
1794         isb.setInstruction(instructions);
1795         return isb;
1796     }
1797
1798     private static InstructionsBuilder createAppyActionInstruction27() {
1799
1800         List<Action> actionList = new ArrayList<Action>();
1801         ActionBuilder ab = new ActionBuilder();
1802
1803         SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
1804         Ipv4Builder ipsrc = new Ipv4Builder();
1805         Ipv4Prefix prefixsrc = new Ipv4Prefix("10.0.23.21/24");
1806         ipsrc.setIpv4Address(prefixsrc);
1807         setNwsrcActionBuilder.setAddress(ipsrc.build());
1808         ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
1809         ab.setKey(new ActionKey(0));
1810         actionList.add(ab.build());
1811
1812         // Create an Apply Action
1813         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1814         aab.setAction(actionList);
1815
1816         // Wrap our Apply Action in an Instruction
1817         InstructionBuilder ib = new InstructionBuilder();
1818         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1819
1820         // Put our Instruction in a list of Instructions
1821         InstructionsBuilder isb = new InstructionsBuilder();
1822         List<Instruction> instructions = new ArrayList<Instruction>();
1823         ib.setKey(new InstructionKey(0));
1824         instructions.add(ib.build());
1825         isb.setInstruction(instructions);
1826         return isb;
1827     }
1828
1829     private static InstructionsBuilder createAppyActionInstruction28() {
1830
1831         List<Action> actionList = new ArrayList<Action>();
1832         ActionBuilder ab = new ActionBuilder();
1833
1834         SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
1835         setNwTosActionBuilder.setTos(8);
1836         ab.setAction(new SetNwTosActionCaseBuilder().setSetNwTosAction(setNwTosActionBuilder.build()).build());
1837         ab.setKey(new ActionKey(0));
1838         actionList.add(ab.build());
1839         // Create an Apply Action
1840         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1841         aab.setAction(actionList);
1842
1843         // Wrap our Apply Action in an Instruction
1844         InstructionBuilder ib = new InstructionBuilder();
1845         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1846
1847         // Put our Instruction in a list of Instructions
1848         InstructionsBuilder isb = new InstructionsBuilder();
1849         List<Instruction> instructions = new ArrayList<Instruction>();
1850         ib.setKey(new InstructionKey(0));
1851         instructions.add(ib.build());
1852         isb.setInstruction(instructions);
1853         return isb;
1854     }
1855
1856     private static InstructionsBuilder createAppyActionInstruction29() {
1857
1858         List<Action> actionList = new ArrayList<Action>();
1859         ActionBuilder ab = new ActionBuilder();
1860
1861         SetNwTtlActionBuilder setNwTtlActionBuilder = new SetNwTtlActionBuilder();
1862         setNwTtlActionBuilder.setNwTtl((short) 1);
1863         ab.setAction(new SetNwTtlActionCaseBuilder().setSetNwTtlAction(setNwTtlActionBuilder.build()).build());
1864         ab.setKey(new ActionKey(0));
1865         actionList.add(ab.build());
1866
1867         // Create an Apply Action
1868         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1869         aab.setAction(actionList);
1870
1871         // Wrap our Apply Action in an Instruction
1872         InstructionBuilder ib = new InstructionBuilder();
1873         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1874
1875         // Put our Instruction in a list of Instructions
1876         InstructionsBuilder isb = new InstructionsBuilder();
1877         List<Instruction> instructions = new ArrayList<Instruction>();
1878         ib.setKey(new InstructionKey(0));
1879         instructions.add(ib.build());
1880         isb.setInstruction(instructions);
1881         return isb;
1882     }
1883
1884     private static InstructionsBuilder createAppyActionInstruction30() {
1885
1886         List<Action> actionList = new ArrayList<Action>();
1887         ActionBuilder ab = new ActionBuilder();
1888
1889         SetQueueActionBuilder setQueueActionBuilder = new SetQueueActionBuilder();
1890         setQueueActionBuilder.setQueueId(1L);
1891         ab.setAction(new SetQueueActionCaseBuilder().setSetQueueAction(setQueueActionBuilder.build()).build());
1892         ab.setKey(new ActionKey(0));
1893         actionList.add(ab.build());
1894         // Create an Apply Action
1895         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1896         aab.setAction(actionList);
1897
1898         // Wrap our Apply Action in an Instruction
1899         InstructionBuilder ib = new InstructionBuilder();
1900         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1901
1902         // Put our Instruction in a list of Instructions
1903         InstructionsBuilder isb = new InstructionsBuilder();
1904         List<Instruction> instructions = new ArrayList<Instruction>();
1905         ib.setKey(new InstructionKey(0));
1906         instructions.add(ib.build());
1907         isb.setInstruction(instructions);
1908         return isb;
1909     }
1910
1911     private static InstructionsBuilder createAppyActionInstruction31() {
1912
1913         List<Action> actionList = new ArrayList<Action>();
1914         ActionBuilder ab = new ActionBuilder();
1915
1916         SetTpDstActionBuilder setTpDstActionBuilder = new SetTpDstActionBuilder();
1917         setTpDstActionBuilder.setPort(new PortNumber(109));
1918
1919         ab.setAction(new SetTpDstActionCaseBuilder().setSetTpDstAction(setTpDstActionBuilder.build()).build());
1920         ab.setKey(new ActionKey(0));
1921         actionList.add(ab.build());
1922         // Create an Apply Action
1923         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1924         aab.setAction(actionList);
1925
1926         // Wrap our Apply Action in an Instruction
1927         InstructionBuilder ib = new InstructionBuilder();
1928         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1929
1930         // Put our Instruction in a list of Instructions
1931         InstructionsBuilder isb = new InstructionsBuilder();
1932         List<Instruction> instructions = new ArrayList<Instruction>();
1933         ib.setKey(new InstructionKey(0));
1934         instructions.add(ib.build());
1935         isb.setInstruction(instructions);
1936         return isb;
1937     }
1938
1939     private static InstructionsBuilder createAppyActionInstruction32() {
1940
1941         List<Action> actionList = new ArrayList<Action>();
1942         ActionBuilder ab = new ActionBuilder();
1943
1944         SetTpSrcActionBuilder setTpSrcActionBuilder = new SetTpSrcActionBuilder();
1945         setTpSrcActionBuilder.setPort(new PortNumber(109));
1946         ab.setAction(new SetTpSrcActionCaseBuilder().setSetTpSrcAction(setTpSrcActionBuilder.build()).build());
1947         ab.setKey(new ActionKey(0));
1948         actionList.add(ab.build());
1949
1950         // Create an Apply Action
1951         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1952         aab.setAction(actionList);
1953
1954         // Wrap our Apply Action in an Instruction
1955         InstructionBuilder ib = new InstructionBuilder();
1956         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1957
1958         // Put our Instruction in a list of Instructions
1959         InstructionsBuilder isb = new InstructionsBuilder();
1960         List<Instruction> instructions = new ArrayList<Instruction>();
1961         ib.setKey(new InstructionKey(0));
1962         instructions.add(ib.build());
1963         isb.setInstruction(instructions);
1964         return isb;
1965     }
1966
1967     private static InstructionsBuilder createAppyActionInstruction33() {
1968
1969         List<Action> actionList = new ArrayList<Action>();
1970         ActionBuilder ab = new ActionBuilder();
1971
1972         SetVlanCfiActionBuilder setVlanCfiActionBuilder = new SetVlanCfiActionBuilder();
1973         setVlanCfiActionBuilder.setVlanCfi(new VlanCfi(2));
1974         ab.setAction(new SetVlanCfiActionCaseBuilder().setSetVlanCfiAction(setVlanCfiActionBuilder.build()).build());
1975         ab.setKey(new ActionKey(0));
1976         actionList.add(ab.build());
1977
1978         // Create an Apply Action
1979         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1980         aab.setAction(actionList);
1981
1982         // Wrap our Apply Action in an Instruction
1983         InstructionBuilder ib = new InstructionBuilder();
1984         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1985
1986         // Put our Instruction in a list of Instructions
1987         InstructionsBuilder isb = new InstructionsBuilder();
1988         List<Instruction> instructions = new ArrayList<Instruction>();
1989         ib.setKey(new InstructionKey(0));
1990         instructions.add(ib.build());
1991         isb.setInstruction(instructions);
1992         return isb;
1993     }
1994
1995     private static InstructionsBuilder createAppyActionInstruction34() {
1996
1997         List<Action> actionList = new ArrayList<Action>();
1998         ActionBuilder ab = new ActionBuilder();
1999
2000         SwPathActionBuilder swPathAction = new SwPathActionBuilder();
2001         ab.setAction(new SwPathActionCaseBuilder().setSwPathAction(swPathAction.build()).build());
2002         ab.setKey(new ActionKey(0));
2003         actionList.add(ab.build());
2004
2005         // Create an Apply Action
2006         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2007         aab.setAction(actionList);
2008
2009         // Wrap our Apply Action in an Instruction
2010         InstructionBuilder ib = new InstructionBuilder();
2011         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2012
2013         // Put our Instruction in a list of Instructions
2014         InstructionsBuilder isb = new InstructionsBuilder();
2015         List<Instruction> instructions = new ArrayList<Instruction>();
2016         ib.setKey(new InstructionKey(0));
2017         instructions.add(ib.build());
2018         isb.setInstruction(instructions);
2019         return isb;
2020     }
2021
2022     private static InstructionsBuilder createAppyActionInstruction35() {
2023
2024         List<Action> actionList = new ArrayList<Action>();
2025         ActionBuilder ab = new ActionBuilder();
2026         ActionBuilder ab1 = new ActionBuilder();
2027         ActionBuilder ab2 = new ActionBuilder();
2028
2029         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2030         SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
2031         SetFieldBuilder setFieldBuilder2 = new SetFieldBuilder();
2032
2033         // Ethernet
2034         EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
2035         EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
2036         ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
2037         EthernetMatchBuilder ethernetMatch1 = new EthernetMatchBuilder();
2038         EthernetDestinationBuilder ethDestBuilder = new EthernetDestinationBuilder();
2039         ethDestBuilder.setAddress(new MacAddress("00:00:00:00:00:02"));
2040         EthernetMatchBuilder ethernetMatch2 = new EthernetMatchBuilder();
2041         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2042         ethTypeBuilder.setType(new EtherType(0x86ddL));
2043
2044         ethernetMatch.setEthernetSource(ethSourceBuilder.build());
2045         ethernetMatch1.setEthernetDestination(ethDestBuilder.build());
2046         ethernetMatch2.setEthernetType(ethTypeBuilder.build());
2047         setFieldBuilder.setEthernetMatch(ethernetMatch.build());
2048         setFieldBuilder1.setEthernetMatch(ethernetMatch1.build());
2049         setFieldBuilder2.setEthernetMatch(ethernetMatch2.build());
2050         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2051         ab.setKey(new ActionKey(0));
2052         actionList.add(ab.build());
2053
2054         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
2055         ab1.setKey(new ActionKey(1));
2056         actionList.add(ab1.build());
2057
2058         ab2.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder2.build()).build());
2059         ab2.setKey(new ActionKey(2));
2060         actionList.add(ab2.build());
2061
2062         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2063         aab.setAction(actionList);
2064
2065         InstructionBuilder ib = new InstructionBuilder();
2066         ib.setKey(new InstructionKey(0));
2067         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2068
2069         // Put our Instruction in a list of Instructions
2070         InstructionsBuilder isb = new InstructionsBuilder();
2071         List<Instruction> instructions = new ArrayList<Instruction>();
2072         ib.setKey(new InstructionKey(0));
2073         instructions.add(ib.build());
2074         isb.setInstruction(instructions);
2075         return isb;
2076     }
2077
2078     private static InstructionsBuilder createAppyActionInstruction36() {
2079
2080         List<Action> actionList = new ArrayList<Action>();
2081         ActionBuilder ab = new ActionBuilder();
2082         ActionBuilder ab1 = new ActionBuilder();
2083
2084         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2085         SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
2086
2087         // Vlan
2088         VlanMatchBuilder vlanBuilder = new VlanMatchBuilder();
2089         VlanMatchBuilder vlanBuilder1 = new VlanMatchBuilder();
2090         VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
2091         VlanId vlanId = new VlanId(10);
2092         VlanPcp vpcp = new VlanPcp((short) 3);
2093         vlanBuilder.setVlanPcp(vpcp);
2094         vlanBuilder1.setVlanId(vlanIdBuilder.setVlanId(vlanId).setVlanIdPresent(true).build());
2095         setFieldBuilder.setVlanMatch(vlanBuilder.build());
2096         setFieldBuilder1.setVlanMatch(vlanBuilder1.build());
2097         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2098         ab.setKey(new ActionKey(0));
2099         actionList.add(ab.build());
2100         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
2101         ab1.setKey(new ActionKey(1));
2102         actionList.add(ab1.build());
2103
2104         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2105         aab.setAction(actionList);
2106
2107         InstructionBuilder ib = new InstructionBuilder();
2108         ib.setKey(new InstructionKey(0));
2109         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2110
2111         // Put our Instruction in a list of Instructions
2112         InstructionsBuilder isb = new InstructionsBuilder();
2113         List<Instruction> instructions = new ArrayList<Instruction>();
2114         instructions.add(ib.build());
2115         isb.setInstruction(instructions);
2116         return isb;
2117     }
2118
2119     private static InstructionsBuilder createAppyActionInstruction37() {
2120
2121         List<Action> actionList = new ArrayList<Action>();
2122         ActionBuilder ab = new ActionBuilder();
2123         ActionBuilder ab1 = new ActionBuilder();
2124         ActionBuilder ab2 = new ActionBuilder();
2125
2126         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2127         SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
2128         SetFieldBuilder setFieldBuilder2 = new SetFieldBuilder();
2129         // Ip
2130         IpMatchBuilder ipmatch = new IpMatchBuilder();
2131         IpMatchBuilder ipmatch1 = new IpMatchBuilder();
2132         IpMatchBuilder ipmatch2 = new IpMatchBuilder();
2133         Dscp dscp = new Dscp((short) 3);
2134         ipmatch.setIpDscp(dscp);
2135         ipmatch1.setIpEcn((short) 2);
2136         ipmatch2.setIpProtocol((short) 120);
2137         setFieldBuilder.setIpMatch(ipmatch.build());
2138         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2139         ab.setKey(new ActionKey(0));
2140         actionList.add(ab.build());
2141
2142         setFieldBuilder1.setIpMatch(ipmatch1.build());
2143         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
2144         ab1.setKey(new ActionKey(1));
2145         actionList.add(ab1.build());
2146
2147         setFieldBuilder2.setIpMatch(ipmatch2.build());
2148         ab2.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder2.build()).build());
2149         ab2.setKey(new ActionKey(2));
2150         actionList.add(ab2.build());
2151
2152         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2153         aab.setAction(actionList);
2154
2155         InstructionBuilder ib = new InstructionBuilder();
2156         ib.setKey(new InstructionKey(0));
2157         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2158
2159         // Put our Instruction in a list of Instructions
2160         InstructionsBuilder isb = new InstructionsBuilder();
2161         List<Instruction> instructions = new ArrayList<Instruction>();
2162         instructions.add(ib.build());
2163         isb.setInstruction(instructions);
2164         return isb;
2165     }
2166
2167     private static InstructionsBuilder createAppyActionInstruction38() {
2168
2169         List<Action> actionList = new ArrayList<Action>();
2170         ActionBuilder ab = new ActionBuilder();
2171         ActionBuilder ab1 = new ActionBuilder();
2172
2173         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2174         SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
2175         // IPv4
2176         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
2177         Ipv4MatchBuilder ipv4Match1 = new Ipv4MatchBuilder();
2178         Ipv4Prefix dstip = new Ipv4Prefix("200.71.9.5210");
2179         Ipv4Prefix srcip = new Ipv4Prefix("100.1.1.1");
2180         ipv4Match1.setIpv4Destination(dstip);
2181         ipv4Match.setIpv4Source(srcip);
2182         setFieldBuilder.setLayer3Match(ipv4Match.build());
2183         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2184         ab.setKey(new ActionKey(0));
2185         actionList.add(ab.build());
2186
2187         setFieldBuilder1.setLayer3Match(ipv4Match1.build());
2188         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
2189         ab1.setKey(new ActionKey(1));
2190         actionList.add(ab1.build());
2191
2192         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2193         aab.setAction(actionList);
2194
2195         InstructionBuilder ib = new InstructionBuilder();
2196         ib.setKey(new InstructionKey(0));
2197         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2198
2199         // Put our Instruction in a list of Instructions
2200         InstructionsBuilder isb = new InstructionsBuilder();
2201         List<Instruction> instructions = new ArrayList<Instruction>();
2202         instructions.add(ib.build());
2203         isb.setInstruction(instructions);
2204         return isb;
2205     }
2206
2207     private static InstructionsBuilder createAppyActionInstruction39() {
2208
2209         List<Action> actionList = new ArrayList<Action>();
2210         ActionBuilder ab = new ActionBuilder();
2211         ActionBuilder ab1 = new ActionBuilder();
2212
2213         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2214         SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
2215
2216         // Tcp
2217         PortNumber tcpsrcport = new PortNumber(1213);
2218         PortNumber tcpdstport = new PortNumber(646);
2219         TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
2220         TcpMatchBuilder tcpmatch1 = new TcpMatchBuilder();
2221         tcpmatch.setTcpSourcePort(tcpsrcport);
2222         tcpmatch1.setTcpDestinationPort(tcpdstport);
2223         setFieldBuilder.setLayer4Match(tcpmatch.build());
2224         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2225         ab.setKey(new ActionKey(0));
2226         actionList.add(ab.build());
2227
2228         setFieldBuilder1.setLayer4Match(tcpmatch1.build());
2229         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
2230         ab1.setKey(new ActionKey(1));
2231         actionList.add(ab.build());
2232
2233         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2234         aab.setAction(actionList);
2235
2236         InstructionBuilder ib = new InstructionBuilder();
2237         ib.setKey(new InstructionKey(0));
2238         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2239
2240         // Put our Instruction in a list of Instructions
2241         InstructionsBuilder isb = new InstructionsBuilder();
2242         List<Instruction> instructions = new ArrayList<Instruction>();
2243         instructions.add(ib.build());
2244         isb.setInstruction(instructions);
2245         return isb;
2246     }
2247
2248     private static InstructionsBuilder createAppyActionInstruction40() {
2249
2250         List<Action> actionList = new ArrayList<Action>();
2251         ActionBuilder ab = new ActionBuilder();
2252         ActionBuilder ab1 = new ActionBuilder();
2253
2254         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2255         SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
2256
2257         // Udp
2258         PortNumber udpsrcport = new PortNumber(1325);
2259         PortNumber udpdstport = new PortNumber(42);
2260         UdpMatchBuilder udpmatch = new UdpMatchBuilder();
2261         UdpMatchBuilder udpmatch1 = new UdpMatchBuilder();
2262         udpmatch.setUdpDestinationPort(udpdstport);
2263         udpmatch1.setUdpSourcePort(udpsrcport);
2264         setFieldBuilder.setLayer4Match(udpmatch.build());
2265         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2266         ab.setKey(new ActionKey(0));
2267         actionList.add(ab.build());
2268
2269         setFieldBuilder1.setLayer4Match(udpmatch1.build());
2270         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
2271         ab1.setKey(new ActionKey(1));
2272         actionList.add(ab1.build());
2273
2274         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2275         aab.setAction(actionList);
2276
2277         InstructionBuilder ib = new InstructionBuilder();
2278         ib.setKey(new InstructionKey(0));
2279         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2280
2281         // Put our Instruction in a list of Instructions
2282         InstructionsBuilder isb = new InstructionsBuilder();
2283         List<Instruction> instructions = new ArrayList<Instruction>();
2284         instructions.add(ib.build());
2285         isb.setInstruction(instructions);
2286         return isb;
2287     }
2288
2289     private static InstructionsBuilder createAppyActionInstruction41() {
2290
2291         List<Action> actionList = new ArrayList<Action>();
2292         ActionBuilder ab = new ActionBuilder();
2293         ActionBuilder ab1 = new ActionBuilder();
2294
2295         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2296         SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
2297
2298         // Sctp
2299         SctpMatchBuilder sctpmatch = new SctpMatchBuilder();
2300         SctpMatchBuilder sctpmatch1 = new SctpMatchBuilder();
2301         PortNumber srcport = new PortNumber(1435);
2302         PortNumber dstport = new PortNumber(22);
2303         sctpmatch.setSctpSourcePort(srcport);
2304         sctpmatch1.setSctpDestinationPort(dstport);
2305         setFieldBuilder.setLayer4Match(sctpmatch.build());
2306         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2307         ab.setKey(new ActionKey(0));
2308         actionList.add(ab.build());
2309
2310         setFieldBuilder1.setLayer4Match(sctpmatch1.build());
2311         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
2312         ab1.setKey(new ActionKey(1));
2313         actionList.add(ab1.build());
2314
2315         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2316         aab.setAction(actionList);
2317
2318         InstructionBuilder ib = new InstructionBuilder();
2319         ib.setKey(new InstructionKey(0));
2320         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2321
2322         // Put our Instruction in a list of Instructions
2323         InstructionsBuilder isb = new InstructionsBuilder();
2324         List<Instruction> instructions = new ArrayList<Instruction>();
2325         instructions.add(ib.build());
2326         isb.setInstruction(instructions);
2327         return isb;
2328     }
2329
2330     private static InstructionsBuilder createAppyActionInstruction42() {
2331
2332         List<Action> actionList = new ArrayList<Action>();
2333         ActionBuilder ab = new ActionBuilder();
2334         ActionBuilder ab1 = new ActionBuilder();
2335         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2336         SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
2337
2338         // Icmpv4
2339         Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
2340         Icmpv4MatchBuilder icmpv4match1 = new Icmpv4MatchBuilder();
2341         icmpv4match.setIcmpv4Type((short) 8);
2342         icmpv4match1.setIcmpv4Code((short) 0);
2343         setFieldBuilder.setIcmpv4Match(icmpv4match.build());
2344         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2345         ab.setKey(new ActionKey(0));
2346         actionList.add(ab.build());
2347
2348         setFieldBuilder1.setIcmpv4Match(icmpv4match1.build());
2349         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
2350         ab1.setKey(new ActionKey(1));
2351         actionList.add(ab1.build());
2352
2353         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2354         aab.setAction(actionList);
2355
2356         InstructionBuilder ib = new InstructionBuilder();
2357         ib.setKey(new InstructionKey(0));
2358         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2359
2360         // Put our Instruction in a list of Instructions
2361         InstructionsBuilder isb = new InstructionsBuilder();
2362         List<Instruction> instructions = new ArrayList<Instruction>();
2363         instructions.add(ib.build());
2364         isb.setInstruction(instructions);
2365         return isb;
2366     }
2367
2368     private static InstructionsBuilder createAppyActionInstruction43() {
2369
2370         List<Action> actionList = new ArrayList<Action>();
2371         ActionBuilder ab = new ActionBuilder();
2372         ActionBuilder ab1 = new ActionBuilder();
2373         ActionBuilder ab2 = new ActionBuilder();
2374         ActionBuilder ab3 = new ActionBuilder();
2375         ActionBuilder ab4 = new ActionBuilder();
2376
2377         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2378         SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
2379         SetFieldBuilder setFieldBuilder2 = new SetFieldBuilder();
2380         SetFieldBuilder setFieldBuilder3 = new SetFieldBuilder();
2381         SetFieldBuilder setFieldBuilder4 = new SetFieldBuilder();
2382
2383         // setting the values of ARP
2384         MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
2385         MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
2386         Ipv4Prefix dstiparp = new Ipv4Prefix("200.71.9.52");
2387         Ipv4Prefix srciparp = new Ipv4Prefix("100.1.1.1");
2388         // create ARP match action
2389         ArpMatchBuilder arpmatch = new ArpMatchBuilder();
2390         ArpMatchBuilder arpmatch1 = new ArpMatchBuilder();
2391         ArpMatchBuilder arpmatch2 = new ArpMatchBuilder();
2392         ArpMatchBuilder arpmatch3 = new ArpMatchBuilder();
2393         ArpMatchBuilder arpmatch4 = new ArpMatchBuilder();
2394         ArpSourceHardwareAddressBuilder arpsrc = new ArpSourceHardwareAddressBuilder();
2395         arpsrc.setAddress(macsrc);
2396         ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder();
2397         arpdst.setAddress(macdest);
2398         arpmatch.setArpOp(2);
2399         arpmatch1.setArpSourceHardwareAddress(arpsrc.build());
2400         arpmatch2.setArpTargetHardwareAddress(arpdst.build());
2401         arpmatch3.setArpSourceTransportAddress(srciparp);
2402         arpmatch4.setArpTargetTransportAddress(dstiparp);
2403         setFieldBuilder.setLayer3Match(arpmatch.build());
2404         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2405         ab.setKey(new ActionKey(0));
2406         actionList.add(ab.build());
2407
2408         setFieldBuilder1.setLayer3Match(arpmatch1.build());
2409         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
2410         ab1.setKey(new ActionKey(1));
2411         actionList.add(ab1.build());
2412
2413         setFieldBuilder2.setLayer3Match(arpmatch2.build());
2414         ab2.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder2.build()).build());
2415         ab2.setKey(new ActionKey(2));
2416         actionList.add(ab2.build());
2417
2418         setFieldBuilder3.setLayer3Match(arpmatch3.build());
2419         ab3.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder3.build()).build());
2420         ab3.setKey(new ActionKey(3));
2421         actionList.add(ab3.build());
2422
2423         setFieldBuilder4.setLayer3Match(arpmatch4.build());
2424         ab4.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder4.build()).build());
2425         ab4.setKey(new ActionKey(4));
2426         actionList.add(ab4.build());
2427
2428         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2429         aab.setAction(actionList);
2430
2431         InstructionBuilder ib = new InstructionBuilder();
2432         ib.setKey(new InstructionKey(0));
2433         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2434
2435         // Put our Instruction in a list of Instructions
2436         InstructionsBuilder isb = new InstructionsBuilder();
2437         List<Instruction> instructions = new ArrayList<Instruction>();
2438         instructions.add(ib.build());
2439         isb.setInstruction(instructions);
2440         return isb;
2441     }
2442
2443     private static InstructionsBuilder createAppyActionInstruction44() {
2444
2445         List<Action> actionLists = new ArrayList<Action>();
2446         ActionBuilder ab = new ActionBuilder();
2447         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2448         ActionBuilder ab1 = new ActionBuilder();
2449         SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
2450         /*
2451          * ActionBuilder ab2 = new ActionBuilder(); SetFieldBuilder
2452          * setFieldBuilder2 = new SetFieldBuilder(); ActionBuilder ab3 = new
2453          * ActionBuilder(); SetFieldBuilder setFieldBuilder3 = new
2454          * SetFieldBuilder(); ActionBuilder ab4 = new ActionBuilder();
2455          * SetFieldBuilder setFieldBuilder4 = new SetFieldBuilder();
2456          */
2457         ActionBuilder ab5 = new ActionBuilder();
2458         SetFieldBuilder setFieldBuilder5 = new SetFieldBuilder();
2459         ActionBuilder ab6 = new ActionBuilder();
2460         SetFieldBuilder setFieldBuilder6 = new SetFieldBuilder();
2461
2462         // IPv6
2463         Ipv6MatchBuilder ipv6Builder = new Ipv6MatchBuilder();
2464         Ipv6MatchBuilder ipv6Builder1 = new Ipv6MatchBuilder();
2465         // Ipv6MatchBuilder ipv6Builder2 = new Ipv6MatchBuilder();
2466         // Ipv6MatchBuilder ipv6Builder3 = new Ipv6MatchBuilder();
2467         // Ipv6MatchBuilder ipv6Builder4 = new Ipv6MatchBuilder();
2468         Ipv6MatchBuilder ipv6Builder5 = new Ipv6MatchBuilder();
2469         Ipv6MatchBuilder ipv6Builder6 = new Ipv6MatchBuilder();
2470
2471         Ipv6Prefix dstip6 = new Ipv6Prefix("2002::2");
2472         Ipv6Prefix srcip6 = new Ipv6Prefix("2001:0:0:0:0:0:0:1");
2473         // Ipv6Address ndtarget = new
2474         // Ipv6Address("2001:db8:0:1:fd97:f9f0:a810:782e");
2475         // MacAddress ndsll = new MacAddress("c2:00:54:f5:00:00");
2476         // MacAddress ndtll = new MacAddress("00:0c:29:0e:4c:67");
2477         Ipv6ExtHeaderBuilder nextheader = new Ipv6ExtHeaderBuilder();
2478         nextheader.setIpv6Exthdr(58);
2479         Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
2480         Ipv6FlowLabel label = new Ipv6FlowLabel(10028L);
2481         ipv6label.setIpv6Flabel(label);
2482
2483         ipv6Builder.setIpv6Source(srcip6);
2484         ipv6Builder1.setIpv6Destination(dstip6);
2485         // ipv6Builder2.setIpv6NdTarget(ndtarget);
2486         // ipv6Builder3.setIpv6NdSll(ndsll);
2487         // ipv6Builder4.setIpv6NdTll(ndtll);
2488         ipv6Builder5.setIpv6ExtHeader(nextheader.build());
2489         ipv6Builder6.setIpv6Label(ipv6label.build());
2490
2491         setFieldBuilder.setLayer3Match(ipv6Builder.build());
2492         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2493         ab.setKey(new ActionKey(0));
2494         actionLists.add(ab.build());
2495
2496         setFieldBuilder1.setLayer3Match(ipv6Builder1.build());
2497         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
2498         ab1.setKey(new ActionKey(1));
2499         actionLists.add(ab1.build());
2500
2501         /*
2502          * setFieldBuilder2.setLayer3Match(ipv6Builder2.build());
2503          * ab2.setAction(new
2504          * SetFieldCaseBuilder().setSetField(setFieldBuilder2.build()).build());
2505          * ab2.setKey(new ActionKey(2)); actionLists.add(ab2.build());
2506          *
2507          * setFieldBuilder3.setLayer3Match(ipv6Builder3.build());
2508          * ab3.setAction(new
2509          * SetFieldCaseBuilder().setSetField(setFieldBuilder3.build()).build());
2510          * ab3.setKey(new ActionKey(3)); actionLists.add(ab3.build());
2511          *
2512          * setFieldBuilder4.setLayer3Match(ipv6Builder4.build());
2513          * ab4.setAction(new
2514          * SetFieldCaseBuilder().setSetField(setFieldBuilder4.build()).build());
2515          * ab4.setKey(new ActionKey(4)); actionLists.add(ab4.build());
2516          */
2517         setFieldBuilder5.setLayer3Match(ipv6Builder5.build());
2518         ab5.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder5.build()).build());
2519         ab5.setKey(new ActionKey(5));
2520         actionLists.add(ab5.build());
2521
2522         setFieldBuilder6.setLayer3Match(ipv6Builder6.build());
2523         ab6.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder6.build()).build());
2524         ab6.setKey(new ActionKey(6));
2525         actionLists.add(ab6.build());
2526
2527         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2528         aab.setAction(actionLists);
2529
2530         InstructionBuilder ib = new InstructionBuilder();
2531         ib.setKey(new InstructionKey(0));
2532         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2533
2534         // Put our Instruction in a list of Instructions
2535         InstructionsBuilder isb = new InstructionsBuilder();
2536         List<Instruction> instructions = new ArrayList<Instruction>();
2537         instructions.add(ib.build());
2538         isb.setInstruction(instructions);
2539         return isb;
2540     }
2541
2542     private static InstructionsBuilder createAppyActionInstruction45() {
2543
2544         List<Action> actionList = new ArrayList<Action>();
2545         ActionBuilder ab = new ActionBuilder();
2546         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2547         ActionBuilder ab1 = new ActionBuilder();
2548         SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
2549
2550         // Icmpv6
2551         Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder();
2552         Icmpv6MatchBuilder icmpv6match1 = new Icmpv6MatchBuilder();
2553         icmpv6match.setIcmpv6Type((short) 135);
2554         icmpv6match1.setIcmpv6Code((short) 0);
2555         setFieldBuilder.setIcmpv6Match(icmpv6match.build());
2556         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2557         ab.setKey(new ActionKey(0));
2558         actionList.add(ab.build());
2559
2560         setFieldBuilder1.setIcmpv6Match(icmpv6match1.build());
2561         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
2562         ab1.setKey(new ActionKey(1));
2563         actionList.add(ab1.build());
2564
2565         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2566         aab.setAction(actionList);
2567
2568         InstructionBuilder ib = new InstructionBuilder();
2569         ib.setKey(new InstructionKey(0));
2570         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2571
2572         // Put our Instruction in a list of Instructions
2573         InstructionsBuilder isb = new InstructionsBuilder();
2574         List<Instruction> instructions = new ArrayList<Instruction>();
2575         instructions.add(ib.build());
2576         isb.setInstruction(instructions);
2577         return isb;
2578     }
2579
2580     private static InstructionsBuilder createAppyActionInstruction46() {
2581
2582         List<Action> actionList = new ArrayList<Action>();
2583         ActionBuilder ab = new ActionBuilder();
2584         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2585         ActionBuilder ab1 = new ActionBuilder();
2586         SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
2587         ActionBuilder ab2 = new ActionBuilder();
2588         SetFieldBuilder setFieldBuilder2 = new SetFieldBuilder();
2589
2590         // MPLS
2591         ProtocolMatchFieldsBuilder protomatch = new ProtocolMatchFieldsBuilder();
2592         ProtocolMatchFieldsBuilder protomatch1 = new ProtocolMatchFieldsBuilder();
2593         ProtocolMatchFieldsBuilder protomatch2 = new ProtocolMatchFieldsBuilder();
2594         protomatch.setMplsLabel((long) 36008);
2595         protomatch1.setMplsTc((short) 4);
2596         protomatch2.setMplsBos((short) 1);
2597         setFieldBuilder.setProtocolMatchFields(protomatch.build());
2598         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2599         ab.setKey(new ActionKey(0));
2600         actionList.add(ab.build());
2601
2602         setFieldBuilder1.setProtocolMatchFields(protomatch1.build());
2603         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
2604         ab1.setKey(new ActionKey(1));
2605         actionList.add(ab1.build());
2606
2607         setFieldBuilder2.setProtocolMatchFields(protomatch2.build());
2608         ab2.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder2.build()).build());
2609         ab2.setKey(new ActionKey(2));
2610         actionList.add(ab2.build());
2611
2612         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2613         aab.setAction(actionList);
2614
2615         InstructionBuilder ib = new InstructionBuilder();
2616         ib.setKey(new InstructionKey(0));
2617         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2618
2619         // Put our Instruction in a list of Instructions
2620         InstructionsBuilder isb = new InstructionsBuilder();
2621         List<Instruction> instructions = new ArrayList<Instruction>();
2622         instructions.add(ib.build());
2623         isb.setInstruction(instructions);
2624         return isb;
2625     }
2626
2627     private static InstructionsBuilder createAppyActionInstruction47() {
2628
2629         List<Action> actionList = new ArrayList<Action>();
2630         ActionBuilder ab = new ActionBuilder();
2631         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2632         // PBB
2633         ProtocolMatchFieldsBuilder protomatch = new ProtocolMatchFieldsBuilder();
2634         protomatch.setPbb(new PbbBuilder().setPbbIsid(4L).setPbbMask((new BigInteger(new byte[]{0, 1, 0, 0}).longValue())).build());
2635         setFieldBuilder.setProtocolMatchFields(protomatch.build());
2636         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2637         actionList.add(ab.build());
2638
2639         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2640         aab.setAction(actionList);
2641
2642         InstructionBuilder ib = new InstructionBuilder();
2643         ib.setKey(new InstructionKey(0));
2644         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2645
2646         // Put our Instruction in a list of Instructions
2647         InstructionsBuilder isb = new InstructionsBuilder();
2648         List<Instruction> instructions = new ArrayList<Instruction>();
2649         instructions.add(ib.build());
2650         isb.setInstruction(instructions);
2651         return isb;
2652     }
2653
2654     private static InstructionsBuilder createAppyActionInstruction48() {
2655
2656         List<Action> actionList = new ArrayList<Action>();
2657         ActionBuilder ab = new ActionBuilder();
2658         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2659         // Tunnel
2660         TunnelBuilder tunnel = new TunnelBuilder();
2661         tunnel.setTunnelId(BigInteger.valueOf(10668));
2662         setFieldBuilder.setTunnel(tunnel.build());
2663         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2664         ab.setKey(new ActionKey(0));
2665         actionList.add(ab.build());
2666
2667         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2668         aab.setAction(actionList);
2669
2670         InstructionBuilder ib = new InstructionBuilder();
2671         ib.setKey(new InstructionKey(0));
2672         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2673
2674         // Put our Instruction in a list of Instructions
2675         InstructionsBuilder isb = new InstructionsBuilder();
2676         List<Instruction> instructions = new ArrayList<Instruction>();
2677         instructions.add(ib.build());
2678         isb.setInstruction(instructions);
2679         return isb;
2680     }
2681
2682     private static InstructionsBuilder createTunnelIpv4DstInstructions() {
2683
2684         List<Action> actionList = new ArrayList<Action>();
2685         ActionBuilder ab = new ActionBuilder();
2686         // Build the tunnel endpoint destination IPv4 address
2687         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2688         Ipv4Prefix dstIp = new Ipv4Prefix("172.16.100.100");
2689         // Add the mew IPv4 object as the tunnel destination
2690         TunnelIpv4MatchBuilder tunnelIpv4DstMatchBuilder = new TunnelIpv4MatchBuilder();
2691         tunnelIpv4DstMatchBuilder.setTunnelIpv4Destination(dstIp);
2692         setFieldBuilder.setLayer3Match(tunnelIpv4DstMatchBuilder.build());
2693         // Add the IPv4 tunnel dst to the set_field value
2694         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2695         ab.setOrder(0);
2696         ab.setKey(new ActionKey(0));
2697         actionList.add(ab.build());
2698         // Resulting action is a per/flow src TEP (set_field:172.16.100.100->tun_dst)
2699         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2700         aab.setAction(actionList);
2701         // Add the action to the ordered list of Instructions
2702         InstructionBuilder ib = new InstructionBuilder();
2703         ib.setOrder(0);
2704         ib.setKey(new InstructionKey(0));
2705         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2706         // Add the Instruction in a list of Instructions
2707         InstructionsBuilder isb = new InstructionsBuilder();
2708         List<Instruction> instructions = new ArrayList<Instruction>();
2709         instructions.add(ib.build());
2710         isb.setInstruction(instructions);
2711         return isb;
2712     }
2713
2714     private static InstructionsBuilder createTunnelIpv4SrcInstructions() {
2715
2716         List<Action> actionList = new ArrayList<Action>();
2717         ActionBuilder ab = new ActionBuilder();
2718         // Build the tunnel endpoint source IPv4 address
2719         SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
2720         Ipv4Prefix dstIp = new Ipv4Prefix("172.16.100.200");
2721         // Add the new IPv4 object as the tunnel destination
2722         TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = new TunnelIpv4MatchBuilder();
2723         tunnelIpv4MatchBuilder.setTunnelIpv4Source(dstIp);
2724         setFieldBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
2725         // Add the IPv4 tunnel src to the set_field value
2726         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
2727         ab.setOrder(0);
2728         ab.setKey(new ActionKey(0));
2729         actionList.add(ab.build());
2730         // Resulting action is a per/flow src TEP (set_field:172.16.100.100->tun_src)
2731         ApplyActionsBuilder aab = new ApplyActionsBuilder();
2732         aab.setAction(actionList);
2733         // Add the action to the ordered list of Instructions
2734         InstructionBuilder ib = new InstructionBuilder();
2735         ib.setOrder(0);
2736         ib.setKey(new InstructionKey(0));
2737         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
2738         // Put our Instruction in a list of Instructions
2739         InstructionsBuilder isb = new InstructionsBuilder();
2740         List<Instruction> instructions = new ArrayList<Instruction>();
2741         instructions.add(ib.build());
2742         isb.setInstruction(instructions);
2743         return isb;
2744     }
2745
2746     private static MatchBuilder createLLDPMatch() {
2747         MatchBuilder match = new MatchBuilder();
2748         EthernetMatchBuilder eth = new EthernetMatchBuilder();
2749         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2750         ethTypeBuilder.setType(new EtherType(0x88ccL));
2751         eth.setEthernetType(ethTypeBuilder.build());
2752         match.setEthernetMatch(eth.build());
2753         return match;
2754     }
2755
2756     /**
2757      * @return
2758      */
2759     private static MatchBuilder createMatch1() {
2760         MatchBuilder match = new MatchBuilder();
2761         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
2762         Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
2763         ipv4Match.setIpv4Destination(prefix);
2764         Ipv4Match i4m = ipv4Match.build();
2765         match.setLayer3Match(i4m);
2766
2767         EthernetMatchBuilder eth = new EthernetMatchBuilder();
2768         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2769         ethTypeBuilder.setType(new EtherType(0x0800L));
2770         eth.setEthernetType(ethTypeBuilder.build());
2771         match.setEthernetMatch(eth.build());
2772         return match;
2773     }
2774
2775     /**
2776      * @return
2777      */
2778     private static MatchBuilder createIPv4DstMatch() {
2779         MatchBuilder match = new MatchBuilder();
2780         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
2781         Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
2782         ipv4Match.setIpv4Destination(prefix);
2783         Ipv4Match i4m = ipv4Match.build();
2784         match.setLayer3Match(i4m);
2785
2786         return match;
2787     }
2788
2789     /**
2790      * @return
2791      */
2792     private static MatchBuilder createIPv4SrcMatch() {
2793         MatchBuilder match = new MatchBuilder();
2794         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
2795         Ipv4Prefix prefix = new Ipv4Prefix("10.20.30.40/24");
2796         ipv4Match.setIpv4Source(prefix);
2797         Ipv4Match i4m = ipv4Match.build();
2798         match.setLayer3Match(i4m);
2799
2800         EthernetMatchBuilder eth = new EthernetMatchBuilder();
2801         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2802         ethTypeBuilder.setType(new EtherType(0x0800L));
2803         eth.setEthernetType(ethTypeBuilder.build());
2804         match.setEthernetMatch(eth.build());
2805         return match;
2806     }
2807
2808     /**
2809      * @return
2810      */
2811     private static MatchBuilder createMatch2() {
2812         MatchBuilder match = new MatchBuilder();
2813         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
2814         Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1");
2815         ipv4Match.setIpv4Source(prefix);
2816         Ipv4Match i4m = ipv4Match.build();
2817         match.setLayer3Match(i4m);
2818
2819         EthernetMatchBuilder eth = new EthernetMatchBuilder();
2820         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2821         ethTypeBuilder.setType(new EtherType(0x0800L));
2822         eth.setEthernetType(ethTypeBuilder.build());
2823         match.setEthernetMatch(eth.build());
2824         return match;
2825     }
2826
2827     /**
2828      * @return
2829      */
2830     private static MatchBuilder createMatch3() {
2831         MatchBuilder match = new MatchBuilder();
2832         EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
2833         EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
2834         ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
2835         ethernetMatch.setEthernetSource(ethSourceBuilder.build());
2836         match.setEthernetMatch(ethernetMatch.build());
2837
2838         return match;
2839     }
2840
2841     /**
2842      * @return
2843      */
2844     private static MatchBuilder createICMPv6Match1() {
2845
2846         MatchBuilder match = new MatchBuilder();
2847         EthernetMatchBuilder eth = new EthernetMatchBuilder();
2848         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2849         ethTypeBuilder.setType(new EtherType(0x86ddL));
2850         eth.setEthernetType(ethTypeBuilder.build());
2851         match.setEthernetMatch(eth.build());
2852
2853         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
2854         ipmatch.setIpProtocol((short) 256);
2855         match.setIpMatch(ipmatch.build());
2856
2857         Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
2858         // match
2859         icmpv6match.setIcmpv6Type((short) 135);
2860         icmpv6match.setIcmpv6Code((short) 1);
2861         match.setIcmpv6Match(icmpv6match.build());
2862
2863         return match;
2864     }
2865
2866     private static MatchBuilder createMatch33() {
2867
2868         MatchBuilder match = new MatchBuilder();
2869         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
2870         Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.10");
2871         ipv4Match.setIpv4Source(prefix);
2872         Ipv4Match i4m = ipv4Match.build();
2873         match.setLayer3Match(i4m);
2874
2875         EthernetMatchBuilder eth = new EthernetMatchBuilder();
2876         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2877         ethTypeBuilder.setType(new EtherType(0xfffeL));
2878         eth.setEthernetType(ethTypeBuilder.build());
2879         match.setEthernetMatch(eth.build());
2880         return match;
2881     }
2882
2883     private static MatchBuilder createInphyportMatch(NodeId nodeId) {
2884         MatchBuilder match = new MatchBuilder();
2885         match.setInPort(new NodeConnectorId(nodeId + ":202"));
2886         match.setInPhyPort(new NodeConnectorId(nodeId + ":10122"));
2887         return match;
2888     }
2889
2890     private static MatchBuilder createEthernetMatch() {
2891         MatchBuilder match = new MatchBuilder();
2892
2893         byte[] mask1 = new byte[]{(byte) -1, (byte) -1, 0, 0, 0, 0};
2894         byte[] mask2 = new byte[]{(byte) -1, (byte) -1, (byte) -1, 0, 0, 0};
2895
2896         EthernetMatchBuilder ethmatch = new EthernetMatchBuilder(); // ethernettype
2897         // match
2898         EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
2899         EtherType type = new EtherType(0x0800L);
2900         ethmatch.setEthernetType(ethtype.setType(type).build());
2901
2902         EthernetDestinationBuilder ethdest = new EthernetDestinationBuilder(); // ethernet
2903         // macaddress
2904         // match
2905         MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
2906         ethdest.setAddress(macdest);
2907         ethdest.setMask(new MacAddress("ff:ff:ff:00:00:00"));
2908
2909         ethmatch.setEthernetDestination(ethdest.build());
2910
2911         EthernetSourceBuilder ethsrc = new EthernetSourceBuilder();
2912         MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
2913         ethsrc.setAddress(macsrc);
2914         ethsrc.setMask(new MacAddress("ff:ff:00:00:00:00"));
2915
2916         ethmatch.setEthernetSource(ethsrc.build());
2917         match.setEthernetMatch(ethmatch.build());
2918         return match;
2919
2920     }
2921
2922     /**
2923      * @return
2924      */
2925
2926     private static MatchBuilder createVlanMatch() {
2927         MatchBuilder match = new MatchBuilder();
2928         VlanMatchBuilder vlanBuilder = new VlanMatchBuilder(); // vlan match
2929         VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
2930         VlanId vlanId = new VlanId(10);
2931         VlanPcp vpcp = new VlanPcp((short) 3);
2932         vlanBuilder.setVlanPcp(vpcp);
2933         vlanIdBuilder.setVlanId(vlanId);
2934         vlanIdBuilder.setVlanIdPresent(true);
2935         vlanBuilder.setVlanId(vlanIdBuilder.build());
2936         match.setVlanMatch(vlanBuilder.build());
2937         return match;
2938     }
2939
2940     /**
2941      * @return
2942      */
2943     private static MatchBuilder createArpMatch() {
2944         MatchBuilder match = new MatchBuilder();
2945
2946         EthernetMatchBuilder ethmatch = new EthernetMatchBuilder();
2947         MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
2948         MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
2949
2950         byte[] mask = new byte[]{(byte) -1, (byte) -1, 0, 0, 0, 0};
2951         byte[] mask2 = new byte[]{(byte) -1, (byte) -1, (byte) -1, 0, 0, 0};
2952
2953         EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
2954         EtherType type = new EtherType(0x0806L);
2955         ethmatch.setEthernetType(ethtype.setType(type).build());
2956
2957         Ipv4Prefix dstip = new Ipv4Prefix("200.71.9.52/10"); // ipv4 match
2958         Ipv4Prefix srcip = new Ipv4Prefix("100.1.1.1/8");
2959
2960         ArpMatchBuilder arpmatch = new ArpMatchBuilder(); // arp match
2961         ArpSourceHardwareAddressBuilder arpsrc = new ArpSourceHardwareAddressBuilder();
2962         arpsrc.setAddress(macsrc);
2963         arpsrc.setMask(new MacAddress("ff:ff:ff:00:00:00"));
2964         ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder();
2965         arpdst.setAddress(macdest);
2966         arpdst.setMask(new MacAddress("ff:ff:00:00:00:00"));
2967         arpmatch.setArpOp(2);
2968         arpmatch.setArpSourceHardwareAddress(arpsrc.build());
2969         arpmatch.setArpTargetHardwareAddress(arpdst.build());
2970         arpmatch.setArpSourceTransportAddress(srcip);
2971         arpmatch.setArpTargetTransportAddress(dstip);
2972
2973         match.setEthernetMatch(ethmatch.build());
2974         match.setLayer3Match(arpmatch.build());
2975
2976         return match;
2977     }
2978
2979     /**
2980      * @return
2981      */
2982     private static MatchBuilder createIPMatch() {
2983         MatchBuilder match = new MatchBuilder();
2984         EthernetMatchBuilder ethmatch = new EthernetMatchBuilder();
2985         EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
2986         EtherType type = new EtherType(0x0800L);
2987         ethmatch.setEthernetType(ethtype.setType(type).build());
2988         match.setEthernetMatch(ethmatch.build());
2989
2990         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
2991         ipmatch.setIpProtocol((short) 1);
2992         Dscp dscp = new Dscp((short) 3);
2993         ipmatch.setIpDscp(dscp);
2994         ipmatch.setIpEcn((short) 2);
2995         match.setIpMatch(ipmatch.build());
2996         return match;
2997     }
2998
2999     /**
3000      * @return
3001      */
3002     private static MatchBuilder createL3IPv4Match() {
3003         MatchBuilder match = new MatchBuilder();
3004
3005         EthernetMatchBuilder eth = new EthernetMatchBuilder();
3006         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
3007         ethTypeBuilder.setType(new EtherType(0x0800L));
3008         eth.setEthernetType(ethTypeBuilder.build());
3009         match.setEthernetMatch(eth.build());
3010
3011         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
3012         Ipv4Prefix dstip = new Ipv4Prefix("200.71.9.52/10"); // ipv4 match
3013         Ipv4Prefix srcip = new Ipv4Prefix("100.1.1.1/8");
3014         Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
3015         ipv4match.setIpv4Destination(dstip);
3016         ipv4match.setIpv4Source(srcip);
3017         match.setLayer3Match(ipv4match.build());
3018
3019         return match;
3020
3021     }
3022
3023     /**
3024      * @return
3025      */
3026     private static MatchBuilder createL3IPv6Match() {
3027         MatchBuilder match = new MatchBuilder();
3028
3029         EthernetMatchBuilder eth = new EthernetMatchBuilder();
3030         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
3031         ethTypeBuilder.setType(new EtherType(0x86ddL));
3032         eth.setEthernetType(ethTypeBuilder.build());
3033         match.setEthernetMatch(eth.build());
3034
3035         Ipv6Prefix dstip6 = new Ipv6Prefix("2002::2/64");
3036         Ipv6Prefix srcip6 = new Ipv6Prefix("2001:0:0:0:0:0:0:1/56");
3037         Ipv6Address ndtarget = new Ipv6Address("2001:db8:0:1:fd97:f9f0:a810:782e");
3038         MacAddress ndsll = new MacAddress("c2:00:54:f5:00:00");
3039         MacAddress ndtll = new MacAddress("00:0c:29:0e:4c:67");
3040         Ipv6ExtHeaderBuilder nextheader = new Ipv6ExtHeaderBuilder();
3041         nextheader.setIpv6Exthdr(58);
3042         Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
3043         Ipv6FlowLabel label = new Ipv6FlowLabel(10028L);
3044         ipv6label.setIpv6Flabel(label);
3045         ipv6label.setFlabelMask(new Ipv6FlowLabel(1L));
3046
3047         Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
3048         // match
3049         icmpv6match.setIcmpv6Type((short) 135);
3050         icmpv6match.setIcmpv6Code((short) 0);
3051         match.setIcmpv6Match(icmpv6match.build());
3052
3053         Ipv6MatchBuilder ipv6match = new Ipv6MatchBuilder();
3054         // ipv6match.setIpv6Source(srcip6);
3055         // ipv6match.setIpv6Destination(dstip6);
3056         // ipv6match.setIpv6ExtHeader(nextheader.build());
3057         ipv6match.setIpv6NdSll(ndsll);
3058         ipv6match.setIpv6NdTll(ndtll);
3059         // ipv6match.setIpv6NdTarget(ndtarget);
3060         ipv6match.setIpv6Label(ipv6label.build());
3061
3062         match.setLayer3Match(ipv6match.build());
3063
3064         return match;
3065     }
3066
3067     /**
3068      * @return
3069      */
3070
3071     private static MatchBuilder createICMPv4Match() {
3072         MatchBuilder match = new MatchBuilder();
3073         EthernetMatchBuilder eth = new EthernetMatchBuilder();
3074         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
3075         ethTypeBuilder.setType(new EtherType(0x0800L));
3076         eth.setEthernetType(ethTypeBuilder.build());
3077         match.setEthernetMatch(eth.build());
3078
3079         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
3080         ipmatch.setIpProtocol((short) 1);
3081         match.setIpMatch(ipmatch.build());
3082
3083         Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder(); // icmpv4
3084         // match
3085         icmpv4match.setIcmpv4Type((short) 8);
3086         icmpv4match.setIcmpv4Code((short) 0);
3087         match.setIcmpv4Match(icmpv4match.build());
3088         return match;
3089     }
3090
3091     /**
3092      * @return
3093      */
3094     private static MatchBuilder createICMPv6Match() {
3095
3096         MatchBuilder match = new MatchBuilder();
3097         EthernetMatchBuilder eth = new EthernetMatchBuilder();
3098         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
3099         ethTypeBuilder.setType(new EtherType(0x86ddL));
3100         eth.setEthernetType(ethTypeBuilder.build());
3101         match.setEthernetMatch(eth.build());
3102
3103         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
3104         ipmatch.setIpProtocol((short) 58);
3105         match.setIpMatch(ipmatch.build());
3106
3107         Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
3108         // match
3109         icmpv6match.setIcmpv6Type((short) 135);
3110         icmpv6match.setIcmpv6Code((short) 1);
3111         match.setIcmpv6Match(icmpv6match.build());
3112
3113         return match;
3114     }
3115
3116     /**
3117      * @return
3118      */
3119     private static MatchBuilder createToSMatch() {
3120         MatchBuilder match = new MatchBuilder();
3121         EthernetMatchBuilder ethmatch = new EthernetMatchBuilder();
3122         EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
3123         EtherType type = new EtherType(0x0800L);
3124         ethmatch.setEthernetType(ethtype.setType(type).build());
3125         match.setEthernetMatch(ethmatch.build());
3126
3127         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
3128         ipmatch.setIpProtocol((short) 6);
3129         Dscp dscp = new Dscp((short) 8);
3130         ipmatch.setIpDscp(dscp);
3131         match.setIpMatch(ipmatch.build());
3132         return match;
3133     }
3134
3135     /**
3136      * @return
3137      */
3138
3139     private static MatchBuilder createL4TCPMatch() {
3140         MatchBuilder match = new MatchBuilder();
3141
3142         EthernetMatchBuilder eth = new EthernetMatchBuilder();
3143         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
3144         ethTypeBuilder.setType(new EtherType(0x0800L));
3145         eth.setEthernetType(ethTypeBuilder.build());
3146         match.setEthernetMatch(eth.build());
3147
3148         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
3149         ipmatch.setIpProtocol((short) 6);
3150         match.setIpMatch(ipmatch.build());
3151
3152         PortNumber srcport = new PortNumber(1213);
3153         PortNumber dstport = new PortNumber(646);
3154         TcpMatchBuilder tcpmatch = new TcpMatchBuilder(); // tcp match
3155         tcpmatch.setTcpSourcePort(srcport);
3156         tcpmatch.setTcpDestinationPort(dstport);
3157         match.setLayer4Match(tcpmatch.build());
3158
3159         return match;
3160     }
3161
3162     /**
3163      * @return
3164      */
3165     private static MatchBuilder createL4UDPMatch() {
3166         MatchBuilder match = new MatchBuilder();
3167
3168         EthernetMatchBuilder eth = new EthernetMatchBuilder();
3169         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
3170         ethTypeBuilder.setType(new EtherType(0x0800L));
3171         eth.setEthernetType(ethTypeBuilder.build());
3172         match.setEthernetMatch(eth.build());
3173
3174         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
3175         ipmatch.setIpProtocol((short) 17);
3176         match.setIpMatch(ipmatch.build());
3177
3178         PortNumber srcport = new PortNumber(1325);
3179         PortNumber dstport = new PortNumber(42);
3180         UdpMatchBuilder udpmatch = new UdpMatchBuilder(); // udp match
3181         udpmatch.setUdpDestinationPort(dstport);
3182         udpmatch.setUdpSourcePort(srcport);
3183         match.setLayer4Match(udpmatch.build());
3184
3185         return match;
3186     }
3187
3188     /**
3189      * @return
3190      */
3191     private static MatchBuilder createL4SCTPMatch() {
3192         MatchBuilder match = new MatchBuilder();
3193
3194         EthernetMatchBuilder eth = new EthernetMatchBuilder();
3195         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
3196         ethTypeBuilder.setType(new EtherType(0x0800L));
3197         eth.setEthernetType(ethTypeBuilder.build());
3198         match.setEthernetMatch(eth.build());
3199
3200         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
3201         ipmatch.setIpProtocol((short) 132);
3202         match.setIpMatch(ipmatch.build());
3203
3204         SctpMatchBuilder sctpmatch = new SctpMatchBuilder();
3205         PortNumber srcport = new PortNumber(1435);
3206         PortNumber dstport = new PortNumber(22);
3207         sctpmatch.setSctpSourcePort(srcport);
3208         sctpmatch.setSctpDestinationPort(dstport);
3209         match.setLayer4Match(sctpmatch.build());
3210
3211         return match;
3212     }
3213
3214     /**
3215      * @return
3216      */
3217     private static MatchBuilder createMetadataMatch() {
3218         MatchBuilder match = new MatchBuilder();
3219         byte[] metamask = new byte[]{(byte) -1, (byte) -1, (byte) -1, 0, 0, 0, (byte) 1, (byte) 1};
3220         MetadataBuilder metadata = new MetadataBuilder(); // metadata match
3221         metadata.setMetadata(BigInteger.valueOf(500L));
3222         metadata.setMetadataMask(new BigInteger(1, metamask));
3223         match.setMetadata(metadata.build());
3224
3225         return match;
3226     }
3227
3228     /**
3229      * @return
3230      */
3231     private static MatchBuilder createMplsMatch() {
3232         MatchBuilder match = new MatchBuilder();
3233
3234         EthernetMatchBuilder eth = new EthernetMatchBuilder();
3235         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
3236         ethTypeBuilder.setType(new EtherType(0x8847L));
3237         eth.setEthernetType(ethTypeBuilder.build());
3238         match.setEthernetMatch(eth.build());
3239
3240         ProtocolMatchFieldsBuilder protomatch = new ProtocolMatchFieldsBuilder(); // mpls
3241         // match
3242         protomatch.setMplsLabel((long) 36008);
3243         protomatch.setMplsTc((short) 4);
3244         protomatch.setMplsBos((short) 1);
3245         match.setProtocolMatchFields(protomatch.build());
3246
3247         return match;
3248
3249     }
3250
3251     /**
3252      * @return
3253      */
3254     private static MatchBuilder createPbbMatch() {
3255         MatchBuilder match = new MatchBuilder();
3256
3257         EthernetMatchBuilder eth = new EthernetMatchBuilder();
3258         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
3259         ethTypeBuilder.setType(new EtherType(0x88E7L));
3260         eth.setEthernetType(ethTypeBuilder.build());
3261         match.setEthernetMatch(eth.build());
3262
3263         ProtocolMatchFieldsBuilder protomatch = new ProtocolMatchFieldsBuilder(); // mpls
3264         // match
3265         protomatch.setPbb(new PbbBuilder().setPbbIsid(4L).setPbbMask(new BigInteger(new byte[]{0, 1, 0, 0}).longValue()).build());
3266         match.setProtocolMatchFields(protomatch.build());
3267
3268         return match;
3269
3270     }
3271
3272     /**
3273      * @return
3274      */
3275     private static MatchBuilder createTunnelIDMatch() {
3276         MatchBuilder match = new MatchBuilder();
3277         TunnelBuilder tunnel = new TunnelBuilder(); // tunnel id match
3278         tunnel.setTunnelId(BigInteger.valueOf(10668));
3279         byte[] mask = new byte[]{(byte) -1, (byte) -1, (byte) -1, 0, 0, 0, (byte) 1, (byte) 1};
3280         tunnel.setTunnelMask(new BigInteger(1, mask));
3281         match.setTunnel(tunnel.build());
3282
3283         return match;
3284     }
3285
3286     /**
3287      * Test match for TCP_Flags
3288      *
3289      * @return match containing Ethertype (0x0800), IP Protocol (TCP), TCP_Flag (SYN)
3290      */
3291     //FIXME: move to extensible support
3292     private static MatchBuilder createTcpFlagMatch() {
3293         MatchBuilder match = new MatchBuilder();
3294
3295         // Ethertype match
3296         EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
3297         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
3298         ethTypeBuilder.setType(new EtherType(0x0800L));
3299         ethernetType.setEthernetType(ethTypeBuilder.build());
3300         match.setEthernetMatch(ethernetType.build());
3301
3302         // TCP Protocol Match
3303         IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
3304         ipMatch.setIpProtocol((short) 6);
3305         match.setIpMatch(ipMatch.build());
3306
3307         // TCP Port Match
3308         PortNumber dstPort = new PortNumber(80);
3309         TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
3310         tcpMatch.setTcpDestinationPort(dstPort);
3311         match.setLayer4Match(tcpMatch.build());
3312         /**
3313          * Defined TCP Flag values in OVS v2.1+
3314          * TCP_FIN 0x001 / TCP_SYN 0x002 / TCP_RST 0x004
3315          * TCP_PSH 0x008 / TCP_ACK 0x010 / TCP_URG 0x020
3316          * TCP_ECE 0x040 / TCP_CWR 0x080 / TCP_NS  0x100
3317          */
3318         TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
3319         tcpFlagMatch.setTcpFlag(0x002);
3320         match.setTcpFlagMatch(tcpFlagMatch.build());
3321
3322         return match;
3323     }
3324
3325     public void _removeMDFlow(final CommandInterpreter ci) {
3326         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
3327         NodeBuilder tn = createTestNode(ci.nextArgument());
3328         String flowtype = ci.nextArgument();
3329         FlowBuilder tf;
3330         if (flowtype.equals("fTM")) {
3331             tf = createtablemiss(tn, flowtype, ci.nextArgument());
3332         } else {
3333             tf = createTestFlow(tn, flowtype, ci.nextArgument());
3334         }
3335         InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
3336                 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
3337                 .child(Flow.class, tf.getKey());
3338         modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
3339         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
3340         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
3341             @Override
3342             public void onSuccess(Void aVoid) {
3343                 ci.println("Status of Group Data Loaded Transaction: success.");
3344             }
3345
3346             @Override
3347             public void onFailure(Throwable throwable) {
3348                 LOG.error(throwable.getMessage(), throwable);
3349                 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
3350             }
3351         });
3352     }
3353
3354     /**
3355      * @param ci arguments: switchId flowType tableNum
3356      *           <p/>
3357      *           <pre>
3358      *                     e.g.: addMDFlow openflow:1 f1 42
3359      *                     </pre>
3360      */
3361     public void _addMDFlow(CommandInterpreter ci) {
3362         NodeBuilder tn = createTestNode(ci.nextArgument());
3363         String flowtype = ci.nextArgument();
3364         FlowBuilder tf;
3365         if (flowtype.equals("fTM")) {
3366             tf = createtablemiss(tn, flowtype, ci.nextArgument());
3367         } else {
3368             tf = createTestFlow(tn, flowtype, ci.nextArgument());
3369         }
3370         writeFlow(ci, tf, tn);
3371     }
3372
3373     private void writeFlow(final CommandInterpreter ci, FlowBuilder flow, NodeBuilder nodeBuilder) {
3374         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
3375         InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class)
3376                 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
3377                 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey());
3378         modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
3379         modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
3380         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
3381         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
3382             @Override
3383             public void onSuccess(Void aVoid) {
3384                 ci.println("Status of Group Data Loaded Transaction: success.");
3385             }
3386
3387             @Override
3388             public void onFailure(Throwable throwable) {
3389                 LOG.error(throwable.getMessage(), throwable);
3390                 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
3391             }
3392         });
3393     }
3394
3395     public void _modifyMDFlow(CommandInterpreter ci) {
3396         NodeBuilder tn = createTestNode(ci.nextArgument());
3397         FlowBuilder tf = createTestFlow(tn, ci.nextArgument(), ci.nextArgument());
3398         tf.setFlowName(updatedFlowName);
3399         writeFlow(ci, tf, tn);
3400         tf.setFlowName(originalFlowName);
3401         writeFlow(ci, tf, tn);
3402     }
3403
3404     private static NodeRef createNodeRef(String string) {
3405         NodeKey key = new NodeKey(new NodeId(string));
3406         InstanceIdentifier<Node> path = InstanceIdentifier.create(Nodes.class).child(Node.class, key);
3407
3408         return new NodeRef(path);
3409     }
3410
3411     @Override
3412     public String getHelp() {
3413         return "No help";
3414     }
3415
3416     /*
3417      * usage testSwitchFlows <numberOfSwitches> <numberOfFlows> <warmup iterations> <Number Of Threads>
3418      * ex: _perfFlowTest 10 5 1 2
3419      */
3420     public void _perfFlowTest(CommandInterpreter ci) {
3421
3422         String numberOfSwtichesStr = ci.nextArgument();
3423         String numberOfFlowsStr = ci.nextArgument();
3424         String warmupIterationsStr = ci.nextArgument();
3425         String threadCountStr = ci.nextArgument();
3426         String warmUpStr = ci.nextArgument();
3427
3428         Collection<String> testResults = null;
3429         if (testResults == null) {
3430             testResults = new ArrayList<String>();
3431         }
3432
3433         int numberOfSwtiches = 0;
3434         int numberOfFlows = 0;
3435         int warmupIterations = 0;
3436         boolean warmUpIterations = false;
3437
3438         int threadCount = 0;
3439         if (numberOfSwtichesStr != null && !numberOfSwtichesStr.trim().equals("")) {
3440             numberOfSwtiches = new Integer(numberOfSwtichesStr).intValue();
3441         } else {
3442             numberOfSwtiches = 2;
3443         }
3444
3445         if (numberOfFlowsStr != null && !numberOfFlowsStr.trim().equals("")) {
3446             numberOfFlows = new Integer(numberOfFlowsStr).intValue();
3447         } else {
3448             numberOfFlows = 2;
3449         }
3450
3451         if (warmupIterationsStr != null && !warmupIterationsStr.trim().equals("")) {
3452             warmupIterations = new Integer(warmupIterationsStr).intValue();
3453         } else {
3454             warmupIterations = 2;
3455         }
3456
3457         if (threadCountStr != null && !threadCountStr.trim().equals("")) {
3458             threadCount = new Integer(threadCountStr).intValue();
3459         } else {
3460             threadCount = 2;
3461         }
3462         if (warmUpStr != null && !warmUpStr.trim().equals("") && warmUpStr.trim().equals("true")) {
3463             warmUpIterations = true;
3464         } else {
3465             warmUpIterations = false;
3466         }
3467         ci.println("*     Test Configurations*");
3468         ci.println("*     numberOfSwtiches:::" + numberOfSwtiches + "");
3469         ci.println("*     numberOfFlows:::" + numberOfFlows + "");
3470         ci.println("*     warmupIterations:::" + warmupIterations + "");
3471         ci.println("*     Number of Threads :::" + threadCount + "");
3472         ci.println("*     Warmup Required? :::" + warmUpIterations + "");
3473
3474         String dataPath = "openflow:1";
3475         String flowType = "fTM";
3476         NodeBuilder tn;
3477         FlowBuilder tf;
3478         String tableId = "0";
3479         if (warmUpIterations) {
3480             ci.println("----Warmup Started-----");
3481             for (int j = 1; j <= warmupIterations; j++) {
3482                 for (int i = 1; i <= numberOfSwtiches; i++) {
3483                     dataPath = "openflow:" + i;
3484                     tn = createTestNode(dataPath);
3485                     for (int flow = 1; flow < numberOfFlows; flow++) {
3486                         tf = createTestFlow_perfTest(tn, "f1", tableId, flow);
3487                         writeFlow(ci, tf, tn);
3488                     }
3489                 }
3490             }
3491
3492             ci.println("----Warmup Done-----");
3493         }
3494         try {
3495             ExecutorService executor = Executors.newFixedThreadPool(threadCount);
3496             int flowID = 0;
3497             int tableID = 0;
3498             for (int t = 0; t < threadCount; t++) {
3499                 tableID = t + 1;
3500                 Runnable tRunnable = new TestFlowThread(numberOfSwtiches, numberOfFlows, ci, t, tableID);
3501                 executor.execute(tRunnable);
3502             }
3503             executor.shutdown();
3504             executor.awaitTermination(1, TimeUnit.SECONDS);
3505         } catch (Exception e) {
3506             ci.println("Exception:" + e.getMessage());
3507         }
3508     }
3509
3510     public class TestFlowThread implements Runnable {
3511
3512         int numberOfSwitches;
3513         int numberOfFlows;
3514         int testTime;
3515         CommandInterpreter ci;
3516         int testFlowsAdded;
3517         int theadNumber;
3518         Collection<String> testResults = null;
3519         int tableID = 0;
3520
3521         TestFlowThread(int numberOfSwtiches, int numberOfFlows, CommandInterpreter ci, int t, int tableID) {
3522             this.numberOfSwitches = numberOfSwtiches;
3523             this.numberOfFlows = numberOfFlows;
3524             this.ci = ci;
3525             this.theadNumber = t;
3526             this.tableID = tableID;
3527         }
3528
3529         @Override
3530         public void run() {
3531             executeFlow();
3532         }
3533
3534         public void executeFlow() {
3535
3536             String dataPath = "openflow:1";
3537             NodeBuilder tn;
3538             FlowBuilder tf;
3539             //String tableId = "0";
3540
3541             ci.println("New Thread started with id:  ID_"
3542                     + this.theadNumber);
3543             int totalNumberOfFlows = 0;
3544             long startTime = System.currentTimeMillis();
3545
3546             for (int i = 1; i <= this.numberOfSwitches; i++) {
3547                 dataPath = "openflow:" + i;
3548                 tn = createTestNode(dataPath);
3549                 for (int flow2 = 1; flow2 <= this.numberOfFlows; flow2++) {
3550                     tf = createTestFlow_perfTest(tn, "f1", "" + this.tableID, flow2);
3551                     writeFlow(this.ci, tf, tn);
3552                     totalNumberOfFlows++;
3553                 }
3554             }
3555             long endTime = System.currentTimeMillis();
3556             long timeInSeconds = Math.round((endTime - startTime) / 1000);
3557             if (timeInSeconds > 0) {
3558                 ci.println("Total flows added in Thread:" + this.theadNumber + ": Flows/Sec::" + Math.round(totalNumberOfFlows / timeInSeconds));
3559             } else {
3560                 ci.println("Total flows added in Thread:" + this.theadNumber + ": Flows/Sec::" + totalNumberOfFlows);
3561             }
3562         }
3563
3564     }
3565
3566     /*
3567      * usage testAllFlows <dp>
3568      * ex: _perfFlowTest 1
3569      */
3570     public void _testAllFlows(CommandInterpreter ci) {
3571         String dataPathID = ci.nextArgument();
3572         int numberOfFlows = 82;
3573         int threadCount = 0;
3574         if (dataPathID == null || dataPathID.trim().equals("")) {
3575             dataPathID = "1";
3576         }
3577         ci.println("*     Test All Flows        *");
3578         ci.println("*     dataPathID:::" + dataPathID + "");
3579         String dataPath = "openflow:" + dataPathID;
3580         String tableId = "0";
3581         NodeBuilder tn = createTestNode(dataPath);
3582         FlowBuilder tf;
3583         for (int flow = 1; flow < numberOfFlows; flow++) {
3584             String flowID = "f" + flow;
3585             try {
3586                 tf = createTestFlow(tn, flowID, tableId);
3587                 writeFlow(ci, tf, tn);
3588             } catch (Exception e) {
3589                 ci.println("--Test Failed--Issue found while adding flow" + flow);
3590                 break;
3591             }
3592         }
3593     }
3594 }