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 java.math.BigInteger;
15 import java.util.ArrayList;
16 import java.util.List;
17 import org.eclipse.osgi.framework.console.CommandInterpreter;
18 import org.eclipse.osgi.framework.console.CommandProvider;
19 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
20 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
21 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
22 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
23 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
24 import org.opendaylight.controller.sal.binding.api.NotificationService;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.all.action._case.FloodAllActionBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.sw.path.action._case.SwPathActionBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.node.error.service.rev140410.NodeErrorListener;
114 import org.opendaylight.yangtools.concepts.Registration;
115 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
116 import org.osgi.framework.BundleContext;
117 import org.slf4j.Logger;
118 import org.slf4j.LoggerFactory;
120 //import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.M
122 public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
124 private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginBulkTransactionProvider.class);
125 private DataBroker dataBroker;
126 private final BundleContext ctx;
127 private NodeBuilder testNode;
128 private ProviderContext pc;
129 private FlowBuilder testFlow;
130 private final String originalFlowName = "Foo";
131 private final NodeErrorListener nodeErrorListener = new NodeErrorListenerLoggingImpl();
132 private Registration listener1Reg;
133 private Registration listener2Reg;
134 private Node testNode12;
135 private final String originalGroupName = "Foo";
136 private static NotificationService notificationService;
138 public OpenflowPluginBulkTransactionProvider(BundleContext ctx) {
142 public void onSessionInitiated(ProviderContext session) {
144 notificationService = session.getSALService(NotificationService.class);
145 listener2Reg = notificationService.registerNotificationListener(nodeErrorListener);
146 dataBroker = session.getSALService(DataBroker.class);
147 ctx.registerService(CommandProvider.class.getName(), this, null);
148 createTestFlow(createTestNode(null), null, null);
151 private NodeBuilder createTestNode(String nodeId) {
152 if (nodeId == null) {
153 nodeId = OpenflowpluginTestActivator.NODE_ID;
155 NodeRef nodeOne = createNodeRef(nodeId);
156 NodeBuilder builder = new NodeBuilder();
157 builder.setId(new NodeId(nodeId));
158 builder.setKey(new NodeKey(builder.getId()));
163 private static NodeRef createNodeRef(String string) {
164 NodeKey key = new NodeKey(new NodeId(string));
165 InstanceIdentifier<Node> path = InstanceIdentifier.create(Nodes.class).child(Node.class, key);
167 return new NodeRef(path);
171 public String getHelp() {
175 private FlowBuilder createTestFlow(NodeBuilder nodeBuilder, String flowTypeArg, String tableId) {
177 FlowBuilder flow = new FlowBuilder();
180 String flowType = flowTypeArg;
181 if (flowType == null) {
188 flow.setMatch(createMatch1().build());
189 flow.setInstructions(createDecNwTtlInstructions().build());
193 flow.setMatch(createMatch2().build());
194 flow.setInstructions(createDropInstructions().build());
198 flow.setMatch(createMatch3().build());
199 flow.setInstructions(createDropInstructions().build());
203 flow.setMatch(createEthernetMatch().build());
204 flow.setInstructions(createDropInstructions().build());
208 flow.setMatch(createMatch1().build());
209 flow.setInstructions(createAppyActionInstruction().build());
213 flow.setMatch(createMatch1().build());
214 flow.setInstructions(createGotoTableInstructions().build());
218 flow.setMatch(createMatch1().build());
219 flow.setInstructions(createMeterInstructions().build());
223 flow.setMatch(createMatch1().build());
224 flow.setInstructions(createAppyActionInstruction7().build());
228 flow.setMatch(createMatch1().build());
229 flow.setInstructions(createAppyActionInstruction2().build());
233 flow.setMatch(createMatch1().build());
234 flow.setInstructions(createAppyActionInstruction3().build());
238 flow.setMatch(createMatch1().build());
239 flow.setInstructions(createAppyActionInstruction16().build());
243 flow.setMatch(createMatch1().build());
244 flow.setInstructions(createAppyActionInstruction160().build());
248 flow.setMatch(createMatch1().build());
249 flow.setInstructions(createAppyActionInstruction26().build());
253 flow.setMatch(createMatch1().build());
254 flow.setInstructions(createAppyActionInstruction27().build());
258 flow.setMatch(createMatch1().build());
259 flow.setInstructions(createAppyActionInstruction28().build());
263 flow.setMatch(createMatch1().build());
264 flow.setInstructions(createAppyActionInstruction34().build());
268 flow.setMatch(createICMPv6Match().build());
269 flow.setInstructions(createDecNwTtlInstructions().build());
273 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
274 flow.setInstructions(createDropInstructions().build());
278 flow.setMatch(createMetadataMatch().build());
279 flow.setInstructions(createDropInstructions().build());
283 flow.setMatch(createL3IPv6Match().build());
284 flow.setInstructions(createDecNwTtlInstructions().build());
288 flow.setMatch(createLLDPMatch().build());
289 flow.setInstructions(createSentToControllerInstructions().build());
294 flow.setMatch(createMatch1().build());
295 flow.setInstructions(createDropInstructions().build());
299 flow.setMatch(createMatch2().build());
300 flow.setInstructions(createDecNwTtlInstructions().build());
304 flow.setMatch(createMatch3().build());
305 flow.setInstructions(createDecNwTtlInstructions().build());
309 flow.setMatch(createEthernetMatch().build());
310 flow.setInstructions(createMeterInstructions().build());
314 flow.setMatch(createMatch1().build());
315 flow.setInstructions(createDecNwTtlInstructions().build());
319 flow.setMatch(createMatch1().build());
320 flow.setInstructions(createAppyActionInstruction7().build());
324 flow.setMatch(createEthernetMatch().build());
325 flow.setInstructions(createAppyActionInstruction6().build());
329 flow.setMatch(createEthernetMatch().build());
330 flow.setInstructions(createAppyActionInstruction7().build());
334 flow.setMatch(createMatch1().build());
335 flow.setInstructions(createAppyActionInstruction9().build());
339 flow.setMatch(createMatch1().build());
340 flow.setInstructions(createAppyActionInstruction9().build());
344 flow.setMatch(createMatch1().build());
345 flow.setInstructions(createAppyActionInstruction6().build());
349 flow.setMatch(createMatch1().build());
350 flow.setInstructions(createDecNwTtlInstructions().build());
354 flow.setMatch(createMatch1().build());
355 flow.setInstructions(createDecNwTtlInstructions().build());
359 flow.setMatch(createMatch1().build());
360 flow.setInstructions(createDecNwTtlInstructions().build());
364 flow.setMatch(createICMPv6Match().build());
365 flow.setInstructions(createDropInstructions().build());
369 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
370 flow.setInstructions(createMeterInstructions().build());
374 flow.setMatch(createMetadataMatch().build());
375 flow.setInstructions(createAppyActionInstruction6().build());
379 flow.setMatch(createMatch1().build());
380 flow.setInstructions(createAppyActionInstruction6().build());
384 flow.setMatch(createMatch1().build());
385 flow.setInstructions(createAppyActionInstruction7().build());
389 flow.setMatch(createMatch1().build());
390 flow.setInstructions(createAppyActionInstruction8().build());
394 flow.setMatch(createMatch3().build());
395 flow.setInstructions(createMeterInstructions().build());
399 flow.setMatch(createMatch1000().build());
400 flow.setInstructions(createAppyActionInstruction6().build());
404 flow.setMatch(createMatch1000().build());
405 flow.setInstructions(createAppyActionInstruction2().build());
409 flow.setMatch(createMatch1000().build());
410 flow.setInstructions(createAppyActionInstruction3().build());
413 LOG.warn("flow type not understood: {}", flowType);
416 FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
417 if (null == flow.isBarrier()) {
418 flow.setBarrier(Boolean.FALSE);
420 // flow.setBufferId(12L);
421 BigInteger value = BigInteger.valueOf(10);
422 BigInteger outputPort = BigInteger.valueOf(4294967295L);
423 flow.setCookie(new FlowCookie(value));
424 flow.setCookieMask(new FlowCookie(value));
425 flow.setHardTimeout(0);
426 flow.setIdleTimeout(0);
427 flow.setInstallHw(false);
428 flow.setStrict(false);
429 flow.setContainerName(null);
430 flow.setFlags(new FlowModFlags(false, false, false, false, true));
431 flow.setId(new FlowId("12"));
432 flow.setTableId(getTableId(tableId));
433 flow.setOutGroup(4294967295L);
434 // set outport to OFPP_NONE (65535) to disable remove restriction for
436 flow.setOutPort(outputPort);
440 flow.setFlowName(originalFlowName + "X" + flowType);
445 private short getTableId(String tableId) {
448 table = Short.parseShort(tableId);
449 } catch (Exception ex) {
450 // ignore exception and continue with default value
457 private void createTestNode() {
458 NodeRef nodeOne = createNodeRef(OpenflowpluginTestActivator.NODE_ID);
459 NodeBuilder builder = new NodeBuilder();
460 builder.setId(new NodeId(OpenflowpluginTestActivator.NODE_ID));
461 builder.setKey(new NodeKey(builder.getId()));
462 testNode12 = builder.build();
465 public void _addFlows(CommandInterpreter ci) {
466 NodeBuilder tn = createTestNode(ci.nextArgument());
467 String flowtype = ci.nextArgument();
468 Integer flowcnt = Integer.parseInt(flowtype);
475 tf = createTestFlow(tn, "f1", "10");
476 tf1 = createTestFlow(tn, "f2", "11");
477 tf2 = createTestFlow(tn, "f3", "12");
478 tf3 = createTestFlow(tn, "f4", "13");
481 tf = createTestFlow(tn, "f3", "3");
482 tf1 = createTestFlow(tn, "f4", "4");
483 tf2 = createTestFlow(tn, "f5", "5");
484 tf3 = createTestFlow(tn, "f6", "6");
487 tf = createTestFlow(tn, "f7", "7");
488 tf1 = createTestFlow(tn, "f8", "8");
489 tf2 = createTestFlow(tn, "f9", "9");
490 tf3 = createTestFlow(tn, "f10", "10");
494 tf = createTestFlow(tn, "f23", "3");
495 tf1 = createTestFlow(tn, "f34", "4");
496 tf2 = createTestFlow(tn, "f35", "5");
497 tf3 = createTestFlow(tn, "f36", "6");
502 tf = createTestFlow(tn, "f230", "3");
503 tf1 = createTestFlow(tn, "f34", "4");
504 tf2 = createTestFlow(tn, "f35", "5");
505 tf3 = createTestFlow(tn, "f36", "6");
509 tf = createTestFlow(tn, "f42", "42");
510 tf1 = createTestFlow(tn, "f43", "43");
511 tf2 = createTestFlow(tn, "f44", "44");
512 tf3 = createTestFlow(tn, "f45", "45");
515 writeFlow(ci, tf, tf1, tf2, tf3, tn);
518 private InstanceIdentifier<Node> nodeBuilderToInstanceId(NodeBuilder node) {
519 return InstanceIdentifier.create(Nodes.class).child(Node.class, node.getKey());
522 public void _modifyFlows(CommandInterpreter ci) {
523 NodeBuilder tn = createTestNode(ci.nextArgument());
524 String flowtype = ci.nextArgument();
525 Integer flowcnt = Integer.parseInt(flowtype);
532 tf = createTestFlow(tn, "f82", "10");
533 tf1 = createTestFlow(tn, "f83", "11");
534 tf2 = createTestFlow(tn, "f84", "12");
535 tf3 = createTestFlow(tn, "f85", "13");
538 tf = createTestFlow(tn, "f700", "3");
539 tf1 = createTestFlow(tn, "f4", "4");
540 tf2 = createTestFlow(tn, "f900", "5");
541 tf3 = createTestFlow(tn, "f86", "6");
545 tf = createTestFlow(tn, "f91", "7");
546 tf1 = createTestFlow(tn, "f92", "8");
547 tf2 = createTestFlow(tn, "f93", "9");
548 tf3 = createTestFlow(tn, "f94", "10");
552 tf = createTestFlow(tn, "f230", "3");
553 tf1 = createTestFlow(tn, "f99", "4");
554 tf2 = createTestFlow(tn, "f100", "5");
555 tf3 = createTestFlow(tn, "f101", "6");
559 tf = createTestFlow(tn, "f23", "3");
560 tf1 = createTestFlow(tn, "f99", "4");
561 tf2 = createTestFlow(tn, "f100", "5");
562 tf3 = createTestFlow(tn, "f101", "6");
566 tf = createTestFlow(tn, "f87", "12");
567 tf1 = createTestFlow(tn, "f88", "13");
568 tf2 = createTestFlow(tn, "f89", "14");
569 tf3 = createTestFlow(tn, "f90", "15");
573 writeFlow(ci, tf, tf1, tf2, tf3, tn);
577 public void _removeFlows(final CommandInterpreter ci) {
578 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
579 NodeBuilder tn = createTestNode(ci.nextArgument());
580 String flowtype = ci.nextArgument();
581 Integer flowcnt = Integer.parseInt(flowtype);
582 FlowBuilder tf = null;
583 FlowBuilder tf1 = null;
584 FlowBuilder tf2 = null;
585 FlowBuilder tf3 = null;
589 tf = createTestFlow(tn, "f1", "10");
590 tf1 = createTestFlow(tn, "f2", "11");
591 tf2 = createTestFlow(tn, "f3", "12");
592 tf3 = createTestFlow(tn, "f4", "13");
596 tf = createTestFlow(tn, "f82", "10");
597 tf1 = createTestFlow(tn, "f83", "11");
598 tf2 = createTestFlow(tn, "f84", "12");
599 tf3 = createTestFlow(tn, "f85", "13");
603 tf = createTestFlow(tn, "f3", "3");
604 tf1 = createTestFlow(tn, "f4", "4");
605 tf2 = createTestFlow(tn, "f5", "5");
606 tf3 = createTestFlow(tn, "f6", "6");
610 tf = createTestFlow(tn, "f700", "3");
611 tf1 = createTestFlow(tn, "f4", "4");
612 tf2 = createTestFlow(tn, "f900", "5");
613 tf3 = createTestFlow(tn, "f86", "6");
617 tf = createTestFlow(tn, "f7", "7");
618 tf1 = createTestFlow(tn, "f8", "8");
619 tf2 = createTestFlow(tn, "f9", "9");
620 tf3 = createTestFlow(tn, "f10", "10");
624 tf = createTestFlow(tn, "f91", "7");
625 tf1 = createTestFlow(tn, "f92", "8");
626 tf2 = createTestFlow(tn, "f93", "9");
627 tf3 = createTestFlow(tn, "f94", "10");
631 tf = createTestFlow(tn, "f23", "3");
632 tf1 = createTestFlow(tn, "f34", "4");
633 tf2 = createTestFlow(tn, "f35", "5");
634 tf3 = createTestFlow(tn, "f36", "6");
639 tf = createTestFlow(tn, "f23", "3");
640 tf1 = createTestFlow(tn, "f99", "4");
641 tf2 = createTestFlow(tn, "f100", "5");
642 tf3 = createTestFlow(tn, "f101", "6");
646 tf = createTestFlow(tn, "f700", "7");
647 tf1 = createTestFlow(tn, "f230", "23");
648 tf2 = createTestFlow(tn, "f900", "9");
649 tf3 = createTestFlow(tn, "f1000", "10");
653 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
654 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
655 .child(Flow.class, tf.getKey());
656 modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
657 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
658 modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
659 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
660 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf1.getTableId()))
661 .child(Flow.class, tf1.getKey());
662 modification.delete(LogicalDatastoreType.OPERATIONAL, path2);
663 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
664 modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
666 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
667 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf2.getTableId()))
668 .child(Flow.class, tf2.getKey());
669 modification.delete(LogicalDatastoreType.OPERATIONAL, path3);
670 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
671 modification.delete(LogicalDatastoreType.CONFIGURATION, path3);
672 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
673 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf3.getTableId()))
674 .child(Flow.class, tf3.getKey());
675 modification.delete(LogicalDatastoreType.OPERATIONAL, path4);
676 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
677 modification.delete(LogicalDatastoreType.CONFIGURATION, path4);
678 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
679 Futures.addCallback(commitFuture, new FutureCallback<Void>() {
681 public void onSuccess(Void aVoid) {
682 ci.println("Status of Group Data Loaded Transaction: success.");
686 public void onFailure(Throwable throwable) {
687 LOG.error(throwable.getMessage(), throwable);
688 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
694 private void writeFlow(final CommandInterpreter ci, FlowBuilder flow, FlowBuilder flow1, FlowBuilder flow2,
695 FlowBuilder flow3, NodeBuilder nodeBuilder) {
696 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
697 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class)
698 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
699 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey());
700 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
701 modification.merge(LogicalDatastoreType.OPERATIONAL, path1, flow.build(), true);
702 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
703 modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
704 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class)
705 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
706 .child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.getKey());
707 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
708 modification.merge(LogicalDatastoreType.OPERATIONAL, path2, flow1.build(), true);
709 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
710 modification.merge(LogicalDatastoreType.CONFIGURATION, path2, flow1.build(), true);
712 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class)
713 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
714 .child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.getKey());
715 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
716 modification.merge(LogicalDatastoreType.OPERATIONAL, path3, flow2.build(), true);
717 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
718 modification.merge(LogicalDatastoreType.CONFIGURATION, path3, flow2.build(), true);
720 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class)
721 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
722 .child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.getKey());
723 modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
724 modification.merge(LogicalDatastoreType.OPERATIONAL, path4, flow3.build(), true);
725 modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
726 modification.merge(LogicalDatastoreType.CONFIGURATION, path4, flow3.build(), true);
727 CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
728 Futures.addCallback(commitFuture, new FutureCallback<Void>() {
730 public void onSuccess(Void aVoid) {
731 ci.println("Status of Group Data Loaded Transaction: success.");
735 public void onFailure(Throwable throwable) {
736 LOG.error(throwable.getMessage(), throwable);
737 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
745 private static InstructionsBuilder createDecNwTtlInstructions() {
746 DecNwTtlBuilder ta = new DecNwTtlBuilder();
747 DecNwTtl decNwTtl = ta.build();
748 ActionBuilder ab = new ActionBuilder();
749 ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
751 // Add our drop action to a list
752 List<Action> actionList = new ArrayList<Action>();
753 actionList.add(ab.build());
755 // Create an Apply Action
756 ApplyActionsBuilder aab = new ApplyActionsBuilder();
757 aab.setAction(actionList);
759 // Wrap our Apply Action in an Instruction
760 InstructionBuilder ib = new InstructionBuilder();
761 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
762 ib.setKey(new InstructionKey(0));
765 // Put our Instruction in a list of Instructions
766 InstructionsBuilder isb = new InstructionsBuilder();
767 List<Instruction> instructions = new ArrayList<Instruction>();
768 instructions.add(ib.build());
769 isb.setInstruction(instructions);
776 private static InstructionsBuilder createMeterInstructions() {
778 MeterBuilder aab = new MeterBuilder();
779 aab.setMeterId(new MeterId(1L));
781 InstructionBuilder ib = new InstructionBuilder();
782 ib.setInstruction(new MeterCaseBuilder().setMeter(aab.build()).build());
784 // Put our Instruction in a list of Instructions
785 InstructionsBuilder isb = new InstructionsBuilder();
786 List<Instruction> instructions = new ArrayList<Instruction>();
787 instructions.add(ib.build());
788 isb.setInstruction(instructions);
792 private static InstructionsBuilder createGotoTableInstructions() {
794 GoToTableBuilder aab = new GoToTableBuilder();
795 aab.setTableId((short) 2);
797 InstructionBuilder ib = new InstructionBuilder();
798 ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(aab.build()).build());
800 // Put our Instruction in a list of Instructions
801 InstructionsBuilder isb = new InstructionsBuilder();
802 List<Instruction> instructions = new ArrayList<Instruction>();
803 instructions.add(ib.build());
804 isb.setInstruction(instructions);
808 private static InstructionsBuilder createDropInstructions() {
809 DropActionBuilder dab = new DropActionBuilder();
810 DropAction dropAction = dab.build();
811 ActionBuilder ab = new ActionBuilder();
812 ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
814 // Add our drop action to a list
815 List<Action> actionList = new ArrayList<Action>();
816 actionList.add(ab.build());
818 // Create an Apply Action
819 ApplyActionsBuilder aab = new ApplyActionsBuilder();
820 aab.setAction(actionList);
822 // Wrap our Apply Action in an Instruction
823 InstructionBuilder ib = new InstructionBuilder();
824 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
826 // Put our Instruction in a list of Instructions
827 InstructionsBuilder isb = new InstructionsBuilder();
828 List<Instruction> instructions = new ArrayList<Instruction>();
829 instructions.add(ib.build());
830 isb.setInstruction(instructions);
834 private static InstructionsBuilder createAppyActionInstruction() {
836 List<Action> actionList = new ArrayList<Action>();
837 ActionBuilder ab = new ActionBuilder();
838 ControllerActionBuilder controller = new ControllerActionBuilder();
839 controller.setMaxLength(5);
840 ab.setAction(new ControllerActionCaseBuilder().setControllerAction(controller.build()).build());
841 actionList.add(ab.build());
842 // Create an Apply Action
843 ApplyActionsBuilder aab = new ApplyActionsBuilder();
844 aab.setAction(actionList);
846 // Wrap our Apply Action in an Instruction
847 InstructionBuilder ib = new InstructionBuilder();
848 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
850 // Put our Instruction in a list of Instructions
851 InstructionsBuilder isb = new InstructionsBuilder();
852 List<Instruction> instructions = new ArrayList<Instruction>();
853 instructions.add(ib.build());
854 isb.setInstruction(instructions);
858 private static InstructionsBuilder createSentToControllerInstructions() {
859 List<Action> actionList = new ArrayList<Action>();
860 ActionBuilder ab = new ActionBuilder();
862 OutputActionBuilder output = new OutputActionBuilder();
863 output.setMaxLength(0xffff);
864 Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
865 output.setOutputNodeConnector(value);
866 ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
868 ab.setKey(new ActionKey(0));
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 ib.setKey(new InstructionKey(0));
880 // Put our Instruction in a list of Instructions
881 InstructionsBuilder isb = new InstructionsBuilder();
882 List<Instruction> instructions = new ArrayList<Instruction>();
883 instructions.add(ib.build());
884 isb.setInstruction(instructions);
888 private static InstructionsBuilder createAppyActionInstruction2() {
890 List<Action> actionList = new ArrayList<Action>();
891 ActionBuilder ab = new ActionBuilder();
893 PushMplsActionBuilder push = new PushMplsActionBuilder();
894 push.setEthernetType(0x8847);
895 ab.setAction(new PushMplsActionCaseBuilder().setPushMplsAction(push.build()).build());
896 actionList.add(ab.build());
897 // Create an Apply Action
898 ApplyActionsBuilder aab = new ApplyActionsBuilder();
899 aab.setAction(actionList);
901 // Wrap our Apply Action in an Instruction
902 InstructionBuilder ib = new InstructionBuilder();
903 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
905 // Put our Instruction in a list of Instructions
906 InstructionsBuilder isb = new InstructionsBuilder();
907 List<Instruction> instructions = new ArrayList<Instruction>();
908 instructions.add(ib.build());
909 isb.setInstruction(instructions);
913 private static InstructionsBuilder createAppyActionInstruction3() {
915 List<Action> actionList = new ArrayList<Action>();
916 ActionBuilder ab = new ActionBuilder();
918 PushPbbActionBuilder pbb = new PushPbbActionBuilder();
919 pbb.setEthernetType(0x88E7);
920 ab.setAction(new PushPbbActionCaseBuilder().setPushPbbAction(pbb.build()).build());
921 actionList.add(ab.build());
922 // Create an Apply Action
923 ApplyActionsBuilder aab = new ApplyActionsBuilder();
924 aab.setAction(actionList);
926 // Wrap our Apply Action in an Instruction
927 InstructionBuilder ib = new InstructionBuilder();
928 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
930 // Put our Instruction in a list of Instructions
931 InstructionsBuilder isb = new InstructionsBuilder();
932 List<Instruction> instructions = new ArrayList<Instruction>();
933 instructions.add(ib.build());
934 isb.setInstruction(instructions);
938 private static InstructionsBuilder createAppyActionInstruction6() {
940 List<Action> actionList = new ArrayList<Action>();
941 ActionBuilder ab = new ActionBuilder();
943 SetDlSrcActionBuilder src = new SetDlSrcActionBuilder();
944 src.setAddress(new MacAddress("00:05:b9:7c:81:5f"));
945 ab.setAction(new SetDlSrcActionCaseBuilder().setSetDlSrcAction(src.build()).build());
946 actionList.add(ab.build());
948 // Create an Apply Action
949 ApplyActionsBuilder aab = new ApplyActionsBuilder();
950 aab.setAction(actionList);
952 // Wrap our Apply Action in an Instruction
953 InstructionBuilder ib = new InstructionBuilder();
954 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
956 // Put our Instruction in a list of Instructions
957 InstructionsBuilder isb = new InstructionsBuilder();
958 List<Instruction> instructions = new ArrayList<Instruction>();
959 instructions.add(ib.build());
960 isb.setInstruction(instructions);
964 private static InstructionsBuilder createAppyActionInstruction7() {
966 List<Action> actionList = new ArrayList<Action>();
967 ActionBuilder ab = new ActionBuilder();
969 SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
970 VlanId a = new VlanId(4012);
972 ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.build()).build());
973 actionList.add(ab.build());
974 // Create an Apply Action
975 ApplyActionsBuilder aab = new ApplyActionsBuilder();
976 aab.setAction(actionList);
978 // Wrap our Apply Action in an Instruction
979 InstructionBuilder ib = new InstructionBuilder();
980 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
982 // Put our Instruction in a list of Instructions
983 InstructionsBuilder isb = new InstructionsBuilder();
984 List<Instruction> instructions = new ArrayList<Instruction>();
985 instructions.add(ib.build());
986 isb.setInstruction(instructions);
990 private static InstructionsBuilder createAppyActionInstruction8() {
992 List<Action> actionList = new ArrayList<Action>();
993 ActionBuilder ab = new ActionBuilder();
995 SetVlanPcpActionBuilder pcp = new SetVlanPcpActionBuilder();
996 VlanPcp pcp1 = new VlanPcp((short) 2);
997 pcp.setVlanPcp(pcp1);
998 ab.setAction(new SetVlanPcpActionCaseBuilder().setSetVlanPcpAction(pcp.build()).build());
999 actionList.add(ab.build());
1000 // Create an Apply Action
1001 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1002 aab.setAction(actionList);
1004 // Wrap our Apply Action in an Instruction
1005 InstructionBuilder ib = new InstructionBuilder();
1006 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1008 // Put our Instruction in a list of Instructions
1009 InstructionsBuilder isb = new InstructionsBuilder();
1010 List<Instruction> instructions = new ArrayList<Instruction>();
1011 instructions.add(ib.build());
1012 isb.setInstruction(instructions);
1016 private static InstructionsBuilder createAppyActionInstruction9() {
1018 List<Action> actionList = new ArrayList<Action>();
1019 ActionBuilder ab = new ActionBuilder();
1021 CopyTtlInBuilder ttlin = new CopyTtlInBuilder();
1022 ab.setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(ttlin.build()).build());
1023 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<Instruction>();
1035 instructions.add(ib.build());
1036 isb.setInstruction(instructions);
1040 private static InstructionsBuilder createAppyActionInstruction16() {
1042 List<Action> actionList = new ArrayList<Action>();
1043 ActionBuilder ab = new ActionBuilder();
1045 GroupActionBuilder groupActionB = new GroupActionBuilder();
1046 groupActionB.setGroupId(1L);
1047 groupActionB.setGroup("0");
1048 ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
1049 actionList.add(ab.build());
1051 // Create an Apply Action
1052 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1053 aab.setAction(actionList);
1055 // Wrap our Apply Action in an Instruction
1056 InstructionBuilder ib = new InstructionBuilder();
1057 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1059 // Put our Instruction in a list of Instructions
1060 InstructionsBuilder isb = new InstructionsBuilder();
1061 List<Instruction> instructions = new ArrayList<Instruction>();
1062 instructions.add(ib.build());
1063 isb.setInstruction(instructions);
1067 private static InstructionsBuilder createAppyActionInstruction160() {
1069 List<Action> actionList = new ArrayList<Action>();
1070 ActionBuilder ab = new ActionBuilder();
1072 FloodAllActionBuilder fldall = new FloodAllActionBuilder();
1073 ab.setAction(new FloodAllActionCaseBuilder().setFloodAllAction(fldall.build()).build());
1074 actionList.add(ab.build());
1075 // Create an Apply Action
1076 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1077 aab.setAction(actionList);
1079 // Wrap our Apply Action in an Instruction
1080 InstructionBuilder ib = new InstructionBuilder();
1081 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1083 // Put our Instruction in a list of Instructions
1084 InstructionsBuilder isb = new InstructionsBuilder();
1085 List<Instruction> instructions = new ArrayList<Instruction>();
1086 instructions.add(ib.build());
1087 isb.setInstruction(instructions);
1091 private static InstructionsBuilder createAppyActionInstruction26() {
1093 List<Action> actionList = new ArrayList<Action>();
1094 ActionBuilder ab = new ActionBuilder();
1096 SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
1097 Ipv4Builder ipdst = new Ipv4Builder();
1098 Ipv4Prefix prefixdst = new Ipv4Prefix("10.0.0.21/24");
1099 ipdst.setIpv4Address(prefixdst);
1100 setNwDstActionBuilder.setAddress(ipdst.build());
1101 ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
1102 actionList.add(ab.build());
1104 // Create an Apply Action
1105 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1106 aab.setAction(actionList);
1108 // Wrap our Apply Action in an Instruction
1109 InstructionBuilder ib = new InstructionBuilder();
1110 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1112 // Put our Instruction in a list of Instructions
1113 InstructionsBuilder isb = new InstructionsBuilder();
1114 List<Instruction> instructions = new ArrayList<Instruction>();
1115 instructions.add(ib.build());
1116 isb.setInstruction(instructions);
1120 private static InstructionsBuilder createAppyActionInstruction27() {
1122 List<Action> actionList = new ArrayList<Action>();
1123 ActionBuilder ab = new ActionBuilder();
1125 SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
1126 Ipv4Builder ipsrc = new Ipv4Builder();
1127 Ipv4Prefix prefixsrc = new Ipv4Prefix("10.0.23.21/24");
1128 ipsrc.setIpv4Address(prefixsrc);
1129 setNwsrcActionBuilder.setAddress(ipsrc.build());
1130 ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
1131 actionList.add(ab.build());
1133 // Create an Apply Action
1134 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1135 aab.setAction(actionList);
1137 // Wrap our Apply Action in an Instruction
1138 InstructionBuilder ib = new InstructionBuilder();
1139 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1141 // Put our Instruction in a list of Instructions
1142 InstructionsBuilder isb = new InstructionsBuilder();
1143 List<Instruction> instructions = new ArrayList<Instruction>();
1144 instructions.add(ib.build());
1145 isb.setInstruction(instructions);
1149 private static InstructionsBuilder createAppyActionInstruction28() {
1151 List<Action> actionList = new ArrayList<Action>();
1152 ActionBuilder ab = new ActionBuilder();
1154 SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
1155 setNwTosActionBuilder.setTos(8);
1156 ab.setAction(new SetNwTosActionCaseBuilder().setSetNwTosAction(setNwTosActionBuilder.build()).build());
1157 actionList.add(ab.build());
1158 // Create an Apply Action
1159 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1160 aab.setAction(actionList);
1162 // Wrap our Apply Action in an Instruction
1163 InstructionBuilder ib = new InstructionBuilder();
1164 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1166 // Put our Instruction in a list of Instructions
1167 InstructionsBuilder isb = new InstructionsBuilder();
1168 List<Instruction> instructions = new ArrayList<Instruction>();
1169 instructions.add(ib.build());
1170 isb.setInstruction(instructions);
1174 private static InstructionsBuilder createAppyActionInstruction34() {
1176 List<Action> actionList = new ArrayList<Action>();
1177 ActionBuilder ab = new ActionBuilder();
1179 SwPathActionBuilder swPathAction = new SwPathActionBuilder();
1180 ab.setAction(new SwPathActionCaseBuilder().setSwPathAction(swPathAction.build()).build());
1181 actionList.add(ab.build());
1183 // Create an Apply Action
1184 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1185 aab.setAction(actionList);
1187 // Wrap our Apply Action in an Instruction
1188 InstructionBuilder ib = new InstructionBuilder();
1189 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1191 // Put our Instruction in a list of Instructions
1192 InstructionsBuilder isb = new InstructionsBuilder();
1193 List<Instruction> instructions = new ArrayList<Instruction>();
1194 instructions.add(ib.build());
1195 isb.setInstruction(instructions);
1199 private static MatchBuilder createLLDPMatch() {
1200 MatchBuilder match = new MatchBuilder();
1201 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1202 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1203 ethTypeBuilder.setType(new EtherType(0x88ccL));
1204 eth.setEthernetType(ethTypeBuilder.build());
1205 match.setEthernetMatch(eth.build());
1212 private static MatchBuilder createMatch1() {
1213 MatchBuilder match = new MatchBuilder();
1214 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1215 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
1216 ipv4Match.setIpv4Destination(prefix);
1217 Ipv4Match i4m = ipv4Match.build();
1218 match.setLayer3Match(i4m);
1220 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1221 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1222 ethTypeBuilder.setType(new EtherType(0x0800L));
1223 eth.setEthernetType(ethTypeBuilder.build());
1224 match.setEthernetMatch(eth.build());
1228 private static MatchBuilder createMatch1000() {
1229 MatchBuilder match = new MatchBuilder();
1230 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1231 Ipv4Prefix prefix = new Ipv4Prefix("10.1.1.1/24");
1232 ipv4Match.setIpv4Destination(prefix);
1233 Ipv4Match i4m = ipv4Match.build();
1234 match.setLayer3Match(i4m);
1236 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1237 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1238 ethTypeBuilder.setType(new EtherType(0x0800L));
1239 eth.setEthernetType(ethTypeBuilder.build());
1240 match.setEthernetMatch(eth.build());
1247 private static MatchBuilder createMatch2() {
1248 MatchBuilder match = new MatchBuilder();
1249 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1250 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1");
1251 ipv4Match.setIpv4Source(prefix);
1252 Ipv4Match i4m = ipv4Match.build();
1253 match.setLayer3Match(i4m);
1255 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1256 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1257 ethTypeBuilder.setType(new EtherType(0x0800L));
1258 eth.setEthernetType(ethTypeBuilder.build());
1259 match.setEthernetMatch(eth.build());
1266 private static MatchBuilder createMatch3() {
1267 MatchBuilder match = new MatchBuilder();
1268 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
1269 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
1270 ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
1271 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
1272 match.setEthernetMatch(ethernetMatch.build());
1277 private static MatchBuilder createMatch33() {
1279 MatchBuilder match = new MatchBuilder();
1280 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1281 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.10");
1282 ipv4Match.setIpv4Source(prefix);
1283 Ipv4Match i4m = ipv4Match.build();
1284 match.setLayer3Match(i4m);
1286 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1287 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1288 ethTypeBuilder.setType(new EtherType(0xfffeL));
1289 eth.setEthernetType(ethTypeBuilder.build());
1290 match.setEthernetMatch(eth.build());
1294 private static MatchBuilder createInphyportMatch(NodeId nodeId) {
1295 MatchBuilder match = new MatchBuilder();
1296 match.setInPort(new NodeConnectorId(nodeId + ":202"));
1297 match.setInPhyPort(new NodeConnectorId(nodeId + ":10122"));
1301 private static MatchBuilder createEthernetMatch() {
1302 MatchBuilder match = new MatchBuilder();
1304 byte[] mask1 = new byte[]{(byte) -1, (byte) -1, 0, 0, 0, 0};
1305 byte[] mask2 = new byte[]{(byte) -1, (byte) -1, (byte) -1, 0, 0, 0};
1307 EthernetMatchBuilder ethmatch = new EthernetMatchBuilder(); // ethernettype
1309 EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
1310 EtherType type = new EtherType(0x0800L);
1311 ethmatch.setEthernetType(ethtype.setType(type).build());
1313 EthernetDestinationBuilder ethdest = new EthernetDestinationBuilder(); // ethernet
1316 MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
1317 ethdest.setAddress(macdest);
1318 // ethdest.setMask(mask1);
1320 ethmatch.setEthernetDestination(ethdest.build());
1322 EthernetSourceBuilder ethsrc = new EthernetSourceBuilder();
1323 MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
1324 ethsrc.setAddress(macsrc);
1325 // ethsrc.setMask(mask2);
1327 ethmatch.setEthernetSource(ethsrc.build());
1328 match.setEthernetMatch(ethmatch.build());
1336 private static MatchBuilder createL3IPv6Match() {
1337 MatchBuilder match = new MatchBuilder();
1339 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1340 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1341 ethTypeBuilder.setType(new EtherType(0x86ddL));
1342 eth.setEthernetType(ethTypeBuilder.build());
1343 match.setEthernetMatch(eth.build());
1345 Ipv6Prefix dstip6 = new Ipv6Prefix("2002::2/64");
1346 Ipv6Prefix srcip6 = new Ipv6Prefix("2001:0:0:0:0:0:0:1/56");
1347 Ipv6Address ndtarget = new Ipv6Address("2001:db8:0:1:fd97:f9f0:a810:782e");
1348 MacAddress ndsll = new MacAddress("c2:00:54:f5:00:00");
1349 MacAddress ndtll = new MacAddress("00:0c:29:0e:4c:67");
1350 Ipv6ExtHeaderBuilder nextheader = new Ipv6ExtHeaderBuilder();
1351 nextheader.setIpv6Exthdr(58);
1352 Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
1353 Ipv6FlowLabel label = new Ipv6FlowLabel(10028L);
1354 ipv6label.setIpv6Flabel(label);
1355 // ipv6label.setFlabelMask(new byte[] { 0, 1, -1, -1 });
1357 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1359 icmpv6match.setIcmpv6Type((short) 135);
1360 icmpv6match.setIcmpv6Code((short) 0);
1361 match.setIcmpv6Match(icmpv6match.build());
1363 Ipv6MatchBuilder ipv6match = new Ipv6MatchBuilder();
1364 // ipv6match.setIpv6Source(srcip6);
1365 // ipv6match.setIpv6Destination(dstip6);
1366 // ipv6match.setIpv6ExtHeader(nextheader.build());
1367 ipv6match.setIpv6NdSll(ndsll);
1368 ipv6match.setIpv6NdTll(ndtll);
1369 // ipv6match.setIpv6NdTarget(ndtarget);
1370 ipv6match.setIpv6Label(ipv6label.build());
1372 match.setLayer3Match(ipv6match.build());
1380 private static MatchBuilder createICMPv6Match() {
1382 MatchBuilder match = new MatchBuilder();
1383 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1384 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1385 ethTypeBuilder.setType(new EtherType(0x86ddL));
1386 eth.setEthernetType(ethTypeBuilder.build());
1387 match.setEthernetMatch(eth.build());
1389 IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
1390 ipmatch.setIpProtocol((short) 58);
1391 match.setIpMatch(ipmatch.build());
1393 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1395 icmpv6match.setIcmpv6Type((short) 135);
1396 icmpv6match.setIcmpv6Code((short) 1);
1397 match.setIcmpv6Match(icmpv6match.build());
1405 private static MatchBuilder createMetadataMatch() {
1406 MatchBuilder match = new MatchBuilder();
1407 byte[] metamask = new byte[]{(byte) -1, (byte) -1, (byte) -1, 0, 0, 0, (byte) 1, (byte) 1};
1408 MetadataBuilder metadata = new MetadataBuilder(); // metadata match
1409 metadata.setMetadata(BigInteger.valueOf(500L));
1410 // metadata.setMetadataMask(metamask);
1411 match.setMetadata(metadata.build());