Bug 1596 - OpenflowpluginTestCommandProvider stopped working
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowPluginBulkTransactionProvider.java
1 package org.opendaylight.openflowplugin.test;
2
3 import com.google.common.util.concurrent.CheckedFuture;
4 import com.google.common.util.concurrent.FutureCallback;
5 import com.google.common.util.concurrent.Futures;
6 import java.math.BigInteger;
7 import java.util.ArrayList;
8 import java.util.List;
9 import org.eclipse.osgi.framework.console.CommandInterpreter;
10 import org.eclipse.osgi.framework.console.CommandProvider;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
16 import org.opendaylight.controller.sal.binding.api.NotificationService;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.all.action._case.FloodAllActionBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.sw.path.action._case.SwPathActionBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.node.error.service.rev140410.NodeErrorListener;
106 import org.opendaylight.yangtools.concepts.Registration;
107 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
108 import org.osgi.framework.BundleContext;
109 import org.slf4j.Logger;
110 import org.slf4j.LoggerFactory;
111
112 //import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.M
113
114 public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
115
116     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestCommandProvider.class);
117     private DataBroker dataBroker;
118     private final BundleContext ctx;
119     private NodeBuilder testNode;
120     private ProviderContext pc;
121     private FlowBuilder testFlow;
122     private final String originalFlowName = "Foo";
123     private final NodeErrorListener nodeErrorListener = new NodeErrorListenerLoggingImpl();
124     private Registration listener1Reg;
125     private Registration listener2Reg;
126     private Node testNode12;
127     private final String originalGroupName = "Foo";
128     private static NotificationService notificationService;
129
130     public OpenflowPluginBulkTransactionProvider(BundleContext ctx) {
131         this.ctx = ctx;
132     }
133
134     public void onSessionInitiated(ProviderContext session) {
135         pc = session;
136         notificationService = session.getSALService(NotificationService.class);
137         listener2Reg = notificationService.registerNotificationListener(nodeErrorListener);
138         dataBroker = session.getSALService(DataBroker.class);
139         ctx.registerService(CommandProvider.class.getName(), this, null);
140         createTestFlow(createTestNode(null), null, null);
141     }
142
143     private NodeBuilder createTestNode(String nodeId) {
144         if (nodeId == null) {
145             nodeId = OpenflowpluginTestActivator.NODE_ID;
146         }
147         NodeRef nodeOne = createNodeRef(nodeId);
148         NodeBuilder builder = new NodeBuilder();
149         builder.setId(new NodeId(nodeId));
150         builder.setKey(new NodeKey(builder.getId()));
151         testNode = builder;
152         return builder;
153     }
154
155     private static NodeRef createNodeRef(String string) {
156         NodeKey key = new NodeKey(new NodeId(string));
157         InstanceIdentifier<Node> path = InstanceIdentifier.create(Nodes.class).child(Node.class, key);
158
159         return new NodeRef(path);
160     }
161
162     @Override
163     public String getHelp() {
164         return "No help";
165     }
166
167     private FlowBuilder createTestFlow(NodeBuilder nodeBuilder, String flowTypeArg, String tableId) {
168
169         FlowBuilder flow = new FlowBuilder();
170         long id = 123;
171
172         String flowType = flowTypeArg;
173         if (flowType == null) {
174             flowType = "f1";
175         }
176
177         switch (flowType) {
178             case "f1":
179                 id += 1;
180                 flow.setMatch(createMatch1().build());
181                 flow.setInstructions(createDecNwTtlInstructions().build());
182                 break;
183             case "f2":
184                 id += 2;
185                 flow.setMatch(createMatch2().build());
186                 flow.setInstructions(createDropInstructions().build());
187                 break;
188             case "f3":
189                 id += 3;
190                 flow.setMatch(createMatch3().build());
191                 flow.setInstructions(createDropInstructions().build());
192                 break;
193             case "f4":
194                 id += 4;
195                 flow.setMatch(createEthernetMatch().build());
196                 flow.setInstructions(createDropInstructions().build());
197                 break;
198             case "f5":
199                 id += 5;
200                 flow.setMatch(createMatch1().build());
201                 flow.setInstructions(createAppyActionInstruction().build());
202                 break;
203             case "f6":
204                 id += 6;
205                 flow.setMatch(createMatch1().build());
206                 flow.setInstructions(createGotoTableInstructions().build());
207                 break;
208             case "f7":
209                 id += 7;
210                 flow.setMatch(createMatch1().build());
211                 flow.setInstructions(createMeterInstructions().build());
212                 break;
213             case "f8":
214                 id += 8;
215                 flow.setMatch(createMatch1().build());
216                 flow.setInstructions(createAppyActionInstruction7().build());
217                 break;
218             case "f9":
219                 id += 9;
220                 flow.setMatch(createMatch1().build());
221                 flow.setInstructions(createAppyActionInstruction2().build());
222                 break;
223             case "f10":
224                 id += 10;
225                 flow.setMatch(createMatch1().build());
226                 flow.setInstructions(createAppyActionInstruction3().build());
227                 break;
228             case "f23":
229                 id += 23;
230                 flow.setMatch(createMatch1().build());
231                 flow.setInstructions(createAppyActionInstruction16().build());
232                 break;
233             case "f230":
234                 id += 23;
235                 flow.setMatch(createMatch1().build());
236                 flow.setInstructions(createAppyActionInstruction160().build());
237                 break;
238             case "f34":
239                 id += 34;
240                 flow.setMatch(createMatch1().build());
241                 flow.setInstructions(createAppyActionInstruction26().build());
242                 break;
243             case "f35":
244                 id += 35;
245                 flow.setMatch(createMatch1().build());
246                 flow.setInstructions(createAppyActionInstruction27().build());
247                 break;
248             case "f36":
249                 id += 36;
250                 flow.setMatch(createMatch1().build());
251                 flow.setInstructions(createAppyActionInstruction28().build());
252                 break;
253             case "f42":
254                 id += 42;
255                 flow.setMatch(createMatch1().build());
256                 flow.setInstructions(createAppyActionInstruction34().build());
257                 break;
258             case "f43":
259                 id += 43;
260                 flow.setMatch(createICMPv6Match().build());
261                 flow.setInstructions(createDecNwTtlInstructions().build());
262                 break;
263             case "f44":
264                 id += 44;
265                 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
266                 flow.setInstructions(createDropInstructions().build());
267                 break;
268             case "f45":
269                 id += 45;
270                 flow.setMatch(createMetadataMatch().build());
271                 flow.setInstructions(createDropInstructions().build());
272                 break;
273             case "f46":
274                 id += 46;
275                 flow.setMatch(createL3IPv6Match().build());
276                 flow.setInstructions(createDecNwTtlInstructions().build());
277                 break;
278             case "f81":
279                 id += 81;
280                 flow.setMatch(createLLDPMatch().build());
281                 flow.setInstructions(createSentToControllerInstructions().build());
282                 break;
283
284             case "f82":
285                 id += 1;
286                 flow.setMatch(createMatch1().build());
287                 flow.setInstructions(createDropInstructions().build());
288                 break;
289             case "f83":
290                 id += 2;
291                 flow.setMatch(createMatch2().build());
292                 flow.setInstructions(createDecNwTtlInstructions().build());
293                 break;
294             case "f84":
295                 id += 3;
296                 flow.setMatch(createMatch3().build());
297                 flow.setInstructions(createDecNwTtlInstructions().build());
298                 break;
299             case "f85":
300                 id += 4;
301                 flow.setMatch(createEthernetMatch().build());
302                 flow.setInstructions(createMeterInstructions().build());
303                 break;
304             case "f86":
305                 id += 6;
306                 flow.setMatch(createMatch1().build());
307                 flow.setInstructions(createDecNwTtlInstructions().build());
308                 break;
309             case "f87":
310                 id += 12;
311                 flow.setMatch(createMatch1().build());
312                 flow.setInstructions(createAppyActionInstruction7().build());
313                 break;
314             case "f88":
315                 id += 13;
316                 flow.setMatch(createEthernetMatch().build());
317                 flow.setInstructions(createAppyActionInstruction6().build());
318                 break;
319             case "f89":
320                 id += 14;
321                 flow.setMatch(createEthernetMatch().build());
322                 flow.setInstructions(createAppyActionInstruction7().build());
323                 break;
324             case "f90":
325                 id += 15;
326                 flow.setMatch(createMatch1().build());
327                 flow.setInstructions(createAppyActionInstruction9().build());
328                 break;
329             case "f91":
330                 id += 7;
331                 flow.setMatch(createMatch1().build());
332                 flow.setInstructions(createAppyActionInstruction9().build());
333                 break;
334             case "f92":
335                 id += 8;
336                 flow.setMatch(createMatch1().build());
337                 flow.setInstructions(createAppyActionInstruction6().build());
338                 break;
339             case "f93":
340                 id += 9;
341                 flow.setMatch(createMatch1().build());
342                 flow.setInstructions(createDecNwTtlInstructions().build());
343                 break;
344             case "f94":
345                 id += 10;
346                 flow.setMatch(createMatch1().build());
347                 flow.setInstructions(createDecNwTtlInstructions().build());
348                 break;
349             case "f95":
350                 id += 42;
351                 flow.setMatch(createMatch1().build());
352                 flow.setInstructions(createDecNwTtlInstructions().build());
353                 break;
354             case "f96":
355                 id += 43;
356                 flow.setMatch(createICMPv6Match().build());
357                 flow.setInstructions(createDropInstructions().build());
358                 break;
359             case "f97":
360                 id += 44;
361                 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
362                 flow.setInstructions(createMeterInstructions().build());
363                 break;
364             case "f98":
365                 id += 45;
366                 flow.setMatch(createMetadataMatch().build());
367                 flow.setInstructions(createAppyActionInstruction6().build());
368                 break;
369             case "f99":
370                 id += 34;
371                 flow.setMatch(createMatch1().build());
372                 flow.setInstructions(createAppyActionInstruction6().build());
373                 break;
374             case "f100":
375                 id += 35;
376                 flow.setMatch(createMatch1().build());
377                 flow.setInstructions(createAppyActionInstruction7().build());
378                 break;
379             case "f101":
380                 id += 36;
381                 flow.setMatch(createMatch1().build());
382                 flow.setInstructions(createAppyActionInstruction8().build());
383                 break;
384             case "f700":
385                 id += 3;
386                 flow.setMatch(createMatch3().build());
387                 flow.setInstructions(createMeterInstructions().build());
388                 break;
389             case "f800":
390                 id += 8;
391                 flow.setMatch(createMatch1000().build());
392                 flow.setInstructions(createAppyActionInstruction6().build());
393                 break;
394             case "f900":
395                 id += 5;
396                 flow.setMatch(createMatch1000().build());
397                 flow.setInstructions(createAppyActionInstruction2().build());
398                 break;
399             case "f1000":
400                 id += 10;
401                 flow.setMatch(createMatch1000().build());
402                 flow.setInstructions(createAppyActionInstruction3().build());
403                 break;
404             default:
405                 LOG.warn("flow type not understood: {}", flowType);
406         }
407
408         FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
409         if (null == flow.isBarrier()) {
410             flow.setBarrier(Boolean.FALSE);
411         }
412         // flow.setBufferId(new Long(12));
413         BigInteger value = new BigInteger("10", 10);
414         BigInteger outputPort = new BigInteger("4294967295", 10);
415         flow.setCookie(new FlowCookie(value));
416         flow.setCookieMask(new FlowCookie(value));
417         flow.setHardTimeout(0);
418         flow.setIdleTimeout(0);
419         flow.setInstallHw(false);
420         flow.setStrict(false);
421         flow.setContainerName(null);
422         flow.setFlags(new FlowModFlags(false, false, false, false, true));
423         flow.setId(new FlowId("12"));
424         flow.setTableId(getTableId(tableId));
425         flow.setOutGroup(new Long("4294967295"));
426         // set outport to OFPP_NONE (65535) to disable remove restriction for
427         // flow
428         flow.setOutPort(outputPort);
429
430         flow.setKey(key);
431         flow.setPriority(2);
432         flow.setFlowName(originalFlowName + "X" + flowType);
433         testFlow = flow;
434         return flow;
435     }
436
437     private short getTableId(String tableId) {
438         short table = 2;
439         try {
440             table = Short.parseShort(tableId);
441         } catch (Exception ex) {
442             // ignore exception and continue with default value
443         }
444
445         return table;
446
447     }
448
449     private void createTestNode() {
450         NodeRef nodeOne = createNodeRef(OpenflowpluginTestActivator.NODE_ID);
451         NodeBuilder builder = new NodeBuilder();
452         builder.setId(new NodeId(OpenflowpluginTestActivator.NODE_ID));
453         builder.setKey(new NodeKey(builder.getId()));
454         testNode12 = builder.build();
455     }
456
457     public void _addFlows(CommandInterpreter ci) {
458         NodeBuilder tn = createTestNode(ci.nextArgument());
459         String flowtype = ci.nextArgument();
460         Integer flowcnt = Integer.parseInt(flowtype);
461         FlowBuilder tf;
462         FlowBuilder tf1;
463         FlowBuilder tf2;
464         FlowBuilder tf3;
465         switch (flowcnt) {
466             case 1:
467                 tf = createTestFlow(tn, "f1", "10");
468                 tf1 = createTestFlow(tn, "f2", "11");
469                 tf2 = createTestFlow(tn, "f3", "12");
470                 tf3 = createTestFlow(tn, "f4", "13");
471                 break;
472             case 2:
473                 tf = createTestFlow(tn, "f3", "3");
474                 tf1 = createTestFlow(tn, "f4", "4");
475                 tf2 = createTestFlow(tn, "f5", "5");
476                 tf3 = createTestFlow(tn, "f6", "6");
477                 break;
478             case 3:
479                 tf = createTestFlow(tn, "f7", "7");
480                 tf1 = createTestFlow(tn, "f8", "8");
481                 tf2 = createTestFlow(tn, "f9", "9");
482                 tf3 = createTestFlow(tn, "f10", "10");
483                 break;
484             case 4:
485                 // -ve scenario
486                 tf = createTestFlow(tn, "f23", "3");
487                 tf1 = createTestFlow(tn, "f34", "4");
488                 tf2 = createTestFlow(tn, "f35", "5");
489                 tf3 = createTestFlow(tn, "f36", "6");
490                 break;
491             case 5:
492                 // +ve scenario
493                 // modify case 6 -ve
494                 tf = createTestFlow(tn, "f230", "3");
495                 tf1 = createTestFlow(tn, "f34", "4");
496                 tf2 = createTestFlow(tn, "f35", "5");
497                 tf3 = createTestFlow(tn, "f36", "6");
498                 break;
499
500             default:
501                 tf = createTestFlow(tn, "f42", "42");
502                 tf1 = createTestFlow(tn, "f43", "43");
503                 tf2 = createTestFlow(tn, "f44", "44");
504                 tf3 = createTestFlow(tn, "f45", "45");
505
506         }
507         writeFlow(ci, tf, tf1, tf2, tf3, tn);
508     }
509
510     private InstanceIdentifier<Node> nodeBuilderToInstanceId(NodeBuilder node) {
511         return InstanceIdentifier.create(Nodes.class).child(Node.class, node.getKey());
512     }
513
514     public void _modifyFlows(CommandInterpreter ci) {
515         NodeBuilder tn = createTestNode(ci.nextArgument());
516         String flowtype = ci.nextArgument();
517         Integer flowcnt = Integer.parseInt(flowtype);
518         FlowBuilder tf;
519         FlowBuilder tf1;
520         FlowBuilder tf2;
521         FlowBuilder tf3;
522         switch (flowcnt) {
523             case 1:
524                 tf = createTestFlow(tn, "f82", "10");
525                 tf1 = createTestFlow(tn, "f83", "11");
526                 tf2 = createTestFlow(tn, "f84", "12");
527                 tf3 = createTestFlow(tn, "f85", "13");
528                 break;
529             case 2:
530                 tf = createTestFlow(tn, "f700", "3");
531                 tf1 = createTestFlow(tn, "f4", "4");
532                 tf2 = createTestFlow(tn, "f900", "5");
533                 tf3 = createTestFlow(tn, "f86", "6");
534                 break;
535             case 3:
536                 // +
537                 tf = createTestFlow(tn, "f91", "7");
538                 tf1 = createTestFlow(tn, "f92", "8");
539                 tf2 = createTestFlow(tn, "f93", "9");
540                 tf3 = createTestFlow(tn, "f94", "10");
541                 break;
542             case 4:
543                 // +ve scenario
544                 tf = createTestFlow(tn, "f230", "3");
545                 tf1 = createTestFlow(tn, "f99", "4");
546                 tf2 = createTestFlow(tn, "f100", "5");
547                 tf3 = createTestFlow(tn, "f101", "6");
548                 break;
549             case 5:
550                 // -
551                 tf = createTestFlow(tn, "f23", "3");
552                 tf1 = createTestFlow(tn, "f99", "4");
553                 tf2 = createTestFlow(tn, "f100", "5");
554                 tf3 = createTestFlow(tn, "f101", "6");
555                 break;
556
557             default:
558                 tf = createTestFlow(tn, "f87", "12");
559                 tf1 = createTestFlow(tn, "f88", "13");
560                 tf2 = createTestFlow(tn, "f89", "14");
561                 tf3 = createTestFlow(tn, "f90", "15");
562
563         }
564
565         writeFlow(ci, tf, tf1, tf2, tf3, tn);
566
567     }
568
569     public void _removeFlows(final CommandInterpreter ci) {
570         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
571         NodeBuilder tn = createTestNode(ci.nextArgument());
572         String flowtype = ci.nextArgument();
573         Integer flowcnt = Integer.parseInt(flowtype);
574         FlowBuilder tf = null;
575         FlowBuilder tf1 = null;
576         FlowBuilder tf2 = null;
577         FlowBuilder tf3 = null;
578         switch (flowcnt) {
579             case 1:
580                 // add case 1
581                 tf = createTestFlow(tn, "f1", "10");
582                 tf1 = createTestFlow(tn, "f2", "11");
583                 tf2 = createTestFlow(tn, "f3", "12");
584                 tf3 = createTestFlow(tn, "f4", "13");
585                 break;
586             case 2:
587                 // modify case 1
588                 tf = createTestFlow(tn, "f82", "10");
589                 tf1 = createTestFlow(tn, "f83", "11");
590                 tf2 = createTestFlow(tn, "f84", "12");
591                 tf3 = createTestFlow(tn, "f85", "13");
592                 break;
593             case 3:
594                 // add case 2
595                 tf = createTestFlow(tn, "f3", "3");
596                 tf1 = createTestFlow(tn, "f4", "4");
597                 tf2 = createTestFlow(tn, "f5", "5");
598                 tf3 = createTestFlow(tn, "f6", "6");
599                 break;
600             case 4:
601                 // modify case 2
602                 tf = createTestFlow(tn, "f700", "3");
603                 tf1 = createTestFlow(tn, "f4", "4");
604                 tf2 = createTestFlow(tn, "f900", "5");
605                 tf3 = createTestFlow(tn, "f86", "6");
606                 break;
607             case 5:
608                 // add case 3
609                 tf = createTestFlow(tn, "f7", "7");
610                 tf1 = createTestFlow(tn, "f8", "8");
611                 tf2 = createTestFlow(tn, "f9", "9");
612                 tf3 = createTestFlow(tn, "f10", "10");
613                 break;
614             case 6:
615                 // modify case 3
616                 tf = createTestFlow(tn, "f91", "7");
617                 tf1 = createTestFlow(tn, "f92", "8");
618                 tf2 = createTestFlow(tn, "f93", "9");
619                 tf3 = createTestFlow(tn, "f94", "10");
620                 break;
621             case 7:
622                 // -ve scenario
623                 tf = createTestFlow(tn, "f23", "3");
624                 tf1 = createTestFlow(tn, "f34", "4");
625                 tf2 = createTestFlow(tn, "f35", "5");
626                 tf3 = createTestFlow(tn, "f36", "6");
627                 break;
628             case 8:
629                 // +ve scenario
630                 // modify case 6 -ve
631                 tf = createTestFlow(tn, "f23", "3");
632                 tf1 = createTestFlow(tn, "f99", "4");
633                 tf2 = createTestFlow(tn, "f100", "5");
634                 tf3 = createTestFlow(tn, "f101", "6");
635                 break;
636             case 9:
637                 // modify case 6
638                 tf = createTestFlow(tn, "f700", "7");
639                 tf1 = createTestFlow(tn, "f230", "23");
640                 tf2 = createTestFlow(tn, "f900", "9");
641                 tf3 = createTestFlow(tn, "f1000", "10");
642                 break;
643         }
644
645         InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
646                 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
647                 .child(Flow.class, tf.getKey());
648         modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
649         modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
650         modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
651         InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
652                 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf1.getTableId()))
653                 .child(Flow.class, tf1.getKey());
654         modification.delete(LogicalDatastoreType.OPERATIONAL, path2);
655         modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
656         modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
657
658         InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
659                 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf2.getTableId()))
660                 .child(Flow.class, tf2.getKey());
661         modification.delete(LogicalDatastoreType.OPERATIONAL, path3);
662         modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
663         modification.delete(LogicalDatastoreType.CONFIGURATION, path3);
664         InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
665                 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf3.getTableId()))
666                 .child(Flow.class, tf3.getKey());
667         modification.delete(LogicalDatastoreType.OPERATIONAL, path4);
668         modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
669         modification.delete(LogicalDatastoreType.CONFIGURATION, path4);
670         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
671         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
672             @Override
673             public void onSuccess(Void aVoid) {
674                 ci.println("Status of Group Data Loaded Transaction: success.");
675             }
676
677             @Override
678             public void onFailure(Throwable throwable) {
679                 LOG.error(throwable.getMessage(), throwable);
680                 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
681             }
682         });
683
684     }
685
686     private void writeFlow(final CommandInterpreter ci, FlowBuilder flow, FlowBuilder flow1, FlowBuilder flow2,
687                            FlowBuilder flow3, NodeBuilder nodeBuilder) {
688         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
689         InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class)
690                 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
691                 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey());
692         modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
693         modification.merge(LogicalDatastoreType.OPERATIONAL, path1, flow.build(), true);
694         modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
695         modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
696         InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class)
697                 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
698                 .child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.getKey());
699         modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
700         modification.merge(LogicalDatastoreType.OPERATIONAL, path2, flow1.build(), true);
701         modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
702         modification.merge(LogicalDatastoreType.CONFIGURATION, path2, flow1.build(), true);
703
704         InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class)
705                 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
706                 .child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.getKey());
707         modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
708         modification.merge(LogicalDatastoreType.OPERATIONAL, path3, flow2.build(), true);
709         modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
710         modification.merge(LogicalDatastoreType.CONFIGURATION, path3, flow2.build(), true);
711
712         InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class)
713                 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
714                 .child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.getKey());
715         modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
716         modification.merge(LogicalDatastoreType.OPERATIONAL, path4, flow3.build(), true);
717         modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
718         modification.merge(LogicalDatastoreType.CONFIGURATION, path4, flow3.build(), true);
719         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
720         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
721             @Override
722             public void onSuccess(Void aVoid) {
723                 ci.println("Status of Group Data Loaded Transaction: success.");
724             }
725
726             @Override
727             public void onFailure(Throwable throwable) {
728                 LOG.error(throwable.getMessage(), throwable);
729                 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
730             }
731         });
732     }
733
734     /**
735      * @return
736      */
737     private static InstructionsBuilder createDecNwTtlInstructions() {
738         DecNwTtlBuilder ta = new DecNwTtlBuilder();
739         DecNwTtl decNwTtl = ta.build();
740         ActionBuilder ab = new ActionBuilder();
741         ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
742
743         // Add our drop action to a list
744         List<Action> actionList = new ArrayList<Action>();
745         actionList.add(ab.build());
746
747         // Create an Apply Action
748         ApplyActionsBuilder aab = new ApplyActionsBuilder();
749         aab.setAction(actionList);
750
751         // Wrap our Apply Action in an Instruction
752         InstructionBuilder ib = new InstructionBuilder();
753         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
754         ib.setKey(new InstructionKey(0));
755         ib.setOrder(0);
756
757         // Put our Instruction in a list of Instructions
758         InstructionsBuilder isb = new InstructionsBuilder();
759         List<Instruction> instructions = new ArrayList<Instruction>();
760         instructions.add(ib.build());
761         isb.setInstruction(instructions);
762         return isb;
763     }
764
765     /**
766      * @return
767      */
768     private static InstructionsBuilder createMeterInstructions() {
769
770         MeterBuilder aab = new MeterBuilder();
771         aab.setMeterId(new MeterId(new Long(1)));
772
773         InstructionBuilder ib = new InstructionBuilder();
774         ib.setInstruction(new MeterCaseBuilder().setMeter(aab.build()).build());
775
776         // Put our Instruction in a list of Instructions
777         InstructionsBuilder isb = new InstructionsBuilder();
778         List<Instruction> instructions = new ArrayList<Instruction>();
779         instructions.add(ib.build());
780         isb.setInstruction(instructions);
781         return isb;
782     }
783
784     private static InstructionsBuilder createGotoTableInstructions() {
785
786         GoToTableBuilder aab = new GoToTableBuilder();
787         aab.setTableId((short) 2);
788
789         InstructionBuilder ib = new InstructionBuilder();
790         ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(aab.build()).build());
791
792         // Put our Instruction in a list of Instructions
793         InstructionsBuilder isb = new InstructionsBuilder();
794         List<Instruction> instructions = new ArrayList<Instruction>();
795         instructions.add(ib.build());
796         isb.setInstruction(instructions);
797         return isb;
798     }
799
800     private static InstructionsBuilder createDropInstructions() {
801         DropActionBuilder dab = new DropActionBuilder();
802         DropAction dropAction = dab.build();
803         ActionBuilder ab = new ActionBuilder();
804         ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
805
806         // Add our drop action to a list
807         List<Action> actionList = new ArrayList<Action>();
808         actionList.add(ab.build());
809
810         // Create an Apply Action
811         ApplyActionsBuilder aab = new ApplyActionsBuilder();
812         aab.setAction(actionList);
813
814         // Wrap our Apply Action in an Instruction
815         InstructionBuilder ib = new InstructionBuilder();
816         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
817
818         // Put our Instruction in a list of Instructions
819         InstructionsBuilder isb = new InstructionsBuilder();
820         List<Instruction> instructions = new ArrayList<Instruction>();
821         instructions.add(ib.build());
822         isb.setInstruction(instructions);
823         return isb;
824     }
825
826     private static InstructionsBuilder createAppyActionInstruction() {
827
828         List<Action> actionList = new ArrayList<Action>();
829         ActionBuilder ab = new ActionBuilder();
830         ControllerActionBuilder controller = new ControllerActionBuilder();
831         controller.setMaxLength(5);
832         ab.setAction(new ControllerActionCaseBuilder().setControllerAction(controller.build()).build());
833         actionList.add(ab.build());
834         // Create an Apply Action
835         ApplyActionsBuilder aab = new ApplyActionsBuilder();
836         aab.setAction(actionList);
837
838         // Wrap our Apply Action in an Instruction
839         InstructionBuilder ib = new InstructionBuilder();
840         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
841
842         // Put our Instruction in a list of Instructions
843         InstructionsBuilder isb = new InstructionsBuilder();
844         List<Instruction> instructions = new ArrayList<Instruction>();
845         instructions.add(ib.build());
846         isb.setInstruction(instructions);
847         return isb;
848     }
849
850     private static InstructionsBuilder createSentToControllerInstructions() {
851         List<Action> actionList = new ArrayList<Action>();
852         ActionBuilder ab = new ActionBuilder();
853
854         OutputActionBuilder output = new OutputActionBuilder();
855         output.setMaxLength(new Integer(0xffff));
856         Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
857         output.setOutputNodeConnector(value);
858         ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
859         ab.setOrder(0);
860         ab.setKey(new ActionKey(0));
861         actionList.add(ab.build());
862         // Create an Apply Action
863         ApplyActionsBuilder aab = new ApplyActionsBuilder();
864         aab.setAction(actionList);
865
866         // Wrap our Apply Action in an Instruction
867         InstructionBuilder ib = new InstructionBuilder();
868         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
869         ib.setOrder(0);
870         ib.setKey(new InstructionKey(0));
871
872         // Put our Instruction in a list of Instructions
873         InstructionsBuilder isb = new InstructionsBuilder();
874         List<Instruction> instructions = new ArrayList<Instruction>();
875         instructions.add(ib.build());
876         isb.setInstruction(instructions);
877         return isb;
878     }
879
880     private static InstructionsBuilder createAppyActionInstruction2() {
881
882         List<Action> actionList = new ArrayList<Action>();
883         ActionBuilder ab = new ActionBuilder();
884
885         PushMplsActionBuilder push = new PushMplsActionBuilder();
886         push.setEthernetType(new Integer(0x8847));
887         ab.setAction(new PushMplsActionCaseBuilder().setPushMplsAction(push.build()).build());
888         actionList.add(ab.build());
889         // Create an Apply Action
890         ApplyActionsBuilder aab = new ApplyActionsBuilder();
891         aab.setAction(actionList);
892
893         // Wrap our Apply Action in an Instruction
894         InstructionBuilder ib = new InstructionBuilder();
895         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
896
897         // Put our Instruction in a list of Instructions
898         InstructionsBuilder isb = new InstructionsBuilder();
899         List<Instruction> instructions = new ArrayList<Instruction>();
900         instructions.add(ib.build());
901         isb.setInstruction(instructions);
902         return isb;
903     }
904
905     private static InstructionsBuilder createAppyActionInstruction3() {
906
907         List<Action> actionList = new ArrayList<Action>();
908         ActionBuilder ab = new ActionBuilder();
909
910         PushPbbActionBuilder pbb = new PushPbbActionBuilder();
911         pbb.setEthernetType(new Integer(0x88E7));
912         ab.setAction(new PushPbbActionCaseBuilder().setPushPbbAction(pbb.build()).build());
913         actionList.add(ab.build());
914         // Create an Apply Action
915         ApplyActionsBuilder aab = new ApplyActionsBuilder();
916         aab.setAction(actionList);
917
918         // Wrap our Apply Action in an Instruction
919         InstructionBuilder ib = new InstructionBuilder();
920         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
921
922         // Put our Instruction in a list of Instructions
923         InstructionsBuilder isb = new InstructionsBuilder();
924         List<Instruction> instructions = new ArrayList<Instruction>();
925         instructions.add(ib.build());
926         isb.setInstruction(instructions);
927         return isb;
928     }
929
930     private static InstructionsBuilder createAppyActionInstruction6() {
931
932         List<Action> actionList = new ArrayList<Action>();
933         ActionBuilder ab = new ActionBuilder();
934
935         SetDlSrcActionBuilder src = new SetDlSrcActionBuilder();
936         src.setAddress(new MacAddress("00:05:b9:7c:81:5f"));
937         ab.setAction(new SetDlSrcActionCaseBuilder().setSetDlSrcAction(src.build()).build());
938         actionList.add(ab.build());
939
940         // Create an Apply Action
941         ApplyActionsBuilder aab = new ApplyActionsBuilder();
942         aab.setAction(actionList);
943
944         // Wrap our Apply Action in an Instruction
945         InstructionBuilder ib = new InstructionBuilder();
946         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
947
948         // Put our Instruction in a list of Instructions
949         InstructionsBuilder isb = new InstructionsBuilder();
950         List<Instruction> instructions = new ArrayList<Instruction>();
951         instructions.add(ib.build());
952         isb.setInstruction(instructions);
953         return isb;
954     }
955
956     private static InstructionsBuilder createAppyActionInstruction7() {
957
958         List<Action> actionList = new ArrayList<Action>();
959         ActionBuilder ab = new ActionBuilder();
960
961         SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
962         VlanId a = new VlanId(4012);
963         vl.setVlanId(a);
964         ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.build()).build());
965         actionList.add(ab.build());
966         // Create an Apply Action
967         ApplyActionsBuilder aab = new ApplyActionsBuilder();
968         aab.setAction(actionList);
969
970         // Wrap our Apply Action in an Instruction
971         InstructionBuilder ib = new InstructionBuilder();
972         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
973
974         // Put our Instruction in a list of Instructions
975         InstructionsBuilder isb = new InstructionsBuilder();
976         List<Instruction> instructions = new ArrayList<Instruction>();
977         instructions.add(ib.build());
978         isb.setInstruction(instructions);
979         return isb;
980     }
981
982     private static InstructionsBuilder createAppyActionInstruction8() {
983
984         List<Action> actionList = new ArrayList<Action>();
985         ActionBuilder ab = new ActionBuilder();
986
987         SetVlanPcpActionBuilder pcp = new SetVlanPcpActionBuilder();
988         VlanPcp pcp1 = new VlanPcp((short) 2);
989         pcp.setVlanPcp(pcp1);
990         ab.setAction(new SetVlanPcpActionCaseBuilder().setSetVlanPcpAction(pcp.build()).build());
991         actionList.add(ab.build());
992         // Create an Apply Action
993         ApplyActionsBuilder aab = new ApplyActionsBuilder();
994         aab.setAction(actionList);
995
996         // Wrap our Apply Action in an Instruction
997         InstructionBuilder ib = new InstructionBuilder();
998         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
999
1000         // Put our Instruction in a list of Instructions
1001         InstructionsBuilder isb = new InstructionsBuilder();
1002         List<Instruction> instructions = new ArrayList<Instruction>();
1003         instructions.add(ib.build());
1004         isb.setInstruction(instructions);
1005         return isb;
1006     }
1007
1008     private static InstructionsBuilder createAppyActionInstruction9() {
1009
1010         List<Action> actionList = new ArrayList<Action>();
1011         ActionBuilder ab = new ActionBuilder();
1012
1013         CopyTtlInBuilder ttlin = new CopyTtlInBuilder();
1014         ab.setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(ttlin.build()).build());
1015         actionList.add(ab.build());
1016         // Create an Apply Action
1017         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1018         aab.setAction(actionList);
1019
1020         // Wrap our Apply Action in an Instruction
1021         InstructionBuilder ib = new InstructionBuilder();
1022         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1023
1024         // Put our Instruction in a list of Instructions
1025         InstructionsBuilder isb = new InstructionsBuilder();
1026         List<Instruction> instructions = new ArrayList<Instruction>();
1027         instructions.add(ib.build());
1028         isb.setInstruction(instructions);
1029         return isb;
1030     }
1031
1032     private static InstructionsBuilder createAppyActionInstruction16() {
1033
1034         List<Action> actionList = new ArrayList<Action>();
1035         ActionBuilder ab = new ActionBuilder();
1036
1037         GroupActionBuilder groupActionB = new GroupActionBuilder();
1038         groupActionB.setGroupId(1L);
1039         groupActionB.setGroup("0");
1040         ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
1041         actionList.add(ab.build());
1042
1043         // Create an Apply Action
1044         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1045         aab.setAction(actionList);
1046
1047         // Wrap our Apply Action in an Instruction
1048         InstructionBuilder ib = new InstructionBuilder();
1049         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1050
1051         // Put our Instruction in a list of Instructions
1052         InstructionsBuilder isb = new InstructionsBuilder();
1053         List<Instruction> instructions = new ArrayList<Instruction>();
1054         instructions.add(ib.build());
1055         isb.setInstruction(instructions);
1056         return isb;
1057     }
1058
1059     private static InstructionsBuilder createAppyActionInstruction160() {
1060
1061         List<Action> actionList = new ArrayList<Action>();
1062         ActionBuilder ab = new ActionBuilder();
1063
1064         FloodAllActionBuilder fldall = new FloodAllActionBuilder();
1065         ab.setAction(new FloodAllActionCaseBuilder().setFloodAllAction(fldall.build()).build());
1066         actionList.add(ab.build());
1067         // Create an Apply Action
1068         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1069         aab.setAction(actionList);
1070
1071         // Wrap our Apply Action in an Instruction
1072         InstructionBuilder ib = new InstructionBuilder();
1073         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1074
1075         // Put our Instruction in a list of Instructions
1076         InstructionsBuilder isb = new InstructionsBuilder();
1077         List<Instruction> instructions = new ArrayList<Instruction>();
1078         instructions.add(ib.build());
1079         isb.setInstruction(instructions);
1080         return isb;
1081     }
1082
1083     private static InstructionsBuilder createAppyActionInstruction26() {
1084
1085         List<Action> actionList = new ArrayList<Action>();
1086         ActionBuilder ab = new ActionBuilder();
1087
1088         SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
1089         Ipv4Builder ipdst = new Ipv4Builder();
1090         Ipv4Prefix prefixdst = new Ipv4Prefix("10.0.0.21/24");
1091         ipdst.setIpv4Address(prefixdst);
1092         setNwDstActionBuilder.setAddress(ipdst.build());
1093         ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
1094         actionList.add(ab.build());
1095
1096         // Create an Apply Action
1097         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1098         aab.setAction(actionList);
1099
1100         // Wrap our Apply Action in an Instruction
1101         InstructionBuilder ib = new InstructionBuilder();
1102         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1103
1104         // Put our Instruction in a list of Instructions
1105         InstructionsBuilder isb = new InstructionsBuilder();
1106         List<Instruction> instructions = new ArrayList<Instruction>();
1107         instructions.add(ib.build());
1108         isb.setInstruction(instructions);
1109         return isb;
1110     }
1111
1112     private static InstructionsBuilder createAppyActionInstruction27() {
1113
1114         List<Action> actionList = new ArrayList<Action>();
1115         ActionBuilder ab = new ActionBuilder();
1116
1117         SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
1118         Ipv4Builder ipsrc = new Ipv4Builder();
1119         Ipv4Prefix prefixsrc = new Ipv4Prefix("10.0.23.21/24");
1120         ipsrc.setIpv4Address(prefixsrc);
1121         setNwsrcActionBuilder.setAddress(ipsrc.build());
1122         ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
1123         actionList.add(ab.build());
1124
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 createAppyActionInstruction28() {
1142
1143         List<Action> actionList = new ArrayList<Action>();
1144         ActionBuilder ab = new ActionBuilder();
1145
1146         SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
1147         setNwTosActionBuilder.setTos(8);
1148         ab.setAction(new SetNwTosActionCaseBuilder().setSetNwTosAction(setNwTosActionBuilder.build()).build());
1149         actionList.add(ab.build());
1150         // Create an Apply Action
1151         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1152         aab.setAction(actionList);
1153
1154         // Wrap our Apply Action in an Instruction
1155         InstructionBuilder ib = new InstructionBuilder();
1156         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1157
1158         // Put our Instruction in a list of Instructions
1159         InstructionsBuilder isb = new InstructionsBuilder();
1160         List<Instruction> instructions = new ArrayList<Instruction>();
1161         instructions.add(ib.build());
1162         isb.setInstruction(instructions);
1163         return isb;
1164     }
1165
1166     private static InstructionsBuilder createAppyActionInstruction34() {
1167
1168         List<Action> actionList = new ArrayList<Action>();
1169         ActionBuilder ab = new ActionBuilder();
1170
1171         SwPathActionBuilder swPathAction = new SwPathActionBuilder();
1172         ab.setAction(new SwPathActionCaseBuilder().setSwPathAction(swPathAction.build()).build());
1173         actionList.add(ab.build());
1174
1175         // Create an Apply Action
1176         ApplyActionsBuilder aab = new ApplyActionsBuilder();
1177         aab.setAction(actionList);
1178
1179         // Wrap our Apply Action in an Instruction
1180         InstructionBuilder ib = new InstructionBuilder();
1181         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1182
1183         // Put our Instruction in a list of Instructions
1184         InstructionsBuilder isb = new InstructionsBuilder();
1185         List<Instruction> instructions = new ArrayList<Instruction>();
1186         instructions.add(ib.build());
1187         isb.setInstruction(instructions);
1188         return isb;
1189     }
1190
1191     private static MatchBuilder createLLDPMatch() {
1192         MatchBuilder match = new MatchBuilder();
1193         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1194         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1195         ethTypeBuilder.setType(new EtherType(0x88ccL));
1196         eth.setEthernetType(ethTypeBuilder.build());
1197         match.setEthernetMatch(eth.build());
1198         return match;
1199     }
1200
1201     /**
1202      * @return
1203      */
1204     private static MatchBuilder createMatch1() {
1205         MatchBuilder match = new MatchBuilder();
1206         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1207         Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
1208         ipv4Match.setIpv4Destination(prefix);
1209         Ipv4Match i4m = ipv4Match.build();
1210         match.setLayer3Match(i4m);
1211
1212         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1213         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1214         ethTypeBuilder.setType(new EtherType(0x0800L));
1215         eth.setEthernetType(ethTypeBuilder.build());
1216         match.setEthernetMatch(eth.build());
1217         return match;
1218     }
1219
1220     private static MatchBuilder createMatch1000() {
1221         MatchBuilder match = new MatchBuilder();
1222         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1223         Ipv4Prefix prefix = new Ipv4Prefix("10.1.1.1/24");
1224         ipv4Match.setIpv4Destination(prefix);
1225         Ipv4Match i4m = ipv4Match.build();
1226         match.setLayer3Match(i4m);
1227
1228         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1229         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1230         ethTypeBuilder.setType(new EtherType(0x0800L));
1231         eth.setEthernetType(ethTypeBuilder.build());
1232         match.setEthernetMatch(eth.build());
1233         return match;
1234     }
1235
1236     /**
1237      * @return
1238      */
1239     private static MatchBuilder createMatch2() {
1240         MatchBuilder match = new MatchBuilder();
1241         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1242         Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1");
1243         ipv4Match.setIpv4Source(prefix);
1244         Ipv4Match i4m = ipv4Match.build();
1245         match.setLayer3Match(i4m);
1246
1247         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1248         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1249         ethTypeBuilder.setType(new EtherType(0x0800L));
1250         eth.setEthernetType(ethTypeBuilder.build());
1251         match.setEthernetMatch(eth.build());
1252         return match;
1253     }
1254
1255     /**
1256      * @return
1257      */
1258     private static MatchBuilder createMatch3() {
1259         MatchBuilder match = new MatchBuilder();
1260         EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
1261         EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
1262         ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
1263         ethernetMatch.setEthernetSource(ethSourceBuilder.build());
1264         match.setEthernetMatch(ethernetMatch.build());
1265
1266         return match;
1267     }
1268
1269     private static MatchBuilder createMatch33() {
1270
1271         MatchBuilder match = new MatchBuilder();
1272         Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1273         Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.10");
1274         ipv4Match.setIpv4Source(prefix);
1275         Ipv4Match i4m = ipv4Match.build();
1276         match.setLayer3Match(i4m);
1277
1278         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1279         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1280         ethTypeBuilder.setType(new EtherType(0xfffeL));
1281         eth.setEthernetType(ethTypeBuilder.build());
1282         match.setEthernetMatch(eth.build());
1283         return match;
1284     }
1285
1286     private static MatchBuilder createInphyportMatch(NodeId nodeId) {
1287         MatchBuilder match = new MatchBuilder();
1288         match.setInPort(new NodeConnectorId(nodeId + ":202"));
1289         match.setInPhyPort(new NodeConnectorId(nodeId + ":10122"));
1290         return match;
1291     }
1292
1293     private static MatchBuilder createEthernetMatch() {
1294         MatchBuilder match = new MatchBuilder();
1295
1296         byte[] mask1 = new byte[]{(byte) -1, (byte) -1, 0, 0, 0, 0};
1297         byte[] mask2 = new byte[]{(byte) -1, (byte) -1, (byte) -1, 0, 0, 0};
1298
1299         EthernetMatchBuilder ethmatch = new EthernetMatchBuilder(); // ethernettype
1300         // match
1301         EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
1302         EtherType type = new EtherType(0x0800L);
1303         ethmatch.setEthernetType(ethtype.setType(type).build());
1304
1305         EthernetDestinationBuilder ethdest = new EthernetDestinationBuilder(); // ethernet
1306         // macaddress
1307         // match
1308         MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
1309         ethdest.setAddress(macdest);
1310         // ethdest.setMask(mask1);
1311
1312         ethmatch.setEthernetDestination(ethdest.build());
1313
1314         EthernetSourceBuilder ethsrc = new EthernetSourceBuilder();
1315         MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
1316         ethsrc.setAddress(macsrc);
1317         // ethsrc.setMask(mask2);
1318
1319         ethmatch.setEthernetSource(ethsrc.build());
1320         match.setEthernetMatch(ethmatch.build());
1321         return match;
1322
1323     }
1324
1325     /**
1326      * @return
1327      */
1328     private static MatchBuilder createL3IPv6Match() {
1329         MatchBuilder match = new MatchBuilder();
1330
1331         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1332         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1333         ethTypeBuilder.setType(new EtherType(0x86ddL));
1334         eth.setEthernetType(ethTypeBuilder.build());
1335         match.setEthernetMatch(eth.build());
1336
1337         Ipv6Prefix dstip6 = new Ipv6Prefix("2002::2/64");
1338         Ipv6Prefix srcip6 = new Ipv6Prefix("2001:0:0:0:0:0:0:1/56");
1339         Ipv6Address ndtarget = new Ipv6Address("2001:db8:0:1:fd97:f9f0:a810:782e");
1340         MacAddress ndsll = new MacAddress("c2:00:54:f5:00:00");
1341         MacAddress ndtll = new MacAddress("00:0c:29:0e:4c:67");
1342         Ipv6ExtHeaderBuilder nextheader = new Ipv6ExtHeaderBuilder();
1343         nextheader.setIpv6Exthdr(58);
1344         Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
1345         Ipv6FlowLabel label = new Ipv6FlowLabel(10028L);
1346         ipv6label.setIpv6Flabel(label);
1347         // ipv6label.setFlabelMask(new byte[] { 0, 1, -1, -1 });
1348
1349         Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1350         // match
1351         icmpv6match.setIcmpv6Type((short) 135);
1352         icmpv6match.setIcmpv6Code((short) 0);
1353         match.setIcmpv6Match(icmpv6match.build());
1354
1355         Ipv6MatchBuilder ipv6match = new Ipv6MatchBuilder();
1356         // ipv6match.setIpv6Source(srcip6);
1357         // ipv6match.setIpv6Destination(dstip6);
1358         // ipv6match.setIpv6ExtHeader(nextheader.build());
1359         ipv6match.setIpv6NdSll(ndsll);
1360         ipv6match.setIpv6NdTll(ndtll);
1361         // ipv6match.setIpv6NdTarget(ndtarget);
1362         ipv6match.setIpv6Label(ipv6label.build());
1363
1364         match.setLayer3Match(ipv6match.build());
1365
1366         return match;
1367     }
1368
1369     /**
1370      * @return
1371      */
1372     private static MatchBuilder createICMPv6Match() {
1373
1374         MatchBuilder match = new MatchBuilder();
1375         EthernetMatchBuilder eth = new EthernetMatchBuilder();
1376         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1377         ethTypeBuilder.setType(new EtherType(0x86ddL));
1378         eth.setEthernetType(ethTypeBuilder.build());
1379         match.setEthernetMatch(eth.build());
1380
1381         IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
1382         ipmatch.setIpProtocol((short) 58);
1383         match.setIpMatch(ipmatch.build());
1384
1385         Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1386         // match
1387         icmpv6match.setIcmpv6Type((short) 135);
1388         icmpv6match.setIcmpv6Code((short) 1);
1389         match.setIcmpv6Match(icmpv6match.build());
1390
1391         return match;
1392     }
1393
1394     /**
1395      * @return
1396      */
1397     private static MatchBuilder createMetadataMatch() {
1398         MatchBuilder match = new MatchBuilder();
1399         byte[] metamask = new byte[]{(byte) -1, (byte) -1, (byte) -1, 0, 0, 0, (byte) 1, (byte) 1};
1400         MetadataBuilder metadata = new MetadataBuilder(); // metadata match
1401         metadata.setMetadata(BigInteger.valueOf(500L));
1402         // metadata.setMetadataMask(metamask);
1403         match.setMetadata(metadata.build());
1404
1405         return match;
1406     }
1407
1408 }