Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | package org.onosproject.net.flow.criteria; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 21 | |
| 22 | /** |
| 23 | * Implementation of lambda (wavelength) criterion (16 bits unsigned |
| 24 | * integer). |
| 25 | */ |
| 26 | public final class LambdaCriterion implements Criterion { |
| 27 | private static final int MASK = 0xffff; |
| 28 | private final int lambda; // Lambda value: 16 bits |
| 29 | private final Type type; |
| 30 | |
| 31 | /** |
| 32 | * Constructor. |
| 33 | * |
| 34 | * @param lambda the lambda (wavelength) to match (16 bits unsigned |
| 35 | * integer) |
| 36 | * @param type the match type. Should be Type.OCH_SIGID |
| 37 | */ |
| 38 | LambdaCriterion(int lambda, Type type) { |
| 39 | this.lambda = lambda & MASK; |
| 40 | this.type = type; |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public Type type() { |
| 45 | return this.type; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Gets the lambda (wavelength) to match. |
| 50 | * |
| 51 | * @return the lambda (wavelength) to match (16 bits unsigned integer) |
| 52 | */ |
| 53 | public int lambda() { |
| 54 | return lambda; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public String toString() { |
| 59 | return toStringHelper(type().toString()) |
| 60 | .add("lambda", lambda).toString(); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 65 | return Objects.hash(type().ordinal(), lambda); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public boolean equals(Object obj) { |
| 70 | if (this == obj) { |
| 71 | return true; |
| 72 | } |
| 73 | if (obj instanceof LambdaCriterion) { |
| 74 | LambdaCriterion that = (LambdaCriterion) obj; |
| 75 | return Objects.equals(lambda, that.lambda) && |
| 76 | Objects.equals(type, that.type); |
| 77 | } |
| 78 | return false; |
| 79 | } |
| 80 | } |