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