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