Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow.instructions; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 18 | import org.onlab.packet.Ethernet; |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.MacAddress; |
| 21 | import org.onlab.packet.MplsLabel; |
| 22 | import org.onlab.packet.VlanId; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 23 | import org.onosproject.core.GroupId; |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 24 | import org.onosproject.net.OchSignal; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.net.PortNumber; |
| 26 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType; |
| 27 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 28 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType; |
| 29 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 30 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 31 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 32 | |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 33 | import java.util.Objects; |
| 34 | |
| 35 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 36 | import static com.google.common.base.Preconditions.checkNotNull; |
alshabib | 64231f6 | 2014-09-16 17:58:36 -0700 | [diff] [blame] | 37 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 38 | /** |
| 39 | * Factory class for creating various traffic treatment instructions. |
| 40 | */ |
| 41 | public final class Instructions { |
| 42 | |
| 43 | |
| 44 | // Ban construction |
| 45 | private Instructions() {} |
| 46 | |
| 47 | /** |
| 48 | * Creates an output instruction using the specified port number. This can |
| 49 | * include logical ports such as CONTROLLER, FLOOD, etc. |
| 50 | * |
| 51 | * @param number port number |
| 52 | * @return output instruction |
| 53 | */ |
| 54 | public static OutputInstruction createOutput(final PortNumber number) { |
| 55 | checkNotNull(number, "PortNumber cannot be null"); |
| 56 | return new OutputInstruction(number); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Creates a drop instruction. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 61 | * |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 62 | * @return drop instruction |
| 63 | */ |
| 64 | public static DropInstruction createDrop() { |
| 65 | return new DropInstruction(); |
| 66 | } |
| 67 | |
| 68 | /** |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 69 | * Creates a group instruction. |
| 70 | * |
| 71 | * @param groupId Group Id |
| 72 | * @return group instruction |
| 73 | */ |
| 74 | public static GroupInstruction createGroup(final GroupId groupId) { |
| 75 | checkNotNull(groupId, "GroupId cannot be null"); |
| 76 | return new GroupInstruction(groupId); |
| 77 | } |
| 78 | |
| 79 | /** |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 80 | * Creates a l0 modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 81 | * |
| 82 | * @param lambda the lambda to modify to |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 83 | * @return a l0 modification |
| 84 | */ |
| 85 | public static L0ModificationInstruction modL0Lambda(short lambda) { |
| 86 | checkNotNull(lambda, "L0 lambda cannot be null"); |
| 87 | return new ModLambdaInstruction(L0SubType.LAMBDA, lambda); |
| 88 | } |
| 89 | |
| 90 | /** |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 91 | * Creates an L0 modification with the specified OCh signal. |
| 92 | * |
| 93 | * @param lambda OCh signal |
| 94 | * @return an L0 modification |
| 95 | */ |
| 96 | public static L0ModificationInstruction modL0OchSignal(OchSignal lambda) { |
| 97 | checkNotNull(lambda, "L0 OCh signal cannot be null"); |
| 98 | return new L0ModificationInstruction.ModOchSignalInstruction(lambda); |
| 99 | } |
| 100 | |
| 101 | /** |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 102 | * Creates a l2 src modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 103 | * |
| 104 | * @param addr the mac address to modify to |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 105 | * @return a l2 modification |
| 106 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 107 | public static L2ModificationInstruction modL2Src(MacAddress addr) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 108 | checkNotNull(addr, "Src l2 address cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 109 | return new L2ModificationInstruction.ModEtherInstruction( |
| 110 | L2ModificationInstruction.L2SubType.ETH_SRC, addr); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Creates a L2 dst modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 115 | * |
| 116 | * @param addr the mac address to modify to |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 117 | * @return a L2 modification |
| 118 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 119 | public static L2ModificationInstruction modL2Dst(MacAddress addr) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 120 | checkNotNull(addr, "Dst l2 address cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 121 | return new L2ModificationInstruction.ModEtherInstruction( |
| 122 | L2ModificationInstruction.L2SubType.ETH_DST, addr); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 126 | * Creates a VLAN ID modification. |
| 127 | * |
| 128 | * @param vlanId the VLAN ID to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 129 | * @return a L2 modification |
| 130 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 131 | public static L2ModificationInstruction modVlanId(VlanId vlanId) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 132 | checkNotNull(vlanId, "VLAN id cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 133 | return new L2ModificationInstruction.ModVlanIdInstruction(vlanId); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 134 | } |
| 135 | |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 136 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 137 | * Creates a VLAN PCP modification. |
| 138 | * |
| 139 | * @param vlanPcp the PCP to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 140 | * @return a L2 modification |
| 141 | */ |
| 142 | public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) { |
| 143 | checkNotNull(vlanPcp, "VLAN Pcp cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 144 | return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 148 | * Creates a MPLS label modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 149 | * |
| 150 | * @param mplsLabel MPLS label to set |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 151 | * @return a L2 Modification |
| 152 | */ |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 153 | public static L2ModificationInstruction modMplsLabel(MplsLabel mplsLabel) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 154 | checkNotNull(mplsLabel, "MPLS label cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 155 | return new L2ModificationInstruction.ModMplsLabelInstruction(mplsLabel); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 156 | } |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 157 | |
| 158 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 159 | * Creates a MPLS decrement TTL modification. |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 160 | * |
| 161 | * @return a L2 Modification |
| 162 | */ |
| 163 | public static L2ModificationInstruction decMplsTtl() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 164 | return new L2ModificationInstruction.ModMplsTtlInstruction(); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 165 | } |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 166 | |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 167 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 168 | * Creates a L3 IPv4 src modification. |
| 169 | * |
| 170 | * @param addr the IPv4 address to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 171 | * @return a L3 modification |
| 172 | */ |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 173 | public static L3ModificationInstruction modL3Src(IpAddress addr) { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 174 | checkNotNull(addr, "Src l3 IPv4 address cannot be null"); |
| 175 | return new ModIPInstruction(L3SubType.IPV4_SRC, addr); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 179 | * Creates a L3 IPv4 dst modification. |
| 180 | * |
| 181 | * @param addr the IPv4 address to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 182 | * @return a L3 modification |
| 183 | */ |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 184 | public static L3ModificationInstruction modL3Dst(IpAddress addr) { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 185 | checkNotNull(addr, "Dst l3 IPv4 address cannot be null"); |
| 186 | return new ModIPInstruction(L3SubType.IPV4_DST, addr); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Creates a L3 IPv6 src modification. |
| 191 | * |
| 192 | * @param addr the IPv6 address to modify to |
| 193 | * @return a L3 modification |
| 194 | */ |
| 195 | public static L3ModificationInstruction modL3IPv6Src(IpAddress addr) { |
| 196 | checkNotNull(addr, "Src l3 IPv6 address cannot be null"); |
| 197 | return new ModIPInstruction(L3SubType.IPV6_SRC, addr); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Creates a L3 IPv6 dst modification. |
| 202 | * |
| 203 | * @param addr the IPv6 address to modify to |
| 204 | * @return a L3 modification |
| 205 | */ |
| 206 | public static L3ModificationInstruction modL3IPv6Dst(IpAddress addr) { |
| 207 | checkNotNull(addr, "Dst l3 IPv6 address cannot be null"); |
| 208 | return new ModIPInstruction(L3SubType.IPV6_DST, addr); |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Creates a L3 IPv6 Flow Label modification. |
| 213 | * |
| 214 | * @param flowLabel the IPv6 flow label to modify to (20 bits) |
| 215 | * @return a L3 modification |
| 216 | */ |
| 217 | public static L3ModificationInstruction modL3IPv6FlowLabel(int flowLabel) { |
| 218 | return new ModIPv6FlowLabelInstruction(flowLabel); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 221 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 222 | * Creates a L3 decrement TTL modification. |
| 223 | * |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 224 | * @return a L3 modification |
| 225 | */ |
| 226 | public static L3ModificationInstruction decNwTtl() { |
| 227 | return new ModTtlInstruction(L3SubType.DEC_TTL); |
| 228 | } |
| 229 | |
| 230 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 231 | * Creates a L3 copy TTL to outer header modification. |
| 232 | * |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 233 | * @return a L3 modification |
| 234 | */ |
| 235 | public static L3ModificationInstruction copyTtlOut() { |
| 236 | return new ModTtlInstruction(L3SubType.TTL_OUT); |
| 237 | } |
| 238 | |
| 239 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 240 | * Creates a L3 copy TTL to inner header modification. |
| 241 | * |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 242 | * @return a L3 modification |
| 243 | */ |
| 244 | public static L3ModificationInstruction copyTtlIn() { |
| 245 | return new ModTtlInstruction(L3SubType.TTL_IN); |
| 246 | } |
| 247 | |
| 248 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 249 | * Creates a push MPLS header instruction. |
| 250 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 251 | * @return a L2 modification. |
| 252 | */ |
| 253 | public static Instruction pushMpls() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 254 | return new L2ModificationInstruction.PushHeaderInstructions( |
| 255 | L2ModificationInstruction.L2SubType.MPLS_PUSH, |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 256 | Ethernet.MPLS_UNICAST); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 260 | * Creates a pop MPLS header instruction. |
| 261 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 262 | * @return a L2 modification. |
| 263 | */ |
| 264 | public static Instruction popMpls() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 265 | return new L2ModificationInstruction.PushHeaderInstructions( |
| 266 | L2ModificationInstruction.L2SubType.MPLS_POP, |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 267 | Ethernet.MPLS_UNICAST); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 268 | } |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 269 | |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 270 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 271 | * Creates a pop MPLS header instruction with a particular ethertype. |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 272 | * |
| 273 | * @param etherType Ethernet type to set |
| 274 | * @return a L2 modification. |
| 275 | */ |
| 276 | public static Instruction popMpls(Short etherType) { |
| 277 | checkNotNull(etherType, "Ethernet type cannot be null"); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 278 | return new L2ModificationInstruction.PushHeaderInstructions( |
| 279 | L2ModificationInstruction.L2SubType.MPLS_POP, etherType); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 282 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 283 | * Creates a pop VLAN header instruction. |
| 284 | * |
| 285 | * @return a L2 modification |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 286 | */ |
| 287 | public static Instruction popVlan() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 288 | return new L2ModificationInstruction.PopVlanInstruction( |
| 289 | L2ModificationInstruction.L2SubType.VLAN_POP); |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 293 | * Creates a push VLAN header instruction. |
| 294 | * |
| 295 | * @return a L2 modification |
| 296 | */ |
| 297 | public static Instruction pushVlan() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 298 | return new L2ModificationInstruction.PushHeaderInstructions( |
| 299 | L2ModificationInstruction.L2SubType.VLAN_PUSH, Ethernet.TYPE_VLAN); |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /** |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 303 | * Sends the packet to the table id. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 304 | * |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 305 | * @param tableId flow rule table id |
Thomas Vachuska | 3e2b651 | 2015-03-05 09:25:03 -0800 | [diff] [blame] | 306 | * @return table type transition instruction |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 307 | */ |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 308 | public static Instruction transition(Integer tableId) { |
| 309 | checkNotNull(tableId, "Table id cannot be null"); |
| 310 | return new TableTypeTransition(tableId); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 313 | /** |
| 314 | * Drop instruction. |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 315 | */ |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 316 | public static final class DropInstruction implements Instruction { |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 317 | |
| 318 | private DropInstruction() {} |
| 319 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 320 | @Override |
| 321 | public Type type() { |
| 322 | return Type.DROP; |
| 323 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 324 | |
| 325 | @Override |
| 326 | public String toString() { |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 327 | return toStringHelper(type().toString()).toString(); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 328 | } |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 329 | |
| 330 | @Override |
| 331 | public int hashCode() { |
| 332 | return Objects.hash(type()); |
| 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public boolean equals(Object obj) { |
| 337 | if (this == obj) { |
| 338 | return true; |
| 339 | } |
| 340 | if (obj instanceof DropInstruction) { |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 341 | return true; |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 342 | } |
| 343 | return false; |
| 344 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 347 | /** |
| 348 | * Output Instruction. |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 349 | */ |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 350 | public static final class OutputInstruction implements Instruction { |
| 351 | private final PortNumber port; |
| 352 | |
| 353 | private OutputInstruction(PortNumber port) { |
| 354 | this.port = port; |
| 355 | } |
| 356 | |
| 357 | public PortNumber port() { |
| 358 | return port; |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public Type type() { |
| 363 | return Type.OUTPUT; |
| 364 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 365 | @Override |
| 366 | public String toString() { |
| 367 | return toStringHelper(type().toString()) |
| 368 | .add("port", port).toString(); |
| 369 | } |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 370 | |
| 371 | @Override |
| 372 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 373 | return Objects.hash(type(), port); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | @Override |
| 377 | public boolean equals(Object obj) { |
| 378 | if (this == obj) { |
| 379 | return true; |
| 380 | } |
| 381 | if (obj instanceof OutputInstruction) { |
| 382 | OutputInstruction that = (OutputInstruction) obj; |
Yuta HIGUCHI | 4ce6529 | 2014-11-01 12:09:55 -0700 | [diff] [blame] | 383 | return Objects.equals(port, that.port); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 384 | |
| 385 | } |
| 386 | return false; |
| 387 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 390 | /** |
| 391 | * Group Instruction. |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 392 | */ |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 393 | public static final class GroupInstruction implements Instruction { |
| 394 | private final GroupId groupId; |
| 395 | |
| 396 | private GroupInstruction(GroupId groupId) { |
| 397 | this.groupId = groupId; |
| 398 | } |
| 399 | |
| 400 | public GroupId groupId() { |
| 401 | return groupId; |
| 402 | } |
| 403 | |
| 404 | @Override |
| 405 | public Type type() { |
| 406 | return Type.GROUP; |
| 407 | } |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 408 | |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 409 | @Override |
| 410 | public String toString() { |
| 411 | return toStringHelper(type().toString()) |
| 412 | .add("group ID", groupId.id()).toString(); |
| 413 | } |
| 414 | |
| 415 | @Override |
| 416 | public int hashCode() { |
| 417 | return Objects.hash(type(), groupId); |
| 418 | } |
| 419 | |
| 420 | @Override |
| 421 | public boolean equals(Object obj) { |
| 422 | if (this == obj) { |
| 423 | return true; |
| 424 | } |
| 425 | if (obj instanceof GroupInstruction) { |
| 426 | GroupInstruction that = (GroupInstruction) obj; |
| 427 | return Objects.equals(groupId, that.groupId); |
| 428 | |
| 429 | } |
| 430 | return false; |
| 431 | } |
| 432 | } |
| 433 | |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 434 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 435 | public static class TableTypeTransition implements Instruction { |
| 436 | private final Integer tableId; |
| 437 | |
| 438 | TableTypeTransition(Integer tableId) { |
| 439 | this.tableId = tableId; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | @Override |
| 443 | public Type type() { |
| 444 | return Type.TABLE; |
| 445 | } |
| 446 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 447 | public Integer tableId() { |
| 448 | return this.tableId; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | @Override |
| 452 | public String toString() { |
| 453 | return toStringHelper(type().toString()) |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 454 | .add("tableId", this.tableId).toString(); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | @Override |
| 458 | public int hashCode() { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 459 | return Objects.hash(type(), tableId); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | @Override |
| 463 | public boolean equals(Object obj) { |
| 464 | if (this == obj) { |
| 465 | return true; |
| 466 | } |
| 467 | if (obj instanceof TableTypeTransition) { |
| 468 | TableTypeTransition that = (TableTypeTransition) obj; |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 469 | return Objects.equals(tableId, that.tableId); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 470 | |
| 471 | } |
| 472 | return false; |
| 473 | } |
| 474 | |
| 475 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 476 | } |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 477 | |
| 478 | |