2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActionsBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40 import com.google.common.collect.ImmutableList;
43 * Utilities for constructing OpenFlow flows
45 public final class FlowUtils {
48 * Creates an Instance Identifier (path) for node with specified id
53 public static final InstanceIdentifier<Node>
54 createNodePath(final NodeId nodeId) {
55 return InstanceIdentifier.builder(Nodes.class)
56 .child(Node.class, new NodeKey(nodeId))
61 * Shorten's node child path to node path.
63 * @param nodeChild child of node, from which we want node path.
66 public static final InstanceIdentifier<Node>
67 getNodePath(final InstanceIdentifier<?> nodeChild) {
68 return nodeChild.firstIdentifierOf(Node.class);
73 * Creates a table path by appending table specific location to node path
79 public static final InstanceIdentifier<Table>
80 createTablePath(final InstanceIdentifier<Node> nodePath,
81 final TableKey tableKey) {
82 return nodePath.builder()
83 .augmentation(FlowCapableNode.class)
84 .child(Table.class, tableKey)
89 * Creates a table path from a node ID and table ID
95 public static final InstanceIdentifier<Table>
96 createTablePath(final NodeId nodeId,
97 final short tableId) {
98 return createNodePath(nodeId).builder()
99 .augmentation(FlowCapableNode.class)
100 .child(Table.class, new TableKey(tableId))
105 * Creates a path for particular flow, by appending flow-specific information
112 public static InstanceIdentifier<Flow>
113 createFlowPath(final InstanceIdentifier<Table> table,
114 final FlowKey flowKey) {
115 return table.child(Flow.class, flowKey);
119 * Creates a path for particular flow, by appending flow-specific information
126 public static InstanceIdentifier<Flow>
127 createFlowPath(final InstanceIdentifier<Table> table,
128 final FlowId flowId) {
129 return createFlowPath(table, new FlowKey(flowId));
132 public static Instructions gotoTable(short tableId) {
133 return new InstructionsBuilder()
134 .setInstruction(ImmutableList.of(new InstructionBuilder()
135 .setOrder(Integer.valueOf(0))
136 .setInstruction(new GoToTableCaseBuilder()
137 .setGoToTable(new GoToTableBuilder()
145 public static Instructions dropInstructions() {
146 return new InstructionsBuilder()
147 .setInstruction(ImmutableList.of(new InstructionBuilder()
148 .setOrder(Integer.valueOf(0))
149 .setInstruction(new WriteActionsCaseBuilder()
150 .setWriteActions(new WriteActionsBuilder()
151 .setAction(ImmutableList.of(new ActionBuilder()
152 .setOrder(Integer.valueOf(0))
153 .setAction(new DropActionCaseBuilder()
154 .setDropAction(new DropActionBuilder()
164 public static EthernetMatch ethernetMatch(MacAddress srcMac,
167 EthernetMatchBuilder emb = new EthernetMatchBuilder();
169 emb.setEthernetSource(new EthernetSourceBuilder()
173 emb.setEthernetDestination(new EthernetDestinationBuilder()
176 if (etherType != null)
177 emb.setEthernetType(new EthernetTypeBuilder()
178 .setType(new EtherType(etherType))