Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 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; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 25 | import org.onosproject.net.flow.FlowRule; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 26 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType; |
| 27 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; |
| 28 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType; |
| 29 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; |
| 30 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType; |
| 31 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 32 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 33 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 34 | |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 35 | import java.util.Objects; |
| 36 | |
| 37 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 38 | import static com.google.common.base.Preconditions.checkNotNull; |
| 39 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction; |
| 40 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsTtlInstruction; |
| 41 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; |
| 42 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction; |
| 43 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.PopVlanInstruction; |
| 44 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeaderInstructions; |
| 45 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.StripVlanInstruction; |
alshabib | 64231f6 | 2014-09-16 17:58:36 -0700 | [diff] [blame] | 46 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 47 | /** |
| 48 | * Factory class for creating various traffic treatment instructions. |
| 49 | */ |
| 50 | public final class Instructions { |
| 51 | |
| 52 | |
| 53 | // Ban construction |
| 54 | private Instructions() {} |
| 55 | |
| 56 | /** |
| 57 | * Creates an output instruction using the specified port number. This can |
| 58 | * include logical ports such as CONTROLLER, FLOOD, etc. |
| 59 | * |
| 60 | * @param number port number |
| 61 | * @return output instruction |
| 62 | */ |
| 63 | public static OutputInstruction createOutput(final PortNumber number) { |
| 64 | checkNotNull(number, "PortNumber cannot be null"); |
| 65 | return new OutputInstruction(number); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Creates a drop instruction. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 70 | * |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 71 | * @return drop instruction |
| 72 | */ |
| 73 | public static DropInstruction createDrop() { |
| 74 | return new DropInstruction(); |
| 75 | } |
| 76 | |
| 77 | /** |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 78 | * Creates a group instruction. |
| 79 | * |
| 80 | * @param groupId Group Id |
| 81 | * @return group instruction |
| 82 | */ |
| 83 | public static GroupInstruction createGroup(final GroupId groupId) { |
| 84 | checkNotNull(groupId, "GroupId cannot be null"); |
| 85 | return new GroupInstruction(groupId); |
| 86 | } |
| 87 | |
| 88 | /** |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 89 | * Creates a l0 modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 90 | * |
| 91 | * @param lambda the lambda to modify to |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 92 | * @return a l0 modification |
| 93 | */ |
| 94 | public static L0ModificationInstruction modL0Lambda(short lambda) { |
| 95 | checkNotNull(lambda, "L0 lambda cannot be null"); |
| 96 | return new ModLambdaInstruction(L0SubType.LAMBDA, lambda); |
| 97 | } |
| 98 | |
| 99 | /** |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 100 | * Creates a l2 src modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 101 | * |
| 102 | * @param addr the mac address to modify to |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 103 | * @return a l2 modification |
| 104 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 105 | public static L2ModificationInstruction modL2Src(MacAddress addr) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 106 | checkNotNull(addr, "Src l2 address cannot be null"); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 107 | return new ModEtherInstruction(L2SubType.ETH_SRC, addr); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Creates a L2 dst modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 112 | * |
| 113 | * @param addr the mac address to modify to |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 114 | * @return a L2 modification |
| 115 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 116 | public static L2ModificationInstruction modL2Dst(MacAddress addr) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 117 | checkNotNull(addr, "Dst l2 address cannot be null"); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 118 | return new ModEtherInstruction(L2SubType.ETH_DST, addr); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 122 | * Creates a VLAN ID modification. |
| 123 | * |
| 124 | * @param vlanId the VLAN ID to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 125 | * @return a L2 modification |
| 126 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 127 | public static L2ModificationInstruction modVlanId(VlanId vlanId) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 128 | checkNotNull(vlanId, "VLAN id cannot be null"); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 129 | return new ModVlanIdInstruction(vlanId); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 130 | } |
| 131 | |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 132 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 133 | * Creates a VLAN PCP modification. |
| 134 | * |
| 135 | * @param vlanPcp the PCP to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 136 | * @return a L2 modification |
| 137 | */ |
| 138 | public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) { |
| 139 | checkNotNull(vlanPcp, "VLAN Pcp cannot be null"); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 140 | return new ModVlanPcpInstruction(vlanPcp); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /** |
alshabib | ab21b2d | 2015-03-04 18:35:33 -0800 | [diff] [blame] | 144 | * Strips the VLAN tag if one is present. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 145 | * |
alshabib | ab21b2d | 2015-03-04 18:35:33 -0800 | [diff] [blame] | 146 | * @return a L2 modification |
| 147 | */ |
| 148 | public static L2ModificationInstruction stripVlanId() { |
| 149 | return new StripVlanInstruction(); |
| 150 | } |
| 151 | |
| 152 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 153 | * Creates a MPLS label modification. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 154 | * |
| 155 | * @param mplsLabel MPLS label to set |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 156 | * @return a L2 Modification |
| 157 | */ |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 158 | public static L2ModificationInstruction modMplsLabel(MplsLabel mplsLabel) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 159 | checkNotNull(mplsLabel, "MPLS label cannot be null"); |
| 160 | return new ModMplsLabelInstruction(mplsLabel); |
| 161 | } |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 162 | |
| 163 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 164 | * Creates a MPLS decrement TTL modification. |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 165 | * |
| 166 | * @return a L2 Modification |
| 167 | */ |
| 168 | public static L2ModificationInstruction decMplsTtl() { |
| 169 | return new ModMplsTtlInstruction(); |
| 170 | } |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 171 | |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 172 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 173 | * Creates a L3 IPv4 src modification. |
| 174 | * |
| 175 | * @param addr the IPv4 address to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 176 | * @return a L3 modification |
| 177 | */ |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 178 | public static L3ModificationInstruction modL3Src(IpAddress addr) { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 179 | checkNotNull(addr, "Src l3 IPv4 address cannot be null"); |
| 180 | return new ModIPInstruction(L3SubType.IPV4_SRC, addr); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 184 | * Creates a L3 IPv4 dst modification. |
| 185 | * |
| 186 | * @param addr the IPv4 address to modify to |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 187 | * @return a L3 modification |
| 188 | */ |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 189 | public static L3ModificationInstruction modL3Dst(IpAddress addr) { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 190 | checkNotNull(addr, "Dst l3 IPv4 address cannot be null"); |
| 191 | return new ModIPInstruction(L3SubType.IPV4_DST, addr); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Creates a L3 IPv6 src modification. |
| 196 | * |
| 197 | * @param addr the IPv6 address to modify to |
| 198 | * @return a L3 modification |
| 199 | */ |
| 200 | public static L3ModificationInstruction modL3IPv6Src(IpAddress addr) { |
| 201 | checkNotNull(addr, "Src l3 IPv6 address cannot be null"); |
| 202 | return new ModIPInstruction(L3SubType.IPV6_SRC, addr); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Creates a L3 IPv6 dst modification. |
| 207 | * |
| 208 | * @param addr the IPv6 address to modify to |
| 209 | * @return a L3 modification |
| 210 | */ |
| 211 | public static L3ModificationInstruction modL3IPv6Dst(IpAddress addr) { |
| 212 | checkNotNull(addr, "Dst l3 IPv6 address cannot be null"); |
| 213 | return new ModIPInstruction(L3SubType.IPV6_DST, addr); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Creates a L3 IPv6 Flow Label modification. |
| 218 | * |
| 219 | * @param flowLabel the IPv6 flow label to modify to (20 bits) |
| 220 | * @return a L3 modification |
| 221 | */ |
| 222 | public static L3ModificationInstruction modL3IPv6FlowLabel(int flowLabel) { |
| 223 | return new ModIPv6FlowLabelInstruction(flowLabel); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 226 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 227 | * Creates a L3 decrement TTL modification. |
| 228 | * |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 229 | * @return a L3 modification |
| 230 | */ |
| 231 | public static L3ModificationInstruction decNwTtl() { |
| 232 | return new ModTtlInstruction(L3SubType.DEC_TTL); |
| 233 | } |
| 234 | |
| 235 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 236 | * Creates a L3 copy TTL to outer header modification. |
| 237 | * |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 238 | * @return a L3 modification |
| 239 | */ |
| 240 | public static L3ModificationInstruction copyTtlOut() { |
| 241 | return new ModTtlInstruction(L3SubType.TTL_OUT); |
| 242 | } |
| 243 | |
| 244 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 245 | * Creates a L3 copy TTL to inner header modification. |
| 246 | * |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 247 | * @return a L3 modification |
| 248 | */ |
| 249 | public static L3ModificationInstruction copyTtlIn() { |
| 250 | return new ModTtlInstruction(L3SubType.TTL_IN); |
| 251 | } |
| 252 | |
| 253 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 254 | * Creates a push MPLS header instruction. |
| 255 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 256 | * @return a L2 modification. |
| 257 | */ |
| 258 | public static Instruction pushMpls() { |
| 259 | return new PushHeaderInstructions(L2SubType.MPLS_PUSH, |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 260 | Ethernet.MPLS_UNICAST); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 264 | * Creates a pop MPLS header instruction. |
| 265 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 266 | * @return a L2 modification. |
| 267 | */ |
| 268 | public static Instruction popMpls() { |
| 269 | return new PushHeaderInstructions(L2SubType.MPLS_POP, |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 270 | Ethernet.MPLS_UNICAST); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 271 | } |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 272 | |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 273 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 274 | * Creates a pop MPLS header instruction with a particular ethertype. |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 275 | * |
| 276 | * @param etherType Ethernet type to set |
| 277 | * @return a L2 modification. |
| 278 | */ |
| 279 | public static Instruction popMpls(Short etherType) { |
| 280 | checkNotNull(etherType, "Ethernet type cannot be null"); |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 281 | return new PushHeaderInstructions(L2SubType.MPLS_POP, etherType); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 282 | } |
| 283 | |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 284 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 285 | * Creates a pop VLAN header instruction. |
| 286 | * |
| 287 | * @return a L2 modification |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 288 | */ |
| 289 | public static Instruction popVlan() { |
| 290 | return new PopVlanInstruction(L2SubType.VLAN_POP); |
| 291 | } |
| 292 | |
| 293 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 294 | * Creates a push VLAN header instruction. |
| 295 | * |
| 296 | * @return a L2 modification |
| 297 | */ |
| 298 | public static Instruction pushVlan() { |
| 299 | return new PushHeaderInstructions(L2SubType.VLAN_PUSH, Ethernet.TYPE_VLAN); |
| 300 | } |
| 301 | |
| 302 | /** |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 303 | * Sends the packet to the table described in 'type'. |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame^] | 304 | * |
Thomas Vachuska | 3e2b651 | 2015-03-05 09:25:03 -0800 | [diff] [blame] | 305 | * @param type flow rule table type |
| 306 | * @return table type transition instruction |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 307 | */ |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 308 | public static Instruction transition(FlowRule.Type type) { |
| 309 | checkNotNull(type, "Table type cannot be null"); |
| 310 | return new TableTypeTransition(type); |
| 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 | // FIXME: Temporary support for this. This should probably become it's own |
| 435 | // type like other instructions. |
| 436 | public static class TableTypeTransition implements Instruction { |
| 437 | private final FlowRule.Type tableType; |
| 438 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 439 | TableTypeTransition(FlowRule.Type type) { |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 440 | this.tableType = type; |
| 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public Type type() { |
| 445 | return Type.TABLE; |
| 446 | } |
| 447 | |
| 448 | public FlowRule.Type tableType() { |
| 449 | return this.tableType; |
| 450 | } |
| 451 | |
| 452 | @Override |
| 453 | public String toString() { |
| 454 | return toStringHelper(type().toString()) |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 455 | .add("tableType", this.tableType).toString(); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | @Override |
| 459 | public int hashCode() { |
| 460 | return Objects.hash(type(), tableType); |
| 461 | } |
| 462 | |
| 463 | @Override |
| 464 | public boolean equals(Object obj) { |
| 465 | if (this == obj) { |
| 466 | return true; |
| 467 | } |
| 468 | if (obj instanceof TableTypeTransition) { |
| 469 | TableTypeTransition that = (TableTypeTransition) obj; |
| 470 | return Objects.equals(tableType, that.tableType); |
| 471 | |
| 472 | } |
| 473 | return false; |
| 474 | } |
| 475 | |
| 476 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 477 | } |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 478 | |
| 479 | |