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