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