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 org.onlab.packet.MplsLabel; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
| 24 | /** |
| 25 | * Implementation of MPLS tag criterion (20 bits). |
| 26 | */ |
| 27 | public final class MplsCriterion implements Criterion { |
| 28 | private static final int MASK = 0xfffff; |
| 29 | private final MplsLabel mplsLabel; |
| 30 | |
| 31 | MplsCriterion(MplsLabel mplsLabel) { |
| 32 | this.mplsLabel = mplsLabel; |
| 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public Type type() { |
| 37 | return Type.MPLS_LABEL; |
| 38 | } |
| 39 | |
| 40 | public MplsLabel label() { |
| 41 | return mplsLabel; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public String toString() { |
| 46 | return toStringHelper(type().toString()) |
| 47 | .add("mpls", mplsLabel).toString(); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public int hashCode() { |
| 52 | return Objects.hash(type(), mplsLabel); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public boolean equals(Object obj) { |
| 57 | if (this == obj) { |
| 58 | return true; |
| 59 | } |
| 60 | if (obj instanceof MplsCriterion) { |
| 61 | MplsCriterion that = (MplsCriterion) obj; |
| 62 | return Objects.equals(mplsLabel, that.mplsLabel) && |
| 63 | Objects.equals(this.type(), that.type()); |
| 64 | } |
| 65 | return false; |
| 66 | } |
| 67 | } |