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