Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
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 | |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 19 | import org.onlab.packet.EthType; |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 20 | import org.onlab.packet.IpAddress; |
| 21 | import org.onlab.packet.MacAddress; |
| 22 | import org.onlab.packet.MplsLabel; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 23 | import org.onlab.packet.TpPort; |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 24 | import org.onlab.packet.VlanId; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 25 | import org.onosproject.core.GroupId; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 26 | import org.onosproject.net.DeviceId; |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 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; |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 31 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction; |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 32 | import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType; |
| 34 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; |
lishuai | 3cce60b | 2015-12-01 19:35:16 +0800 | [diff] [blame] | 35 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction; |
| 36 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction; |
| 37 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 38 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 39 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction; |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 40 | import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType; |
| 41 | import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction; |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame] | 42 | import org.onosproject.net.meter.MeterId; |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 43 | import org.onosproject.net.pi.runtime.PiTableAction; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 44 | |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 45 | import java.util.Objects; |
| 46 | |
| 47 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 48 | import static com.google.common.base.Preconditions.checkNotNull; |
alshabib | 64231f6 | 2014-09-16 17:58:36 -0700 | [diff] [blame] | 49 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 50 | /** |
| 51 | * Factory class for creating various traffic treatment instructions. |
| 52 | */ |
| 53 | public final class Instructions { |
| 54 | |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 55 | private static final String SEPARATOR = ":"; |
| 56 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 57 | // Ban construction |
| 58 | private Instructions() {} |
| 59 | |
| 60 | /** |
| 61 | * Creates an output instruction using the specified port number. This can |
| 62 | * include logical ports such as CONTROLLER, FLOOD, etc. |
| 63 | * |
| 64 | * @param number port number |
| 65 | * @return output instruction |
| 66 | */ |
| 67 | public static OutputInstruction createOutput(final PortNumber number) { |
| 68 | checkNotNull(number, "PortNumber cannot be null"); |
| 69 | return new OutputInstruction(number); |
| 70 | } |
| 71 | |
| 72 | /** |
Charles Chan | 7efabeb | 2015-09-28 15:12:19 -0700 | [diff] [blame] | 73 | * Creates a no action instruction. |
| 74 | * |
| 75 | * @return no action instruction |
| 76 | */ |
| 77 | public static NoActionInstruction createNoAction() { |
| 78 | return new NoActionInstruction(); |
| 79 | } |
| 80 | |
| 81 | /** |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 82 | * Creates a group instruction. |
| 83 | * |
| 84 | * @param groupId Group Id |
| 85 | * @return group instruction |
| 86 | */ |
| 87 | public static GroupInstruction createGroup(final GroupId groupId) { |
| 88 | checkNotNull(groupId, "GroupId cannot be null"); |
| 89 | return new GroupInstruction(groupId); |
| 90 | } |
| 91 | |
Steffen Gebert | bbfdaaa | 2015-09-29 11:01:46 +0200 | [diff] [blame] | 92 | /** |
| 93 | * Creates a set-queue instruction. |
| 94 | * |
| 95 | * @param queueId Queue Id |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 96 | * @param port Port number |
Steffen Gebert | bbfdaaa | 2015-09-29 11:01:46 +0200 | [diff] [blame] | 97 | * @return set-queue instruction |
| 98 | */ |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 99 | public static SetQueueInstruction setQueue(final long queueId, final PortNumber port) { |
Steffen Gebert | bbfdaaa | 2015-09-29 11:01:46 +0200 | [diff] [blame] | 100 | checkNotNull(queueId, "queue ID cannot be null"); |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 101 | return new SetQueueInstruction(queueId, port); |
Steffen Gebert | bbfdaaa | 2015-09-29 11:01:46 +0200 | [diff] [blame] | 102 | } |
| 103 | |
Jian Li | 1ef82db | 2016-03-03 14:43:21 -0800 | [diff] [blame] | 104 | /** |
| 105 | * Creates a meter instruction. |
| 106 | * |
| 107 | * @param meterId Meter Id |
| 108 | * @return meter instruction |
| 109 | */ |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame] | 110 | public static MeterInstruction meterTraffic(final MeterId meterId) { |
| 111 | checkNotNull(meterId, "meter id cannot be null"); |
| 112 | return new MeterInstruction(meterId); |
| 113 | } |
| 114 | |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 115 | /** |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 116 | * Creates an L0 modification with the specified OCh signal. |
| 117 | * |
| 118 | * @param lambda OCh signal |
| 119 | * @return an L0 modification |
| 120 | */ |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 121 | public static L0ModificationInstruction modL0Lambda(Lambda lambda) { |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 122 | checkNotNull(lambda, "L0 OCh signal cannot be null"); |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 123 | |
Sho SHIMIZU | a114d89 | 2016-03-11 16:48:19 -0800 | [diff] [blame] | 124 | if (lambda instanceof OchSignal) { |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 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 | /** |
lishuai | 3cce60b | 2015-12-01 19:35:16 +0800 | [diff] [blame] | 299 | * Creates a L3 ARP IP src modification. |
| 300 | * |
| 301 | * @param addr the ip address to modify to |
| 302 | * @return a L3 modification |
| 303 | */ |
| 304 | public static L3ModificationInstruction modArpSpa(IpAddress addr) { |
| 305 | checkNotNull(addr, "Src l3 ARP IP address cannot be null"); |
| 306 | return new ModArpIPInstruction(L3SubType.ARP_SPA, addr); |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Creates a l3 ARP Ether src modification. |
| 311 | * |
| 312 | * @param addr the mac address to modify to |
| 313 | * @return a l3 modification |
| 314 | */ |
| 315 | public static L3ModificationInstruction modArpSha(MacAddress addr) { |
| 316 | checkNotNull(addr, "Src l3 ARP address cannot be null"); |
| 317 | return new ModArpEthInstruction(L3SubType.ARP_SHA, addr); |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Creates a l3 ARP operation modification. |
| 322 | * |
| 323 | * @param op the ARP operation to modify to |
| 324 | * @return a l3 modification |
| 325 | */ |
| 326 | public static L3ModificationInstruction modL3ArpOp(short op) { |
| 327 | checkNotNull(op, "Arp operation cannot be null"); |
| 328 | return new ModArpOpInstruction(L3SubType.ARP_OP, op); |
| 329 | } |
| 330 | |
| 331 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 332 | * Creates a push MPLS header instruction. |
| 333 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 334 | * @return a L2 modification. |
| 335 | */ |
| 336 | public static Instruction pushMpls() { |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 337 | return new L2ModificationInstruction.ModMplsHeaderInstruction( |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 338 | L2ModificationInstruction.L2SubType.MPLS_PUSH, |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 339 | EthType.EtherType.MPLS_UNICAST.ethType()); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 343 | * Creates a pop MPLS header instruction. |
| 344 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 345 | * @return a L2 modification. |
| 346 | */ |
| 347 | public static Instruction popMpls() { |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 348 | return new L2ModificationInstruction.ModMplsHeaderInstruction( |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 349 | L2ModificationInstruction.L2SubType.MPLS_POP, |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 350 | EthType.EtherType.MPLS_UNICAST.ethType()); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 351 | } |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 352 | |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 353 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 354 | * Creates a pop MPLS header instruction with a particular ethertype. |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 355 | * |
| 356 | * @param etherType Ethernet type to set |
| 357 | * @return a L2 modification. |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 358 | */ |
| 359 | public static Instruction popMpls(EthType etherType) { |
| 360 | checkNotNull(etherType, "Ethernet type cannot be null"); |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 361 | return new L2ModificationInstruction.ModMplsHeaderInstruction( |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 362 | L2ModificationInstruction.L2SubType.MPLS_POP, etherType); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 363 | } |
| 364 | |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 365 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 366 | * Creates a pop VLAN header instruction. |
| 367 | * |
| 368 | * @return a L2 modification |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 369 | */ |
| 370 | public static Instruction popVlan() { |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 371 | return new L2ModificationInstruction.ModVlanHeaderInstruction( |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 372 | L2ModificationInstruction.L2SubType.VLAN_POP); |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 376 | * Creates a push VLAN header instruction. |
| 377 | * |
| 378 | * @return a L2 modification |
| 379 | */ |
| 380 | public static Instruction pushVlan() { |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 381 | return new L2ModificationInstruction.ModVlanHeaderInstruction( |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 382 | L2ModificationInstruction.L2SubType.VLAN_PUSH, |
| 383 | EthType.EtherType.VLAN.ethType()); |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | /** |
Konstantinos Kanonakis | 9215ff2 | 2016-11-04 13:28:11 -0500 | [diff] [blame] | 387 | * Creates a push VLAN header instruction using the supplied Ethernet type. |
| 388 | * |
| 389 | * @param ethType the Ethernet type to use |
| 390 | * @return a L2 modification |
| 391 | */ |
| 392 | public static Instruction pushVlan(EthType ethType) { |
| 393 | return new L2ModificationInstruction.ModVlanHeaderInstruction( |
| 394 | L2ModificationInstruction.L2SubType.VLAN_PUSH, |
| 395 | ethType); |
| 396 | } |
| 397 | |
| 398 | /** |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 399 | * Sends the packet to the table id. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 400 | * |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 401 | * @param tableId flow rule table id |
Thomas Vachuska | 3e2b651 | 2015-03-05 09:25:03 -0800 | [diff] [blame] | 402 | * @return table type transition instruction |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 403 | */ |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 404 | public static Instruction transition(Integer tableId) { |
| 405 | checkNotNull(tableId, "Table id cannot be null"); |
| 406 | return new TableTypeTransition(tableId); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 407 | } |
| 408 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 409 | /** |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 410 | * Writes metadata to associate with a packet. |
| 411 | * |
| 412 | * @param metadata the metadata value to write |
| 413 | * @param metadataMask the bits to mask for the metadata value |
| 414 | * @return metadata instruction |
| 415 | */ |
| 416 | public static Instruction writeMetadata(long metadata, long metadataMask) { |
| 417 | return new MetadataInstruction(metadata, metadataMask); |
| 418 | } |
| 419 | |
| 420 | /** |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 421 | * Creates a Tunnel ID modification. |
| 422 | * |
| 423 | * @param tunnelId the Tunnel ID to modify to |
| 424 | * @return a L2 modification |
| 425 | */ |
| 426 | public static L2ModificationInstruction modTunnelId(long tunnelId) { |
| 427 | checkNotNull(tunnelId, "Tunnel id cannot be null"); |
| 428 | return new L2ModificationInstruction.ModTunnelIdInstruction(tunnelId); |
| 429 | } |
| 430 | |
| 431 | /** |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 432 | * Creates a TCP src modification. |
| 433 | * |
| 434 | * @param port the TCP port number to modify to |
| 435 | * @return a L4 modification |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 436 | */ |
| 437 | public static L4ModificationInstruction modTcpSrc(TpPort port) { |
| 438 | checkNotNull(port, "Src TCP port cannot be null"); |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 439 | return new ModTransportPortInstruction(L4SubType.TCP_SRC, port); |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * Creates a TCP dst modification. |
| 444 | * |
| 445 | * @param port the TCP port number to modify to |
| 446 | * @return a L4 modification |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 447 | */ |
| 448 | public static L4ModificationInstruction modTcpDst(TpPort port) { |
| 449 | checkNotNull(port, "Dst TCP port cannot be null"); |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 450 | return new ModTransportPortInstruction(L4SubType.TCP_DST, port); |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * Creates a UDP src modification. |
| 455 | * |
| 456 | * @param port the UDP port number to modify to |
| 457 | * @return a L4 modification |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 458 | */ |
| 459 | public static L4ModificationInstruction modUdpSrc(TpPort port) { |
| 460 | checkNotNull(port, "Src UDP port cannot be null"); |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 461 | return new ModTransportPortInstruction(L4SubType.UDP_SRC, port); |
| 462 | } |
| 463 | |
| 464 | /** |
| 465 | * Creates a UDP dst modification. |
| 466 | * |
| 467 | * @param port the UDP port number to modify to |
| 468 | * @return a L4 modification |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 469 | */ |
| 470 | public static L4ModificationInstruction modUdpDst(TpPort port) { |
| 471 | checkNotNull(port, "Dst UDP port cannot be null"); |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 472 | return new ModTransportPortInstruction(L4SubType.UDP_DST, port); |
| 473 | } |
| 474 | |
| 475 | /** |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 476 | * Creates a protocol independent instruction. |
| 477 | * |
| 478 | * @param piTableAction protocol independent instruction |
| 479 | * @return extension instruction |
| 480 | */ |
| 481 | public static PiInstruction piTableAction(PiTableAction piTableAction) { |
| 482 | checkNotNull(piTableAction, "PiTableAction instruction cannot be null"); |
| 483 | return new PiInstruction(piTableAction); |
| 484 | } |
| 485 | |
| 486 | /** |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 487 | * Creates an extension instruction. |
| 488 | * |
| 489 | * @param extension extension instruction |
| 490 | * @param deviceId device ID |
| 491 | * @return extension instruction |
| 492 | */ |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 493 | public static ExtensionInstructionWrapper extension(ExtensionTreatment extension, |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 494 | DeviceId deviceId) { |
| 495 | checkNotNull(extension, "Extension instruction cannot be null"); |
| 496 | checkNotNull(deviceId, "Device ID cannot be null"); |
| 497 | return new ExtensionInstructionWrapper(extension, deviceId); |
| 498 | } |
| 499 | |
| 500 | /** |
Charles Chan | 7efabeb | 2015-09-28 15:12:19 -0700 | [diff] [blame] | 501 | * No Action instruction. |
| 502 | */ |
| 503 | public static final class NoActionInstruction implements Instruction { |
| 504 | |
| 505 | private NoActionInstruction() {} |
| 506 | |
| 507 | @Override |
| 508 | public Type type() { |
| 509 | return Type.NOACTION; |
| 510 | } |
| 511 | |
| 512 | @Override |
| 513 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 514 | return type().toString(); |
Charles Chan | 7efabeb | 2015-09-28 15:12:19 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | @Override |
| 518 | public int hashCode() { |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 519 | return type().ordinal(); |
Charles Chan | 7efabeb | 2015-09-28 15:12:19 -0700 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | @Override |
| 523 | public boolean equals(Object obj) { |
| 524 | if (this == obj) { |
| 525 | return true; |
| 526 | } |
| 527 | if (obj instanceof NoActionInstruction) { |
| 528 | return true; |
| 529 | } |
| 530 | return false; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | /** |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 535 | * Output Instruction. |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 536 | */ |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 537 | public static final class OutputInstruction implements Instruction { |
| 538 | private final PortNumber port; |
| 539 | |
| 540 | private OutputInstruction(PortNumber port) { |
| 541 | this.port = port; |
| 542 | } |
| 543 | |
| 544 | public PortNumber port() { |
| 545 | return port; |
| 546 | } |
| 547 | |
| 548 | @Override |
| 549 | public Type type() { |
| 550 | return Type.OUTPUT; |
| 551 | } |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 552 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 553 | @Override |
| 554 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 555 | return type().toString() + SEPARATOR + port.toString(); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 556 | } |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 557 | |
| 558 | @Override |
| 559 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 560 | return Objects.hash(type().ordinal(), port); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | @Override |
| 564 | public boolean equals(Object obj) { |
| 565 | if (this == obj) { |
| 566 | return true; |
| 567 | } |
| 568 | if (obj instanceof OutputInstruction) { |
| 569 | OutputInstruction that = (OutputInstruction) obj; |
Yuta HIGUCHI | 4ce6529 | 2014-11-01 12:09:55 -0700 | [diff] [blame] | 570 | return Objects.equals(port, that.port); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 571 | |
| 572 | } |
| 573 | return false; |
| 574 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 577 | /** |
| 578 | * Group Instruction. |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 579 | */ |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 580 | public static final class GroupInstruction implements Instruction { |
| 581 | private final GroupId groupId; |
| 582 | |
| 583 | private GroupInstruction(GroupId groupId) { |
| 584 | this.groupId = groupId; |
| 585 | } |
| 586 | |
| 587 | public GroupId groupId() { |
| 588 | return groupId; |
| 589 | } |
| 590 | |
| 591 | @Override |
| 592 | public Type type() { |
| 593 | return Type.GROUP; |
| 594 | } |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 595 | |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 596 | @Override |
| 597 | public String toString() { |
Saurav Das | 0fd79d9 | 2016-03-07 10:58:36 -0800 | [diff] [blame] | 598 | return type().toString() + SEPARATOR + "0x" + Integer.toHexString(groupId.id()); |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | @Override |
| 602 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 603 | return Objects.hash(type().ordinal(), groupId); |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | @Override |
| 607 | public boolean equals(Object obj) { |
| 608 | if (this == obj) { |
| 609 | return true; |
| 610 | } |
| 611 | if (obj instanceof GroupInstruction) { |
| 612 | GroupInstruction that = (GroupInstruction) obj; |
| 613 | return Objects.equals(groupId, that.groupId); |
| 614 | |
| 615 | } |
| 616 | return false; |
| 617 | } |
| 618 | } |
| 619 | |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 620 | /** |
Steffen Gebert | bbfdaaa | 2015-09-29 11:01:46 +0200 | [diff] [blame] | 621 | * Set-Queue Instruction. |
| 622 | */ |
| 623 | public static final class SetQueueInstruction implements Instruction { |
| 624 | private final long queueId; |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 625 | private final PortNumber port; |
Steffen Gebert | bbfdaaa | 2015-09-29 11:01:46 +0200 | [diff] [blame] | 626 | |
| 627 | private SetQueueInstruction(long queueId) { |
| 628 | this.queueId = queueId; |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 629 | this.port = null; |
| 630 | } |
| 631 | |
| 632 | private SetQueueInstruction(long queueId, PortNumber port) { |
| 633 | this.queueId = queueId; |
| 634 | this.port = port; |
Steffen Gebert | bbfdaaa | 2015-09-29 11:01:46 +0200 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | public long queueId() { |
| 638 | return queueId; |
| 639 | } |
| 640 | |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 641 | public PortNumber port() { |
| 642 | return port; |
| 643 | } |
| 644 | |
Steffen Gebert | bbfdaaa | 2015-09-29 11:01:46 +0200 | [diff] [blame] | 645 | @Override |
| 646 | public Type type() { |
| 647 | return Type.QUEUE; |
| 648 | } |
| 649 | |
| 650 | @Override |
| 651 | public String toString() { |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 652 | MoreObjects.ToStringHelper toStringHelper = toStringHelper(type().toString()); |
| 653 | toStringHelper.add("queueId", queueId); |
| 654 | |
| 655 | if (port() != null) { |
| 656 | toStringHelper.add("port", port); |
| 657 | } |
| 658 | return toStringHelper.toString(); |
Steffen Gebert | bbfdaaa | 2015-09-29 11:01:46 +0200 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | @Override |
| 662 | public int hashCode() { |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 663 | return Objects.hash(type().ordinal(), queueId, port); |
Steffen Gebert | bbfdaaa | 2015-09-29 11:01:46 +0200 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | @Override |
| 667 | public boolean equals(Object obj) { |
| 668 | if (this == obj) { |
| 669 | return true; |
| 670 | } |
| 671 | if (obj instanceof SetQueueInstruction) { |
| 672 | SetQueueInstruction that = (SetQueueInstruction) obj; |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 673 | return Objects.equals(queueId, that.queueId) && Objects.equals(port, that.port); |
Steffen Gebert | bbfdaaa | 2015-09-29 11:01:46 +0200 | [diff] [blame] | 674 | |
| 675 | } |
| 676 | return false; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | /** |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame] | 681 | * A meter instruction. |
| 682 | */ |
| 683 | public static final class MeterInstruction implements Instruction { |
| 684 | private final MeterId meterId; |
| 685 | |
| 686 | private MeterInstruction(MeterId meterId) { |
| 687 | this.meterId = meterId; |
| 688 | } |
| 689 | |
| 690 | public MeterId meterId() { |
| 691 | return meterId; |
| 692 | } |
| 693 | |
| 694 | @Override |
| 695 | public Type type() { |
| 696 | return Type.METER; |
| 697 | } |
| 698 | |
| 699 | @Override |
| 700 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 701 | return type().toString() + SEPARATOR + meterId.id(); |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | @Override |
| 705 | public int hashCode() { |
| 706 | return Objects.hash(type().ordinal(), meterId); |
| 707 | } |
| 708 | |
| 709 | @Override |
| 710 | public boolean equals(Object obj) { |
| 711 | if (this == obj) { |
| 712 | return true; |
| 713 | } |
| 714 | if (obj instanceof MeterInstruction) { |
| 715 | MeterInstruction that = (MeterInstruction) obj; |
| 716 | return Objects.equals(meterId, that.meterId); |
| 717 | |
| 718 | } |
| 719 | return false; |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | /** |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 724 | * Transition instruction. |
| 725 | */ |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 726 | public static class TableTypeTransition implements Instruction { |
| 727 | private final Integer tableId; |
| 728 | |
| 729 | TableTypeTransition(Integer tableId) { |
| 730 | this.tableId = tableId; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | @Override |
| 734 | public Type type() { |
| 735 | return Type.TABLE; |
| 736 | } |
| 737 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 738 | public Integer tableId() { |
| 739 | return this.tableId; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | @Override |
| 743 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 744 | return type().toString() + SEPARATOR + this.tableId; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | @Override |
| 748 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 749 | return Objects.hash(type().ordinal(), tableId); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | @Override |
| 753 | public boolean equals(Object obj) { |
| 754 | if (this == obj) { |
| 755 | return true; |
| 756 | } |
| 757 | if (obj instanceof TableTypeTransition) { |
| 758 | TableTypeTransition that = (TableTypeTransition) obj; |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 759 | return Objects.equals(tableId, that.tableId); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 760 | |
| 761 | } |
| 762 | return false; |
| 763 | } |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 764 | } |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 765 | |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 766 | /** |
| 767 | * Metadata instruction. |
| 768 | */ |
| 769 | public static class MetadataInstruction implements Instruction { |
| 770 | private final long metadata; |
| 771 | private final long metadataMask; |
| 772 | |
| 773 | MetadataInstruction(long metadata, long metadataMask) { |
| 774 | this.metadata = metadata; |
| 775 | this.metadataMask = metadataMask; |
| 776 | } |
| 777 | |
| 778 | @Override |
| 779 | public Type type() { |
| 780 | return Type.METADATA; |
| 781 | } |
| 782 | |
| 783 | public long metadata() { |
| 784 | return this.metadata; |
| 785 | } |
| 786 | |
| 787 | public long metadataMask() { |
| 788 | return this.metadataMask; |
| 789 | } |
| 790 | |
| 791 | @Override |
| 792 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 793 | return type().toString() + SEPARATOR + |
| 794 | Long.toHexString(this.metadata) + "/" + |
| 795 | Long.toHexString(this.metadataMask); |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | @Override |
| 799 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 800 | return Objects.hash(type().ordinal(), metadata, metadataMask); |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | @Override |
| 804 | public boolean equals(Object obj) { |
| 805 | if (this == obj) { |
| 806 | return true; |
| 807 | } |
| 808 | if (obj instanceof MetadataInstruction) { |
| 809 | MetadataInstruction that = (MetadataInstruction) obj; |
| 810 | return Objects.equals(metadata, that.metadata) && |
| 811 | Objects.equals(metadataMask, that.metadataMask); |
| 812 | |
| 813 | } |
| 814 | return false; |
| 815 | } |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 816 | } |
Saurav Das | 73a7dd4 | 2015-08-19 22:20:31 -0700 | [diff] [blame] | 817 | |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 818 | /** |
| 819 | * Extension instruction. |
| 820 | */ |
| 821 | public static class ExtensionInstructionWrapper implements Instruction { |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 822 | private final ExtensionTreatment extensionTreatment; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 823 | private final DeviceId deviceId; |
| 824 | |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 825 | ExtensionInstructionWrapper(ExtensionTreatment extension, DeviceId deviceId) { |
| 826 | extensionTreatment = extension; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 827 | this.deviceId = deviceId; |
| 828 | } |
| 829 | |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 830 | public ExtensionTreatment extensionInstruction() { |
| 831 | return extensionTreatment; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | public DeviceId deviceId() { |
| 835 | return deviceId; |
| 836 | } |
| 837 | |
| 838 | @Override |
| 839 | public Type type() { |
| 840 | return Type.EXTENSION; |
| 841 | } |
| 842 | |
| 843 | @Override |
| 844 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 845 | return type().toString() + SEPARATOR + deviceId + "/" + extensionTreatment; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | @Override |
| 849 | public int hashCode() { |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 850 | return Objects.hash(type().ordinal(), extensionTreatment, deviceId); |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | @Override |
| 854 | public boolean equals(Object obj) { |
| 855 | if (this == obj) { |
| 856 | return true; |
| 857 | } |
| 858 | if (obj instanceof ExtensionInstructionWrapper) { |
| 859 | ExtensionInstructionWrapper that = (ExtensionInstructionWrapper) obj; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 860 | return Objects.equals(extensionTreatment, that.extensionTreatment) |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 861 | && Objects.equals(deviceId, that.deviceId); |
| 862 | |
| 863 | } |
| 864 | return false; |
| 865 | } |
| 866 | } |
| 867 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 868 | } |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 869 | |
| 870 | |