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