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