2 * Copyright (c) 2014, 2015 Ericsson, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.test;
11 import com.google.common.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.MoreExecutors;
15 import java.math.BigInteger;
16 import java.util.ArrayList;
17 import java.util.List;
18 import org.eclipse.osgi.framework.console.CommandInterpreter;
19 import org.eclipse.osgi.framework.console.CommandProvider;
20 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
21 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
22 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
23 import org.opendaylight.controller.sal.binding.api.NotificationService;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.all.action._case.FloodAllActionBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.sw.path.action._case.SwPathActionBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
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.Nodes;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.node.error.service.rev140410.NodeErrorListener;
110 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
111 import org.osgi.framework.BundleContext;
112 import org.slf4j.Logger;
113 import org.slf4j.LoggerFactory;
115 @SuppressWarnings("checkstyle:MethodName")
116 public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
118 private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginBulkTransactionProvider.class);
119 private final DataBroker dataBroker;
120 private final BundleContext ctx;
121 private final String originalFlowName = "Foo";
122 private final NodeErrorListener nodeErrorListener = new NodeErrorListenerLoggingImpl();
123 private final NotificationService notificationService;
125 public OpenflowPluginBulkTransactionProvider(DataBroker dataBroker, NotificationService notificationService,
127 this.dataBroker = dataBroker;
128 this.notificationService = notificationService;
133 notificationService.registerNotificationListener(nodeErrorListener);
134 ctx.registerService(CommandProvider.class.getName(), this, null);
135 createTestFlow(createTestNode(null), null, null);
138 private NodeBuilder createTestNode(String nodeId) {
139 if (nodeId == null) {
140 nodeId = OpenflowpluginTestActivator.NODE_ID;
142 NodeBuilder builder = new NodeBuilder();
143 builder.setId(new NodeId(nodeId));
144 builder.withKey(new NodeKey(builder.getId()));
149 public String getHelp() {
153 private FlowBuilder createTestFlow(NodeBuilder nodeBuilder, String flowTypeArg, String tableId) {
155 FlowBuilder flow = new FlowBuilder();
158 String flowType = flowTypeArg;
159 if (flowType == null) {
166 flow.setMatch(createMatch1().build());
167 flow.setInstructions(createDecNwTtlInstructions().build());
171 flow.setMatch(createMatch2().build());
172 flow.setInstructions(createDropInstructions().build());
176 flow.setMatch(createMatch3().build());
177 flow.setInstructions(createDropInstructions().build());
181 flow.setMatch(createEthernetMatch().build());
182 flow.setInstructions(createDropInstructions().build());
186 flow.setMatch(createMatch1().build());
187 flow.setInstructions(createAppyActionInstruction().build());
191 flow.setMatch(createMatch1().build());
192 flow.setInstructions(createGotoTableInstructions().build());
196 flow.setMatch(createMatch1().build());
197 flow.setInstructions(createMeterInstructions().build());
201 flow.setMatch(createMatch1().build());
202 flow.setInstructions(createAppyActionInstruction7().build());
206 flow.setMatch(createMatch1().build());
207 flow.setInstructions(createAppyActionInstruction2().build());
211 flow.setMatch(createMatch1().build());
212 flow.setInstructions(createAppyActionInstruction3().build());
216 flow.setMatch(createMatch1().build());
217 flow.setInstructions(createAppyActionInstruction16().build());
221 flow.setMatch(createMatch1().build());
222 flow.setInstructions(createAppyActionInstruction160().build());
226 flow.setMatch(createMatch1().build());
227 flow.setInstructions(createAppyActionInstruction26().build());
231 flow.setMatch(createMatch1().build());
232 flow.setInstructions(createAppyActionInstruction27().build());
236 flow.setMatch(createMatch1().build());
237 flow.setInstructions(createAppyActionInstruction28().build());
241 flow.setMatch(createMatch1().build());
242 flow.setInstructions(createAppyActionInstruction34().build());
246 flow.setMatch(createICMPv6Match().build());
247 flow.setInstructions(createDecNwTtlInstructions().build());
251 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
252 flow.setInstructions(createDropInstructions().build());
256 flow.setMatch(createMetadataMatch().build());
257 flow.setInstructions(createDropInstructions().build());
261 flow.setMatch(createL3IPv6Match().build());
262 flow.setInstructions(createDecNwTtlInstructions().build());
266 flow.setMatch(createLLDPMatch().build());
267 flow.setInstructions(createSentToControllerInstructions().build());
272 flow.setMatch(createMatch1().build());
273 flow.setInstructions(createDropInstructions().build());
277 flow.setMatch(createMatch2().build());
278 flow.setInstructions(createDecNwTtlInstructions().build());
282 flow.setMatch(createMatch3().build());
283 flow.setInstructions(createDecNwTtlInstructions().build());
287 flow.setMatch(createEthernetMatch().build());
288 flow.setInstructions(createMeterInstructions().build());
292 flow.setMatch(createMatch1().build());
293 flow.setInstructions(createDecNwTtlInstructions().build());
297 flow.setMatch(createMatch1().build());
298 flow.setInstructions(createAppyActionInstruction7().build());
302 flow.setMatch(createEthernetMatch().build());
303 flow.setInstructions(createAppyActionInstruction6().build());
307 flow.setMatch(createEthernetMatch().build());
308 flow.setInstructions(createAppyActionInstruction7().build());
312 flow.setMatch(createMatch1().build());
313 flow.setInstructions(createAppyActionInstruction9().build());
317 flow.setMatch(createMatch1().build());
318 flow.setInstructions(createAppyActionInstruction9().build());
322 flow.setMatch(createMatch1().build());
323 flow.setInstructions(createAppyActionInstruction6().build());
327 flow.setMatch(createMatch1().build());
328 flow.setInstructions(createDecNwTtlInstructions().build());
332 flow.setMatch(createMatch1().build());
333 flow.setInstructions(createDecNwTtlInstructions().build());
337 flow.setMatch(createMatch1().build());
338 flow.setInstructions(createDecNwTtlInstructions().build());
342 flow.setMatch(createICMPv6Match().build());
343 flow.setInstructions(createDropInstructions().build());
347 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
348 flow.setInstructions(createMeterInstructions().build());
352 flow.setMatch(createMetadataMatch().build());
353 flow.setInstructions(createAppyActionInstruction6().build());
357 flow.setMatch(createMatch1().build());
358 flow.setInstructions(createAppyActionInstruction6().build());
362 flow.setMatch(createMatch1().build());
363 flow.setInstructions(createAppyActionInstruction7().build());
367 flow.setMatch(createMatch1().build());
368 flow.setInstructions(createAppyActionInstruction8().build());
372 flow.setMatch(createMatch3().build());
373 flow.setInstructions(createMeterInstructions().build());
377 flow.setMatch(createMatch1000().build());
378 flow.setInstructions(createAppyActionInstruction6().build());
382 flow.setMatch(createMatch1000().build());
383 flow.setInstructions(createAppyActionInstruction2().build());
387 flow.setMatch(createMatch1000().build());
388 flow.setInstructions(createAppyActionInstruction3().build());
391 LOG.warn("flow type not understood: {}", flowType);
394 if (null == flow.isBarrier()) {
395 flow.setBarrier(Boolean.FALSE);
397 // flow.setBufferId(12L);
398 BigInteger value = BigInteger.valueOf(10);
399 BigInteger outputPort = BigInteger.valueOf(4294967295L);
400 flow.setCookie(new FlowCookie(value));
401 flow.setCookieMask(new FlowCookie(value));
402 flow.setHardTimeout(0);
403 flow.setIdleTimeout(0);
404 flow.setInstallHw(false);
405 flow.setStrict(false);
406 flow.setContainerName(null);
407 flow.setFlags(new FlowModFlags(false, false, false, false, true));
408 flow.setId(new FlowId("12"));
409 flow.setTableId(getTableId(tableId));
410 flow.setOutGroup(4294967295L);
411 // set outport to OFPP_NONE (65535) to disable remove restriction for
413 flow.setOutPort(outputPort);
415 FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
418 flow.setFlowName(originalFlowName + "X" + flowType);
422 private short getTableId(String tableId) {
424 if (tableId == null) {
429 table = Short.parseShort(tableId);
430 } catch (NumberFormatException ex) {
431 // ignore exception and continue with default value
438 public void _addFlows(CommandInterpreter ci) {
439 NodeBuilder tn = createTestNode(ci.nextArgument());
440 String flowtype = ci.nextArgument();
441 Integer flowcnt = Integer.parseInt(flowtype);
448 tf = createTestFlow(tn, "f1", "10");
449 tf1 = createTestFlow(tn, "f2", "11");
450 tf2 = createTestFlow(tn, "f3", "12");
451 tf3 = createTestFlow(tn, "f4", "13");
454 tf = createTestFlow(tn, "f3", "3");
455 tf1 = createTestFlow(tn, "f4", "4");
456 tf2 = createTestFlow(tn, "f5", "5");
457 tf3 = createTestFlow(tn, "f6", "6");
460 tf = createTestFlow(tn, "f7", "7");
461 tf1 = createTestFlow(tn, "f8", "8");
462 tf2 = createTestFlow(tn, "f9", "9");
463 tf3 = createTestFlow(tn, "f10", "10");
467 tf = createTestFlow(tn, "f23", "3");
468 tf1 = createTestFlow(tn, "f34", "4");
469 tf2 = createTestFlow(tn, "f35", "5");
470 tf3 = createTestFlow(tn, "f36", "6");
475 tf = createTestFlow(tn, "f230", "3");
476 tf1 = createTestFlow(tn, "f34", "4");
477 tf2 = createTestFlow(tn, "f35", "5");
478 tf3 = createTestFlow(tn, "f36", "6");
482 tf = createTestFlow(tn, "f42", "42");
483 tf1 = createTestFlow(tn, "f43", "43");
484 tf2 = createTestFlow(tn, "f44", "44");
485 tf3 = createTestFlow(tn, "f45", "45");
488 writeFlow(ci, tf, tf1, tf2, tf3, tn);
491 private InstanceIdentifier<Node> nodeBuilderToInstanceId(NodeBuilder node) {
492 return InstanceIdentifier.create(Nodes.class).child(Node.class, node.key());
495 public void _modifyFlows(CommandInterpreter ci) {
496 NodeBuilder tn = createTestNode(ci.nextArgument());
497 String flowtype = ci.nextArgument();
498 Integer flowcnt = Integer.parseInt(flowtype);
505 tf = createTestFlow(tn, "f82", "10");
506 tf1 = createTestFlow(tn, "f83", "11");
507 tf2 = createTestFlow(tn, "f84", "12");
508 tf3 = createTestFlow(tn, "f85", "13");
511 tf = createTestFlow(tn, "f700", "3");
512 tf1 = createTestFlow(tn, "f4", "4");
513 tf2 = createTestFlow(tn, "f900", "5");
514 tf3 = createTestFlow(tn, "f86", "6");
518 tf = createTestFlow(tn, "f91", "7");
519 tf1 = createTestFlow(tn, "f92", "8");
520 tf2 = createTestFlow(tn, "f93", "9");
521 tf3 = createTestFlow(tn, "f94", "10");
525 tf = createTestFlow(tn, "f230", "3");
526 tf1 = createTestFlow(tn, "f99", "4");
527 tf2 = createTestFlow(tn, "f100", "5");
528 tf3 = createTestFlow(tn, "f101", "6");
532 tf = createTestFlow(tn, "f23", "3");
533 tf1 = createTestFlow(tn, "f99", "4");
534 tf2 = createTestFlow(tn, "f100", "5");
535 tf3 = createTestFlow(tn, "f101", "6");
539 tf = createTestFlow(tn, "f87", "12");
540 tf1 = createTestFlow(tn, "f88", "13");
541 tf2 = createTestFlow(tn, "f89", "14");
542 tf3 = createTestFlow(tn, "f90", "15");
546 writeFlow(ci, tf, tf1, tf2, tf3, tn);
550 public void _removeFlows(final CommandInterpreter ci) {
551 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
552 NodeBuilder tn = createTestNode(ci.nextArgument());
553 String flowtype = ci.nextArgument();
554 Integer flowcnt = Integer.parseInt(flowtype);
555 FlowBuilder tf = null;
556 FlowBuilder tf1 = null;
557 FlowBuilder tf2 = null;
558 FlowBuilder tf3 = null;
562 tf = createTestFlow(tn, "f1", "10");
563 tf1 = createTestFlow(tn, "f2", "11");
564 tf2 = createTestFlow(tn, "f3", "12");
565 tf3 = createTestFlow(tn, "f4", "13");
569 tf = createTestFlow(tn, "f82", "10");
570 tf1 = createTestFlow(tn, "f83", "11");
571 tf2 = createTestFlow(tn, "f84", "12");
572 tf3 = createTestFlow(tn, "f85", "13");
576 tf = createTestFlow(tn, "f3", "3");
577 tf1 = createTestFlow(tn, "f4", "4");
578 tf2 = createTestFlow(tn, "f5", "5");
579 tf3 = createTestFlow(tn, "f6", "6");
583 tf = createTestFlow(tn, "f700", "3");
584 tf1 = createTestFlow(tn, "f4", "4");
585 tf2 = createTestFlow(tn, "f900", "5");
586 tf3 = createTestFlow(tn, "f86", "6");
590 tf = createTestFlow(tn, "f7", "7");
591 tf1 = createTestFlow(tn, "f8", "8");
592 tf2 = createTestFlow(tn, "f9", "9");
593 tf3 = createTestFlow(tn, "f10", "10");
597 tf = createTestFlow(tn, "f91", "7");
598 tf1 = createTestFlow(tn, "f92", "8");
599 tf2 = createTestFlow(tn, "f93", "9");
600 tf3 = createTestFlow(tn, "f94", "10");
604 tf = createTestFlow(tn, "f23", "3");
605 tf1 = createTestFlow(tn, "f34", "4");
606 tf2 = createTestFlow(tn, "f35", "5");
607 tf3 = createTestFlow(tn, "f36", "6");
612 tf = createTestFlow(tn, "f23", "3");
613 tf1 = createTestFlow(tn, "f99", "4");
614 tf2 = createTestFlow(tn, "f100", "5");
615 tf3 = createTestFlow(tn, "f101", "6");
619 tf = createTestFlow(tn, "f700", "7");
620 tf1 = createTestFlow(tn, "f230", "23");
621 tf2 = createTestFlow(tn, "f900", "9");
622 tf3 = createTestFlow(tn, "f1000", "10");
625 throw new IllegalArgumentException("Invalid flowtype: " + flowtype);
628 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
629 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
630 .child(Flow.class, tf.key());
631 modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
632 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
633 modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
634 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
635 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf1.getTableId()))
636 .child(Flow.class, tf1.key());
637 modification.delete(LogicalDatastoreType.OPERATIONAL, path2);
638 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
639 modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
641 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
642 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf2.getTableId()))
643 .child(Flow.class, tf2.key());
644 modification.delete(LogicalDatastoreType.OPERATIONAL, path3);
645 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
646 modification.delete(LogicalDatastoreType.CONFIGURATION, path3);
647 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
648 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf3.getTableId()))
649 .child(Flow.class, tf3.key());
650 modification.delete(LogicalDatastoreType.OPERATIONAL, path4);
651 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
652 modification.delete(LogicalDatastoreType.CONFIGURATION, path4);
653 ListenableFuture<Void> commitFuture = modification.submit();
654 Futures.addCallback(commitFuture, new FutureCallback<Void>() {
656 public void onSuccess(Void notUsed) {
657 ci.println("Status of Group Data Loaded Transaction: success.");
661 public void onFailure(Throwable throwable) {
662 LOG.error("Status of Group Data Loaded Transaction : failure. Reason : {}", throwable);
663 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
665 }, MoreExecutors.directExecutor());
669 private void writeFlow(final CommandInterpreter ci, FlowBuilder flow, FlowBuilder flow1, FlowBuilder flow2,
670 FlowBuilder flow3, NodeBuilder nodeBuilder) {
671 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
672 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class)
673 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
674 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.key());
675 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(),
677 modification.merge(LogicalDatastoreType.OPERATIONAL, path1, flow.build(), true);
678 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
679 nodeBuilder.build(), true);
680 modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
681 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class)
682 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
683 .child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.key());
684 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(),
686 modification.merge(LogicalDatastoreType.OPERATIONAL, path2, flow1.build(), true);
687 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
688 nodeBuilder.build(), true);
689 modification.merge(LogicalDatastoreType.CONFIGURATION, path2, flow1.build(), true);
691 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class)
692 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
693 .child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.key());
694 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(),
696 modification.merge(LogicalDatastoreType.OPERATIONAL, path3, flow2.build(), true);
697 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
698 nodeBuilder.build(), true);
699 modification.merge(LogicalDatastoreType.CONFIGURATION, path3, flow2.build(), true);
701 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class)
702 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
703 .child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.key());
704 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(),
706 modification.merge(LogicalDatastoreType.OPERATIONAL, path4, flow3.build(), true);
707 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
708 nodeBuilder.build(), true);
709 modification.merge(LogicalDatastoreType.CONFIGURATION, path4, flow3.build(), true);
710 ListenableFuture<Void> commitFuture = modification.submit();
711 Futures.addCallback(commitFuture, new FutureCallback<Void>() {
713 public void onSuccess(Void notUsed) {
714 ci.println("Status of Group Data Loaded Transaction: success.");
718 public void onFailure(Throwable throwable) {
719 LOG.error("Status of Group Data Loaded Transaction : failure. Reason : {}", throwable);
720 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
722 }, MoreExecutors.directExecutor());
725 private static InstructionsBuilder createDecNwTtlInstructions() {
726 DecNwTtlBuilder ta = new DecNwTtlBuilder();
727 DecNwTtl decNwTtl = ta.build();
728 ActionBuilder ab = new ActionBuilder();
729 ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
731 // Add our drop action to a list
732 List<Action> actionList = new ArrayList<>();
733 actionList.add(ab.build());
735 // Create an Apply Action
736 ApplyActionsBuilder aab = new ApplyActionsBuilder();
737 aab.setAction(actionList);
739 // Wrap our Apply Action in an Instruction
740 InstructionBuilder ib = new InstructionBuilder();
741 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
742 ib.withKey(new InstructionKey(0));
745 // Put our Instruction in a list of Instructions
746 InstructionsBuilder isb = new InstructionsBuilder();
747 List<Instruction> instructions = new ArrayList<>();
748 instructions.add(ib.build());
749 isb.setInstruction(instructions);
753 private static InstructionsBuilder createMeterInstructions() {
755 MeterBuilder aab = new MeterBuilder();
756 aab.setMeterId(new MeterId(1L));
758 InstructionBuilder ib = new InstructionBuilder();
759 ib.setInstruction(new MeterCaseBuilder().setMeter(aab.build()).build());
761 // Put our Instruction in a list of Instructions
762 InstructionsBuilder isb = new InstructionsBuilder();
763 List<Instruction> instructions = new ArrayList<>();
764 instructions.add(ib.build());
765 isb.setInstruction(instructions);
769 private static InstructionsBuilder createGotoTableInstructions() {
771 GoToTableBuilder aab = new GoToTableBuilder();
772 aab.setTableId((short) 2);
774 InstructionBuilder ib = new InstructionBuilder();
775 ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(aab.build()).build());
777 // Put our Instruction in a list of Instructions
778 InstructionsBuilder isb = new InstructionsBuilder();
779 List<Instruction> instructions = new ArrayList<>();
780 instructions.add(ib.build());
781 isb.setInstruction(instructions);
785 private static InstructionsBuilder createDropInstructions() {
786 DropActionBuilder dab = new DropActionBuilder();
787 DropAction dropAction = dab.build();
788 ActionBuilder ab = new ActionBuilder();
789 ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
791 // Add our drop action to a list
792 List<Action> actionList = new ArrayList<>();
793 actionList.add(ab.build());
795 // Create an Apply Action
796 ApplyActionsBuilder aab = new ApplyActionsBuilder();
797 aab.setAction(actionList);
799 // Wrap our Apply Action in an Instruction
800 InstructionBuilder ib = new InstructionBuilder();
801 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
803 // Put our Instruction in a list of Instructions
804 InstructionsBuilder isb = new InstructionsBuilder();
805 List<Instruction> instructions = new ArrayList<>();
806 instructions.add(ib.build());
807 isb.setInstruction(instructions);
811 private static InstructionsBuilder createAppyActionInstruction() {
813 List<Action> actionList = new ArrayList<>();
814 ActionBuilder ab = new ActionBuilder();
815 ControllerActionBuilder controller = new ControllerActionBuilder();
816 controller.setMaxLength(5);
817 ab.setAction(new ControllerActionCaseBuilder().setControllerAction(controller.build()).build());
818 actionList.add(ab.build());
819 // Create an Apply Action
820 ApplyActionsBuilder aab = new ApplyActionsBuilder();
821 aab.setAction(actionList);
823 // Wrap our Apply Action in an Instruction
824 InstructionBuilder ib = new InstructionBuilder();
825 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
827 // Put our Instruction in a list of Instructions
828 InstructionsBuilder isb = new InstructionsBuilder();
829 List<Instruction> instructions = new ArrayList<>();
830 instructions.add(ib.build());
831 isb.setInstruction(instructions);
835 private static InstructionsBuilder createSentToControllerInstructions() {
836 ActionBuilder ab = new ActionBuilder();
838 OutputActionBuilder output = new OutputActionBuilder();
839 output.setMaxLength(0xffff);
840 Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
841 output.setOutputNodeConnector(value);
842 ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
844 ab.withKey(new ActionKey(0));
846 List<Action> actionList = new ArrayList<>();
847 actionList.add(ab.build());
848 // Create an Apply Action
849 ApplyActionsBuilder aab = new ApplyActionsBuilder();
850 aab.setAction(actionList);
852 // Wrap our Apply Action in an Instruction
853 InstructionBuilder ib = new InstructionBuilder();
854 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
856 ib.withKey(new InstructionKey(0));
858 // Put our Instruction in a list of Instructions
859 InstructionsBuilder isb = new InstructionsBuilder();
860 List<Instruction> instructions = new ArrayList<>();
861 instructions.add(ib.build());
862 isb.setInstruction(instructions);
866 private static InstructionsBuilder createAppyActionInstruction2() {
868 List<Action> actionList = new ArrayList<>();
869 ActionBuilder ab = new ActionBuilder();
871 PushMplsActionBuilder push = new PushMplsActionBuilder();
872 push.setEthernetType(0x8847);
873 ab.setAction(new PushMplsActionCaseBuilder().setPushMplsAction(push.build()).build());
874 actionList.add(ab.build());
875 // Create an Apply Action
876 ApplyActionsBuilder aab = new ApplyActionsBuilder();
877 aab.setAction(actionList);
879 // Wrap our Apply Action in an Instruction
880 InstructionBuilder ib = new InstructionBuilder();
881 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
883 // Put our Instruction in a list of Instructions
884 InstructionsBuilder isb = new InstructionsBuilder();
885 List<Instruction> instructions = new ArrayList<>();
886 instructions.add(ib.build());
887 isb.setInstruction(instructions);
891 private static InstructionsBuilder createAppyActionInstruction3() {
893 List<Action> actionList = new ArrayList<>();
894 ActionBuilder ab = new ActionBuilder();
896 PushPbbActionBuilder pbb = new PushPbbActionBuilder();
897 pbb.setEthernetType(0x88E7);
898 ab.setAction(new PushPbbActionCaseBuilder().setPushPbbAction(pbb.build()).build());
899 actionList.add(ab.build());
900 // Create an Apply Action
901 ApplyActionsBuilder aab = new ApplyActionsBuilder();
902 aab.setAction(actionList);
904 // Wrap our Apply Action in an Instruction
905 InstructionBuilder ib = new InstructionBuilder();
906 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
908 // Put our Instruction in a list of Instructions
909 InstructionsBuilder isb = new InstructionsBuilder();
910 List<Instruction> instructions = new ArrayList<>();
911 instructions.add(ib.build());
912 isb.setInstruction(instructions);
916 private static InstructionsBuilder createAppyActionInstruction6() {
918 List<Action> actionList = new ArrayList<>();
919 ActionBuilder ab = new ActionBuilder();
921 SetDlSrcActionBuilder src = new SetDlSrcActionBuilder();
922 src.setAddress(new MacAddress("00:05:b9:7c:81:5f"));
923 ab.setAction(new SetDlSrcActionCaseBuilder().setSetDlSrcAction(src.build()).build());
924 actionList.add(ab.build());
926 // Create an Apply Action
927 ApplyActionsBuilder aab = new ApplyActionsBuilder();
928 aab.setAction(actionList);
930 // Wrap our Apply Action in an Instruction
931 InstructionBuilder ib = new InstructionBuilder();
932 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
934 // Put our Instruction in a list of Instructions
935 InstructionsBuilder isb = new InstructionsBuilder();
936 List<Instruction> instructions = new ArrayList<>();
937 instructions.add(ib.build());
938 isb.setInstruction(instructions);
942 private static InstructionsBuilder createAppyActionInstruction7() {
944 List<Action> actionList = new ArrayList<>();
945 ActionBuilder ab = new ActionBuilder();
947 SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
948 VlanId vlanId = new VlanId(4012);
949 vl.setVlanId(vlanId);
950 ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.build()).build());
951 actionList.add(ab.build());
952 // Create an Apply Action
953 ApplyActionsBuilder aab = new ApplyActionsBuilder();
954 aab.setAction(actionList);
956 // Wrap our Apply Action in an Instruction
957 InstructionBuilder ib = new InstructionBuilder();
958 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
960 // Put our Instruction in a list of Instructions
961 InstructionsBuilder isb = new InstructionsBuilder();
962 List<Instruction> instructions = new ArrayList<>();
963 instructions.add(ib.build());
964 isb.setInstruction(instructions);
968 private static InstructionsBuilder createAppyActionInstruction8() {
970 List<Action> actionList = new ArrayList<>();
971 ActionBuilder ab = new ActionBuilder();
973 SetVlanPcpActionBuilder pcp = new SetVlanPcpActionBuilder();
974 VlanPcp pcp1 = new VlanPcp((short) 2);
975 pcp.setVlanPcp(pcp1);
976 ab.setAction(new SetVlanPcpActionCaseBuilder().setSetVlanPcpAction(pcp.build()).build());
977 actionList.add(ab.build());
978 // Create an Apply Action
979 ApplyActionsBuilder aab = new ApplyActionsBuilder();
980 aab.setAction(actionList);
982 // Wrap our Apply Action in an Instruction
983 InstructionBuilder ib = new InstructionBuilder();
984 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
986 // Put our Instruction in a list of Instructions
987 InstructionsBuilder isb = new InstructionsBuilder();
988 List<Instruction> instructions = new ArrayList<>();
989 instructions.add(ib.build());
990 isb.setInstruction(instructions);
994 private static InstructionsBuilder createAppyActionInstruction9() {
996 List<Action> actionList = new ArrayList<>();
997 ActionBuilder ab = new ActionBuilder();
999 CopyTtlInBuilder ttlin = new CopyTtlInBuilder();
1000 ab.setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(ttlin.build()).build());
1001 actionList.add(ab.build());
1002 // Create an Apply Action
1003 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1004 aab.setAction(actionList);
1006 // Wrap our Apply Action in an Instruction
1007 InstructionBuilder ib = new InstructionBuilder();
1008 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1010 // Put our Instruction in a list of Instructions
1011 InstructionsBuilder isb = new InstructionsBuilder();
1012 List<Instruction> instructions = new ArrayList<>();
1013 instructions.add(ib.build());
1014 isb.setInstruction(instructions);
1018 private static InstructionsBuilder createAppyActionInstruction16() {
1019 ActionBuilder ab = new ActionBuilder();
1021 GroupActionBuilder groupActionB = new GroupActionBuilder();
1022 groupActionB.setGroupId(1L);
1023 groupActionB.setGroup("0");
1024 ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
1026 List<Action> actionList = new ArrayList<>();
1027 actionList.add(ab.build());
1029 // Create an Apply Action
1030 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1031 aab.setAction(actionList);
1033 // Wrap our Apply Action in an Instruction
1034 InstructionBuilder ib = new InstructionBuilder();
1035 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1037 // Put our Instruction in a list of Instructions
1038 InstructionsBuilder isb = new InstructionsBuilder();
1039 List<Instruction> instructions = new ArrayList<>();
1040 instructions.add(ib.build());
1041 isb.setInstruction(instructions);
1045 private static InstructionsBuilder createAppyActionInstruction160() {
1047 List<Action> actionList = new ArrayList<>();
1048 ActionBuilder ab = new ActionBuilder();
1050 FloodAllActionBuilder fldall = new FloodAllActionBuilder();
1051 ab.setAction(new FloodAllActionCaseBuilder().setFloodAllAction(fldall.build()).build());
1052 actionList.add(ab.build());
1053 // Create an Apply Action
1054 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1055 aab.setAction(actionList);
1057 // Wrap our Apply Action in an Instruction
1058 InstructionBuilder ib = new InstructionBuilder();
1059 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1061 // Put our Instruction in a list of Instructions
1062 InstructionsBuilder isb = new InstructionsBuilder();
1063 List<Instruction> instructions = new ArrayList<>();
1064 instructions.add(ib.build());
1065 isb.setInstruction(instructions);
1069 private static InstructionsBuilder createAppyActionInstruction26() {
1070 ActionBuilder ab = new ActionBuilder();
1072 SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
1073 Ipv4Builder ipdst = new Ipv4Builder();
1074 Ipv4Prefix prefixdst = new Ipv4Prefix("10.0.0.21/24");
1075 ipdst.setIpv4Address(prefixdst);
1076 setNwDstActionBuilder.setAddress(ipdst.build());
1077 ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
1079 List<Action> actionList = new ArrayList<>();
1080 actionList.add(ab.build());
1082 // Create an Apply Action
1083 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1084 aab.setAction(actionList);
1086 // Wrap our Apply Action in an Instruction
1087 InstructionBuilder ib = new InstructionBuilder();
1088 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1090 // Put our Instruction in a list of Instructions
1091 InstructionsBuilder isb = new InstructionsBuilder();
1092 List<Instruction> instructions = new ArrayList<>();
1093 instructions.add(ib.build());
1094 isb.setInstruction(instructions);
1098 private static InstructionsBuilder createAppyActionInstruction27() {
1099 ActionBuilder ab = new ActionBuilder();
1101 SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
1102 Ipv4Builder ipsrc = new Ipv4Builder();
1103 Ipv4Prefix prefixsrc = new Ipv4Prefix("10.0.23.21/24");
1104 ipsrc.setIpv4Address(prefixsrc);
1105 setNwsrcActionBuilder.setAddress(ipsrc.build());
1106 ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
1108 List<Action> actionList = new ArrayList<>();
1109 actionList.add(ab.build());
1111 // Create an Apply Action
1112 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1113 aab.setAction(actionList);
1115 // Wrap our Apply Action in an Instruction
1116 InstructionBuilder ib = new InstructionBuilder();
1117 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1119 // Put our Instruction in a list of Instructions
1120 InstructionsBuilder isb = new InstructionsBuilder();
1121 List<Instruction> instructions = new ArrayList<>();
1122 instructions.add(ib.build());
1123 isb.setInstruction(instructions);
1127 private static InstructionsBuilder createAppyActionInstruction28() {
1129 List<Action> actionList = new ArrayList<>();
1130 ActionBuilder ab = new ActionBuilder();
1132 SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
1133 setNwTosActionBuilder.setTos(8);
1134 ab.setAction(new SetNwTosActionCaseBuilder().setSetNwTosAction(setNwTosActionBuilder.build()).build());
1135 actionList.add(ab.build());
1136 // Create an Apply Action
1137 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1138 aab.setAction(actionList);
1140 // Wrap our Apply Action in an Instruction
1141 InstructionBuilder ib = new InstructionBuilder();
1142 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1144 // Put our Instruction in a list of Instructions
1145 InstructionsBuilder isb = new InstructionsBuilder();
1146 List<Instruction> instructions = new ArrayList<>();
1147 instructions.add(ib.build());
1148 isb.setInstruction(instructions);
1152 private static InstructionsBuilder createAppyActionInstruction34() {
1154 List<Action> actionList = new ArrayList<>();
1155 ActionBuilder ab = new ActionBuilder();
1157 SwPathActionBuilder swPathAction = new SwPathActionBuilder();
1158 ab.setAction(new SwPathActionCaseBuilder().setSwPathAction(swPathAction.build()).build());
1159 actionList.add(ab.build());
1161 // Create an Apply Action
1162 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1163 aab.setAction(actionList);
1165 // Wrap our Apply Action in an Instruction
1166 InstructionBuilder ib = new InstructionBuilder();
1167 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1169 // Put our Instruction in a list of Instructions
1170 InstructionsBuilder isb = new InstructionsBuilder();
1171 List<Instruction> instructions = new ArrayList<>();
1172 instructions.add(ib.build());
1173 isb.setInstruction(instructions);
1177 private static MatchBuilder createLLDPMatch() {
1178 MatchBuilder match = new MatchBuilder();
1179 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1180 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1181 ethTypeBuilder.setType(new EtherType(0x88ccL));
1182 eth.setEthernetType(ethTypeBuilder.build());
1183 match.setEthernetMatch(eth.build());
1187 private static MatchBuilder createMatch1() {
1188 MatchBuilder match = new MatchBuilder();
1189 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1190 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
1191 ipv4Match.setIpv4Destination(prefix);
1192 Ipv4Match i4m = ipv4Match.build();
1193 match.setLayer3Match(i4m);
1195 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1196 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1197 ethTypeBuilder.setType(new EtherType(0x0800L));
1198 eth.setEthernetType(ethTypeBuilder.build());
1199 match.setEthernetMatch(eth.build());
1203 private static MatchBuilder createMatch1000() {
1204 MatchBuilder match = new MatchBuilder();
1205 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1206 Ipv4Prefix prefix = new Ipv4Prefix("10.1.1.1/24");
1207 ipv4Match.setIpv4Destination(prefix);
1208 Ipv4Match i4m = ipv4Match.build();
1209 match.setLayer3Match(i4m);
1211 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1212 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1213 ethTypeBuilder.setType(new EtherType(0x0800L));
1214 eth.setEthernetType(ethTypeBuilder.build());
1215 match.setEthernetMatch(eth.build());
1219 private static MatchBuilder createMatch2() {
1220 MatchBuilder match = new MatchBuilder();
1221 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1222 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1");
1223 ipv4Match.setIpv4Source(prefix);
1224 Ipv4Match i4m = ipv4Match.build();
1225 match.setLayer3Match(i4m);
1227 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1228 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1229 ethTypeBuilder.setType(new EtherType(0x0800L));
1230 eth.setEthernetType(ethTypeBuilder.build());
1231 match.setEthernetMatch(eth.build());
1235 private static MatchBuilder createMatch3() {
1236 MatchBuilder match = new MatchBuilder();
1237 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
1238 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
1239 ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
1240 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
1241 match.setEthernetMatch(ethernetMatch.build());
1246 private static MatchBuilder createInphyportMatch(NodeId nodeId) {
1247 MatchBuilder match = new MatchBuilder();
1248 match.setInPort(new NodeConnectorId(nodeId + ":202"));
1249 match.setInPhyPort(new NodeConnectorId(nodeId + ":10122"));
1253 private static MatchBuilder createEthernetMatch() {
1254 EthernetMatchBuilder ethmatch = new EthernetMatchBuilder(); // ethernettype
1256 EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
1257 EtherType type = new EtherType(0x0800L);
1258 ethmatch.setEthernetType(ethtype.setType(type).build());
1260 EthernetDestinationBuilder ethdest = new EthernetDestinationBuilder(); // ethernet
1263 MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
1264 ethdest.setAddress(macdest);
1265 // ethdest.setMask(mask1);
1267 ethmatch.setEthernetDestination(ethdest.build());
1269 EthernetSourceBuilder ethsrc = new EthernetSourceBuilder();
1270 MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
1271 ethsrc.setAddress(macsrc);
1272 // ethsrc.setMask(mask2);
1274 ethmatch.setEthernetSource(ethsrc.build());
1276 MatchBuilder match = new MatchBuilder();
1277 match.setEthernetMatch(ethmatch.build());
1282 private static MatchBuilder createL3IPv6Match() {
1283 MatchBuilder match = new MatchBuilder();
1285 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1286 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1287 ethTypeBuilder.setType(new EtherType(0x86ddL));
1288 eth.setEthernetType(ethTypeBuilder.build());
1289 match.setEthernetMatch(eth.build());
1291 Ipv6ExtHeaderBuilder nextheader = new Ipv6ExtHeaderBuilder();
1292 nextheader.setIpv6Exthdr(58);
1293 Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
1294 Ipv6FlowLabel label = new Ipv6FlowLabel(10028L);
1295 ipv6label.setIpv6Flabel(label);
1296 // ipv6label.setFlabelMask(new byte[] { 0, 1, -1, -1 });
1298 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1300 icmpv6match.setIcmpv6Type((short) 135);
1301 icmpv6match.setIcmpv6Code((short) 0);
1302 match.setIcmpv6Match(icmpv6match.build());
1304 Ipv6MatchBuilder ipv6match = new Ipv6MatchBuilder();
1305 // ipv6match.setIpv6Source(srcip6);
1306 // ipv6match.setIpv6Destination(dstip6);
1307 // ipv6match.setIpv6ExtHeader(nextheader.build());
1309 ipv6match.setIpv6NdSll(new MacAddress("c2:00:54:f5:00:00"));
1310 ipv6match.setIpv6NdTll(new MacAddress("00:0c:29:0e:4c:67"));
1311 // ipv6match.setIpv6NdTarget(ndtarget);
1312 ipv6match.setIpv6Label(ipv6label.build());
1314 match.setLayer3Match(ipv6match.build());
1319 private static MatchBuilder createICMPv6Match() {
1321 MatchBuilder match = new MatchBuilder();
1322 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1323 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1324 ethTypeBuilder.setType(new EtherType(0x86ddL));
1325 eth.setEthernetType(ethTypeBuilder.build());
1326 match.setEthernetMatch(eth.build());
1328 IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
1329 ipmatch.setIpProtocol((short) 58);
1330 match.setIpMatch(ipmatch.build());
1332 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1334 icmpv6match.setIcmpv6Type((short) 135);
1335 icmpv6match.setIcmpv6Code((short) 1);
1336 match.setIcmpv6Match(icmpv6match.build());
1341 private static MatchBuilder createMetadataMatch() {
1342 MatchBuilder match = new MatchBuilder();
1343 MetadataBuilder metadata = new MetadataBuilder(); // metadata match
1344 metadata.setMetadata(BigInteger.valueOf(500L));
1345 // metadata.setMetadataMask(metamask);
1346 match.setMetadata(metadata.build());