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 | */ |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.flow.criteria; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 17 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 20 | import java.util.Objects; |
| 21 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 22 | import org.onlab.onos.net.PortNumber; |
| 23 | import org.onlab.onos.net.flow.criteria.Criterion.Type; |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 24 | import org.onlab.packet.IpPrefix; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 25 | import org.onlab.packet.MacAddress; |
| 26 | import org.onlab.packet.VlanId; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 27 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Factory class to create various traffic selection criteria. |
| 30 | */ |
| 31 | public final class Criteria { |
| 32 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 33 | //TODO: incomplete type implementation. Need to implement complete list from Criterion |
| 34 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 35 | // Ban construction |
| 36 | private Criteria() { |
| 37 | } |
| 38 | |
| 39 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 40 | * Creates a match on IN_PORT field using the specified value. |
| 41 | * |
| 42 | * @param port inport value |
| 43 | * @return match criterion |
| 44 | */ |
| 45 | public static Criterion matchInPort(PortNumber port) { |
| 46 | return new PortCriterion(port); |
| 47 | } |
| 48 | |
| 49 | /** |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 50 | * Creates a match on ETH_SRC field using the specified value. This value |
| 51 | * may be a wildcard mask. |
| 52 | * |
tom | c104d28 | 2014-09-19 10:57:55 -0700 | [diff] [blame] | 53 | * @param mac MAC address value or wildcard mask |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 54 | * @return match criterion |
| 55 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 56 | public static Criterion matchEthSrc(MacAddress mac) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 57 | return new EthCriterion(mac, Type.ETH_SRC); |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 58 | } |
| 59 | |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 60 | /** |
| 61 | * Creates a match on ETH_DST field using the specified value. This value |
| 62 | * may be a wildcard mask. |
| 63 | * |
tom | c104d28 | 2014-09-19 10:57:55 -0700 | [diff] [blame] | 64 | * @param mac MAC address value or wildcard mask |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 65 | * @return match criterion |
| 66 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 67 | public static Criterion matchEthDst(MacAddress mac) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 68 | return new EthCriterion(mac, Type.ETH_DST); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Creates a match on ETH_TYPE field using the specified value. |
| 73 | * |
| 74 | * @param ethType eth type value |
| 75 | * @return match criterion |
| 76 | */ |
| 77 | public static Criterion matchEthType(Short ethType) { |
| 78 | return new EthTypeCriterion(ethType); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Creates a match on VLAN ID field using the specified value. |
| 83 | * |
| 84 | * @param vlanId vlan id value |
| 85 | * @return match criterion |
| 86 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 87 | public static Criterion matchVlanId(VlanId vlanId) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 88 | return new VlanIdCriterion(vlanId); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Creates a match on VLAN PCP field using the specified value. |
| 93 | * |
| 94 | * @param vlanPcp vlan pcp value |
| 95 | * @return match criterion |
| 96 | */ |
alshabib | b45d196 | 2014-09-18 14:25:45 -0700 | [diff] [blame] | 97 | public static Criterion matchVlanPcp(Byte vlanPcp) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 98 | return new VlanPcpCriterion(vlanPcp); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Creates a match on IP proto field using the specified value. |
| 103 | * |
| 104 | * @param proto ip protocol value |
| 105 | * @return match criterion |
| 106 | */ |
| 107 | public static Criterion matchIPProtocol(Byte proto) { |
| 108 | return new IPProtocolCriterion(proto); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Creates a match on IP src field using the specified value. |
| 113 | * |
| 114 | * @param ip ip src value |
| 115 | * @return match criterion |
| 116 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 117 | public static Criterion matchIPSrc(IpPrefix ip) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 118 | return new IPCriterion(ip, Type.IPV4_SRC); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Creates a match on IP dst field using the specified value. |
| 123 | * |
| 124 | * @param ip ip src value |
| 125 | * @return match criterion |
| 126 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 127 | public static Criterion matchIPDst(IpPrefix ip) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 128 | return new IPCriterion(ip, Type.IPV4_DST); |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 131 | /** |
| 132 | * Creates a match on TCP source port field using the specified value. |
| 133 | * |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 134 | * @param tcpPort TCP source port |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 135 | * @return match criterion |
| 136 | */ |
| 137 | public static Criterion matchTcpSrc(Short tcpPort) { |
| 138 | return new TcpPortCriterion(tcpPort, Type.TCP_SRC); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Creates a match on TCP destination port field using the specified value. |
| 143 | * |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 144 | * @param tcpPort TCP destination port |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 145 | * @return match criterion |
| 146 | */ |
| 147 | public static Criterion matchTcpDst(Short tcpPort) { |
| 148 | return new TcpPortCriterion(tcpPort, Type.TCP_DST); |
| 149 | } |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 150 | |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 151 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame^] | 152 | * Creates a match on MPLS label. |
| 153 | * @param mplsLabel MPLS label |
| 154 | * @return match criterion |
| 155 | */ |
| 156 | |
| 157 | public static Criterion matchMplsLabel(Integer mplsLabel) { |
| 158 | return new MplsCriterion(mplsLabel); |
| 159 | } |
| 160 | |
| 161 | /** |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 162 | * Creates a match on lambda field using the specified value. |
| 163 | * |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 164 | * @param lambda lamda to match on |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 165 | * @return match criterion |
| 166 | */ |
| 167 | public static Criterion matchLambda(Short lambda) { |
| 168 | return new LambdaCriterion(lambda, Type.OCH_SIGID); |
| 169 | } |
| 170 | |
| 171 | /** |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 172 | * Creates a match on lambda field using the specified value. |
| 173 | * |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 174 | * @param sigType signame type |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 175 | * @return match criterion |
| 176 | */ |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 177 | public static Criterion matchOpticalSignalType(Short sigType) { |
| 178 | return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE); |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | |
| 182 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 183 | * Implementations of criteria. |
| 184 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 185 | public static final class PortCriterion implements Criterion { |
| 186 | private final PortNumber port; |
| 187 | |
| 188 | public PortCriterion(PortNumber port) { |
| 189 | this.port = port; |
| 190 | } |
| 191 | |
| 192 | @Override |
| 193 | public Type type() { |
| 194 | return Type.IN_PORT; |
| 195 | } |
| 196 | |
| 197 | public PortNumber port() { |
| 198 | return this.port; |
| 199 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 200 | |
| 201 | @Override |
| 202 | public String toString() { |
| 203 | return toStringHelper(type().toString()) |
| 204 | .add("port", port).toString(); |
| 205 | } |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 206 | |
| 207 | @Override |
| 208 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 209 | return Objects.hash(type(), port); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public boolean equals(Object obj) { |
| 214 | if (this == obj) { |
| 215 | return true; |
| 216 | } |
| 217 | if (obj instanceof PortCriterion) { |
| 218 | PortCriterion that = (PortCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 219 | return Objects.equals(port, that.port) && |
| 220 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 221 | |
| 222 | } |
| 223 | return false; |
| 224 | } |
| 225 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | |
| 229 | public static final class EthCriterion implements Criterion { |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 230 | private final MacAddress mac; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 231 | private final Type type; |
| 232 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 233 | public EthCriterion(MacAddress mac, Type type) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 234 | this.mac = mac; |
| 235 | this.type = type; |
| 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public Type type() { |
| 240 | return this.type; |
| 241 | } |
| 242 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 243 | public MacAddress mac() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 244 | return this.mac; |
| 245 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 246 | |
| 247 | @Override |
| 248 | public String toString() { |
| 249 | return toStringHelper(type().toString()) |
| 250 | .add("mac", mac).toString(); |
| 251 | } |
| 252 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 253 | @Override |
| 254 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 255 | return Objects.hash(type, mac); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public boolean equals(Object obj) { |
| 260 | if (this == obj) { |
| 261 | return true; |
| 262 | } |
| 263 | if (obj instanceof EthCriterion) { |
| 264 | EthCriterion that = (EthCriterion) obj; |
| 265 | return Objects.equals(mac, that.mac) && |
| 266 | Objects.equals(type, that.type); |
| 267 | |
| 268 | |
| 269 | } |
| 270 | return false; |
| 271 | } |
| 272 | |
| 273 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | public static final class EthTypeCriterion implements Criterion { |
| 277 | |
| 278 | private final Short ethType; |
| 279 | |
| 280 | public EthTypeCriterion(Short ethType) { |
| 281 | this.ethType = ethType; |
| 282 | } |
| 283 | |
| 284 | @Override |
| 285 | public Type type() { |
| 286 | return Type.ETH_TYPE; |
| 287 | } |
| 288 | |
| 289 | public Short ethType() { |
| 290 | return ethType; |
| 291 | } |
| 292 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 293 | @Override |
| 294 | public String toString() { |
| 295 | return toStringHelper(type().toString()) |
| 296 | .add("ethType", Long.toHexString(ethType)).toString(); |
| 297 | } |
| 298 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 299 | @Override |
| 300 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 301 | return Objects.hash(type(), ethType); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public boolean equals(Object obj) { |
| 306 | if (this == obj) { |
| 307 | return true; |
| 308 | } |
| 309 | if (obj instanceof EthTypeCriterion) { |
| 310 | EthTypeCriterion that = (EthTypeCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 311 | return Objects.equals(ethType, that.ethType) && |
| 312 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 313 | |
| 314 | |
| 315 | } |
| 316 | return false; |
| 317 | } |
| 318 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | |
| 322 | public static final class IPCriterion implements Criterion { |
| 323 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 324 | private final IpPrefix ip; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 325 | private final Type type; |
| 326 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 327 | public IPCriterion(IpPrefix ip, Type type) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 328 | this.ip = ip; |
| 329 | this.type = type; |
| 330 | } |
| 331 | |
| 332 | @Override |
| 333 | public Type type() { |
| 334 | return this.type; |
| 335 | } |
| 336 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 337 | public IpPrefix ip() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 338 | return this.ip; |
| 339 | } |
| 340 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 341 | @Override |
| 342 | public String toString() { |
| 343 | return toStringHelper(type().toString()) |
| 344 | .add("ip", ip).toString(); |
| 345 | } |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 346 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 347 | @Override |
| 348 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 349 | return Objects.hash(type, ip); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | @Override |
| 353 | public boolean equals(Object obj) { |
| 354 | if (this == obj) { |
| 355 | return true; |
| 356 | } |
| 357 | if (obj instanceof IPCriterion) { |
| 358 | IPCriterion that = (IPCriterion) obj; |
| 359 | return Objects.equals(ip, that.ip) && |
| 360 | Objects.equals(type, that.type); |
| 361 | |
| 362 | |
| 363 | } |
| 364 | return false; |
| 365 | } |
| 366 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | |
| 370 | public static final class IPProtocolCriterion implements Criterion { |
| 371 | |
| 372 | private final Byte proto; |
| 373 | |
| 374 | public IPProtocolCriterion(Byte protocol) { |
| 375 | this.proto = protocol; |
| 376 | } |
| 377 | |
| 378 | @Override |
| 379 | public Type type() { |
| 380 | return Type.IP_PROTO; |
| 381 | } |
| 382 | |
| 383 | public Byte protocol() { |
| 384 | return proto; |
| 385 | } |
| 386 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 387 | @Override |
| 388 | public String toString() { |
| 389 | return toStringHelper(type().toString()) |
| 390 | .add("protocol", Long.toHexString(proto)).toString(); |
| 391 | } |
| 392 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 393 | @Override |
| 394 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 395 | return Objects.hash(type(), proto); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | @Override |
| 399 | public boolean equals(Object obj) { |
| 400 | if (this == obj) { |
| 401 | return true; |
| 402 | } |
| 403 | if (obj instanceof IPProtocolCriterion) { |
| 404 | IPProtocolCriterion that = (IPProtocolCriterion) obj; |
| 405 | return Objects.equals(proto, that.proto); |
| 406 | |
| 407 | |
| 408 | } |
| 409 | return false; |
| 410 | } |
| 411 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | |
| 415 | public static final class VlanPcpCriterion implements Criterion { |
| 416 | |
| 417 | private final Byte vlanPcp; |
| 418 | |
| 419 | public VlanPcpCriterion(Byte vlanPcp) { |
| 420 | this.vlanPcp = vlanPcp; |
| 421 | } |
| 422 | |
| 423 | @Override |
| 424 | public Type type() { |
| 425 | return Type.VLAN_PCP; |
| 426 | } |
| 427 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 428 | public Byte priority() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 429 | return vlanPcp; |
| 430 | } |
| 431 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 432 | @Override |
| 433 | public String toString() { |
| 434 | return toStringHelper(type().toString()) |
| 435 | .add("pcp", Long.toHexString(vlanPcp)).toString(); |
| 436 | } |
| 437 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 438 | @Override |
| 439 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 440 | return Objects.hash(type(), vlanPcp); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public boolean equals(Object obj) { |
| 445 | if (this == obj) { |
| 446 | return true; |
| 447 | } |
| 448 | if (obj instanceof VlanPcpCriterion) { |
| 449 | VlanPcpCriterion that = (VlanPcpCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 450 | return Objects.equals(vlanPcp, that.vlanPcp) && |
| 451 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 452 | |
| 453 | |
| 454 | } |
| 455 | return false; |
| 456 | } |
| 457 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | |
| 461 | public static final class VlanIdCriterion implements Criterion { |
| 462 | |
| 463 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 464 | private final VlanId vlanId; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 465 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 466 | public VlanIdCriterion(VlanId vlanId) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 467 | this.vlanId = vlanId; |
| 468 | } |
| 469 | |
| 470 | @Override |
| 471 | public Type type() { |
| 472 | return Type.VLAN_VID; |
| 473 | } |
| 474 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 475 | public VlanId vlanId() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 476 | return vlanId; |
| 477 | } |
| 478 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 479 | @Override |
| 480 | public String toString() { |
| 481 | return toStringHelper(type().toString()) |
| 482 | .add("id", vlanId).toString(); |
| 483 | } |
| 484 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 485 | @Override |
| 486 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 487 | return Objects.hash(type(), vlanId); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | @Override |
| 491 | public boolean equals(Object obj) { |
| 492 | if (this == obj) { |
| 493 | return true; |
| 494 | } |
| 495 | if (obj instanceof VlanIdCriterion) { |
| 496 | VlanIdCriterion that = (VlanIdCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 497 | return Objects.equals(vlanId, that.vlanId) && |
| 498 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 499 | |
| 500 | |
| 501 | } |
| 502 | return false; |
| 503 | } |
| 504 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 508 | public static final class TcpPortCriterion implements Criterion { |
| 509 | |
| 510 | private final Short tcpPort; |
| 511 | private final Type type; |
| 512 | |
| 513 | public TcpPortCriterion(Short tcpPort, Type type) { |
| 514 | this.tcpPort = tcpPort; |
| 515 | this.type = type; |
| 516 | } |
| 517 | |
| 518 | @Override |
| 519 | public Type type() { |
| 520 | return this.type; |
| 521 | } |
| 522 | |
| 523 | public Short tcpPort() { |
| 524 | return this.tcpPort; |
| 525 | } |
| 526 | |
| 527 | @Override |
| 528 | public String toString() { |
| 529 | return toStringHelper(type().toString()) |
| 530 | .add("tcpPort", tcpPort).toString(); |
| 531 | } |
| 532 | |
| 533 | @Override |
| 534 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 535 | return Objects.hash(type, tcpPort); |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | @Override |
| 539 | public boolean equals(Object obj) { |
| 540 | if (this == obj) { |
| 541 | return true; |
| 542 | } |
| 543 | if (obj instanceof TcpPortCriterion) { |
| 544 | TcpPortCriterion that = (TcpPortCriterion) obj; |
| 545 | return Objects.equals(tcpPort, that.tcpPort) && |
| 546 | Objects.equals(type, that.type); |
| 547 | |
| 548 | |
| 549 | } |
| 550 | return false; |
| 551 | } |
| 552 | } |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 553 | |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame^] | 554 | public static final class MplsCriterion implements Criterion { |
| 555 | |
| 556 | private final Integer mplsLabel; |
| 557 | |
| 558 | public MplsCriterion(Integer mplsLabel) { |
| 559 | this.mplsLabel = mplsLabel; |
| 560 | } |
| 561 | |
| 562 | @Override |
| 563 | public Type type() { |
| 564 | return Type.MPLS_LABEL; |
| 565 | } |
| 566 | |
| 567 | public Integer label() { |
| 568 | return mplsLabel; |
| 569 | } |
| 570 | |
| 571 | @Override |
| 572 | public String toString() { |
| 573 | return toStringHelper(type().toString()) |
| 574 | .add("mpls", mplsLabel.intValue()).toString(); |
| 575 | } |
| 576 | |
| 577 | @Override |
| 578 | public int hashCode() { |
| 579 | return Objects.hash(mplsLabel, type()); |
| 580 | } |
| 581 | |
| 582 | @Override |
| 583 | public boolean equals(Object obj) { |
| 584 | if (this == obj) { |
| 585 | return true; |
| 586 | } |
| 587 | if (obj instanceof MplsCriterion) { |
| 588 | MplsCriterion that = (MplsCriterion) obj; |
| 589 | return Objects.equals(mplsLabel, that.mplsLabel) && |
| 590 | Objects.equals(this.type(), that.type()); |
| 591 | |
| 592 | |
| 593 | } |
| 594 | return false; |
| 595 | } |
| 596 | |
| 597 | } |
| 598 | |
| 599 | |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 600 | public static final class LambdaCriterion implements Criterion { |
| 601 | |
| 602 | private final short lambda; |
| 603 | private final Type type; |
| 604 | |
| 605 | public LambdaCriterion(short lambda, Type type) { |
| 606 | this.lambda = lambda; |
| 607 | this.type = type; |
| 608 | } |
| 609 | |
| 610 | @Override |
| 611 | public Type type() { |
| 612 | return this.type; |
| 613 | } |
| 614 | |
| 615 | public Short lambda() { |
| 616 | return this.lambda; |
| 617 | } |
| 618 | |
| 619 | @Override |
| 620 | public String toString() { |
| 621 | return toStringHelper(type().toString()) |
| 622 | .add("lambda", lambda).toString(); |
| 623 | } |
| 624 | |
| 625 | @Override |
| 626 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 627 | return Objects.hash(type, lambda); |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | @Override |
| 631 | public boolean equals(Object obj) { |
| 632 | if (this == obj) { |
| 633 | return true; |
| 634 | } |
| 635 | if (obj instanceof LambdaCriterion) { |
| 636 | LambdaCriterion that = (LambdaCriterion) obj; |
| 637 | return Objects.equals(lambda, that.lambda) && |
| 638 | Objects.equals(type, that.type); |
| 639 | } |
| 640 | return false; |
| 641 | } |
| 642 | } |
| 643 | |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 644 | public static final class OpticalSignalTypeCriterion implements Criterion { |
| 645 | |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 646 | private final Short signalType; |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 647 | private final Type type; |
| 648 | |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 649 | public OpticalSignalTypeCriterion(Short signalType, Type type) { |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 650 | this.signalType = signalType; |
| 651 | this.type = type; |
| 652 | } |
| 653 | |
| 654 | @Override |
| 655 | public Type type() { |
| 656 | return this.type; |
| 657 | } |
| 658 | |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 659 | public Short signalType() { |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 660 | return this.signalType; |
| 661 | } |
| 662 | |
| 663 | @Override |
| 664 | public String toString() { |
| 665 | return toStringHelper(type().toString()) |
| 666 | .add("signalType", signalType).toString(); |
| 667 | } |
| 668 | |
| 669 | @Override |
| 670 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 671 | return Objects.hash(type, signalType); |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | @Override |
| 675 | public boolean equals(Object obj) { |
| 676 | if (this == obj) { |
| 677 | return true; |
| 678 | } |
| 679 | if (obj instanceof OpticalSignalTypeCriterion) { |
| 680 | OpticalSignalTypeCriterion that = (OpticalSignalTypeCriterion) obj; |
| 681 | return Objects.equals(signalType, that.signalType) && |
| 682 | Objects.equals(type, that.type); |
| 683 | } |
| 684 | return false; |
| 685 | } |
| 686 | } |
| 687 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 688 | } |