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 | |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 18 | import org.onlab.packet.EthType; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 19 | import org.onlab.packet.MacAddress; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 20 | import org.onlab.packet.MplsLabel; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 21 | import org.onlab.packet.VlanId; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 22 | |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 23 | import java.util.Objects; |
| 24 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 25 | /** |
| 26 | * Abstraction of a single traffic treatment step. |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 27 | */ |
| 28 | public abstract class L2ModificationInstruction implements Instruction { |
| 29 | |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 30 | private static final String SEPARATOR = ":"; |
| 31 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Represents the type of traffic treatment. |
| 34 | */ |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 35 | public enum L2SubType { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Ether src modification. |
| 38 | */ |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 39 | ETH_SRC, |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Ether dst modification. |
| 43 | */ |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 44 | ETH_DST, |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 47 | * VLAN id modification. |
| 48 | */ |
| 49 | VLAN_ID, |
| 50 | |
| 51 | /** |
| 52 | * VLAN priority modification. |
| 53 | */ |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 54 | VLAN_PCP, |
| 55 | |
| 56 | /** |
| 57 | * MPLS Label modification. |
| 58 | */ |
| 59 | MPLS_LABEL, |
| 60 | |
| 61 | /** |
| 62 | * MPLS Push modification. |
| 63 | */ |
| 64 | MPLS_PUSH, |
| 65 | |
| 66 | /** |
| 67 | * MPLS Pop modification. |
| 68 | */ |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 69 | MPLS_POP, |
| 70 | |
| 71 | /** |
| 72 | * MPLS TTL modification. |
| 73 | */ |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 74 | DEC_MPLS_TTL, |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 75 | |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 76 | /** |
| 77 | * VLAN Pop modification. |
| 78 | */ |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 79 | VLAN_POP, |
| 80 | |
| 81 | /** |
| 82 | * VLAN Push modification. |
| 83 | */ |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 84 | VLAN_PUSH, |
| 85 | |
| 86 | /** |
Saurav Das | 73a7dd4 | 2015-08-19 22:20:31 -0700 | [diff] [blame] | 87 | * Tunnel id modification. |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 88 | */ |
Saurav Das | 73a7dd4 | 2015-08-19 22:20:31 -0700 | [diff] [blame] | 89 | TUNNEL_ID, |
| 90 | |
| 91 | /** |
| 92 | * MPLS BOS instruction. |
| 93 | */ |
| 94 | MPLS_BOS |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 95 | } |
| 96 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 97 | public abstract L2SubType subtype(); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 98 | |
| 99 | @Override |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 100 | public final Type type() { |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 101 | return Type.L2MODIFICATION; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Represents a L2 src/dst modification instruction. |
| 106 | */ |
| 107 | public static final class ModEtherInstruction extends L2ModificationInstruction { |
| 108 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 109 | private final L2SubType subtype; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 110 | private final MacAddress mac; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 111 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 112 | ModEtherInstruction(L2SubType subType, MacAddress addr) { |
alshabib | 64231f6 | 2014-09-16 17:58:36 -0700 | [diff] [blame] | 113 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 114 | this.subtype = subType; |
| 115 | this.mac = addr; |
| 116 | } |
| 117 | |
| 118 | @Override |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 119 | public L2SubType subtype() { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 120 | return this.subtype; |
| 121 | } |
| 122 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 123 | public MacAddress mac() { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 124 | return this.mac; |
| 125 | } |
| 126 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 127 | @Override |
| 128 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 129 | return subtype().toString() + SEPARATOR + mac; |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 130 | } |
| 131 | |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 132 | @Override |
| 133 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 134 | return Objects.hash(type(), subtype, mac); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public boolean equals(Object obj) { |
| 139 | if (this == obj) { |
| 140 | return true; |
| 141 | } |
| 142 | if (obj instanceof ModEtherInstruction) { |
| 143 | ModEtherInstruction that = (ModEtherInstruction) obj; |
| 144 | return Objects.equals(mac, that.mac) && |
| 145 | Objects.equals(subtype, that.subtype); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 146 | } |
| 147 | return false; |
| 148 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Jian Li | ddfd2eb | 2016-05-19 11:32:18 -0700 | [diff] [blame] | 151 | /** |
Jian Li | ddfd2eb | 2016-05-19 11:32:18 -0700 | [diff] [blame] | 152 | * Represents a MPLS header modification instruction. |
| 153 | */ |
| 154 | public static final class ModMplsHeaderInstruction extends L2ModificationInstruction { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 155 | |
Jian Li | ddfd2eb | 2016-05-19 11:32:18 -0700 | [diff] [blame] | 156 | private final L2SubType subtype; |
| 157 | private final EthType ethernetType; // Ethernet type value: 16 bits |
| 158 | |
| 159 | ModMplsHeaderInstruction(L2SubType subType, EthType ethernetType) { |
| 160 | this.subtype = subType; |
| 161 | this.ethernetType = ethernetType; |
| 162 | } |
| 163 | |
| 164 | public EthType ethernetType() { |
| 165 | return ethernetType; |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public L2SubType subtype() { |
| 170 | return subtype; |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public String toString() { |
| 175 | return subtype().toString() + SEPARATOR + ethernetType; |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public int hashCode() { |
| 180 | return Objects.hash(type(), subtype, ethernetType); |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public boolean equals(Object obj) { |
| 185 | if (this == obj) { |
| 186 | return true; |
| 187 | } |
| 188 | if (obj instanceof ModMplsHeaderInstruction) { |
| 189 | ModMplsHeaderInstruction that = (ModMplsHeaderInstruction) obj; |
| 190 | return Objects.equals(subtype, that.subtype) && |
| 191 | Objects.equals(this.ethernetType, that.ethernetType); |
| 192 | } |
| 193 | return false; |
| 194 | } |
| 195 | } |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 196 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 197 | /** |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 198 | * Represents a VLAN id modification instruction. |
| 199 | */ |
| 200 | public static final class ModVlanIdInstruction extends L2ModificationInstruction { |
| 201 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 202 | private final VlanId vlanId; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 203 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 204 | ModVlanIdInstruction(VlanId vlanId) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 205 | this.vlanId = vlanId; |
| 206 | } |
| 207 | |
| 208 | @Override |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 209 | public L2SubType subtype() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 210 | return L2SubType.VLAN_ID; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 213 | public VlanId vlanId() { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 214 | return this.vlanId; |
| 215 | } |
| 216 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 217 | @Override |
| 218 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 219 | return subtype().toString() + SEPARATOR + vlanId; |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 220 | } |
| 221 | |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 222 | @Override |
| 223 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 224 | return Objects.hash(type(), subtype(), vlanId); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public boolean equals(Object obj) { |
| 229 | if (this == obj) { |
| 230 | return true; |
| 231 | } |
| 232 | if (obj instanceof ModVlanIdInstruction) { |
| 233 | ModVlanIdInstruction that = (ModVlanIdInstruction) obj; |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 234 | return Objects.equals(vlanId, that.vlanId); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 235 | } |
| 236 | return false; |
| 237 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 238 | } |
| 239 | |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 240 | /** |
| 241 | * Represents a VLAN PCP modification instruction. |
| 242 | */ |
| 243 | public static final class ModVlanPcpInstruction extends L2ModificationInstruction { |
| 244 | |
alshabib | 0ad4398 | 2015-05-07 13:43:13 -0700 | [diff] [blame] | 245 | private static final byte MASK = 0x7; |
| 246 | private final byte vlanPcp; |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 247 | |
alshabib | 0ad4398 | 2015-05-07 13:43:13 -0700 | [diff] [blame] | 248 | ModVlanPcpInstruction(byte vlanPcp) { |
| 249 | this.vlanPcp = (byte) (vlanPcp & MASK); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | @Override |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 253 | public L2SubType subtype() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 254 | return L2SubType.VLAN_PCP; |
| 255 | } |
| 256 | |
alshabib | 0ad4398 | 2015-05-07 13:43:13 -0700 | [diff] [blame] | 257 | public byte vlanPcp() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 258 | return this.vlanPcp; |
| 259 | } |
| 260 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 261 | @Override |
| 262 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 263 | return subtype().toString() + SEPARATOR + Long.toHexString(vlanPcp); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 264 | } |
| 265 | |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 266 | @Override |
| 267 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 268 | return Objects.hash(type(), subtype(), vlanPcp); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | @Override |
| 272 | public boolean equals(Object obj) { |
| 273 | if (this == obj) { |
| 274 | return true; |
| 275 | } |
| 276 | if (obj instanceof ModVlanPcpInstruction) { |
| 277 | ModVlanPcpInstruction that = (ModVlanPcpInstruction) obj; |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 278 | return Objects.equals(vlanPcp, that.vlanPcp); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 279 | } |
| 280 | return false; |
| 281 | } |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 284 | /** |
Jian Li | ddfd2eb | 2016-05-19 11:32:18 -0700 | [diff] [blame] | 285 | * Represents a VLAN Header modification instruction. |
| 286 | */ |
| 287 | public static final class ModVlanHeaderInstruction extends L2ModificationInstruction { |
| 288 | |
| 289 | private final L2SubType subtype; |
| 290 | private EthType ethernetType; // Ethernet type value: 16 bits |
| 291 | |
| 292 | ModVlanHeaderInstruction(L2SubType subType, EthType ethernetType) { |
| 293 | this.subtype = subType; |
| 294 | this.ethernetType = ethernetType; |
| 295 | } |
| 296 | |
| 297 | ModVlanHeaderInstruction(L2SubType subType) { |
| 298 | this(subType, EthType.EtherType.UNKNOWN.ethType()); |
| 299 | } |
| 300 | |
| 301 | public EthType ethernetType() { |
| 302 | return ethernetType; |
| 303 | } |
| 304 | |
| 305 | @Override |
| 306 | public L2SubType subtype() { |
| 307 | return subtype; |
| 308 | } |
| 309 | |
| 310 | @Override |
| 311 | public String toString() { |
Charles Chan | cefcf77 | 2017-01-22 13:53:13 -0800 | [diff] [blame] | 312 | // etherType is not specified in VLAN_POP case. Ignore it. |
| 313 | return subtype().equals(L2SubType.VLAN_POP) ? |
| 314 | subtype().toString() : |
| 315 | subtype().toString() + SEPARATOR + ethernetType; |
Jian Li | ddfd2eb | 2016-05-19 11:32:18 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | @Override |
| 319 | public int hashCode() { |
| 320 | return Objects.hash(type(), subtype, ethernetType); |
| 321 | } |
| 322 | |
| 323 | @Override |
| 324 | public boolean equals(Object obj) { |
| 325 | if (this == obj) { |
| 326 | return true; |
| 327 | } |
| 328 | if (obj instanceof ModVlanHeaderInstruction) { |
| 329 | ModVlanHeaderInstruction that = (ModVlanHeaderInstruction) obj; |
| 330 | return Objects.equals(subtype, that.subtype) && |
| 331 | Objects.equals(this.ethernetType, that.ethernetType); |
| 332 | } |
| 333 | return false; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 338 | * Represents a MPLS label modification. |
| 339 | */ |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 340 | public static final class ModMplsLabelInstruction |
| 341 | extends L2ModificationInstruction { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 342 | |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 343 | private final MplsLabel mplsLabel; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 344 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 345 | ModMplsLabelInstruction(MplsLabel mplsLabel) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 346 | this.mplsLabel = mplsLabel; |
| 347 | } |
| 348 | |
Ray Milkey | 125572b | 2016-02-22 16:48:17 -0800 | [diff] [blame] | 349 | public MplsLabel label() { |
| 350 | return mplsLabel; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | @Override |
| 354 | public L2SubType subtype() { |
| 355 | return L2SubType.MPLS_LABEL; |
| 356 | } |
| 357 | |
| 358 | @Override |
| 359 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 360 | return subtype().toString() + SEPARATOR + mplsLabel; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | @Override |
| 364 | public int hashCode() { |
Yuta HIGUCHI | cca5e72 | 2015-02-05 14:00:41 -0800 | [diff] [blame] | 365 | return Objects.hash(type(), subtype(), mplsLabel); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | @Override |
| 369 | public boolean equals(Object obj) { |
| 370 | if (this == obj) { |
| 371 | return true; |
| 372 | } |
| 373 | if (obj instanceof ModMplsLabelInstruction) { |
| 374 | ModMplsLabelInstruction that = (ModMplsLabelInstruction) obj; |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 375 | return Objects.equals(mplsLabel, that.mplsLabel); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 376 | } |
| 377 | return false; |
| 378 | } |
| 379 | } |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 380 | |
| 381 | /** |
Saurav Das | 73a7dd4 | 2015-08-19 22:20:31 -0700 | [diff] [blame] | 382 | * Represents a MPLS BOS modification. |
| 383 | */ |
| 384 | public static final class ModMplsBosInstruction |
| 385 | extends L2ModificationInstruction { |
| 386 | |
| 387 | private final boolean mplsBos; |
| 388 | |
| 389 | ModMplsBosInstruction(boolean mplsBos) { |
| 390 | this.mplsBos = mplsBos; |
| 391 | } |
| 392 | |
| 393 | public boolean mplsBos() { |
| 394 | return mplsBos; |
| 395 | } |
| 396 | |
| 397 | @Override |
| 398 | public L2SubType subtype() { |
| 399 | return L2SubType.MPLS_BOS; |
| 400 | } |
| 401 | |
| 402 | @Override |
| 403 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 404 | return subtype().toString() + SEPARATOR + mplsBos; |
Saurav Das | 73a7dd4 | 2015-08-19 22:20:31 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | @Override |
| 408 | public int hashCode() { |
| 409 | return Objects.hash(type(), subtype(), mplsBos); |
| 410 | } |
| 411 | |
| 412 | @Override |
| 413 | public boolean equals(Object obj) { |
| 414 | if (this == obj) { |
| 415 | return true; |
| 416 | } |
| 417 | if (obj instanceof ModMplsBosInstruction) { |
| 418 | ModMplsBosInstruction that = (ModMplsBosInstruction) obj; |
| 419 | return Objects.equals(mplsBos, that.mplsBos()); |
| 420 | } |
| 421 | return false; |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | /** |
Yuta HIGUCHI | cca5e72 | 2015-02-05 14:00:41 -0800 | [diff] [blame] | 426 | * Represents a MPLS TTL modification. |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 427 | */ |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 428 | public static final class ModMplsTtlInstruction |
| 429 | extends L2ModificationInstruction { |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 430 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 431 | ModMplsTtlInstruction() { |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | @Override |
| 435 | public L2SubType subtype() { |
| 436 | return L2SubType.DEC_MPLS_TTL; |
| 437 | } |
| 438 | |
| 439 | @Override |
| 440 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 441 | return subtype().toString(); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | @Override |
| 445 | public int hashCode() { |
Yuta HIGUCHI | cca5e72 | 2015-02-05 14:00:41 -0800 | [diff] [blame] | 446 | return Objects.hash(type(), subtype()); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | @Override |
| 450 | public boolean equals(Object obj) { |
| 451 | if (this == obj) { |
| 452 | return true; |
| 453 | } |
Yuta HIGUCHI | cca5e72 | 2015-02-05 14:00:41 -0800 | [diff] [blame] | 454 | if (obj instanceof ModMplsTtlInstruction) { |
| 455 | return true; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 456 | } |
| 457 | return false; |
| 458 | } |
| 459 | } |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 460 | |
| 461 | /** |
| 462 | * Represents a Tunnel id modification. |
| 463 | */ |
| 464 | public static final class ModTunnelIdInstruction |
| 465 | extends L2ModificationInstruction { |
| 466 | |
| 467 | private final long tunnelId; |
| 468 | |
| 469 | ModTunnelIdInstruction(long tunnelId) { |
| 470 | this.tunnelId = tunnelId; |
| 471 | } |
| 472 | |
| 473 | public long tunnelId() { |
| 474 | return this.tunnelId; |
| 475 | } |
| 476 | |
| 477 | @Override |
| 478 | public L2SubType subtype() { |
| 479 | return L2SubType.TUNNEL_ID; |
| 480 | } |
| 481 | |
| 482 | @Override |
| 483 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 484 | return subtype().toString() + SEPARATOR + Long.toHexString(tunnelId); |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | @Override |
| 488 | public int hashCode() { |
| 489 | return Objects.hash(type(), subtype(), tunnelId); |
| 490 | } |
| 491 | |
| 492 | @Override |
| 493 | public boolean equals(Object obj) { |
| 494 | if (this == obj) { |
| 495 | return true; |
| 496 | } |
| 497 | if (obj instanceof ModTunnelIdInstruction) { |
| 498 | ModTunnelIdInstruction that = (ModTunnelIdInstruction) obj; |
| 499 | return Objects.equals(tunnelId, that.tunnelId); |
| 500 | } |
| 501 | return false; |
| 502 | } |
| 503 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 504 | } |