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