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; |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 6 | import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.L2SubType; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 7 | import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 8 | import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.L3SubType; |
| 9 | import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame^] | 10 | import org.onlab.packet.IpPrefix; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 11 | import org.onlab.packet.MacAddress; |
| 12 | import org.onlab.packet.VlanId; |
alshabib | 64231f6 | 2014-09-16 17:58:36 -0700 | [diff] [blame] | 13 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 14 | /** |
| 15 | * Factory class for creating various traffic treatment instructions. |
| 16 | */ |
| 17 | public final class Instructions { |
| 18 | |
| 19 | |
| 20 | // Ban construction |
| 21 | private Instructions() {} |
| 22 | |
| 23 | /** |
| 24 | * Creates an output instruction using the specified port number. This can |
| 25 | * include logical ports such as CONTROLLER, FLOOD, etc. |
| 26 | * |
| 27 | * @param number port number |
| 28 | * @return output instruction |
| 29 | */ |
| 30 | public static OutputInstruction createOutput(final PortNumber number) { |
| 31 | checkNotNull(number, "PortNumber cannot be null"); |
| 32 | return new OutputInstruction(number); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Creates a drop instruction. |
| 37 | * @return drop instruction |
| 38 | */ |
| 39 | public static DropInstruction createDrop() { |
| 40 | return new DropInstruction(); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Creates a l2 src modification. |
| 45 | * @param addr the mac address to modify to. |
| 46 | * @return a l2 modification |
| 47 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 48 | public static L2ModificationInstruction modL2Src(MacAddress addr) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 49 | checkNotNull(addr, "Src l2 address cannot be null"); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 50 | return new ModEtherInstruction(L2SubType.L2_SRC, addr); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Creates a L2 dst modification. |
| 55 | * @param addr the mac address to modify to. |
| 56 | * @return a L2 modification |
| 57 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 58 | public static L2ModificationInstruction modL2Dst(MacAddress addr) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 59 | checkNotNull(addr, "Dst l2 address cannot be null"); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 60 | return new L2ModificationInstruction.ModEtherInstruction(L2SubType.L2_DST, addr); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /** |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 64 | * Creates a Vlan id modification. |
| 65 | * @param vlanId the vlan id to modify to. |
| 66 | * @return a L2 modification |
| 67 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 68 | public static L2ModificationInstruction modVlanId(VlanId vlanId) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 69 | checkNotNull(vlanId, "VLAN id cannot be null"); |
| 70 | return new L2ModificationInstruction.ModVlanIdInstruction(vlanId); |
| 71 | } |
| 72 | |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 73 | /** |
| 74 | * Creates a Vlan pcp modification. |
| 75 | * @param vlanPcp the pcp to modify to. |
| 76 | * @return a L2 modification |
| 77 | */ |
| 78 | public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) { |
| 79 | checkNotNull(vlanPcp, "VLAN Pcp cannot be null"); |
| 80 | return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Creates a L3 src modification. |
| 85 | * @param addr the ip address to modify to. |
| 86 | * @return a L3 modification |
| 87 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame^] | 88 | public static L3ModificationInstruction modL3Src(IpPrefix addr) { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 89 | checkNotNull(addr, "Src l3 address cannot be null"); |
| 90 | return new ModIPInstruction(L3SubType.L3_SRC, addr); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Creates a L3 dst modification. |
| 95 | * @param addr the ip address to modify to. |
| 96 | * @return a L3 modification |
| 97 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame^] | 98 | public static L3ModificationInstruction modL3Dst(IpPrefix addr) { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 99 | checkNotNull(addr, "Dst l3 address cannot be null"); |
| 100 | return new ModIPInstruction(L3SubType.L3_DST, addr); |
| 101 | } |
| 102 | |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 103 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 104 | /* |
| 105 | * Output instructions |
| 106 | */ |
| 107 | |
| 108 | public static final class DropInstruction implements Instruction { |
| 109 | @Override |
| 110 | public Type type() { |
| 111 | return Type.DROP; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | |
| 116 | public static final class OutputInstruction implements Instruction { |
| 117 | private final PortNumber port; |
| 118 | |
| 119 | private OutputInstruction(PortNumber port) { |
| 120 | this.port = port; |
| 121 | } |
| 122 | |
| 123 | public PortNumber port() { |
| 124 | return port; |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public Type type() { |
| 129 | return Type.OUTPUT; |
| 130 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | } |