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