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
8 package org.opendaylight.openflowplugin.test;
10 import com.google.common.util.concurrent.FutureCallback;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.eclipse.osgi.framework.console.CommandInterpreter;
15 import org.eclipse.osgi.framework.console.CommandProvider;
16 import org.opendaylight.mdsal.binding.api.DataBroker;
17 import org.opendaylight.mdsal.binding.api.NotificationService;
18 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
19 import org.opendaylight.mdsal.common.api.CommitInfo;
20 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.all.action._case.FloodAllActionBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.sw.path.action._case.SwPathActionBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.node.error.service.rev140410.NodeErrorListener;
106 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
107 import org.opendaylight.yangtools.yang.common.Uint16;
108 import org.opendaylight.yangtools.yang.common.Uint32;
109 import org.opendaylight.yangtools.yang.common.Uint64;
110 import org.opendaylight.yangtools.yang.common.Uint8;
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 flow.setCookie(new FlowCookie(Uint64.TEN));
399 flow.setCookieMask(new FlowCookie(Uint64.TEN));
400 flow.setHardTimeout(Uint16.ZERO);
401 flow.setIdleTimeout(Uint16.ZERO);
402 flow.setInstallHw(false);
403 flow.setStrict(false);
404 flow.setContainerName(null);
405 flow.setFlags(new FlowModFlags(false, false, false, false, true));
406 flow.setId(new FlowId("12"));
407 flow.setTableId(getTableId(tableId));
408 flow.setOutGroup(Uint32.MAX_VALUE);
409 // set outport to OFPP_NONE (65535) to disable remove restriction for
411 flow.setOutPort(Uint64.valueOf(4294967295L));
413 FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
415 flow.setPriority(Uint16.TWO);
416 flow.setFlowName(originalFlowName + "X" + flowType);
420 private static Uint8 getTableId(String tableId) {
421 if (tableId != null) {
423 return Uint8.valueOf(tableId);
424 } catch (IllegalArgumentException ex) {
425 // ignore exception and continue with default value
431 public void _addFlows(CommandInterpreter ci) {
432 NodeBuilder tn = createTestNode(ci.nextArgument());
433 String flowtype = ci.nextArgument();
434 Integer flowcnt = Integer.parseInt(flowtype);
441 tf = createTestFlow(tn, "f1", "10");
442 tf1 = createTestFlow(tn, "f2", "11");
443 tf2 = createTestFlow(tn, "f3", "12");
444 tf3 = createTestFlow(tn, "f4", "13");
447 tf = createTestFlow(tn, "f3", "3");
448 tf1 = createTestFlow(tn, "f4", "4");
449 tf2 = createTestFlow(tn, "f5", "5");
450 tf3 = createTestFlow(tn, "f6", "6");
453 tf = createTestFlow(tn, "f7", "7");
454 tf1 = createTestFlow(tn, "f8", "8");
455 tf2 = createTestFlow(tn, "f9", "9");
456 tf3 = createTestFlow(tn, "f10", "10");
460 tf = createTestFlow(tn, "f23", "3");
461 tf1 = createTestFlow(tn, "f34", "4");
462 tf2 = createTestFlow(tn, "f35", "5");
463 tf3 = createTestFlow(tn, "f36", "6");
468 tf = createTestFlow(tn, "f230", "3");
469 tf1 = createTestFlow(tn, "f34", "4");
470 tf2 = createTestFlow(tn, "f35", "5");
471 tf3 = createTestFlow(tn, "f36", "6");
475 tf = createTestFlow(tn, "f42", "42");
476 tf1 = createTestFlow(tn, "f43", "43");
477 tf2 = createTestFlow(tn, "f44", "44");
478 tf3 = createTestFlow(tn, "f45", "45");
481 writeFlow(ci, tf, tf1, tf2, tf3, tn);
484 private InstanceIdentifier<Node> nodeBuilderToInstanceId(NodeBuilder node) {
485 return InstanceIdentifier.create(Nodes.class).child(Node.class, node.key());
488 public void _modifyFlows(CommandInterpreter ci) {
489 NodeBuilder tn = createTestNode(ci.nextArgument());
490 String flowtype = ci.nextArgument();
491 Integer flowcnt = Integer.parseInt(flowtype);
498 tf = createTestFlow(tn, "f82", "10");
499 tf1 = createTestFlow(tn, "f83", "11");
500 tf2 = createTestFlow(tn, "f84", "12");
501 tf3 = createTestFlow(tn, "f85", "13");
504 tf = createTestFlow(tn, "f700", "3");
505 tf1 = createTestFlow(tn, "f4", "4");
506 tf2 = createTestFlow(tn, "f900", "5");
507 tf3 = createTestFlow(tn, "f86", "6");
511 tf = createTestFlow(tn, "f91", "7");
512 tf1 = createTestFlow(tn, "f92", "8");
513 tf2 = createTestFlow(tn, "f93", "9");
514 tf3 = createTestFlow(tn, "f94", "10");
518 tf = createTestFlow(tn, "f230", "3");
519 tf1 = createTestFlow(tn, "f99", "4");
520 tf2 = createTestFlow(tn, "f100", "5");
521 tf3 = createTestFlow(tn, "f101", "6");
525 tf = createTestFlow(tn, "f23", "3");
526 tf1 = createTestFlow(tn, "f99", "4");
527 tf2 = createTestFlow(tn, "f100", "5");
528 tf3 = createTestFlow(tn, "f101", "6");
532 tf = createTestFlow(tn, "f87", "12");
533 tf1 = createTestFlow(tn, "f88", "13");
534 tf2 = createTestFlow(tn, "f89", "14");
535 tf3 = createTestFlow(tn, "f90", "15");
539 writeFlow(ci, tf, tf1, tf2, tf3, tn);
543 public void _removeFlows(final CommandInterpreter ci) {
544 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
545 NodeBuilder tn = createTestNode(ci.nextArgument());
546 String flowtype = ci.nextArgument();
547 Integer flowcnt = Integer.parseInt(flowtype);
548 FlowBuilder tf = null;
549 FlowBuilder tf1 = null;
550 FlowBuilder tf2 = null;
551 FlowBuilder tf3 = null;
555 tf = createTestFlow(tn, "f1", "10");
556 tf1 = createTestFlow(tn, "f2", "11");
557 tf2 = createTestFlow(tn, "f3", "12");
558 tf3 = createTestFlow(tn, "f4", "13");
562 tf = createTestFlow(tn, "f82", "10");
563 tf1 = createTestFlow(tn, "f83", "11");
564 tf2 = createTestFlow(tn, "f84", "12");
565 tf3 = createTestFlow(tn, "f85", "13");
569 tf = createTestFlow(tn, "f3", "3");
570 tf1 = createTestFlow(tn, "f4", "4");
571 tf2 = createTestFlow(tn, "f5", "5");
572 tf3 = createTestFlow(tn, "f6", "6");
576 tf = createTestFlow(tn, "f700", "3");
577 tf1 = createTestFlow(tn, "f4", "4");
578 tf2 = createTestFlow(tn, "f900", "5");
579 tf3 = createTestFlow(tn, "f86", "6");
583 tf = createTestFlow(tn, "f7", "7");
584 tf1 = createTestFlow(tn, "f8", "8");
585 tf2 = createTestFlow(tn, "f9", "9");
586 tf3 = createTestFlow(tn, "f10", "10");
590 tf = createTestFlow(tn, "f91", "7");
591 tf1 = createTestFlow(tn, "f92", "8");
592 tf2 = createTestFlow(tn, "f93", "9");
593 tf3 = createTestFlow(tn, "f94", "10");
597 tf = createTestFlow(tn, "f23", "3");
598 tf1 = createTestFlow(tn, "f34", "4");
599 tf2 = createTestFlow(tn, "f35", "5");
600 tf3 = createTestFlow(tn, "f36", "6");
605 tf = createTestFlow(tn, "f23", "3");
606 tf1 = createTestFlow(tn, "f99", "4");
607 tf2 = createTestFlow(tn, "f100", "5");
608 tf3 = createTestFlow(tn, "f101", "6");
612 tf = createTestFlow(tn, "f700", "7");
613 tf1 = createTestFlow(tn, "f230", "23");
614 tf2 = createTestFlow(tn, "f900", "9");
615 tf3 = createTestFlow(tn, "f1000", "10");
618 throw new IllegalArgumentException("Invalid flowtype: " + flowtype);
621 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
622 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
623 .child(Flow.class, tf.key());
624 modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
625 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
626 modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
627 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
628 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf1.getTableId()))
629 .child(Flow.class, tf1.key());
630 modification.delete(LogicalDatastoreType.OPERATIONAL, path2);
631 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
632 modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
634 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
635 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf2.getTableId()))
636 .child(Flow.class, tf2.key());
637 modification.delete(LogicalDatastoreType.OPERATIONAL, path3);
638 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
639 modification.delete(LogicalDatastoreType.CONFIGURATION, path3);
640 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
641 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf3.getTableId()))
642 .child(Flow.class, tf3.key());
643 modification.delete(LogicalDatastoreType.OPERATIONAL, path4);
644 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
645 modification.delete(LogicalDatastoreType.CONFIGURATION, path4);
646 modification.commit().addCallback(new FutureCallback<CommitInfo>() {
648 public void onSuccess(CommitInfo notUsed) {
649 ci.println("Status of Group Data Loaded Transaction: success.");
653 public void onFailure(Throwable throwable) {
654 LOG.error("Status of Group Data Loaded Transaction : failure.", throwable);
655 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
657 }, MoreExecutors.directExecutor());
661 private void writeFlow(final CommandInterpreter ci, FlowBuilder flow, FlowBuilder flow1, FlowBuilder flow2,
662 FlowBuilder flow3, NodeBuilder nodeBuilder) {
663 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
664 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class)
665 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
666 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.key());
667 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder),
668 nodeBuilder.build());
669 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path1, flow.build());
670 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
671 nodeBuilder.build());
672 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path1, flow.build());
673 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class)
674 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
675 .child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.key());
676 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder),
677 nodeBuilder.build());
678 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path2, flow1.build());
679 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
680 nodeBuilder.build());
681 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path2, flow1.build());
683 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class)
684 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
685 .child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.key());
686 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder),
687 nodeBuilder.build());
688 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path3, flow2.build());
689 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
690 nodeBuilder.build());
691 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path3, flow2.build());
693 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class)
694 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
695 .child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.key());
696 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder),
697 nodeBuilder.build());
698 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path4, flow3.build());
699 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
700 nodeBuilder.build());
701 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path4, flow3.build());
702 modification.commit().addCallback(new FutureCallback<CommitInfo>() {
704 public void onSuccess(CommitInfo notUsed) {
705 ci.println("Status of Group Data Loaded Transaction: success.");
709 public void onFailure(Throwable throwable) {
710 LOG.error("Status of Group Data Loaded Transaction : failure.", throwable);
711 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
713 }, MoreExecutors.directExecutor());
716 private static InstructionsBuilder createDecNwTtlInstructions() {
717 DecNwTtlBuilder ta = new DecNwTtlBuilder();
718 DecNwTtl decNwTtl = ta.build();
719 ActionBuilder ab = new ActionBuilder();
720 ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
722 // Add our drop action to a list
723 List<Action> actionList = new ArrayList<>();
724 actionList.add(ab.build());
726 // Create an Apply Action
727 ApplyActionsBuilder aab = new ApplyActionsBuilder();
728 aab.setAction(actionList);
730 // Wrap our Apply Action in an Instruction
731 InstructionBuilder ib = new InstructionBuilder();
732 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
733 ib.withKey(new InstructionKey(0));
736 // Put our Instruction in a list of Instructions
737 InstructionsBuilder isb = new InstructionsBuilder();
738 List<Instruction> instructions = new ArrayList<>();
739 instructions.add(ib.build());
740 isb.setInstruction(instructions);
744 private static InstructionsBuilder createMeterInstructions() {
746 MeterBuilder aab = new MeterBuilder();
747 aab.setMeterId(new MeterId(Uint32.ONE));
749 InstructionBuilder ib = new InstructionBuilder();
750 ib.setInstruction(new MeterCaseBuilder().setMeter(aab.build()).build());
752 // Put our Instruction in a list of Instructions
753 InstructionsBuilder isb = new InstructionsBuilder();
754 List<Instruction> instructions = new ArrayList<>();
755 instructions.add(ib.build());
756 isb.setInstruction(instructions);
760 private static InstructionsBuilder createGotoTableInstructions() {
762 GoToTableBuilder aab = new GoToTableBuilder();
763 aab.setTableId(Uint8.TWO);
765 InstructionBuilder ib = new InstructionBuilder();
766 ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(aab.build()).build());
768 // Put our Instruction in a list of Instructions
769 InstructionsBuilder isb = new InstructionsBuilder();
770 List<Instruction> instructions = new ArrayList<>();
771 instructions.add(ib.build());
772 isb.setInstruction(instructions);
776 private static InstructionsBuilder createDropInstructions() {
777 DropActionBuilder dab = new DropActionBuilder();
778 DropAction dropAction = dab.build();
779 ActionBuilder ab = new ActionBuilder();
780 ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
782 // Add our drop action to a list
783 List<Action> actionList = new ArrayList<>();
784 actionList.add(ab.build());
786 // Create an Apply Action
787 ApplyActionsBuilder aab = new ApplyActionsBuilder();
788 aab.setAction(actionList);
790 // Wrap our Apply Action in an Instruction
791 InstructionBuilder ib = new InstructionBuilder();
792 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
794 // Put our Instruction in a list of Instructions
795 InstructionsBuilder isb = new InstructionsBuilder();
796 List<Instruction> instructions = new ArrayList<>();
797 instructions.add(ib.build());
798 isb.setInstruction(instructions);
802 private static InstructionsBuilder createAppyActionInstruction() {
804 List<Action> actionList = new ArrayList<>();
805 ActionBuilder ab = new ActionBuilder();
806 ControllerActionBuilder controller = new ControllerActionBuilder();
807 controller.setMaxLength(Uint16.valueOf(5));
808 ab.setAction(new ControllerActionCaseBuilder().setControllerAction(controller.build()).build());
809 actionList.add(ab.build());
810 // Create an Apply Action
811 ApplyActionsBuilder aab = new ApplyActionsBuilder();
812 aab.setAction(actionList);
814 // Wrap our Apply Action in an Instruction
815 InstructionBuilder ib = new InstructionBuilder();
816 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
818 // Put our Instruction in a list of Instructions
819 InstructionsBuilder isb = new InstructionsBuilder();
820 List<Instruction> instructions = new ArrayList<>();
821 instructions.add(ib.build());
822 isb.setInstruction(instructions);
826 private static InstructionsBuilder createSentToControllerInstructions() {
827 ActionBuilder ab = new ActionBuilder();
829 OutputActionBuilder output = new OutputActionBuilder();
830 output.setMaxLength(Uint16.MAX_VALUE);
831 Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
832 output.setOutputNodeConnector(value);
833 ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
835 ab.withKey(new ActionKey(0));
837 List<Action> actionList = new ArrayList<>();
838 actionList.add(ab.build());
839 // Create an Apply Action
840 ApplyActionsBuilder aab = new ApplyActionsBuilder();
841 aab.setAction(actionList);
843 // Wrap our Apply Action in an Instruction
844 InstructionBuilder ib = new InstructionBuilder();
845 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
847 ib.withKey(new InstructionKey(0));
849 // Put our Instruction in a list of Instructions
850 InstructionsBuilder isb = new InstructionsBuilder();
851 List<Instruction> instructions = new ArrayList<>();
852 instructions.add(ib.build());
853 isb.setInstruction(instructions);
857 private static InstructionsBuilder createAppyActionInstruction2() {
859 List<Action> actionList = new ArrayList<>();
860 ActionBuilder ab = new ActionBuilder();
862 PushMplsActionBuilder push = new PushMplsActionBuilder();
863 push.setEthernetType(Uint16.valueOf(0x8847));
864 ab.setAction(new PushMplsActionCaseBuilder().setPushMplsAction(push.build()).build());
865 actionList.add(ab.build());
866 // Create an Apply Action
867 ApplyActionsBuilder aab = new ApplyActionsBuilder();
868 aab.setAction(actionList);
870 // Wrap our Apply Action in an Instruction
871 InstructionBuilder ib = new InstructionBuilder();
872 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
874 // Put our Instruction in a list of Instructions
875 InstructionsBuilder isb = new InstructionsBuilder();
876 List<Instruction> instructions = new ArrayList<>();
877 instructions.add(ib.build());
878 isb.setInstruction(instructions);
882 private static InstructionsBuilder createAppyActionInstruction3() {
884 List<Action> actionList = new ArrayList<>();
885 ActionBuilder ab = new ActionBuilder();
887 PushPbbActionBuilder pbb = new PushPbbActionBuilder();
888 pbb.setEthernetType(Uint16.valueOf(0x88E7));
889 ab.setAction(new PushPbbActionCaseBuilder().setPushPbbAction(pbb.build()).build());
890 actionList.add(ab.build());
891 // Create an Apply Action
892 ApplyActionsBuilder aab = new ApplyActionsBuilder();
893 aab.setAction(actionList);
895 // Wrap our Apply Action in an Instruction
896 InstructionBuilder ib = new InstructionBuilder();
897 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
899 // Put our Instruction in a list of Instructions
900 InstructionsBuilder isb = new InstructionsBuilder();
901 List<Instruction> instructions = new ArrayList<>();
902 instructions.add(ib.build());
903 isb.setInstruction(instructions);
907 private static InstructionsBuilder createAppyActionInstruction6() {
909 List<Action> actionList = new ArrayList<>();
910 ActionBuilder ab = new ActionBuilder();
912 SetDlSrcActionBuilder src = new SetDlSrcActionBuilder();
913 src.setAddress(new MacAddress("00:05:b9:7c:81:5f"));
914 ab.setAction(new SetDlSrcActionCaseBuilder().setSetDlSrcAction(src.build()).build());
915 actionList.add(ab.build());
917 // Create an Apply Action
918 ApplyActionsBuilder aab = new ApplyActionsBuilder();
919 aab.setAction(actionList);
921 // Wrap our Apply Action in an Instruction
922 InstructionBuilder ib = new InstructionBuilder();
923 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
925 // Put our Instruction in a list of Instructions
926 InstructionsBuilder isb = new InstructionsBuilder();
927 List<Instruction> instructions = new ArrayList<>();
928 instructions.add(ib.build());
929 isb.setInstruction(instructions);
933 private static InstructionsBuilder createAppyActionInstruction7() {
935 List<Action> actionList = new ArrayList<>();
936 ActionBuilder ab = new ActionBuilder();
938 SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
939 VlanId vlanId = new VlanId(Uint16.valueOf(4012));
940 vl.setVlanId(vlanId);
941 ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.build()).build());
942 actionList.add(ab.build());
943 // Create an Apply Action
944 ApplyActionsBuilder aab = new ApplyActionsBuilder();
945 aab.setAction(actionList);
947 // Wrap our Apply Action in an Instruction
948 InstructionBuilder ib = new InstructionBuilder();
949 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
951 // Put our Instruction in a list of Instructions
952 InstructionsBuilder isb = new InstructionsBuilder();
953 List<Instruction> instructions = new ArrayList<>();
954 instructions.add(ib.build());
955 isb.setInstruction(instructions);
959 private static InstructionsBuilder createAppyActionInstruction8() {
961 List<Action> actionList = new ArrayList<>();
962 ActionBuilder ab = new ActionBuilder();
964 SetVlanPcpActionBuilder pcp = new SetVlanPcpActionBuilder();
965 VlanPcp pcp1 = new VlanPcp(Uint8.TWO);
966 pcp.setVlanPcp(pcp1);
967 ab.setAction(new SetVlanPcpActionCaseBuilder().setSetVlanPcpAction(pcp.build()).build());
968 actionList.add(ab.build());
969 // Create an Apply Action
970 ApplyActionsBuilder aab = new ApplyActionsBuilder();
971 aab.setAction(actionList);
973 // Wrap our Apply Action in an Instruction
974 InstructionBuilder ib = new InstructionBuilder();
975 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
977 // Put our Instruction in a list of Instructions
978 InstructionsBuilder isb = new InstructionsBuilder();
979 List<Instruction> instructions = new ArrayList<>();
980 instructions.add(ib.build());
981 isb.setInstruction(instructions);
985 private static InstructionsBuilder createAppyActionInstruction9() {
987 List<Action> actionList = new ArrayList<>();
988 ActionBuilder ab = new ActionBuilder();
990 CopyTtlInBuilder ttlin = new CopyTtlInBuilder();
991 ab.setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(ttlin.build()).build());
992 actionList.add(ab.build());
993 // Create an Apply Action
994 ApplyActionsBuilder aab = new ApplyActionsBuilder();
995 aab.setAction(actionList);
997 // Wrap our Apply Action in an Instruction
998 InstructionBuilder ib = new InstructionBuilder();
999 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1001 // Put our Instruction in a list of Instructions
1002 InstructionsBuilder isb = new InstructionsBuilder();
1003 List<Instruction> instructions = new ArrayList<>();
1004 instructions.add(ib.build());
1005 isb.setInstruction(instructions);
1009 private static InstructionsBuilder createAppyActionInstruction16() {
1010 ActionBuilder ab = new ActionBuilder();
1012 GroupActionBuilder groupActionB = new GroupActionBuilder();
1013 groupActionB.setGroupId(Uint32.ONE);
1014 groupActionB.setGroup("0");
1015 ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
1017 List<Action> actionList = new ArrayList<>();
1018 actionList.add(ab.build());
1020 // Create an Apply Action
1021 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1022 aab.setAction(actionList);
1024 // Wrap our Apply Action in an Instruction
1025 InstructionBuilder ib = new InstructionBuilder();
1026 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1028 // Put our Instruction in a list of Instructions
1029 InstructionsBuilder isb = new InstructionsBuilder();
1030 List<Instruction> instructions = new ArrayList<>();
1031 instructions.add(ib.build());
1032 isb.setInstruction(instructions);
1036 private static InstructionsBuilder createAppyActionInstruction160() {
1038 List<Action> actionList = new ArrayList<>();
1039 ActionBuilder ab = new ActionBuilder();
1041 FloodAllActionBuilder fldall = new FloodAllActionBuilder();
1042 ab.setAction(new FloodAllActionCaseBuilder().setFloodAllAction(fldall.build()).build());
1043 actionList.add(ab.build());
1044 // Create an Apply Action
1045 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1046 aab.setAction(actionList);
1048 // Wrap our Apply Action in an Instruction
1049 InstructionBuilder ib = new InstructionBuilder();
1050 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1052 // Put our Instruction in a list of Instructions
1053 InstructionsBuilder isb = new InstructionsBuilder();
1054 List<Instruction> instructions = new ArrayList<>();
1055 instructions.add(ib.build());
1056 isb.setInstruction(instructions);
1060 private static InstructionsBuilder createAppyActionInstruction26() {
1061 ActionBuilder ab = new ActionBuilder();
1063 SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
1064 Ipv4Builder ipdst = new Ipv4Builder();
1065 Ipv4Prefix prefixdst = new Ipv4Prefix("10.0.0.21/24");
1066 ipdst.setIpv4Address(prefixdst);
1067 setNwDstActionBuilder.setAddress(ipdst.build());
1068 ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
1070 List<Action> actionList = new ArrayList<>();
1071 actionList.add(ab.build());
1073 // Create an Apply Action
1074 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1075 aab.setAction(actionList);
1077 // Wrap our Apply Action in an Instruction
1078 InstructionBuilder ib = new InstructionBuilder();
1079 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1081 // Put our Instruction in a list of Instructions
1082 InstructionsBuilder isb = new InstructionsBuilder();
1083 List<Instruction> instructions = new ArrayList<>();
1084 instructions.add(ib.build());
1085 isb.setInstruction(instructions);
1089 private static InstructionsBuilder createAppyActionInstruction27() {
1090 ActionBuilder ab = new ActionBuilder();
1092 SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
1093 Ipv4Builder ipsrc = new Ipv4Builder();
1094 Ipv4Prefix prefixsrc = new Ipv4Prefix("10.0.23.21/24");
1095 ipsrc.setIpv4Address(prefixsrc);
1096 setNwsrcActionBuilder.setAddress(ipsrc.build());
1097 ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
1099 List<Action> actionList = new ArrayList<>();
1100 actionList.add(ab.build());
1102 // Create an Apply Action
1103 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1104 aab.setAction(actionList);
1106 // Wrap our Apply Action in an Instruction
1107 InstructionBuilder ib = new InstructionBuilder();
1108 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1110 // Put our Instruction in a list of Instructions
1111 InstructionsBuilder isb = new InstructionsBuilder();
1112 List<Instruction> instructions = new ArrayList<>();
1113 instructions.add(ib.build());
1114 isb.setInstruction(instructions);
1118 private static InstructionsBuilder createAppyActionInstruction28() {
1120 List<Action> actionList = new ArrayList<>();
1121 ActionBuilder ab = new ActionBuilder();
1123 SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
1124 setNwTosActionBuilder.setTos(8);
1125 ab.setAction(new SetNwTosActionCaseBuilder().setSetNwTosAction(setNwTosActionBuilder.build()).build());
1126 actionList.add(ab.build());
1127 // Create an Apply Action
1128 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1129 aab.setAction(actionList);
1131 // Wrap our Apply Action in an Instruction
1132 InstructionBuilder ib = new InstructionBuilder();
1133 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1135 // Put our Instruction in a list of Instructions
1136 InstructionsBuilder isb = new InstructionsBuilder();
1137 List<Instruction> instructions = new ArrayList<>();
1138 instructions.add(ib.build());
1139 isb.setInstruction(instructions);
1143 private static InstructionsBuilder createAppyActionInstruction34() {
1145 List<Action> actionList = new ArrayList<>();
1146 ActionBuilder ab = new ActionBuilder();
1148 SwPathActionBuilder swPathAction = new SwPathActionBuilder();
1149 ab.setAction(new SwPathActionCaseBuilder().setSwPathAction(swPathAction.build()).build());
1150 actionList.add(ab.build());
1152 // Create an Apply Action
1153 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1154 aab.setAction(actionList);
1156 // Wrap our Apply Action in an Instruction
1157 InstructionBuilder ib = new InstructionBuilder();
1158 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1160 // Put our Instruction in a list of Instructions
1161 InstructionsBuilder isb = new InstructionsBuilder();
1162 List<Instruction> instructions = new ArrayList<>();
1163 instructions.add(ib.build());
1164 isb.setInstruction(instructions);
1168 private static MatchBuilder createLLDPMatch() {
1169 MatchBuilder match = new MatchBuilder();
1170 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1171 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1172 ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x88cc)));
1173 eth.setEthernetType(ethTypeBuilder.build());
1174 match.setEthernetMatch(eth.build());
1178 private static MatchBuilder createMatch1() {
1179 MatchBuilder match = new MatchBuilder();
1180 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1181 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
1182 ipv4Match.setIpv4Destination(prefix);
1183 Ipv4Match i4m = ipv4Match.build();
1184 match.setLayer3Match(i4m);
1186 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1187 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1188 ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x0800)));
1189 eth.setEthernetType(ethTypeBuilder.build());
1190 match.setEthernetMatch(eth.build());
1194 private static MatchBuilder createMatch1000() {
1195 MatchBuilder match = new MatchBuilder();
1196 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1197 Ipv4Prefix prefix = new Ipv4Prefix("10.1.1.1/24");
1198 ipv4Match.setIpv4Destination(prefix);
1199 Ipv4Match i4m = ipv4Match.build();
1200 match.setLayer3Match(i4m);
1202 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1203 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1204 ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x0800)));
1205 eth.setEthernetType(ethTypeBuilder.build());
1206 match.setEthernetMatch(eth.build());
1210 private static MatchBuilder createMatch2() {
1211 MatchBuilder match = new MatchBuilder();
1212 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1213 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1");
1214 ipv4Match.setIpv4Source(prefix);
1215 Ipv4Match i4m = ipv4Match.build();
1216 match.setLayer3Match(i4m);
1218 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1219 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1220 ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x0800)));
1221 eth.setEthernetType(ethTypeBuilder.build());
1222 match.setEthernetMatch(eth.build());
1226 private static MatchBuilder createMatch3() {
1227 MatchBuilder match = new MatchBuilder();
1228 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
1229 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
1230 ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
1231 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
1232 match.setEthernetMatch(ethernetMatch.build());
1237 private static MatchBuilder createInphyportMatch(NodeId nodeId) {
1238 MatchBuilder match = new MatchBuilder();
1239 match.setInPort(new NodeConnectorId(nodeId + ":202"));
1240 match.setInPhyPort(new NodeConnectorId(nodeId + ":10122"));
1244 private static MatchBuilder createEthernetMatch() {
1245 EthernetMatchBuilder ethmatch = new EthernetMatchBuilder(); // ethernettype
1247 EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
1248 EtherType type = new EtherType(Uint32.valueOf(0x0800));
1249 ethmatch.setEthernetType(ethtype.setType(type).build());
1251 EthernetDestinationBuilder ethdest = new EthernetDestinationBuilder(); // ethernet
1254 MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
1255 ethdest.setAddress(macdest);
1256 // ethdest.setMask(mask1);
1258 ethmatch.setEthernetDestination(ethdest.build());
1260 EthernetSourceBuilder ethsrc = new EthernetSourceBuilder();
1261 MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
1262 ethsrc.setAddress(macsrc);
1263 // ethsrc.setMask(mask2);
1265 ethmatch.setEthernetSource(ethsrc.build());
1267 MatchBuilder match = new MatchBuilder();
1268 match.setEthernetMatch(ethmatch.build());
1273 private static MatchBuilder createL3IPv6Match() {
1274 MatchBuilder match = new MatchBuilder();
1276 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1277 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1278 ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x86dd)));
1279 eth.setEthernetType(ethTypeBuilder.build());
1280 match.setEthernetMatch(eth.build());
1282 Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
1283 Ipv6FlowLabel label = new Ipv6FlowLabel(Uint32.valueOf(10028));
1284 ipv6label.setIpv6Flabel(label);
1285 // ipv6label.setFlabelMask(new byte[] { 0, 1, -1, -1 });
1287 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1289 icmpv6match.setIcmpv6Type(Uint8.valueOf(135));
1290 icmpv6match.setIcmpv6Code(Uint8.ZERO);
1291 match.setIcmpv6Match(icmpv6match.build());
1293 Ipv6MatchBuilder ipv6match = new Ipv6MatchBuilder();
1294 // ipv6match.setIpv6Source(srcip6);
1295 // ipv6match.setIpv6Destination(dstip6);
1296 // ipv6match.setIpv6ExtHeader(nextheader.build());
1298 ipv6match.setIpv6NdSll(new MacAddress("c2:00:54:f5:00:00"));
1299 ipv6match.setIpv6NdTll(new MacAddress("00:0c:29:0e:4c:67"));
1300 // ipv6match.setIpv6NdTarget(ndtarget);
1301 ipv6match.setIpv6Label(ipv6label.build());
1303 match.setLayer3Match(ipv6match.build());
1308 private static MatchBuilder createICMPv6Match() {
1310 MatchBuilder match = new MatchBuilder();
1311 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1312 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1313 ethTypeBuilder.setType(new EtherType(Uint32.valueOf(0x86dd)));
1314 eth.setEthernetType(ethTypeBuilder.build());
1315 match.setEthernetMatch(eth.build());
1317 IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
1318 ipmatch.setIpProtocol(Uint8.valueOf(58));
1319 match.setIpMatch(ipmatch.build());
1321 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1323 icmpv6match.setIcmpv6Type(Uint8.valueOf(135));
1324 icmpv6match.setIcmpv6Code(Uint8.ONE);
1325 match.setIcmpv6Match(icmpv6match.build());
1330 private static MatchBuilder createMetadataMatch() {
1331 MatchBuilder match = new MatchBuilder();
1332 MetadataBuilder metadata = new MetadataBuilder(); // metadata match
1333 metadata.setMetadata(Uint64.valueOf(500));
1334 // metadata.setMetadataMask(metamask);
1335 match.setMetadata(metadata.build());