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