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