Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow.instructions; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 18 | import org.onlab.packet.Ethernet; |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.MacAddress; |
| 21 | import org.onlab.packet.MplsLabel; |
| 22 | import org.onlab.packet.VlanId; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 23 | import org.onosproject.core.GroupId; |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 24 | import org.onosproject.net.IndexedLambda; |
| 25 | import org.onosproject.net.Lambda; |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 26 | import org.onosproject.net.OchSignal; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 27 | import org.onosproject.net.PortNumber; |
| 28 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType; |
| 29 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 30 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType; |
| 32 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 33 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 34 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 35 | |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 36 | import java.util.Objects; |
| 37 | |
| 38 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 39 | import static com.google.common.base.Preconditions.checkNotNull; |
alshabib | 64231f6 | 2014-09-16 17:58:36 -0700 | [diff] [blame] | 40 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 41 | /** |
| 42 | * Factory class for creating various traffic treatment instructions. |
| 43 | */ |
| 44 | public final class Instructions { |
| 45 | |
| 46 | |
| 47 | // Ban construction |
| 48 | private Instructions() {} |
| 49 | |
| 50 | /** |
| 51 | * Creates an output instruction using the specified port number. This can |
| 52 | * include logical ports such as CONTROLLER, FLOOD, etc. |
| 53 | * |
| 54 | * @param number port number |
| 55 | * @return output instruction |
| 56 | */ |
| 57 | public static OutputInstruction createOutput(final PortNumber number) { |
| 58 | checkNotNull(number, "PortNumber cannot be null"); |
| 59 | return new OutputInstruction(number); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Creates a drop instruction. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 64 | * |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 65 | * @return drop instruction |
| 66 | */ |
| 67 | public static DropInstruction createDrop() { |
| 68 | return new DropInstruction(); |
| 69 | } |
| 70 | |
| 71 | /** |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 72 | * Creates a group instruction. |
| 73 | * |
| 74 | * @param groupId Group Id |
| 75 | * @return group instruction |
| 76 | */ |
| 77 | public static GroupInstruction createGroup(final GroupId groupId) { |
| 78 | checkNotNull(groupId, "GroupId cannot be null"); |
| 79 | return new GroupInstruction(groupId); |
| 80 | } |
| 81 | |
| 82 | /** |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 83 | * Creates a l0 modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 84 | * |
| 85 | * @param lambda the lambda to modify to |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 86 | * @return a l0 modification |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 87 | * @deprecated in Cardinal Release. Use {@link #modL0Lambda(Lambda)} instead. |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 88 | */ |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 89 | @Deprecated |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 90 | public static L0ModificationInstruction modL0Lambda(short lambda) { |
| 91 | checkNotNull(lambda, "L0 lambda cannot be null"); |
| 92 | return new ModLambdaInstruction(L0SubType.LAMBDA, lambda); |
| 93 | } |
| 94 | |
| 95 | /** |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 96 | * Creates an L0 modification with the specified OCh signal. |
| 97 | * |
| 98 | * @param lambda OCh signal |
| 99 | * @return an L0 modification |
| 100 | */ |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 101 | public static L0ModificationInstruction modL0Lambda(Lambda lambda) { |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 102 | checkNotNull(lambda, "L0 OCh signal cannot be null"); |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 103 | |
| 104 | if (lambda instanceof IndexedLambda) { |
| 105 | return new ModLambdaInstruction(L0SubType.LAMBDA, (short) ((IndexedLambda) lambda).index()); |
| 106 | } else if (lambda instanceof OchSignal) { |
| 107 | return new ModOchSignalInstruction((OchSignal) lambda); |
| 108 | } else { |
| 109 | throw new UnsupportedOperationException(String.format("Unsupported type: %s", lambda)); |
| 110 | } |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /** |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 114 | * Creates a l2 src modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 115 | * |
| 116 | * @param addr the mac address to modify to |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 117 | * @return a l2 modification |
| 118 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 119 | public static L2ModificationInstruction modL2Src(MacAddress addr) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 120 | checkNotNull(addr, "Src l2 address cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 121 | return new L2ModificationInstruction.ModEtherInstruction( |
| 122 | L2ModificationInstruction.L2SubType.ETH_SRC, addr); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Creates a L2 dst modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 127 | * |
| 128 | * @param addr the mac address to modify to |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 129 | * @return a L2 modification |
| 130 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 131 | public static L2ModificationInstruction modL2Dst(MacAddress addr) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 132 | checkNotNull(addr, "Dst l2 address cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 133 | return new L2ModificationInstruction.ModEtherInstruction( |
| 134 | L2ModificationInstruction.L2SubType.ETH_DST, addr); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 138 | * Creates a VLAN ID modification. |
| 139 | * |
| 140 | * @param vlanId the VLAN ID to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 141 | * @return a L2 modification |
| 142 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 143 | public static L2ModificationInstruction modVlanId(VlanId vlanId) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 144 | checkNotNull(vlanId, "VLAN id cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 145 | return new L2ModificationInstruction.ModVlanIdInstruction(vlanId); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 146 | } |
| 147 | |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 148 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 149 | * Creates a VLAN PCP modification. |
| 150 | * |
| 151 | * @param vlanPcp the PCP to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 152 | * @return a L2 modification |
| 153 | */ |
| 154 | public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) { |
| 155 | checkNotNull(vlanPcp, "VLAN Pcp cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 156 | return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 160 | * Creates a MPLS label modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 161 | * |
| 162 | * @param mplsLabel MPLS label to set |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 163 | * @return a L2 Modification |
| 164 | */ |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 165 | public static L2ModificationInstruction modMplsLabel(MplsLabel mplsLabel) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 166 | checkNotNull(mplsLabel, "MPLS label cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 167 | return new L2ModificationInstruction.ModMplsLabelInstruction(mplsLabel); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 168 | } |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 169 | |
| 170 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 171 | * Creates a MPLS decrement TTL modification. |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 172 | * |
| 173 | * @return a L2 Modification |
| 174 | */ |
| 175 | public static L2ModificationInstruction decMplsTtl() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 176 | return new L2ModificationInstruction.ModMplsTtlInstruction(); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 177 | } |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 178 | |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 179 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 180 | * Creates a L3 IPv4 src modification. |
| 181 | * |
| 182 | * @param addr the IPv4 address to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 183 | * @return a L3 modification |
| 184 | */ |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 185 | public static L3ModificationInstruction modL3Src(IpAddress addr) { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 186 | checkNotNull(addr, "Src l3 IPv4 address cannot be null"); |
| 187 | return new ModIPInstruction(L3SubType.IPV4_SRC, addr); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 191 | * Creates a L3 IPv4 dst modification. |
| 192 | * |
| 193 | * @param addr the IPv4 address to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 194 | * @return a L3 modification |
| 195 | */ |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 196 | public static L3ModificationInstruction modL3Dst(IpAddress addr) { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 197 | checkNotNull(addr, "Dst l3 IPv4 address cannot be null"); |
| 198 | return new ModIPInstruction(L3SubType.IPV4_DST, addr); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Creates a L3 IPv6 src modification. |
| 203 | * |
| 204 | * @param addr the IPv6 address to modify to |
| 205 | * @return a L3 modification |
| 206 | */ |
| 207 | public static L3ModificationInstruction modL3IPv6Src(IpAddress addr) { |
| 208 | checkNotNull(addr, "Src l3 IPv6 address cannot be null"); |
| 209 | return new ModIPInstruction(L3SubType.IPV6_SRC, addr); |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Creates a L3 IPv6 dst modification. |
| 214 | * |
| 215 | * @param addr the IPv6 address to modify to |
| 216 | * @return a L3 modification |
| 217 | */ |
| 218 | public static L3ModificationInstruction modL3IPv6Dst(IpAddress addr) { |
| 219 | checkNotNull(addr, "Dst l3 IPv6 address cannot be null"); |
| 220 | return new ModIPInstruction(L3SubType.IPV6_DST, addr); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Creates a L3 IPv6 Flow Label modification. |
| 225 | * |
| 226 | * @param flowLabel the IPv6 flow label to modify to (20 bits) |
| 227 | * @return a L3 modification |
| 228 | */ |
| 229 | public static L3ModificationInstruction modL3IPv6FlowLabel(int flowLabel) { |
| 230 | return new ModIPv6FlowLabelInstruction(flowLabel); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 233 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 234 | * Creates a L3 decrement TTL modification. |
| 235 | * |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 236 | * @return a L3 modification |
| 237 | */ |
| 238 | public static L3ModificationInstruction decNwTtl() { |
| 239 | return new ModTtlInstruction(L3SubType.DEC_TTL); |
| 240 | } |
| 241 | |
| 242 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 243 | * Creates a L3 copy TTL to outer header modification. |
| 244 | * |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 245 | * @return a L3 modification |
| 246 | */ |
| 247 | public static L3ModificationInstruction copyTtlOut() { |
| 248 | return new ModTtlInstruction(L3SubType.TTL_OUT); |
| 249 | } |
| 250 | |
| 251 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 252 | * Creates a L3 copy TTL to inner header modification. |
| 253 | * |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 254 | * @return a L3 modification |
| 255 | */ |
| 256 | public static L3ModificationInstruction copyTtlIn() { |
| 257 | return new ModTtlInstruction(L3SubType.TTL_IN); |
| 258 | } |
| 259 | |
| 260 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 261 | * Creates a push MPLS header instruction. |
| 262 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 263 | * @return a L2 modification. |
| 264 | */ |
| 265 | public static Instruction pushMpls() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 266 | return new L2ModificationInstruction.PushHeaderInstructions( |
| 267 | L2ModificationInstruction.L2SubType.MPLS_PUSH, |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 268 | Ethernet.MPLS_UNICAST); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 272 | * Creates a pop MPLS header instruction. |
| 273 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 274 | * @return a L2 modification. |
| 275 | */ |
| 276 | public static Instruction popMpls() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 277 | return new L2ModificationInstruction.PushHeaderInstructions( |
| 278 | L2ModificationInstruction.L2SubType.MPLS_POP, |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 279 | Ethernet.MPLS_UNICAST); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 280 | } |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 281 | |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 282 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 283 | * Creates a pop MPLS header instruction with a particular ethertype. |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 284 | * |
| 285 | * @param etherType Ethernet type to set |
| 286 | * @return a L2 modification. |
| 287 | */ |
alshabib | 0ad4398 | 2015-05-07 13:43:13 -0700 | [diff] [blame] | 288 | public static Instruction popMpls(int etherType) { |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 289 | checkNotNull(etherType, "Ethernet type cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 290 | return new L2ModificationInstruction.PushHeaderInstructions( |
| 291 | L2ModificationInstruction.L2SubType.MPLS_POP, etherType); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 294 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 295 | * Creates a pop VLAN header instruction. |
| 296 | * |
| 297 | * @return a L2 modification |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 298 | */ |
| 299 | public static Instruction popVlan() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 300 | return new L2ModificationInstruction.PopVlanInstruction( |
| 301 | L2ModificationInstruction.L2SubType.VLAN_POP); |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 305 | * Creates a push VLAN header instruction. |
| 306 | * |
| 307 | * @return a L2 modification |
| 308 | */ |
| 309 | public static Instruction pushVlan() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 310 | return new L2ModificationInstruction.PushHeaderInstructions( |
| 311 | L2ModificationInstruction.L2SubType.VLAN_PUSH, Ethernet.TYPE_VLAN); |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /** |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 315 | * Sends the packet to the table id. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 316 | * |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 317 | * @param tableId flow rule table id |
Thomas Vachuska | 3e2b651 | 2015-03-05 09:25:03 -0800 | [diff] [blame] | 318 | * @return table type transition instruction |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 319 | */ |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 320 | public static Instruction transition(Integer tableId) { |
| 321 | checkNotNull(tableId, "Table id cannot be null"); |
| 322 | return new TableTypeTransition(tableId); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 325 | /** |
| 326 | * Drop instruction. |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 327 | */ |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 328 | public static final class DropInstruction implements Instruction { |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 329 | |
| 330 | private DropInstruction() {} |
| 331 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 332 | @Override |
| 333 | public Type type() { |
| 334 | return Type.DROP; |
| 335 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 336 | |
| 337 | @Override |
| 338 | public String toString() { |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 339 | return toStringHelper(type().toString()).toString(); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 340 | } |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 341 | |
| 342 | @Override |
| 343 | public int hashCode() { |
| 344 | return Objects.hash(type()); |
| 345 | } |
| 346 | |
| 347 | @Override |
| 348 | public boolean equals(Object obj) { |
| 349 | if (this == obj) { |
| 350 | return true; |
| 351 | } |
| 352 | if (obj instanceof DropInstruction) { |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 353 | return true; |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 354 | } |
| 355 | return false; |
| 356 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 359 | /** |
| 360 | * Output Instruction. |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 361 | */ |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 362 | public static final class OutputInstruction implements Instruction { |
| 363 | private final PortNumber port; |
| 364 | |
| 365 | private OutputInstruction(PortNumber port) { |
| 366 | this.port = port; |
| 367 | } |
| 368 | |
| 369 | public PortNumber port() { |
| 370 | return port; |
| 371 | } |
| 372 | |
| 373 | @Override |
| 374 | public Type type() { |
| 375 | return Type.OUTPUT; |
| 376 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 377 | @Override |
| 378 | public String toString() { |
| 379 | return toStringHelper(type().toString()) |
| 380 | .add("port", port).toString(); |
| 381 | } |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 382 | |
| 383 | @Override |
| 384 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 385 | return Objects.hash(type(), port); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public boolean equals(Object obj) { |
| 390 | if (this == obj) { |
| 391 | return true; |
| 392 | } |
| 393 | if (obj instanceof OutputInstruction) { |
| 394 | OutputInstruction that = (OutputInstruction) obj; |
Yuta HIGUCHI | 4ce6529 | 2014-11-01 12:09:55 -0700 | [diff] [blame] | 395 | return Objects.equals(port, that.port); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 396 | |
| 397 | } |
| 398 | return false; |
| 399 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 402 | /** |
| 403 | * Group Instruction. |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 404 | */ |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 405 | public static final class GroupInstruction implements Instruction { |
| 406 | private final GroupId groupId; |
| 407 | |
| 408 | private GroupInstruction(GroupId groupId) { |
| 409 | this.groupId = groupId; |
| 410 | } |
| 411 | |
| 412 | public GroupId groupId() { |
| 413 | return groupId; |
| 414 | } |
| 415 | |
| 416 | @Override |
| 417 | public Type type() { |
| 418 | return Type.GROUP; |
| 419 | } |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 420 | |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 421 | @Override |
| 422 | public String toString() { |
| 423 | return toStringHelper(type().toString()) |
| 424 | .add("group ID", groupId.id()).toString(); |
| 425 | } |
| 426 | |
| 427 | @Override |
| 428 | public int hashCode() { |
| 429 | return Objects.hash(type(), groupId); |
| 430 | } |
| 431 | |
| 432 | @Override |
| 433 | public boolean equals(Object obj) { |
| 434 | if (this == obj) { |
| 435 | return true; |
| 436 | } |
| 437 | if (obj instanceof GroupInstruction) { |
| 438 | GroupInstruction that = (GroupInstruction) obj; |
| 439 | return Objects.equals(groupId, that.groupId); |
| 440 | |
| 441 | } |
| 442 | return false; |
| 443 | } |
| 444 | } |
| 445 | |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 446 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 447 | public static class TableTypeTransition implements Instruction { |
| 448 | private final Integer tableId; |
| 449 | |
| 450 | TableTypeTransition(Integer tableId) { |
| 451 | this.tableId = tableId; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | @Override |
| 455 | public Type type() { |
| 456 | return Type.TABLE; |
| 457 | } |
| 458 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 459 | public Integer tableId() { |
| 460 | return this.tableId; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | @Override |
| 464 | public String toString() { |
| 465 | return toStringHelper(type().toString()) |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 466 | .add("tableId", this.tableId).toString(); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | @Override |
| 470 | public int hashCode() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 471 | return Objects.hash(type(), tableId); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | @Override |
| 475 | public boolean equals(Object obj) { |
| 476 | if (this == obj) { |
| 477 | return true; |
| 478 | } |
| 479 | if (obj instanceof TableTypeTransition) { |
| 480 | TableTypeTransition that = (TableTypeTransition) obj; |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 481 | return Objects.equals(tableId, that.tableId); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 482 | |
| 483 | } |
| 484 | return false; |
| 485 | } |
| 486 | |
| 487 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 488 | } |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 489 | |
| 490 | |