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.NotificationService;
17 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
18 import org.opendaylight.mdsal.common.api.CommitInfo;
19 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.all.action._case.FloodAllActionBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.sw.path.action._case.SwPathActionBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.node.error.service.rev140410.NodeErrorListener;
97 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
98 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
99 import org.opendaylight.yangtools.yang.common.Uint16;
100 import org.opendaylight.yangtools.yang.common.Uint32;
101 import org.opendaylight.yangtools.yang.common.Uint64;
102 import org.opendaylight.yangtools.yang.common.Uint8;
103 import org.osgi.framework.BundleContext;
104 import org.slf4j.Logger;
105 import org.slf4j.LoggerFactory;
107 public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
108 private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginBulkTransactionProvider.class);
110 private final DataBroker dataBroker;
111 private final BundleContext ctx;
112 private final String originalFlowName = "Foo";
113 private final NodeErrorListener nodeErrorListener = new NodeErrorListenerLoggingImpl();
114 private final NotificationService notificationService;
116 public OpenflowPluginBulkTransactionProvider(final DataBroker dataBroker,
117 final NotificationService notificationService, final BundleContext ctx) {
118 this.dataBroker = dataBroker;
119 this.notificationService = notificationService;
124 notificationService.registerNotificationListener(nodeErrorListener);
125 ctx.registerService(CommandProvider.class.getName(), this, null);
126 createTestFlow(createTestNode(null), null, null);
129 private static NodeBuilder createTestNode(String nodeId) {
130 if (nodeId == null) {
131 nodeId = OpenflowpluginTestActivator.NODE_ID;
133 return new NodeBuilder().setId(new NodeId(nodeId));
137 public String getHelp() {
141 private FlowBuilder createTestFlow(final NodeBuilder nodeBuilder, final String flowTypeArg, final String tableId) {
143 FlowBuilder flow = new FlowBuilder();
146 String flowType = flowTypeArg;
147 if (flowType == null) {
154 flow.setMatch(createMatch1().build());
155 flow.setInstructions(createDecNwTtlInstructions().build());
159 flow.setMatch(createMatch2().build());
160 flow.setInstructions(createDropInstructions().build());
164 flow.setMatch(createMatch3().build());
165 flow.setInstructions(createDropInstructions().build());
169 flow.setMatch(createEthernetMatch().build());
170 flow.setInstructions(createDropInstructions().build());
174 flow.setMatch(createMatch1().build());
175 flow.setInstructions(createAppyActionInstruction().build());
179 flow.setMatch(createMatch1().build());
180 flow.setInstructions(createGotoTableInstructions().build());
184 flow.setMatch(createMatch1().build());
185 flow.setInstructions(createMeterInstructions().build());
189 flow.setMatch(createMatch1().build());
190 flow.setInstructions(createAppyActionInstruction7().build());
194 flow.setMatch(createMatch1().build());
195 flow.setInstructions(createAppyActionInstruction2().build());
199 flow.setMatch(createMatch1().build());
200 flow.setInstructions(createAppyActionInstruction3().build());
204 flow.setMatch(createMatch1().build());
205 flow.setInstructions(createAppyActionInstruction16().build());
209 flow.setMatch(createMatch1().build());
210 flow.setInstructions(createAppyActionInstruction160().build());
214 flow.setMatch(createMatch1().build());
215 flow.setInstructions(createAppyActionInstruction26().build());
219 flow.setMatch(createMatch1().build());
220 flow.setInstructions(createAppyActionInstruction27().build());
224 flow.setMatch(createMatch1().build());
225 flow.setInstructions(createAppyActionInstruction28().build());
229 flow.setMatch(createMatch1().build());
230 flow.setInstructions(createAppyActionInstruction34().build());
234 flow.setMatch(createICMPv6Match().build());
235 flow.setInstructions(createDecNwTtlInstructions().build());
239 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
240 flow.setInstructions(createDropInstructions().build());
244 flow.setMatch(createMetadataMatch().build());
245 flow.setInstructions(createDropInstructions().build());
249 flow.setMatch(createL3IPv6Match().build());
250 flow.setInstructions(createDecNwTtlInstructions().build());
254 flow.setMatch(createLLDPMatch().build());
255 flow.setInstructions(createSentToControllerInstructions().build());
260 flow.setMatch(createMatch1().build());
261 flow.setInstructions(createDropInstructions().build());
265 flow.setMatch(createMatch2().build());
266 flow.setInstructions(createDecNwTtlInstructions().build());
270 flow.setMatch(createMatch3().build());
271 flow.setInstructions(createDecNwTtlInstructions().build());
275 flow.setMatch(createEthernetMatch().build());
276 flow.setInstructions(createMeterInstructions().build());
280 flow.setMatch(createMatch1().build());
281 flow.setInstructions(createDecNwTtlInstructions().build());
285 flow.setMatch(createMatch1().build());
286 flow.setInstructions(createAppyActionInstruction7().build());
290 flow.setMatch(createEthernetMatch().build());
291 flow.setInstructions(createAppyActionInstruction6().build());
295 flow.setMatch(createEthernetMatch().build());
296 flow.setInstructions(createAppyActionInstruction7().build());
300 flow.setMatch(createMatch1().build());
301 flow.setInstructions(createAppyActionInstruction9().build());
305 flow.setMatch(createMatch1().build());
306 flow.setInstructions(createAppyActionInstruction9().build());
310 flow.setMatch(createMatch1().build());
311 flow.setInstructions(createAppyActionInstruction6().build());
315 flow.setMatch(createMatch1().build());
316 flow.setInstructions(createDecNwTtlInstructions().build());
320 flow.setMatch(createMatch1().build());
321 flow.setInstructions(createDecNwTtlInstructions().build());
325 flow.setMatch(createMatch1().build());
326 flow.setInstructions(createDecNwTtlInstructions().build());
330 flow.setMatch(createICMPv6Match().build());
331 flow.setInstructions(createDropInstructions().build());
335 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
336 flow.setInstructions(createMeterInstructions().build());
340 flow.setMatch(createMetadataMatch().build());
341 flow.setInstructions(createAppyActionInstruction6().build());
345 flow.setMatch(createMatch1().build());
346 flow.setInstructions(createAppyActionInstruction6().build());
350 flow.setMatch(createMatch1().build());
351 flow.setInstructions(createAppyActionInstruction7().build());
355 flow.setMatch(createMatch1().build());
356 flow.setInstructions(createAppyActionInstruction8().build());
360 flow.setMatch(createMatch3().build());
361 flow.setInstructions(createMeterInstructions().build());
365 flow.setMatch(createMatch1000().build());
366 flow.setInstructions(createAppyActionInstruction6().build());
370 flow.setMatch(createMatch1000().build());
371 flow.setInstructions(createAppyActionInstruction2().build());
375 flow.setMatch(createMatch1000().build());
376 flow.setInstructions(createAppyActionInstruction3().build());
379 LOG.warn("flow type not understood: {}", flowType);
382 if (null == flow.getBarrier()) {
383 flow.setBarrier(Boolean.FALSE);
385 // flow.setBufferId(12L);
386 flow.setCookie(new FlowCookie(Uint64.TEN));
387 flow.setCookieMask(new FlowCookie(Uint64.TEN));
388 flow.setHardTimeout(Uint16.ZERO);
389 flow.setIdleTimeout(Uint16.ZERO);
390 flow.setInstallHw(false);
391 flow.setStrict(false);
392 flow.setContainerName(null);
393 flow.setFlags(new FlowModFlags(false, false, false, false, true));
394 flow.setId(new FlowId("12"));
395 flow.setTableId(getTableId(tableId));
396 flow.setOutGroup(Uint32.MAX_VALUE);
397 // set outport to OFPP_NONE (65535) to disable remove restriction for
399 flow.setOutPort(Uint64.valueOf(4294967295L));
401 FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
403 flow.setPriority(Uint16.TWO);
404 flow.setFlowName(originalFlowName + "X" + flowType);
408 private static Uint8 getTableId(final String tableId) {
409 if (tableId != null) {
411 return Uint8.valueOf(tableId);
412 } catch (IllegalArgumentException ex) {
413 // ignore exception and continue with default value
419 @SuppressWarnings("checkstyle:MethodName")
420 public void _addFlows(final CommandInterpreter ci) {
421 NodeBuilder tn = createTestNode(ci.nextArgument());
422 String flowtype = ci.nextArgument();
423 Integer flowcnt = Integer.parseInt(flowtype);
430 tf = createTestFlow(tn, "f1", "10");
431 tf1 = createTestFlow(tn, "f2", "11");
432 tf2 = createTestFlow(tn, "f3", "12");
433 tf3 = createTestFlow(tn, "f4", "13");
436 tf = createTestFlow(tn, "f3", "3");
437 tf1 = createTestFlow(tn, "f4", "4");
438 tf2 = createTestFlow(tn, "f5", "5");
439 tf3 = createTestFlow(tn, "f6", "6");
442 tf = createTestFlow(tn, "f7", "7");
443 tf1 = createTestFlow(tn, "f8", "8");
444 tf2 = createTestFlow(tn, "f9", "9");
445 tf3 = createTestFlow(tn, "f10", "10");
449 tf = createTestFlow(tn, "f23", "3");
450 tf1 = createTestFlow(tn, "f34", "4");
451 tf2 = createTestFlow(tn, "f35", "5");
452 tf3 = createTestFlow(tn, "f36", "6");
457 tf = createTestFlow(tn, "f230", "3");
458 tf1 = createTestFlow(tn, "f34", "4");
459 tf2 = createTestFlow(tn, "f35", "5");
460 tf3 = createTestFlow(tn, "f36", "6");
464 tf = createTestFlow(tn, "f42", "42");
465 tf1 = createTestFlow(tn, "f43", "43");
466 tf2 = createTestFlow(tn, "f44", "44");
467 tf3 = createTestFlow(tn, "f45", "45");
470 writeFlow(ci, tf, tf1, tf2, tf3, tn);
473 private static @NonNull InstanceIdentifier<Node> nodeBuilderToInstanceId(final NodeBuilder node) {
474 return InstanceIdentifier.create(Nodes.class).child(Node.class, node.key());
477 @SuppressWarnings("checkstyle:MethodName")
478 public void _modifyFlows(final CommandInterpreter ci) {
479 NodeBuilder tn = createTestNode(ci.nextArgument());
480 String flowtype = ci.nextArgument();
481 Integer flowcnt = Integer.parseInt(flowtype);
488 tf = createTestFlow(tn, "f82", "10");
489 tf1 = createTestFlow(tn, "f83", "11");
490 tf2 = createTestFlow(tn, "f84", "12");
491 tf3 = createTestFlow(tn, "f85", "13");
494 tf = createTestFlow(tn, "f700", "3");
495 tf1 = createTestFlow(tn, "f4", "4");
496 tf2 = createTestFlow(tn, "f900", "5");
497 tf3 = createTestFlow(tn, "f86", "6");
501 tf = createTestFlow(tn, "f91", "7");
502 tf1 = createTestFlow(tn, "f92", "8");
503 tf2 = createTestFlow(tn, "f93", "9");
504 tf3 = createTestFlow(tn, "f94", "10");
508 tf = createTestFlow(tn, "f230", "3");
509 tf1 = createTestFlow(tn, "f99", "4");
510 tf2 = createTestFlow(tn, "f100", "5");
511 tf3 = createTestFlow(tn, "f101", "6");
515 tf = createTestFlow(tn, "f23", "3");
516 tf1 = createTestFlow(tn, "f99", "4");
517 tf2 = createTestFlow(tn, "f100", "5");
518 tf3 = createTestFlow(tn, "f101", "6");
522 tf = createTestFlow(tn, "f87", "12");
523 tf1 = createTestFlow(tn, "f88", "13");
524 tf2 = createTestFlow(tn, "f89", "14");
525 tf3 = createTestFlow(tn, "f90", "15");
529 writeFlow(ci, tf, tf1, tf2, tf3, tn);
532 @SuppressWarnings("checkstyle:MethodName")
533 public void _removeFlows(final CommandInterpreter ci) {
534 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
535 NodeBuilder tn = createTestNode(ci.nextArgument());
536 String flowtype = ci.nextArgument();
537 Integer flowcnt = Integer.parseInt(flowtype);
538 FlowBuilder tf = null;
539 FlowBuilder tf1 = null;
540 FlowBuilder tf2 = null;
541 FlowBuilder tf3 = null;
545 tf = createTestFlow(tn, "f1", "10");
546 tf1 = createTestFlow(tn, "f2", "11");
547 tf2 = createTestFlow(tn, "f3", "12");
548 tf3 = createTestFlow(tn, "f4", "13");
552 tf = createTestFlow(tn, "f82", "10");
553 tf1 = createTestFlow(tn, "f83", "11");
554 tf2 = createTestFlow(tn, "f84", "12");
555 tf3 = createTestFlow(tn, "f85", "13");
559 tf = createTestFlow(tn, "f3", "3");
560 tf1 = createTestFlow(tn, "f4", "4");
561 tf2 = createTestFlow(tn, "f5", "5");
562 tf3 = createTestFlow(tn, "f6", "6");
566 tf = createTestFlow(tn, "f700", "3");
567 tf1 = createTestFlow(tn, "f4", "4");
568 tf2 = createTestFlow(tn, "f900", "5");
569 tf3 = createTestFlow(tn, "f86", "6");
573 tf = createTestFlow(tn, "f7", "7");
574 tf1 = createTestFlow(tn, "f8", "8");
575 tf2 = createTestFlow(tn, "f9", "9");
576 tf3 = createTestFlow(tn, "f10", "10");
580 tf = createTestFlow(tn, "f91", "7");
581 tf1 = createTestFlow(tn, "f92", "8");
582 tf2 = createTestFlow(tn, "f93", "9");
583 tf3 = createTestFlow(tn, "f94", "10");
587 tf = createTestFlow(tn, "f23", "3");
588 tf1 = createTestFlow(tn, "f34", "4");
589 tf2 = createTestFlow(tn, "f35", "5");
590 tf3 = createTestFlow(tn, "f36", "6");
595 tf = createTestFlow(tn, "f23", "3");
596 tf1 = createTestFlow(tn, "f99", "4");
597 tf2 = createTestFlow(tn, "f100", "5");
598 tf3 = createTestFlow(tn, "f101", "6");
602 tf = createTestFlow(tn, "f700", "7");
603 tf1 = createTestFlow(tn, "f230", "23");
604 tf2 = createTestFlow(tn, "f900", "9");
605 tf3 = createTestFlow(tn, "f1000", "10");
608 throw new IllegalArgumentException("Invalid flowtype: " + flowtype);
611 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
612 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
613 .child(Flow.class, tf.key());
614 modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
615 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
616 modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
617 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
618 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf1.getTableId()))
619 .child(Flow.class, tf1.key());
620 modification.delete(LogicalDatastoreType.OPERATIONAL, path2);
621 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
622 modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
624 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
625 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf2.getTableId()))
626 .child(Flow.class, tf2.key());
627 modification.delete(LogicalDatastoreType.OPERATIONAL, path3);
628 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
629 modification.delete(LogicalDatastoreType.CONFIGURATION, path3);
630 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.key())
631 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf3.getTableId()))
632 .child(Flow.class, tf3.key());
633 modification.delete(LogicalDatastoreType.OPERATIONAL, path4);
634 modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
635 modification.delete(LogicalDatastoreType.CONFIGURATION, path4);
636 modification.commit().addCallback(new FutureCallback<CommitInfo>() {
638 public void onSuccess(final CommitInfo notUsed) {
639 ci.println("Status of Group Data Loaded Transaction: success.");
643 public void onFailure(final Throwable throwable) {
644 LOG.error("Status of Group Data Loaded Transaction : failure.", throwable);
645 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
647 }, MoreExecutors.directExecutor());
651 private void writeFlow(final CommandInterpreter ci, final FlowBuilder flow, final FlowBuilder flow1,
652 final FlowBuilder flow2, final FlowBuilder flow3, final NodeBuilder nodeBuilder) {
653 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
654 InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class)
655 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
656 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.key());
657 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder),
658 nodeBuilder.build());
659 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path1, flow.build());
660 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
661 nodeBuilder.build());
662 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path1, flow.build());
663 InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class)
664 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
665 .child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.key());
666 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder),
667 nodeBuilder.build());
668 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path2, flow1.build());
669 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
670 nodeBuilder.build());
671 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path2, flow1.build());
673 InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class)
674 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
675 .child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.key());
676 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder),
677 nodeBuilder.build());
678 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path3, flow2.build());
679 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
680 nodeBuilder.build());
681 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path3, flow2.build());
683 InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class)
684 .child(Node.class, nodeBuilder.key()).augmentation(FlowCapableNode.class)
685 .child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.key());
686 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder),
687 nodeBuilder.build());
688 modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path4, flow3.build());
689 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder),
690 nodeBuilder.build());
691 modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path4, flow3.build());
692 modification.commit().addCallback(new FutureCallback<CommitInfo>() {
694 public void onSuccess(final CommitInfo notUsed) {
695 ci.println("Status of Group Data Loaded Transaction: success.");
699 public void onFailure(final Throwable throwable) {
700 LOG.error("Status of Group Data Loaded Transaction : failure.", throwable);
701 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
703 }, MoreExecutors.directExecutor());
706 private static InstructionsBuilder createDecNwTtlInstructions() {
707 return new InstructionsBuilder()
708 .setInstruction(BindingMap.of(new InstructionBuilder()
710 .setInstruction(new ApplyActionsCaseBuilder()
711 .setApplyActions(new ApplyActionsBuilder()
712 .setAction(BindingMap.of(new ActionBuilder()
713 .setAction(new DecNwTtlCaseBuilder().setDecNwTtl(new DecNwTtlBuilder().build()).build())
720 private static InstructionsBuilder createMeterInstructions() {
721 return new InstructionsBuilder()
722 .setInstruction(BindingMap.of(new InstructionBuilder()
724 .setInstruction(new MeterCaseBuilder()
725 .setMeter(new MeterBuilder().setMeterId(new MeterId(Uint32.ONE)).build())
730 private static InstructionsBuilder createGotoTableInstructions() {
731 return new InstructionsBuilder()
732 .setInstruction(BindingMap.of(new InstructionBuilder()
734 .setInstruction(new GoToTableCaseBuilder()
735 .setGoToTable(new GoToTableBuilder().setTableId(Uint8.TWO).build())
740 private static InstructionsBuilder createDropInstructions() {
741 return new InstructionsBuilder()
742 .setInstruction(BindingMap.of(new InstructionBuilder()
744 .setInstruction(new ApplyActionsCaseBuilder()
745 .setApplyActions(new ApplyActionsBuilder()
746 .setAction(BindingMap.of(new ActionBuilder()
747 .setAction(new DropActionCaseBuilder()
748 .setDropAction(new DropActionBuilder().build())
756 private static InstructionsBuilder createAppyActionInstruction() {
757 return new InstructionsBuilder()
758 .setInstruction(BindingMap.of(new InstructionBuilder()
760 .setInstruction(new ApplyActionsCaseBuilder()
761 .setApplyActions(new ApplyActionsBuilder()
762 .setAction(BindingMap.of(new ActionBuilder()
763 .setAction(new ControllerActionCaseBuilder()
764 .setControllerAction(new ControllerActionBuilder()
765 .setMaxLength(Uint16.valueOf(5))
774 private static InstructionsBuilder createSentToControllerInstructions() {
775 return new InstructionsBuilder()
776 .setInstruction(BindingMap.of(new InstructionBuilder()
778 .setInstruction(new ApplyActionsCaseBuilder()
779 .setApplyActions(new ApplyActionsBuilder()
780 .setAction(BindingMap.of(new ActionBuilder()
782 .setAction(new OutputActionCaseBuilder()
783 .setOutputAction(new OutputActionBuilder()
784 .setMaxLength(Uint16.MAX_VALUE)
785 .setOutputNodeConnector(new Uri(OutputPortValues.CONTROLLER.toString()))
794 private static InstructionsBuilder createAppyActionInstruction2() {
795 return new InstructionsBuilder()
796 .setInstruction(BindingMap.of(new InstructionBuilder()
798 .setInstruction(new ApplyActionsCaseBuilder()
799 .setApplyActions(new ApplyActionsBuilder()
800 .setAction(BindingMap.of(new ActionBuilder()
801 .setAction(new PushMplsActionCaseBuilder()
802 .setPushMplsAction(new PushMplsActionBuilder()
803 .setEthernetType(Uint16.valueOf(0x8847))
812 private static InstructionsBuilder createAppyActionInstruction3() {
813 return new InstructionsBuilder()
814 .setInstruction(BindingMap.of(new InstructionBuilder()
816 .setInstruction(new ApplyActionsCaseBuilder()
817 .setApplyActions(new ApplyActionsBuilder()
818 .setAction(BindingMap.of(new ActionBuilder()
819 .setAction(new PushPbbActionCaseBuilder()
820 .setPushPbbAction(new PushPbbActionBuilder()
821 .setEthernetType(Uint16.valueOf(0x88E7))
830 private static InstructionsBuilder createAppyActionInstruction6() {
831 return new InstructionsBuilder()
832 .setInstruction(BindingMap.of(new InstructionBuilder()
834 .setInstruction(new ApplyActionsCaseBuilder()
835 .setApplyActions(new ApplyActionsBuilder()
836 .setAction(BindingMap.of(new ActionBuilder()
837 .setAction(new SetDlSrcActionCaseBuilder()
838 .setSetDlSrcAction(new SetDlSrcActionBuilder()
839 .setAddress(new MacAddress("00:05:b9:7c:81:5f"))
848 private static InstructionsBuilder createAppyActionInstruction7() {
849 return new InstructionsBuilder()
850 .setInstruction(BindingMap.of(new InstructionBuilder()
852 .setInstruction(new ApplyActionsCaseBuilder()
853 .setApplyActions(new ApplyActionsBuilder()
854 .setAction(BindingMap.of(new ActionBuilder()
855 .setAction(new SetVlanIdActionCaseBuilder()
856 .setSetVlanIdAction(new SetVlanIdActionBuilder()
857 .setVlanId(new VlanId(Uint16.valueOf(4012)))
866 private static InstructionsBuilder createAppyActionInstruction8() {
867 return new InstructionsBuilder()
868 .setInstruction(BindingMap.of(new InstructionBuilder()
870 .setInstruction(new ApplyActionsCaseBuilder()
871 .setApplyActions(new ApplyActionsBuilder()
872 .setAction(BindingMap.of(new ActionBuilder()
873 .setAction(new SetVlanPcpActionCaseBuilder()
874 .setSetVlanPcpAction(new SetVlanPcpActionBuilder()
875 .setVlanPcp(new VlanPcp(Uint8.TWO))
884 private static InstructionsBuilder createAppyActionInstruction9() {
885 return new InstructionsBuilder()
886 .setInstruction(BindingMap.of(new InstructionBuilder()
888 .setInstruction(new ApplyActionsCaseBuilder()
889 .setApplyActions(new ApplyActionsBuilder()
890 .setAction(BindingMap.of(new ActionBuilder()
891 .setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(new CopyTtlInBuilder().build()).build())
898 private static InstructionsBuilder createAppyActionInstruction16() {
899 return new InstructionsBuilder()
900 .setInstruction(BindingMap.of(new InstructionBuilder()
902 .setInstruction(new ApplyActionsCaseBuilder()
903 .setApplyActions(new ApplyActionsBuilder()
904 .setAction(BindingMap.of(new ActionBuilder()
905 .setAction(new GroupActionCaseBuilder()
906 .setGroupAction(new GroupActionBuilder().setGroupId(Uint32.ONE).setGroup("0").build())
914 private static InstructionsBuilder createAppyActionInstruction160() {
915 return new InstructionsBuilder()
916 .setInstruction(BindingMap.of(new InstructionBuilder()
918 .setInstruction(new ApplyActionsCaseBuilder()
919 .setApplyActions(new ApplyActionsBuilder()
920 .setAction(BindingMap.of(new ActionBuilder()
921 .setAction(new FloodAllActionCaseBuilder()
922 .setFloodAllAction(new FloodAllActionBuilder().build())
930 private static InstructionsBuilder createAppyActionInstruction26() {
931 return new InstructionsBuilder()
932 .setInstruction(BindingMap.of(new InstructionBuilder()
934 .setInstruction(new ApplyActionsCaseBuilder()
935 .setApplyActions(new ApplyActionsBuilder()
936 .setAction(BindingMap.of(new ActionBuilder()
937 .setAction(new SetNwDstActionCaseBuilder()
938 .setSetNwDstAction(new SetNwDstActionBuilder()
939 .setAddress(new Ipv4Builder()
940 .setIpv4Address(new Ipv4Prefix("10.0.0.21/24"))
950 private static InstructionsBuilder createAppyActionInstruction27() {
951 return new InstructionsBuilder()
952 .setInstruction(BindingMap.of(new InstructionBuilder()
954 .setInstruction(new ApplyActionsCaseBuilder()
955 .setApplyActions(new ApplyActionsBuilder()
956 .setAction(BindingMap.of(new ActionBuilder()
957 .setAction(new SetNwSrcActionCaseBuilder()
958 .setSetNwSrcAction(new SetNwSrcActionBuilder()
959 .setAddress(new Ipv4Builder()
960 .setIpv4Address(new Ipv4Prefix("10.0.23.21/24"))
970 private static InstructionsBuilder createAppyActionInstruction28() {
971 return new InstructionsBuilder()
972 .setInstruction(BindingMap.of(new InstructionBuilder()
974 .setInstruction(new ApplyActionsCaseBuilder()
975 .setApplyActions(new ApplyActionsBuilder()
976 .setAction(BindingMap.of(new ActionBuilder()
977 .setAction(new SetNwTosActionCaseBuilder()
978 .setSetNwTosAction(new SetNwTosActionBuilder().setTos(8).build())
986 private static InstructionsBuilder createAppyActionInstruction34() {
987 return new InstructionsBuilder()
988 .setInstruction(BindingMap.of(new InstructionBuilder()
990 .setInstruction(new ApplyActionsCaseBuilder()
991 .setApplyActions(new ApplyActionsBuilder()
992 .setAction(BindingMap.of(new ActionBuilder()
993 .setAction(new SwPathActionCaseBuilder()
994 .setSwPathAction(new SwPathActionBuilder().build())
1002 private static MatchBuilder createLLDPMatch() {
1003 return new MatchBuilder()
1004 .setEthernetMatch(new EthernetMatchBuilder()
1005 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x88cc))).build())
1009 private static MatchBuilder createMatch1() {
1010 return new MatchBuilder()
1011 .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix("10.0.0.1/24")).build())
1012 .setEthernetMatch(new EthernetMatchBuilder()
1013 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x0800))).build())
1017 private static MatchBuilder createMatch1000() {
1018 return new MatchBuilder()
1019 .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix("10.1.1.1/24")).build())
1020 .setEthernetMatch(new EthernetMatchBuilder()
1021 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x0800))).build())
1025 private static MatchBuilder createMatch2() {
1026 return new MatchBuilder()
1027 .setLayer3Match(new Ipv4MatchBuilder().setIpv4Source(new Ipv4Prefix("10.0.0.1")).build())
1028 .setEthernetMatch(new EthernetMatchBuilder()
1029 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x0800))).build())
1033 private static MatchBuilder createMatch3() {
1034 return new MatchBuilder()
1035 .setEthernetMatch(new EthernetMatchBuilder()
1036 .setEthernetSource(new EthernetSourceBuilder().setAddress(new MacAddress("00:00:00:00:00:01")).build())
1040 private static MatchBuilder createInphyportMatch(final NodeId nodeId) {
1041 return new MatchBuilder()
1042 .setInPort(new NodeConnectorId(nodeId + ":202"))
1043 .setInPhyPort(new NodeConnectorId(nodeId + ":10122"));
1046 private static MatchBuilder createEthernetMatch() {
1047 return new MatchBuilder()
1048 .setEthernetMatch(new EthernetMatchBuilder()
1049 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x0800))).build())
1050 .setEthernetDestination(new EthernetDestinationBuilder()
1051 .setAddress(new MacAddress("ff:ff:ff:ff:ff:ff"))
1054 .setEthernetSource(new EthernetSourceBuilder()
1055 .setAddress(new MacAddress("00:00:00:00:23:ae"))
1061 private static MatchBuilder createL3IPv6Match() {
1062 return new MatchBuilder()
1063 .setEthernetMatch(new EthernetMatchBuilder()
1064 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x86dd))).build())
1067 .setIcmpv6Match(new Icmpv6MatchBuilder()
1068 .setIcmpv6Type(Uint8.valueOf(135))
1069 .setIcmpv6Code(Uint8.ZERO)
1071 .setLayer3Match(new Ipv6MatchBuilder()
1072 // .setIpv6Source(srcip6)
1073 // .setIpv6Destination(dstip6)
1074 // .setIpv6ExtHeader(nextheader.build())
1075 .setIpv6NdSll(new MacAddress("c2:00:54:f5:00:00"))
1076 .setIpv6NdTll(new MacAddress("00:0c:29:0e:4c:67"))
1077 // .setIpv6NdTarget(ndtarget)
1078 .setIpv6Label(new Ipv6LabelBuilder()
1079 .setIpv6Flabel(new Ipv6FlowLabel(Uint32.valueOf(10028)))
1080 // .setFlabelMask(new byte[] { 0, 1, -1, -1 })
1085 private static MatchBuilder createICMPv6Match() {
1086 return new MatchBuilder()
1087 .setEthernetMatch(new EthernetMatchBuilder()
1088 .setEthernetType(new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(0x86dd))).build())
1091 .setIpMatch(new IpMatchBuilder().setIpProtocol(Uint8.valueOf(58)).build())
1093 .setIcmpv6Match(new Icmpv6MatchBuilder()
1094 .setIcmpv6Type(Uint8.valueOf(135))
1095 .setIcmpv6Code(Uint8.ONE)
1099 private static MatchBuilder createMetadataMatch() {
1100 return new MatchBuilder()
1101 .setMetadata(new MetadataBuilder()
1102 .setMetadata(Uint64.valueOf(500))
1103 // .setMetadataMask(metamask)