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