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