Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present 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 | |
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 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 151 | // TODO This instruction is reused for Pop-Mpls. Consider renaming. |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 152 | public static final class PushHeaderInstructions extends |
| 153 | L2ModificationInstruction { |
| 154 | |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 155 | |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 156 | private final L2SubType subtype; |
| 157 | private final EthType ethernetType; // Ethernet type value: 16 bits |
| 158 | |
| 159 | PushHeaderInstructions(L2SubType subType, EthType ethernetType) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 160 | this.subtype = subType; |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 161 | this.ethernetType = ethernetType; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 162 | } |
| 163 | |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 164 | public EthType ethernetType() { |
alshabib | 0ad4398 | 2015-05-07 13:43:13 -0700 | [diff] [blame] | 165 | return ethernetType; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public L2SubType subtype() { |
| 170 | return this.subtype; |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 175 | return subtype().toString() + SEPARATOR + ethernetType; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public int hashCode() { |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 180 | return Objects.hash(type(), subtype, ethernetType); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public boolean equals(Object obj) { |
| 185 | if (this == obj) { |
| 186 | return true; |
| 187 | } |
| 188 | if (obj instanceof PushHeaderInstructions) { |
| 189 | PushHeaderInstructions that = (PushHeaderInstructions) obj; |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 190 | return Objects.equals(subtype, that.subtype) && |
| 191 | Objects.equals(this.ethernetType, that.ethernetType); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 192 | } |
| 193 | return false; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | |
| 198 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 199 | /** |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 200 | * Represents a VLAN id modification instruction. |
| 201 | */ |
| 202 | public static final class ModVlanIdInstruction extends L2ModificationInstruction { |
| 203 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 204 | private final VlanId vlanId; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 205 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 206 | ModVlanIdInstruction(VlanId vlanId) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 207 | this.vlanId = vlanId; |
| 208 | } |
| 209 | |
| 210 | @Override |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 211 | public L2SubType subtype() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 212 | return L2SubType.VLAN_ID; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 215 | public VlanId vlanId() { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 216 | return this.vlanId; |
| 217 | } |
| 218 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 219 | @Override |
| 220 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 221 | return subtype().toString() + SEPARATOR + vlanId; |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 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 | |
alshabib | 0ad4398 | 2015-05-07 13:43:13 -0700 | [diff] [blame] | 247 | private static final byte MASK = 0x7; |
| 248 | private final byte vlanPcp; |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 249 | |
alshabib | 0ad4398 | 2015-05-07 13:43:13 -0700 | [diff] [blame] | 250 | ModVlanPcpInstruction(byte vlanPcp) { |
| 251 | this.vlanPcp = (byte) (vlanPcp & MASK); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | @Override |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 255 | public L2SubType subtype() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 256 | return L2SubType.VLAN_PCP; |
| 257 | } |
| 258 | |
alshabib | 0ad4398 | 2015-05-07 13:43:13 -0700 | [diff] [blame] | 259 | public byte vlanPcp() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 260 | return this.vlanPcp; |
| 261 | } |
| 262 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 263 | @Override |
| 264 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 265 | return subtype().toString() + SEPARATOR + Long.toHexString(vlanPcp); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 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 | |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 286 | /** |
| 287 | * Represents a VLAN POP modification instruction. |
| 288 | */ |
| 289 | public static final class PopVlanInstruction extends L2ModificationInstruction { |
| 290 | private final L2SubType subtype; |
| 291 | |
| 292 | PopVlanInstruction(L2SubType subType) { |
| 293 | this.subtype = subType; |
| 294 | } |
| 295 | |
| 296 | @Override |
| 297 | public L2SubType subtype() { |
| 298 | return subtype; |
| 299 | } |
| 300 | |
| 301 | @Override |
| 302 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 303 | return subtype().toString(); |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | @Override |
| 307 | public int hashCode() { |
| 308 | return Objects.hash(type(), subtype); |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public boolean equals(Object obj) { |
| 313 | if (this == obj) { |
| 314 | return true; |
| 315 | } |
HIGUCHI Yuta | 7bb8b3f | 2015-03-13 23:21:37 -0700 | [diff] [blame] | 316 | if (obj instanceof PopVlanInstruction) { |
| 317 | PopVlanInstruction that = (PopVlanInstruction) obj; |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 318 | return Objects.equals(subtype, that.subtype); |
| 319 | } |
| 320 | return false; |
| 321 | } |
| 322 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 323 | |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 324 | /** |
| 325 | * Represents a MPLS label modification. |
| 326 | */ |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 327 | public static final class ModMplsLabelInstruction |
| 328 | extends L2ModificationInstruction { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 329 | |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 330 | private final MplsLabel mplsLabel; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 331 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 332 | ModMplsLabelInstruction(MplsLabel mplsLabel) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 333 | this.mplsLabel = mplsLabel; |
| 334 | } |
| 335 | |
Ray Milkey | 125572b | 2016-02-22 16:48:17 -0800 | [diff] [blame] | 336 | public MplsLabel label() { |
| 337 | return mplsLabel; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Ray Milkey | 125572b | 2016-02-22 16:48:17 -0800 | [diff] [blame] | 340 | /** |
| 341 | * Extracts the MPLS label from the instruction. |
| 342 | * |
| 343 | * @return MPLS label |
| 344 | * @deprecated deprecated in 1.5.0 Falcon |
| 345 | */ |
| 346 | @Deprecated |
HIGUCHI Yuta | 60db977 | 2015-08-26 17:49:34 -0700 | [diff] [blame] | 347 | public MplsLabel mplsLabel() { |
Ray Milkey | 125572b | 2016-02-22 16:48:17 -0800 | [diff] [blame] | 348 | return label(); |
HIGUCHI Yuta | 60db977 | 2015-08-26 17:49:34 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 351 | @Override |
| 352 | public L2SubType subtype() { |
| 353 | return L2SubType.MPLS_LABEL; |
| 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 358 | return subtype().toString() + SEPARATOR + mplsLabel; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public int hashCode() { |
Yuta HIGUCHI | cca5e72 | 2015-02-05 14:00:41 -0800 | [diff] [blame] | 363 | return Objects.hash(type(), subtype(), mplsLabel); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | @Override |
| 367 | public boolean equals(Object obj) { |
| 368 | if (this == obj) { |
| 369 | return true; |
| 370 | } |
| 371 | if (obj instanceof ModMplsLabelInstruction) { |
| 372 | ModMplsLabelInstruction that = (ModMplsLabelInstruction) obj; |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 373 | return Objects.equals(mplsLabel, that.mplsLabel); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 374 | } |
| 375 | return false; |
| 376 | } |
| 377 | } |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 378 | |
| 379 | /** |
Saurav Das | 73a7dd4 | 2015-08-19 22:20:31 -0700 | [diff] [blame] | 380 | * Represents a MPLS BOS modification. |
| 381 | */ |
| 382 | public static final class ModMplsBosInstruction |
| 383 | extends L2ModificationInstruction { |
| 384 | |
| 385 | private final boolean mplsBos; |
| 386 | |
| 387 | ModMplsBosInstruction(boolean mplsBos) { |
| 388 | this.mplsBos = mplsBos; |
| 389 | } |
| 390 | |
| 391 | public boolean mplsBos() { |
| 392 | return mplsBos; |
| 393 | } |
| 394 | |
| 395 | @Override |
| 396 | public L2SubType subtype() { |
| 397 | return L2SubType.MPLS_BOS; |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 402 | return subtype().toString() + SEPARATOR + mplsBos; |
Saurav Das | 73a7dd4 | 2015-08-19 22:20:31 -0700 | [diff] [blame] | 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() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 439 | return subtype().toString(); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | @Override |
| 443 | public int hashCode() { |
Yuta HIGUCHI | cca5e72 | 2015-02-05 14:00:41 -0800 | [diff] [blame] | 444 | return Objects.hash(type(), subtype()); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | @Override |
| 448 | public boolean equals(Object obj) { |
| 449 | if (this == obj) { |
| 450 | return true; |
| 451 | } |
Yuta HIGUCHI | cca5e72 | 2015-02-05 14:00:41 -0800 | [diff] [blame] | 452 | if (obj instanceof ModMplsTtlInstruction) { |
| 453 | return true; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 454 | } |
| 455 | return false; |
| 456 | } |
| 457 | } |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 458 | |
| 459 | /** |
| 460 | * Represents a Tunnel id modification. |
| 461 | */ |
| 462 | public static final class ModTunnelIdInstruction |
| 463 | extends L2ModificationInstruction { |
| 464 | |
| 465 | private final long tunnelId; |
| 466 | |
| 467 | ModTunnelIdInstruction(long tunnelId) { |
| 468 | this.tunnelId = tunnelId; |
| 469 | } |
| 470 | |
| 471 | public long tunnelId() { |
| 472 | return this.tunnelId; |
| 473 | } |
| 474 | |
| 475 | @Override |
| 476 | public L2SubType subtype() { |
| 477 | return L2SubType.TUNNEL_ID; |
| 478 | } |
| 479 | |
| 480 | @Override |
| 481 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 482 | return subtype().toString() + SEPARATOR + Long.toHexString(tunnelId); |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | @Override |
| 486 | public int hashCode() { |
| 487 | return Objects.hash(type(), subtype(), tunnelId); |
| 488 | } |
| 489 | |
| 490 | @Override |
| 491 | public boolean equals(Object obj) { |
| 492 | if (this == obj) { |
| 493 | return true; |
| 494 | } |
| 495 | if (obj instanceof ModTunnelIdInstruction) { |
| 496 | ModTunnelIdInstruction that = (ModTunnelIdInstruction) obj; |
| 497 | return Objects.equals(tunnelId, that.tunnelId); |
| 498 | } |
| 499 | return false; |
| 500 | } |
| 501 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 502 | } |