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