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