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