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