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