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