2 * Copyright (c) 2014, 2015 Ericsson, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.test;
10 import com.google.common.util.concurrent.FutureCallback;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.osgi.framework.console.CommandInterpreter;
14 import org.eclipse.osgi.framework.console.CommandProvider;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
17 import org.opendaylight.mdsal.common.api.CommitInfo;
18 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.all.action._case.FloodAllActionBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.sw.path.action._case.SwPathActionBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
95 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
96 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
97 import org.opendaylight.yangtools.yang.common.Uint16;
98 import org.opendaylight.yangtools.yang.common.Uint32;
99 import org.opendaylight.yangtools.yang.common.Uint64;
100 import org.opendaylight.yangtools.yang.common.Uint8;
101 import org.osgi.framework.BundleContext;
102 import org.slf4j.Logger;
103 import org.slf4j.LoggerFactory;
105 public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
106 private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginBulkTransactionProvider.class);
108 private final DataBroker dataBroker;
109 private final BundleContext ctx;
110 private final String originalFlowName = "Foo";
112 public OpenflowPluginBulkTransactionProvider(final DataBroker dataBroker, final BundleContext ctx) {
113 this.dataBroker = dataBroker;
118 ctx.registerService(CommandProvider.class.getName(), this, null);
119 createTestFlow(createTestNode(null), null, null);
122 private static NodeBuilder createTestNode(String nodeId) {
123 if (nodeId == null) {
124 nodeId = OpenflowpluginTestActivator.NODE_ID;
126 return new NodeBuilder().setId(new NodeId(nodeId));
130 public String getHelp() {
134 private FlowBuilder createTestFlow(final NodeBuilder nodeBuilder, final String flowTypeArg, final String tableId) {
136 FlowBuilder flow = new FlowBuilder();
139 String flowType = flowTypeArg;
140 if (flowType == null) {
147 flow.setMatch(createMatch1().build());
148 flow.setInstructions(createDecNwTtlInstructions().build());
152 flow.setMatch(createMatch2().build());
153 flow.setInstructions(createDropInstructions().build());
157 flow.setMatch(createMatch3().build());
158 flow.setInstructions(createDropInstructions().build());
162 flow.setMatch(createEthernetMatch().build());
163 flow.setInstructions(createDropInstructions().build());
167 flow.setMatch(createMatch1().build());
168 flow.setInstructions(createAppyActionInstruction().build());
172 flow.setMatch(createMatch1().build());
173 flow.setInstructions(createGotoTableInstructions().build());
177 flow.setMatch(createMatch1().build());
178 flow.setInstructions(createMeterInstructions().build());
182 flow.setMatch(createMatch1().build());
183 flow.setInstructions(createAppyActionInstruction7().build());
187 flow.setMatch(createMatch1().build());
188 flow.setInstructions(createAppyActionInstruction2().build());
192 flow.setMatch(createMatch1().build());
193 flow.setInstructions(createAppyActionInstruction3().build());
197 flow.setMatch(createMatch1().build());
198 flow.setInstructions(createAppyActionInstruction16().build());
202 flow.setMatch(createMatch1().build());
203 flow.setInstructions(createAppyActionInstruction160().build());
207 flow.setMatch(createMatch1().build());
208 flow.setInstructions(createAppyActionInstruction26().build());
212 flow.setMatch(createMatch1().build());
213 flow.setInstructions(createAppyActionInstruction27().build());
217 flow.setMatch(createMatch1().build());
218 flow.setInstructions(createAppyActionInstruction28().build());
222 flow.setMatch(createMatch1().build());
223 flow.setInstructions(createAppyActionInstruction34().build());
227 flow.setMatch(createICMPv6Match().build());
228 flow.setInstructions(createDecNwTtlInstructions().build());
232 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
233 flow.setInstructions(createDropInstructions().build());
237 flow.setMatch(createMetadataMatch().build());
238 flow.setInstructions(createDropInstructions().build());
242 flow.setMatch(createL3IPv6Match().build());
243 flow.setInstructions(createDecNwTtlInstructions().build());
247 flow.setMatch(createLLDPMatch().build());
248 flow.setInstructions(createSentToControllerInstructions().build());
253 flow.setMatch(createMatch1().build());
254 flow.setInstructions(createDropInstructions().build());
258 flow.setMatch(createMatch2().build());
259 flow.setInstructions(createDecNwTtlInstructions().build());
263 flow.setMatch(createMatch3().build());
264 flow.setInstructions(createDecNwTtlInstructions().build());
268 flow.setMatch(createEthernetMatch().build());
269 flow.setInstructions(createMeterInstructions().build());
273 flow.setMatch(createMatch1().build());
274 flow.setInstructions(createDecNwTtlInstructions().build());
278 flow.setMatch(createMatch1().build());
279 flow.setInstructions(createAppyActionInstruction7().build());
283 flow.setMatch(createEthernetMatch().build());
284 flow.setInstructions(createAppyActionInstruction6().build());
288 flow.setMatch(createEthernetMatch().build());
289 flow.setInstructions(createAppyActionInstruction7().build());
293 flow.setMatch(createMatch1().build());
294 flow.setInstructions(createAppyActionInstruction9().build());
298 flow.setMatch(createMatch1().build());
299 flow.setInstructions(createAppyActionInstruction9().build());
303 flow.setMatch(createMatch1().build());
304 flow.setInstructions(createAppyActionInstruction6().build());
308 flow.setMatch(createMatch1().build());
309 flow.setInstructions(createDecNwTtlInstructions().build());
313 flow.setMatch(createMatch1().build());
314 flow.setInstructions(createDecNwTtlInstructions().build());
318 flow.setMatch(createMatch1().build());
319 flow.setInstructions(createDecNwTtlInstructions().build());
323 flow.setMatch(createICMPv6Match().build());
324 flow.setInstructions(createDropInstructions().build());
328 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
329 flow.setInstructions(createMeterInstructions().build());
333 flow.setMatch(createMetadataMatch().build());
334 flow.setInstructions(createAppyActionInstruction6().build());
338 flow.setMatch(createMatch1().build());
339 flow.setInstructions(createAppyActionInstruction6().build());
343 flow.setMatch(createMatch1().build());
344 flow.setInstructions(createAppyActionInstruction7().build());
348 flow.setMatch(createMatch1().build());
349 flow.setInstructions(createAppyActionInstruction8().build());
353 flow.setMatch(createMatch3().build());
354 flow.setInstructions(createMeterInstructions().build());
358 flow.setMatch(createMatch1000().build());
359 flow.setInstructions(createAppyActionInstruction6().build());
363 flow.setMatch(createMatch1000().build());
364 flow.setInstructions(createAppyActionInstruction2().build());
368 flow.setMatch(createMatch1000().build());
369 flow.setInstructions(createAppyActionInstruction3().build());
372 LOG.warn("flow type not understood: {}", flowType);
375 if (null == flow.getBarrier()) {
376 flow.setBarrier(Boolean.FALSE);
378 // flow.setBufferId(12L);
379 flow.setCookie(new FlowCookie(Uint64.TEN));
380 flow.setCookieMask(new FlowCookie(Uint64.TEN));
381 flow.setHardTimeout(Uint16.ZERO);
382 flow.setIdleTimeout(Uint16.ZERO);
383 flow.setInstallHw(false);
384 flow.setStrict(false);
385 flow.setContainerName(null);
386 flow.setFlags(new FlowModFlags(false, false, false, false, true));
387 flow.setId(new FlowId("12"));
388 flow.setTableId(getTableId(tableId));
389 flow.setOutGroup(Uint32.MAX_VALUE);
390 // set outport to OFPP_NONE (65535) to disable remove restriction for
392 flow.setOutPort(Uint64.valueOf(4294967295L));
394 FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
396 flow.setPriority(Uint16.TWO);
397 flow.setFlowName(originalFlowName + "X" + flowType);
401 private static Uint8 getTableId(final String tableId) {
402 if (tableId != null) {
404 return Uint8.valueOf(tableId);
405 } catch (IllegalArgumentException ex) {
406 // ignore exception and continue with default value
412 @SuppressWarnings("checkstyle:MethodName")
413 public void _addFlows(final CommandInterpreter ci) {
414 NodeBuilder tn = createTestNode(ci.nextArgument());
415 String flowtype = ci.nextArgument();
416 Integer flowcnt = Integer.parseInt(flowtype);
423 tf = createTestFlow(tn, "f1", "10");
424 tf1 = createTestFlow(tn, "f2", "11");
425 tf2 = createTestFlow(tn, "f3", "12");
426 tf3 = createTestFlow(tn, "f4", "13");
429 tf = createTestFlow(tn, "f3", "3");
430 tf1 = createTestFlow(tn, "f4", "4");
431 tf2 = createTestFlow(tn, "f5", "5");
432 tf3 = createTestFlow(tn, "f6", "6");
435 tf = createTestFlow(tn, "f7", "7");
436 tf1 = createTestFlow(tn, "f8", "8");
437 tf2 = createTestFlow(tn, "f9", "9");
438 tf3 = createTestFlow(tn, "f10", "10");
442 tf = createTestFlow(tn, "f23", "3");
443 tf1 = createTestFlow(tn, "f34", "4");
444 tf2 = createTestFlow(tn, "f35", "5");
445 tf3 = createTestFlow(tn, "f36", "6");
450 tf = createTestFlow(tn, "f230", "3");
451 tf1 = createTestFlow(tn, "f34", "4");
452 tf2 = createTestFlow(tn, "f35", "5");
453 tf3 = createTestFlow(tn, "f36", "6");
457 tf = createTestFlow(tn, "f42", "42");
458 tf1 = createTestFlow(tn, "f43", "43");
459 tf2 = createTestFlow(tn, "f44", "44");
460 tf3 = createTestFlow(tn, "f45", "45");
463 writeFlow(ci, tf, tf1, tf2, tf3, tn);
466 private static @NonNull InstanceIdentifier<Node> nodeBuilderToInstanceId(final NodeBuilder node) {
467 return InstanceIdentifier.create(Nodes.class).child(Node.class, node.key());
470 @SuppressWarnings("checkstyle:MethodName")
471 public void _modifyFlows(final CommandInterpreter ci) {
472 NodeBuilder tn = createTestNode(ci.nextArgument());
473 String flowtype = ci.nextArgument();
474 Integer flowcnt = Integer.parseInt(flowtype);
481 tf = createTestFlow(tn, "f82", "10");
482 tf1 = createTestFlow(tn, "f83", "11");
483 tf2 = createTestFlow(tn, "f84", "12");
484 tf3 = createTestFlow(tn, "f85", "13");
487 tf = createTestFlow(tn, "f700", "3");
488 tf1 = createTestFlow(tn, "f4", "4");
489 tf2 = createTestFlow(tn, "f900", "5");
490 tf3 = createTestFlow(tn, "f86", "6");
494 tf = createTestFlow(tn, "f91", "7");
495 tf1 = createTestFlow(tn, "f92", "8");
496 tf2 = createTestFlow(tn, "f93", "9");
497 tf3 = createTestFlow(tn, "f94", "10");
501 tf = createTestFlow(tn, "f230", "3");
502 tf1 = createTestFlow(tn, "f99", "4");
503 tf2 = createTestFlow(tn, "f100", "5");
504 tf3 = createTestFlow(tn, "f101", "6");
508 tf = createTestFlow(tn, "f23", "3");
509 tf1 = createTestFlow(tn, "f99", "4");
510 tf2 = createTestFlow(tn, "f100", "5");
511 tf3 = createTestFlow(tn, "f101", "6");
515 tf = createTestFlow(tn, "f87", "12");
516 tf1 = createTestFlow(tn, "f88", "13");
517 tf2 = createTestFlow(tn, "f89", "14");
518 tf3 = createTestFlow(tn, "f90", "15");
522 writeFlow(ci, tf, tf1, tf2, tf3, tn);
525 @SuppressWarnings("checkstyle:MethodName")
526 public void _removeFlows(final CommandInterpreter ci) {
527 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
528 NodeBuilder tn = createTestNode(ci.nextArgument());
529 String flowtype = ci.nextArgument();
530 Integer flowcnt = Integer.parseInt(flowtype);
531 FlowBuilder tf = null;
532 FlowBuilder tf1 = null;
533 FlowBuilder tf2 = null;
534 FlowBuilder tf3 = null;
538 tf = createTestFlow(tn, "f1", "10");
539 tf1 = createTestFlow(tn, "f2", "11");
540 tf2 = createTestFlow(tn, "f3", "12");
541 tf3 = createTestFlow(tn, "f4", "13");
545 tf = createTestFlow(tn, "f82", "10");
546 tf1 = createTestFlow(tn, "f83", "11");
547 tf2 = createTestFlow(tn, "f84", "12");
548 tf3 = createTestFlow(tn, "f85", "13");
552 tf = createTestFlow(tn, "f3", "3");
553 tf1 = createTestFlow(tn, "f4", "4");
554 tf2 = createTestFlow(tn, "f5", "5");
555 tf3 = createTestFlow(tn, "f6", "6");
559 tf = createTestFlow(tn, "f700", "3");
560 tf1 = createTestFlow(tn, "f4", "4");
561 tf2 = createTestFlow(tn, "f900", "5");
562 tf3 = createTestFlow(tn, "f86", "6");
566 tf = createTestFlow(tn, "f7", "7");
567 tf1 = createTestFlow(tn, "f8", "8");
568 tf2 = createTestFlow(tn, "f9", "9");
569 tf3 = createTestFlow(tn, "f10", "10");
573 tf = createTestFlow(tn, "f91", "7");
574 tf1 = createTestFlow(tn, "f92", "8");
575 tf2 = createTestFlow(tn, "f93", "9");
576 tf3 = createTestFlow(tn, "f94", "10");
580 tf = createTestFlow(tn, "f23", "3");
581 tf1 = createTestFlow(tn, "f34", "4");
582 tf2 = createTestFlow(tn, "f35", "5");
583 tf3 = createTestFlow(tn, "f36", "6");
588 tf = createTestFlow(tn, "f23", "3");
589 tf1 = createTestFlow(tn, "f99", "4");
590 tf2 = createTestFlow(tn, "f100", "5");
591 tf3 = createTestFlow(tn, "f101", "6");
595 tf = createTestFlow(tn, "f700", "7");
596 tf1 = createTestFlow(tn, "f230", "23");
597 tf2 = createTestFlow(tn, "f900", "9");
598 tf3 = createTestFlow(tn, "f1000", "10");
601 throw new IllegalArgumentException("Invalid flowtype: " + flowtype);
604 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
605 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
606 .child(Flow.class, tf.key());
607 modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
608 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
609 modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
610 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
611 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf1.getTableId()))
612 .child(Flow.class, tf1.key());
613 modification.delete(LogicalDatastoreType.OPERATIONAL, path2);
614 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
615 modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
617 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
618 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf2.getTableId()))
619 .child(Flow.class, tf2.key());
620 modification.delete(LogicalDatastoreType.OPERATIONAL, path3);
621 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
622 modification.delete(LogicalDatastoreType.CONFIGURATION, path3);
623 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
624 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf3.getTableId()))
625 .child(Flow.class, tf3.key());
626 modification.delete(LogicalDatastoreType.OPERATIONAL, path4);
627 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
628 modification.delete(LogicalDatastoreType.CONFIGURATION, path4);
629 modification.commit().addCallback(new FutureCallback<CommitInfo>() {
631 public void onSuccess(final CommitInfo notUsed) {
632 ci.println("Status of Group Data Loaded Transaction: success.");
636 public void onFailure(final Throwable throwable) {
637 LOG.error("Status of Group Data Loaded Transaction : failure.", throwable);
638 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
640 }, MoreExecutors.directExecutor());
644 private void writeFlow(final CommandInterpreter ci, final FlowBuilder flow, final FlowBuilder flow1,
645 final FlowBuilder flow2, final FlowBuilder flow3, final NodeBuilder nodeBuilder) {
646 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
647 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class)
648 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
649 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.key());
650 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder),
651 nodeBuilder.build());
652 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path1, flow.build());
653 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
654 nodeBuilder.build());
655 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path1, flow.build());
656 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class)
657 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
658 .child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.key());
659 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder),
660 nodeBuilder.build());
661 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path2, flow1.build());
662 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
663 nodeBuilder.build());
664 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path2, flow1.build());
666 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class)
667 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
668 .child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.key());
669 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder),
670 nodeBuilder.build());
671 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path3, flow2.build());
672 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
673 nodeBuilder.build());
674 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path3, flow2.build());
676 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class)
677 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
678 .child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.key());
679 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder),
680 nodeBuilder.build());
681 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path4, flow3.build());
682 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
683 nodeBuilder.build());
684 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path4, flow3.build());
685 modification.commit().addCallback(new FutureCallback<CommitInfo>() {
687 public void onSuccess(final CommitInfo notUsed) {
688 ci.println("Status of Group Data Loaded Transaction: success.");
692 public void onFailure(final Throwable throwable) {
693 LOG.error("Status of Group Data Loaded Transaction : failure.", throwable);
694 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
696 }, MoreExecutors.directExecutor());
699 private static InstructionsBuilder createDecNwTtlInstructions() {
700 return new InstructionsBuilder()
701 .setInstruction(BindingMap.of(new InstructionBuilder()
703 .setInstruction(new ApplyActionsCaseBuilder()
704 .setApplyActions(new ApplyActionsBuilder()
705 .setAction(BindingMap.of(new ActionBuilder()
706 .setAction(new DecNwTtlCaseBuilder().setDecNwTtl(new DecNwTtlBuilder().build()).build())
713 private static InstructionsBuilder createMeterInstructions() {
714 return new InstructionsBuilder()
715 .setInstruction(BindingMap.of(new InstructionBuilder()
717 .setInstruction(new MeterCaseBuilder()
718 .setMeter(new MeterBuilder().setMeterId(new MeterId(Uint32.ONE)).build())
723 private static InstructionsBuilder createGotoTableInstructions() {
724 return new InstructionsBuilder()
725 .setInstruction(BindingMap.of(new InstructionBuilder()
727 .setInstruction(new GoToTableCaseBuilder()
728 .setGoToTable(new GoToTableBuilder().setTableId(Uint8.TWO).build())
733 private static InstructionsBuilder createDropInstructions() {
734 return new InstructionsBuilder()
735 .setInstruction(BindingMap.of(new InstructionBuilder()
737 .setInstruction(new ApplyActionsCaseBuilder()
738 .setApplyActions(new ApplyActionsBuilder()
739 .setAction(BindingMap.of(new ActionBuilder()
740 .setAction(new DropActionCaseBuilder()
741 .setDropAction(new DropActionBuilder().build())
749 private static InstructionsBuilder createAppyActionInstruction() {
750 return new InstructionsBuilder()
751 .setInstruction(BindingMap.of(new InstructionBuilder()
753 .setInstruction(new ApplyActionsCaseBuilder()
754 .setApplyActions(new ApplyActionsBuilder()
755 .setAction(BindingMap.of(new ActionBuilder()
756 .setAction(new ControllerActionCaseBuilder()
757 .setControllerAction(new ControllerActionBuilder()
758 .setMaxLength(Uint16.valueOf(5))
767 private static InstructionsBuilder createSentToControllerInstructions() {
768 return new InstructionsBuilder()
769 .setInstruction(BindingMap.of(new InstructionBuilder()
771 .setInstruction(new ApplyActionsCaseBuilder()
772 .setApplyActions(new ApplyActionsBuilder()
773 .setAction(BindingMap.of(new ActionBuilder()
775 .setAction(new OutputActionCaseBuilder()
776 .setOutputAction(new OutputActionBuilder()
777 .setMaxLength(Uint16.MAX_VALUE)
778 .setOutputNodeConnector(new Uri(OutputPortValues.CONTROLLER.toString()))
787 private static InstructionsBuilder createAppyActionInstruction2() {
788 return new InstructionsBuilder()
789 .setInstruction(BindingMap.of(new InstructionBuilder()
791 .setInstruction(new ApplyActionsCaseBuilder()
792 .setApplyActions(new ApplyActionsBuilder()
793 .setAction(BindingMap.of(new ActionBuilder()
794 .setAction(new PushMplsActionCaseBuilder()
795 .setPushMplsAction(new PushMplsActionBuilder()
796 .setEthernetType(Uint16.valueOf(0x8847))
805 private static InstructionsBuilder createAppyActionInstruction3() {
806 return new InstructionsBuilder()
807 .setInstruction(BindingMap.of(new InstructionBuilder()
809 .setInstruction(new ApplyActionsCaseBuilder()
810 .setApplyActions(new ApplyActionsBuilder()
811 .setAction(BindingMap.of(new ActionBuilder()
812 .setAction(new PushPbbActionCaseBuilder()
813 .setPushPbbAction(new PushPbbActionBuilder()
814 .setEthernetType(Uint16.valueOf(0x88E7))
823 private static InstructionsBuilder createAppyActionInstruction6() {
824 return new InstructionsBuilder()
825 .setInstruction(BindingMap.of(new InstructionBuilder()
827 .setInstruction(new ApplyActionsCaseBuilder()
828 .setApplyActions(new ApplyActionsBuilder()
829 .setAction(BindingMap.of(new ActionBuilder()
830 .setAction(new SetDlSrcActionCaseBuilder()
831 .setSetDlSrcAction(new SetDlSrcActionBuilder()
832 .setAddress(new MacAddress("00:05:b9:7c:81:5f"))
841 private static InstructionsBuilder createAppyActionInstruction7() {
842 return new InstructionsBuilder()
843 .setInstruction(BindingMap.of(new InstructionBuilder()
845 .setInstruction(new ApplyActionsCaseBuilder()
846 .setApplyActions(new ApplyActionsBuilder()
847 .setAction(BindingMap.of(new ActionBuilder()
848 .setAction(new SetVlanIdActionCaseBuilder()
849 .setSetVlanIdAction(new SetVlanIdActionBuilder()
850 .setVlanId(new VlanId(Uint16.valueOf(4012)))
859 private static InstructionsBuilder createAppyActionInstruction8() {
860 return new InstructionsBuilder()
861 .setInstruction(BindingMap.of(new InstructionBuilder()
863 .setInstruction(new ApplyActionsCaseBuilder()
864 .setApplyActions(new ApplyActionsBuilder()
865 .setAction(BindingMap.of(new ActionBuilder()
866 .setAction(new SetVlanPcpActionCaseBuilder()
867 .setSetVlanPcpAction(new SetVlanPcpActionBuilder()
868 .setVlanPcp(new VlanPcp(Uint8.TWO))
877 private static InstructionsBuilder createAppyActionInstruction9() {
878 return new InstructionsBuilder()
879 .setInstruction(BindingMap.of(new InstructionBuilder()
881 .setInstruction(new ApplyActionsCaseBuilder()
882 .setApplyActions(new ApplyActionsBuilder()
883 .setAction(BindingMap.of(new ActionBuilder()
884 .setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(new CopyTtlInBuilder().build()).build())
891 private static InstructionsBuilder createAppyActionInstruction16() {
892 return new InstructionsBuilder()
893 .setInstruction(BindingMap.of(new InstructionBuilder()
895 .setInstruction(new ApplyActionsCaseBuilder()
896 .setApplyActions(new ApplyActionsBuilder()
897 .setAction(BindingMap.of(new ActionBuilder()
898 .setAction(new GroupActionCaseBuilder()
899 .setGroupAction(new GroupActionBuilder().setGroupId(Uint32.ONE).setGroup("0").build())
907 private static InstructionsBuilder createAppyActionInstruction160() {
908 return new InstructionsBuilder()
909 .setInstruction(BindingMap.of(new InstructionBuilder()
911 .setInstruction(new ApplyActionsCaseBuilder()
912 .setApplyActions(new ApplyActionsBuilder()
913 .setAction(BindingMap.of(new ActionBuilder()
914 .setAction(new FloodAllActionCaseBuilder()
915 .setFloodAllAction(new FloodAllActionBuilder().build())
923 private static InstructionsBuilder createAppyActionInstruction26() {
924 return new InstructionsBuilder()
925 .setInstruction(BindingMap.of(new InstructionBuilder()
927 .setInstruction(new ApplyActionsCaseBuilder()
928 .setApplyActions(new ApplyActionsBuilder()
929 .setAction(BindingMap.of(new ActionBuilder()
930 .setAction(new SetNwDstActionCaseBuilder()
931 .setSetNwDstAction(new SetNwDstActionBuilder()
932 .setAddress(new Ipv4Builder()
933 .setIpv4Address(new Ipv4Prefix("10.0.0.21/24"))
943 private static InstructionsBuilder createAppyActionInstruction27() {
944 return new InstructionsBuilder()
945 .setInstruction(BindingMap.of(new InstructionBuilder()
947 .setInstruction(new ApplyActionsCaseBuilder()
948 .setApplyActions(new ApplyActionsBuilder()
949 .setAction(BindingMap.of(new ActionBuilder()
950 .setAction(new SetNwSrcActionCaseBuilder()
951 .setSetNwSrcAction(new SetNwSrcActionBuilder()
952 .setAddress(new Ipv4Builder()
953 .setIpv4Address(new Ipv4Prefix("10.0.23.21/24"))
963 private static InstructionsBuilder createAppyActionInstruction28() {
964 return new InstructionsBuilder()
965 .setInstruction(BindingMap.of(new InstructionBuilder()
967 .setInstruction(new ApplyActionsCaseBuilder()
968 .setApplyActions(new ApplyActionsBuilder()
969 .setAction(BindingMap.of(new ActionBuilder()
970 .setAction(new SetNwTosActionCaseBuilder()
971 .setSetNwTosAction(new SetNwTosActionBuilder().setTos(8).build())
979 private static InstructionsBuilder createAppyActionInstruction34() {
980 return new InstructionsBuilder()
981 .setInstruction(BindingMap.of(new InstructionBuilder()
983 .setInstruction(new ApplyActionsCaseBuilder()
984 .setApplyActions(new ApplyActionsBuilder()
985 .setAction(BindingMap.of(new ActionBuilder()
986 .setAction(new SwPathActionCaseBuilder()
987 .setSwPathAction(new SwPathActionBuilder().build())
995 private static MatchBuilder createLLDPMatch() {
996 return new MatchBuilder()
997 .setEthernetMatch(new EthernetMatchBuilder()
998 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x88cc))).build())
1002 private static MatchBuilder createMatch1() {
1003 return new MatchBuilder()
1004 .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix("10.0.0.1/24")).build())
1005 .setEthernetMatch(new EthernetMatchBuilder()
1006 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x0800))).build())
1010 private static MatchBuilder createMatch1000() {
1011 return new MatchBuilder()
1012 .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix("10.1.1.1/24")).build())
1013 .setEthernetMatch(new EthernetMatchBuilder()
1014 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x0800))).build())
1018 private static MatchBuilder createMatch2() {
1019 return new MatchBuilder()
1020 .setLayer3Match(new Ipv4MatchBuilder().setIpv4Source(new Ipv4Prefix("10.0.0.1")).build())
1021 .setEthernetMatch(new EthernetMatchBuilder()
1022 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x0800))).build())
1026 private static MatchBuilder createMatch3() {
1027 return new MatchBuilder()
1028 .setEthernetMatch(new EthernetMatchBuilder()
1029 .setEthernetSource(new EthernetSourceBuilder().setAddress(new MacAddress("00:00:00:00:00:01")).build())
1033 private static MatchBuilder createInphyportMatch(final NodeId nodeId) {
1034 return new MatchBuilder()
1035 .setInPort(new NodeConnectorId(nodeId + ":202"))
1036 .setInPhyPort(new NodeConnectorId(nodeId + ":10122"));
1039 private static MatchBuilder createEthernetMatch() {
1040 return new MatchBuilder()
1041 .setEthernetMatch(new EthernetMatchBuilder()
1042 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x0800))).build())
1043 .setEthernetDestination(new EthernetDestinationBuilder()
1044 .setAddress(new MacAddress("ff:ff:ff:ff:ff:ff"))
1047 .setEthernetSource(new EthernetSourceBuilder()
1048 .setAddress(new MacAddress("00:00:00:00:23:ae"))
1054 private static MatchBuilder createL3IPv6Match() {
1055 return new MatchBuilder()
1056 .setEthernetMatch(new EthernetMatchBuilder()
1057 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x86dd))).build())
1060 .setIcmpv6Match(new Icmpv6MatchBuilder()
1061 .setIcmpv6Type(Uint8.valueOf(135))
1062 .setIcmpv6Code(Uint8.ZERO)
1064 .setLayer3Match(new Ipv6MatchBuilder()
1065 // .setIpv6Source(srcip6)
1066 // .setIpv6Destination(dstip6)
1067 // .setIpv6ExtHeader(nextheader.build())
1068 .setIpv6NdSll(new MacAddress("c2:00:54:f5:00:00"))
1069 .setIpv6NdTll(new MacAddress("00:0c:29:0e:4c:67"))
1070 // .setIpv6NdTarget(ndtarget)
1071 .setIpv6Label(new Ipv6LabelBuilder()
1072 .setIpv6Flabel(new Ipv6FlowLabel(Uint32.valueOf(10028)))
1073 // .setFlabelMask(new byte[] { 0, 1, -1, -1 })
1078 private static MatchBuilder createICMPv6Match() {
1079 return new MatchBuilder()
1080 .setEthernetMatch(new EthernetMatchBuilder()
1081 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x86dd))).build())
1084 .setIpMatch(new IpMatchBuilder().setIpProtocol(Uint8.valueOf(58)).build())
1086 .setIcmpv6Match(new Icmpv6MatchBuilder()
1087 .setIcmpv6Type(Uint8.valueOf(135))
1088 .setIcmpv6Code(Uint8.ONE)
1092 private static MatchBuilder createMetadataMatch() {
1093 return new MatchBuilder()
1094 .setMetadata(new MetadataBuilder()
1095 .setMetadata(Uint64.valueOf(500))
1096 // .setMetadataMask(metamask)