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