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