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.CheckedFuture;
12 import com.google.common.util.concurrent.FutureCallback;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.MoreExecutors;
15 import java.math.BigInteger;
16 import java.util.ArrayList;
17 import java.util.List;
18 import org.eclipse.osgi.framework.console.CommandInterpreter;
19 import org.eclipse.osgi.framework.console.CommandProvider;
20 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
21 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
22 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
23 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
24 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
25 import org.opendaylight.controller.sal.binding.api.NotificationService;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.all.action._case.FloodAllActionBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.sw.path.action._case.SwPathActionBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.node.error.service.rev140410.NodeErrorListener;
112 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
113 import org.osgi.framework.BundleContext;
114 import org.slf4j.Logger;
115 import org.slf4j.LoggerFactory;
117 @SuppressWarnings("checkstyle:MethodName")
118 public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
120 private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginBulkTransactionProvider.class);
121 private DataBroker dataBroker;
122 private final BundleContext ctx;
123 private final String originalFlowName = "Foo";
124 private final NodeErrorListener nodeErrorListener = new NodeErrorListenerLoggingImpl();
125 private NotificationService notificationService;
127 public OpenflowPluginBulkTransactionProvider(BundleContext ctx) {
131 public void onSessionInitiated(ProviderContext session) {
132 notificationService = session.getSALService(NotificationService.class);
133 notificationService.registerNotificationListener(nodeErrorListener);
134 dataBroker = session.getSALService(DataBroker.class);
135 ctx.registerService(CommandProvider.class.getName(), this, null);
136 createTestFlow(createTestNode(null), null, null);
139 private NodeBuilder createTestNode(String nodeId) {
140 if (nodeId == null) {
141 nodeId = OpenflowpluginTestActivator.NODE_ID;
143 NodeBuilder builder = new NodeBuilder();
144 builder.setId(new NodeId(nodeId));
145 builder.setKey(new NodeKey(builder.getId()));
150 public String getHelp() {
154 private FlowBuilder createTestFlow(NodeBuilder nodeBuilder, String flowTypeArg, String tableId) {
156 FlowBuilder flow = new FlowBuilder();
159 String flowType = flowTypeArg;
160 if (flowType == null) {
167 flow.setMatch(createMatch1().build());
168 flow.setInstructions(createDecNwTtlInstructions().build());
172 flow.setMatch(createMatch2().build());
173 flow.setInstructions(createDropInstructions().build());
177 flow.setMatch(createMatch3().build());
178 flow.setInstructions(createDropInstructions().build());
182 flow.setMatch(createEthernetMatch().build());
183 flow.setInstructions(createDropInstructions().build());
187 flow.setMatch(createMatch1().build());
188 flow.setInstructions(createAppyActionInstruction().build());
192 flow.setMatch(createMatch1().build());
193 flow.setInstructions(createGotoTableInstructions().build());
197 flow.setMatch(createMatch1().build());
198 flow.setInstructions(createMeterInstructions().build());
202 flow.setMatch(createMatch1().build());
203 flow.setInstructions(createAppyActionInstruction7().build());
207 flow.setMatch(createMatch1().build());
208 flow.setInstructions(createAppyActionInstruction2().build());
212 flow.setMatch(createMatch1().build());
213 flow.setInstructions(createAppyActionInstruction3().build());
217 flow.setMatch(createMatch1().build());
218 flow.setInstructions(createAppyActionInstruction16().build());
222 flow.setMatch(createMatch1().build());
223 flow.setInstructions(createAppyActionInstruction160().build());
227 flow.setMatch(createMatch1().build());
228 flow.setInstructions(createAppyActionInstruction26().build());
232 flow.setMatch(createMatch1().build());
233 flow.setInstructions(createAppyActionInstruction27().build());
237 flow.setMatch(createMatch1().build());
238 flow.setInstructions(createAppyActionInstruction28().build());
242 flow.setMatch(createMatch1().build());
243 flow.setInstructions(createAppyActionInstruction34().build());
247 flow.setMatch(createICMPv6Match().build());
248 flow.setInstructions(createDecNwTtlInstructions().build());
252 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
253 flow.setInstructions(createDropInstructions().build());
257 flow.setMatch(createMetadataMatch().build());
258 flow.setInstructions(createDropInstructions().build());
262 flow.setMatch(createL3IPv6Match().build());
263 flow.setInstructions(createDecNwTtlInstructions().build());
267 flow.setMatch(createLLDPMatch().build());
268 flow.setInstructions(createSentToControllerInstructions().build());
273 flow.setMatch(createMatch1().build());
274 flow.setInstructions(createDropInstructions().build());
278 flow.setMatch(createMatch2().build());
279 flow.setInstructions(createDecNwTtlInstructions().build());
283 flow.setMatch(createMatch3().build());
284 flow.setInstructions(createDecNwTtlInstructions().build());
288 flow.setMatch(createEthernetMatch().build());
289 flow.setInstructions(createMeterInstructions().build());
293 flow.setMatch(createMatch1().build());
294 flow.setInstructions(createDecNwTtlInstructions().build());
298 flow.setMatch(createMatch1().build());
299 flow.setInstructions(createAppyActionInstruction7().build());
303 flow.setMatch(createEthernetMatch().build());
304 flow.setInstructions(createAppyActionInstruction6().build());
308 flow.setMatch(createEthernetMatch().build());
309 flow.setInstructions(createAppyActionInstruction7().build());
313 flow.setMatch(createMatch1().build());
314 flow.setInstructions(createAppyActionInstruction9().build());
318 flow.setMatch(createMatch1().build());
319 flow.setInstructions(createAppyActionInstruction9().build());
323 flow.setMatch(createMatch1().build());
324 flow.setInstructions(createAppyActionInstruction6().build());
328 flow.setMatch(createMatch1().build());
329 flow.setInstructions(createDecNwTtlInstructions().build());
333 flow.setMatch(createMatch1().build());
334 flow.setInstructions(createDecNwTtlInstructions().build());
338 flow.setMatch(createMatch1().build());
339 flow.setInstructions(createDecNwTtlInstructions().build());
343 flow.setMatch(createICMPv6Match().build());
344 flow.setInstructions(createDropInstructions().build());
348 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
349 flow.setInstructions(createMeterInstructions().build());
353 flow.setMatch(createMetadataMatch().build());
354 flow.setInstructions(createAppyActionInstruction6().build());
358 flow.setMatch(createMatch1().build());
359 flow.setInstructions(createAppyActionInstruction6().build());
363 flow.setMatch(createMatch1().build());
364 flow.setInstructions(createAppyActionInstruction7().build());
368 flow.setMatch(createMatch1().build());
369 flow.setInstructions(createAppyActionInstruction8().build());
373 flow.setMatch(createMatch3().build());
374 flow.setInstructions(createMeterInstructions().build());
378 flow.setMatch(createMatch1000().build());
379 flow.setInstructions(createAppyActionInstruction6().build());
383 flow.setMatch(createMatch1000().build());
384 flow.setInstructions(createAppyActionInstruction2().build());
388 flow.setMatch(createMatch1000().build());
389 flow.setInstructions(createAppyActionInstruction3().build());
392 LOG.warn("flow type not understood: {}", flowType);
395 if (null == flow.isBarrier()) {
396 flow.setBarrier(Boolean.FALSE);
398 // flow.setBufferId(12L);
399 BigInteger value = BigInteger.valueOf(10);
400 BigInteger outputPort = BigInteger.valueOf(4294967295L);
401 flow.setCookie(new FlowCookie(value));
402 flow.setCookieMask(new FlowCookie(value));
403 flow.setHardTimeout(0);
404 flow.setIdleTimeout(0);
405 flow.setInstallHw(false);
406 flow.setStrict(false);
407 flow.setContainerName(null);
408 flow.setFlags(new FlowModFlags(false, false, false, false, true));
409 flow.setId(new FlowId("12"));
410 flow.setTableId(getTableId(tableId));
411 flow.setOutGroup(4294967295L);
412 // set outport to OFPP_NONE (65535) to disable remove restriction for
414 flow.setOutPort(outputPort);
416 FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
419 flow.setFlowName(originalFlowName + "X" + flowType);
423 private short getTableId(String tableId) {
425 if (tableId == null) {
430 table = Short.parseShort(tableId);
431 } catch (NumberFormatException ex) {
432 // ignore exception and continue with default value
439 public void _addFlows(CommandInterpreter ci) {
440 NodeBuilder tn = createTestNode(ci.nextArgument());
441 String flowtype = ci.nextArgument();
442 Integer flowcnt = Integer.parseInt(flowtype);
449 tf = createTestFlow(tn, "f1", "10");
450 tf1 = createTestFlow(tn, "f2", "11");
451 tf2 = createTestFlow(tn, "f3", "12");
452 tf3 = createTestFlow(tn, "f4", "13");
455 tf = createTestFlow(tn, "f3", "3");
456 tf1 = createTestFlow(tn, "f4", "4");
457 tf2 = createTestFlow(tn, "f5", "5");
458 tf3 = createTestFlow(tn, "f6", "6");
461 tf = createTestFlow(tn, "f7", "7");
462 tf1 = createTestFlow(tn, "f8", "8");
463 tf2 = createTestFlow(tn, "f9", "9");
464 tf3 = createTestFlow(tn, "f10", "10");
468 tf = createTestFlow(tn, "f23", "3");
469 tf1 = createTestFlow(tn, "f34", "4");
470 tf2 = createTestFlow(tn, "f35", "5");
471 tf3 = createTestFlow(tn, "f36", "6");
476 tf = createTestFlow(tn, "f230", "3");
477 tf1 = createTestFlow(tn, "f34", "4");
478 tf2 = createTestFlow(tn, "f35", "5");
479 tf3 = createTestFlow(tn, "f36", "6");
483 tf = createTestFlow(tn, "f42", "42");
484 tf1 = createTestFlow(tn, "f43", "43");
485 tf2 = createTestFlow(tn, "f44", "44");
486 tf3 = createTestFlow(tn, "f45", "45");
489 writeFlow(ci, tf, tf1, tf2, tf3, tn);
492 private InstanceIdentifier<Node> nodeBuilderToInstanceId(NodeBuilder node) {
493 return InstanceIdentifier.create(Nodes.class).child(Node.class, node.getKey());
496 public void _modifyFlows(CommandInterpreter ci) {
497 NodeBuilder tn = createTestNode(ci.nextArgument());
498 String flowtype = ci.nextArgument();
499 Integer flowcnt = Integer.parseInt(flowtype);
506 tf = createTestFlow(tn, "f82", "10");
507 tf1 = createTestFlow(tn, "f83", "11");
508 tf2 = createTestFlow(tn, "f84", "12");
509 tf3 = createTestFlow(tn, "f85", "13");
512 tf = createTestFlow(tn, "f700", "3");
513 tf1 = createTestFlow(tn, "f4", "4");
514 tf2 = createTestFlow(tn, "f900", "5");
515 tf3 = createTestFlow(tn, "f86", "6");
519 tf = createTestFlow(tn, "f91", "7");
520 tf1 = createTestFlow(tn, "f92", "8");
521 tf2 = createTestFlow(tn, "f93", "9");
522 tf3 = createTestFlow(tn, "f94", "10");
526 tf = createTestFlow(tn, "f230", "3");
527 tf1 = createTestFlow(tn, "f99", "4");
528 tf2 = createTestFlow(tn, "f100", "5");
529 tf3 = createTestFlow(tn, "f101", "6");
533 tf = createTestFlow(tn, "f23", "3");
534 tf1 = createTestFlow(tn, "f99", "4");
535 tf2 = createTestFlow(tn, "f100", "5");
536 tf3 = createTestFlow(tn, "f101", "6");
540 tf = createTestFlow(tn, "f87", "12");
541 tf1 = createTestFlow(tn, "f88", "13");
542 tf2 = createTestFlow(tn, "f89", "14");
543 tf3 = createTestFlow(tn, "f90", "15");
547 writeFlow(ci, tf, tf1, tf2, tf3, tn);
551 public void _removeFlows(final CommandInterpreter ci) {
552 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
553 NodeBuilder tn = createTestNode(ci.nextArgument());
554 String flowtype = ci.nextArgument();
555 Integer flowcnt = Integer.parseInt(flowtype);
556 FlowBuilder tf = null;
557 FlowBuilder tf1 = null;
558 FlowBuilder tf2 = null;
559 FlowBuilder tf3 = null;
563 tf = createTestFlow(tn, "f1", "10");
564 tf1 = createTestFlow(tn, "f2", "11");
565 tf2 = createTestFlow(tn, "f3", "12");
566 tf3 = createTestFlow(tn, "f4", "13");
570 tf = createTestFlow(tn, "f82", "10");
571 tf1 = createTestFlow(tn, "f83", "11");
572 tf2 = createTestFlow(tn, "f84", "12");
573 tf3 = createTestFlow(tn, "f85", "13");
577 tf = createTestFlow(tn, "f3", "3");
578 tf1 = createTestFlow(tn, "f4", "4");
579 tf2 = createTestFlow(tn, "f5", "5");
580 tf3 = createTestFlow(tn, "f6", "6");
584 tf = createTestFlow(tn, "f700", "3");
585 tf1 = createTestFlow(tn, "f4", "4");
586 tf2 = createTestFlow(tn, "f900", "5");
587 tf3 = createTestFlow(tn, "f86", "6");
591 tf = createTestFlow(tn, "f7", "7");
592 tf1 = createTestFlow(tn, "f8", "8");
593 tf2 = createTestFlow(tn, "f9", "9");
594 tf3 = createTestFlow(tn, "f10", "10");
598 tf = createTestFlow(tn, "f91", "7");
599 tf1 = createTestFlow(tn, "f92", "8");
600 tf2 = createTestFlow(tn, "f93", "9");
601 tf3 = createTestFlow(tn, "f94", "10");
605 tf = createTestFlow(tn, "f23", "3");
606 tf1 = createTestFlow(tn, "f34", "4");
607 tf2 = createTestFlow(tn, "f35", "5");
608 tf3 = createTestFlow(tn, "f36", "6");
613 tf = createTestFlow(tn, "f23", "3");
614 tf1 = createTestFlow(tn, "f99", "4");
615 tf2 = createTestFlow(tn, "f100", "5");
616 tf3 = createTestFlow(tn, "f101", "6");
620 tf = createTestFlow(tn, "f700", "7");
621 tf1 = createTestFlow(tn, "f230", "23");
622 tf2 = createTestFlow(tn, "f900", "9");
623 tf3 = createTestFlow(tn, "f1000", "10");
626 throw new IllegalArgumentException("Invalid flowtype: " + flowtype);
629 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
630 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
631 .child(Flow.class, tf.getKey());
632 modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
633 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
634 modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
635 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
636 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf1.getTableId()))
637 .child(Flow.class, tf1.getKey());
638 modification.delete(LogicalDatastoreType.OPERATIONAL, path2);
639 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
640 modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
642 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
643 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf2.getTableId()))
644 .child(Flow.class, tf2.getKey());
645 modification.delete(LogicalDatastoreType.OPERATIONAL, path3);
646 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
647 modification.delete(LogicalDatastoreType.CONFIGURATION, path3);
648 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
649 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf3.getTableId()))
650 .child(Flow.class, tf3.getKey());
651 modification.delete(LogicalDatastoreType.OPERATIONAL, path4);
652 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
653 modification.delete(LogicalDatastoreType.CONFIGURATION, path4);
654 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
655 Futures.addCallback(commitFuture, new FutureCallback<Void>() {
657 public void onSuccess(Void notUsed) {
658 ci.println("Status of Group Data Loaded Transaction: success.");
662 public void onFailure(Throwable throwable) {
663 LOG.error(throwable.getMessage(), throwable);
664 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
666 }, MoreExecutors.directExecutor());
670 private void writeFlow(final CommandInterpreter ci, FlowBuilder flow, FlowBuilder flow1, FlowBuilder flow2,
671 FlowBuilder flow3, NodeBuilder nodeBuilder) {
672 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
673 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class)
674 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
675 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey());
676 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(),
678 modification.merge(LogicalDatastoreType.OPERATIONAL, path1, flow.build(), true);
679 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
680 nodeBuilder.build(), true);
681 modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
682 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class)
683 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
684 .child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.getKey());
685 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(),
687 modification.merge(LogicalDatastoreType.OPERATIONAL, path2, flow1.build(), true);
688 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
689 nodeBuilder.build(), true);
690 modification.merge(LogicalDatastoreType.CONFIGURATION, path2, flow1.build(), true);
692 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class)
693 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
694 .child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.getKey());
695 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(),
697 modification.merge(LogicalDatastoreType.OPERATIONAL, path3, flow2.build(), true);
698 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
699 nodeBuilder.build(), true);
700 modification.merge(LogicalDatastoreType.CONFIGURATION, path3, flow2.build(), true);
702 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class)
703 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
704 .child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.getKey());
705 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(),
707 modification.merge(LogicalDatastoreType.OPERATIONAL, path4, flow3.build(), true);
708 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
709 nodeBuilder.build(), true);
710 modification.merge(LogicalDatastoreType.CONFIGURATION, path4, flow3.build(), true);
711 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
712 Futures.addCallback(commitFuture, new FutureCallback<Void>() {
714 public void onSuccess(Void notUsed) {
715 ci.println("Status of Group Data Loaded Transaction: success.");
719 public void onFailure(Throwable throwable) {
720 LOG.error(throwable.getMessage(), throwable);
721 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
723 }, MoreExecutors.directExecutor());
726 private static InstructionsBuilder createDecNwTtlInstructions() {
727 DecNwTtlBuilder ta = new DecNwTtlBuilder();
728 DecNwTtl decNwTtl = ta.build();
729 ActionBuilder ab = new ActionBuilder();
730 ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
732 // Add our drop action to a list
733 List<Action> actionList = new ArrayList<>();
734 actionList.add(ab.build());
736 // Create an Apply Action
737 ApplyActionsBuilder aab = new ApplyActionsBuilder();
738 aab.setAction(actionList);
740 // Wrap our Apply Action in an Instruction
741 InstructionBuilder ib = new InstructionBuilder();
742 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
743 ib.setKey(new InstructionKey(0));
746 // Put our Instruction in a list of Instructions
747 InstructionsBuilder isb = new InstructionsBuilder();
748 List<Instruction> instructions = new ArrayList<>();
749 instructions.add(ib.build());
750 isb.setInstruction(instructions);
754 private static InstructionsBuilder createMeterInstructions() {
756 MeterBuilder aab = new MeterBuilder();
757 aab.setMeterId(new MeterId(1L));
759 InstructionBuilder ib = new InstructionBuilder();
760 ib.setInstruction(new MeterCaseBuilder().setMeter(aab.build()).build());
762 // Put our Instruction in a list of Instructions
763 InstructionsBuilder isb = new InstructionsBuilder();
764 List<Instruction> instructions = new ArrayList<>();
765 instructions.add(ib.build());
766 isb.setInstruction(instructions);
770 private static InstructionsBuilder createGotoTableInstructions() {
772 GoToTableBuilder aab = new GoToTableBuilder();
773 aab.setTableId((short) 2);
775 InstructionBuilder ib = new InstructionBuilder();
776 ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(aab.build()).build());
778 // Put our Instruction in a list of Instructions
779 InstructionsBuilder isb = new InstructionsBuilder();
780 List<Instruction> instructions = new ArrayList<>();
781 instructions.add(ib.build());
782 isb.setInstruction(instructions);
786 private static InstructionsBuilder createDropInstructions() {
787 DropActionBuilder dab = new DropActionBuilder();
788 DropAction dropAction = dab.build();
789 ActionBuilder ab = new ActionBuilder();
790 ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
792 // Add our drop action to a list
793 List<Action> actionList = new ArrayList<>();
794 actionList.add(ab.build());
796 // Create an Apply Action
797 ApplyActionsBuilder aab = new ApplyActionsBuilder();
798 aab.setAction(actionList);
800 // Wrap our Apply Action in an Instruction
801 InstructionBuilder ib = new InstructionBuilder();
802 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
804 // Put our Instruction in a list of Instructions
805 InstructionsBuilder isb = new InstructionsBuilder();
806 List<Instruction> instructions = new ArrayList<>();
807 instructions.add(ib.build());
808 isb.setInstruction(instructions);
812 private static InstructionsBuilder createAppyActionInstruction() {
814 List<Action> actionList = new ArrayList<>();
815 ActionBuilder ab = new ActionBuilder();
816 ControllerActionBuilder controller = new ControllerActionBuilder();
817 controller.setMaxLength(5);
818 ab.setAction(new ControllerActionCaseBuilder().setControllerAction(controller.build()).build());
819 actionList.add(ab.build());
820 // Create an Apply Action
821 ApplyActionsBuilder aab = new ApplyActionsBuilder();
822 aab.setAction(actionList);
824 // Wrap our Apply Action in an Instruction
825 InstructionBuilder ib = new InstructionBuilder();
826 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
828 // Put our Instruction in a list of Instructions
829 InstructionsBuilder isb = new InstructionsBuilder();
830 List<Instruction> instructions = new ArrayList<>();
831 instructions.add(ib.build());
832 isb.setInstruction(instructions);
836 private static InstructionsBuilder createSentToControllerInstructions() {
837 ActionBuilder ab = new ActionBuilder();
839 OutputActionBuilder output = new OutputActionBuilder();
840 output.setMaxLength(0xffff);
841 Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
842 output.setOutputNodeConnector(value);
843 ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
845 ab.setKey(new ActionKey(0));
847 List<Action> actionList = new ArrayList<>();
848 actionList.add(ab.build());
849 // Create an Apply Action
850 ApplyActionsBuilder aab = new ApplyActionsBuilder();
851 aab.setAction(actionList);
853 // Wrap our Apply Action in an Instruction
854 InstructionBuilder ib = new InstructionBuilder();
855 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
857 ib.setKey(new InstructionKey(0));
859 // Put our Instruction in a list of Instructions
860 InstructionsBuilder isb = new InstructionsBuilder();
861 List<Instruction> instructions = new ArrayList<>();
862 instructions.add(ib.build());
863 isb.setInstruction(instructions);
867 private static InstructionsBuilder createAppyActionInstruction2() {
869 List<Action> actionList = new ArrayList<>();
870 ActionBuilder ab = new ActionBuilder();
872 PushMplsActionBuilder push = new PushMplsActionBuilder();
873 push.setEthernetType(0x8847);
874 ab.setAction(new PushMplsActionCaseBuilder().setPushMplsAction(push.build()).build());
875 actionList.add(ab.build());
876 // Create an Apply Action
877 ApplyActionsBuilder aab = new ApplyActionsBuilder();
878 aab.setAction(actionList);
880 // Wrap our Apply Action in an Instruction
881 InstructionBuilder ib = new InstructionBuilder();
882 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
884 // Put our Instruction in a list of Instructions
885 InstructionsBuilder isb = new InstructionsBuilder();
886 List<Instruction> instructions = new ArrayList<>();
887 instructions.add(ib.build());
888 isb.setInstruction(instructions);
892 private static InstructionsBuilder createAppyActionInstruction3() {
894 List<Action> actionList = new ArrayList<>();
895 ActionBuilder ab = new ActionBuilder();
897 PushPbbActionBuilder pbb = new PushPbbActionBuilder();
898 pbb.setEthernetType(0x88E7);
899 ab.setAction(new PushPbbActionCaseBuilder().setPushPbbAction(pbb.build()).build());
900 actionList.add(ab.build());
901 // Create an Apply Action
902 ApplyActionsBuilder aab = new ApplyActionsBuilder();
903 aab.setAction(actionList);
905 // Wrap our Apply Action in an Instruction
906 InstructionBuilder ib = new InstructionBuilder();
907 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
909 // Put our Instruction in a list of Instructions
910 InstructionsBuilder isb = new InstructionsBuilder();
911 List<Instruction> instructions = new ArrayList<>();
912 instructions.add(ib.build());
913 isb.setInstruction(instructions);
917 private static InstructionsBuilder createAppyActionInstruction6() {
919 List<Action> actionList = new ArrayList<>();
920 ActionBuilder ab = new ActionBuilder();
922 SetDlSrcActionBuilder src = new SetDlSrcActionBuilder();
923 src.setAddress(new MacAddress("00:05:b9:7c:81:5f"));
924 ab.setAction(new SetDlSrcActionCaseBuilder().setSetDlSrcAction(src.build()).build());
925 actionList.add(ab.build());
927 // Create an Apply Action
928 ApplyActionsBuilder aab = new ApplyActionsBuilder();
929 aab.setAction(actionList);
931 // Wrap our Apply Action in an Instruction
932 InstructionBuilder ib = new InstructionBuilder();
933 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
935 // Put our Instruction in a list of Instructions
936 InstructionsBuilder isb = new InstructionsBuilder();
937 List<Instruction> instructions = new ArrayList<>();
938 instructions.add(ib.build());
939 isb.setInstruction(instructions);
943 private static InstructionsBuilder createAppyActionInstruction7() {
945 List<Action> actionList = new ArrayList<>();
946 ActionBuilder ab = new ActionBuilder();
948 SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
949 VlanId vlanId = new VlanId(4012);
950 vl.setVlanId(vlanId);
951 ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.build()).build());
952 actionList.add(ab.build());
953 // Create an Apply Action
954 ApplyActionsBuilder aab = new ApplyActionsBuilder();
955 aab.setAction(actionList);
957 // Wrap our Apply Action in an Instruction
958 InstructionBuilder ib = new InstructionBuilder();
959 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
961 // Put our Instruction in a list of Instructions
962 InstructionsBuilder isb = new InstructionsBuilder();
963 List<Instruction> instructions = new ArrayList<>();
964 instructions.add(ib.build());
965 isb.setInstruction(instructions);
969 private static InstructionsBuilder createAppyActionInstruction8() {
971 List<Action> actionList = new ArrayList<>();
972 ActionBuilder ab = new ActionBuilder();
974 SetVlanPcpActionBuilder pcp = new SetVlanPcpActionBuilder();
975 VlanPcp pcp1 = new VlanPcp((short) 2);
976 pcp.setVlanPcp(pcp1);
977 ab.setAction(new SetVlanPcpActionCaseBuilder().setSetVlanPcpAction(pcp.build()).build());
978 actionList.add(ab.build());
979 // Create an Apply Action
980 ApplyActionsBuilder aab = new ApplyActionsBuilder();
981 aab.setAction(actionList);
983 // Wrap our Apply Action in an Instruction
984 InstructionBuilder ib = new InstructionBuilder();
985 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
987 // Put our Instruction in a list of Instructions
988 InstructionsBuilder isb = new InstructionsBuilder();
989 List<Instruction> instructions = new ArrayList<>();
990 instructions.add(ib.build());
991 isb.setInstruction(instructions);
995 private static InstructionsBuilder createAppyActionInstruction9() {
997 List<Action> actionList = new ArrayList<>();
998 ActionBuilder ab = new ActionBuilder();
1000 CopyTtlInBuilder ttlin = new CopyTtlInBuilder();
1001 ab.setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(ttlin.build()).build());
1002 actionList.add(ab.build());
1003 // Create an Apply Action
1004 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1005 aab.setAction(actionList);
1007 // Wrap our Apply Action in an Instruction
1008 InstructionBuilder ib = new InstructionBuilder();
1009 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1011 // Put our Instruction in a list of Instructions
1012 InstructionsBuilder isb = new InstructionsBuilder();
1013 List<Instruction> instructions = new ArrayList<>();
1014 instructions.add(ib.build());
1015 isb.setInstruction(instructions);
1019 private static InstructionsBuilder createAppyActionInstruction16() {
1020 ActionBuilder ab = new ActionBuilder();
1022 GroupActionBuilder groupActionB = new GroupActionBuilder();
1023 groupActionB.setGroupId(1L);
1024 groupActionB.setGroup("0");
1025 ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
1027 List<Action> actionList = new ArrayList<>();
1028 actionList.add(ab.build());
1030 // Create an Apply Action
1031 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1032 aab.setAction(actionList);
1034 // Wrap our Apply Action in an Instruction
1035 InstructionBuilder ib = new InstructionBuilder();
1036 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1038 // Put our Instruction in a list of Instructions
1039 InstructionsBuilder isb = new InstructionsBuilder();
1040 List<Instruction> instructions = new ArrayList<>();
1041 instructions.add(ib.build());
1042 isb.setInstruction(instructions);
1046 private static InstructionsBuilder createAppyActionInstruction160() {
1048 List<Action> actionList = new ArrayList<>();
1049 ActionBuilder ab = new ActionBuilder();
1051 FloodAllActionBuilder fldall = new FloodAllActionBuilder();
1052 ab.setAction(new FloodAllActionCaseBuilder().setFloodAllAction(fldall.build()).build());
1053 actionList.add(ab.build());
1054 // Create an Apply Action
1055 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1056 aab.setAction(actionList);
1058 // Wrap our Apply Action in an Instruction
1059 InstructionBuilder ib = new InstructionBuilder();
1060 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1062 // Put our Instruction in a list of Instructions
1063 InstructionsBuilder isb = new InstructionsBuilder();
1064 List<Instruction> instructions = new ArrayList<>();
1065 instructions.add(ib.build());
1066 isb.setInstruction(instructions);
1070 private static InstructionsBuilder createAppyActionInstruction26() {
1071 ActionBuilder ab = new ActionBuilder();
1073 SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
1074 Ipv4Builder ipdst = new Ipv4Builder();
1075 Ipv4Prefix prefixdst = new Ipv4Prefix("10.0.0.21/24");
1076 ipdst.setIpv4Address(prefixdst);
1077 setNwDstActionBuilder.setAddress(ipdst.build());
1078 ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
1080 List<Action> actionList = new ArrayList<>();
1081 actionList.add(ab.build());
1083 // Create an Apply Action
1084 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1085 aab.setAction(actionList);
1087 // Wrap our Apply Action in an Instruction
1088 InstructionBuilder ib = new InstructionBuilder();
1089 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1091 // Put our Instruction in a list of Instructions
1092 InstructionsBuilder isb = new InstructionsBuilder();
1093 List<Instruction> instructions = new ArrayList<>();
1094 instructions.add(ib.build());
1095 isb.setInstruction(instructions);
1099 private static InstructionsBuilder createAppyActionInstruction27() {
1100 ActionBuilder ab = new ActionBuilder();
1102 SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
1103 Ipv4Builder ipsrc = new Ipv4Builder();
1104 Ipv4Prefix prefixsrc = new Ipv4Prefix("10.0.23.21/24");
1105 ipsrc.setIpv4Address(prefixsrc);
1106 setNwsrcActionBuilder.setAddress(ipsrc.build());
1107 ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
1109 List<Action> actionList = new ArrayList<>();
1110 actionList.add(ab.build());
1112 // Create an Apply Action
1113 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1114 aab.setAction(actionList);
1116 // Wrap our Apply Action in an Instruction
1117 InstructionBuilder ib = new InstructionBuilder();
1118 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1120 // Put our Instruction in a list of Instructions
1121 InstructionsBuilder isb = new InstructionsBuilder();
1122 List<Instruction> instructions = new ArrayList<>();
1123 instructions.add(ib.build());
1124 isb.setInstruction(instructions);
1128 private static InstructionsBuilder createAppyActionInstruction28() {
1130 List<Action> actionList = new ArrayList<>();
1131 ActionBuilder ab = new ActionBuilder();
1133 SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
1134 setNwTosActionBuilder.setTos(8);
1135 ab.setAction(new SetNwTosActionCaseBuilder().setSetNwTosAction(setNwTosActionBuilder.build()).build());
1136 actionList.add(ab.build());
1137 // Create an Apply Action
1138 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1139 aab.setAction(actionList);
1141 // Wrap our Apply Action in an Instruction
1142 InstructionBuilder ib = new InstructionBuilder();
1143 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1145 // Put our Instruction in a list of Instructions
1146 InstructionsBuilder isb = new InstructionsBuilder();
1147 List<Instruction> instructions = new ArrayList<>();
1148 instructions.add(ib.build());
1149 isb.setInstruction(instructions);
1153 private static InstructionsBuilder createAppyActionInstruction34() {
1155 List<Action> actionList = new ArrayList<>();
1156 ActionBuilder ab = new ActionBuilder();
1158 SwPathActionBuilder swPathAction = new SwPathActionBuilder();
1159 ab.setAction(new SwPathActionCaseBuilder().setSwPathAction(swPathAction.build()).build());
1160 actionList.add(ab.build());
1162 // Create an Apply Action
1163 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1164 aab.setAction(actionList);
1166 // Wrap our Apply Action in an Instruction
1167 InstructionBuilder ib = new InstructionBuilder();
1168 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1170 // Put our Instruction in a list of Instructions
1171 InstructionsBuilder isb = new InstructionsBuilder();
1172 List<Instruction> instructions = new ArrayList<>();
1173 instructions.add(ib.build());
1174 isb.setInstruction(instructions);
1178 private static MatchBuilder createLLDPMatch() {
1179 MatchBuilder match = new MatchBuilder();
1180 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1181 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1182 ethTypeBuilder.setType(new EtherType(0x88ccL));
1183 eth.setEthernetType(ethTypeBuilder.build());
1184 match.setEthernetMatch(eth.build());
1188 private static MatchBuilder createMatch1() {
1189 MatchBuilder match = new MatchBuilder();
1190 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1191 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
1192 ipv4Match.setIpv4Destination(prefix);
1193 Ipv4Match i4m = ipv4Match.build();
1194 match.setLayer3Match(i4m);
1196 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1197 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1198 ethTypeBuilder.setType(new EtherType(0x0800L));
1199 eth.setEthernetType(ethTypeBuilder.build());
1200 match.setEthernetMatch(eth.build());
1204 private static MatchBuilder createMatch1000() {
1205 MatchBuilder match = new MatchBuilder();
1206 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1207 Ipv4Prefix prefix = new Ipv4Prefix("10.1.1.1/24");
1208 ipv4Match.setIpv4Destination(prefix);
1209 Ipv4Match i4m = ipv4Match.build();
1210 match.setLayer3Match(i4m);
1212 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1213 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1214 ethTypeBuilder.setType(new EtherType(0x0800L));
1215 eth.setEthernetType(ethTypeBuilder.build());
1216 match.setEthernetMatch(eth.build());
1220 private static MatchBuilder createMatch2() {
1221 MatchBuilder match = new MatchBuilder();
1222 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1223 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1");
1224 ipv4Match.setIpv4Source(prefix);
1225 Ipv4Match i4m = ipv4Match.build();
1226 match.setLayer3Match(i4m);
1228 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1229 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1230 ethTypeBuilder.setType(new EtherType(0x0800L));
1231 eth.setEthernetType(ethTypeBuilder.build());
1232 match.setEthernetMatch(eth.build());
1236 private static MatchBuilder createMatch3() {
1237 MatchBuilder match = new MatchBuilder();
1238 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
1239 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
1240 ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
1241 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
1242 match.setEthernetMatch(ethernetMatch.build());
1247 private static MatchBuilder createInphyportMatch(NodeId nodeId) {
1248 MatchBuilder match = new MatchBuilder();
1249 match.setInPort(new NodeConnectorId(nodeId + ":202"));
1250 match.setInPhyPort(new NodeConnectorId(nodeId + ":10122"));
1254 private static MatchBuilder createEthernetMatch() {
1255 EthernetMatchBuilder ethmatch = new EthernetMatchBuilder(); // ethernettype
1257 EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
1258 EtherType type = new EtherType(0x0800L);
1259 ethmatch.setEthernetType(ethtype.setType(type).build());
1261 EthernetDestinationBuilder ethdest = new EthernetDestinationBuilder(); // ethernet
1264 MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
1265 ethdest.setAddress(macdest);
1266 // ethdest.setMask(mask1);
1268 ethmatch.setEthernetDestination(ethdest.build());
1270 EthernetSourceBuilder ethsrc = new EthernetSourceBuilder();
1271 MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
1272 ethsrc.setAddress(macsrc);
1273 // ethsrc.setMask(mask2);
1275 ethmatch.setEthernetSource(ethsrc.build());
1277 MatchBuilder match = new MatchBuilder();
1278 match.setEthernetMatch(ethmatch.build());
1283 private static MatchBuilder createL3IPv6Match() {
1284 MatchBuilder match = new MatchBuilder();
1286 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1287 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1288 ethTypeBuilder.setType(new EtherType(0x86ddL));
1289 eth.setEthernetType(ethTypeBuilder.build());
1290 match.setEthernetMatch(eth.build());
1292 Ipv6ExtHeaderBuilder nextheader = new Ipv6ExtHeaderBuilder();
1293 nextheader.setIpv6Exthdr(58);
1294 Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
1295 Ipv6FlowLabel label = new Ipv6FlowLabel(10028L);
1296 ipv6label.setIpv6Flabel(label);
1297 // ipv6label.setFlabelMask(new byte[] { 0, 1, -1, -1 });
1299 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1301 icmpv6match.setIcmpv6Type((short) 135);
1302 icmpv6match.setIcmpv6Code((short) 0);
1303 match.setIcmpv6Match(icmpv6match.build());
1305 Ipv6MatchBuilder ipv6match = new Ipv6MatchBuilder();
1306 // ipv6match.setIpv6Source(srcip6);
1307 // ipv6match.setIpv6Destination(dstip6);
1308 // ipv6match.setIpv6ExtHeader(nextheader.build());
1310 ipv6match.setIpv6NdSll(new MacAddress("c2:00:54:f5:00:00"));
1311 ipv6match.setIpv6NdTll(new MacAddress("00:0c:29:0e:4c:67"));
1312 // ipv6match.setIpv6NdTarget(ndtarget);
1313 ipv6match.setIpv6Label(ipv6label.build());
1315 match.setLayer3Match(ipv6match.build());
1320 private static MatchBuilder createICMPv6Match() {
1322 MatchBuilder match = new MatchBuilder();
1323 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1324 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1325 ethTypeBuilder.setType(new EtherType(0x86ddL));
1326 eth.setEthernetType(ethTypeBuilder.build());
1327 match.setEthernetMatch(eth.build());
1329 IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
1330 ipmatch.setIpProtocol((short) 58);
1331 match.setIpMatch(ipmatch.build());
1333 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1335 icmpv6match.setIcmpv6Type((short) 135);
1336 icmpv6match.setIcmpv6Code((short) 1);
1337 match.setIcmpv6Match(icmpv6match.build());
1342 private static MatchBuilder createMetadataMatch() {
1343 MatchBuilder match = new MatchBuilder();
1344 MetadataBuilder metadata = new MetadataBuilder(); // metadata match
1345 metadata.setMetadata(BigInteger.valueOf(500L));
1346 // metadata.setMetadataMask(metamask);
1347 match.setMetadata(metadata.build());