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 | |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 18 | import org.onlab.packet.EthType; |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 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; |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 35 | import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType; |
| 36 | import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction; |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame^] | 37 | import org.onosproject.net.meter.MeterId; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 38 | |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 39 | import java.util.Objects; |
| 40 | |
| 41 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 42 | import static com.google.common.base.Preconditions.checkNotNull; |
alshabib | 64231f6 | 2014-09-16 17:58:36 -0700 | [diff] [blame] | 43 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Factory class for creating various traffic treatment instructions. |
| 46 | */ |
| 47 | public final class Instructions { |
| 48 | |
| 49 | |
| 50 | // Ban construction |
| 51 | private Instructions() {} |
| 52 | |
| 53 | /** |
| 54 | * Creates an output instruction using the specified port number. This can |
| 55 | * include logical ports such as CONTROLLER, FLOOD, etc. |
| 56 | * |
| 57 | * @param number port number |
| 58 | * @return output instruction |
| 59 | */ |
| 60 | public static OutputInstruction createOutput(final PortNumber number) { |
| 61 | checkNotNull(number, "PortNumber cannot be null"); |
| 62 | return new OutputInstruction(number); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Creates a drop instruction. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 67 | * |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 68 | * @return drop instruction |
| 69 | */ |
| 70 | public static DropInstruction createDrop() { |
| 71 | return new DropInstruction(); |
| 72 | } |
| 73 | |
| 74 | /** |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 75 | * Creates a group instruction. |
| 76 | * |
| 77 | * @param groupId Group Id |
| 78 | * @return group instruction |
| 79 | */ |
| 80 | public static GroupInstruction createGroup(final GroupId groupId) { |
| 81 | checkNotNull(groupId, "GroupId cannot be null"); |
| 82 | return new GroupInstruction(groupId); |
| 83 | } |
| 84 | |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame^] | 85 | public static MeterInstruction meterTraffic(final MeterId meterId) { |
| 86 | checkNotNull(meterId, "meter id cannot be null"); |
| 87 | return new MeterInstruction(meterId); |
| 88 | } |
| 89 | |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 90 | /** |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 91 | * Creates a l0 modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 92 | * |
| 93 | * @param lambda the lambda to modify to |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 94 | * @return a l0 modification |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 95 | * @deprecated in Cardinal Release. Use {@link #modL0Lambda(Lambda)} instead. |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 96 | */ |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 97 | @Deprecated |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 98 | public static L0ModificationInstruction modL0Lambda(short lambda) { |
| 99 | checkNotNull(lambda, "L0 lambda cannot be null"); |
| 100 | return new ModLambdaInstruction(L0SubType.LAMBDA, lambda); |
| 101 | } |
| 102 | |
| 103 | /** |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 104 | * Creates an L0 modification with the specified OCh signal. |
| 105 | * |
| 106 | * @param lambda OCh signal |
| 107 | * @return an L0 modification |
| 108 | */ |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 109 | public static L0ModificationInstruction modL0Lambda(Lambda lambda) { |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 110 | checkNotNull(lambda, "L0 OCh signal cannot be null"); |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 111 | |
| 112 | if (lambda instanceof IndexedLambda) { |
| 113 | return new ModLambdaInstruction(L0SubType.LAMBDA, (short) ((IndexedLambda) lambda).index()); |
| 114 | } else if (lambda instanceof OchSignal) { |
| 115 | return new ModOchSignalInstruction((OchSignal) lambda); |
| 116 | } else { |
| 117 | throw new UnsupportedOperationException(String.format("Unsupported type: %s", lambda)); |
| 118 | } |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /** |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 122 | * Creates a l2 src modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 123 | * |
| 124 | * @param addr the mac address to modify to |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 125 | * @return a l2 modification |
| 126 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 127 | public static L2ModificationInstruction modL2Src(MacAddress addr) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 128 | checkNotNull(addr, "Src l2 address cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 129 | return new L2ModificationInstruction.ModEtherInstruction( |
| 130 | L2ModificationInstruction.L2SubType.ETH_SRC, addr); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Creates a L2 dst modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 135 | * |
| 136 | * @param addr the mac address to modify to |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 137 | * @return a L2 modification |
| 138 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 139 | public static L2ModificationInstruction modL2Dst(MacAddress addr) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 140 | checkNotNull(addr, "Dst l2 address cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 141 | return new L2ModificationInstruction.ModEtherInstruction( |
| 142 | L2ModificationInstruction.L2SubType.ETH_DST, addr); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 146 | * Creates a VLAN ID modification. |
| 147 | * |
| 148 | * @param vlanId the VLAN ID to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 149 | * @return a L2 modification |
| 150 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 151 | public static L2ModificationInstruction modVlanId(VlanId vlanId) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 152 | checkNotNull(vlanId, "VLAN id cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 153 | return new L2ModificationInstruction.ModVlanIdInstruction(vlanId); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 154 | } |
| 155 | |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 156 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 157 | * Creates a VLAN PCP modification. |
| 158 | * |
| 159 | * @param vlanPcp the PCP to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 160 | * @return a L2 modification |
| 161 | */ |
| 162 | public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) { |
| 163 | checkNotNull(vlanPcp, "VLAN Pcp cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 164 | return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 168 | * Creates a MPLS label modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 169 | * |
| 170 | * @param mplsLabel MPLS label to set |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 171 | * @return a L2 Modification |
| 172 | */ |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 173 | public static L2ModificationInstruction modMplsLabel(MplsLabel mplsLabel) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 174 | checkNotNull(mplsLabel, "MPLS label cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 175 | return new L2ModificationInstruction.ModMplsLabelInstruction(mplsLabel); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 176 | } |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 177 | |
| 178 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 179 | * Creates a MPLS decrement TTL modification. |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 180 | * |
| 181 | * @return a L2 Modification |
| 182 | */ |
| 183 | public static L2ModificationInstruction decMplsTtl() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 184 | return new L2ModificationInstruction.ModMplsTtlInstruction(); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 185 | } |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 186 | |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 187 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 188 | * Creates a L3 IPv4 src modification. |
| 189 | * |
| 190 | * @param addr the IPv4 address to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 191 | * @return a L3 modification |
| 192 | */ |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 193 | public static L3ModificationInstruction modL3Src(IpAddress addr) { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 194 | checkNotNull(addr, "Src l3 IPv4 address cannot be null"); |
| 195 | return new ModIPInstruction(L3SubType.IPV4_SRC, addr); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 199 | * Creates a L3 IPv4 dst modification. |
| 200 | * |
| 201 | * @param addr the IPv4 address to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 202 | * @return a L3 modification |
| 203 | */ |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 204 | public static L3ModificationInstruction modL3Dst(IpAddress addr) { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 205 | checkNotNull(addr, "Dst l3 IPv4 address cannot be null"); |
| 206 | return new ModIPInstruction(L3SubType.IPV4_DST, addr); |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Creates a L3 IPv6 src modification. |
| 211 | * |
| 212 | * @param addr the IPv6 address to modify to |
| 213 | * @return a L3 modification |
| 214 | */ |
| 215 | public static L3ModificationInstruction modL3IPv6Src(IpAddress addr) { |
| 216 | checkNotNull(addr, "Src l3 IPv6 address cannot be null"); |
| 217 | return new ModIPInstruction(L3SubType.IPV6_SRC, addr); |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Creates a L3 IPv6 dst modification. |
| 222 | * |
| 223 | * @param addr the IPv6 address to modify to |
| 224 | * @return a L3 modification |
| 225 | */ |
| 226 | public static L3ModificationInstruction modL3IPv6Dst(IpAddress addr) { |
| 227 | checkNotNull(addr, "Dst l3 IPv6 address cannot be null"); |
| 228 | return new ModIPInstruction(L3SubType.IPV6_DST, addr); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Creates a L3 IPv6 Flow Label modification. |
| 233 | * |
| 234 | * @param flowLabel the IPv6 flow label to modify to (20 bits) |
| 235 | * @return a L3 modification |
| 236 | */ |
| 237 | public static L3ModificationInstruction modL3IPv6FlowLabel(int flowLabel) { |
| 238 | return new ModIPv6FlowLabelInstruction(flowLabel); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 241 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 242 | * Creates a L3 decrement TTL modification. |
| 243 | * |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 244 | * @return a L3 modification |
| 245 | */ |
| 246 | public static L3ModificationInstruction decNwTtl() { |
| 247 | return new ModTtlInstruction(L3SubType.DEC_TTL); |
| 248 | } |
| 249 | |
| 250 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 251 | * Creates a L3 copy TTL to outer header modification. |
| 252 | * |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 253 | * @return a L3 modification |
| 254 | */ |
| 255 | public static L3ModificationInstruction copyTtlOut() { |
| 256 | return new ModTtlInstruction(L3SubType.TTL_OUT); |
| 257 | } |
| 258 | |
| 259 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 260 | * Creates a L3 copy TTL to inner header modification. |
| 261 | * |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 262 | * @return a L3 modification |
| 263 | */ |
| 264 | public static L3ModificationInstruction copyTtlIn() { |
| 265 | return new ModTtlInstruction(L3SubType.TTL_IN); |
| 266 | } |
| 267 | |
| 268 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 269 | * Creates a push MPLS header instruction. |
| 270 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 271 | * @return a L2 modification. |
| 272 | */ |
| 273 | public static Instruction pushMpls() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 274 | return new L2ModificationInstruction.PushHeaderInstructions( |
| 275 | L2ModificationInstruction.L2SubType.MPLS_PUSH, |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 276 | EthType.EtherType.MPLS_UNICAST.ethType()); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 280 | * Creates a pop MPLS header instruction. |
| 281 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 282 | * @return a L2 modification. |
| 283 | */ |
| 284 | public static Instruction popMpls() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 285 | return new L2ModificationInstruction.PushHeaderInstructions( |
| 286 | L2ModificationInstruction.L2SubType.MPLS_POP, |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 287 | EthType.EtherType.MPLS_UNICAST.ethType()); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 288 | } |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 289 | |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 290 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 291 | * Creates a pop MPLS header instruction with a particular ethertype. |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 292 | * |
| 293 | * @param etherType Ethernet type to set |
| 294 | * @return a L2 modification. |
Sho SHIMIZU | be63b23 | 2015-06-30 10:57:58 -0700 | [diff] [blame] | 295 | * @deprecated in Cardinal Release |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 296 | */ |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 297 | @Deprecated |
alshabib | 0ad4398 | 2015-05-07 13:43:13 -0700 | [diff] [blame] | 298 | public static Instruction popMpls(int etherType) { |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 299 | checkNotNull(etherType, "Ethernet type cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 300 | return new L2ModificationInstruction.PushHeaderInstructions( |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 301 | L2ModificationInstruction.L2SubType.MPLS_POP, new EthType(etherType)); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | /** |
| 306 | * Creates a pop MPLS header instruction with a particular ethertype. |
| 307 | * |
| 308 | * @param etherType Ethernet type to set |
| 309 | * @return a L2 modification. |
| 310 | */ |
| 311 | public static Instruction popMpls(EthType etherType) { |
| 312 | checkNotNull(etherType, "Ethernet type cannot be null"); |
| 313 | return new L2ModificationInstruction.PushHeaderInstructions( |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 314 | L2ModificationInstruction.L2SubType.MPLS_POP, etherType); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 315 | } |
| 316 | |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 317 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 318 | * Creates a pop VLAN header instruction. |
| 319 | * |
| 320 | * @return a L2 modification |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 321 | */ |
| 322 | public static Instruction popVlan() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 323 | return new L2ModificationInstruction.PopVlanInstruction( |
| 324 | L2ModificationInstruction.L2SubType.VLAN_POP); |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 328 | * Creates a push VLAN header instruction. |
| 329 | * |
| 330 | * @return a L2 modification |
| 331 | */ |
| 332 | public static Instruction pushVlan() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 333 | return new L2ModificationInstruction.PushHeaderInstructions( |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 334 | L2ModificationInstruction.L2SubType.VLAN_PUSH, |
| 335 | EthType.EtherType.VLAN.ethType()); |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | /** |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 339 | * Sends the packet to the table id. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 340 | * |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 341 | * @param tableId flow rule table id |
Thomas Vachuska | 3e2b651 | 2015-03-05 09:25:03 -0800 | [diff] [blame] | 342 | * @return table type transition instruction |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 343 | */ |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 344 | public static Instruction transition(Integer tableId) { |
| 345 | checkNotNull(tableId, "Table id cannot be null"); |
| 346 | return new TableTypeTransition(tableId); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 349 | /** |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 350 | * Writes metadata to associate with a packet. |
| 351 | * |
| 352 | * @param metadata the metadata value to write |
| 353 | * @param metadataMask the bits to mask for the metadata value |
| 354 | * @return metadata instruction |
| 355 | */ |
| 356 | public static Instruction writeMetadata(long metadata, long metadataMask) { |
| 357 | return new MetadataInstruction(metadata, metadataMask); |
| 358 | } |
| 359 | |
| 360 | /** |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 361 | * Creates a Tunnel ID modification. |
| 362 | * |
| 363 | * @param tunnelId the Tunnel ID to modify to |
| 364 | * @return a L2 modification |
| 365 | */ |
| 366 | public static L2ModificationInstruction modTunnelId(long tunnelId) { |
| 367 | checkNotNull(tunnelId, "Tunnel id cannot be null"); |
| 368 | return new L2ModificationInstruction.ModTunnelIdInstruction(tunnelId); |
| 369 | } |
| 370 | |
| 371 | /** |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 372 | * Creates a TCP src modification. |
| 373 | * |
| 374 | * @param port the TCP port number to modify to |
| 375 | * @return a L4 modification |
| 376 | */ |
| 377 | public static L4ModificationInstruction modTcpSrc(short port) { |
| 378 | checkNotNull(port, "Src TCP port cannot be null"); |
| 379 | return new ModTransportPortInstruction(L4SubType.TCP_SRC, port); |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * Creates a TCP dst modification. |
| 384 | * |
| 385 | * @param port the TCP port number to modify to |
| 386 | * @return a L4 modification |
| 387 | */ |
| 388 | public static L4ModificationInstruction modTcpDst(short port) { |
| 389 | checkNotNull(port, "Dst TCP port cannot be null"); |
| 390 | return new ModTransportPortInstruction(L4SubType.TCP_DST, port); |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * Creates a UDP src modification. |
| 395 | * |
| 396 | * @param port the UDP port number to modify to |
| 397 | * @return a L4 modification |
| 398 | */ |
| 399 | public static L4ModificationInstruction modUdpSrc(short port) { |
| 400 | checkNotNull(port, "Src UDP port cannot be null"); |
| 401 | return new ModTransportPortInstruction(L4SubType.UDP_SRC, port); |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * Creates a UDP dst modification. |
| 406 | * |
| 407 | * @param port the UDP port number to modify to |
| 408 | * @return a L4 modification |
| 409 | */ |
| 410 | public static L4ModificationInstruction modUdpDst(short port) { |
| 411 | checkNotNull(port, "Dst UDP port cannot be null"); |
| 412 | return new ModTransportPortInstruction(L4SubType.UDP_DST, port); |
| 413 | } |
| 414 | |
| 415 | /** |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 416 | * Drop instruction. |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 417 | */ |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 418 | public static final class DropInstruction implements Instruction { |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 419 | |
| 420 | private DropInstruction() {} |
| 421 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 422 | @Override |
| 423 | public Type type() { |
| 424 | return Type.DROP; |
| 425 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 426 | |
| 427 | @Override |
| 428 | public String toString() { |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 429 | return toStringHelper(type().toString()).toString(); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 430 | } |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 431 | |
| 432 | @Override |
| 433 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 434 | return Objects.hash(type().ordinal()); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | @Override |
| 438 | public boolean equals(Object obj) { |
| 439 | if (this == obj) { |
| 440 | return true; |
| 441 | } |
| 442 | if (obj instanceof DropInstruction) { |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 443 | return true; |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 444 | } |
| 445 | return false; |
| 446 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 449 | /** |
| 450 | * Output Instruction. |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 451 | */ |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 452 | public static final class OutputInstruction implements Instruction { |
| 453 | private final PortNumber port; |
| 454 | |
| 455 | private OutputInstruction(PortNumber port) { |
| 456 | this.port = port; |
| 457 | } |
| 458 | |
| 459 | public PortNumber port() { |
| 460 | return port; |
| 461 | } |
| 462 | |
| 463 | @Override |
| 464 | public Type type() { |
| 465 | return Type.OUTPUT; |
| 466 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 467 | @Override |
| 468 | public String toString() { |
| 469 | return toStringHelper(type().toString()) |
| 470 | .add("port", port).toString(); |
| 471 | } |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 472 | |
| 473 | @Override |
| 474 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 475 | return Objects.hash(type().ordinal(), port); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | @Override |
| 479 | public boolean equals(Object obj) { |
| 480 | if (this == obj) { |
| 481 | return true; |
| 482 | } |
| 483 | if (obj instanceof OutputInstruction) { |
| 484 | OutputInstruction that = (OutputInstruction) obj; |
Yuta HIGUCHI | 4ce6529 | 2014-11-01 12:09:55 -0700 | [diff] [blame] | 485 | return Objects.equals(port, that.port); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 486 | |
| 487 | } |
| 488 | return false; |
| 489 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 492 | /** |
| 493 | * Group Instruction. |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 494 | */ |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 495 | public static final class GroupInstruction implements Instruction { |
| 496 | private final GroupId groupId; |
| 497 | |
| 498 | private GroupInstruction(GroupId groupId) { |
| 499 | this.groupId = groupId; |
| 500 | } |
| 501 | |
| 502 | public GroupId groupId() { |
| 503 | return groupId; |
| 504 | } |
| 505 | |
| 506 | @Override |
| 507 | public Type type() { |
| 508 | return Type.GROUP; |
| 509 | } |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 510 | |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 511 | @Override |
| 512 | public String toString() { |
| 513 | return toStringHelper(type().toString()) |
| 514 | .add("group ID", groupId.id()).toString(); |
| 515 | } |
| 516 | |
| 517 | @Override |
| 518 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 519 | return Objects.hash(type().ordinal(), groupId); |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | @Override |
| 523 | public boolean equals(Object obj) { |
| 524 | if (this == obj) { |
| 525 | return true; |
| 526 | } |
| 527 | if (obj instanceof GroupInstruction) { |
| 528 | GroupInstruction that = (GroupInstruction) obj; |
| 529 | return Objects.equals(groupId, that.groupId); |
| 530 | |
| 531 | } |
| 532 | return false; |
| 533 | } |
| 534 | } |
| 535 | |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 536 | /** |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame^] | 537 | * A meter instruction. |
| 538 | */ |
| 539 | public static final class MeterInstruction implements Instruction { |
| 540 | private final MeterId meterId; |
| 541 | |
| 542 | private MeterInstruction(MeterId meterId) { |
| 543 | this.meterId = meterId; |
| 544 | } |
| 545 | |
| 546 | public MeterId meterId() { |
| 547 | return meterId; |
| 548 | } |
| 549 | |
| 550 | @Override |
| 551 | public Type type() { |
| 552 | return Type.METER; |
| 553 | } |
| 554 | |
| 555 | @Override |
| 556 | public String toString() { |
| 557 | return toStringHelper(type().toString()) |
| 558 | .add("meter ID", meterId.id()).toString(); |
| 559 | } |
| 560 | |
| 561 | @Override |
| 562 | public int hashCode() { |
| 563 | return Objects.hash(type().ordinal(), meterId); |
| 564 | } |
| 565 | |
| 566 | @Override |
| 567 | public boolean equals(Object obj) { |
| 568 | if (this == obj) { |
| 569 | return true; |
| 570 | } |
| 571 | if (obj instanceof MeterInstruction) { |
| 572 | MeterInstruction that = (MeterInstruction) obj; |
| 573 | return Objects.equals(meterId, that.meterId); |
| 574 | |
| 575 | } |
| 576 | return false; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | /** |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 581 | * Transition instruction. |
| 582 | */ |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 583 | public static class TableTypeTransition implements Instruction { |
| 584 | private final Integer tableId; |
| 585 | |
| 586 | TableTypeTransition(Integer tableId) { |
| 587 | this.tableId = tableId; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | @Override |
| 591 | public Type type() { |
| 592 | return Type.TABLE; |
| 593 | } |
| 594 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 595 | public Integer tableId() { |
| 596 | return this.tableId; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | @Override |
| 600 | public String toString() { |
| 601 | return toStringHelper(type().toString()) |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 602 | .add("tableId", this.tableId).toString(); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | @Override |
| 606 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 607 | return Objects.hash(type().ordinal(), tableId); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | @Override |
| 611 | public boolean equals(Object obj) { |
| 612 | if (this == obj) { |
| 613 | return true; |
| 614 | } |
| 615 | if (obj instanceof TableTypeTransition) { |
| 616 | TableTypeTransition that = (TableTypeTransition) obj; |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 617 | return Objects.equals(tableId, that.tableId); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 618 | |
| 619 | } |
| 620 | return false; |
| 621 | } |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 622 | } |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 623 | |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 624 | /** |
| 625 | * Metadata instruction. |
| 626 | */ |
| 627 | public static class MetadataInstruction implements Instruction { |
| 628 | private final long metadata; |
| 629 | private final long metadataMask; |
| 630 | |
| 631 | MetadataInstruction(long metadata, long metadataMask) { |
| 632 | this.metadata = metadata; |
| 633 | this.metadataMask = metadataMask; |
| 634 | } |
| 635 | |
| 636 | @Override |
| 637 | public Type type() { |
| 638 | return Type.METADATA; |
| 639 | } |
| 640 | |
| 641 | public long metadata() { |
| 642 | return this.metadata; |
| 643 | } |
| 644 | |
| 645 | public long metadataMask() { |
| 646 | return this.metadataMask; |
| 647 | } |
| 648 | |
| 649 | @Override |
| 650 | public String toString() { |
| 651 | return toStringHelper(type().toString()) |
| 652 | .add("metadata", Long.toHexString(this.metadata)) |
| 653 | .add("metadata mask", Long.toHexString(this.metadataMask)) |
| 654 | .toString(); |
| 655 | } |
| 656 | |
| 657 | @Override |
| 658 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 659 | return Objects.hash(type().ordinal(), metadata, metadataMask); |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | @Override |
| 663 | public boolean equals(Object obj) { |
| 664 | if (this == obj) { |
| 665 | return true; |
| 666 | } |
| 667 | if (obj instanceof MetadataInstruction) { |
| 668 | MetadataInstruction that = (MetadataInstruction) obj; |
| 669 | return Objects.equals(metadata, that.metadata) && |
| 670 | Objects.equals(metadataMask, that.metadataMask); |
| 671 | |
| 672 | } |
| 673 | return false; |
| 674 | } |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 675 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 676 | } |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 677 | |
| 678 | |