1 package org.opendaylight.openflowplugin.test;
3 import java.math.BigInteger;
4 import java.util.ArrayList;
6 import java.util.concurrent.ExecutionException;
7 import java.util.concurrent.Future;
9 import org.eclipse.osgi.framework.console.CommandInterpreter;
10 import org.eclipse.osgi.framework.console.CommandProvider;
11 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
12 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
14 import org.opendaylight.controller.sal.binding.api.NotificationService;
15 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl;
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.DropAction;
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.Action;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowListener;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.node.error.service.rev140410.NodeErrorListener;
106 import org.opendaylight.yangtools.concepts.Registration;
107 import org.opendaylight.yangtools.yang.binding.DataObject;
108 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
109 import org.opendaylight.yangtools.yang.common.RpcResult;
110 import org.osgi.framework.BundleContext;
111 import org.slf4j.Logger;
112 import org.slf4j.LoggerFactory;
114 //import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.M
116 public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
118 private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestCommandProvider.class);
119 private DataBrokerService dataBrokerService;
120 private final BundleContext ctx;
121 private NodeBuilder testNode;
122 private ProviderContext pc;
123 private FlowBuilder testFlow;
124 private final String originalFlowName = "Foo";
125 private final NodeErrorListener nodeErrorListener = new NodeErrorListenerLoggingImpl();
126 private Registration listener1Reg;
127 private Registration listener2Reg;
128 private Node testNode12;
129 private final String originalGroupName = "Foo";
130 private static NotificationService notificationService;
132 public OpenflowPluginBulkTransactionProvider(BundleContext ctx) {
136 public void onSessionInitiated(ProviderContext session) {
138 notificationService = session.getSALService(NotificationService.class);
139 listener2Reg = notificationService.registerNotificationListener(nodeErrorListener);
140 dataBrokerService = session.getSALService(DataBrokerService.class);
141 ctx.registerService(CommandProvider.class.getName(), this, null);
142 createTestFlow(createTestNode(null), null, null);
145 private NodeBuilder createTestNode(String nodeId) {
146 if (nodeId == null) {
147 nodeId = OpenflowpluginTestActivator.NODE_ID;
149 NodeRef nodeOne = createNodeRef(nodeId);
150 NodeBuilder builder = new NodeBuilder();
151 builder.setId(new NodeId(nodeId));
152 builder.setKey(new NodeKey(builder.getId()));
157 private static NodeRef createNodeRef(String string) {
158 NodeKey key = new NodeKey(new NodeId(string));
159 InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
162 return new NodeRef(path);
166 public String getHelp() {
170 private FlowBuilder createTestFlow(NodeBuilder nodeBuilder, String flowTypeArg, String tableId) {
172 FlowBuilder flow = new FlowBuilder();
175 String flowType = flowTypeArg;
176 if (flowType == null) {
183 flow.setMatch(createMatch1().build());
184 flow.setInstructions(createDecNwTtlInstructions().build());
188 flow.setMatch(createMatch2().build());
189 flow.setInstructions(createDropInstructions().build());
193 flow.setMatch(createMatch3().build());
194 flow.setInstructions(createDropInstructions().build());
198 flow.setMatch(createEthernetMatch().build());
199 flow.setInstructions(createDropInstructions().build());
203 flow.setMatch(createMatch1().build());
204 flow.setInstructions(createAppyActionInstruction().build());
208 flow.setMatch(createMatch1().build());
209 flow.setInstructions(createGotoTableInstructions().build());
213 flow.setMatch(createMatch1().build());
214 flow.setInstructions(createMeterInstructions().build());
218 flow.setMatch(createMatch1().build());
219 flow.setInstructions(createAppyActionInstruction7().build());
223 flow.setMatch(createMatch1().build());
224 flow.setInstructions(createAppyActionInstruction2().build());
228 flow.setMatch(createMatch1().build());
229 flow.setInstructions(createAppyActionInstruction3().build());
233 flow.setMatch(createMatch1().build());
234 flow.setInstructions(createAppyActionInstruction16().build());
238 flow.setMatch(createMatch1().build());
239 flow.setInstructions(createAppyActionInstruction160().build());
243 flow.setMatch(createMatch1().build());
244 flow.setInstructions(createAppyActionInstruction26().build());
248 flow.setMatch(createMatch1().build());
249 flow.setInstructions(createAppyActionInstruction27().build());
253 flow.setMatch(createMatch1().build());
254 flow.setInstructions(createAppyActionInstruction28().build());
258 flow.setMatch(createMatch1().build());
259 flow.setInstructions(createAppyActionInstruction34().build());
263 flow.setMatch(createICMPv6Match().build());
264 flow.setInstructions(createDecNwTtlInstructions().build());
268 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
269 flow.setInstructions(createDropInstructions().build());
273 flow.setMatch(createMetadataMatch().build());
274 flow.setInstructions(createDropInstructions().build());
278 flow.setMatch(createL3IPv6Match().build());
279 flow.setInstructions(createDecNwTtlInstructions().build());
283 flow.setMatch(createLLDPMatch().build());
284 flow.setInstructions(createSentToControllerInstructions().build());
289 flow.setMatch(createMatch1().build());
290 flow.setInstructions(createDropInstructions().build());
294 flow.setMatch(createMatch2().build());
295 flow.setInstructions(createDecNwTtlInstructions().build());
299 flow.setMatch(createMatch3().build());
300 flow.setInstructions(createDecNwTtlInstructions().build());
304 flow.setMatch(createEthernetMatch().build());
305 flow.setInstructions(createMeterInstructions().build());
309 flow.setMatch(createMatch1().build());
310 flow.setInstructions(createDecNwTtlInstructions().build());
314 flow.setMatch(createMatch1().build());
315 flow.setInstructions(createAppyActionInstruction7().build());
319 flow.setMatch(createEthernetMatch().build());
320 flow.setInstructions(createAppyActionInstruction6().build());
324 flow.setMatch(createEthernetMatch().build());
325 flow.setInstructions(createAppyActionInstruction7().build());
329 flow.setMatch(createMatch1().build());
330 flow.setInstructions(createAppyActionInstruction9().build());
334 flow.setMatch(createMatch1().build());
335 flow.setInstructions(createAppyActionInstruction9().build());
339 flow.setMatch(createMatch1().build());
340 flow.setInstructions(createAppyActionInstruction6().build());
344 flow.setMatch(createMatch1().build());
345 flow.setInstructions(createDecNwTtlInstructions().build());
349 flow.setMatch(createMatch1().build());
350 flow.setInstructions(createDecNwTtlInstructions().build());
354 flow.setMatch(createMatch1().build());
355 flow.setInstructions(createDecNwTtlInstructions().build());
359 flow.setMatch(createICMPv6Match().build());
360 flow.setInstructions(createDropInstructions().build());
364 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
365 flow.setInstructions(createMeterInstructions().build());
369 flow.setMatch(createMetadataMatch().build());
370 flow.setInstructions(createAppyActionInstruction6().build());
374 flow.setMatch(createMatch1().build());
375 flow.setInstructions(createAppyActionInstruction6().build());
379 flow.setMatch(createMatch1().build());
380 flow.setInstructions(createAppyActionInstruction7().build());
384 flow.setMatch(createMatch1().build());
385 flow.setInstructions(createAppyActionInstruction8().build());
389 flow.setMatch(createMatch3().build());
390 flow.setInstructions(createMeterInstructions().build());
394 flow.setMatch(createMatch1000().build());
395 flow.setInstructions(createAppyActionInstruction6().build());
399 flow.setMatch(createMatch1000().build());
400 flow.setInstructions(createAppyActionInstruction2().build());
404 flow.setMatch(createMatch1000().build());
405 flow.setInstructions(createAppyActionInstruction3().build());
408 LOG.warn("flow type not understood: {}", flowType);
411 FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
412 if (null == flow.isBarrier()) {
413 flow.setBarrier(Boolean.FALSE);
415 // flow.setBufferId(new Long(12));
416 BigInteger value = new BigInteger("10", 10);
417 BigInteger outputPort = new BigInteger("4294967295", 10);
418 flow.setCookie(new FlowCookie(value));
419 flow.setCookieMask(new FlowCookie(value));
420 flow.setHardTimeout(0);
421 flow.setIdleTimeout(0);
422 flow.setInstallHw(false);
423 flow.setStrict(false);
424 flow.setContainerName(null);
425 flow.setFlags(new FlowModFlags(false, false, false, false, true));
426 flow.setId(new FlowId("12"));
427 flow.setTableId(getTableId(tableId));
428 flow.setOutGroup(new Long("4294967295"));
429 // set outport to OFPP_NONE (65535) to disable remove restriction for
431 flow.setOutPort(outputPort);
435 flow.setFlowName(originalFlowName + "X" + flowType);
440 private short getTableId(String tableId) {
443 table = Short.parseShort(tableId);
444 } catch (Exception ex) {
445 // ignore exception and continue with default value
452 private void createTestNode() {
453 NodeRef nodeOne = createNodeRef(OpenflowpluginTestActivator.NODE_ID);
454 NodeBuilder builder = new NodeBuilder();
455 builder.setId(new NodeId(OpenflowpluginTestActivator.NODE_ID));
456 builder.setKey(new NodeKey(builder.getId()));
457 testNode12 = builder.build();
460 public void _addFlows(CommandInterpreter ci) {
461 NodeBuilder tn = createTestNode(ci.nextArgument());
462 String flowtype = ci.nextArgument();
463 Integer flowcnt = Integer.parseInt(flowtype);
470 tf = createTestFlow(tn, "f1", "10");
471 tf1 = createTestFlow(tn, "f2", "11");
472 tf2 = createTestFlow(tn, "f3", "12");
473 tf3 = createTestFlow(tn, "f4", "13");
476 tf = createTestFlow(tn, "f3", "3");
477 tf1 = createTestFlow(tn, "f4", "4");
478 tf2 = createTestFlow(tn, "f5", "5");
479 tf3 = createTestFlow(tn, "f6", "6");
482 tf = createTestFlow(tn, "f7", "7");
483 tf1 = createTestFlow(tn, "f8", "8");
484 tf2 = createTestFlow(tn, "f9", "9");
485 tf3 = createTestFlow(tn, "f10", "10");
489 tf = createTestFlow(tn, "f23", "3");
490 tf1 = createTestFlow(tn, "f34", "4");
491 tf2 = createTestFlow(tn, "f35", "5");
492 tf3 = createTestFlow(tn, "f36", "6");
497 tf = createTestFlow(tn, "f230", "3");
498 tf1 = createTestFlow(tn, "f34", "4");
499 tf2 = createTestFlow(tn, "f35", "5");
500 tf3 = createTestFlow(tn, "f36", "6");
504 tf = createTestFlow(tn, "f42", "42");
505 tf1 = createTestFlow(tn, "f43", "43");
506 tf2 = createTestFlow(tn, "f44", "44");
507 tf3 = createTestFlow(tn, "f45", "45");
510 writeFlow(ci, tf, tf1, tf2, tf3, tn);
513 private InstanceIdentifier<Node> nodeBuilderToInstanceId(NodeBuilder node) {
514 return InstanceIdentifier.builder(Nodes.class).child(Node.class, node.getKey()).toInstance();
517 public void _modifyFlows(CommandInterpreter ci) {
518 NodeBuilder tn = createTestNode(ci.nextArgument());
519 String flowtype = ci.nextArgument();
520 Integer flowcnt = Integer.parseInt(flowtype);
527 tf = createTestFlow(tn, "f82", "10");
528 tf1 = createTestFlow(tn, "f83", "11");
529 tf2 = createTestFlow(tn, "f84", "12");
530 tf3 = createTestFlow(tn, "f85", "13");
533 tf = createTestFlow(tn, "f700", "3");
534 tf1 = createTestFlow(tn, "f4", "4");
535 tf2 = createTestFlow(tn, "f900", "5");
536 tf3 = createTestFlow(tn, "f86", "6");
540 tf = createTestFlow(tn, "f91", "7");
541 tf1 = createTestFlow(tn, "f92", "8");
542 tf2 = createTestFlow(tn, "f93", "9");
543 tf3 = createTestFlow(tn, "f94", "10");
547 tf = createTestFlow(tn, "f230", "3");
548 tf1 = createTestFlow(tn, "f99", "4");
549 tf2 = createTestFlow(tn, "f100", "5");
550 tf3 = createTestFlow(tn, "f101", "6");
554 tf = createTestFlow(tn, "f23", "3");
555 tf1 = createTestFlow(tn, "f99", "4");
556 tf2 = createTestFlow(tn, "f100", "5");
557 tf3 = createTestFlow(tn, "f101", "6");
561 tf = createTestFlow(tn, "f87", "12");
562 tf1 = createTestFlow(tn, "f88", "13");
563 tf2 = createTestFlow(tn, "f89", "14");
564 tf3 = createTestFlow(tn, "f90", "15");
568 writeFlow(ci, tf, tf1, tf2, tf3, tn);
572 public void _removeFlows(CommandInterpreter ci) {
573 DataModification<InstanceIdentifier<?>, DataObject> modification = dataBrokerService.beginTransaction();
574 NodeBuilder tn = createTestNode(ci.nextArgument());
575 String flowtype = ci.nextArgument();
576 Integer flowcnt = Integer.parseInt(flowtype);
577 FlowBuilder tf = null;
578 FlowBuilder tf1 = null;
579 FlowBuilder tf2 = null;
580 FlowBuilder tf3 = null;
584 tf = createTestFlow(tn, "f1", "10");
585 tf1 = createTestFlow(tn, "f2", "11");
586 tf2 = createTestFlow(tn, "f3", "12");
587 tf3 = createTestFlow(tn, "f4", "13");
591 tf = createTestFlow(tn, "f82", "10");
592 tf1 = createTestFlow(tn, "f83", "11");
593 tf2 = createTestFlow(tn, "f84", "12");
594 tf3 = createTestFlow(tn, "f85", "13");
598 tf = createTestFlow(tn, "f3", "3");
599 tf1 = createTestFlow(tn, "f4", "4");
600 tf2 = createTestFlow(tn, "f5", "5");
601 tf3 = createTestFlow(tn, "f6", "6");
605 tf = createTestFlow(tn, "f700", "3");
606 tf1 = createTestFlow(tn, "f4", "4");
607 tf2 = createTestFlow(tn, "f900", "5");
608 tf3 = createTestFlow(tn, "f86", "6");
612 tf = createTestFlow(tn, "f7", "7");
613 tf1 = createTestFlow(tn, "f8", "8");
614 tf2 = createTestFlow(tn, "f9", "9");
615 tf3 = createTestFlow(tn, "f10", "10");
619 tf = createTestFlow(tn, "f91", "7");
620 tf1 = createTestFlow(tn, "f92", "8");
621 tf2 = createTestFlow(tn, "f93", "9");
622 tf3 = createTestFlow(tn, "f94", "10");
626 tf = createTestFlow(tn, "f23", "3");
627 tf1 = createTestFlow(tn, "f34", "4");
628 tf2 = createTestFlow(tn, "f35", "5");
629 tf3 = createTestFlow(tn, "f36", "6");
634 tf = createTestFlow(tn, "f23", "3");
635 tf1 = createTestFlow(tn, "f99", "4");
636 tf2 = createTestFlow(tn, "f100", "5");
637 tf3 = createTestFlow(tn, "f101", "6");
641 tf = createTestFlow(tn, "f700", "7");
642 tf1 = createTestFlow(tn, "f230", "23");
643 tf2 = createTestFlow(tn, "f900", "9");
644 tf3 = createTestFlow(tn, "f1000", "10");
648 InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(Node.class, tn.getKey())
649 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
650 .child(Flow.class, tf.getKey()).build();
651 modification.removeOperationalData(path1);
652 modification.removeConfigurationData(nodeBuilderToInstanceId(tn));
653 modification.removeConfigurationData(path1);
654 InstanceIdentifier<Flow> path2 = InstanceIdentifier.builder(Nodes.class).child(Node.class, tn.getKey())
655 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf1.getTableId()))
656 .child(Flow.class, tf1.getKey()).build();
657 modification.removeOperationalData(path2);
658 modification.removeConfigurationData(nodeBuilderToInstanceId(tn));
659 modification.removeConfigurationData(path2);
661 InstanceIdentifier<Flow> path3 = InstanceIdentifier.builder(Nodes.class).child(Node.class, tn.getKey())
662 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf2.getTableId()))
663 .child(Flow.class, tf2.getKey()).build();
664 modification.removeOperationalData(path3);
665 modification.removeConfigurationData(nodeBuilderToInstanceId(tn));
666 modification.removeConfigurationData(path3);
667 InstanceIdentifier<Flow> path4 = InstanceIdentifier.builder(Nodes.class).child(Node.class, tn.getKey())
668 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf3.getTableId()))
669 .child(Flow.class, tf3.getKey()).build();
670 modification.removeOperationalData(path4);
671 modification.removeConfigurationData(nodeBuilderToInstanceId(tn));
672 modification.removeConfigurationData(path4);
673 Future<RpcResult<TransactionStatus>> commitFuture = modification.commit();
675 RpcResult<TransactionStatus> result = commitFuture.get();
676 TransactionStatus status = result.getResult();
677 ci.println("Status of Flow Data Loaded Transaction: " + status);
679 } catch (InterruptedException e) {
680 LOG.error(e.getMessage(), e);
681 } catch (ExecutionException e) {
682 LOG.error(e.getMessage(), e);
686 private void writeFlow(CommandInterpreter ci, FlowBuilder flow, FlowBuilder flow1, FlowBuilder flow2,
687 FlowBuilder flow3, NodeBuilder nodeBuilder) {
688 DataModification<InstanceIdentifier<?>, DataObject> modification = dataBrokerService.beginTransaction();
689 InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class)
690 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
691 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey()).build();
692 modification.putOperationalData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
693 modification.putOperationalData(path1, flow.build());
694 modification.putConfigurationData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
695 modification.putConfigurationData(path1, flow.build());
696 InstanceIdentifier<Flow> path2 = InstanceIdentifier.builder(Nodes.class)
697 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
698 .child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.getKey()).build();
699 modification.putOperationalData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
700 modification.putOperationalData(path2, flow1.build());
701 modification.putConfigurationData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
702 modification.putConfigurationData(path2, flow1.build());
704 InstanceIdentifier<Flow> path3 = InstanceIdentifier.builder(Nodes.class)
705 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
706 .child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.getKey()).build();
707 modification.putOperationalData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
708 modification.putOperationalData(path3, flow2.build());
709 modification.putConfigurationData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
710 modification.putConfigurationData(path3, flow2.build());
712 InstanceIdentifier<Flow> path4 = InstanceIdentifier.builder(Nodes.class)
713 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
714 .child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.getKey()).build();
715 modification.putOperationalData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
716 modification.putOperationalData(path4, flow3.build());
717 modification.putConfigurationData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
718 modification.putConfigurationData(path4, flow3.build());
719 Future<RpcResult<TransactionStatus>> commitFuture = modification.commit();
721 RpcResult<TransactionStatus> result = commitFuture.get();
722 TransactionStatus status = result.getResult();
723 ci.println("Status of Flow Data Loaded Transaction: " + status);
725 } catch (InterruptedException e) {
726 LOG.error(e.getMessage(), e);
727 } catch (ExecutionException e) {
728 LOG.error(e.getMessage(), e);
735 private static InstructionsBuilder createDecNwTtlInstructions() {
736 DecNwTtlBuilder ta = new DecNwTtlBuilder();
737 DecNwTtl decNwTtl = ta.build();
738 ActionBuilder ab = new ActionBuilder();
739 ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
741 // Add our drop action to a list
742 List<Action> actionList = new ArrayList<Action>();
743 actionList.add(ab.build());
745 // Create an Apply Action
746 ApplyActionsBuilder aab = new ApplyActionsBuilder();
747 aab.setAction(actionList);
749 // Wrap our Apply Action in an Instruction
750 InstructionBuilder ib = new InstructionBuilder();
751 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
752 ib.setKey(new InstructionKey(0));
755 // Put our Instruction in a list of Instructions
756 InstructionsBuilder isb = new InstructionsBuilder();
757 List<Instruction> instructions = new ArrayList<Instruction>();
758 instructions.add(ib.build());
759 isb.setInstruction(instructions);
766 private static InstructionsBuilder createMeterInstructions() {
768 MeterBuilder aab = new MeterBuilder();
769 aab.setMeterId(new MeterId(new Long(1)));
771 InstructionBuilder ib = new InstructionBuilder();
772 ib.setInstruction(new MeterCaseBuilder().setMeter(aab.build()).build());
774 // Put our Instruction in a list of Instructions
775 InstructionsBuilder isb = new InstructionsBuilder();
776 List<Instruction> instructions = new ArrayList<Instruction>();
777 instructions.add(ib.build());
778 isb.setInstruction(instructions);
782 private static InstructionsBuilder createGotoTableInstructions() {
784 GoToTableBuilder aab = new GoToTableBuilder();
785 aab.setTableId((short) 2);
787 InstructionBuilder ib = new InstructionBuilder();
788 ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(aab.build()).build());
790 // Put our Instruction in a list of Instructions
791 InstructionsBuilder isb = new InstructionsBuilder();
792 List<Instruction> instructions = new ArrayList<Instruction>();
793 instructions.add(ib.build());
794 isb.setInstruction(instructions);
798 private static InstructionsBuilder createDropInstructions() {
799 DropActionBuilder dab = new DropActionBuilder();
800 DropAction dropAction = dab.build();
801 ActionBuilder ab = new ActionBuilder();
802 ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
804 // Add our drop action to a list
805 List<Action> actionList = new ArrayList<Action>();
806 actionList.add(ab.build());
808 // Create an Apply Action
809 ApplyActionsBuilder aab = new ApplyActionsBuilder();
810 aab.setAction(actionList);
812 // Wrap our Apply Action in an Instruction
813 InstructionBuilder ib = new InstructionBuilder();
814 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
816 // Put our Instruction in a list of Instructions
817 InstructionsBuilder isb = new InstructionsBuilder();
818 List<Instruction> instructions = new ArrayList<Instruction>();
819 instructions.add(ib.build());
820 isb.setInstruction(instructions);
824 private static InstructionsBuilder createAppyActionInstruction() {
826 List<Action> actionList = new ArrayList<Action>();
827 ActionBuilder ab = new ActionBuilder();
828 ControllerActionBuilder controller = new ControllerActionBuilder();
829 controller.setMaxLength(5);
830 ab.setAction(new ControllerActionCaseBuilder().setControllerAction(controller.build()).build());
831 actionList.add(ab.build());
832 // Create an Apply Action
833 ApplyActionsBuilder aab = new ApplyActionsBuilder();
834 aab.setAction(actionList);
836 // Wrap our Apply Action in an Instruction
837 InstructionBuilder ib = new InstructionBuilder();
838 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
840 // Put our Instruction in a list of Instructions
841 InstructionsBuilder isb = new InstructionsBuilder();
842 List<Instruction> instructions = new ArrayList<Instruction>();
843 instructions.add(ib.build());
844 isb.setInstruction(instructions);
848 private static InstructionsBuilder createSentToControllerInstructions() {
849 List<Action> actionList = new ArrayList<Action>();
850 ActionBuilder ab = new ActionBuilder();
852 OutputActionBuilder output = new OutputActionBuilder();
853 output.setMaxLength(new Integer(0xffff));
854 Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
855 output.setOutputNodeConnector(value);
856 ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
858 ab.setKey(new ActionKey(0));
859 actionList.add(ab.build());
860 // Create an Apply Action
861 ApplyActionsBuilder aab = new ApplyActionsBuilder();
862 aab.setAction(actionList);
864 // Wrap our Apply Action in an Instruction
865 InstructionBuilder ib = new InstructionBuilder();
866 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
868 ib.setKey(new InstructionKey(0));
870 // Put our Instruction in a list of Instructions
871 InstructionsBuilder isb = new InstructionsBuilder();
872 List<Instruction> instructions = new ArrayList<Instruction>();
873 instructions.add(ib.build());
874 isb.setInstruction(instructions);
878 private static InstructionsBuilder createAppyActionInstruction2() {
880 List<Action> actionList = new ArrayList<Action>();
881 ActionBuilder ab = new ActionBuilder();
883 PushMplsActionBuilder push = new PushMplsActionBuilder();
884 push.setEthernetType(new Integer(0x8847));
885 ab.setAction(new PushMplsActionCaseBuilder().setPushMplsAction(push.build()).build());
886 actionList.add(ab.build());
887 // Create an Apply Action
888 ApplyActionsBuilder aab = new ApplyActionsBuilder();
889 aab.setAction(actionList);
891 // Wrap our Apply Action in an Instruction
892 InstructionBuilder ib = new InstructionBuilder();
893 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
895 // Put our Instruction in a list of Instructions
896 InstructionsBuilder isb = new InstructionsBuilder();
897 List<Instruction> instructions = new ArrayList<Instruction>();
898 instructions.add(ib.build());
899 isb.setInstruction(instructions);
903 private static InstructionsBuilder createAppyActionInstruction3() {
905 List<Action> actionList = new ArrayList<Action>();
906 ActionBuilder ab = new ActionBuilder();
908 PushPbbActionBuilder pbb = new PushPbbActionBuilder();
909 pbb.setEthernetType(new Integer(0x88E7));
910 ab.setAction(new PushPbbActionCaseBuilder().setPushPbbAction(pbb.build()).build());
911 actionList.add(ab.build());
912 // Create an Apply Action
913 ApplyActionsBuilder aab = new ApplyActionsBuilder();
914 aab.setAction(actionList);
916 // Wrap our Apply Action in an Instruction
917 InstructionBuilder ib = new InstructionBuilder();
918 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
920 // Put our Instruction in a list of Instructions
921 InstructionsBuilder isb = new InstructionsBuilder();
922 List<Instruction> instructions = new ArrayList<Instruction>();
923 instructions.add(ib.build());
924 isb.setInstruction(instructions);
928 private static InstructionsBuilder createAppyActionInstruction6() {
930 List<Action> actionList = new ArrayList<Action>();
931 ActionBuilder ab = new ActionBuilder();
933 SetDlSrcActionBuilder src = new SetDlSrcActionBuilder();
934 src.setAddress(new MacAddress("00:05:b9:7c:81:5f"));
935 ab.setAction(new SetDlSrcActionCaseBuilder().setSetDlSrcAction(src.build()).build());
936 actionList.add(ab.build());
938 // Create an Apply Action
939 ApplyActionsBuilder aab = new ApplyActionsBuilder();
940 aab.setAction(actionList);
942 // Wrap our Apply Action in an Instruction
943 InstructionBuilder ib = new InstructionBuilder();
944 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
946 // Put our Instruction in a list of Instructions
947 InstructionsBuilder isb = new InstructionsBuilder();
948 List<Instruction> instructions = new ArrayList<Instruction>();
949 instructions.add(ib.build());
950 isb.setInstruction(instructions);
954 private static InstructionsBuilder createAppyActionInstruction7() {
956 List<Action> actionList = new ArrayList<Action>();
957 ActionBuilder ab = new ActionBuilder();
959 SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
960 VlanId a = new VlanId(4012);
962 ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.build()).build());
963 actionList.add(ab.build());
964 // Create an Apply Action
965 ApplyActionsBuilder aab = new ApplyActionsBuilder();
966 aab.setAction(actionList);
968 // Wrap our Apply Action in an Instruction
969 InstructionBuilder ib = new InstructionBuilder();
970 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
972 // Put our Instruction in a list of Instructions
973 InstructionsBuilder isb = new InstructionsBuilder();
974 List<Instruction> instructions = new ArrayList<Instruction>();
975 instructions.add(ib.build());
976 isb.setInstruction(instructions);
980 private static InstructionsBuilder createAppyActionInstruction8() {
982 List<Action> actionList = new ArrayList<Action>();
983 ActionBuilder ab = new ActionBuilder();
985 SetVlanPcpActionBuilder pcp = new SetVlanPcpActionBuilder();
986 VlanPcp pcp1 = new VlanPcp((short) 2);
987 pcp.setVlanPcp(pcp1);
988 ab.setAction(new SetVlanPcpActionCaseBuilder().setSetVlanPcpAction(pcp.build()).build());
989 actionList.add(ab.build());
990 // Create an Apply Action
991 ApplyActionsBuilder aab = new ApplyActionsBuilder();
992 aab.setAction(actionList);
994 // Wrap our Apply Action in an Instruction
995 InstructionBuilder ib = new InstructionBuilder();
996 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
998 // Put our Instruction in a list of Instructions
999 InstructionsBuilder isb = new InstructionsBuilder();
1000 List<Instruction> instructions = new ArrayList<Instruction>();
1001 instructions.add(ib.build());
1002 isb.setInstruction(instructions);
1006 private static InstructionsBuilder createAppyActionInstruction9() {
1008 List<Action> actionList = new ArrayList<Action>();
1009 ActionBuilder ab = new ActionBuilder();
1011 CopyTtlInBuilder ttlin = new CopyTtlInBuilder();
1012 ab.setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(ttlin.build()).build());
1013 actionList.add(ab.build());
1014 // Create an Apply Action
1015 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1016 aab.setAction(actionList);
1018 // Wrap our Apply Action in an Instruction
1019 InstructionBuilder ib = new InstructionBuilder();
1020 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1022 // Put our Instruction in a list of Instructions
1023 InstructionsBuilder isb = new InstructionsBuilder();
1024 List<Instruction> instructions = new ArrayList<Instruction>();
1025 instructions.add(ib.build());
1026 isb.setInstruction(instructions);
1030 private static InstructionsBuilder createAppyActionInstruction16() {
1032 List<Action> actionList = new ArrayList<Action>();
1033 ActionBuilder ab = new ActionBuilder();
1035 GroupActionBuilder groupActionB = new GroupActionBuilder();
1036 groupActionB.setGroupId(1L);
1037 groupActionB.setGroup("0");
1038 ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
1039 actionList.add(ab.build());
1041 // Create an Apply Action
1042 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1043 aab.setAction(actionList);
1045 // Wrap our Apply Action in an Instruction
1046 InstructionBuilder ib = new InstructionBuilder();
1047 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1049 // Put our Instruction in a list of Instructions
1050 InstructionsBuilder isb = new InstructionsBuilder();
1051 List<Instruction> instructions = new ArrayList<Instruction>();
1052 instructions.add(ib.build());
1053 isb.setInstruction(instructions);
1057 private static InstructionsBuilder createAppyActionInstruction160() {
1059 List<Action> actionList = new ArrayList<Action>();
1060 ActionBuilder ab = new ActionBuilder();
1062 FloodAllActionBuilder fldall = new FloodAllActionBuilder();
1063 ab.setAction(new FloodAllActionCaseBuilder().setFloodAllAction(fldall.build()).build());
1064 actionList.add(ab.build());
1065 // Create an Apply Action
1066 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1067 aab.setAction(actionList);
1069 // Wrap our Apply Action in an Instruction
1070 InstructionBuilder ib = new InstructionBuilder();
1071 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1073 // Put our Instruction in a list of Instructions
1074 InstructionsBuilder isb = new InstructionsBuilder();
1075 List<Instruction> instructions = new ArrayList<Instruction>();
1076 instructions.add(ib.build());
1077 isb.setInstruction(instructions);
1081 private static InstructionsBuilder createAppyActionInstruction26() {
1083 List<Action> actionList = new ArrayList<Action>();
1084 ActionBuilder ab = new ActionBuilder();
1086 SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
1087 Ipv4Builder ipdst = new Ipv4Builder();
1088 Ipv4Prefix prefixdst = new Ipv4Prefix("10.0.0.21/24");
1089 ipdst.setIpv4Address(prefixdst);
1090 setNwDstActionBuilder.setAddress(ipdst.build());
1091 ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
1092 actionList.add(ab.build());
1094 // Create an Apply Action
1095 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1096 aab.setAction(actionList);
1098 // Wrap our Apply Action in an Instruction
1099 InstructionBuilder ib = new InstructionBuilder();
1100 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1102 // Put our Instruction in a list of Instructions
1103 InstructionsBuilder isb = new InstructionsBuilder();
1104 List<Instruction> instructions = new ArrayList<Instruction>();
1105 instructions.add(ib.build());
1106 isb.setInstruction(instructions);
1110 private static InstructionsBuilder createAppyActionInstruction27() {
1112 List<Action> actionList = new ArrayList<Action>();
1113 ActionBuilder ab = new ActionBuilder();
1115 SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
1116 Ipv4Builder ipsrc = new Ipv4Builder();
1117 Ipv4Prefix prefixsrc = new Ipv4Prefix("10.0.23.21/24");
1118 ipsrc.setIpv4Address(prefixsrc);
1119 setNwsrcActionBuilder.setAddress(ipsrc.build());
1120 ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
1121 actionList.add(ab.build());
1123 // Create an Apply Action
1124 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1125 aab.setAction(actionList);
1127 // Wrap our Apply Action in an Instruction
1128 InstructionBuilder ib = new InstructionBuilder();
1129 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1131 // Put our Instruction in a list of Instructions
1132 InstructionsBuilder isb = new InstructionsBuilder();
1133 List<Instruction> instructions = new ArrayList<Instruction>();
1134 instructions.add(ib.build());
1135 isb.setInstruction(instructions);
1139 private static InstructionsBuilder createAppyActionInstruction28() {
1141 List<Action> actionList = new ArrayList<Action>();
1142 ActionBuilder ab = new ActionBuilder();
1144 SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
1145 setNwTosActionBuilder.setTos(8);
1146 ab.setAction(new SetNwTosActionCaseBuilder().setSetNwTosAction(setNwTosActionBuilder.build()).build());
1147 actionList.add(ab.build());
1148 // Create an Apply Action
1149 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1150 aab.setAction(actionList);
1152 // Wrap our Apply Action in an Instruction
1153 InstructionBuilder ib = new InstructionBuilder();
1154 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1156 // Put our Instruction in a list of Instructions
1157 InstructionsBuilder isb = new InstructionsBuilder();
1158 List<Instruction> instructions = new ArrayList<Instruction>();
1159 instructions.add(ib.build());
1160 isb.setInstruction(instructions);
1164 private static InstructionsBuilder createAppyActionInstruction34() {
1166 List<Action> actionList = new ArrayList<Action>();
1167 ActionBuilder ab = new ActionBuilder();
1169 SwPathActionBuilder swPathAction = new SwPathActionBuilder();
1170 ab.setAction(new SwPathActionCaseBuilder().setSwPathAction(swPathAction.build()).build());
1171 actionList.add(ab.build());
1173 // Create an Apply Action
1174 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1175 aab.setAction(actionList);
1177 // Wrap our Apply Action in an Instruction
1178 InstructionBuilder ib = new InstructionBuilder();
1179 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1181 // Put our Instruction in a list of Instructions
1182 InstructionsBuilder isb = new InstructionsBuilder();
1183 List<Instruction> instructions = new ArrayList<Instruction>();
1184 instructions.add(ib.build());
1185 isb.setInstruction(instructions);
1189 private static MatchBuilder createLLDPMatch() {
1190 MatchBuilder match = new MatchBuilder();
1191 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1192 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1193 ethTypeBuilder.setType(new EtherType(0x88ccL));
1194 eth.setEthernetType(ethTypeBuilder.build());
1195 match.setEthernetMatch(eth.build());
1202 private static MatchBuilder createMatch1() {
1203 MatchBuilder match = new MatchBuilder();
1204 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1205 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
1206 ipv4Match.setIpv4Destination(prefix);
1207 Ipv4Match i4m = ipv4Match.build();
1208 match.setLayer3Match(i4m);
1210 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1211 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1212 ethTypeBuilder.setType(new EtherType(0x0800L));
1213 eth.setEthernetType(ethTypeBuilder.build());
1214 match.setEthernetMatch(eth.build());
1218 private static MatchBuilder createMatch1000() {
1219 MatchBuilder match = new MatchBuilder();
1220 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1221 Ipv4Prefix prefix = new Ipv4Prefix("10.1.1.1/24");
1222 ipv4Match.setIpv4Destination(prefix);
1223 Ipv4Match i4m = ipv4Match.build();
1224 match.setLayer3Match(i4m);
1226 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1227 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1228 ethTypeBuilder.setType(new EtherType(0x0800L));
1229 eth.setEthernetType(ethTypeBuilder.build());
1230 match.setEthernetMatch(eth.build());
1237 private static MatchBuilder createMatch2() {
1238 MatchBuilder match = new MatchBuilder();
1239 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1240 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1");
1241 ipv4Match.setIpv4Source(prefix);
1242 Ipv4Match i4m = ipv4Match.build();
1243 match.setLayer3Match(i4m);
1245 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1246 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1247 ethTypeBuilder.setType(new EtherType(0x0800L));
1248 eth.setEthernetType(ethTypeBuilder.build());
1249 match.setEthernetMatch(eth.build());
1256 private static MatchBuilder createMatch3() {
1257 MatchBuilder match = new MatchBuilder();
1258 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
1259 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
1260 ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
1261 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
1262 match.setEthernetMatch(ethernetMatch.build());
1267 private static MatchBuilder createMatch33() {
1269 MatchBuilder match = new MatchBuilder();
1270 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1271 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.10");
1272 ipv4Match.setIpv4Source(prefix);
1273 Ipv4Match i4m = ipv4Match.build();
1274 match.setLayer3Match(i4m);
1276 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1277 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1278 ethTypeBuilder.setType(new EtherType(0xfffeL));
1279 eth.setEthernetType(ethTypeBuilder.build());
1280 match.setEthernetMatch(eth.build());
1284 private static MatchBuilder createInphyportMatch(NodeId nodeId) {
1285 MatchBuilder match = new MatchBuilder();
1286 match.setInPort(new NodeConnectorId(nodeId + ":202"));
1287 match.setInPhyPort(new NodeConnectorId(nodeId + ":10122"));
1291 private static MatchBuilder createEthernetMatch() {
1292 MatchBuilder match = new MatchBuilder();
1294 byte[] mask1 = new byte[] { (byte) -1, (byte) -1, 0, 0, 0, 0 };
1295 byte[] mask2 = new byte[] { (byte) -1, (byte) -1, (byte) -1, 0, 0, 0 };
1297 EthernetMatchBuilder ethmatch = new EthernetMatchBuilder(); // ethernettype
1299 EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
1300 EtherType type = new EtherType(0x0800L);
1301 ethmatch.setEthernetType(ethtype.setType(type).build());
1303 EthernetDestinationBuilder ethdest = new EthernetDestinationBuilder(); // ethernet
1306 MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
1307 ethdest.setAddress(macdest);
1308 // ethdest.setMask(mask1);
1310 ethmatch.setEthernetDestination(ethdest.build());
1312 EthernetSourceBuilder ethsrc = new EthernetSourceBuilder();
1313 MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
1314 ethsrc.setAddress(macsrc);
1315 // ethsrc.setMask(mask2);
1317 ethmatch.setEthernetSource(ethsrc.build());
1318 match.setEthernetMatch(ethmatch.build());
1326 private static MatchBuilder createL3IPv6Match() {
1327 MatchBuilder match = new MatchBuilder();
1329 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1330 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1331 ethTypeBuilder.setType(new EtherType(0x86ddL));
1332 eth.setEthernetType(ethTypeBuilder.build());
1333 match.setEthernetMatch(eth.build());
1335 Ipv6Prefix dstip6 = new Ipv6Prefix("2002::2/64");
1336 Ipv6Prefix srcip6 = new Ipv6Prefix("2001:0:0:0:0:0:0:1/56");
1337 Ipv6Address ndtarget = new Ipv6Address("2001:db8:0:1:fd97:f9f0:a810:782e");
1338 MacAddress ndsll = new MacAddress("c2:00:54:f5:00:00");
1339 MacAddress ndtll = new MacAddress("00:0c:29:0e:4c:67");
1340 Ipv6ExtHeaderBuilder nextheader = new Ipv6ExtHeaderBuilder();
1341 nextheader.setIpv6Exthdr(58);
1342 Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
1343 Ipv6FlowLabel label = new Ipv6FlowLabel(10028L);
1344 ipv6label.setIpv6Flabel(label);
1345 // ipv6label.setFlabelMask(new byte[] { 0, 1, -1, -1 });
1347 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1349 icmpv6match.setIcmpv6Type((short) 135);
1350 icmpv6match.setIcmpv6Code((short) 0);
1351 match.setIcmpv6Match(icmpv6match.build());
1353 Ipv6MatchBuilder ipv6match = new Ipv6MatchBuilder();
1354 // ipv6match.setIpv6Source(srcip6);
1355 // ipv6match.setIpv6Destination(dstip6);
1356 // ipv6match.setIpv6ExtHeader(nextheader.build());
1357 ipv6match.setIpv6NdSll(ndsll);
1358 ipv6match.setIpv6NdTll(ndtll);
1359 // ipv6match.setIpv6NdTarget(ndtarget);
1360 ipv6match.setIpv6Label(ipv6label.build());
1362 match.setLayer3Match(ipv6match.build());
1370 private static MatchBuilder createICMPv6Match() {
1372 MatchBuilder match = new MatchBuilder();
1373 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1374 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1375 ethTypeBuilder.setType(new EtherType(0x86ddL));
1376 eth.setEthernetType(ethTypeBuilder.build());
1377 match.setEthernetMatch(eth.build());
1379 IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
1380 ipmatch.setIpProtocol((short) 58);
1381 match.setIpMatch(ipmatch.build());
1383 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1385 icmpv6match.setIcmpv6Type((short) 135);
1386 icmpv6match.setIcmpv6Code((short) 1);
1387 match.setIcmpv6Match(icmpv6match.build());
1395 private static MatchBuilder createMetadataMatch() {
1396 MatchBuilder match = new MatchBuilder();
1397 byte[] metamask = new byte[] { (byte) -1, (byte) -1, (byte) -1, 0, 0, 0, (byte) 1, (byte) 1 };
1398 MetadataBuilder metadata = new MetadataBuilder(); // metadata match
1399 metadata.setMetadata(BigInteger.valueOf(500L));
1400 // metadata.setMetadataMask(metamask);
1401 match.setMetadata(metadata.build());