2 * Copyright (c) 2014, 2015 Ericsson, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.test;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import com.google.common.util.concurrent.FutureCallback;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.MoreExecutors;
15 import java.math.BigInteger;
16 import java.util.ArrayList;
17 import java.util.List;
18 import org.eclipse.osgi.framework.console.CommandInterpreter;
19 import org.eclipse.osgi.framework.console.CommandProvider;
20 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
21 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
22 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
23 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
24 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
25 import org.opendaylight.controller.sal.binding.api.NotificationService;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.all.action._case.FloodAllActionBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.sw.path.action._case.SwPathActionBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.node.error.service.rev140410.NodeErrorListener;
115 import org.opendaylight.yangtools.concepts.Registration;
116 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
117 import org.osgi.framework.BundleContext;
118 import org.slf4j.Logger;
119 import org.slf4j.LoggerFactory;
121 public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
123 private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginBulkTransactionProvider.class);
124 private DataBroker dataBroker;
125 private final BundleContext ctx;
126 private NodeBuilder testNode;
127 private ProviderContext pc;
128 private FlowBuilder testFlow;
129 private final String originalFlowName = "Foo";
130 private final NodeErrorListener nodeErrorListener = new NodeErrorListenerLoggingImpl();
131 private Registration listener1Reg;
132 private Registration listener2Reg;
133 private Node testNode12;
134 private final String originalGroupName = "Foo";
135 private static NotificationService notificationService;
137 public OpenflowPluginBulkTransactionProvider(BundleContext ctx) {
141 public void onSessionInitiated(ProviderContext session) {
143 notificationService = session.getSALService(NotificationService.class);
144 listener2Reg = notificationService.registerNotificationListener(nodeErrorListener);
145 dataBroker = session.getSALService(DataBroker.class);
146 ctx.registerService(CommandProvider.class.getName(), this, null);
147 createTestFlow(createTestNode(null), null, null);
150 private NodeBuilder createTestNode(String nodeId) {
151 if (nodeId == null) {
152 nodeId = OpenflowpluginTestActivator.NODE_ID;
154 NodeRef nodeOne = createNodeRef(nodeId);
155 NodeBuilder builder = new NodeBuilder();
156 builder.setId(new NodeId(nodeId));
157 builder.setKey(new NodeKey(builder.getId()));
162 private static NodeRef createNodeRef(String string) {
163 NodeKey key = new NodeKey(new NodeId(string));
164 InstanceIdentifier<Node> path = InstanceIdentifier.create(Nodes.class).child(Node.class, key);
166 return new NodeRef(path);
170 public String getHelp() {
174 private FlowBuilder createTestFlow(NodeBuilder nodeBuilder, String flowTypeArg, String tableId) {
176 FlowBuilder flow = new FlowBuilder();
179 String flowType = flowTypeArg;
180 if (flowType == null) {
187 flow.setMatch(createMatch1().build());
188 flow.setInstructions(createDecNwTtlInstructions().build());
192 flow.setMatch(createMatch2().build());
193 flow.setInstructions(createDropInstructions().build());
197 flow.setMatch(createMatch3().build());
198 flow.setInstructions(createDropInstructions().build());
202 flow.setMatch(createEthernetMatch().build());
203 flow.setInstructions(createDropInstructions().build());
207 flow.setMatch(createMatch1().build());
208 flow.setInstructions(createAppyActionInstruction().build());
212 flow.setMatch(createMatch1().build());
213 flow.setInstructions(createGotoTableInstructions().build());
217 flow.setMatch(createMatch1().build());
218 flow.setInstructions(createMeterInstructions().build());
222 flow.setMatch(createMatch1().build());
223 flow.setInstructions(createAppyActionInstruction7().build());
227 flow.setMatch(createMatch1().build());
228 flow.setInstructions(createAppyActionInstruction2().build());
232 flow.setMatch(createMatch1().build());
233 flow.setInstructions(createAppyActionInstruction3().build());
237 flow.setMatch(createMatch1().build());
238 flow.setInstructions(createAppyActionInstruction16().build());
242 flow.setMatch(createMatch1().build());
243 flow.setInstructions(createAppyActionInstruction160().build());
247 flow.setMatch(createMatch1().build());
248 flow.setInstructions(createAppyActionInstruction26().build());
252 flow.setMatch(createMatch1().build());
253 flow.setInstructions(createAppyActionInstruction27().build());
257 flow.setMatch(createMatch1().build());
258 flow.setInstructions(createAppyActionInstruction28().build());
262 flow.setMatch(createMatch1().build());
263 flow.setInstructions(createAppyActionInstruction34().build());
267 flow.setMatch(createICMPv6Match().build());
268 flow.setInstructions(createDecNwTtlInstructions().build());
272 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
273 flow.setInstructions(createDropInstructions().build());
277 flow.setMatch(createMetadataMatch().build());
278 flow.setInstructions(createDropInstructions().build());
282 flow.setMatch(createL3IPv6Match().build());
283 flow.setInstructions(createDecNwTtlInstructions().build());
287 flow.setMatch(createLLDPMatch().build());
288 flow.setInstructions(createSentToControllerInstructions().build());
293 flow.setMatch(createMatch1().build());
294 flow.setInstructions(createDropInstructions().build());
298 flow.setMatch(createMatch2().build());
299 flow.setInstructions(createDecNwTtlInstructions().build());
303 flow.setMatch(createMatch3().build());
304 flow.setInstructions(createDecNwTtlInstructions().build());
308 flow.setMatch(createEthernetMatch().build());
309 flow.setInstructions(createMeterInstructions().build());
313 flow.setMatch(createMatch1().build());
314 flow.setInstructions(createDecNwTtlInstructions().build());
318 flow.setMatch(createMatch1().build());
319 flow.setInstructions(createAppyActionInstruction7().build());
323 flow.setMatch(createEthernetMatch().build());
324 flow.setInstructions(createAppyActionInstruction6().build());
328 flow.setMatch(createEthernetMatch().build());
329 flow.setInstructions(createAppyActionInstruction7().build());
333 flow.setMatch(createMatch1().build());
334 flow.setInstructions(createAppyActionInstruction9().build());
338 flow.setMatch(createMatch1().build());
339 flow.setInstructions(createAppyActionInstruction9().build());
343 flow.setMatch(createMatch1().build());
344 flow.setInstructions(createAppyActionInstruction6().build());
348 flow.setMatch(createMatch1().build());
349 flow.setInstructions(createDecNwTtlInstructions().build());
353 flow.setMatch(createMatch1().build());
354 flow.setInstructions(createDecNwTtlInstructions().build());
358 flow.setMatch(createMatch1().build());
359 flow.setInstructions(createDecNwTtlInstructions().build());
363 flow.setMatch(createICMPv6Match().build());
364 flow.setInstructions(createDropInstructions().build());
368 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
369 flow.setInstructions(createMeterInstructions().build());
373 flow.setMatch(createMetadataMatch().build());
374 flow.setInstructions(createAppyActionInstruction6().build());
378 flow.setMatch(createMatch1().build());
379 flow.setInstructions(createAppyActionInstruction6().build());
383 flow.setMatch(createMatch1().build());
384 flow.setInstructions(createAppyActionInstruction7().build());
388 flow.setMatch(createMatch1().build());
389 flow.setInstructions(createAppyActionInstruction8().build());
393 flow.setMatch(createMatch3().build());
394 flow.setInstructions(createMeterInstructions().build());
398 flow.setMatch(createMatch1000().build());
399 flow.setInstructions(createAppyActionInstruction6().build());
403 flow.setMatch(createMatch1000().build());
404 flow.setInstructions(createAppyActionInstruction2().build());
408 flow.setMatch(createMatch1000().build());
409 flow.setInstructions(createAppyActionInstruction3().build());
412 LOG.warn("flow type not understood: {}", flowType);
415 FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
416 if (null == flow.isBarrier()) {
417 flow.setBarrier(Boolean.FALSE);
419 // flow.setBufferId(12L);
420 BigInteger value = BigInteger.valueOf(10);
421 BigInteger outputPort = BigInteger.valueOf(4294967295L);
422 flow.setCookie(new FlowCookie(value));
423 flow.setCookieMask(new FlowCookie(value));
424 flow.setHardTimeout(0);
425 flow.setIdleTimeout(0);
426 flow.setInstallHw(false);
427 flow.setStrict(false);
428 flow.setContainerName(null);
429 flow.setFlags(new FlowModFlags(false, false, false, false, true));
430 flow.setId(new FlowId("12"));
431 flow.setTableId(getTableId(tableId));
432 flow.setOutGroup(4294967295L);
433 // set outport to OFPP_NONE (65535) to disable remove restriction for
435 flow.setOutPort(outputPort);
439 flow.setFlowName(originalFlowName + "X" + flowType);
444 private short getTableId(String tableId) {
447 table = Short.parseShort(tableId);
448 } catch (Exception ex) {
449 // ignore exception and continue with default value
456 private void createTestNode() {
457 NodeRef nodeOne = createNodeRef(OpenflowpluginTestActivator.NODE_ID);
458 NodeBuilder builder = new NodeBuilder();
459 builder.setId(new NodeId(OpenflowpluginTestActivator.NODE_ID));
460 builder.setKey(new NodeKey(builder.getId()));
461 testNode12 = builder.build();
464 public void _addFlows(CommandInterpreter ci) {
465 NodeBuilder tn = createTestNode(ci.nextArgument());
466 String flowtype = ci.nextArgument();
467 Integer flowcnt = Integer.parseInt(flowtype);
474 tf = createTestFlow(tn, "f1", "10");
475 tf1 = createTestFlow(tn, "f2", "11");
476 tf2 = createTestFlow(tn, "f3", "12");
477 tf3 = createTestFlow(tn, "f4", "13");
480 tf = createTestFlow(tn, "f3", "3");
481 tf1 = createTestFlow(tn, "f4", "4");
482 tf2 = createTestFlow(tn, "f5", "5");
483 tf3 = createTestFlow(tn, "f6", "6");
486 tf = createTestFlow(tn, "f7", "7");
487 tf1 = createTestFlow(tn, "f8", "8");
488 tf2 = createTestFlow(tn, "f9", "9");
489 tf3 = createTestFlow(tn, "f10", "10");
493 tf = createTestFlow(tn, "f23", "3");
494 tf1 = createTestFlow(tn, "f34", "4");
495 tf2 = createTestFlow(tn, "f35", "5");
496 tf3 = createTestFlow(tn, "f36", "6");
501 tf = createTestFlow(tn, "f230", "3");
502 tf1 = createTestFlow(tn, "f34", "4");
503 tf2 = createTestFlow(tn, "f35", "5");
504 tf3 = createTestFlow(tn, "f36", "6");
508 tf = createTestFlow(tn, "f42", "42");
509 tf1 = createTestFlow(tn, "f43", "43");
510 tf2 = createTestFlow(tn, "f44", "44");
511 tf3 = createTestFlow(tn, "f45", "45");
514 writeFlow(ci, tf, tf1, tf2, tf3, tn);
517 private InstanceIdentifier<Node> nodeBuilderToInstanceId(NodeBuilder node) {
518 return InstanceIdentifier.create(Nodes.class).child(Node.class, node.getKey());
521 public void _modifyFlows(CommandInterpreter ci) {
522 NodeBuilder tn = createTestNode(ci.nextArgument());
523 String flowtype = ci.nextArgument();
524 Integer flowcnt = Integer.parseInt(flowtype);
531 tf = createTestFlow(tn, "f82", "10");
532 tf1 = createTestFlow(tn, "f83", "11");
533 tf2 = createTestFlow(tn, "f84", "12");
534 tf3 = createTestFlow(tn, "f85", "13");
537 tf = createTestFlow(tn, "f700", "3");
538 tf1 = createTestFlow(tn, "f4", "4");
539 tf2 = createTestFlow(tn, "f900", "5");
540 tf3 = createTestFlow(tn, "f86", "6");
544 tf = createTestFlow(tn, "f91", "7");
545 tf1 = createTestFlow(tn, "f92", "8");
546 tf2 = createTestFlow(tn, "f93", "9");
547 tf3 = createTestFlow(tn, "f94", "10");
551 tf = createTestFlow(tn, "f230", "3");
552 tf1 = createTestFlow(tn, "f99", "4");
553 tf2 = createTestFlow(tn, "f100", "5");
554 tf3 = createTestFlow(tn, "f101", "6");
558 tf = createTestFlow(tn, "f23", "3");
559 tf1 = createTestFlow(tn, "f99", "4");
560 tf2 = createTestFlow(tn, "f100", "5");
561 tf3 = createTestFlow(tn, "f101", "6");
565 tf = createTestFlow(tn, "f87", "12");
566 tf1 = createTestFlow(tn, "f88", "13");
567 tf2 = createTestFlow(tn, "f89", "14");
568 tf3 = createTestFlow(tn, "f90", "15");
572 writeFlow(ci, tf, tf1, tf2, tf3, tn);
576 public void _removeFlows(final CommandInterpreter ci) {
577 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
578 NodeBuilder tn = createTestNode(ci.nextArgument());
579 String flowtype = ci.nextArgument();
580 Integer flowcnt = Integer.parseInt(flowtype);
581 FlowBuilder tf = null;
582 FlowBuilder tf1 = null;
583 FlowBuilder tf2 = null;
584 FlowBuilder tf3 = null;
588 tf = createTestFlow(tn, "f1", "10");
589 tf1 = createTestFlow(tn, "f2", "11");
590 tf2 = createTestFlow(tn, "f3", "12");
591 tf3 = createTestFlow(tn, "f4", "13");
595 tf = createTestFlow(tn, "f82", "10");
596 tf1 = createTestFlow(tn, "f83", "11");
597 tf2 = createTestFlow(tn, "f84", "12");
598 tf3 = createTestFlow(tn, "f85", "13");
602 tf = createTestFlow(tn, "f3", "3");
603 tf1 = createTestFlow(tn, "f4", "4");
604 tf2 = createTestFlow(tn, "f5", "5");
605 tf3 = createTestFlow(tn, "f6", "6");
609 tf = createTestFlow(tn, "f700", "3");
610 tf1 = createTestFlow(tn, "f4", "4");
611 tf2 = createTestFlow(tn, "f900", "5");
612 tf3 = createTestFlow(tn, "f86", "6");
616 tf = createTestFlow(tn, "f7", "7");
617 tf1 = createTestFlow(tn, "f8", "8");
618 tf2 = createTestFlow(tn, "f9", "9");
619 tf3 = createTestFlow(tn, "f10", "10");
623 tf = createTestFlow(tn, "f91", "7");
624 tf1 = createTestFlow(tn, "f92", "8");
625 tf2 = createTestFlow(tn, "f93", "9");
626 tf3 = createTestFlow(tn, "f94", "10");
630 tf = createTestFlow(tn, "f23", "3");
631 tf1 = createTestFlow(tn, "f34", "4");
632 tf2 = createTestFlow(tn, "f35", "5");
633 tf3 = createTestFlow(tn, "f36", "6");
638 tf = createTestFlow(tn, "f23", "3");
639 tf1 = createTestFlow(tn, "f99", "4");
640 tf2 = createTestFlow(tn, "f100", "5");
641 tf3 = createTestFlow(tn, "f101", "6");
645 tf = createTestFlow(tn, "f700", "7");
646 tf1 = createTestFlow(tn, "f230", "23");
647 tf2 = createTestFlow(tn, "f900", "9");
648 tf3 = createTestFlow(tn, "f1000", "10");
652 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
653 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
654 .child(Flow.class, tf.getKey());
655 modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
656 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
657 modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
658 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
659 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf1.getTableId()))
660 .child(Flow.class, tf1.getKey());
661 modification.delete(LogicalDatastoreType.OPERATIONAL, path2);
662 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
663 modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
665 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
666 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf2.getTableId()))
667 .child(Flow.class, tf2.getKey());
668 modification.delete(LogicalDatastoreType.OPERATIONAL, path3);
669 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
670 modification.delete(LogicalDatastoreType.CONFIGURATION, path3);
671 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
672 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf3.getTableId()))
673 .child(Flow.class, tf3.getKey());
674 modification.delete(LogicalDatastoreType.OPERATIONAL, path4);
675 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
676 modification.delete(LogicalDatastoreType.CONFIGURATION, path4);
677 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
678 Futures.addCallback(commitFuture, new FutureCallback<Void>() {
680 public void onSuccess(Void aVoid) {
681 ci.println("Status of Group Data Loaded Transaction: success.");
685 public void onFailure(Throwable throwable) {
686 LOG.error(throwable.getMessage(), throwable);
687 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
689 }, MoreExecutors.directExecutor());
693 private void writeFlow(final CommandInterpreter ci, FlowBuilder flow, FlowBuilder flow1, FlowBuilder flow2,
694 FlowBuilder flow3, NodeBuilder nodeBuilder) {
695 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
696 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class)
697 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
698 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey());
699 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
700 modification.merge(LogicalDatastoreType.OPERATIONAL, path1, flow.build(), true);
701 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
702 modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
703 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class)
704 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
705 .child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.getKey());
706 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
707 modification.merge(LogicalDatastoreType.OPERATIONAL, path2, flow1.build(), true);
708 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
709 modification.merge(LogicalDatastoreType.CONFIGURATION, path2, flow1.build(), true);
711 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class)
712 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
713 .child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.getKey());
714 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
715 modification.merge(LogicalDatastoreType.OPERATIONAL, path3, flow2.build(), true);
716 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
717 modification.merge(LogicalDatastoreType.CONFIGURATION, path3, flow2.build(), true);
719 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class)
720 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
721 .child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.getKey());
722 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
723 modification.merge(LogicalDatastoreType.OPERATIONAL, path4, flow3.build(), true);
724 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
725 modification.merge(LogicalDatastoreType.CONFIGURATION, path4, flow3.build(), true);
726 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
727 Futures.addCallback(commitFuture, new FutureCallback<Void>() {
729 public void onSuccess(Void aVoid) {
730 ci.println("Status of Group Data Loaded Transaction: success.");
734 public void onFailure(Throwable throwable) {
735 LOG.error(throwable.getMessage(), throwable);
736 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
738 }, MoreExecutors.directExecutor());
744 private static InstructionsBuilder createDecNwTtlInstructions() {
745 DecNwTtlBuilder ta = new DecNwTtlBuilder();
746 DecNwTtl decNwTtl = ta.build();
747 ActionBuilder ab = new ActionBuilder();
748 ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
750 // Add our drop action to a list
751 List<Action> actionList = new ArrayList<Action>();
752 actionList.add(ab.build());
754 // Create an Apply Action
755 ApplyActionsBuilder aab = new ApplyActionsBuilder();
756 aab.setAction(actionList);
758 // Wrap our Apply Action in an Instruction
759 InstructionBuilder ib = new InstructionBuilder();
760 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
761 ib.setKey(new InstructionKey(0));
764 // Put our Instruction in a list of Instructions
765 InstructionsBuilder isb = new InstructionsBuilder();
766 List<Instruction> instructions = new ArrayList<Instruction>();
767 instructions.add(ib.build());
768 isb.setInstruction(instructions);
775 private static InstructionsBuilder createMeterInstructions() {
777 MeterBuilder aab = new MeterBuilder();
778 aab.setMeterId(new MeterId(1L));
780 InstructionBuilder ib = new InstructionBuilder();
781 ib.setInstruction(new MeterCaseBuilder().setMeter(aab.build()).build());
783 // Put our Instruction in a list of Instructions
784 InstructionsBuilder isb = new InstructionsBuilder();
785 List<Instruction> instructions = new ArrayList<Instruction>();
786 instructions.add(ib.build());
787 isb.setInstruction(instructions);
791 private static InstructionsBuilder createGotoTableInstructions() {
793 GoToTableBuilder aab = new GoToTableBuilder();
794 aab.setTableId((short) 2);
796 InstructionBuilder ib = new InstructionBuilder();
797 ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(aab.build()).build());
799 // Put our Instruction in a list of Instructions
800 InstructionsBuilder isb = new InstructionsBuilder();
801 List<Instruction> instructions = new ArrayList<Instruction>();
802 instructions.add(ib.build());
803 isb.setInstruction(instructions);
807 private static InstructionsBuilder createDropInstructions() {
808 DropActionBuilder dab = new DropActionBuilder();
809 DropAction dropAction = dab.build();
810 ActionBuilder ab = new ActionBuilder();
811 ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
813 // Add our drop action to a list
814 List<Action> actionList = new ArrayList<Action>();
815 actionList.add(ab.build());
817 // Create an Apply Action
818 ApplyActionsBuilder aab = new ApplyActionsBuilder();
819 aab.setAction(actionList);
821 // Wrap our Apply Action in an Instruction
822 InstructionBuilder ib = new InstructionBuilder();
823 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
825 // Put our Instruction in a list of Instructions
826 InstructionsBuilder isb = new InstructionsBuilder();
827 List<Instruction> instructions = new ArrayList<Instruction>();
828 instructions.add(ib.build());
829 isb.setInstruction(instructions);
833 private static InstructionsBuilder createAppyActionInstruction() {
835 List<Action> actionList = new ArrayList<Action>();
836 ActionBuilder ab = new ActionBuilder();
837 ControllerActionBuilder controller = new ControllerActionBuilder();
838 controller.setMaxLength(5);
839 ab.setAction(new ControllerActionCaseBuilder().setControllerAction(controller.build()).build());
840 actionList.add(ab.build());
841 // Create an Apply Action
842 ApplyActionsBuilder aab = new ApplyActionsBuilder();
843 aab.setAction(actionList);
845 // Wrap our Apply Action in an Instruction
846 InstructionBuilder ib = new InstructionBuilder();
847 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
849 // Put our Instruction in a list of Instructions
850 InstructionsBuilder isb = new InstructionsBuilder();
851 List<Instruction> instructions = new ArrayList<Instruction>();
852 instructions.add(ib.build());
853 isb.setInstruction(instructions);
857 private static InstructionsBuilder createSentToControllerInstructions() {
858 List<Action> actionList = new ArrayList<Action>();
859 ActionBuilder ab = new ActionBuilder();
861 OutputActionBuilder output = new OutputActionBuilder();
862 output.setMaxLength(0xffff);
863 Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
864 output.setOutputNodeConnector(value);
865 ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
867 ab.setKey(new ActionKey(0));
868 actionList.add(ab.build());
869 // Create an Apply Action
870 ApplyActionsBuilder aab = new ApplyActionsBuilder();
871 aab.setAction(actionList);
873 // Wrap our Apply Action in an Instruction
874 InstructionBuilder ib = new InstructionBuilder();
875 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
877 ib.setKey(new InstructionKey(0));
879 // Put our Instruction in a list of Instructions
880 InstructionsBuilder isb = new InstructionsBuilder();
881 List<Instruction> instructions = new ArrayList<Instruction>();
882 instructions.add(ib.build());
883 isb.setInstruction(instructions);
887 private static InstructionsBuilder createAppyActionInstruction2() {
889 List<Action> actionList = new ArrayList<Action>();
890 ActionBuilder ab = new ActionBuilder();
892 PushMplsActionBuilder push = new PushMplsActionBuilder();
893 push.setEthernetType(0x8847);
894 ab.setAction(new PushMplsActionCaseBuilder().setPushMplsAction(push.build()).build());
895 actionList.add(ab.build());
896 // Create an Apply Action
897 ApplyActionsBuilder aab = new ApplyActionsBuilder();
898 aab.setAction(actionList);
900 // Wrap our Apply Action in an Instruction
901 InstructionBuilder ib = new InstructionBuilder();
902 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
904 // Put our Instruction in a list of Instructions
905 InstructionsBuilder isb = new InstructionsBuilder();
906 List<Instruction> instructions = new ArrayList<Instruction>();
907 instructions.add(ib.build());
908 isb.setInstruction(instructions);
912 private static InstructionsBuilder createAppyActionInstruction3() {
914 List<Action> actionList = new ArrayList<Action>();
915 ActionBuilder ab = new ActionBuilder();
917 PushPbbActionBuilder pbb = new PushPbbActionBuilder();
918 pbb.setEthernetType(0x88E7);
919 ab.setAction(new PushPbbActionCaseBuilder().setPushPbbAction(pbb.build()).build());
920 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<Instruction>();
932 instructions.add(ib.build());
933 isb.setInstruction(instructions);
937 private static InstructionsBuilder createAppyActionInstruction6() {
939 List<Action> actionList = new ArrayList<Action>();
940 ActionBuilder ab = new ActionBuilder();
942 SetDlSrcActionBuilder src = new SetDlSrcActionBuilder();
943 src.setAddress(new MacAddress("00:05:b9:7c:81:5f"));
944 ab.setAction(new SetDlSrcActionCaseBuilder().setSetDlSrcAction(src.build()).build());
945 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<Instruction>();
958 instructions.add(ib.build());
959 isb.setInstruction(instructions);
963 private static InstructionsBuilder createAppyActionInstruction7() {
965 List<Action> actionList = new ArrayList<Action>();
966 ActionBuilder ab = new ActionBuilder();
968 SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
969 VlanId a = new VlanId(4012);
971 ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.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<Instruction>();
984 instructions.add(ib.build());
985 isb.setInstruction(instructions);
989 private static InstructionsBuilder createAppyActionInstruction8() {
991 List<Action> actionList = new ArrayList<Action>();
992 ActionBuilder ab = new ActionBuilder();
994 SetVlanPcpActionBuilder pcp = new SetVlanPcpActionBuilder();
995 VlanPcp pcp1 = new VlanPcp((short) 2);
996 pcp.setVlanPcp(pcp1);
997 ab.setAction(new SetVlanPcpActionCaseBuilder().setSetVlanPcpAction(pcp.build()).build());
998 actionList.add(ab.build());
999 // Create an Apply Action
1000 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1001 aab.setAction(actionList);
1003 // Wrap our Apply Action in an Instruction
1004 InstructionBuilder ib = new InstructionBuilder();
1005 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1007 // Put our Instruction in a list of Instructions
1008 InstructionsBuilder isb = new InstructionsBuilder();
1009 List<Instruction> instructions = new ArrayList<Instruction>();
1010 instructions.add(ib.build());
1011 isb.setInstruction(instructions);
1015 private static InstructionsBuilder createAppyActionInstruction9() {
1017 List<Action> actionList = new ArrayList<Action>();
1018 ActionBuilder ab = new ActionBuilder();
1020 CopyTtlInBuilder ttlin = new CopyTtlInBuilder();
1021 ab.setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(ttlin.build()).build());
1022 actionList.add(ab.build());
1023 // Create an Apply Action
1024 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1025 aab.setAction(actionList);
1027 // Wrap our Apply Action in an Instruction
1028 InstructionBuilder ib = new InstructionBuilder();
1029 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1031 // Put our Instruction in a list of Instructions
1032 InstructionsBuilder isb = new InstructionsBuilder();
1033 List<Instruction> instructions = new ArrayList<Instruction>();
1034 instructions.add(ib.build());
1035 isb.setInstruction(instructions);
1039 private static InstructionsBuilder createAppyActionInstruction16() {
1041 List<Action> actionList = new ArrayList<Action>();
1042 ActionBuilder ab = new ActionBuilder();
1044 GroupActionBuilder groupActionB = new GroupActionBuilder();
1045 groupActionB.setGroupId(1L);
1046 groupActionB.setGroup("0");
1047 ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
1048 actionList.add(ab.build());
1050 // Create an Apply Action
1051 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1052 aab.setAction(actionList);
1054 // Wrap our Apply Action in an Instruction
1055 InstructionBuilder ib = new InstructionBuilder();
1056 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1058 // Put our Instruction in a list of Instructions
1059 InstructionsBuilder isb = new InstructionsBuilder();
1060 List<Instruction> instructions = new ArrayList<Instruction>();
1061 instructions.add(ib.build());
1062 isb.setInstruction(instructions);
1066 private static InstructionsBuilder createAppyActionInstruction160() {
1068 List<Action> actionList = new ArrayList<Action>();
1069 ActionBuilder ab = new ActionBuilder();
1071 FloodAllActionBuilder fldall = new FloodAllActionBuilder();
1072 ab.setAction(new FloodAllActionCaseBuilder().setFloodAllAction(fldall.build()).build());
1073 actionList.add(ab.build());
1074 // Create an Apply Action
1075 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1076 aab.setAction(actionList);
1078 // Wrap our Apply Action in an Instruction
1079 InstructionBuilder ib = new InstructionBuilder();
1080 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1082 // Put our Instruction in a list of Instructions
1083 InstructionsBuilder isb = new InstructionsBuilder();
1084 List<Instruction> instructions = new ArrayList<Instruction>();
1085 instructions.add(ib.build());
1086 isb.setInstruction(instructions);
1090 private static InstructionsBuilder createAppyActionInstruction26() {
1092 List<Action> actionList = new ArrayList<Action>();
1093 ActionBuilder ab = new ActionBuilder();
1095 SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
1096 Ipv4Builder ipdst = new Ipv4Builder();
1097 Ipv4Prefix prefixdst = new Ipv4Prefix("10.0.0.21/24");
1098 ipdst.setIpv4Address(prefixdst);
1099 setNwDstActionBuilder.setAddress(ipdst.build());
1100 ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
1101 actionList.add(ab.build());
1103 // Create an Apply Action
1104 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1105 aab.setAction(actionList);
1107 // Wrap our Apply Action in an Instruction
1108 InstructionBuilder ib = new InstructionBuilder();
1109 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1111 // Put our Instruction in a list of Instructions
1112 InstructionsBuilder isb = new InstructionsBuilder();
1113 List<Instruction> instructions = new ArrayList<Instruction>();
1114 instructions.add(ib.build());
1115 isb.setInstruction(instructions);
1119 private static InstructionsBuilder createAppyActionInstruction27() {
1121 List<Action> actionList = new ArrayList<Action>();
1122 ActionBuilder ab = new ActionBuilder();
1124 SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
1125 Ipv4Builder ipsrc = new Ipv4Builder();
1126 Ipv4Prefix prefixsrc = new Ipv4Prefix("10.0.23.21/24");
1127 ipsrc.setIpv4Address(prefixsrc);
1128 setNwsrcActionBuilder.setAddress(ipsrc.build());
1129 ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
1130 actionList.add(ab.build());
1132 // Create an Apply Action
1133 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1134 aab.setAction(actionList);
1136 // Wrap our Apply Action in an Instruction
1137 InstructionBuilder ib = new InstructionBuilder();
1138 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1140 // Put our Instruction in a list of Instructions
1141 InstructionsBuilder isb = new InstructionsBuilder();
1142 List<Instruction> instructions = new ArrayList<Instruction>();
1143 instructions.add(ib.build());
1144 isb.setInstruction(instructions);
1148 private static InstructionsBuilder createAppyActionInstruction28() {
1150 List<Action> actionList = new ArrayList<Action>();
1151 ActionBuilder ab = new ActionBuilder();
1153 SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
1154 setNwTosActionBuilder.setTos(8);
1155 ab.setAction(new SetNwTosActionCaseBuilder().setSetNwTosAction(setNwTosActionBuilder.build()).build());
1156 actionList.add(ab.build());
1157 // Create an Apply Action
1158 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1159 aab.setAction(actionList);
1161 // Wrap our Apply Action in an Instruction
1162 InstructionBuilder ib = new InstructionBuilder();
1163 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1165 // Put our Instruction in a list of Instructions
1166 InstructionsBuilder isb = new InstructionsBuilder();
1167 List<Instruction> instructions = new ArrayList<Instruction>();
1168 instructions.add(ib.build());
1169 isb.setInstruction(instructions);
1173 private static InstructionsBuilder createAppyActionInstruction34() {
1175 List<Action> actionList = new ArrayList<Action>();
1176 ActionBuilder ab = new ActionBuilder();
1178 SwPathActionBuilder swPathAction = new SwPathActionBuilder();
1179 ab.setAction(new SwPathActionCaseBuilder().setSwPathAction(swPathAction.build()).build());
1180 actionList.add(ab.build());
1182 // Create an Apply Action
1183 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1184 aab.setAction(actionList);
1186 // Wrap our Apply Action in an Instruction
1187 InstructionBuilder ib = new InstructionBuilder();
1188 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1190 // Put our Instruction in a list of Instructions
1191 InstructionsBuilder isb = new InstructionsBuilder();
1192 List<Instruction> instructions = new ArrayList<Instruction>();
1193 instructions.add(ib.build());
1194 isb.setInstruction(instructions);
1198 private static MatchBuilder createLLDPMatch() {
1199 MatchBuilder match = new MatchBuilder();
1200 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1201 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1202 ethTypeBuilder.setType(new EtherType(0x88ccL));
1203 eth.setEthernetType(ethTypeBuilder.build());
1204 match.setEthernetMatch(eth.build());
1211 private static MatchBuilder createMatch1() {
1212 MatchBuilder match = new MatchBuilder();
1213 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1214 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
1215 ipv4Match.setIpv4Destination(prefix);
1216 Ipv4Match i4m = ipv4Match.build();
1217 match.setLayer3Match(i4m);
1219 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1220 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1221 ethTypeBuilder.setType(new EtherType(0x0800L));
1222 eth.setEthernetType(ethTypeBuilder.build());
1223 match.setEthernetMatch(eth.build());
1227 private static MatchBuilder createMatch1000() {
1228 MatchBuilder match = new MatchBuilder();
1229 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1230 Ipv4Prefix prefix = new Ipv4Prefix("10.1.1.1/24");
1231 ipv4Match.setIpv4Destination(prefix);
1232 Ipv4Match i4m = ipv4Match.build();
1233 match.setLayer3Match(i4m);
1235 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1236 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1237 ethTypeBuilder.setType(new EtherType(0x0800L));
1238 eth.setEthernetType(ethTypeBuilder.build());
1239 match.setEthernetMatch(eth.build());
1246 private static MatchBuilder createMatch2() {
1247 MatchBuilder match = new MatchBuilder();
1248 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1249 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1");
1250 ipv4Match.setIpv4Source(prefix);
1251 Ipv4Match i4m = ipv4Match.build();
1252 match.setLayer3Match(i4m);
1254 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1255 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1256 ethTypeBuilder.setType(new EtherType(0x0800L));
1257 eth.setEthernetType(ethTypeBuilder.build());
1258 match.setEthernetMatch(eth.build());
1265 private static MatchBuilder createMatch3() {
1266 MatchBuilder match = new MatchBuilder();
1267 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
1268 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
1269 ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
1270 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
1271 match.setEthernetMatch(ethernetMatch.build());
1276 private static MatchBuilder createMatch33() {
1278 MatchBuilder match = new MatchBuilder();
1279 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1280 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.10");
1281 ipv4Match.setIpv4Source(prefix);
1282 Ipv4Match i4m = ipv4Match.build();
1283 match.setLayer3Match(i4m);
1285 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1286 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1287 ethTypeBuilder.setType(new EtherType(0xfffeL));
1288 eth.setEthernetType(ethTypeBuilder.build());
1289 match.setEthernetMatch(eth.build());
1293 private static MatchBuilder createInphyportMatch(NodeId nodeId) {
1294 MatchBuilder match = new MatchBuilder();
1295 match.setInPort(new NodeConnectorId(nodeId + ":202"));
1296 match.setInPhyPort(new NodeConnectorId(nodeId + ":10122"));
1300 private static MatchBuilder createEthernetMatch() {
1301 MatchBuilder match = new MatchBuilder();
1303 byte[] mask1 = new byte[]{(byte) -1, (byte) -1, 0, 0, 0, 0};
1304 byte[] mask2 = new byte[]{(byte) -1, (byte) -1, (byte) -1, 0, 0, 0};
1306 EthernetMatchBuilder ethmatch = new EthernetMatchBuilder(); // ethernettype
1308 EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
1309 EtherType type = new EtherType(0x0800L);
1310 ethmatch.setEthernetType(ethtype.setType(type).build());
1312 EthernetDestinationBuilder ethdest = new EthernetDestinationBuilder(); // ethernet
1315 MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
1316 ethdest.setAddress(macdest);
1317 // ethdest.setMask(mask1);
1319 ethmatch.setEthernetDestination(ethdest.build());
1321 EthernetSourceBuilder ethsrc = new EthernetSourceBuilder();
1322 MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
1323 ethsrc.setAddress(macsrc);
1324 // ethsrc.setMask(mask2);
1326 ethmatch.setEthernetSource(ethsrc.build());
1327 match.setEthernetMatch(ethmatch.build());
1335 private static MatchBuilder createL3IPv6Match() {
1336 MatchBuilder match = new MatchBuilder();
1338 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1339 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1340 ethTypeBuilder.setType(new EtherType(0x86ddL));
1341 eth.setEthernetType(ethTypeBuilder.build());
1342 match.setEthernetMatch(eth.build());
1344 Ipv6Prefix dstip6 = new Ipv6Prefix("2002::2/64");
1345 Ipv6Prefix srcip6 = new Ipv6Prefix("2001:0:0:0:0:0:0:1/56");
1346 Ipv6Address ndtarget = new Ipv6Address("2001:db8:0:1:fd97:f9f0:a810:782e");
1347 MacAddress ndsll = new MacAddress("c2:00:54:f5:00:00");
1348 MacAddress ndtll = new MacAddress("00:0c:29:0e:4c:67");
1349 Ipv6ExtHeaderBuilder nextheader = new Ipv6ExtHeaderBuilder();
1350 nextheader.setIpv6Exthdr(58);
1351 Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
1352 Ipv6FlowLabel label = new Ipv6FlowLabel(10028L);
1353 ipv6label.setIpv6Flabel(label);
1354 // ipv6label.setFlabelMask(new byte[] { 0, 1, -1, -1 });
1356 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1358 icmpv6match.setIcmpv6Type((short) 135);
1359 icmpv6match.setIcmpv6Code((short) 0);
1360 match.setIcmpv6Match(icmpv6match.build());
1362 Ipv6MatchBuilder ipv6match = new Ipv6MatchBuilder();
1363 // ipv6match.setIpv6Source(srcip6);
1364 // ipv6match.setIpv6Destination(dstip6);
1365 // ipv6match.setIpv6ExtHeader(nextheader.build());
1366 ipv6match.setIpv6NdSll(ndsll);
1367 ipv6match.setIpv6NdTll(ndtll);
1368 // ipv6match.setIpv6NdTarget(ndtarget);
1369 ipv6match.setIpv6Label(ipv6label.build());
1371 match.setLayer3Match(ipv6match.build());
1379 private static MatchBuilder createICMPv6Match() {
1381 MatchBuilder match = new MatchBuilder();
1382 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1383 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1384 ethTypeBuilder.setType(new EtherType(0x86ddL));
1385 eth.setEthernetType(ethTypeBuilder.build());
1386 match.setEthernetMatch(eth.build());
1388 IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
1389 ipmatch.setIpProtocol((short) 58);
1390 match.setIpMatch(ipmatch.build());
1392 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1394 icmpv6match.setIcmpv6Type((short) 135);
1395 icmpv6match.setIcmpv6Code((short) 1);
1396 match.setIcmpv6Match(icmpv6match.build());
1404 private static MatchBuilder createMetadataMatch() {
1405 MatchBuilder match = new MatchBuilder();
1406 byte[] metamask = new byte[]{(byte) -1, (byte) -1, (byte) -1, 0, 0, 0, (byte) 1, (byte) 1};
1407 MetadataBuilder metadata = new MetadataBuilder(); // metadata match
1408 metadata.setMetadata(BigInteger.valueOf(500L));
1409 // metadata.setMetadataMask(metamask);
1410 match.setMetadata(metadata.build());