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.FlowAdded;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotification;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeExperimenterErrorNotification;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowListener;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
110 import org.opendaylight.yangtools.concepts.Registration;
111 import org.opendaylight.yangtools.yang.binding.DataObject;
112 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
113 import org.opendaylight.yangtools.yang.common.RpcResult;
114 import org.osgi.framework.BundleContext;
115 import org.slf4j.Logger;
116 import org.slf4j.LoggerFactory;
118 //import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.M
120 public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
122 private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestCommandProvider.class);
123 private DataBrokerService dataBrokerService;
124 private final BundleContext ctx;
125 private NodeBuilder testNode;
126 private ProviderContext pc;
127 private FlowBuilder testFlow;
128 private final String originalFlowName = "Foo";
129 private final FlowEventListener flowEventListener = new FlowEventListener();
130 private Registration<org.opendaylight.yangtools.yang.binding.NotificationListener> listener1Reg;
131 private Node testNode12;
132 private final String originalGroupName = "Foo";
133 private static NotificationService notificationService;
135 public OpenflowPluginBulkTransactionProvider(BundleContext ctx) {
139 public void onSessionInitiated(ProviderContext session) {
141 notificationService = session.getSALService(NotificationService.class);
142 listener1Reg = notificationService.registerNotificationListener(flowEventListener);
143 dataBrokerService = session.getSALService(DataBrokerService.class);
144 ctx.registerService(CommandProvider.class.getName(), this, null);
145 createTestFlow(createTestNode(null), null, null);
148 private NodeBuilder createTestNode(String nodeId) {
149 if (nodeId == null) {
150 nodeId = OpenflowpluginTestActivator.NODE_ID;
152 NodeRef nodeOne = createNodeRef(nodeId);
153 NodeBuilder builder = new NodeBuilder();
154 builder.setId(new NodeId(nodeId));
155 builder.setKey(new NodeKey(builder.getId()));
160 final class FlowEventListener implements SalFlowListener {
162 List<FlowAdded> addedFlows = new ArrayList<>();
163 List<FlowRemoved> removedFlows = new ArrayList<>();
164 List<FlowUpdated> updatedFlows = new ArrayList<>();
167 public void onFlowAdded(FlowAdded notification) {
168 // TODO Auto-generated method stub
172 public void onFlowRemoved(FlowRemoved notification) {
173 // TODO Auto-generated method stub
178 public void onFlowUpdated(FlowUpdated notification) {
179 // TODO Auto-generated method stub
183 public void onNodeErrorNotification(NodeErrorNotification notification) {
184 LOG.error("Error notification flow Xid........................."
185 + notification.getTransactionId().getValue());
186 LOG.debug("notification Begin-Transaction:" + notification.getTransactionUri().toString()
187 + "-----------------------------------------------------------------------------------");
191 public void onNodeExperimenterErrorNotification(NodeExperimenterErrorNotification notification) {
192 // TODO Auto-generated method stub
197 public void onSwitchFlowRemoved(SwitchFlowRemoved notification) {
198 LOG.debug("Switch flow removed : Cookies..................." + notification.getCookie().toString());
199 LOG.debug("-----------------------------------------------------------------------------------");
203 private static NodeRef createNodeRef(String string) {
204 NodeKey key = new NodeKey(new NodeId(string));
205 InstanceIdentifier<Node> path = InstanceIdentifier.builder().node(Nodes.class).node(Node.class, key)
208 return new NodeRef(path);
212 public String getHelp() {
216 private FlowBuilder createTestFlow(NodeBuilder nodeBuilder, String flowTypeArg, String tableId) {
218 FlowBuilder flow = new FlowBuilder();
221 String flowType = flowTypeArg;
222 if (flowType == null) {
229 flow.setMatch(createMatch1().build());
230 flow.setInstructions(createDecNwTtlInstructions().build());
234 flow.setMatch(createMatch2().build());
235 flow.setInstructions(createDropInstructions().build());
239 flow.setMatch(createMatch3().build());
240 flow.setInstructions(createDropInstructions().build());
244 flow.setMatch(createEthernetMatch().build());
245 flow.setInstructions(createDropInstructions().build());
249 flow.setMatch(createMatch1().build());
250 flow.setInstructions(createAppyActionInstruction().build());
254 flow.setMatch(createMatch1().build());
255 flow.setInstructions(createGotoTableInstructions().build());
259 flow.setMatch(createMatch1().build());
260 flow.setInstructions(createMeterInstructions().build());
264 flow.setMatch(createMatch1().build());
265 flow.setInstructions(createAppyActionInstruction7().build());
269 flow.setMatch(createMatch1().build());
270 flow.setInstructions(createAppyActionInstruction2().build());
274 flow.setMatch(createMatch1().build());
275 flow.setInstructions(createAppyActionInstruction3().build());
279 flow.setMatch(createMatch1().build());
280 flow.setInstructions(createAppyActionInstruction16().build());
284 flow.setMatch(createMatch1().build());
285 flow.setInstructions(createAppyActionInstruction160().build());
289 flow.setMatch(createMatch1().build());
290 flow.setInstructions(createAppyActionInstruction26().build());
294 flow.setMatch(createMatch1().build());
295 flow.setInstructions(createAppyActionInstruction27().build());
299 flow.setMatch(createMatch1().build());
300 flow.setInstructions(createAppyActionInstruction28().build());
304 flow.setMatch(createMatch1().build());
305 flow.setInstructions(createAppyActionInstruction34().build());
309 flow.setMatch(createICMPv6Match().build());
310 flow.setInstructions(createDecNwTtlInstructions().build());
314 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
315 flow.setInstructions(createDropInstructions().build());
319 flow.setMatch(createMetadataMatch().build());
320 flow.setInstructions(createDropInstructions().build());
324 flow.setMatch(createL3IPv6Match().build());
325 flow.setInstructions(createDecNwTtlInstructions().build());
329 flow.setMatch(createLLDPMatch().build());
330 flow.setInstructions(createSentToControllerInstructions().build());
335 flow.setMatch(createMatch1().build());
336 flow.setInstructions(createDropInstructions().build());
340 flow.setMatch(createMatch2().build());
341 flow.setInstructions(createDecNwTtlInstructions().build());
345 flow.setMatch(createMatch3().build());
346 flow.setInstructions(createDecNwTtlInstructions().build());
350 flow.setMatch(createEthernetMatch().build());
351 flow.setInstructions(createMeterInstructions().build());
355 flow.setMatch(createMatch1().build());
356 flow.setInstructions(createDecNwTtlInstructions().build());
360 flow.setMatch(createMatch1().build());
361 flow.setInstructions(createAppyActionInstruction7().build());
365 flow.setMatch(createEthernetMatch().build());
366 flow.setInstructions(createAppyActionInstruction6().build());
370 flow.setMatch(createEthernetMatch().build());
371 flow.setInstructions(createAppyActionInstruction7().build());
375 flow.setMatch(createMatch1().build());
376 flow.setInstructions(createAppyActionInstruction9().build());
380 flow.setMatch(createMatch1().build());
381 flow.setInstructions(createAppyActionInstruction9().build());
385 flow.setMatch(createMatch1().build());
386 flow.setInstructions(createAppyActionInstruction6().build());
390 flow.setMatch(createMatch1().build());
391 flow.setInstructions(createDecNwTtlInstructions().build());
395 flow.setMatch(createMatch1().build());
396 flow.setInstructions(createDecNwTtlInstructions().build());
400 flow.setMatch(createMatch1().build());
401 flow.setInstructions(createDecNwTtlInstructions().build());
405 flow.setMatch(createICMPv6Match().build());
406 flow.setInstructions(createDropInstructions().build());
410 flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
411 flow.setInstructions(createMeterInstructions().build());
415 flow.setMatch(createMetadataMatch().build());
416 flow.setInstructions(createAppyActionInstruction6().build());
420 flow.setMatch(createMatch1().build());
421 flow.setInstructions(createAppyActionInstruction6().build());
425 flow.setMatch(createMatch1().build());
426 flow.setInstructions(createAppyActionInstruction7().build());
430 flow.setMatch(createMatch1().build());
431 flow.setInstructions(createAppyActionInstruction8().build());
435 flow.setMatch(createMatch3().build());
436 flow.setInstructions(createMeterInstructions().build());
440 flow.setMatch(createMatch1000().build());
441 flow.setInstructions(createAppyActionInstruction6().build());
445 flow.setMatch(createMatch1000().build());
446 flow.setInstructions(createAppyActionInstruction2().build());
450 flow.setMatch(createMatch1000().build());
451 flow.setInstructions(createAppyActionInstruction3().build());
454 LOG.warn("flow type not understood: {}", flowType);
457 FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
458 if (null == flow.isBarrier()) {
459 flow.setBarrier(Boolean.FALSE);
461 // flow.setBufferId(new Long(12));
462 BigInteger value = new BigInteger("10", 10);
463 BigInteger outputPort = new BigInteger("4294967295", 10);
464 flow.setCookie(value);
465 flow.setCookieMask(value);
466 flow.setHardTimeout(0);
467 flow.setIdleTimeout(0);
468 flow.setInstallHw(false);
469 flow.setStrict(false);
470 flow.setContainerName(null);
471 flow.setFlags(new FlowModFlags(false, false, false, false, true));
472 flow.setId(new FlowId("12"));
473 flow.setTableId(getTableId(tableId));
474 flow.setOutGroup(new Long("4294967295"));
475 // set outport to OFPP_NONE (65535) to disable remove restriction for
477 flow.setOutPort(outputPort);
481 flow.setFlowName(originalFlowName + "X" + flowType);
486 private short getTableId(String tableId) {
489 table = Short.parseShort(tableId);
490 } catch (Exception ex) {
491 // ignore exception and continue with default value
498 private void createTestNode() {
499 NodeRef nodeOne = createNodeRef(OpenflowpluginTestActivator.NODE_ID);
500 NodeBuilder builder = new NodeBuilder();
501 builder.setId(new NodeId(OpenflowpluginTestActivator.NODE_ID));
502 builder.setKey(new NodeKey(builder.getId()));
503 testNode12 = builder.build();
506 public void _addFlows(CommandInterpreter ci) {
507 NodeBuilder tn = createTestNode(ci.nextArgument());
508 String flowtype = ci.nextArgument();
509 Integer flowcnt = Integer.parseInt(flowtype);
516 tf = createTestFlow(tn, "f1", "10");
517 tf1 = createTestFlow(tn, "f2", "11");
518 tf2 = createTestFlow(tn, "f3", "12");
519 tf3 = createTestFlow(tn, "f4", "13");
522 tf = createTestFlow(tn, "f3", "3");
523 tf1 = createTestFlow(tn, "f4", "4");
524 tf2 = createTestFlow(tn, "f5", "5");
525 tf3 = createTestFlow(tn, "f6", "6");
528 tf = createTestFlow(tn, "f7", "7");
529 tf1 = createTestFlow(tn, "f8", "8");
530 tf2 = createTestFlow(tn, "f9", "9");
531 tf3 = createTestFlow(tn, "f10", "10");
535 tf = createTestFlow(tn, "f23", "3");
536 tf1 = createTestFlow(tn, "f34", "4");
537 tf2 = createTestFlow(tn, "f35", "5");
538 tf3 = createTestFlow(tn, "f36", "6");
543 tf = createTestFlow(tn, "f230", "3");
544 tf1 = createTestFlow(tn, "f34", "4");
545 tf2 = createTestFlow(tn, "f35", "5");
546 tf3 = createTestFlow(tn, "f36", "6");
550 tf = createTestFlow(tn, "f42", "42");
551 tf1 = createTestFlow(tn, "f43", "43");
552 tf2 = createTestFlow(tn, "f44", "44");
553 tf3 = createTestFlow(tn, "f45", "45");
556 writeFlow(ci, tf, tf1, tf2, tf3, tn);
559 private InstanceIdentifier<Node> nodeBuilderToInstanceId(NodeBuilder node) {
560 return InstanceIdentifier.builder(Nodes.class).child(Node.class, node.getKey()).toInstance();
563 public void _modifyFlows(CommandInterpreter ci) {
564 NodeBuilder tn = createTestNode(ci.nextArgument());
565 String flowtype = ci.nextArgument();
566 Integer flowcnt = Integer.parseInt(flowtype);
573 tf = createTestFlow(tn, "f82", "10");
574 tf1 = createTestFlow(tn, "f83", "11");
575 tf2 = createTestFlow(tn, "f84", "12");
576 tf3 = createTestFlow(tn, "f85", "13");
579 tf = createTestFlow(tn, "f700", "3");
580 tf1 = createTestFlow(tn, "f4", "4");
581 tf2 = createTestFlow(tn, "f900", "5");
582 tf3 = createTestFlow(tn, "f86", "6");
586 tf = createTestFlow(tn, "f91", "7");
587 tf1 = createTestFlow(tn, "f92", "8");
588 tf2 = createTestFlow(tn, "f93", "9");
589 tf3 = createTestFlow(tn, "f94", "10");
593 tf = createTestFlow(tn, "f230", "3");
594 tf1 = createTestFlow(tn, "f99", "4");
595 tf2 = createTestFlow(tn, "f100", "5");
596 tf3 = createTestFlow(tn, "f101", "6");
600 tf = createTestFlow(tn, "f23", "3");
601 tf1 = createTestFlow(tn, "f99", "4");
602 tf2 = createTestFlow(tn, "f100", "5");
603 tf3 = createTestFlow(tn, "f101", "6");
607 tf = createTestFlow(tn, "f87", "12");
608 tf1 = createTestFlow(tn, "f88", "13");
609 tf2 = createTestFlow(tn, "f89", "14");
610 tf3 = createTestFlow(tn, "f90", "15");
614 writeFlow(ci, tf, tf1, tf2, tf3, tn);
618 public void _removeFlows(CommandInterpreter ci) {
619 DataModification<InstanceIdentifier<?>, DataObject> modification = dataBrokerService.beginTransaction();
620 NodeBuilder tn = createTestNode(ci.nextArgument());
621 String flowtype = ci.nextArgument();
622 Integer flowcnt = Integer.parseInt(flowtype);
623 FlowBuilder tf = null;
624 FlowBuilder tf1 = null;
625 FlowBuilder tf2 = null;
626 FlowBuilder tf3 = null;
630 tf = createTestFlow(tn, "f1", "10");
631 tf1 = createTestFlow(tn, "f2", "11");
632 tf2 = createTestFlow(tn, "f3", "12");
633 tf3 = createTestFlow(tn, "f4", "13");
637 tf = createTestFlow(tn, "f82", "10");
638 tf1 = createTestFlow(tn, "f83", "11");
639 tf2 = createTestFlow(tn, "f84", "12");
640 tf3 = createTestFlow(tn, "f85", "13");
644 tf = createTestFlow(tn, "f3", "3");
645 tf1 = createTestFlow(tn, "f4", "4");
646 tf2 = createTestFlow(tn, "f5", "5");
647 tf3 = createTestFlow(tn, "f6", "6");
651 tf = createTestFlow(tn, "f700", "3");
652 tf1 = createTestFlow(tn, "f4", "4");
653 tf2 = createTestFlow(tn, "f900", "5");
654 tf3 = createTestFlow(tn, "f86", "6");
658 tf = createTestFlow(tn, "f7", "7");
659 tf1 = createTestFlow(tn, "f8", "8");
660 tf2 = createTestFlow(tn, "f9", "9");
661 tf3 = createTestFlow(tn, "f10", "10");
665 tf = createTestFlow(tn, "f91", "7");
666 tf1 = createTestFlow(tn, "f92", "8");
667 tf2 = createTestFlow(tn, "f93", "9");
668 tf3 = createTestFlow(tn, "f94", "10");
672 tf = createTestFlow(tn, "f23", "3");
673 tf1 = createTestFlow(tn, "f34", "4");
674 tf2 = createTestFlow(tn, "f35", "5");
675 tf3 = createTestFlow(tn, "f36", "6");
680 tf = createTestFlow(tn, "f23", "3");
681 tf1 = createTestFlow(tn, "f99", "4");
682 tf2 = createTestFlow(tn, "f100", "5");
683 tf3 = createTestFlow(tn, "f101", "6");
687 tf = createTestFlow(tn, "f700", "7");
688 tf1 = createTestFlow(tn, "f230", "23");
689 tf2 = createTestFlow(tn, "f900", "9");
690 tf3 = createTestFlow(tn, "f1000", "10");
694 InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(Node.class, tn.getKey())
695 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
696 .child(Flow.class, tf.getKey()).build();
697 modification.removeOperationalData(path1);
698 modification.removeConfigurationData(nodeBuilderToInstanceId(tn));
699 modification.removeConfigurationData(path1);
700 InstanceIdentifier<Flow> path2 = InstanceIdentifier.builder(Nodes.class).child(Node.class, tn.getKey())
701 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf1.getTableId()))
702 .child(Flow.class, tf1.getKey()).build();
703 modification.removeOperationalData(path2);
704 modification.removeConfigurationData(nodeBuilderToInstanceId(tn));
705 modification.removeConfigurationData(path2);
707 InstanceIdentifier<Flow> path3 = InstanceIdentifier.builder(Nodes.class).child(Node.class, tn.getKey())
708 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf2.getTableId()))
709 .child(Flow.class, tf2.getKey()).build();
710 modification.removeOperationalData(path3);
711 modification.removeConfigurationData(nodeBuilderToInstanceId(tn));
712 modification.removeConfigurationData(path3);
713 InstanceIdentifier<Flow> path4 = InstanceIdentifier.builder(Nodes.class).child(Node.class, tn.getKey())
714 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf3.getTableId()))
715 .child(Flow.class, tf3.getKey()).build();
716 modification.removeOperationalData(path4);
717 modification.removeConfigurationData(nodeBuilderToInstanceId(tn));
718 modification.removeConfigurationData(path4);
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);
732 private void writeFlow(CommandInterpreter ci, FlowBuilder flow, FlowBuilder flow1, FlowBuilder flow2,
733 FlowBuilder flow3, NodeBuilder nodeBuilder) {
734 DataModification<InstanceIdentifier<?>, DataObject> modification = dataBrokerService.beginTransaction();
735 InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class)
736 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
737 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey()).build();
738 modification.putOperationalData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
739 modification.putOperationalData(path1, flow.build());
740 modification.putConfigurationData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
741 modification.putConfigurationData(path1, flow.build());
742 InstanceIdentifier<Flow> path2 = InstanceIdentifier.builder(Nodes.class)
743 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
744 .child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.getKey()).build();
745 modification.putOperationalData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
746 modification.putOperationalData(path2, flow1.build());
747 modification.putConfigurationData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
748 modification.putConfigurationData(path2, flow1.build());
750 InstanceIdentifier<Flow> path3 = InstanceIdentifier.builder(Nodes.class)
751 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
752 .child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.getKey()).build();
753 modification.putOperationalData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
754 modification.putOperationalData(path3, flow2.build());
755 modification.putConfigurationData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
756 modification.putConfigurationData(path3, flow2.build());
758 InstanceIdentifier<Flow> path4 = InstanceIdentifier.builder(Nodes.class)
759 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
760 .child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.getKey()).build();
761 modification.putOperationalData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
762 modification.putOperationalData(path4, flow3.build());
763 modification.putConfigurationData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
764 modification.putConfigurationData(path4, flow3.build());
765 Future<RpcResult<TransactionStatus>> commitFuture = modification.commit();
767 RpcResult<TransactionStatus> result = commitFuture.get();
768 TransactionStatus status = result.getResult();
769 ci.println("Status of Flow Data Loaded Transaction: " + status);
771 } catch (InterruptedException e) {
772 LOG.error(e.getMessage(), e);
773 } catch (ExecutionException e) {
774 LOG.error(e.getMessage(), e);
781 private static InstructionsBuilder createDecNwTtlInstructions() {
782 DecNwTtlBuilder ta = new DecNwTtlBuilder();
783 DecNwTtl decNwTtl = ta.build();
784 ActionBuilder ab = new ActionBuilder();
785 ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
787 // Add our drop action to a list
788 List<Action> actionList = new ArrayList<Action>();
789 actionList.add(ab.build());
791 // Create an Apply Action
792 ApplyActionsBuilder aab = new ApplyActionsBuilder();
793 aab.setAction(actionList);
795 // Wrap our Apply Action in an Instruction
796 InstructionBuilder ib = new InstructionBuilder();
797 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
798 ib.setKey(new InstructionKey(0));
801 // Put our Instruction in a list of Instructions
802 InstructionsBuilder isb = new InstructionsBuilder();
803 List<Instruction> instructions = new ArrayList<Instruction>();
804 instructions.add(ib.build());
805 isb.setInstruction(instructions);
812 private static InstructionsBuilder createMeterInstructions() {
814 MeterBuilder aab = new MeterBuilder();
815 aab.setMeterId(new MeterId(new Long(1)));
817 InstructionBuilder ib = new InstructionBuilder();
818 ib.setInstruction(new MeterCaseBuilder().setMeter(aab.build()).build());
820 // Put our Instruction in a list of Instructions
821 InstructionsBuilder isb = new InstructionsBuilder();
822 List<Instruction> instructions = new ArrayList<Instruction>();
823 instructions.add(ib.build());
824 isb.setInstruction(instructions);
828 private static InstructionsBuilder createGotoTableInstructions() {
830 GoToTableBuilder aab = new GoToTableBuilder();
831 aab.setTableId((short) 2);
833 InstructionBuilder ib = new InstructionBuilder();
834 ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(aab.build()).build());
836 // Put our Instruction in a list of Instructions
837 InstructionsBuilder isb = new InstructionsBuilder();
838 List<Instruction> instructions = new ArrayList<Instruction>();
839 instructions.add(ib.build());
840 isb.setInstruction(instructions);
844 private static InstructionsBuilder createDropInstructions() {
845 DropActionBuilder dab = new DropActionBuilder();
846 DropAction dropAction = dab.build();
847 ActionBuilder ab = new ActionBuilder();
848 ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
850 // Add our drop action to a list
851 List<Action> actionList = new ArrayList<Action>();
852 actionList.add(ab.build());
854 // Create an Apply Action
855 ApplyActionsBuilder aab = new ApplyActionsBuilder();
856 aab.setAction(actionList);
858 // Wrap our Apply Action in an Instruction
859 InstructionBuilder ib = new InstructionBuilder();
860 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
862 // Put our Instruction in a list of Instructions
863 InstructionsBuilder isb = new InstructionsBuilder();
864 List<Instruction> instructions = new ArrayList<Instruction>();
865 instructions.add(ib.build());
866 isb.setInstruction(instructions);
870 private static InstructionsBuilder createAppyActionInstruction() {
872 List<Action> actionList = new ArrayList<Action>();
873 ActionBuilder ab = new ActionBuilder();
874 ControllerActionBuilder controller = new ControllerActionBuilder();
875 controller.setMaxLength(5);
876 ab.setAction(new ControllerActionCaseBuilder().setControllerAction(controller.build()).build());
877 actionList.add(ab.build());
878 // Create an Apply Action
879 ApplyActionsBuilder aab = new ApplyActionsBuilder();
880 aab.setAction(actionList);
882 // Wrap our Apply Action in an Instruction
883 InstructionBuilder ib = new InstructionBuilder();
884 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
886 // Put our Instruction in a list of Instructions
887 InstructionsBuilder isb = new InstructionsBuilder();
888 List<Instruction> instructions = new ArrayList<Instruction>();
889 instructions.add(ib.build());
890 isb.setInstruction(instructions);
894 private static InstructionsBuilder createSentToControllerInstructions() {
895 List<Action> actionList = new ArrayList<Action>();
896 ActionBuilder ab = new ActionBuilder();
898 OutputActionBuilder output = new OutputActionBuilder();
899 output.setMaxLength(new Integer(0xffff));
900 Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
901 output.setOutputNodeConnector(value);
902 ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
904 ab.setKey(new ActionKey(0));
905 actionList.add(ab.build());
906 // Create an Apply Action
907 ApplyActionsBuilder aab = new ApplyActionsBuilder();
908 aab.setAction(actionList);
910 // Wrap our Apply Action in an Instruction
911 InstructionBuilder ib = new InstructionBuilder();
912 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
914 ib.setKey(new InstructionKey(0));
916 // Put our Instruction in a list of Instructions
917 InstructionsBuilder isb = new InstructionsBuilder();
918 List<Instruction> instructions = new ArrayList<Instruction>();
919 instructions.add(ib.build());
920 isb.setInstruction(instructions);
924 private static InstructionsBuilder createAppyActionInstruction2() {
926 List<Action> actionList = new ArrayList<Action>();
927 ActionBuilder ab = new ActionBuilder();
929 PushMplsActionBuilder push = new PushMplsActionBuilder();
930 push.setEthernetType(new Integer(0x8847));
931 ab.setAction(new PushMplsActionCaseBuilder().setPushMplsAction(push.build()).build());
932 actionList.add(ab.build());
933 // Create an Apply Action
934 ApplyActionsBuilder aab = new ApplyActionsBuilder();
935 aab.setAction(actionList);
937 // Wrap our Apply Action in an Instruction
938 InstructionBuilder ib = new InstructionBuilder();
939 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
941 // Put our Instruction in a list of Instructions
942 InstructionsBuilder isb = new InstructionsBuilder();
943 List<Instruction> instructions = new ArrayList<Instruction>();
944 instructions.add(ib.build());
945 isb.setInstruction(instructions);
949 private static InstructionsBuilder createAppyActionInstruction3() {
951 List<Action> actionList = new ArrayList<Action>();
952 ActionBuilder ab = new ActionBuilder();
954 PushPbbActionBuilder pbb = new PushPbbActionBuilder();
955 pbb.setEthernetType(new Integer(0x88E7));
956 ab.setAction(new PushPbbActionCaseBuilder().setPushPbbAction(pbb.build()).build());
957 actionList.add(ab.build());
958 // Create an Apply Action
959 ApplyActionsBuilder aab = new ApplyActionsBuilder();
960 aab.setAction(actionList);
962 // Wrap our Apply Action in an Instruction
963 InstructionBuilder ib = new InstructionBuilder();
964 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
966 // Put our Instruction in a list of Instructions
967 InstructionsBuilder isb = new InstructionsBuilder();
968 List<Instruction> instructions = new ArrayList<Instruction>();
969 instructions.add(ib.build());
970 isb.setInstruction(instructions);
974 private static InstructionsBuilder createAppyActionInstruction6() {
976 List<Action> actionList = new ArrayList<Action>();
977 ActionBuilder ab = new ActionBuilder();
979 SetDlSrcActionBuilder src = new SetDlSrcActionBuilder();
980 src.setAddress(new MacAddress("00:05:b9:7c:81:5f"));
981 ab.setAction(new SetDlSrcActionCaseBuilder().setSetDlSrcAction(src.build()).build());
982 actionList.add(ab.build());
984 // Create an Apply Action
985 ApplyActionsBuilder aab = new ApplyActionsBuilder();
986 aab.setAction(actionList);
988 // Wrap our Apply Action in an Instruction
989 InstructionBuilder ib = new InstructionBuilder();
990 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
992 // Put our Instruction in a list of Instructions
993 InstructionsBuilder isb = new InstructionsBuilder();
994 List<Instruction> instructions = new ArrayList<Instruction>();
995 instructions.add(ib.build());
996 isb.setInstruction(instructions);
1000 private static InstructionsBuilder createAppyActionInstruction7() {
1002 List<Action> actionList = new ArrayList<Action>();
1003 ActionBuilder ab = new ActionBuilder();
1005 SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
1006 VlanId a = new VlanId(4012);
1008 ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.build()).build());
1009 actionList.add(ab.build());
1010 // Create an Apply Action
1011 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1012 aab.setAction(actionList);
1014 // Wrap our Apply Action in an Instruction
1015 InstructionBuilder ib = new InstructionBuilder();
1016 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1018 // Put our Instruction in a list of Instructions
1019 InstructionsBuilder isb = new InstructionsBuilder();
1020 List<Instruction> instructions = new ArrayList<Instruction>();
1021 instructions.add(ib.build());
1022 isb.setInstruction(instructions);
1026 private static InstructionsBuilder createAppyActionInstruction8() {
1028 List<Action> actionList = new ArrayList<Action>();
1029 ActionBuilder ab = new ActionBuilder();
1031 SetVlanPcpActionBuilder pcp = new SetVlanPcpActionBuilder();
1032 VlanPcp pcp1 = new VlanPcp((short) 2);
1033 pcp.setVlanPcp(pcp1);
1034 ab.setAction(new SetVlanPcpActionCaseBuilder().setSetVlanPcpAction(pcp.build()).build());
1035 actionList.add(ab.build());
1036 // Create an Apply Action
1037 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1038 aab.setAction(actionList);
1040 // Wrap our Apply Action in an Instruction
1041 InstructionBuilder ib = new InstructionBuilder();
1042 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1044 // Put our Instruction in a list of Instructions
1045 InstructionsBuilder isb = new InstructionsBuilder();
1046 List<Instruction> instructions = new ArrayList<Instruction>();
1047 instructions.add(ib.build());
1048 isb.setInstruction(instructions);
1052 private static InstructionsBuilder createAppyActionInstruction9() {
1054 List<Action> actionList = new ArrayList<Action>();
1055 ActionBuilder ab = new ActionBuilder();
1057 CopyTtlInBuilder ttlin = new CopyTtlInBuilder();
1058 ab.setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(ttlin.build()).build());
1059 actionList.add(ab.build());
1060 // Create an Apply Action
1061 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1062 aab.setAction(actionList);
1064 // Wrap our Apply Action in an Instruction
1065 InstructionBuilder ib = new InstructionBuilder();
1066 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1068 // Put our Instruction in a list of Instructions
1069 InstructionsBuilder isb = new InstructionsBuilder();
1070 List<Instruction> instructions = new ArrayList<Instruction>();
1071 instructions.add(ib.build());
1072 isb.setInstruction(instructions);
1076 private static InstructionsBuilder createAppyActionInstruction16() {
1078 List<Action> actionList = new ArrayList<Action>();
1079 ActionBuilder ab = new ActionBuilder();
1081 GroupActionBuilder groupActionB = new GroupActionBuilder();
1082 groupActionB.setGroupId(1L);
1083 groupActionB.setGroup("0");
1084 ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
1085 actionList.add(ab.build());
1087 // Create an Apply Action
1088 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1089 aab.setAction(actionList);
1091 // Wrap our Apply Action in an Instruction
1092 InstructionBuilder ib = new InstructionBuilder();
1093 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1095 // Put our Instruction in a list of Instructions
1096 InstructionsBuilder isb = new InstructionsBuilder();
1097 List<Instruction> instructions = new ArrayList<Instruction>();
1098 instructions.add(ib.build());
1099 isb.setInstruction(instructions);
1103 private static InstructionsBuilder createAppyActionInstruction160() {
1105 List<Action> actionList = new ArrayList<Action>();
1106 ActionBuilder ab = new ActionBuilder();
1108 FloodAllActionBuilder fldall = new FloodAllActionBuilder();
1109 ab.setAction(new FloodAllActionCaseBuilder().setFloodAllAction(fldall.build()).build());
1110 actionList.add(ab.build());
1111 // Create an Apply Action
1112 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1113 aab.setAction(actionList);
1115 // Wrap our Apply Action in an Instruction
1116 InstructionBuilder ib = new InstructionBuilder();
1117 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1119 // Put our Instruction in a list of Instructions
1120 InstructionsBuilder isb = new InstructionsBuilder();
1121 List<Instruction> instructions = new ArrayList<Instruction>();
1122 instructions.add(ib.build());
1123 isb.setInstruction(instructions);
1127 private static InstructionsBuilder createAppyActionInstruction26() {
1129 List<Action> actionList = new ArrayList<Action>();
1130 ActionBuilder ab = new ActionBuilder();
1132 SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
1133 Ipv4Builder ipdst = new Ipv4Builder();
1134 Ipv4Prefix prefixdst = new Ipv4Prefix("10.0.0.21/24");
1135 ipdst.setIpv4Address(prefixdst);
1136 setNwDstActionBuilder.setAddress(ipdst.build());
1137 ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
1138 actionList.add(ab.build());
1140 // Create an Apply Action
1141 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1142 aab.setAction(actionList);
1144 // Wrap our Apply Action in an Instruction
1145 InstructionBuilder ib = new InstructionBuilder();
1146 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1148 // Put our Instruction in a list of Instructions
1149 InstructionsBuilder isb = new InstructionsBuilder();
1150 List<Instruction> instructions = new ArrayList<Instruction>();
1151 instructions.add(ib.build());
1152 isb.setInstruction(instructions);
1156 private static InstructionsBuilder createAppyActionInstruction27() {
1158 List<Action> actionList = new ArrayList<Action>();
1159 ActionBuilder ab = new ActionBuilder();
1161 SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
1162 Ipv4Builder ipsrc = new Ipv4Builder();
1163 Ipv4Prefix prefixsrc = new Ipv4Prefix("10.0.23.21/24");
1164 ipsrc.setIpv4Address(prefixsrc);
1165 setNwsrcActionBuilder.setAddress(ipsrc.build());
1166 ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
1167 actionList.add(ab.build());
1169 // Create an Apply Action
1170 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1171 aab.setAction(actionList);
1173 // Wrap our Apply Action in an Instruction
1174 InstructionBuilder ib = new InstructionBuilder();
1175 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1177 // Put our Instruction in a list of Instructions
1178 InstructionsBuilder isb = new InstructionsBuilder();
1179 List<Instruction> instructions = new ArrayList<Instruction>();
1180 instructions.add(ib.build());
1181 isb.setInstruction(instructions);
1185 private static InstructionsBuilder createAppyActionInstruction28() {
1187 List<Action> actionList = new ArrayList<Action>();
1188 ActionBuilder ab = new ActionBuilder();
1190 SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
1191 setNwTosActionBuilder.setTos(8);
1192 ab.setAction(new SetNwTosActionCaseBuilder().setSetNwTosAction(setNwTosActionBuilder.build()).build());
1193 actionList.add(ab.build());
1194 // Create an Apply Action
1195 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1196 aab.setAction(actionList);
1198 // Wrap our Apply Action in an Instruction
1199 InstructionBuilder ib = new InstructionBuilder();
1200 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1202 // Put our Instruction in a list of Instructions
1203 InstructionsBuilder isb = new InstructionsBuilder();
1204 List<Instruction> instructions = new ArrayList<Instruction>();
1205 instructions.add(ib.build());
1206 isb.setInstruction(instructions);
1210 private static InstructionsBuilder createAppyActionInstruction34() {
1212 List<Action> actionList = new ArrayList<Action>();
1213 ActionBuilder ab = new ActionBuilder();
1215 SwPathActionBuilder swPathAction = new SwPathActionBuilder();
1216 ab.setAction(new SwPathActionCaseBuilder().setSwPathAction(swPathAction.build()).build());
1217 actionList.add(ab.build());
1219 // Create an Apply Action
1220 ApplyActionsBuilder aab = new ApplyActionsBuilder();
1221 aab.setAction(actionList);
1223 // Wrap our Apply Action in an Instruction
1224 InstructionBuilder ib = new InstructionBuilder();
1225 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
1227 // Put our Instruction in a list of Instructions
1228 InstructionsBuilder isb = new InstructionsBuilder();
1229 List<Instruction> instructions = new ArrayList<Instruction>();
1230 instructions.add(ib.build());
1231 isb.setInstruction(instructions);
1235 private static MatchBuilder createLLDPMatch() {
1236 MatchBuilder match = new MatchBuilder();
1237 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1238 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1239 ethTypeBuilder.setType(new EtherType(0x88ccL));
1240 eth.setEthernetType(ethTypeBuilder.build());
1241 match.setEthernetMatch(eth.build());
1248 private static MatchBuilder createMatch1() {
1249 MatchBuilder match = new MatchBuilder();
1250 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1251 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
1252 ipv4Match.setIpv4Destination(prefix);
1253 Ipv4Match i4m = ipv4Match.build();
1254 match.setLayer3Match(i4m);
1256 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1257 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1258 ethTypeBuilder.setType(new EtherType(0x0800L));
1259 eth.setEthernetType(ethTypeBuilder.build());
1260 match.setEthernetMatch(eth.build());
1264 private static MatchBuilder createMatch1000() {
1265 MatchBuilder match = new MatchBuilder();
1266 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1267 Ipv4Prefix prefix = new Ipv4Prefix("10.1.1.1/24");
1268 ipv4Match.setIpv4Destination(prefix);
1269 Ipv4Match i4m = ipv4Match.build();
1270 match.setLayer3Match(i4m);
1272 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1273 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1274 ethTypeBuilder.setType(new EtherType(0x0800L));
1275 eth.setEthernetType(ethTypeBuilder.build());
1276 match.setEthernetMatch(eth.build());
1283 private static MatchBuilder createMatch2() {
1284 MatchBuilder match = new MatchBuilder();
1285 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1286 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1");
1287 ipv4Match.setIpv4Source(prefix);
1288 Ipv4Match i4m = ipv4Match.build();
1289 match.setLayer3Match(i4m);
1291 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1292 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1293 ethTypeBuilder.setType(new EtherType(0x0800L));
1294 eth.setEthernetType(ethTypeBuilder.build());
1295 match.setEthernetMatch(eth.build());
1302 private static MatchBuilder createMatch3() {
1303 MatchBuilder match = new MatchBuilder();
1304 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
1305 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
1306 ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
1307 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
1308 match.setEthernetMatch(ethernetMatch.build());
1313 private static MatchBuilder createMatch33() {
1315 MatchBuilder match = new MatchBuilder();
1316 Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
1317 Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.10");
1318 ipv4Match.setIpv4Source(prefix);
1319 Ipv4Match i4m = ipv4Match.build();
1320 match.setLayer3Match(i4m);
1322 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1323 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1324 ethTypeBuilder.setType(new EtherType(0xfffeL));
1325 eth.setEthernetType(ethTypeBuilder.build());
1326 match.setEthernetMatch(eth.build());
1330 private static MatchBuilder createInphyportMatch(NodeId nodeId) {
1331 MatchBuilder match = new MatchBuilder();
1332 match.setInPort(new NodeConnectorId(nodeId + ":202"));
1333 match.setInPhyPort(new NodeConnectorId(nodeId + ":10122"));
1337 private static MatchBuilder createEthernetMatch() {
1338 MatchBuilder match = new MatchBuilder();
1340 byte[] mask1 = new byte[] { (byte) -1, (byte) -1, 0, 0, 0, 0 };
1341 byte[] mask2 = new byte[] { (byte) -1, (byte) -1, (byte) -1, 0, 0, 0 };
1343 EthernetMatchBuilder ethmatch = new EthernetMatchBuilder(); // ethernettype
1345 EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
1346 EtherType type = new EtherType(0x0800L);
1347 ethmatch.setEthernetType(ethtype.setType(type).build());
1349 EthernetDestinationBuilder ethdest = new EthernetDestinationBuilder(); // ethernet
1352 MacAddress macdest = new MacAddress("ff:ff:ff:ff:ff:ff");
1353 ethdest.setAddress(macdest);
1354 // ethdest.setMask(mask1);
1356 ethmatch.setEthernetDestination(ethdest.build());
1358 EthernetSourceBuilder ethsrc = new EthernetSourceBuilder();
1359 MacAddress macsrc = new MacAddress("00:00:00:00:23:ae");
1360 ethsrc.setAddress(macsrc);
1361 // ethsrc.setMask(mask2);
1363 ethmatch.setEthernetSource(ethsrc.build());
1364 match.setEthernetMatch(ethmatch.build());
1372 private static MatchBuilder createL3IPv6Match() {
1373 MatchBuilder match = new MatchBuilder();
1375 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1376 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1377 ethTypeBuilder.setType(new EtherType(0x86ddL));
1378 eth.setEthernetType(ethTypeBuilder.build());
1379 match.setEthernetMatch(eth.build());
1381 Ipv6Prefix dstip6 = new Ipv6Prefix("2002::2/64");
1382 Ipv6Prefix srcip6 = new Ipv6Prefix("2001:0:0:0:0:0:0:1/56");
1383 Ipv6Address ndtarget = new Ipv6Address("2001:db8:0:1:fd97:f9f0:a810:782e");
1384 MacAddress ndsll = new MacAddress("c2:00:54:f5:00:00");
1385 MacAddress ndtll = new MacAddress("00:0c:29:0e:4c:67");
1386 Ipv6ExtHeaderBuilder nextheader = new Ipv6ExtHeaderBuilder();
1387 nextheader.setIpv6Exthdr(58);
1388 Ipv6LabelBuilder ipv6label = new Ipv6LabelBuilder();
1389 Ipv6FlowLabel label = new Ipv6FlowLabel(10028L);
1390 ipv6label.setIpv6Flabel(label);
1391 // ipv6label.setFlabelMask(new byte[] { 0, 1, -1, -1 });
1393 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1395 icmpv6match.setIcmpv6Type((short) 135);
1396 icmpv6match.setIcmpv6Code((short) 0);
1397 match.setIcmpv6Match(icmpv6match.build());
1399 Ipv6MatchBuilder ipv6match = new Ipv6MatchBuilder();
1400 // ipv6match.setIpv6Source(srcip6);
1401 // ipv6match.setIpv6Destination(dstip6);
1402 // ipv6match.setIpv6ExtHeader(nextheader.build());
1403 ipv6match.setIpv6NdSll(ndsll);
1404 ipv6match.setIpv6NdTll(ndtll);
1405 // ipv6match.setIpv6NdTarget(ndtarget);
1406 ipv6match.setIpv6Label(ipv6label.build());
1408 match.setLayer3Match(ipv6match.build());
1416 private static MatchBuilder createICMPv6Match() {
1418 MatchBuilder match = new MatchBuilder();
1419 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1420 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1421 ethTypeBuilder.setType(new EtherType(0x86ddL));
1422 eth.setEthernetType(ethTypeBuilder.build());
1423 match.setEthernetMatch(eth.build());
1425 IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version
1426 ipmatch.setIpProtocol((short) 58);
1427 match.setIpMatch(ipmatch.build());
1429 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder(); // icmpv6
1431 icmpv6match.setIcmpv6Type((short) 135);
1432 icmpv6match.setIcmpv6Code((short) 1);
1433 match.setIcmpv6Match(icmpv6match.build());
1441 private static MatchBuilder createMetadataMatch() {
1442 MatchBuilder match = new MatchBuilder();
1443 byte[] metamask = new byte[] { (byte) -1, (byte) -1, (byte) -1, 0, 0, 0, (byte) 1, (byte) 1 };
1444 MetadataBuilder metadata = new MetadataBuilder(); // metadata match
1445 metadata.setMetadata(BigInteger.valueOf(500L));
1446 // metadata.setMetadataMask(metamask);
1447 match.setMetadata(metadata.build());