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.math.BigInteger;
13 import java.util.ArrayList;
14 import java.util.List;
15 import org.eclipse.osgi.framework.console.CommandInterpreter;
16 import org.eclipse.osgi.framework.console.CommandProvider;
17 import org.opendaylight.mdsal.binding.api.DataBroker;
18 import org.opendaylight.mdsal.binding.api.NotificationService;
19 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
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.Ipv6ExtHeaderBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.node.error.service.rev140410.NodeErrorListener;
107 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
108 import org.osgi.framework.BundleContext;
109 import org.slf4j.Logger;
110 import org.slf4j.LoggerFactory;
112 @SuppressWarnings("checkstyle:MethodName")
113 public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
115 private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginBulkTransactionProvider.class);
116 private final DataBroker dataBroker;
117 private final BundleContext ctx;
118 private final String originalFlowName = "Foo";
119 private final NodeErrorListener nodeErrorListener = new NodeErrorListenerLoggingImpl();
120 private final NotificationService notificationService;
122 public OpenflowPluginBulkTransactionProvider(DataBroker dataBroker, NotificationService notificationService,
124 this.dataBroker = dataBroker;
125 this.notificationService = notificationService;
130 notificationService.registerNotificationListener(nodeErrorListener);
131 ctx.registerService(CommandProvider.class.getName(), this, null);
132 createTestFlow(createTestNode(null), null, null);
135 private NodeBuilder createTestNode(String nodeId) {
136 if (nodeId == null) {
137 nodeId = OpenflowpluginTestActivator.NODE_ID;
139 NodeBuilder builder = new NodeBuilder();
140 builder.setId(new NodeId(nodeId));
141 builder.withKey(new NodeKey(builder.getId()));
146 public String getHelp() {
150 private FlowBuilder createTestFlow(NodeBuilder nodeBuilder, String flowTypeArg, String tableId) {
152 FlowBuilder flow = new FlowBuilder();
155 String flowType = flowTypeArg;
156 if (flowType == null) {
163 flow.setMatch(createMatch1().build());
164 flow.setInstructions(createDecNwTtlInstructions().build());
168 flow.setMatch(createMatch2().build());
169 flow.setInstructions(createDropInstructions().build());
173 flow.setMatch(createMatch3().build());
174 flow.setInstructions(createDropInstructions().build());
178 flow.setMatch(createEthernetMatch().build());
179 flow.setInstructions(createDropInstructions().build());
183 flow.setMatch(createMatch1().build());
184 flow.setInstructions(createAppyActionInstruction().build());
188 flow.setMatch(createMatch1().build());
189 flow.setInstructions(createGotoTableInstructions().build());
193 flow.setMatch(createMatch1().build());
194 flow.setInstructions(createMeterInstructions().build());
198 flow.setMatch(createMatch1().build());
199 flow.setInstructions(createAppyActionInstruction7().build());
203 flow.setMatch(createMatch1().build());
204 flow.setInstructions(createAppyActionInstruction2().build());
208 flow.setMatch(createMatch1().build());
209 flow.setInstructions(createAppyActionInstruction3().build());
213 flow.setMatch(createMatch1().build());
214 flow.setInstructions(createAppyActionInstruction16().build());
218 flow.setMatch(createMatch1().build());
219 flow.setInstructions(createAppyActionInstruction160().build());
223 flow.setMatch(createMatch1().build());
224 flow.setInstructions(createAppyActionInstruction26().build());
228 flow.setMatch(createMatch1().build());
229 flow.setInstructions(createAppyActionInstruction27().build());
233 flow.setMatch(createMatch1().build());
234 flow.setInstructions(createAppyActionInstruction28().build());
238 flow.setMatch(createMatch1().build());
239 flow.setInstructions(createAppyActionInstruction34().build());
243 flow.setMatch(createICMPv6Match().build());
244 flow.setInstructions(createDecNwTtlInstructions().build());
248 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
249 flow.setInstructions(createDropInstructions().build());
253 flow.setMatch(createMetadataMatch().build());
254 flow.setInstructions(createDropInstructions().build());
258 flow.setMatch(createL3IPv6Match().build());
259 flow.setInstructions(createDecNwTtlInstructions().build());
263 flow.setMatch(createLLDPMatch().build());
264 flow.setInstructions(createSentToControllerInstructions().build());
269 flow.setMatch(createMatch1().build());
270 flow.setInstructions(createDropInstructions().build());
274 flow.setMatch(createMatch2().build());
275 flow.setInstructions(createDecNwTtlInstructions().build());
279 flow.setMatch(createMatch3().build());
280 flow.setInstructions(createDecNwTtlInstructions().build());
284 flow.setMatch(createEthernetMatch().build());
285 flow.setInstructions(createMeterInstructions().build());
289 flow.setMatch(createMatch1().build());
290 flow.setInstructions(createDecNwTtlInstructions().build());
294 flow.setMatch(createMatch1().build());
295 flow.setInstructions(createAppyActionInstruction7().build());
299 flow.setMatch(createEthernetMatch().build());
300 flow.setInstructions(createAppyActionInstruction6().build());
304 flow.setMatch(createEthernetMatch().build());
305 flow.setInstructions(createAppyActionInstruction7().build());
309 flow.setMatch(createMatch1().build());
310 flow.setInstructions(createAppyActionInstruction9().build());
314 flow.setMatch(createMatch1().build());
315 flow.setInstructions(createAppyActionInstruction9().build());
319 flow.setMatch(createMatch1().build());
320 flow.setInstructions(createAppyActionInstruction6().build());
324 flow.setMatch(createMatch1().build());
325 flow.setInstructions(createDecNwTtlInstructions().build());
329 flow.setMatch(createMatch1().build());
330 flow.setInstructions(createDecNwTtlInstructions().build());
334 flow.setMatch(createMatch1().build());
335 flow.setInstructions(createDecNwTtlInstructions().build());
339 flow.setMatch(createICMPv6Match().build());
340 flow.setInstructions(createDropInstructions().build());
344 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
345 flow.setInstructions(createMeterInstructions().build());
349 flow.setMatch(createMetadataMatch().build());
350 flow.setInstructions(createAppyActionInstruction6().build());
354 flow.setMatch(createMatch1().build());
355 flow.setInstructions(createAppyActionInstruction6().build());
359 flow.setMatch(createMatch1().build());
360 flow.setInstructions(createAppyActionInstruction7().build());
364 flow.setMatch(createMatch1().build());
365 flow.setInstructions(createAppyActionInstruction8().build());
369 flow.setMatch(createMatch3().build());
370 flow.setInstructions(createMeterInstructions().build());
374 flow.setMatch(createMatch1000().build());
375 flow.setInstructions(createAppyActionInstruction6().build());
379 flow.setMatch(createMatch1000().build());
380 flow.setInstructions(createAppyActionInstruction2().build());
384 flow.setMatch(createMatch1000().build());
385 flow.setInstructions(createAppyActionInstruction3().build());
388 LOG.warn("flow type not understood: {}", flowType);
391 if (null == flow.isBarrier()) {
392 flow.setBarrier(Boolean.FALSE);
394 // flow.setBufferId(12L);
395 BigInteger value = BigInteger.valueOf(10);
396 BigInteger outputPort = BigInteger.valueOf(4294967295L);
397 flow.setCookie(new FlowCookie(value));
398 flow.setCookieMask(new FlowCookie(value));
399 flow.setHardTimeout(0);
400 flow.setIdleTimeout(0);
401 flow.setInstallHw(false);
402 flow.setStrict(false);
403 flow.setContainerName(null);
404 flow.setFlags(new FlowModFlags(false, false, false, false, true));
405 flow.setId(new FlowId("12"));
406 flow.setTableId(getTableId(tableId));
407 flow.setOutGroup(4294967295L);
408 // set outport to OFPP_NONE (65535) to disable remove restriction for
410 flow.setOutPort(outputPort);
412 FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
415 flow.setFlowName(originalFlowName + "X" + flowType);
419 private short getTableId(String tableId) {
421 if (tableId == null) {
426 table = Short.parseShort(tableId);
427 } catch (NumberFormatException ex) {
428 // ignore exception and continue with default value
435 public void _addFlows(CommandInterpreter ci) {
436 NodeBuilder tn = createTestNode(ci.nextArgument());
437 String flowtype = ci.nextArgument();
438 Integer flowcnt = Integer.parseInt(flowtype);
445 tf = createTestFlow(tn, "f1", "10");
446 tf1 = createTestFlow(tn, "f2", "11");
447 tf2 = createTestFlow(tn, "f3", "12");
448 tf3 = createTestFlow(tn, "f4", "13");
451 tf = createTestFlow(tn, "f3", "3");
452 tf1 = createTestFlow(tn, "f4", "4");
453 tf2 = createTestFlow(tn, "f5", "5");
454 tf3 = createTestFlow(tn, "f6", "6");
457 tf = createTestFlow(tn, "f7", "7");
458 tf1 = createTestFlow(tn, "f8", "8");
459 tf2 = createTestFlow(tn, "f9", "9");
460 tf3 = createTestFlow(tn, "f10", "10");
464 tf = createTestFlow(tn, "f23", "3");
465 tf1 = createTestFlow(tn, "f34", "4");
466 tf2 = createTestFlow(tn, "f35", "5");
467 tf3 = createTestFlow(tn, "f36", "6");
472 tf = createTestFlow(tn, "f230", "3");
473 tf1 = createTestFlow(tn, "f34", "4");
474 tf2 = createTestFlow(tn, "f35", "5");
475 tf3 = createTestFlow(tn, "f36", "6");
479 tf = createTestFlow(tn, "f42", "42");
480 tf1 = createTestFlow(tn, "f43", "43");
481 tf2 = createTestFlow(tn, "f44", "44");
482 tf3 = createTestFlow(tn, "f45", "45");
485 writeFlow(ci, tf, tf1, tf2, tf3, tn);
488 private InstanceIdentifier<Node> nodeBuilderToInstanceId(NodeBuilder node) {
489 return InstanceIdentifier.create(Nodes.class).child(Node.class, node.key());
492 public void _modifyFlows(CommandInterpreter ci) {
493 NodeBuilder tn = createTestNode(ci.nextArgument());
494 String flowtype = ci.nextArgument();
495 Integer flowcnt = Integer.parseInt(flowtype);
502 tf = createTestFlow(tn, "f82", "10");
503 tf1 = createTestFlow(tn, "f83", "11");
504 tf2 = createTestFlow(tn, "f84", "12");
505 tf3 = createTestFlow(tn, "f85", "13");
508 tf = createTestFlow(tn, "f700", "3");
509 tf1 = createTestFlow(tn, "f4", "4");
510 tf2 = createTestFlow(tn, "f900", "5");
511 tf3 = createTestFlow(tn, "f86", "6");
515 tf = createTestFlow(tn, "f91", "7");
516 tf1 = createTestFlow(tn, "f92", "8");
517 tf2 = createTestFlow(tn, "f93", "9");
518 tf3 = createTestFlow(tn, "f94", "10");
522 tf = createTestFlow(tn, "f230", "3");
523 tf1 = createTestFlow(tn, "f99", "4");
524 tf2 = createTestFlow(tn, "f100", "5");
525 tf3 = createTestFlow(tn, "f101", "6");
529 tf = createTestFlow(tn, "f23", "3");
530 tf1 = createTestFlow(tn, "f99", "4");
531 tf2 = createTestFlow(tn, "f100", "5");
532 tf3 = createTestFlow(tn, "f101", "6");
536 tf = createTestFlow(tn, "f87", "12");
537 tf1 = createTestFlow(tn, "f88", "13");
538 tf2 = createTestFlow(tn, "f89", "14");
539 tf3 = createTestFlow(tn, "f90", "15");
543 writeFlow(ci, tf, tf1, tf2, tf3, tn);
547 public void _removeFlows(final CommandInterpreter ci) {
548 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
549 NodeBuilder tn = createTestNode(ci.nextArgument());
550 String flowtype = ci.nextArgument();
551 Integer flowcnt = Integer.parseInt(flowtype);
552 FlowBuilder tf = null;
553 FlowBuilder tf1 = null;
554 FlowBuilder tf2 = null;
555 FlowBuilder tf3 = null;
559 tf = createTestFlow(tn, "f1", "10");
560 tf1 = createTestFlow(tn, "f2", "11");
561 tf2 = createTestFlow(tn, "f3", "12");
562 tf3 = createTestFlow(tn, "f4", "13");
566 tf = createTestFlow(tn, "f82", "10");
567 tf1 = createTestFlow(tn, "f83", "11");
568 tf2 = createTestFlow(tn, "f84", "12");
569 tf3 = createTestFlow(tn, "f85", "13");
573 tf = createTestFlow(tn, "f3", "3");
574 tf1 = createTestFlow(tn, "f4", "4");
575 tf2 = createTestFlow(tn, "f5", "5");
576 tf3 = createTestFlow(tn, "f6", "6");
580 tf = createTestFlow(tn, "f700", "3");
581 tf1 = createTestFlow(tn, "f4", "4");
582 tf2 = createTestFlow(tn, "f900", "5");
583 tf3 = createTestFlow(tn, "f86", "6");
587 tf = createTestFlow(tn, "f7", "7");
588 tf1 = createTestFlow(tn, "f8", "8");
589 tf2 = createTestFlow(tn, "f9", "9");
590 tf3 = createTestFlow(tn, "f10", "10");
594 tf = createTestFlow(tn, "f91", "7");
595 tf1 = createTestFlow(tn, "f92", "8");
596 tf2 = createTestFlow(tn, "f93", "9");
597 tf3 = createTestFlow(tn, "f94", "10");
601 tf = createTestFlow(tn, "f23", "3");
602 tf1 = createTestFlow(tn, "f34", "4");
603 tf2 = createTestFlow(tn, "f35", "5");
604 tf3 = createTestFlow(tn, "f36", "6");
609 tf = createTestFlow(tn, "f23", "3");
610 tf1 = createTestFlow(tn, "f99", "4");
611 tf2 = createTestFlow(tn, "f100", "5");
612 tf3 = createTestFlow(tn, "f101", "6");
616 tf = createTestFlow(tn, "f700", "7");
617 tf1 = createTestFlow(tn, "f230", "23");
618 tf2 = createTestFlow(tn, "f900", "9");
619 tf3 = createTestFlow(tn, "f1000", "10");
622 throw new IllegalArgumentException("Invalid flowtype: " + flowtype);
625 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
626 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
627 .child(Flow.class, tf.key());
628 modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
629 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
630 modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
631 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
632 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf1.getTableId()))
633 .child(Flow.class, tf1.key());
634 modification.delete(LogicalDatastoreType.OPERATIONAL, path2);
635 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
636 modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
638 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
639 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf2.getTableId()))
640 .child(Flow.class, tf2.key());
641 modification.delete(LogicalDatastoreType.OPERATIONAL, path3);
642 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
643 modification.delete(LogicalDatastoreType.CONFIGURATION, path3);
644 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
645 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf3.getTableId()))
646 .child(Flow.class, tf3.key());
647 modification.delete(LogicalDatastoreType.OPERATIONAL, path4);
648 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
649 modification.delete(LogicalDatastoreType.CONFIGURATION, path4);
650 modification.commit().addCallback(new FutureCallback<Object>() {
652 public void onSuccess(Object notUsed) {
653 ci.println("Status of Group Data Loaded Transaction: success.");
657 public void onFailure(Throwable throwable) {
658 LOG.error("Status of Group Data Loaded Transaction : failure.", throwable);
659 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
661 }, MoreExecutors.directExecutor());
665 private void writeFlow(final CommandInterpreter ci, FlowBuilder flow, FlowBuilder flow1, FlowBuilder flow2,
666 FlowBuilder flow3, NodeBuilder nodeBuilder) {
667 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
668 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class)
669 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
670 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.key());
671 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(),
673 modification.merge(LogicalDatastoreType.OPERATIONAL, path1, flow.build(), true);
674 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
675 nodeBuilder.build(), true);
676 modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
677 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class)
678 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
679 .child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.key());
680 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(),
682 modification.merge(LogicalDatastoreType.OPERATIONAL, path2, flow1.build(), true);
683 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
684 nodeBuilder.build(), true);
685 modification.merge(LogicalDatastoreType.CONFIGURATION, path2, flow1.build(), true);
687 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class)
688 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
689 .child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.key());
690 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(),
692 modification.merge(LogicalDatastoreType.OPERATIONAL, path3, flow2.build(), true);
693 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
694 nodeBuilder.build(), true);
695 modification.merge(LogicalDatastoreType.CONFIGURATION, path3, flow2.build(), true);
697 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class)
698 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
699 .child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.key());
700 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(),
702 modification.merge(LogicalDatastoreType.OPERATIONAL, path4, flow3.build(), true);
703 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
704 nodeBuilder.build(), true);
705 modification.merge(LogicalDatastoreType.CONFIGURATION, path4, flow3.build(), true);
706 modification.commit().addCallback(new FutureCallback<Object>() {
708 public void onSuccess(Object notUsed) {
709 ci.println("Status of Group Data Loaded Transaction: success.");
713 public void onFailure(Throwable throwable) {
714 LOG.error("Status of Group Data Loaded Transaction : failure.", throwable);
715 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
717 }, MoreExecutors.directExecutor());
720 private static InstructionsBuilder createDecNwTtlInstructions() {
721 DecNwTtlBuilder ta = new DecNwTtlBuilder();
722 DecNwTtl decNwTtl = ta.build();
723 ActionBuilder ab = new ActionBuilder();
724 ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
726 // Add our drop action to a list
727 List<Action> actionList = new ArrayList<>();
728 actionList.add(ab.build());
730 // Create an Apply Action
731 ApplyActionsBuilder aab = new ApplyActionsBuilder();
732 aab.setAction(actionList);
734 // Wrap our Apply Action in an Instruction
735 InstructionBuilder ib = new InstructionBuilder();
736 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
737 ib.withKey(new InstructionKey(0));
740 // Put our Instruction in a list of Instructions
741 InstructionsBuilder isb = new InstructionsBuilder();
742 List<Instruction> instructions = new ArrayList<>();
743 instructions.add(ib.build());
744 isb.setInstruction(instructions);
748 private static InstructionsBuilder createMeterInstructions() {
750 MeterBuilder aab = new MeterBuilder();
751 aab.setMeterId(new MeterId(1L));
753 InstructionBuilder ib = new InstructionBuilder();
754 ib.setInstruction(new MeterCaseBuilder().setMeter(aab.build()).build());
756 // Put our Instruction in a list of Instructions
757 InstructionsBuilder isb = new InstructionsBuilder();
758 List<Instruction> instructions = new ArrayList<>();
759 instructions.add(ib.build());
760 isb.setInstruction(instructions);
764 private static InstructionsBuilder createGotoTableInstructions() {
766 GoToTableBuilder aab = new GoToTableBuilder();
767 aab.setTableId((short) 2);
769 InstructionBuilder ib = new InstructionBuilder();
770 ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(aab.build()).build());
772 // Put our Instruction in a list of Instructions
773 InstructionsBuilder isb = new InstructionsBuilder();
774 List<Instruction> instructions = new ArrayList<>();
775 instructions.add(ib.build());
776 isb.setInstruction(instructions);
780 private static InstructionsBuilder createDropInstructions() {
781 DropActionBuilder dab = new DropActionBuilder();
782 DropAction dropAction = dab.build();
783 ActionBuilder ab = new ActionBuilder();
784 ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
786 // Add our drop action to a list
787 List<Action> actionList = new ArrayList<>();
788 actionList.add(ab.build());
790 // Create an Apply Action
791 ApplyActionsBuilder aab = new ApplyActionsBuilder();
792 aab.setAction(actionList);
794 // Wrap our Apply Action in an Instruction
795 InstructionBuilder ib = new InstructionBuilder();
796 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
798 // Put our Instruction in a list of Instructions
799 InstructionsBuilder isb = new InstructionsBuilder();
800 List<Instruction> instructions = new ArrayList<>();
801 instructions.add(ib.build());
802 isb.setInstruction(instructions);
806 private static InstructionsBuilder createAppyActionInstruction() {
808 List<Action> actionList = new ArrayList<>();
809 ActionBuilder ab = new ActionBuilder();
810 ControllerActionBuilder controller = new ControllerActionBuilder();
811 controller.setMaxLength(5);
812 ab.setAction(new ControllerActionCaseBuilder().setControllerAction(controller.build()).build());
813 actionList.add(ab.build());
814 // Create an Apply Action
815 ApplyActionsBuilder aab = new ApplyActionsBuilder();
816 aab.setAction(actionList);
818 // Wrap our Apply Action in an Instruction
819 InstructionBuilder ib = new InstructionBuilder();
820 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
822 // Put our Instruction in a list of Instructions
823 InstructionsBuilder isb = new InstructionsBuilder();
824 List<Instruction> instructions = new ArrayList<>();
825 instructions.add(ib.build());
826 isb.setInstruction(instructions);
830 private static InstructionsBuilder createSentToControllerInstructions() {
831 ActionBuilder ab = new ActionBuilder();
833 OutputActionBuilder output = new OutputActionBuilder();
834 output.setMaxLength(0xffff);
835 Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
836 output.setOutputNodeConnector(value);
837 ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
839 ab.withKey(new ActionKey(0));
841 List<Action> actionList = new ArrayList<>();
842 actionList.add(ab.build());
843 // Create an Apply Action
844 ApplyActionsBuilder aab = new ApplyActionsBuilder();
845 aab.setAction(actionList);
847 // Wrap our Apply Action in an Instruction
848 InstructionBuilder ib = new InstructionBuilder();
849 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
851 ib.withKey(new InstructionKey(0));
853 // Put our Instruction in a list of Instructions
854 InstructionsBuilder isb = new InstructionsBuilder();
855 List<Instruction> instructions = new ArrayList<>();
856 instructions.add(ib.build());
857 isb.setInstruction(instructions);
861 private static InstructionsBuilder createAppyActionInstruction2() {
863 List<Action> actionList = new ArrayList<>();
864 ActionBuilder ab = new ActionBuilder();
866 PushMplsActionBuilder push = new PushMplsActionBuilder();
867 push.setEthernetType(0x8847);
868 ab.setAction(new PushMplsActionCaseBuilder().setPushMplsAction(push.build()).build());
869 actionList.add(ab.build());
870 // Create an Apply Action
871 ApplyActionsBuilder aab = new ApplyActionsBuilder();
872 aab.setAction(actionList);
874 // Wrap our Apply Action in an Instruction
875 InstructionBuilder ib = new InstructionBuilder();
876 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
878 // Put our Instruction in a list of Instructions
879 InstructionsBuilder isb = new InstructionsBuilder();
880 List<Instruction> instructions = new ArrayList<>();
881 instructions.add(ib.build());
882 isb.setInstruction(instructions);
886 private static InstructionsBuilder createAppyActionInstruction3() {
888 List<Action> actionList = new ArrayList<>();
889 ActionBuilder ab = new ActionBuilder();
891 PushPbbActionBuilder pbb = new PushPbbActionBuilder();
892 pbb.setEthernetType(0x88E7);
893 ab.setAction(new PushPbbActionCaseBuilder().setPushPbbAction(pbb.build()).build());
894 actionList.add(ab.build());
895 // Create an Apply Action
896 ApplyActionsBuilder aab = new ApplyActionsBuilder();
897 aab.setAction(actionList);
899 // Wrap our Apply Action in an Instruction
900 InstructionBuilder ib = new InstructionBuilder();
901 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
903 // Put our Instruction in a list of Instructions
904 InstructionsBuilder isb = new InstructionsBuilder();
905 List<Instruction> instructions = new ArrayList<>();
906 instructions.add(ib.build());
907 isb.setInstruction(instructions);
911 private static InstructionsBuilder createAppyActionInstruction6() {
913 List<Action> actionList = new ArrayList<>();
914 ActionBuilder ab = new ActionBuilder();
916 SetDlSrcActionBuilder src = new SetDlSrcActionBuilder();
917 src.setAddress(new MacAddress("00:05:b9:7c:81:5f"));
918 ab.setAction(new SetDlSrcActionCaseBuilder().setSetDlSrcAction(src.build()).build());
919 actionList.add(ab.build());
921 // Create an Apply Action
922 ApplyActionsBuilder aab = new ApplyActionsBuilder();
923 aab.setAction(actionList);
925 // Wrap our Apply Action in an Instruction
926 InstructionBuilder ib = new InstructionBuilder();
927 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
929 // Put our Instruction in a list of Instructions
930 InstructionsBuilder isb = new InstructionsBuilder();
931 List<Instruction> instructions = new ArrayList<>();
932 instructions.add(ib.build());
933 isb.setInstruction(instructions);
937 private static InstructionsBuilder createAppyActionInstruction7() {
939 List<Action> actionList = new ArrayList<>();
940 ActionBuilder ab = new ActionBuilder();
942 SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
943 VlanId vlanId = new VlanId(4012);
944 vl.setVlanId(vlanId);
945 ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.build()).build());
946 actionList.add(ab.build());
947 // Create an Apply Action
948 ApplyActionsBuilder aab = new ApplyActionsBuilder();
949 aab.setAction(actionList);
951 // Wrap our Apply Action in an Instruction
952 InstructionBuilder ib = new InstructionBuilder();
953 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
955 // Put our Instruction in a list of Instructions
956 InstructionsBuilder isb = new InstructionsBuilder();
957 List<Instruction> instructions = new ArrayList<>();
958 instructions.add(ib.build());
959 isb.setInstruction(instructions);
963 private static InstructionsBuilder createAppyActionInstruction8() {
965 List<Action> actionList = new ArrayList<>();
966 ActionBuilder ab = new ActionBuilder();
968 SetVlanPcpActionBuilder pcp = new SetVlanPcpActionBuilder();
969 VlanPcp pcp1 = new VlanPcp((short) 2);
970 pcp.setVlanPcp(pcp1);
971 ab.setAction(new SetVlanPcpActionCaseBuilder().setSetVlanPcpAction(pcp.build()).build());
972 actionList.add(ab.build());
973 // Create an Apply Action
974 ApplyActionsBuilder aab = new ApplyActionsBuilder();
975 aab.setAction(actionList);
977 // Wrap our Apply Action in an Instruction
978 InstructionBuilder ib = new InstructionBuilder();
979 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
981 // Put our Instruction in a list of Instructions
982 InstructionsBuilder isb = new InstructionsBuilder();
983 List<Instruction> instructions = new ArrayList<>();
984 instructions.add(ib.build());
985 isb.setInstruction(instructions);
989 private static InstructionsBuilder createAppyActionInstruction9() {
991 List<Action> actionList = new ArrayList<>();
992 ActionBuilder ab = new ActionBuilder();
994 CopyTtlInBuilder ttlin = new CopyTtlInBuilder();
995 ab.setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(ttlin.build()).build());
996 actionList.add(ab.build());
997 // Create an Apply Action
998 ApplyActionsBuilder aab = new ApplyActionsBuilder();
999 aab.setAction(actionList);
1001 // Wrap our Apply Action in an Instruction
1002 InstructionBuilder ib = new InstructionBuilder();
1003 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1005 // Put our Instruction in a list of Instructions
1006 InstructionsBuilder isb = new InstructionsBuilder();
1007 List<Instruction> instructions = new ArrayList<>();
1008 instructions.add(ib.build());
1009 isb.setInstruction(instructions);
1013 private static InstructionsBuilder createAppyActionInstruction16() {
1014 ActionBuilder ab = new ActionBuilder();
1016 GroupActionBuilder groupActionB = new GroupActionBuilder();
1017 groupActionB.setGroupId(1L);
1018 groupActionB.setGroup("0");
1019 ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
1021 List<Action> actionList = new ArrayList<>();
1022 actionList.add(ab.build());
1024 // Create an Apply Action
1025 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1026 aab.setAction(actionList);
1028 // Wrap our Apply Action in an Instruction
1029 InstructionBuilder ib = new InstructionBuilder();
1030 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1032 // Put our Instruction in a list of Instructions
1033 InstructionsBuilder isb = new InstructionsBuilder();
1034 List<Instruction> instructions = new ArrayList<>();
1035 instructions.add(ib.build());
1036 isb.setInstruction(instructions);
1040 private static InstructionsBuilder createAppyActionInstruction160() {
1042 List<Action> actionList = new ArrayList<>();
1043 ActionBuilder ab = new ActionBuilder();
1045 FloodAllActionBuilder fldall = new FloodAllActionBuilder();
1046 ab.setAction(new FloodAllActionCaseBuilder().setFloodAllAction(fldall.build()).build());
1047 actionList.add(ab.build());
1048 // Create an Apply Action
1049 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1050 aab.setAction(actionList);
1052 // Wrap our Apply Action in an Instruction
1053 InstructionBuilder ib = new InstructionBuilder();
1054 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1056 // Put our Instruction in a list of Instructions
1057 InstructionsBuilder isb = new InstructionsBuilder();
1058 List<Instruction> instructions = new ArrayList<>();
1059 instructions.add(ib.build());
1060 isb.setInstruction(instructions);
1064 private static InstructionsBuilder createAppyActionInstruction26() {
1065 ActionBuilder ab = new ActionBuilder();
1067 SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
1068 Ipv4Builder ipdst = new Ipv4Builder();
1069 Ipv4Prefix prefixdst = new Ipv4Prefix("10.0.0.21/24");
1070 ipdst.setIpv4Address(prefixdst);
1071 setNwDstActionBuilder.setAddress(ipdst.build());
1072 ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
1074 List<Action> actionList = new ArrayList<>();
1075 actionList.add(ab.build());
1077 // Create an Apply Action
1078 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1079 aab.setAction(actionList);
1081 // Wrap our Apply Action in an Instruction
1082 InstructionBuilder ib = new InstructionBuilder();
1083 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1085 // Put our Instruction in a list of Instructions
1086 InstructionsBuilder isb = new InstructionsBuilder();
1087 List<Instruction> instructions = new ArrayList<>();
1088 instructions.add(ib.build());
1089 isb.setInstruction(instructions);
1093 private static InstructionsBuilder createAppyActionInstruction27() {
1094 ActionBuilder ab = new ActionBuilder();
1096 SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
1097 Ipv4Builder ipsrc = new Ipv4Builder();
1098 Ipv4Prefix prefixsrc = new Ipv4Prefix("10.0.23.21/24");
1099 ipsrc.setIpv4Address(prefixsrc);
1100 setNwsrcActionBuilder.setAddress(ipsrc.build());
1101 ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
1103 List<Action> actionList = new ArrayList<>();
1104 actionList.add(ab.build());
1106 // Create an Apply Action
1107 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1108 aab.setAction(actionList);
1110 // Wrap our Apply Action in an Instruction
1111 InstructionBuilder ib = new InstructionBuilder();
1112 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1114 // Put our Instruction in a list of Instructions
1115 InstructionsBuilder isb = new InstructionsBuilder();
1116 List<Instruction> instructions = new ArrayList<>();
1117 instructions.add(ib.build());
1118 isb.setInstruction(instructions);
1122 private static InstructionsBuilder createAppyActionInstruction28() {
1124 List<Action> actionList = new ArrayList<>();
1125 ActionBuilder ab = new ActionBuilder();
1127 SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
1128 setNwTosActionBuilder.setTos(8);
1129 ab.setAction(new SetNwTosActionCaseBuilder().setSetNwTosAction(setNwTosActionBuilder.build()).build());
1130 actionList.add(ab.build());
1131 // Create an Apply Action
1132 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1133 aab.setAction(actionList);
1135 // Wrap our Apply Action in an Instruction
1136 InstructionBuilder ib = new InstructionBuilder();
1137 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1139 // Put our Instruction in a list of Instructions
1140 InstructionsBuilder isb = new InstructionsBuilder();
1141 List<Instruction> instructions = new ArrayList<>();
1142 instructions.add(ib.build());
1143 isb.setInstruction(instructions);
1147 private static InstructionsBuilder createAppyActionInstruction34() {
1149 List<Action> actionList = new ArrayList<>();
1150 ActionBuilder ab = new ActionBuilder();
1152 SwPathActionBuilder swPathAction = new SwPathActionBuilder();
1153 ab.setAction(new SwPathActionCaseBuilder().setSwPathAction(swPathAction.build()).build());
1154 actionList.add(ab.build());
1156 // Create an Apply Action
1157 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1158 aab.setAction(actionList);
1160 // Wrap our Apply Action in an Instruction
1161 InstructionBuilder ib = new InstructionBuilder();
1162 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1164 // Put our Instruction in a list of Instructions
1165 InstructionsBuilder isb = new InstructionsBuilder();
1166 List<Instruction> instructions = new ArrayList<>();
1167 instructions.add(ib.build());
1168 isb.setInstruction(instructions);
1172 private static MatchBuilder createLLDPMatch() {
1173 MatchBuilder match = new MatchBuilder();
1174 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1175 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1176 ethTypeBuilder.setType(new EtherType(0x88ccL));
1177 eth.setEthernetType(ethTypeBuilder.build());
1178 match.setEthernetMatch(eth.build());
1182 private static MatchBuilder createMatch1() {
1183 MatchBuilder match = new MatchBuilder();
1184 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1185 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
1186 ipv4Match.setIpv4Destination(prefix);
1187 Ipv4Match i4m = ipv4Match.build();
1188 match.setLayer3Match(i4m);
1190 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1191 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1192 ethTypeBuilder.setType(new EtherType(0x0800L));
1193 eth.setEthernetType(ethTypeBuilder.build());
1194 match.setEthernetMatch(eth.build());
1198 private static MatchBuilder createMatch1000() {
1199 MatchBuilder match = new MatchBuilder();
1200 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1201 Ipv4Prefix prefix = new Ipv4Prefix("10.1.1.1/24");
1202 ipv4Match.setIpv4Destination(prefix);
1203 Ipv4Match i4m = ipv4Match.build();
1204 match.setLayer3Match(i4m);
1206 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1207 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1208 ethTypeBuilder.setType(new EtherType(0x0800L));
1209 eth.setEthernetType(ethTypeBuilder.build());
1210 match.setEthernetMatch(eth.build());
1214 private static MatchBuilder createMatch2() {
1215 MatchBuilder match = new MatchBuilder();
1216 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1217 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1");
1218 ipv4Match.setIpv4Source(prefix);
1219 Ipv4Match i4m = ipv4Match.build();
1220 match.setLayer3Match(i4m);
1222 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1223 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1224 ethTypeBuilder.setType(new EtherType(0x0800L));
1225 eth.setEthernetType(ethTypeBuilder.build());
1226 match.setEthernetMatch(eth.build());
1230 private static MatchBuilder createMatch3() {
1231 MatchBuilder match = new MatchBuilder();
1232 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
1233 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
1234 ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
1235 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
1236 match.setEthernetMatch(ethernetMatch.build());
1241 private static MatchBuilder createInphyportMatch(NodeId nodeId) {
1242 MatchBuilder match = new MatchBuilder();
1243 match.setInPort(new NodeConnectorId(nodeId + ":202"));
1244 match.setInPhyPort(new NodeConnectorId(nodeId + ":10122"));
1248 private static MatchBuilder createEthernetMatch() {
1249 EthernetMatchBuilder ethmatch = new EthernetMatchBuilder(); // ethernettype
1251 EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
1252 EtherType type = new EtherType(0x0800L);
1253 ethmatch.setEthernetType(ethtype.setType(type).build());
1255 EthernetDestinationBuilder ethdest = new EthernetDestinationBuilder(); // ethernet
1258 MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
1259 ethdest.setAddress(macdest);
1260 // ethdest.setMask(mask1);
1262 ethmatch.setEthernetDestination(ethdest.build());
1264 EthernetSourceBuilder ethsrc = new EthernetSourceBuilder();
1265 MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
1266 ethsrc.setAddress(macsrc);
1267 // ethsrc.setMask(mask2);
1269 ethmatch.setEthernetSource(ethsrc.build());
1271 MatchBuilder match = new MatchBuilder();
1272 match.setEthernetMatch(ethmatch.build());
1277 private static MatchBuilder createL3IPv6Match() {
1278 MatchBuilder match = new MatchBuilder();
1280 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1281 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1282 ethTypeBuilder.setType(new EtherType(0x86ddL));
1283 eth.setEthernetType(ethTypeBuilder.build());
1284 match.setEthernetMatch(eth.build());
1286 Ipv6ExtHeaderBuilder nextheader = new Ipv6ExtHeaderBuilder();
1287 nextheader.setIpv6Exthdr(58);
1288 Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
1289 Ipv6FlowLabel label = new Ipv6FlowLabel(10028L);
1290 ipv6label.setIpv6Flabel(label);
1291 // ipv6label.setFlabelMask(new byte[] { 0, 1, -1, -1 });
1293 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1295 icmpv6match.setIcmpv6Type((short) 135);
1296 icmpv6match.setIcmpv6Code((short) 0);
1297 match.setIcmpv6Match(icmpv6match.build());
1299 Ipv6MatchBuilder ipv6match = new Ipv6MatchBuilder();
1300 // ipv6match.setIpv6Source(srcip6);
1301 // ipv6match.setIpv6Destination(dstip6);
1302 // ipv6match.setIpv6ExtHeader(nextheader.build());
1304 ipv6match.setIpv6NdSll(new MacAddress("c2:00:54:f5:00:00"));
1305 ipv6match.setIpv6NdTll(new MacAddress("00:0c:29:0e:4c:67"));
1306 // ipv6match.setIpv6NdTarget(ndtarget);
1307 ipv6match.setIpv6Label(ipv6label.build());
1309 match.setLayer3Match(ipv6match.build());
1314 private static MatchBuilder createICMPv6Match() {
1316 MatchBuilder match = new MatchBuilder();
1317 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1318 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1319 ethTypeBuilder.setType(new EtherType(0x86ddL));
1320 eth.setEthernetType(ethTypeBuilder.build());
1321 match.setEthernetMatch(eth.build());
1323 IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
1324 ipmatch.setIpProtocol((short) 58);
1325 match.setIpMatch(ipmatch.build());
1327 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1329 icmpv6match.setIcmpv6Type((short) 135);
1330 icmpv6match.setIcmpv6Code((short) 1);
1331 match.setIcmpv6Match(icmpv6match.build());
1336 private static MatchBuilder createMetadataMatch() {
1337 MatchBuilder match = new MatchBuilder();
1338 MetadataBuilder metadata = new MetadataBuilder(); // metadata match
1339 metadata.setMetadata(BigInteger.valueOf(500L));
1340 // metadata.setMetadataMask(metamask);
1341 match.setMetadata(metadata.build());