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