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