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