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