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 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 18 | import org.onlab.packet.MacAddress; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 19 | import org.onlab.packet.MplsLabel; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 20 | import org.onlab.packet.VlanId; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 21 | |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 22 | import java.util.Objects; |
| 23 | |
| 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Abstraction of a single traffic treatment step. |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 28 | */ |
| 29 | public abstract class L2ModificationInstruction implements Instruction { |
| 30 | |
| 31 | /** |
| 32 | * Represents the type of traffic treatment. |
| 33 | */ |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 34 | public enum L2SubType { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Ether src modification. |
| 37 | */ |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 38 | ETH_SRC, |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Ether dst modification. |
| 42 | */ |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 43 | ETH_DST, |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 46 | * VLAN id modification. |
| 47 | */ |
| 48 | VLAN_ID, |
| 49 | |
| 50 | /** |
| 51 | * VLAN priority modification. |
| 52 | */ |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 53 | VLAN_PCP, |
| 54 | |
| 55 | /** |
alshabib | ab21b2d | 2015-03-04 18:35:33 -0800 | [diff] [blame] | 56 | * Strips the vlan. |
| 57 | */ |
| 58 | STRIP_VLAN, |
| 59 | |
| 60 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 61 | * MPLS Label modification. |
| 62 | */ |
| 63 | MPLS_LABEL, |
| 64 | |
| 65 | /** |
| 66 | * MPLS Push modification. |
| 67 | */ |
| 68 | MPLS_PUSH, |
| 69 | |
| 70 | /** |
| 71 | * MPLS Pop modification. |
| 72 | */ |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 73 | MPLS_POP, |
| 74 | |
| 75 | /** |
| 76 | * MPLS TTL modification. |
| 77 | */ |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 78 | DEC_MPLS_TTL, |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 79 | |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 80 | /** |
| 81 | * VLAN Pop modification. |
| 82 | */ |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 83 | VLAN_POP, |
| 84 | |
| 85 | /** |
| 86 | * VLAN Push modification. |
| 87 | */ |
| 88 | VLAN_PUSH |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | // TODO: Create factory class 'Instructions' that will have various factory |
| 92 | // to create specific instructions. |
| 93 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 94 | public abstract L2SubType subtype(); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 95 | |
| 96 | @Override |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 97 | public final Type type() { |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 98 | return Type.L2MODIFICATION; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Represents a L2 src/dst modification instruction. |
| 103 | */ |
| 104 | public static final class ModEtherInstruction extends L2ModificationInstruction { |
| 105 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 106 | private final L2SubType subtype; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 107 | private final MacAddress mac; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 108 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 109 | ModEtherInstruction(L2SubType subType, MacAddress addr) { |
alshabib | 64231f6 | 2014-09-16 17:58:36 -0700 | [diff] [blame] | 110 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 111 | this.subtype = subType; |
| 112 | this.mac = addr; |
| 113 | } |
| 114 | |
| 115 | @Override |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 116 | public L2SubType subtype() { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 117 | return this.subtype; |
| 118 | } |
| 119 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 120 | public MacAddress mac() { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 121 | return this.mac; |
| 122 | } |
| 123 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 124 | @Override |
| 125 | public String toString() { |
| 126 | return toStringHelper(subtype().toString()) |
| 127 | .add("mac", mac).toString(); |
| 128 | } |
| 129 | |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 130 | @Override |
| 131 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 132 | return Objects.hash(type(), subtype, mac); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public boolean equals(Object obj) { |
| 137 | if (this == obj) { |
| 138 | return true; |
| 139 | } |
| 140 | if (obj instanceof ModEtherInstruction) { |
| 141 | ModEtherInstruction that = (ModEtherInstruction) obj; |
| 142 | return Objects.equals(mac, that.mac) && |
| 143 | Objects.equals(subtype, that.subtype); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 144 | } |
| 145 | return false; |
| 146 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 149 | // TODO This instruction is reused for Pop-Mpls. Consider renaming. |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 150 | public static final class PushHeaderInstructions extends |
| 151 | L2ModificationInstruction { |
| 152 | |
| 153 | private final L2SubType subtype; |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 154 | private final short ethernetType; // uint16_t |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 155 | |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 156 | PushHeaderInstructions(L2SubType subType, short ethernetType) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 157 | this.subtype = subType; |
| 158 | this.ethernetType = ethernetType; |
| 159 | } |
| 160 | |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 161 | public int ethernetType() { |
| 162 | return Short.toUnsignedInt(ethernetType); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public L2SubType subtype() { |
| 167 | return this.subtype; |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public String toString() { |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 172 | return toStringHelper(subtype().toString()) |
| 173 | .add("ethernetType", String.format("0x%04x", ethernetType())) |
| 174 | .toString(); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | @Override |
| 178 | public int hashCode() { |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 179 | return Objects.hash(type(), subtype, ethernetType); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public boolean equals(Object obj) { |
| 184 | if (this == obj) { |
| 185 | return true; |
| 186 | } |
| 187 | if (obj instanceof PushHeaderInstructions) { |
| 188 | PushHeaderInstructions that = (PushHeaderInstructions) obj; |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 189 | return Objects.equals(subtype, that.subtype) && |
| 190 | Objects.equals(this.ethernetType, that.ethernetType); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 191 | } |
| 192 | return false; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | |
| 197 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 198 | /** |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 199 | * Represents a VLAN id modification instruction. |
| 200 | */ |
| 201 | public static final class ModVlanIdInstruction extends L2ModificationInstruction { |
| 202 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 203 | private final VlanId vlanId; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 204 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 205 | ModVlanIdInstruction(VlanId vlanId) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 206 | this.vlanId = vlanId; |
| 207 | } |
| 208 | |
| 209 | @Override |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 210 | public L2SubType subtype() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 211 | return L2SubType.VLAN_ID; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 214 | public VlanId vlanId() { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 215 | return this.vlanId; |
| 216 | } |
| 217 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 218 | @Override |
| 219 | public String toString() { |
| 220 | return toStringHelper(subtype().toString()) |
| 221 | .add("id", vlanId).toString(); |
| 222 | } |
| 223 | |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 224 | @Override |
| 225 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 226 | return Objects.hash(type(), subtype(), vlanId); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | @Override |
| 230 | public boolean equals(Object obj) { |
| 231 | if (this == obj) { |
| 232 | return true; |
| 233 | } |
| 234 | if (obj instanceof ModVlanIdInstruction) { |
| 235 | ModVlanIdInstruction that = (ModVlanIdInstruction) obj; |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 236 | return Objects.equals(vlanId, that.vlanId); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 237 | } |
| 238 | return false; |
| 239 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 240 | } |
| 241 | |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 242 | /** |
| 243 | * Represents a VLAN PCP modification instruction. |
| 244 | */ |
| 245 | public static final class ModVlanPcpInstruction extends L2ModificationInstruction { |
| 246 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 247 | private final Byte vlanPcp; |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 248 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 249 | ModVlanPcpInstruction(Byte vlanPcp) { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 250 | this.vlanPcp = vlanPcp; |
| 251 | } |
| 252 | |
| 253 | @Override |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 254 | public L2SubType subtype() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 255 | return L2SubType.VLAN_PCP; |
| 256 | } |
| 257 | |
| 258 | public Byte vlanPcp() { |
| 259 | return this.vlanPcp; |
| 260 | } |
| 261 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 262 | @Override |
| 263 | public String toString() { |
| 264 | return toStringHelper(subtype().toString()) |
| 265 | .add("pcp", Long.toHexString(vlanPcp)).toString(); |
| 266 | } |
| 267 | |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 268 | @Override |
| 269 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 270 | return Objects.hash(type(), subtype(), vlanPcp); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public boolean equals(Object obj) { |
| 275 | if (this == obj) { |
| 276 | return true; |
| 277 | } |
| 278 | if (obj instanceof ModVlanPcpInstruction) { |
| 279 | ModVlanPcpInstruction that = (ModVlanPcpInstruction) obj; |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 280 | return Objects.equals(vlanPcp, that.vlanPcp); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 281 | } |
| 282 | return false; |
| 283 | } |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 284 | } |
| 285 | |
alshabib | ab21b2d | 2015-03-04 18:35:33 -0800 | [diff] [blame] | 286 | public static final class StripVlanInstruction extends L2ModificationInstruction { |
| 287 | |
| 288 | @Override |
| 289 | public L2SubType subtype() { |
| 290 | return L2SubType.STRIP_VLAN; |
| 291 | } |
| 292 | |
| 293 | @Override |
| 294 | public String toString() { |
| 295 | return subtype().toString(); |
| 296 | } |
| 297 | |
| 298 | @Override |
| 299 | public int hashCode() { |
| 300 | return Objects.hash(type(), subtype()); |
| 301 | } |
| 302 | |
| 303 | @Override |
| 304 | public boolean equals(Object obj) { |
| 305 | if (this == obj) { |
| 306 | return true; |
| 307 | } |
| 308 | |
| 309 | return false; |
| 310 | } |
| 311 | } |
| 312 | |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 313 | /** |
| 314 | * Represents a VLAN POP modification instruction. |
| 315 | */ |
| 316 | public static final class PopVlanInstruction extends L2ModificationInstruction { |
| 317 | private final L2SubType subtype; |
| 318 | |
| 319 | PopVlanInstruction(L2SubType subType) { |
| 320 | this.subtype = subType; |
| 321 | } |
| 322 | |
| 323 | @Override |
| 324 | public L2SubType subtype() { |
| 325 | return subtype; |
| 326 | } |
| 327 | |
| 328 | @Override |
| 329 | public String toString() { |
| 330 | return toStringHelper(subtype().toString()) |
| 331 | .toString(); |
| 332 | } |
| 333 | |
| 334 | @Override |
| 335 | public int hashCode() { |
| 336 | return Objects.hash(type(), subtype); |
| 337 | } |
| 338 | |
| 339 | @Override |
| 340 | public boolean equals(Object obj) { |
| 341 | if (this == obj) { |
| 342 | return true; |
| 343 | } |
| 344 | if (obj instanceof PushHeaderInstructions) { |
| 345 | PushHeaderInstructions that = (PushHeaderInstructions) obj; |
| 346 | return Objects.equals(subtype, that.subtype); |
| 347 | } |
| 348 | return false; |
| 349 | } |
| 350 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 351 | |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 352 | /** |
| 353 | * Represents a MPLS label modification. |
| 354 | */ |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 355 | public static final class ModMplsLabelInstruction |
| 356 | extends L2ModificationInstruction { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 357 | |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 358 | private final MplsLabel mplsLabel; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 359 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 360 | ModMplsLabelInstruction(MplsLabel mplsLabel) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 361 | this.mplsLabel = mplsLabel; |
| 362 | } |
| 363 | |
| 364 | public Integer label() { |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 365 | return mplsLabel.toInt(); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | @Override |
| 369 | public L2SubType subtype() { |
| 370 | return L2SubType.MPLS_LABEL; |
| 371 | } |
| 372 | |
| 373 | @Override |
| 374 | public String toString() { |
Pavlin Radoslavov | 3ebe170 | 2015-02-17 09:53:17 -0800 | [diff] [blame] | 375 | return toStringHelper(subtype().toString()) |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 376 | .add("mpls", mplsLabel).toString(); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public int hashCode() { |
Yuta HIGUCHI | cca5e72 | 2015-02-05 14:00:41 -0800 | [diff] [blame] | 381 | return Objects.hash(type(), subtype(), mplsLabel); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | @Override |
| 385 | public boolean equals(Object obj) { |
| 386 | if (this == obj) { |
| 387 | return true; |
| 388 | } |
| 389 | if (obj instanceof ModMplsLabelInstruction) { |
| 390 | ModMplsLabelInstruction that = (ModMplsLabelInstruction) obj; |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 391 | return Objects.equals(mplsLabel, that.mplsLabel); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 392 | } |
| 393 | return false; |
| 394 | } |
| 395 | } |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 396 | |
| 397 | /** |
Yuta HIGUCHI | cca5e72 | 2015-02-05 14:00:41 -0800 | [diff] [blame] | 398 | * Represents a MPLS TTL modification. |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 399 | */ |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 400 | public static final class ModMplsTtlInstruction |
| 401 | extends L2ModificationInstruction { |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 402 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 403 | ModMplsTtlInstruction() { |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | @Override |
| 407 | public L2SubType subtype() { |
| 408 | return L2SubType.DEC_MPLS_TTL; |
| 409 | } |
| 410 | |
| 411 | @Override |
| 412 | public String toString() { |
Yuta HIGUCHI | cca5e72 | 2015-02-05 14:00:41 -0800 | [diff] [blame] | 413 | return toStringHelper(subtype().toString()) |
| 414 | .toString(); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | @Override |
| 418 | public int hashCode() { |
Yuta HIGUCHI | cca5e72 | 2015-02-05 14:00:41 -0800 | [diff] [blame] | 419 | return Objects.hash(type(), subtype()); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | @Override |
| 423 | public boolean equals(Object obj) { |
| 424 | if (this == obj) { |
| 425 | return true; |
| 426 | } |
Yuta HIGUCHI | cca5e72 | 2015-02-05 14:00:41 -0800 | [diff] [blame] | 427 | if (obj instanceof ModMplsTtlInstruction) { |
| 428 | return true; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 429 | } |
| 430 | return false; |
| 431 | } |
| 432 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 433 | } |