Migrate test-provider to CompositeListener
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTestCommandProvider.java
1 /*
2  * Copyright (c) 2013, 2015 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 package org.opendaylight.openflowplugin.test;
9
10 import com.google.common.util.concurrent.FutureCallback;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import java.util.concurrent.ExecutorService;
13 import java.util.concurrent.Executors;
14 import java.util.concurrent.TimeUnit;
15 import org.eclipse.osgi.framework.console.CommandInterpreter;
16 import org.eclipse.osgi.framework.console.CommandProvider;
17 import org.opendaylight.mdsal.binding.api.DataBroker;
18 import org.opendaylight.mdsal.binding.api.NotificationService;
19 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
20 import org.opendaylight.mdsal.common.api.CommitInfo;
21 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.VlanCfi;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodActionCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.HwPathActionCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.LoopbackActionCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlTypeActionCaseBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNextHopActionCaseBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCaseBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCaseBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanCfiActionCaseBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCaseBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.out._case.CopyTtlOutBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.mpls.ttl._case.DecMplsTtlBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.action._case.FloodActionBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.all.action._case.FloodAllActionBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.hw.path.action._case.HwPathActionBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.loopback.action._case.LoopbackActionBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstActionBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.type.action._case.SetDlTypeActionBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.next.hop.action._case.SetNextHopActionBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstActionBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcActionBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.cfi.action._case.SetVlanCfiActionBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.strip.vlan.action._case.StripVlanActionBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.sw.path.action._case.SwPathActionBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagsMatchBuilder;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
162 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
163 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
164 import org.opendaylight.yangtools.yang.common.Uint16;
165 import org.opendaylight.yangtools.yang.common.Uint32;
166 import org.opendaylight.yangtools.yang.common.Uint64;
167 import org.opendaylight.yangtools.yang.common.Uint8;
168 import org.osgi.framework.BundleContext;
169 import org.slf4j.Logger;
170 import org.slf4j.LoggerFactory;
171
172 public class OpenflowpluginTestCommandProvider implements CommandProvider {
173
174     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestCommandProvider.class);
175
176     private final DataBroker dataBroker;
177     private final BundleContext ctx;
178     private static final String ORIGINAL_FLOW_NAME = "Foo";
179     private static final String UPDATED_FLOW_NAME = "Bar";
180     private static final String IPV4_PREFIX = "10.0.0.1/24";
181     private static final String DEST_MAC_ADDRESS = "ff:ff:ff:ff:ff:ff";
182     private static final String SRC_MAC_ADDRESS = "00:00:00:00:23:ae";
183
184     private final NotificationService notificationService;
185
186     public OpenflowpluginTestCommandProvider(final DataBroker dataBroker, final NotificationService notificationService,
187             final BundleContext ctx) {
188         this.dataBroker = dataBroker;
189         this.notificationService = notificationService;
190         this.ctx = ctx;
191     }
192
193     public void init() {
194         // For switch events
195         notificationService.registerCompositeListener(FlowEventListenerLoggingImpl.newListener());
196
197         ctx.registerService(CommandProvider.class.getName(), this, null);
198         createTestFlow(createTestNode(null), null, null);
199     }
200
201     private static NodeBuilder createTestNode(final String nodeId) {
202         return new NodeBuilder().setId(new NodeId(nodeId != null ? nodeId : OpenflowpluginTestActivator.NODE_ID));
203     }
204
205     private static InstanceIdentifier<Node> nodeBuilderToInstanceId(final NodeBuilder node) {
206         return InstanceIdentifier.create(Nodes.class).child(Node.class, node.key());
207     }
208
209     private static FlowBuilder createTestFlow(final NodeBuilder nodeBuilder, final String flowTypeArg,
210             final String tableId) {
211         final long TEST_ID = 123;
212
213         long id = TEST_ID;
214
215         String flowType = flowTypeArg;
216         if (flowType == null) {
217             flowType = "f1";
218         }
219
220         final FlowBuilder flow = new FlowBuilder()
221             .setPriority(Uint16.TWO);
222
223         switch (flowType) {
224             case "f1":
225                 id += 1;
226                 flow.setMatch(createMatch1().build());
227                 flow.setInstructions(createDecNwTtlInstructions().build());
228                 break;
229             case "f2":
230                 id += 2;
231                 flow.setMatch(createMatch2().build());
232                 flow.setInstructions(createDropInstructions().build());
233                 break;
234             case "f3":
235                 id += 3;
236                 flow.setMatch(createMatch3().build());
237                 flow.setInstructions(createDropInstructions().build());
238                 break;
239             case "f4":
240                 id += 4;
241                 flow.setMatch(createEthernetMatch().build());
242                 flow.setInstructions(createDropInstructions().build());
243                 break;
244             case "f5":
245                 id += 5;
246                 flow.setMatch(createMatch1().build());
247                 flow.setInstructions(createAppyActionInstruction().build());
248                 break;
249             case "f6":
250                 id += 6;
251                 flow.setMatch(createMatch1().build());
252                 flow.setInstructions(createGotoTableInstructions().build());
253                 break;
254             case "f7":
255                 id += 7;
256                 flow.setMatch(createMatch1().build());
257                 flow.setInstructions(createMeterInstructions().build());
258                 break;
259             case "f8":
260                 id += 8;
261                 flow.setMatch(createMatch1().build());
262                 flow.setInstructions(createAppyActionInstruction1().build());
263                 break;
264             case "f9":
265                 id += 9;
266                 flow.setMatch(createMatch1().build());
267                 flow.setInstructions(createAppyActionInstruction2().build());
268                 break;
269             case "f10":
270                 id += 10;
271                 flow.setMatch(createMatch1().build());
272                 flow.setInstructions(createAppyActionInstruction3().build());
273                 break;
274             case "f11":
275                 id += 11;
276                 flow.setMatch(createMatch1().build());
277                 flow.setInstructions(createAppyActionInstruction4().build());
278                 break;
279             case "f12":
280                 id += 12;
281                 flow.setMatch(createMatch1().build());
282                 flow.setInstructions(createAppyActionInstruction5().build());
283                 break;
284             case "f13":
285                 id += 13;
286                 flow.setMatch(createMatch1().build());
287                 flow.setInstructions(createAppyActionInstruction6().build());
288                 break;
289             case "f14":
290                 id += 14;
291                 flow.setMatch(createMatch1().build());
292                 flow.setInstructions(createAppyActionInstruction7().build());
293                 break;
294             case "f15":
295                 id += 15;
296                 flow.setMatch(createMatch1().build());
297                 flow.setInstructions(createAppyActionInstruction8().build());
298                 break;
299             case "f16":
300                 id += 16;
301                 flow.setMatch(createMatch1().build());
302                 flow.setInstructions(createAppyActionInstruction9().build());
303                 break;
304             case "f17":
305                 id += 17;
306                 flow.setMatch(createMatch1().build());
307                 flow.setInstructions(createAppyActionInstruction10().build());
308                 break;
309             case "f18":
310                 id += 18;
311                 flow.setMatch(createMatch1().build());
312                 flow.setInstructions(createAppyActionInstruction11().build());
313                 break;
314             case "f19":
315                 id += 19;
316                 flow.setMatch(createMatch1().build());
317                 flow.setInstructions(createAppyActionInstruction12().build());
318                 break;
319             case "f20":
320                 id += 20;
321                 flow.setMatch(createMatch1().build());
322                 flow.setInstructions(createAppyActionInstruction13().build());
323                 break;
324             case "f21":
325                 id += 21;
326                 flow.setMatch(createMatch1().build());
327                 flow.setInstructions(createAppyActionInstruction14().build());
328                 break;
329             case "f22":
330                 id += 22;
331                 flow.setMatch(createMatch1().build());
332                 flow.setInstructions(createAppyActionInstruction15().build());
333                 break;
334             case "f23":
335                 id += 23;
336                 // f23 can be used as test-case for generating error notification
337                 // if the particular group is not configured - tested
338                 flow.setMatch(createMatch1().build());
339                 flow.setInstructions(createAppyActionInstruction16().build());
340                 break;
341             case "f24":
342                 id += 24;
343                 flow.setMatch(createMatch1().build());
344                 flow.setInstructions(createAppyActionInstruction17().build());
345                 break;
346             case "f25":
347                 id += 25;
348                 flow.setMatch(createMatch1().build());
349                 flow.setInstructions(createAppyActionInstruction18().build());
350                 break;
351             case "f26":
352                 id += 26;
353                 flow.setMatch(createMatch1().build());
354                 flow.setInstructions(createAppyActionInstruction19().build());
355                 break;
356             case "f27":
357                 id += 27;
358                 flow.setMatch(createMatch1().build());
359                 flow.setInstructions(createMetadataInstructions().build());
360                 break;
361             case "f28":
362                 id += 28;
363                 flow.setMatch(createMatch1().build());
364                 flow.setInstructions(createAppyActionInstruction20().build());
365                 break;
366             case "f29":
367                 id += 29;
368                 flow.setMatch(createMatch1().build());
369                 flow.setInstructions(createAppyActionInstruction21().build());
370                 break;
371             case "f30":
372                 id += 30;
373                 flow.setMatch(createMatch1().build());
374                 flow.setInstructions(createAppyActionInstruction22().build());
375                 break;
376             case "f31":
377                 id += 31;
378                 flow.setMatch(createMatch1().build());
379                 flow.setInstructions(createAppyActionInstruction23(nodeBuilder.getId()).build());
380                 break;
381             case "f32":
382                 id += 32;
383                 flow.setMatch(createMatch1().build());
384                 flow.setInstructions(createAppyActionInstruction24().build());
385                 break;
386             case "f33":
387                 id += 33;
388                 flow.setMatch(createMatch1().build());
389                 flow.setInstructions(createAppyActionInstruction25().build());
390                 break;
391             case "f34":
392                 id += 34;
393                 flow.setMatch(createMatch1().build());
394                 flow.setInstructions(createAppyActionInstruction26().build());
395                 break;
396             case "f35":
397                 id += 35;
398                 flow.setMatch(createMatch1().build());
399                 flow.setInstructions(createAppyActionInstruction27().build());
400                 break;
401             case "f36":
402                 id += 36;
403                 flow.setMatch(createMatch1().build());
404                 flow.setInstructions(createAppyActionInstruction28().build());
405                 break;
406             case "f37":
407                 id += 37;
408                 flow.setMatch(createMatch1().build());
409                 flow.setInstructions(createAppyActionInstruction29().build());
410                 break;
411             case "f38":
412                 id += 38;
413                 flow.setMatch(createMatch1().build());
414                 flow.setInstructions(createAppyActionInstruction30().build());
415                 break;
416             case "f39":
417                 id += 39;
418                 flow.setMatch(createMatch1().build());
419                 flow.setInstructions(createAppyActionInstruction31().build());
420                 break;
421             case "f40":
422                 id += 40;
423                 flow.setMatch(createMatch1().build());
424                 flow.setInstructions(createAppyActionInstruction32().build());
425                 break;
426             case "f41":
427                 id += 41;
428                 flow.setMatch(createMatch1().build());
429                 flow.setInstructions(createAppyActionInstruction33().build());
430                 break;
431             case "f42":
432                 id += 42;
433                 flow.setMatch(createMatch1().build());
434                 flow.setInstructions(createAppyActionInstruction34().build());
435                 break;
436             case "f43":
437                 id += 43;
438                 flow.setMatch(createICMPv6Match().build());
439                 flow.setInstructions(createDecNwTtlInstructions().build());
440                 break;
441             case "f44":
442                 id += 44;
443                 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
444                 flow.setInstructions(createDropInstructions().build());
445                 break;
446             case "f45":
447                 id += 45;
448                 flow.setMatch(createMetadataMatch().build());
449                 flow.setInstructions(createDropInstructions().build());
450                 break;
451             case "f46":
452                 id += 46;
453                 flow.setMatch(createL3IPv6Match().build());
454                 flow.setInstructions(createDecNwTtlInstructions().build());
455                 break;
456             case "f47":
457                 id += 47;
458                 flow.setMatch(createL4SCTPMatch().build());
459                 flow.setInstructions(createAppyActionInstruction().build());
460                 break;
461             case "f48":
462                 id += 48;
463                 flow.setMatch(createTunnelIDMatch().build());
464                 flow.setInstructions(createGotoTableInstructions().build());
465                 break;
466             case "f49":
467                 id += 49;
468                 flow.setMatch(createVlanMatch().build());
469                 flow.setInstructions(createMeterInstructions().build());
470                 break;
471             case "f50":
472                 id += 50;
473                 flow.setMatch(createPbbMatch().build());
474                 flow.setInstructions(createMeterInstructions().build());
475                 break;
476             case "f51":
477                 id += 51;
478                 flow.setMatch(createVlanMatch().build());
479                 flow.setInstructions(createDropInstructions().build());
480                 break;
481             case "f52":
482                 id += 52;
483                 flow.setMatch(createL4TCPMatch().build());
484                 flow.setInstructions(createDropInstructions().build());
485                 break;
486
487             case "f53":
488                 id += 53;
489                 flow.setMatch(createL4UDPMatch().build());
490                 flow.setInstructions(createDropInstructions().build());
491                 break;
492             case "f54":
493                 id += 54;
494                 flow.setMatch(new MatchBuilder().build());
495                 flow.setInstructions(createSentToControllerInstructions().build());
496                 flow.setPriority(Uint16.ZERO);
497                 break;
498             case "f55":
499                 id += 55;
500                 flow.setMatch(createToSMatch().build());
501                 flow.setInstructions(createDropInstructions().build());
502                 break;
503             case "f56":
504                 id += 56;
505                 flow.setMatch(createToSMatch().build());
506                 flow.setInstructions(createOutputInstructions("INPORT", Uint16.TEN).build());
507                 break;
508             case "f57":
509                 id += 57;
510                 flow.setMatch(createToSMatch().build());
511                 flow.setInstructions(createOutputInstructions("FLOOD", Uint16.valueOf(20)).build());
512                 break;
513             case "f58":
514                 id += 58;
515                 flow.setMatch(createToSMatch().build());
516                 flow.setInstructions(createOutputInstructions("ALL", Uint16.valueOf(30)).build());
517                 break;
518             case "f59":
519                 id += 59;
520                 flow.setMatch(createToSMatch().build());
521                 flow.setInstructions(createOutputInstructions("NORMAL", Uint16.valueOf(40)).build());
522                 break;
523             case "f60":
524                 id += 60;
525                 flow.setMatch(createToSMatch().build());
526                 flow.setInstructions(createOutputInstructions("LOCAL", Uint16.valueOf(50)).build());
527                 break;
528             case "f61":
529                 id += 61;
530                 flow.setMatch(createToSMatch().build());
531                 flow.setInstructions(createOutputInstructions("TABLE", Uint16.valueOf(60)).build());
532                 break;
533             case "f62":
534                 id += 62;
535                 flow.setMatch(createToSMatch().build());
536                 flow.setInstructions(createOutputInstructions("NONE", Uint16.valueOf(70)).build());
537                 break;
538             case "f63":
539                 id += 63;
540                 flow.setMatch(createToSMatch().build());
541                 flow.setInstructions(createStripVlanInstructions().build());
542                 flow.setBarrier(Boolean.TRUE);
543                 break;
544             case "f64":
545                 id += 64;
546                 flow.setMatch(createMatch1().build());
547                 flow.setInstructions(createAppyActionInstruction35().build());
548                 break;
549             case "f65":
550                 id += 65;
551                 flow.setMatch(createMatch1().build());
552                 flow.setInstructions(createAppyActionInstruction36().build());
553                 break;
554             case "f66":
555                 id += 66;
556                 flow.setMatch(createMatch1().build());
557                 flow.setInstructions(createAppyActionInstruction37().build());
558                 break;
559             case "f67":
560                 id += 67;
561                 flow.setMatch(createMatch1().build());
562                 flow.setInstructions(createAppyActionInstruction38().build());
563                 break;
564             case "f68":
565                 id += 68;
566                 flow.setMatch(createL4TCPMatch().build());
567                 flow.setInstructions(createAppyActionInstruction39().build());
568                 break;
569             case "f69":
570                 id += 69;
571                 flow.setMatch(createL4UDPMatch().build());
572                 flow.setInstructions(createAppyActionInstruction40().build());
573                 break;
574             case "f70":
575                 id += 70;
576                 flow.setMatch(createL4SCTPMatch().build());
577                 flow.setInstructions(createAppyActionInstruction41().build());
578                 break;
579             case "f71":
580                 id += 71;
581                 flow.setMatch(createICMPv4Match().build());
582                 flow.setInstructions(createAppyActionInstruction42().build());
583                 break;
584             case "f72":
585                 id += 72;
586                 flow.setMatch(createArpMatch().build());
587                 flow.setInstructions(createAppyActionInstruction43().build());
588                 break;
589             case "f73":
590                 id += 73;
591                 flow.setMatch(createL3IPv6Match().build());
592                 flow.setInstructions(createAppyActionInstruction44().build());
593                 break;
594             case "f74":
595                 id += 74;
596                 flow.setMatch(createICMPv6Match().build());
597                 flow.setInstructions(createAppyActionInstruction45().build());
598                 break;
599             case "f75":
600                 id += 75;
601                 flow.setMatch(createMplsMatch().build());
602                 flow.setInstructions(createAppyActionInstruction46().build());
603                 break;
604             case "f76":
605                 id += 76;
606                 flow.setMatch(createPbbMatch().build());
607                 flow.setInstructions(createAppyActionInstruction47().build());
608                 break;
609             case "f77":
610                 id += 77;
611                 flow.setMatch(createTunnelIDMatch().build());
612                 flow.setInstructions(createAppyActionInstruction48().build());
613                 break;
614             case "f78":
615                 id += 78;
616                 flow.setMatch(createMatch33().build());
617                 flow.setInstructions(createDropInstructions().build());
618                 break;
619             case "f79":
620                 id += 79;
621                 flow.setMatch(createICMPv6Match1().build());
622                 flow.setInstructions(createDecNwTtlInstructions().build());
623                 break;
624             case "f80":
625                 id += 80;
626                 flow.setMatch(createVlanMatch().build());
627                 flow.setInstructions(createAppyActionInstruction88().build());
628                 break;
629             case "f81":
630                 id += 81;
631                 flow.setMatch(createLLDPMatch().build());
632                 flow.setInstructions(createSentToControllerInstructions().build());
633                 break;
634             case "f82":
635                 id += 82;
636                 flow.setMatch(createToSMatch().build());
637                 flow.setInstructions(createOutputInstructions().build());
638                 break;
639             case "f83":
640                 // Test TCP_Flag Match
641                 id += 83;
642                 flow.setMatch(createTcpFlagMatch().build());
643                 flow.setInstructions(createDropInstructions().build());
644                 break;
645             case "f84":
646                 id += 84;
647                 // match vlan=10,dl_vlan_pcp=3
648                 flow.setMatch(createVlanMatch().build());
649                 // vlan_pcp=4
650                 flow.setInstructions(createAppyActionInstruction88().build());
651                 break;
652             case "f85":
653                 // Test Tunnel IPv4 Src (e.g. set_field:172.16.100.200->tun_src)
654                 id += 85;
655                 flow.setMatch(createMatch3().build());
656                 flow.setInstructions(createTunnelIpv4SrcInstructions().build());
657                 break;
658             case "f86":
659                 // Test Tunnel IPv4 Dst (e.g. set_field:172.16.100.100->tun_dst)
660                 id += 86;
661                 flow.setMatch(createMatch1().build());
662                 flow.setInstructions(createTunnelIpv4DstInstructions().build());
663                 break;
664             default:
665                 LOG.warn("flow type not understood: {}", flowType);
666         }
667
668         if (flow.getBarrier() == null) {
669             flow.setBarrier(Boolean.FALSE);
670         }
671
672         return flow
673             .setCookie(new FlowCookie(Uint64.TEN))
674             .setCookieMask(new FlowCookie(Uint64.TEN))
675             .setHardTimeout(Uint16.ZERO)
676             .setIdleTimeout(Uint16.ZERO)
677             .setInstallHw(false)
678             .setStrict(false)
679             .setContainerName(null)
680             .setFlags(new FlowModFlags(false, false, false, false, true))
681             .setId(new FlowId("12"))
682             .setTableId(getTableId(tableId))
683             .withKey(new FlowKey(new FlowId(Long.toString(id))))
684             .setFlowName(ORIGINAL_FLOW_NAME + "X" + flowType);
685     }
686
687     private static FlowBuilder createTestFlowPerfTest(final String flowTypeArg, final String tableId, final int id) {
688         String flowType = flowTypeArg;
689         int flowId = id;
690
691         if (flowType == null) {
692             flowType = "f1";
693         }
694
695         final FlowBuilder flow = new FlowBuilder()
696             .setPriority(Uint16.valueOf(flowId));
697
698         switch (flowType) {
699             case "f1":
700                 flowId += 1;
701                 flow.setMatch(createMatch1().build());
702                 flow.setInstructions(createDecNwTtlInstructions().build());
703                 break;
704             default:
705                 LOG.warn("flow type not understood: {}", flowType);
706         }
707
708         if (flow.getBarrier() == null) {
709             flow.setBarrier(Boolean.FALSE);
710         }
711
712         return flow
713             .setCookie(new FlowCookie(Uint64.TEN))
714             .setCookieMask(new FlowCookie(Uint64.TEN))
715             .setHardTimeout(Uint16.ZERO)
716             .setIdleTimeout(Uint16.ZERO)
717             .setInstallHw(false)
718             .setStrict(false)
719             .setContainerName(null)
720             .setFlags(new FlowModFlags(false, false, false, false, true))
721             .setId(new FlowId("12"))
722             .setTableId(getTableId(tableId))
723             .withKey(new FlowKey(new FlowId(Long.toString(flowId))))
724             .setFlowName(ORIGINAL_FLOW_NAME + "X" + flowType);
725     }
726
727     private static FlowBuilder createtablemiss() {
728         return new FlowBuilder()
729             .setMatch(new MatchBuilder().build())
730             .setInstructions(createSentToControllerInstructions().build())
731             .setPriority(Uint16.ZERO)
732             .setTableId(Uint8.ZERO)
733             .withKey(new FlowKey(new FlowId("456")));
734     }
735
736     private static Uint8 getTableId(final String tableId) {
737         Uint8 table = Uint8.TWO;
738
739         if (tableId == null) {
740             return table;
741         }
742
743         try {
744             table = Uint8.valueOf(tableId);
745         } catch (NumberFormatException ex) {
746             LOG.info("Parsing String tableId {} failed. Continuing with default tableId {}.",
747                     tableId, table);
748         }
749         return table;
750     }
751
752     private static InstructionsBuilder createDecNwTtlInstructions() {
753         return new InstructionsBuilder()
754             .setInstruction(BindingMap.of(new InstructionBuilder()
755                 .setOrder(0)
756                 .setInstruction(new ApplyActionsCaseBuilder()
757                     .setApplyActions(new ApplyActionsBuilder()
758                         .setAction(BindingMap.of(new ActionBuilder()
759                             .setOrder(0)
760                             .setAction(new DecNwTtlCaseBuilder().setDecNwTtl(new DecNwTtlBuilder().build()).build())
761                             .build()))
762                         .build())
763                     .build())
764                 .build()));
765     }
766
767     private static InstructionsBuilder createMeterInstructions() {
768         return new InstructionsBuilder()
769             .setInstruction(BindingMap.of(new InstructionBuilder()
770                 .setOrder(0)
771                 .setInstruction(new MeterCaseBuilder()
772                     .setMeter(new MeterBuilder().setMeterId(new MeterId(Uint32.ONE)).build())
773                     .build())
774                 .build()));
775     }
776
777     private static InstructionsBuilder createMetadataInstructions() {
778         return new InstructionsBuilder()
779             .setInstruction(BindingMap.of(new InstructionBuilder()
780                 .withKey(new InstructionKey(0))
781                 .setInstruction(new WriteMetadataCaseBuilder()
782                     .setWriteMetadata(new WriteMetadataBuilder()
783                         .setMetadata(Uint64.TEN).setMetadataMask(Uint64.TEN)
784                         .build())
785                     .build())
786                 .build()));
787     }
788
789     private static InstructionsBuilder createGotoTableInstructions() {
790         return new InstructionsBuilder()
791             .setInstruction(BindingMap.of(new InstructionBuilder()
792                 .setOrder(0)
793                 .setInstruction(new GoToTableCaseBuilder()
794                     .setGoToTable(new GoToTableBuilder().setTableId(Uint8.valueOf(5)).build())
795                     .build())
796                 .build()));
797     }
798
799     private static InstructionsBuilder createDropInstructions() {
800         // Wrap our Apply Action in an Instruction
801         return new InstructionsBuilder()
802             .setInstruction(BindingMap.of(new InstructionBuilder()
803                 .setOrder(0)
804                 .setInstruction(new ApplyActionsCaseBuilder()
805                     .setApplyActions(new ApplyActionsBuilder()
806                         .setAction(BindingMap.of(new ActionBuilder()
807                             .withKey(new ActionKey(0))
808                             .setAction(new DropActionCaseBuilder()
809                                 .setDropAction(new DropActionBuilder().build())
810                                 .build())
811                             .build()))
812                         .build())
813                     .build())
814                 .build()));
815     }
816
817     private static InstructionsBuilder createAppyActionInstruction() {
818         return new InstructionsBuilder()
819             .setInstruction(BindingMap.of(new InstructionBuilder()
820                 .setOrder(0)
821                 .setInstruction(new ApplyActionsCaseBuilder()
822                     .setApplyActions(new ApplyActionsBuilder()
823                         .setAction(BindingMap.of(new ActionBuilder()
824                             .setOrder(0)
825                             .setAction(new ControllerActionCaseBuilder()
826                                 .setControllerAction(new ControllerActionBuilder()
827                                     .setMaxLength(Uint16.valueOf(5))
828                                     .build())
829                                 .build())
830                             .build()))
831                         .build())
832                     .build())
833                 .build()));
834     }
835
836     private static InstructionsBuilder createAppyActionInstruction1() {
837         return new InstructionsBuilder()
838             .setInstruction(BindingMap.of(new InstructionBuilder()
839                 .setOrder(0)
840                 .setInstruction(new ApplyActionsCaseBuilder()
841                     .setApplyActions(new ApplyActionsBuilder()
842                         .setAction(BindingMap.of(new ActionBuilder()
843                             .setOrder(0)
844                             .setAction(new OutputActionCaseBuilder()
845                                 .setOutputAction(new OutputActionBuilder()
846                                     .setMaxLength(Uint16.valueOf(56))
847                                     .setOutputNodeConnector(new Uri("PCEP"))
848                                     .build())
849                                 .build())
850                             .build()))
851                         .build())
852                     .build())
853                 .build()));
854     }
855
856     private static InstructionsBuilder createOutputInstructions() {
857         // test case for Output Port works if the particular port exists
858         // this particular test-case is for Port : 1
859         // tested as (addMDFlow openflow:<dpid> f82)
860         return new InstructionsBuilder()
861             .setInstruction(BindingMap.of(new InstructionBuilder()
862                 .setOrder(0)
863                 .setInstruction(new ApplyActionsCaseBuilder()
864                     .setApplyActions(new ApplyActionsBuilder()
865                         .setAction(BindingMap.of(new ActionBuilder()
866                             .setOrder(0)
867                             .setAction(new OutputActionCaseBuilder()
868                                 .setOutputAction(new OutputActionBuilder().setOutputNodeConnector(new Uri("1")).build())
869                                 .build())
870                             .build()))
871                         .build())
872                     .build())
873                 .build()));
874     }
875
876     private static InstructionsBuilder createOutputInstructions(final String outputType, final Uint16 outputValue) {
877         return new InstructionsBuilder()
878             .setInstruction(BindingMap.of(new InstructionBuilder()
879                 .setOrder(0)
880                 .setInstruction(new ApplyActionsCaseBuilder()
881                     .setApplyActions(new ApplyActionsBuilder()
882                         .setAction(BindingMap.of(new ActionBuilder()
883                             .setOrder(0)
884                             .setAction(new OutputActionCaseBuilder()
885                                 .setOutputAction(new OutputActionBuilder()
886                                     .setMaxLength(outputValue)
887                                     .setOutputNodeConnector(new Uri(outputType))
888                                     .build())
889                                 .build())
890                             .build()))
891                         .build())
892                     .build())
893                 .build()));
894     }
895
896     private static InstructionsBuilder createSentToControllerInstructions() {
897         return new InstructionsBuilder()
898             .setInstruction(BindingMap.of(new InstructionBuilder()
899                 .setOrder(0)
900                 .setInstruction(new ApplyActionsCaseBuilder()
901                     .setApplyActions(new ApplyActionsBuilder()
902                         .setAction(BindingMap.of(new ActionBuilder()
903                             .setOrder(0)
904                             .setAction(new OutputActionCaseBuilder()
905                                 .setOutputAction(new OutputActionBuilder()
906                                     .setMaxLength(Uint16.MAX_VALUE)
907                                     .setOutputNodeConnector(new Uri(OutputPortValues.CONTROLLER.toString()))
908                                     .build())
909                                 .build())
910                             .build()))
911                         .build())
912                     .build())
913                 .build()));
914     }
915
916     private static InstructionsBuilder createStripVlanInstructions() {
917         return new InstructionsBuilder()
918             .setInstruction(BindingMap.of(new InstructionBuilder()
919                 .setOrder(0)
920                 .setInstruction(new ApplyActionsCaseBuilder()
921                     .setApplyActions(new ApplyActionsBuilder()
922                         .setAction(BindingMap.of(new ActionBuilder()
923                             .setOrder(0)
924                             .setAction(new StripVlanActionCaseBuilder()
925                                 .setStripVlanAction(new StripVlanActionBuilder().build())
926                                 .build())
927                             .build()))
928                         .build())
929                     .build())
930                 .build()));
931     }
932
933     private static InstructionsBuilder createAppyActionInstruction2() {
934         return new InstructionsBuilder()
935             .setInstruction(BindingMap.of(new InstructionBuilder()
936                 .setOrder(0)
937                 .setInstruction(new ApplyActionsCaseBuilder()
938                     .setApplyActions(new ApplyActionsBuilder()
939                         .setAction(BindingMap.of(new ActionBuilder()
940                             .setOrder(0)
941                             .setAction(new PushMplsActionCaseBuilder()
942                                 .setPushMplsAction(new PushMplsActionBuilder()
943                                     .setEthernetType(Uint16.valueOf(0x8847))
944                                     .build())
945                                 .build())
946                             .build()))
947                         .build())
948                     .build())
949                 .build()));
950     }
951
952     private static InstructionsBuilder createAppyActionInstruction3() {
953         return new InstructionsBuilder()
954             .setInstruction(BindingMap.of(new InstructionBuilder()
955                 .setOrder(0)
956                 .setInstruction(new ApplyActionsCaseBuilder()
957                     .setApplyActions(new ApplyActionsBuilder()
958                         .setAction(BindingMap.of(new ActionBuilder()
959                             .setOrder(0)
960                             .setAction(new PushPbbActionCaseBuilder()
961                                 .setPushPbbAction(new PushPbbActionBuilder()
962                                     .setEthernetType(Uint16.valueOf(0x88E7))
963                                     .build())
964                                 .build())
965                             .build()))
966                         .build())
967                     .build())
968                 .build()));
969     }
970
971     private static InstructionsBuilder createAppyActionInstruction4() {
972         return new InstructionsBuilder()
973             .setInstruction(BindingMap.of(new InstructionBuilder()
974                 .setOrder(0)
975                 .setInstruction(new ApplyActionsCaseBuilder()
976                     .setApplyActions(new ApplyActionsBuilder()
977                         .setAction(BindingMap.of(new ActionBuilder()
978                             .setOrder(0)
979                             .setAction(new PushVlanActionCaseBuilder()
980                                 .setPushVlanAction(new PushVlanActionBuilder()
981                                     .setEthernetType(Uint16.valueOf(0x8100))
982                                     .build())
983                                 .build())
984                             .build()))
985                         .build())
986                     .build())
987                 .build()));
988     }
989
990     private static InstructionsBuilder createAppyActionInstruction5() {
991         return new InstructionsBuilder()
992             .setInstruction(BindingMap.of(new InstructionBuilder()
993                 .setOrder(0)
994                 .setInstruction(new ApplyActionsCaseBuilder()
995                     .setApplyActions(new ApplyActionsBuilder()
996                         .setAction(BindingMap.of(new ActionBuilder()
997                             .setOrder(0)
998                             .setAction(new SetDlDstActionCaseBuilder()
999                                 .setSetDlDstAction(new SetDlDstActionBuilder()
1000                                     .setAddress(new MacAddress("00:05:b9:7c:81:5f"))
1001                                     .build())
1002                                 .build())
1003                             .build()))
1004                         .build())
1005                     .build())
1006                 .build()));
1007     }
1008
1009     private static InstructionsBuilder createAppyActionInstruction6() {
1010         return new InstructionsBuilder()
1011             .setInstruction(BindingMap.of(new InstructionBuilder()
1012                 .setOrder(0)
1013                 .setInstruction(new ApplyActionsCaseBuilder()
1014                     .setApplyActions(new ApplyActionsBuilder().setAction(BindingMap.of(new ActionBuilder()
1015                         .setOrder(0)
1016                         .setAction(new SetDlSrcActionCaseBuilder()
1017                             .setSetDlSrcAction(new SetDlSrcActionBuilder()
1018                                 .setAddress(new MacAddress("00:05:b9:7c:81:5f"))
1019                                 .build())
1020                             .build()).build()))
1021                         .build())
1022                     .build())
1023                 .build()));
1024     }
1025
1026     private static InstructionsBuilder createAppyActionInstruction7() {
1027         return new InstructionsBuilder()
1028             .setInstruction(BindingMap.of(new InstructionBuilder()
1029                 .setOrder(0)
1030                 .setInstruction(new ApplyActionsCaseBuilder()
1031                     .setApplyActions(new ApplyActionsBuilder()
1032                         .setAction(BindingMap.of(new ActionBuilder()
1033                             .setOrder(0)
1034                             .setAction(new SetVlanIdActionCaseBuilder()
1035                                 .setSetVlanIdAction(new SetVlanIdActionBuilder()
1036                                     .setVlanId(new VlanId(Uint16.valueOf(4000))).build())
1037                                 .build())
1038                             .build()))
1039                         .build())
1040                     .build())
1041                 .build()));
1042     }
1043
1044     private static InstructionsBuilder createAppyActionInstruction8() {
1045         return new InstructionsBuilder()
1046             .setInstruction(BindingMap.of(new InstructionBuilder()
1047                 .setOrder(0)
1048                 .setInstruction(new ApplyActionsCaseBuilder()
1049                     .setApplyActions(new ApplyActionsBuilder()
1050                         .setAction(BindingMap.of(new ActionBuilder()
1051                             .setOrder(0)
1052                             .setAction(new SetVlanPcpActionCaseBuilder()
1053                                 .setSetVlanPcpAction(new SetVlanPcpActionBuilder()
1054                                     .setVlanPcp(new VlanPcp(Uint8.TWO))
1055                                     .build())
1056                                 .build())
1057                             .build()))
1058                         .build())
1059                     .build())
1060                 .build()));
1061     }
1062
1063     private static InstructionsBuilder createAppyActionInstruction88() {
1064         return new InstructionsBuilder()
1065             .setInstruction(BindingMap.of(new InstructionBuilder()
1066                 .setOrder(0)
1067                 .setInstruction(new ApplyActionsCaseBuilder()
1068                     .setApplyActions(new ApplyActionsBuilder()
1069                         .setAction(BindingMap.of(new ActionBuilder()
1070                             .setOrder(0)
1071                             .setAction(new SetVlanPcpActionCaseBuilder()
1072                                 .setSetVlanPcpAction(new SetVlanPcpActionBuilder()
1073                                     // the code point is a 3-bit(0-7) field representing the frame priority level
1074                                     .setVlanPcp(new VlanPcp(Uint8.valueOf(4)))
1075                                     .build())
1076                                 .build())
1077                             .build()))
1078                         .build())
1079                     .build())
1080                 .build()));
1081     }
1082
1083     private static InstructionsBuilder createAppyActionInstruction9() {
1084         return new InstructionsBuilder()
1085             .setInstruction(BindingMap.of(new InstructionBuilder()
1086                 .setOrder(0)
1087                 .setInstruction(new ApplyActionsCaseBuilder()
1088                     .setApplyActions(new ApplyActionsBuilder()
1089                         .setAction(BindingMap.of(new ActionBuilder()
1090                             .setOrder(0)
1091                             .setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(new CopyTtlInBuilder().build()).build())
1092                             .build()))
1093                         .build())
1094                     .build())
1095                 .build()));
1096     }
1097
1098     private static InstructionsBuilder createAppyActionInstruction10() {
1099         return new InstructionsBuilder()
1100             .setInstruction(BindingMap.of(new InstructionBuilder()
1101                 .setOrder(0)
1102                 .setInstruction(new ApplyActionsCaseBuilder()
1103                     .setApplyActions(new ApplyActionsBuilder()
1104                         .setAction(BindingMap.of(new ActionBuilder()
1105                             .setOrder(0)
1106                             .setAction(new CopyTtlOutCaseBuilder()
1107                                 .setCopyTtlOut(new CopyTtlOutBuilder().build())
1108                                 .build())
1109                             .build()))
1110                         .build())
1111                     .build())
1112                 .build()));
1113     }
1114
1115     private static InstructionsBuilder createAppyActionInstruction11() {
1116         return new InstructionsBuilder()
1117             .setInstruction(BindingMap.of(new InstructionBuilder()
1118                 .setOrder(0)
1119                 .setInstruction(new ApplyActionsCaseBuilder()
1120                     .setApplyActions(new ApplyActionsBuilder()
1121                         .setAction(BindingMap.of(new ActionBuilder()
1122                             .setOrder(0)
1123                             .setAction(new DecMplsTtlCaseBuilder()
1124                                 .setDecMplsTtl(new DecMplsTtlBuilder().build())
1125                                 .build())
1126                             .build()))
1127                         .build())
1128                     .build())
1129                 .build()));
1130     }
1131
1132     private static InstructionsBuilder createAppyActionInstruction12() {
1133         return new InstructionsBuilder()
1134             .setInstruction(BindingMap.of(new InstructionBuilder()
1135                 .setOrder(0)
1136                 .setInstruction(new ApplyActionsCaseBuilder()
1137                     .setApplyActions(new ApplyActionsBuilder()
1138                         .setAction(BindingMap.of(new ActionBuilder()
1139                             .setOrder(0)
1140                             .setAction(new DecNwTtlCaseBuilder().setDecNwTtl(new DecNwTtlBuilder().build()).build())
1141                             .build()))
1142                         .build())
1143                     .build())
1144                 .build()));
1145     }
1146
1147     private static InstructionsBuilder createAppyActionInstruction13() {
1148         return new InstructionsBuilder()
1149             .setInstruction(BindingMap.of(new InstructionBuilder()
1150                 .setOrder(0)
1151                 .setInstruction(new ApplyActionsCaseBuilder()
1152                     .setApplyActions(new ApplyActionsBuilder()
1153                         .setAction(BindingMap.of(new ActionBuilder()
1154                             .setOrder(0)
1155                             .setAction(new DropActionCaseBuilder()
1156                                 .setDropAction(new DropActionBuilder().build())
1157                                 .build())
1158                             .build()))
1159                         .build())
1160                     .build())
1161                 .build()));
1162     }
1163
1164     private static InstructionsBuilder createAppyActionInstruction14() {
1165         return new InstructionsBuilder()
1166             .setInstruction(BindingMap.of(new InstructionBuilder()
1167                 .setOrder(0)
1168                 .setInstruction(new ApplyActionsCaseBuilder()
1169                     .setApplyActions(new ApplyActionsBuilder()
1170                         .setAction(BindingMap.of(new ActionBuilder()
1171                             .setOrder(0)
1172                             .setAction(new FloodActionCaseBuilder()
1173                                 .setFloodAction(new FloodActionBuilder().build())
1174                                 .build())
1175                             .build()))
1176                         .build())
1177                     .build())
1178                 .build()));
1179     }
1180
1181     private static InstructionsBuilder createAppyActionInstruction15() {
1182         return new InstructionsBuilder()
1183             .setInstruction(BindingMap.of(new InstructionBuilder()
1184                 .setOrder(0)
1185                 .setInstruction(new ApplyActionsCaseBuilder()
1186                     .setApplyActions(new ApplyActionsBuilder()
1187                         .setAction(BindingMap.of(new ActionBuilder()
1188                             .setOrder(0)
1189                             .setAction(new FloodAllActionCaseBuilder()
1190                                 .setFloodAllAction(new FloodAllActionBuilder().build())
1191                                 .build())
1192                             .build()))
1193                         .build())
1194                     .build())
1195                 .build()));
1196     }
1197
1198     private static InstructionsBuilder createAppyActionInstruction16() {
1199         return new InstructionsBuilder()
1200             .setInstruction(BindingMap.of(new InstructionBuilder()
1201                 .setOrder(0)
1202                 .setInstruction(new ApplyActionsCaseBuilder()
1203                     .setApplyActions(new ApplyActionsBuilder()
1204                         .setAction(BindingMap.of(new ActionBuilder()
1205                             .setOrder(0)
1206                             .setAction(new GroupActionCaseBuilder()
1207                                 .setGroupAction(new GroupActionBuilder().setGroupId(Uint32.ONE).setGroup("0").build())
1208                                 .build())
1209                             .build()))
1210                         .build())
1211                     .build())
1212                 .build()));
1213     }
1214
1215     private static InstructionsBuilder createAppyActionInstruction17() {
1216         return new InstructionsBuilder()
1217             .setInstruction(BindingMap.of(new InstructionBuilder()
1218                 .setOrder(0)
1219                 .setInstruction(new ApplyActionsCaseBuilder()
1220                     .setApplyActions(new ApplyActionsBuilder()
1221                         .setAction(BindingMap.of(new ActionBuilder()
1222                             .setOrder(0)
1223                             .setAction(new HwPathActionCaseBuilder()
1224                                 .setHwPathAction(new HwPathActionBuilder().build())
1225                                 .build())
1226                             .build()))
1227                         .build())
1228                     .build())
1229                 .build()));
1230     }
1231
1232     private static InstructionsBuilder createAppyActionInstruction18() {
1233         return new InstructionsBuilder()
1234             .setInstruction(BindingMap.of(new InstructionBuilder()
1235                 .setOrder(0)
1236                 .setInstruction(new ApplyActionsCaseBuilder()
1237                     .setApplyActions(new ApplyActionsBuilder()
1238                         .setAction(BindingMap.of(new ActionBuilder()
1239                             .setOrder(0)
1240                             .setAction(new LoopbackActionCaseBuilder()
1241                                 .setLoopbackAction(new LoopbackActionBuilder().build())
1242                                 .build())
1243                             .build()))
1244                         .build())
1245                     .build())
1246                 .build()));
1247     }
1248
1249     private static InstructionsBuilder createAppyActionInstruction19() {
1250         return new InstructionsBuilder()
1251             .setInstruction(BindingMap.of(new InstructionBuilder()
1252                 .setOrder(0)
1253                 .setInstruction(new ApplyActionsCaseBuilder()
1254                     .setApplyActions(new ApplyActionsBuilder()
1255                         .setAction(BindingMap.of(new ActionBuilder()
1256                             .setOrder(0)
1257                             .setAction(new PopMplsActionCaseBuilder()
1258                                 .setPopMplsAction(new PopMplsActionBuilder()
1259                                     .setEthernetType(Uint16.valueOf(0xB))
1260                                     .build())
1261                                 .build())
1262                             .build()))
1263                         .build())
1264                     .build())
1265                 .build()));
1266     }
1267
1268     private static InstructionsBuilder createAppyActionInstruction20() {
1269         return new InstructionsBuilder()
1270             .setInstruction(BindingMap.of(new InstructionBuilder()
1271                 .setOrder(0)
1272                 .setInstruction(new ApplyActionsCaseBuilder()
1273                     .setApplyActions(new ApplyActionsBuilder()
1274                         .setAction(BindingMap.of(new ActionBuilder()
1275                             .setOrder(0)
1276                             .setAction(new PopPbbActionCaseBuilder()
1277                                 .setPopPbbAction(new PopPbbActionBuilder().build())
1278                                 .build())
1279                             .build()))
1280                         .build())
1281                     .build())
1282                 .build()));
1283     }
1284
1285     private static InstructionsBuilder createAppyActionInstruction21() {
1286         return new InstructionsBuilder()
1287             .setInstruction(BindingMap.of(new InstructionBuilder()
1288                 .setOrder(0)
1289                 .setInstruction(new ApplyActionsCaseBuilder()
1290                     .setApplyActions(new ApplyActionsBuilder()
1291                         .setAction(BindingMap.of(new ActionBuilder()
1292                             .setOrder(0)
1293                             .setAction(new PopVlanActionCaseBuilder()
1294                                 .setPopVlanAction(new PopVlanActionBuilder().build())
1295                                 .build())
1296                             .build()))
1297                         .build())
1298                     .build())
1299                 .build()));
1300     }
1301
1302     private static InstructionsBuilder createAppyActionInstruction22() {
1303         return new InstructionsBuilder()
1304             .setInstruction(BindingMap.of(new InstructionBuilder()
1305                 .setOrder(0)
1306                 .setInstruction(new ApplyActionsCaseBuilder()
1307                     .setApplyActions(new ApplyActionsBuilder()
1308                         .setAction(BindingMap.of(new ActionBuilder()
1309                             .setOrder(0)
1310                             .setAction(new SetDlTypeActionCaseBuilder()
1311                                 .setSetDlTypeAction(new SetDlTypeActionBuilder()
1312                                     .setDlType(new EtherType(Uint32.valueOf(8)))
1313                                     .build())
1314                                 .build())
1315                             .build()))
1316                         .build())
1317                     .build())
1318                 .build()));
1319     }
1320
1321     private static InstructionsBuilder createAppyActionInstruction23(final NodeId nodeId) {
1322         return new InstructionsBuilder()
1323             .setInstruction(BindingMap.of(new InstructionBuilder()
1324                 .setOrder(0)
1325                 .setInstruction(new ApplyActionsCaseBuilder()
1326                     .setApplyActions(new ApplyActionsBuilder()
1327                         .setAction(BindingMap.of(new ActionBuilder().setOrder(0).build()))
1328                         .build())
1329                     .build())
1330                 .build()));
1331     }
1332
1333     private static InstructionsBuilder createAppyActionInstruction24() {
1334         return new InstructionsBuilder()
1335             .setInstruction(BindingMap.of(new InstructionBuilder()
1336                 .setOrder(0)
1337                 .setInstruction(new ApplyActionsCaseBuilder()
1338                     .setApplyActions(new ApplyActionsBuilder()
1339                         .setAction(BindingMap.of(new ActionBuilder()
1340                             .setOrder(0)
1341                             .setAction(new SetMplsTtlActionCaseBuilder()
1342                                 .setSetMplsTtlAction(new SetMplsTtlActionBuilder().setMplsTtl(Uint8.ONE).build())
1343                                 .build())
1344                             .build()))
1345                         .build())
1346                     .build())
1347                 .build()));
1348     }
1349
1350     private static InstructionsBuilder createAppyActionInstruction25() {
1351         return new InstructionsBuilder()
1352             .setInstruction(BindingMap.of(new InstructionBuilder()
1353                 .setOrder(0)
1354                 .setInstruction(new ApplyActionsCaseBuilder()
1355                     .setApplyActions(new ApplyActionsBuilder()
1356                         .setAction(BindingMap.of(new ActionBuilder()
1357                             .setOrder(0)
1358                             .setAction(new SetNextHopActionCaseBuilder()
1359                                 .setSetNextHopAction(new SetNextHopActionBuilder()
1360                                     .setAddress(new Ipv4Builder().setIpv4Address(new Ipv4Prefix(IPV4_PREFIX)).build())
1361                                     .build())
1362                                 .build())
1363                             .build()))
1364                         .build())
1365                     .build())
1366                 .build()));
1367     }
1368
1369     private static InstructionsBuilder createAppyActionInstruction26() {
1370         return new InstructionsBuilder()
1371             .setInstruction(BindingMap.of(new InstructionBuilder()
1372                 .setOrder(0)
1373                 .setInstruction(new ApplyActionsCaseBuilder()
1374                     .setApplyActions(new ApplyActionsBuilder()
1375                         .setAction(BindingMap.of(new ActionBuilder()
1376                             .setOrder(0)
1377                             .setAction(new SetNwDstActionCaseBuilder()
1378                                 .setSetNwDstAction(new SetNwDstActionBuilder()
1379                                     .setAddress(new Ipv4Builder()
1380                                         .setIpv4Address(new Ipv4Prefix("10.0.0.21/24"))
1381                                         .build())
1382                                     .build())
1383                                 .build())
1384                             .build()))
1385                         .build())
1386                     .build())
1387                 .build()));
1388     }
1389
1390     private static InstructionsBuilder createAppyActionInstruction27() {
1391         return new InstructionsBuilder()
1392             .setInstruction(BindingMap.of(new InstructionBuilder()
1393                 .setOrder(0)
1394                 .setInstruction(new ApplyActionsCaseBuilder()
1395                     .setApplyActions(new ApplyActionsBuilder()
1396                         .setAction(BindingMap.of(new ActionBuilder()
1397                             .setOrder(0)
1398                             .setAction(new SetNwSrcActionCaseBuilder()
1399                                 .setSetNwSrcAction(new SetNwSrcActionBuilder()
1400                                     .setAddress(new Ipv4Builder()
1401                                         .setIpv4Address(new Ipv4Prefix("10.0.23.21/24"))
1402                                         .build())
1403                                     .build())
1404                                 .build())
1405                             .build()))
1406                         .build())
1407                     .build())
1408                 .build()));
1409     }
1410
1411     private static InstructionsBuilder createAppyActionInstruction28() {
1412         return new InstructionsBuilder()
1413             .setInstruction(BindingMap.of(new InstructionBuilder()
1414                 .setOrder(0)
1415                 .setInstruction(new ApplyActionsCaseBuilder()
1416                     .setApplyActions(new ApplyActionsBuilder()
1417                         .setAction(BindingMap.of(new ActionBuilder()
1418                             .setOrder(0)
1419                             .setAction(new SetNwTosActionCaseBuilder()
1420                                 .setSetNwTosAction(new SetNwTosActionBuilder().setTos(8).build())
1421                                 .build())
1422                             .build()))
1423                         .build())
1424                     .build())
1425                 .build()));
1426     }
1427
1428     private static InstructionsBuilder createAppyActionInstruction29() {
1429         return new InstructionsBuilder()
1430             .setInstruction(BindingMap.of(new InstructionBuilder()
1431                 .setOrder(0)
1432                 .setInstruction(new ApplyActionsCaseBuilder()
1433                     .setApplyActions(new ApplyActionsBuilder()
1434                         .setAction(BindingMap.of(new ActionBuilder()
1435                             .setOrder(0)
1436                             .setAction(new SetNwTtlActionCaseBuilder()
1437                                 .setSetNwTtlAction(new SetNwTtlActionBuilder().setNwTtl(Uint8.ONE).build())
1438                                 .build())
1439                             .build()))
1440                         .build())
1441                     .build())
1442                 .build()));
1443     }
1444
1445     private static InstructionsBuilder createAppyActionInstruction30() {
1446         return new InstructionsBuilder()
1447             .setInstruction(BindingMap.of(new InstructionBuilder()
1448                 .setOrder(0)
1449                 .setInstruction(new ApplyActionsCaseBuilder()
1450                     .setApplyActions(new ApplyActionsBuilder()
1451                         .setAction(BindingMap.of(new ActionBuilder()
1452                             .setOrder(0)
1453                             .setAction(new SetQueueActionCaseBuilder()
1454                                 .setSetQueueAction(new SetQueueActionBuilder().setQueueId(Uint32.ONE).build())
1455                                 .build())
1456                             .build()))
1457                         .build())
1458                     .build())
1459                 .build()));
1460     }
1461
1462     private static InstructionsBuilder createAppyActionInstruction31() {
1463         return new InstructionsBuilder()
1464             .setInstruction(BindingMap.of(new InstructionBuilder()
1465                 .setOrder(0)
1466                 .setInstruction(new ApplyActionsCaseBuilder()
1467                     .setApplyActions(new ApplyActionsBuilder()
1468                         .setAction(BindingMap.of(new ActionBuilder()
1469                             .setOrder(0)
1470                             .setAction(new SetTpDstActionCaseBuilder()
1471                                 .setSetTpDstAction(new SetTpDstActionBuilder()
1472                                     .setPort(new PortNumber(Uint16.valueOf(109)))
1473                                     .build())
1474                                 .build())
1475                             .build()))
1476                         .build())
1477                     .build())
1478                 .build()));
1479     }
1480
1481     private static InstructionsBuilder createAppyActionInstruction32() {
1482         return new InstructionsBuilder()
1483             .setInstruction(BindingMap.of(new InstructionBuilder()
1484                 .setOrder(0)
1485                 .setInstruction(new ApplyActionsCaseBuilder()
1486                     .setApplyActions(new ApplyActionsBuilder()
1487                         .setAction(BindingMap.of(new ActionBuilder()
1488                             .setOrder(0)
1489                             .setAction(new SetTpSrcActionCaseBuilder()
1490                                 .setSetTpSrcAction(new SetTpSrcActionBuilder()
1491                                     .setPort(new PortNumber(Uint16.valueOf(109)))
1492                                     .build())
1493                                 .build())
1494                             .build()))
1495                         .build())
1496                     .build())
1497                 .build()));
1498     }
1499
1500     private static InstructionsBuilder createAppyActionInstruction33() {
1501         return new InstructionsBuilder()
1502             .setInstruction(BindingMap.of(new InstructionBuilder()
1503                 .setOrder(0)
1504                 .setInstruction(new ApplyActionsCaseBuilder()
1505                     .setApplyActions(new ApplyActionsBuilder()
1506                         .setAction(BindingMap.of(new ActionBuilder()
1507                             .setOrder(0)
1508                             .setAction(new SetVlanCfiActionCaseBuilder()
1509                                 .setSetVlanCfiAction(new SetVlanCfiActionBuilder().setVlanCfi(new VlanCfi(2)).build())
1510                                 .build())
1511                             .build()))
1512                         .build())
1513                     .build())
1514                 .build()));
1515     }
1516
1517     private static InstructionsBuilder createAppyActionInstruction34() {
1518         return new InstructionsBuilder()
1519             .setInstruction(BindingMap.of(new InstructionBuilder()
1520                 .setOrder(0)
1521                 .setInstruction(new ApplyActionsCaseBuilder()
1522                     .setApplyActions(new ApplyActionsBuilder()
1523                         .setAction(BindingMap.of(new ActionBuilder()
1524                             .setOrder(0)
1525                             .setAction(new SwPathActionCaseBuilder()
1526                                 .setSwPathAction(new SwPathActionBuilder().build())
1527                                 .build())
1528                             .build()))
1529                         .build())
1530                     .build())
1531                 .build()));
1532     }
1533
1534     private static InstructionsBuilder createAppyActionInstruction35() {
1535         // Ethernet
1536         return new InstructionsBuilder()
1537             .setInstruction(BindingMap.of(new InstructionBuilder()
1538                 .setOrder(0)
1539                 .setInstruction(new ApplyActionsCaseBuilder()
1540                     .setApplyActions(new ApplyActionsBuilder()
1541                         .setAction(BindingMap.of(new ActionBuilder()
1542                             .setOrder(0)
1543                             .setAction(new SetFieldCaseBuilder()
1544                                 .setSetField(new SetFieldBuilder()
1545                                     .setEthernetMatch(new EthernetMatchBuilder()
1546                                         .setEthernetSource(new EthernetSourceBuilder()
1547                                             .setAddress(new MacAddress("00:00:00:00:00:01"))
1548                                             .build())
1549                                         .build())
1550                                     .build())
1551                                 .build())
1552                             .build(), new ActionBuilder()
1553                             .setOrder(1)
1554                             .setAction(new SetFieldCaseBuilder()
1555                                 .setSetField(new SetFieldBuilder()
1556                                     .setEthernetMatch(new EthernetMatchBuilder()
1557                                         .setEthernetDestination(new EthernetDestinationBuilder()
1558                                             .setAddress(new MacAddress("00:00:00:00:00:02"))
1559                                             .build())
1560                                         .build())
1561                                     .build())
1562                                 .build())
1563                             .build(), new ActionBuilder()
1564                             .setOrder(2)
1565                             .setAction(new SetFieldCaseBuilder()
1566                                 .setSetField(new SetFieldBuilder()
1567                                     .setEthernetMatch(new EthernetMatchBuilder()
1568                                         .setEthernetType(new EthernetTypeBuilder()
1569                                             .setType(new EtherType(Uint32.valueOf(0x86dd))).build())
1570                                         .build())
1571                                     .build())
1572                                 .build())
1573                             .build()))
1574                         .build())
1575                     .build())
1576                 .build()));
1577     }
1578
1579     private static InstructionsBuilder createAppyActionInstruction36() {
1580         return new InstructionsBuilder()
1581             .setInstruction(BindingMap.of(new InstructionBuilder()
1582                 .setOrder(0)
1583                 .setInstruction(new ApplyActionsCaseBuilder()
1584                     .setApplyActions(new ApplyActionsBuilder()
1585                         .setAction(BindingMap.of(new ActionBuilder()
1586                             .setOrder(0)
1587                             .setAction(new SetFieldCaseBuilder().setSetField(new SetFieldBuilder()
1588                                 .setVlanMatch(new VlanMatchBuilder()
1589                                     .setVlanPcp(new VlanPcp(Uint8.valueOf(3)))
1590                                     .build())
1591                                 .build()).build()).build(), new ActionBuilder()
1592                             .setOrder(0)
1593                             .setAction(new SetFieldCaseBuilder().setSetField(new SetFieldBuilder()
1594                                 .setVlanMatch(new VlanMatchBuilder()
1595                                     .setVlanId(new VlanIdBuilder()
1596                                         .setVlanId(new VlanId(Uint16.TEN))
1597                                         .setVlanIdPresent(true)
1598                                         .build())
1599                                     .build())
1600                                 .build())
1601                                 .build())
1602                             .build()))
1603                         .build())
1604                     .build())
1605                 .build()));
1606     }
1607
1608     private static InstructionsBuilder createAppyActionInstruction37() {
1609         // Ip
1610         return new InstructionsBuilder()
1611             .setInstruction(BindingMap.of(new InstructionBuilder()
1612                 .setOrder(0)
1613                 .setInstruction(new ApplyActionsCaseBuilder()
1614                     .setApplyActions(new ApplyActionsBuilder()
1615                         .setAction(BindingMap.of(new ActionBuilder()
1616                             .setOrder(0)
1617                             .setAction(new SetFieldCaseBuilder()
1618                                 .setSetField(new SetFieldBuilder()
1619                                     .setIpMatch(new IpMatchBuilder().setIpDscp(new Dscp(Uint8.valueOf(3))).build())
1620                                     .build())
1621                                 .build())
1622                             .build(), new ActionBuilder()
1623                             .setOrder(1)
1624                             .setAction(new SetFieldCaseBuilder()
1625                                 .setSetField(new SetFieldBuilder()
1626                                     .setIpMatch(new IpMatchBuilder().setIpEcn(Uint8.TWO).build())
1627                                     .build())
1628                                 .build())
1629                             .build(), new ActionBuilder()
1630                             .setOrder(2)
1631                             .setAction(new SetFieldCaseBuilder()
1632                                 .setSetField(new SetFieldBuilder()
1633                                     .setIpMatch(new IpMatchBuilder().setIpProtocol(Uint8.valueOf(120)).build())
1634                                     .build())
1635                                 .build()).build()))
1636                         .build())
1637                     .build())
1638                 .build()));
1639     }
1640
1641     private static InstructionsBuilder createAppyActionInstruction38() {
1642         // IPv4
1643         return new InstructionsBuilder()
1644             .setInstruction(BindingMap.of(new InstructionBuilder()
1645                 .setOrder(0)
1646                 .setInstruction(new ApplyActionsCaseBuilder()
1647                     .setApplyActions(new ApplyActionsBuilder()
1648                         .setAction(BindingMap.of(new ActionBuilder()
1649                             .setOrder(0)
1650                             .setAction(new SetFieldCaseBuilder()
1651                                 .setSetField(new SetFieldBuilder()
1652                                     .setLayer3Match(new Ipv4MatchBuilder()
1653                                         .setIpv4Source(new Ipv4Prefix("100.1.1.1"))
1654                                         .build())
1655                                     .build())
1656                                 .build())
1657                             .build(), new ActionBuilder()
1658                             .setOrder(1)
1659                             .setAction(new SetFieldCaseBuilder()
1660                                 .setSetField(new SetFieldBuilder()
1661                                     .setLayer3Match(new Ipv4MatchBuilder()
1662                                         .setIpv4Destination(new Ipv4Prefix("200.71.9.5210"))
1663                                         .build())
1664                                 .build())
1665                                 .build())
1666                             .build()))
1667                         .build())
1668                     .build())
1669                 .build()));
1670     }
1671
1672     // FIXME: refactor these for brevity
1673
1674     private static InstructionsBuilder createAppyActionInstruction39() {
1675         final ActionBuilder ab = new ActionBuilder();
1676         final ActionBuilder ab1 = new ActionBuilder();
1677
1678         final SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
1679         final SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
1680
1681         // Tcp
1682         final PortNumber tcpsrcport = new PortNumber(Uint16.valueOf(1213));
1683         final PortNumber tcpdstport = new PortNumber(Uint16.valueOf(646));
1684         final TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
1685         final TcpMatchBuilder tcpmatch1 = new TcpMatchBuilder();
1686         tcpmatch.setTcpSourcePort(tcpsrcport);
1687         tcpmatch1.setTcpDestinationPort(tcpdstport);
1688         setFieldBuilder.setLayer4Match(tcpmatch.build());
1689         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
1690         ab.setOrder(0);
1691
1692         setFieldBuilder1.setLayer4Match(tcpmatch1.build());
1693         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
1694         ab1.withKey(new ActionKey(1));
1695
1696         return new InstructionsBuilder()
1697             .setInstruction(BindingMap.of(new InstructionBuilder()
1698                 .setOrder(0)
1699                 .setInstruction(new ApplyActionsCaseBuilder()
1700                     .setApplyActions(new ApplyActionsBuilder()
1701                         .setAction(BindingMap.of(ab.build(), ab1.build()))
1702                         .build())
1703                     .build())
1704                 .build()));
1705     }
1706
1707     private static InstructionsBuilder createAppyActionInstruction40() {
1708         final ActionBuilder ab = new ActionBuilder();
1709         final ActionBuilder ab1 = new ActionBuilder();
1710
1711         final SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
1712         final SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
1713
1714         // Udp
1715         final PortNumber udpsrcport = new PortNumber(Uint16.valueOf(1325));
1716         final PortNumber udpdstport = new PortNumber(Uint16.valueOf(42));
1717         final UdpMatchBuilder udpmatch = new UdpMatchBuilder();
1718         final UdpMatchBuilder udpmatch1 = new UdpMatchBuilder();
1719         udpmatch.setUdpDestinationPort(udpdstport);
1720         udpmatch1.setUdpSourcePort(udpsrcport);
1721         setFieldBuilder.setLayer4Match(udpmatch.build());
1722         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
1723         ab.setOrder(0);
1724
1725         setFieldBuilder1.setLayer4Match(udpmatch1.build());
1726         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
1727         ab1.withKey(new ActionKey(1));
1728
1729         return new InstructionsBuilder()
1730             .setInstruction(BindingMap.of(new InstructionBuilder()
1731                 .setOrder(0)
1732                 .setInstruction(new ApplyActionsCaseBuilder()
1733                     .setApplyActions(new ApplyActionsBuilder()
1734                         .setAction(BindingMap.of(ab.build(), ab1.build()))
1735                         .build())
1736                     .build())
1737                 .build()));
1738     }
1739
1740     private static InstructionsBuilder createAppyActionInstruction41() {
1741         final ActionBuilder ab = new ActionBuilder();
1742         final ActionBuilder ab1 = new ActionBuilder();
1743
1744         final SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
1745         final SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
1746
1747         // Sctp
1748         final SctpMatchBuilder sctpmatch = new SctpMatchBuilder();
1749         final SctpMatchBuilder sctpmatch1 = new SctpMatchBuilder();
1750         final PortNumber srcport = new PortNumber(Uint16.valueOf(1435));
1751         final PortNumber dstport = new PortNumber(Uint16.valueOf(22));
1752         sctpmatch.setSctpSourcePort(srcport);
1753         sctpmatch1.setSctpDestinationPort(dstport);
1754         setFieldBuilder.setLayer4Match(sctpmatch.build());
1755         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
1756         ab.setOrder(0);
1757
1758         setFieldBuilder1.setLayer4Match(sctpmatch1.build());
1759         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
1760         ab1.withKey(new ActionKey(1));
1761
1762         return new InstructionsBuilder()
1763             .setInstruction(BindingMap.of(new InstructionBuilder()
1764                 .setOrder(0)
1765                 .setInstruction(new ApplyActionsCaseBuilder()
1766                     .setApplyActions(new ApplyActionsBuilder()
1767                         .setAction(BindingMap.of(ab.build(), ab1.build()))
1768                         .build())
1769                     .build())
1770                 .build()));
1771     }
1772
1773     private static InstructionsBuilder createAppyActionInstruction42() {
1774         final ActionBuilder ab = new ActionBuilder();
1775         final ActionBuilder ab1 = new ActionBuilder();
1776         final SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
1777         final SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
1778
1779         // Icmpv4
1780         final Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
1781         final Icmpv4MatchBuilder icmpv4match1 = new Icmpv4MatchBuilder();
1782         icmpv4match.setIcmpv4Type(Uint8.valueOf(8));
1783         icmpv4match1.setIcmpv4Code(Uint8.ZERO);
1784         setFieldBuilder.setIcmpv4Match(icmpv4match.build());
1785         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
1786         ab.setOrder(0);
1787
1788         setFieldBuilder1.setIcmpv4Match(icmpv4match1.build());
1789         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
1790         ab1.withKey(new ActionKey(1));
1791
1792         return new InstructionsBuilder()
1793             .setInstruction(BindingMap.of(new InstructionBuilder()
1794                 .setOrder(0)
1795                 .setInstruction(new ApplyActionsCaseBuilder()
1796                     .setApplyActions(new ApplyActionsBuilder()
1797                         .setAction(BindingMap.of(ab.build(), ab1.build()))
1798                         .build())
1799                     .build())
1800                 .build()));
1801     }
1802
1803     private static InstructionsBuilder createAppyActionInstruction43() {
1804         final ActionBuilder ab = new ActionBuilder();
1805         final ActionBuilder ab1 = new ActionBuilder();
1806         final ActionBuilder ab2 = new ActionBuilder();
1807         final ActionBuilder ab3 = new ActionBuilder();
1808         final ActionBuilder ab4 = new ActionBuilder();
1809
1810         final SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
1811         final SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
1812         final SetFieldBuilder setFieldBuilder2 = new SetFieldBuilder();
1813         final SetFieldBuilder setFieldBuilder3 = new SetFieldBuilder();
1814         final SetFieldBuilder setFieldBuilder4 = new SetFieldBuilder();
1815
1816         // setting the values of ARP
1817         final MacAddress macdest = new MacAddress(DEST_MAC_ADDRESS);
1818         final MacAddress macsrc = new MacAddress(SRC_MAC_ADDRESS);
1819         final Ipv4Prefix dstiparp = new Ipv4Prefix("200.71.9.52");
1820         final Ipv4Prefix srciparp = new Ipv4Prefix("100.1.1.1");
1821         // create ARP match action
1822         final ArpMatchBuilder arpmatch = new ArpMatchBuilder();
1823         final ArpMatchBuilder arpmatch1 = new ArpMatchBuilder();
1824         final ArpMatchBuilder arpmatch2 = new ArpMatchBuilder();
1825         final ArpMatchBuilder arpmatch3 = new ArpMatchBuilder();
1826         final ArpMatchBuilder arpmatch4 = new ArpMatchBuilder();
1827         final ArpSourceHardwareAddressBuilder arpsrc = new ArpSourceHardwareAddressBuilder();
1828         arpsrc.setAddress(macsrc);
1829         final ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder();
1830         arpdst.setAddress(macdest);
1831         arpmatch.setArpOp(Uint16.TWO);
1832         arpmatch1.setArpSourceHardwareAddress(arpsrc.build());
1833         arpmatch2.setArpTargetHardwareAddress(arpdst.build());
1834         arpmatch3.setArpSourceTransportAddress(srciparp);
1835         arpmatch4.setArpTargetTransportAddress(dstiparp);
1836         setFieldBuilder.setLayer3Match(arpmatch.build());
1837         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
1838         ab.setOrder(0);
1839
1840         setFieldBuilder1.setLayer3Match(arpmatch1.build());
1841         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
1842         ab1.withKey(new ActionKey(1));
1843
1844         setFieldBuilder2.setLayer3Match(arpmatch2.build());
1845         ab2.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder2.build()).build());
1846         ab2.withKey(new ActionKey(2));
1847
1848         setFieldBuilder3.setLayer3Match(arpmatch3.build());
1849         ab3.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder3.build()).build());
1850         ab3.withKey(new ActionKey(3));
1851
1852         setFieldBuilder4.setLayer3Match(arpmatch4.build());
1853         ab4.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder4.build()).build());
1854         ab4.withKey(new ActionKey(4));
1855
1856         return new InstructionsBuilder()
1857             .setInstruction(BindingMap.of(new InstructionBuilder()
1858                 .setOrder(0)
1859                 .setInstruction(new ApplyActionsCaseBuilder()
1860                     .setApplyActions(new ApplyActionsBuilder()
1861                         .setAction(BindingMap.of(ab.build(), ab1.build(), ab2.build(), ab3.build(), ab4.build()))
1862                         .build())
1863                     .build())
1864                 .build()));
1865     }
1866
1867     private static InstructionsBuilder createAppyActionInstruction44() {
1868         final ActionBuilder ab = new ActionBuilder();
1869         final SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
1870         final ActionBuilder ab1 = new ActionBuilder();
1871         final SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
1872         final ActionBuilder ab5 = new ActionBuilder();
1873         final SetFieldBuilder setFieldBuilder5 = new SetFieldBuilder();
1874         final ActionBuilder ab6 = new ActionBuilder();
1875         final SetFieldBuilder setFieldBuilder6 = new SetFieldBuilder();
1876
1877         // IPv6
1878         final Ipv6MatchBuilder ipv6Builder = new Ipv6MatchBuilder();
1879         final Ipv6MatchBuilder ipv6Builder1 = new Ipv6MatchBuilder();
1880         final Ipv6MatchBuilder ipv6Builder5 = new Ipv6MatchBuilder();
1881         final Ipv6MatchBuilder ipv6Builder6 = new Ipv6MatchBuilder();
1882
1883         final Ipv6Prefix dstip6 = new Ipv6Prefix("2002::2/128");
1884         final Ipv6Prefix srcip6 = new Ipv6Prefix("2001:0:0:0:0:0:0:1/128");
1885         final Ipv6ExtHeaderBuilder nextheader = new Ipv6ExtHeaderBuilder();
1886         nextheader.setIpv6Exthdr(Uint16.valueOf(58));
1887         final Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
1888         final Ipv6FlowLabel label = new Ipv6FlowLabel(Uint32.valueOf(10028));
1889         ipv6label.setIpv6Flabel(label);
1890
1891         ipv6Builder.setIpv6Source(srcip6);
1892         ipv6Builder1.setIpv6Destination(dstip6);
1893         ipv6Builder5.setIpv6ExtHeader(nextheader.build());
1894         ipv6Builder6.setIpv6Label(ipv6label.build());
1895
1896         setFieldBuilder.setLayer3Match(ipv6Builder.build());
1897         ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
1898         ab.setOrder(0);
1899
1900         setFieldBuilder1.setLayer3Match(ipv6Builder1.build());
1901         ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
1902         ab1.withKey(new ActionKey(1));
1903
1904         setFieldBuilder5.setLayer3Match(ipv6Builder5.build());
1905         ab5.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder5.build()).build());
1906         ab5.withKey(new ActionKey(5));
1907
1908         setFieldBuilder6.setLayer3Match(ipv6Builder6.build());
1909         ab6.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder6.build()).build());
1910         ab6.withKey(new ActionKey(6));
1911
1912         return new InstructionsBuilder()
1913             .setInstruction(BindingMap.of(new InstructionBuilder()
1914                 .setOrder(0)
1915                 .setInstruction(new ApplyActionsCaseBuilder()
1916                     .setApplyActions(new ApplyActionsBuilder()
1917                         .setAction(BindingMap.of(ab.build(), ab1.build(), ab5.build(), ab6.build()))
1918                         .build())
1919                     .build())
1920                 .build()));
1921     }
1922
1923     private static InstructionsBuilder createAppyActionInstruction45() {
1924         // Icmpv6
1925         return new InstructionsBuilder()
1926             .setInstruction(BindingMap.of(new InstructionBuilder()
1927                 .setOrder(0)
1928                 .setInstruction(new ApplyActionsCaseBuilder()
1929                     .setApplyActions(new ApplyActionsBuilder()
1930                         .setAction(BindingMap.of(new ActionBuilder()
1931                             .setOrder(0)
1932                             .setAction(new SetFieldCaseBuilder()
1933                                 .setSetField(new SetFieldBuilder()
1934                                     .setIcmpv6Match(new Icmpv6MatchBuilder().setIcmpv6Type(Uint8.valueOf(135)).build())
1935                                     .build())
1936                                 .build())
1937                             .build(), new ActionBuilder()
1938                             .setOrder(1)
1939                             .setAction(new SetFieldCaseBuilder()
1940                                 .setSetField(new SetFieldBuilder()
1941                                     .setIcmpv6Match(new Icmpv6MatchBuilder().setIcmpv6Code(Uint8.ZERO).build())
1942                                     .build())
1943                                 .build())
1944                             .build()))
1945                         .build())
1946                     .build())
1947                 .build()));
1948     }
1949
1950     private static InstructionsBuilder createAppyActionInstruction46() {
1951         // MPLS
1952         return new InstructionsBuilder()
1953             .setInstruction(BindingMap.of(new InstructionBuilder()
1954                 .setOrder(0)
1955                 .setInstruction(new ApplyActionsCaseBuilder()
1956                     .setApplyActions(new ApplyActionsBuilder()
1957                         .setAction(BindingMap.of(new ActionBuilder()
1958                             .setOrder(0)
1959                             .setAction(new SetFieldCaseBuilder()
1960                                 .setSetField(new SetFieldBuilder()
1961                                     .setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
1962                                         .setMplsLabel(Uint32.valueOf(36008))
1963                                         .build())
1964                                     .build())
1965                                 .build())
1966                             .build(), new ActionBuilder()
1967                             .setOrder(1)
1968                             .setAction(new SetFieldCaseBuilder()
1969                                 .setSetField(new SetFieldBuilder()
1970                                     .setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
1971                                         .setMplsTc(Uint8.valueOf(4))
1972                                         .build())
1973                                     .build())
1974                                 .build())
1975                             .build(), new ActionBuilder()
1976                             .setOrder(2)
1977                             .setAction(new SetFieldCaseBuilder()
1978                                 .setSetField(new SetFieldBuilder()
1979                                     .setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
1980                                         .setMplsBos(Uint8.ONE)
1981                                         .build())
1982                                     .build())
1983                                 .build())
1984                             .build()))
1985                         .build())
1986                     .build())
1987                 .build()));
1988     }
1989
1990     private static InstructionsBuilder createAppyActionInstruction47() {
1991         return new InstructionsBuilder()
1992             .setInstruction(BindingMap.of(new InstructionBuilder()
1993                 .setOrder(0)
1994                 .setInstruction(new ApplyActionsCaseBuilder()
1995                     .setApplyActions(new ApplyActionsBuilder()
1996                         .setAction(BindingMap.of(new ActionBuilder()
1997                             .setOrder(0)
1998                             .setAction(new SetFieldCaseBuilder()
1999                                 .setSetField(new SetFieldBuilder()
2000                                     .setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
2001                                         .setPbb(new PbbBuilder()
2002                                             .setPbbIsid(Uint32.valueOf(4))
2003                                             .setPbbMask(Uint32.valueOf(0x10000))
2004                                             .build())
2005                                         .build())
2006                                     .build())
2007                                 .build())
2008                             .build()))
2009                         .build())
2010                     .build())
2011                 .build()));
2012     }
2013
2014     private static InstructionsBuilder createAppyActionInstruction48() {
2015         return new InstructionsBuilder()
2016             .setInstruction(BindingMap.of(new InstructionBuilder()
2017                 .setOrder(0)
2018                 .setInstruction(new ApplyActionsCaseBuilder()
2019                     .setApplyActions(new ApplyActionsBuilder()
2020                         .setAction(BindingMap.of(new ActionBuilder()
2021                             .setOrder(0)
2022                             .setAction(new SetFieldCaseBuilder()
2023                                 .setSetField(new SetFieldBuilder()
2024                                     // Tunnel
2025                                     .setTunnel(new TunnelBuilder().setTunnelId(Uint64.valueOf(10668)).build()).build())
2026                                 .build())
2027                             .build()))
2028                         .build())
2029                     .build())
2030                 .build()));
2031     }
2032
2033     private static InstructionsBuilder createTunnelIpv4DstInstructions() {
2034         return new InstructionsBuilder()
2035             .setInstruction(BindingMap.of(new InstructionBuilder()
2036                 .setOrder(0)
2037                 .setInstruction(new ApplyActionsCaseBuilder()
2038                     .setApplyActions(new ApplyActionsBuilder()
2039                         .setAction(BindingMap.of(new ActionBuilder()
2040                             .setOrder(0)
2041                             .setAction(new SetFieldCaseBuilder()
2042                                 // Add the IPv4 tunnel dst to the set_field value
2043                                 .setSetField(new SetFieldBuilder()
2044                                     .setLayer3Match(new TunnelIpv4MatchBuilder()
2045                                         // Add the mew IPv4 object as the tunnel destination
2046                                         .setTunnelIpv4Destination(new Ipv4Prefix("172.16.100.100"))
2047                                         .build())
2048                                     .build())
2049                                 .build())
2050                             .build()))
2051                         .build())
2052                     .build())
2053                 .build()));
2054     }
2055
2056     private static InstructionsBuilder createTunnelIpv4SrcInstructions() {
2057         return new InstructionsBuilder()
2058             .setInstruction(BindingMap.of(new InstructionBuilder()
2059                 .setOrder(0)
2060                 .setInstruction(new ApplyActionsCaseBuilder()
2061                     .setApplyActions(new ApplyActionsBuilder()
2062                         .setAction(BindingMap.of(new ActionBuilder()
2063                             .setOrder(0)
2064                             .setAction(new SetFieldCaseBuilder()
2065                                 // Add the IPv4 tunnel src to the set_field value
2066                                 .setSetField(new SetFieldBuilder()
2067                                     .setLayer3Match(new TunnelIpv4MatchBuilder()
2068                                         // Add the new IPv4 object as the tunnel destination
2069                                         .setTunnelIpv4Source(new Ipv4Prefix("172.16.100.200"))
2070                                         .build())
2071                                     .build())
2072                                 .build())
2073                             .build()))
2074                         .build())
2075                     .build())
2076                 .build()));
2077     }
2078
2079     private static MatchBuilder createLLDPMatch() {
2080         final MatchBuilder match = new MatchBuilder();
2081         final EthernetMatchBuilder eth = new EthernetMatchBuilder();
2082         final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2083         ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x88cc)));
2084         eth.setEthernetType(ethTypeBuilder.build());
2085         match.setEthernetMatch(eth.build());
2086         return match;
2087     }
2088
2089     private static MatchBuilder createMatch1() {
2090         final MatchBuilder match = new MatchBuilder();
2091         final Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
2092         final Ipv4Prefix prefix = new Ipv4Prefix(IPV4_PREFIX);
2093         ipv4Match.setIpv4Destination(prefix);
2094         final Ipv4Match i4m = ipv4Match.build();
2095         match.setLayer3Match(i4m);
2096
2097         final EthernetMatchBuilder eth = new EthernetMatchBuilder();
2098         final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2099         ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x0800)));
2100         eth.setEthernetType(ethTypeBuilder.build());
2101         match.setEthernetMatch(eth.build());
2102         return match;
2103     }
2104
2105     private static MatchBuilder createMatch2() {
2106         final MatchBuilder match = new MatchBuilder();
2107         final Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
2108         final Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1");
2109         ipv4Match.setIpv4Source(prefix);
2110         final Ipv4Match i4m = ipv4Match.build();
2111         match.setLayer3Match(i4m);
2112
2113         final EthernetMatchBuilder eth = new EthernetMatchBuilder();
2114         final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2115         ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x0800)));
2116         eth.setEthernetType(ethTypeBuilder.build());
2117         match.setEthernetMatch(eth.build());
2118         return match;
2119     }
2120
2121     private static MatchBuilder createMatch3() {
2122         final MatchBuilder match = new MatchBuilder();
2123         final EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
2124         final EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
2125         ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
2126         ethernetMatch.setEthernetSource(ethSourceBuilder.build());
2127         match.setEthernetMatch(ethernetMatch.build());
2128
2129         return match;
2130     }
2131
2132     private static MatchBuilder createICMPv6Match1() {
2133         return new MatchBuilder()
2134             .setEthernetMatch(new EthernetMatchBuilder()
2135                 .setEthernetType(new EthernetTypeBuilder()
2136                     .setType(new EtherType(Uint32.valueOf(0x86dd)))
2137                     .build())
2138                 .build())
2139             // ipv4 version
2140             .setIpMatch(new IpMatchBuilder().setIpProtocol(Uint8.MAX_VALUE).build())
2141             // icmpv6
2142             .setIcmpv6Match(new Icmpv6MatchBuilder()
2143                 .setIcmpv6Type(Uint8.valueOf(135))
2144                 .setIcmpv6Code(Uint8.ONE)
2145                 .build());
2146     }
2147
2148     private static MatchBuilder createMatch33() {
2149
2150         final MatchBuilder match = new MatchBuilder();
2151         final Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
2152         final Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.10");
2153         ipv4Match.setIpv4Source(prefix);
2154         final Ipv4Match i4m = ipv4Match.build();
2155         match.setLayer3Match(i4m);
2156
2157         final EthernetMatchBuilder eth = new EthernetMatchBuilder();
2158         final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2159         ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0xfffe)));
2160         eth.setEthernetType(ethTypeBuilder.build());
2161         match.setEthernetMatch(eth.build());
2162         return match;
2163     }
2164
2165     private static MatchBuilder createInphyportMatch(final NodeId nodeId) {
2166         final MatchBuilder match = new MatchBuilder();
2167         match.setInPort(new NodeConnectorId(nodeId + ":202"));
2168         match.setInPhyPort(new NodeConnectorId(nodeId + ":10122"));
2169         return match;
2170     }
2171
2172     private static MatchBuilder createEthernetMatch() {
2173         final MatchBuilder match = new MatchBuilder();
2174         final EthernetMatchBuilder ethmatch = new EthernetMatchBuilder(); // ethernettype
2175         // match
2176         final EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
2177         final EtherType type = new EtherType(Uint32.valueOf(0x0800));
2178         ethmatch.setEthernetType(ethtype.setType(type).build());
2179
2180         final EthernetDestinationBuilder ethdest = new EthernetDestinationBuilder(); // ethernet
2181         // macaddress
2182         // match
2183         final MacAddress macdest = new MacAddress(DEST_MAC_ADDRESS);
2184         ethdest.setAddress(macdest);
2185         ethdest.setMask(new MacAddress("ff:ff:ff:00:00:00"));
2186
2187         ethmatch.setEthernetDestination(ethdest.build());
2188
2189         final EthernetSourceBuilder ethsrc = new EthernetSourceBuilder();
2190         final MacAddress macsrc = new MacAddress(SRC_MAC_ADDRESS);
2191         ethsrc.setAddress(macsrc);
2192         ethsrc.setMask(new MacAddress("ff:ff:00:00:00:00"));
2193
2194         ethmatch.setEthernetSource(ethsrc.build());
2195         match.setEthernetMatch(ethmatch.build());
2196         return match;
2197
2198     }
2199
2200     private static MatchBuilder createVlanMatch() {
2201         final MatchBuilder match = new MatchBuilder();
2202         // vlan match
2203         final VlanMatchBuilder vlanBuilder = new VlanMatchBuilder();
2204         final VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
2205         final VlanId vlanId = new VlanId(Uint16.TEN);
2206         final VlanPcp vpcp = new VlanPcp(Uint8.valueOf(3));
2207         vlanBuilder.setVlanPcp(vpcp);
2208         vlanIdBuilder.setVlanId(vlanId);
2209         vlanIdBuilder.setVlanIdPresent(true);
2210         vlanBuilder.setVlanId(vlanIdBuilder.build());
2211         match.setVlanMatch(vlanBuilder.build());
2212         return match;
2213     }
2214
2215     private static MatchBuilder createArpMatch() {
2216         final MatchBuilder match = new MatchBuilder();
2217
2218         final EthernetMatchBuilder ethmatch = new EthernetMatchBuilder();
2219         final MacAddress macdest = new MacAddress(DEST_MAC_ADDRESS);
2220         final MacAddress macsrc = new MacAddress(SRC_MAC_ADDRESS);
2221
2222         final EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
2223         final EtherType type = new EtherType(Uint32.valueOf(0x0806));
2224         ethmatch.setEthernetType(ethtype.setType(type).build());
2225
2226         // ipv4 match
2227         final Ipv4Prefix dstip = new Ipv4Prefix("200.71.9.52/10");
2228         final Ipv4Prefix srcip = new Ipv4Prefix("100.1.1.1/8");
2229
2230         // arp match
2231         final ArpMatchBuilder arpmatch = new ArpMatchBuilder();
2232         final ArpSourceHardwareAddressBuilder arpsrc = new ArpSourceHardwareAddressBuilder();
2233         arpsrc.setAddress(macsrc);
2234         arpsrc.setMask(new MacAddress("ff:ff:ff:00:00:00"));
2235         final ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder();
2236         arpdst.setAddress(macdest);
2237         arpdst.setMask(new MacAddress("ff:ff:00:00:00:00"));
2238         arpmatch.setArpOp(Uint16.TWO);
2239         arpmatch.setArpSourceHardwareAddress(arpsrc.build());
2240         arpmatch.setArpTargetHardwareAddress(arpdst.build());
2241         arpmatch.setArpSourceTransportAddress(srcip);
2242         arpmatch.setArpTargetTransportAddress(dstip);
2243
2244         match.setEthernetMatch(ethmatch.build());
2245         match.setLayer3Match(arpmatch.build());
2246
2247         return match;
2248     }
2249
2250     private static MatchBuilder createL3IPv6Match() {
2251         final MatchBuilder match = new MatchBuilder();
2252
2253         final EthernetMatchBuilder eth = new EthernetMatchBuilder();
2254         final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2255         ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x86dd)));
2256         eth.setEthernetType(ethTypeBuilder.build());
2257         match.setEthernetMatch(eth.build());
2258
2259         final MacAddress ndsll = new MacAddress("c2:00:54:f5:00:00");
2260         final MacAddress ndtll = new MacAddress("00:0c:29:0e:4c:67");
2261         final Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
2262         final Ipv6FlowLabel label = new Ipv6FlowLabel(Uint32.valueOf(10028));
2263         ipv6label.setIpv6Flabel(label);
2264         ipv6label.setFlabelMask(new Ipv6FlowLabel(Uint32.ONE));
2265
2266         final Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
2267         // match
2268         icmpv6match.setIcmpv6Type(Uint8.valueOf(135));
2269         icmpv6match.setIcmpv6Code(Uint8.ZERO);
2270         match.setIcmpv6Match(icmpv6match.build());
2271
2272         final Ipv6MatchBuilder ipv6match = new Ipv6MatchBuilder();
2273         // ipv6match.setIpv6Source(srcip6);
2274         // ipv6match.setIpv6Destination(dstip6);
2275         // ipv6match.setIpv6ExtHeader(nextheader.build());
2276         ipv6match.setIpv6NdSll(ndsll);
2277         ipv6match.setIpv6NdTll(ndtll);
2278         // ipv6match.setIpv6NdTarget(ndtarget);
2279         ipv6match.setIpv6Label(ipv6label.build());
2280
2281         match.setLayer3Match(ipv6match.build());
2282
2283         return match;
2284     }
2285
2286     private static MatchBuilder createICMPv4Match() {
2287         final MatchBuilder match = new MatchBuilder();
2288         final EthernetMatchBuilder eth = new EthernetMatchBuilder();
2289         final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2290         ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x0800)));
2291         eth.setEthernetType(ethTypeBuilder.build());
2292         match.setEthernetMatch(eth.build());
2293
2294         final IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
2295         ipmatch.setIpProtocol(Uint8.ONE);
2296         match.setIpMatch(ipmatch.build());
2297
2298         final Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder(); // icmpv4
2299         // match
2300         icmpv4match.setIcmpv4Type(Uint8.valueOf(8));
2301         icmpv4match.setIcmpv4Code(Uint8.ZERO);
2302         match.setIcmpv4Match(icmpv4match.build());
2303         return match;
2304     }
2305
2306     private static MatchBuilder createICMPv6Match() {
2307
2308         final MatchBuilder match = new MatchBuilder();
2309         final EthernetMatchBuilder eth = new EthernetMatchBuilder();
2310         final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2311         ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x86dd)));
2312         eth.setEthernetType(ethTypeBuilder.build());
2313         match.setEthernetMatch(eth.build());
2314
2315         final IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
2316         ipmatch.setIpProtocol(Uint8.valueOf(58));
2317         match.setIpMatch(ipmatch.build());
2318
2319         final Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
2320         // match
2321         icmpv6match.setIcmpv6Type(Uint8.valueOf(135));
2322         icmpv6match.setIcmpv6Code(Uint8.ONE);
2323         match.setIcmpv6Match(icmpv6match.build());
2324
2325         return match;
2326     }
2327
2328     private static MatchBuilder createToSMatch() {
2329         final MatchBuilder match = new MatchBuilder();
2330         final EthernetMatchBuilder ethmatch = new EthernetMatchBuilder();
2331         final EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
2332         final EtherType type = new EtherType(Uint32.valueOf(0x0800));
2333         ethmatch.setEthernetType(ethtype.setType(type).build());
2334         match.setEthernetMatch(ethmatch.build());
2335
2336         final IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
2337         ipmatch.setIpProtocol(Uint8.valueOf(6));
2338         final Dscp dscp = new Dscp(Uint8.valueOf(8));
2339         ipmatch.setIpDscp(dscp);
2340         match.setIpMatch(ipmatch.build());
2341         return match;
2342     }
2343
2344     private static MatchBuilder createL4TCPMatch() {
2345         final MatchBuilder match = new MatchBuilder();
2346
2347         final EthernetMatchBuilder eth = new EthernetMatchBuilder();
2348         final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2349         ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x0800)));
2350         eth.setEthernetType(ethTypeBuilder.build());
2351         match.setEthernetMatch(eth.build());
2352
2353         final IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
2354         ipmatch.setIpProtocol(Uint8.valueOf(6));
2355         match.setIpMatch(ipmatch.build());
2356
2357         final PortNumber srcport = new PortNumber(Uint16.valueOf(1213));
2358         final PortNumber dstport = new PortNumber(Uint16.valueOf(646));
2359         final TcpMatchBuilder tcpmatch = new TcpMatchBuilder(); // tcp match
2360         tcpmatch.setTcpSourcePort(srcport);
2361         tcpmatch.setTcpDestinationPort(dstport);
2362         match.setLayer4Match(tcpmatch.build());
2363
2364         return match;
2365     }
2366
2367     private static MatchBuilder createL4UDPMatch() {
2368         final MatchBuilder match = new MatchBuilder();
2369
2370         final EthernetMatchBuilder eth = new EthernetMatchBuilder();
2371         final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2372         ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x0800)));
2373         eth.setEthernetType(ethTypeBuilder.build());
2374         match.setEthernetMatch(eth.build());
2375
2376         final IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
2377         ipmatch.setIpProtocol(Uint8.valueOf(17));
2378         match.setIpMatch(ipmatch.build());
2379
2380         final PortNumber srcport = new PortNumber(Uint16.valueOf(1325));
2381         final PortNumber dstport = new PortNumber(Uint16.valueOf(42));
2382         final UdpMatchBuilder udpmatch = new UdpMatchBuilder(); // udp match
2383         udpmatch.setUdpDestinationPort(dstport);
2384         udpmatch.setUdpSourcePort(srcport);
2385         match.setLayer4Match(udpmatch.build());
2386
2387         return match;
2388     }
2389
2390     private static MatchBuilder createL4SCTPMatch() {
2391         final MatchBuilder match = new MatchBuilder();
2392
2393         final EthernetMatchBuilder eth = new EthernetMatchBuilder();
2394         final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2395         ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x0800)));
2396         eth.setEthernetType(ethTypeBuilder.build());
2397         match.setEthernetMatch(eth.build());
2398
2399         final IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
2400         ipmatch.setIpProtocol(Uint8.valueOf(132));
2401         match.setIpMatch(ipmatch.build());
2402
2403         final SctpMatchBuilder sctpmatch = new SctpMatchBuilder();
2404         final PortNumber srcport = new PortNumber(Uint16.valueOf(1435));
2405         final PortNumber dstport = new PortNumber(Uint16.valueOf(22));
2406         sctpmatch.setSctpSourcePort(srcport);
2407         sctpmatch.setSctpDestinationPort(dstport);
2408         match.setLayer4Match(sctpmatch.build());
2409
2410         return match;
2411     }
2412
2413     private static MatchBuilder createMetadataMatch() {
2414         final MatchBuilder match = new MatchBuilder();
2415         final MetadataBuilder metadata = new MetadataBuilder(); // metadata match
2416         metadata.setMetadata(Uint64.valueOf(500));
2417         metadata.setMetadataMask(Uint64.valueOf(0xFFFFFF00_00000101L));
2418         match.setMetadata(metadata.build());
2419
2420         return match;
2421     }
2422
2423     private static MatchBuilder createMplsMatch() {
2424         final MatchBuilder match = new MatchBuilder();
2425
2426         final EthernetMatchBuilder eth = new EthernetMatchBuilder();
2427         final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2428         ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x8847)));
2429         eth.setEthernetType(ethTypeBuilder.build());
2430         match.setEthernetMatch(eth.build());
2431
2432         final ProtocolMatchFieldsBuilder protomatch = new ProtocolMatchFieldsBuilder(); // mpls
2433         // match
2434         protomatch.setMplsLabel(Uint32.valueOf(36008));
2435         protomatch.setMplsTc(Uint8.valueOf(4));
2436         protomatch.setMplsBos(Uint8.ONE);
2437         match.setProtocolMatchFields(protomatch.build());
2438
2439         return match;
2440
2441     }
2442
2443     private static MatchBuilder createPbbMatch() {
2444         final MatchBuilder match = new MatchBuilder();
2445
2446         final EthernetMatchBuilder eth = new EthernetMatchBuilder();
2447         final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2448         ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x88E7)));
2449         eth.setEthernetType(ethTypeBuilder.build());
2450         match.setEthernetMatch(eth.build());
2451
2452         final ProtocolMatchFieldsBuilder protomatch = new ProtocolMatchFieldsBuilder(); // mpls
2453         // match
2454         protomatch.setPbb(new PbbBuilder().setPbbIsid(Uint32.valueOf(4)).setPbbMask(Uint32.valueOf(0x10000)).build());
2455         match.setProtocolMatchFields(protomatch.build());
2456
2457         return match;
2458
2459     }
2460
2461     private static MatchBuilder createTunnelIDMatch() {
2462         final MatchBuilder match = new MatchBuilder();
2463         final TunnelBuilder tunnel = new TunnelBuilder(); // tunnel id match
2464         tunnel.setTunnelId(Uint64.valueOf(10668));
2465         tunnel.setTunnelMask(Uint64.valueOf(0xFFFFFF00_00000101L));
2466         match.setTunnel(tunnel.build());
2467
2468         return match;
2469     }
2470
2471     /**
2472      * Test match for TCP_Flags.
2473      *
2474      * @return match containing Ethertype (0x0800), IP Protocol (TCP), TCP_Flag (SYN)
2475      */
2476     //FIXME: move to extensible support
2477     private static MatchBuilder createTcpFlagMatch() {
2478         final MatchBuilder match = new MatchBuilder();
2479
2480         // Ethertype match
2481         final EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
2482         final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
2483         ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x0800)));
2484         ethernetType.setEthernetType(ethTypeBuilder.build());
2485         match.setEthernetMatch(ethernetType.build());
2486
2487         // TCP Protocol Match
2488         final IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
2489         ipMatch.setIpProtocol(Uint8.valueOf(6));
2490         match.setIpMatch(ipMatch.build());
2491
2492         // TCP Port Match
2493         final PortNumber dstPort = new PortNumber(Uint16.valueOf(80));
2494         final TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
2495         tcpMatch.setTcpDestinationPort(dstPort);
2496         match.setLayer4Match(tcpMatch.build());
2497         /**
2498          * Defined TCP Flag values in OVS v2.1+
2499          * TCP_FIN 0x001 / TCP_SYN 0x002 / TCP_RST 0x004
2500          * TCP_PSH 0x008 / TCP_ACK 0x010 / TCP_URG 0x020
2501          * TCP_ECE 0x040 / TCP_CWR 0x080 / TCP_NS  0x100
2502          */
2503         final TcpFlagsMatchBuilder tcpFlagsMatch = new TcpFlagsMatchBuilder();
2504         tcpFlagsMatch.setTcpFlags(Uint16.valueOf(0x002));
2505         match.setTcpFlagsMatch(tcpFlagsMatch.build());
2506
2507         return match;
2508     }
2509
2510     @SuppressWarnings("checkstyle:MethodName")
2511     public void _removeMDFlow(final CommandInterpreter ci) {
2512         final ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
2513         final NodeBuilder tn = createTestNode(ci.nextArgument());
2514         final String flowtype = ci.nextArgument();
2515         FlowBuilder tf;
2516         if (flowtype.equals("fTM")) {
2517             tf = createtablemiss();
2518         } else {
2519             tf = createTestFlow(tn, flowtype, ci.nextArgument());
2520         }
2521         final InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
2522                 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
2523                 .child(Flow.class, tf.key());
2524         modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
2525         modification.commit().addCallback(new FutureCallback<CommitInfo>() {
2526             @Override
2527             public void onSuccess(final CommitInfo notUsed) {
2528                 ci.println("Status of Group Data Loaded Transaction: success.");
2529             }
2530
2531             @Override
2532             public void onFailure(final Throwable throwable) {
2533                 LOG.error("Status of Group Data Loaded Transaction : failure.", throwable);
2534                 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
2535             }
2536         }, MoreExecutors.directExecutor());
2537     }
2538
2539     /**
2540      * Adds a flow.
2541      *
2542      * @param ci arguments: switchId flowType tableNum, e.g.: addMDFlow openflow:1 f1 42
2543      */
2544     @SuppressWarnings("checkstyle:MethodName")
2545     public void _addMDFlow(final CommandInterpreter ci) {
2546         final NodeBuilder tn = createTestNode(ci.nextArgument());
2547         final String flowtype = ci.nextArgument();
2548         FlowBuilder tf;
2549         if (flowtype.equals("fTM")) {
2550             tf = createtablemiss();
2551         } else {
2552             tf = createTestFlow(tn, flowtype, ci.nextArgument());
2553         }
2554         writeFlow(ci, tf, tn);
2555     }
2556
2557     private void writeFlow(final CommandInterpreter ci, final FlowBuilder flow, final NodeBuilder nodeBuilder) {
2558         final ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
2559         final InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class)
2560                 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
2561                 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.key());
2562         modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION,
2563                 nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
2564         modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path1, flow.build());
2565         modification.commit().addCallback(new FutureCallback<CommitInfo>() {
2566             @Override
2567             public void onSuccess(final CommitInfo notUsed) {
2568                 ci.println("Status of Group Data Loaded Transaction: success.");
2569             }
2570
2571             @Override
2572             public void onFailure(final Throwable throwable) {
2573                 LOG.error("Status of Group Data Loaded Transaction : failure.", throwable);
2574                 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
2575             }
2576         }, MoreExecutors.directExecutor());
2577     }
2578
2579     @SuppressWarnings("checkstyle:MethodName")
2580     public void _modifyMDFlow(final CommandInterpreter ci) {
2581         final NodeBuilder tn = createTestNode(ci.nextArgument());
2582         final FlowBuilder tf = createTestFlow(tn, ci.nextArgument(), ci.nextArgument());
2583         tf.setFlowName(UPDATED_FLOW_NAME);
2584         writeFlow(ci, tf, tn);
2585         tf.setFlowName(ORIGINAL_FLOW_NAME);
2586         writeFlow(ci, tf, tn);
2587     }
2588
2589     @Override
2590     public String getHelp() {
2591         return "No help";
2592     }
2593
2594     /*
2595      * usage testSwitchFlows <numberOfSwitches> <numberOfFlows> <warmup iterations> <Number Of Threads>
2596      * ex: _perfFlowTest 10 5 1 2
2597      */
2598     @SuppressWarnings("checkstyle:MethodName")
2599     public void _perfFlowTest(final CommandInterpreter ci) {
2600
2601         final String numberOfSwtichesStr = ci.nextArgument();
2602         final String numberOfFlowsStr = ci.nextArgument();
2603         final String warmupIterationsStr = ci.nextArgument();
2604         final String threadCountStr = ci.nextArgument();
2605         final String warmUpStr = ci.nextArgument();
2606
2607         int numberOfSwtiches = 0;
2608         int numberOfFlows = 0;
2609         int warmupIterations = 0;
2610         boolean warmUpIterations = false;
2611
2612         int threadCount = 0;
2613         if (numberOfSwtichesStr != null && !numberOfSwtichesStr.trim().equals("")) {
2614             numberOfSwtiches = Integer.parseInt(numberOfSwtichesStr);
2615         } else {
2616             numberOfSwtiches = 2;
2617         }
2618
2619         if (numberOfFlowsStr != null && !numberOfFlowsStr.trim().equals("")) {
2620             numberOfFlows = Integer.parseInt(numberOfFlowsStr);
2621         } else {
2622             numberOfFlows = 2;
2623         }
2624
2625         if (warmupIterationsStr != null && !warmupIterationsStr.trim().equals("")) {
2626             warmupIterations = Integer.parseInt(warmupIterationsStr);
2627         } else {
2628             warmupIterations = 2;
2629         }
2630
2631         if (threadCountStr != null && !threadCountStr.trim().equals("")) {
2632             threadCount = Integer.parseInt(threadCountStr);
2633         } else {
2634             threadCount = 2;
2635         }
2636         if (warmUpStr != null && !warmUpStr.trim().equals("") && warmUpStr.trim().equals("true")) {
2637             warmUpIterations = true;
2638         } else {
2639             warmUpIterations = false;
2640         }
2641         ci.println("*     Test Configurations*");
2642         ci.println("*     numberOfSwtiches:::" + numberOfSwtiches + "");
2643         ci.println("*     numberOfFlows:::" + numberOfFlows + "");
2644         ci.println("*     warmupIterations:::" + warmupIterations + "");
2645         ci.println("*     Number of Threads :::" + threadCount + "");
2646         ci.println("*     Warmup Required? :::" + warmUpIterations + "");
2647
2648         String dataPath = "openflow:1";
2649         NodeBuilder tn;
2650         FlowBuilder tf;
2651         final String tableId = "0";
2652         if (warmUpIterations) {
2653             ci.println("----Warmup Started-----");
2654             for (int j = 1; j <= warmupIterations; j++) {
2655                 for (int i = 1; i <= numberOfSwtiches; i++) {
2656                     dataPath = "openflow:" + i;
2657                     tn = createTestNode(dataPath);
2658                     for (int flow = 1; flow < numberOfFlows; flow++) {
2659                         tf = createTestFlowPerfTest("f1", tableId, flow);
2660                         writeFlow(ci, tf, tn);
2661                     }
2662                 }
2663             }
2664
2665             ci.println("----Warmup Done-----");
2666         }
2667         try {
2668             final ExecutorService executor = Executors.newFixedThreadPool(threadCount);
2669             int tableID = 0;
2670             for (int t = 0; t < threadCount; t++) {
2671                 tableID = t + 1;
2672                 final Runnable tRunnable = new TestFlowThread(numberOfSwtiches, numberOfFlows, ci, t, tableID);
2673                 executor.execute(tRunnable);
2674             }
2675             executor.shutdown();
2676             executor.awaitTermination(1, TimeUnit.SECONDS);
2677         } catch (InterruptedException e) {
2678             ci.println("Exception:" + e.getMessage());
2679         }
2680     }
2681
2682     public class TestFlowThread implements Runnable {
2683
2684         int numberOfSwitches;
2685         int numberOfFlows;
2686         CommandInterpreter ci;
2687         int theadNumber;
2688         int tableID = 0;
2689
2690         TestFlowThread(final int numberOfSwtiches, final int numberOfFlows, final CommandInterpreter ci,
2691                 final int threadNumber, final int tableID) {
2692             numberOfSwitches = numberOfSwtiches;
2693             this.numberOfFlows = numberOfFlows;
2694             this.ci = ci;
2695             theadNumber = threadNumber;
2696             this.tableID = tableID;
2697         }
2698
2699         @Override
2700         public void run() {
2701             executeFlow();
2702         }
2703
2704         public void executeFlow() {
2705
2706             String dataPath = "openflow:1";
2707             NodeBuilder tn;
2708             FlowBuilder tf;
2709             //String tableId = "0";
2710
2711             ci.println("New Thread started with id:  ID_" + theadNumber);
2712             int totalNumberOfFlows = 0;
2713             final long startTime = System.currentTimeMillis();
2714
2715             for (int i = 1; i <= numberOfSwitches; i++) {
2716                 dataPath = "openflow:" + i;
2717                 tn = createTestNode(dataPath);
2718                 for (int flow2 = 1; flow2 <= numberOfFlows; flow2++) {
2719                     tf = createTestFlowPerfTest("f1", "" + tableID, flow2);
2720                     writeFlow(ci, tf, tn);
2721                     totalNumberOfFlows++;
2722                 }
2723             }
2724             final long endTime = System.currentTimeMillis();
2725             final long timeInSeconds = Math.round((endTime - startTime) / 1000.0F);
2726             if (timeInSeconds > 0) {
2727                 ci.println("Total flows added in Thread:" + theadNumber + ": Flows/Sec::"
2728                     + Math.round((float)totalNumberOfFlows / timeInSeconds));
2729             } else {
2730                 ci.println("Total flows added in Thread:" + theadNumber + ": Flows/Sec::" + totalNumberOfFlows);
2731             }
2732         }
2733
2734     }
2735
2736     /*
2737      * usage testAllFlows <dp>
2738      * ex: _perfFlowTest 1
2739      */
2740     @SuppressWarnings({ "checkstyle:MethodName", "checkstyle:IllegalCatch" })
2741     public void _testAllFlows(final CommandInterpreter ci) {
2742         String dataPathID = ci.nextArgument();
2743         final int numberOfFlows = 82;
2744         if (dataPathID == null || dataPathID.trim().equals("")) {
2745             dataPathID = "1";
2746         }
2747         ci.println("*     Test All Flows    *");
2748         ci.println("*     dataPathID:::" + dataPathID + "");
2749         final String dataPath = "openflow:" + dataPathID;
2750         final String tableId = "0";
2751         final NodeBuilder tn = createTestNode(dataPath);
2752         FlowBuilder tf;
2753         for (int flow = 1; flow < numberOfFlows; flow++) {
2754             final String flowID = "f" + flow;
2755             try {
2756                 tf = createTestFlow(tn, flowID, tableId);
2757                 writeFlow(ci, tf, tn);
2758             } catch (RuntimeException e) {
2759                 ci.println("--Test Failed--Issue found while adding flow" + flow);
2760                 break;
2761             }
2762         }
2763     }
2764 }