alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.net.flow.instructions; |
| 2 | |
| 3 | import static com.google.common.base.Preconditions.checkNotNull; |
| 4 | |
| 5 | import org.onlab.onos.net.PortNumber; |
| 6 | import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; |
| 7 | import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.SubType; |
| 8 | import org.onlab.packet.MACAddress; |
| 9 | /** |
| 10 | * Factory class for creating various traffic treatment instructions. |
| 11 | */ |
| 12 | public final class Instructions { |
| 13 | |
| 14 | |
| 15 | // Ban construction |
| 16 | private Instructions() {} |
| 17 | |
| 18 | /** |
| 19 | * Creates an output instruction using the specified port number. This can |
| 20 | * include logical ports such as CONTROLLER, FLOOD, etc. |
| 21 | * |
| 22 | * @param number port number |
| 23 | * @return output instruction |
| 24 | */ |
| 25 | public static OutputInstruction createOutput(final PortNumber number) { |
| 26 | checkNotNull(number, "PortNumber cannot be null"); |
| 27 | return new OutputInstruction(number); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Creates a drop instruction. |
| 32 | * @return drop instruction |
| 33 | */ |
| 34 | public static DropInstruction createDrop() { |
| 35 | return new DropInstruction(); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Creates a l2 src modification. |
| 40 | * @param addr the mac address to modify to. |
| 41 | * @return a l2 modification |
| 42 | */ |
| 43 | public static L2ModificationInstruction modL2Src(MACAddress addr) { |
| 44 | checkNotNull(addr, "Src l2 address cannot be null"); |
| 45 | return new ModEtherInstruction(SubType.L2_SRC, addr); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Creates a L2 dst modification. |
| 50 | * @param addr the mac address to modify to. |
| 51 | * @return a L2 modification |
| 52 | */ |
| 53 | public static L2ModificationInstruction modL2Dst(MACAddress addr) { |
| 54 | checkNotNull(addr, "Dst l2 address cannot be null"); |
| 55 | return new L2ModificationInstruction.ModEtherInstruction(SubType.L2_DST, addr); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Creates a L2 type modification. |
| 60 | * @param l2Type the type to change to |
| 61 | * @return a L2 modifications |
| 62 | */ |
| 63 | public static L2ModificationInstruction modL2Type(Short l2Type) { |
| 64 | checkNotNull(l2Type, "L2 type cannot be null"); |
| 65 | return new L2ModificationInstruction.ModEtherTypeInstruction(l2Type); |
| 66 | } |
| 67 | |
| 68 | public static L2ModificationInstruction modVlanId(Short vlanId) { |
| 69 | checkNotNull(vlanId, "VLAN id cannot be null"); |
| 70 | return new L2ModificationInstruction.ModVlanIdInstruction(vlanId); |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | * Output instructions |
| 75 | */ |
| 76 | |
| 77 | public static final class DropInstruction implements Instruction { |
| 78 | @Override |
| 79 | public Type type() { |
| 80 | return Type.DROP; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | |
| 85 | public static final class OutputInstruction implements Instruction { |
| 86 | private final PortNumber port; |
| 87 | |
| 88 | private OutputInstruction(PortNumber port) { |
| 89 | this.port = port; |
| 90 | } |
| 91 | |
| 92 | public PortNumber port() { |
| 93 | return port; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public Type type() { |
| 98 | return Type.OUTPUT; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | } |