Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 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 | |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Implementation of MPLS tag criterion (20 bits). |
| 24 | */ |
| 25 | public final class MplsCriterion implements Criterion { |
| 26 | private static final int MASK = 0xfffff; |
| 27 | private final MplsLabel mplsLabel; |
| 28 | |
| 29 | MplsCriterion(MplsLabel mplsLabel) { |
| 30 | this.mplsLabel = mplsLabel; |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public Type type() { |
| 35 | return Type.MPLS_LABEL; |
| 36 | } |
| 37 | |
| 38 | public MplsLabel label() { |
| 39 | return mplsLabel; |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 44 | return type().toString() + SEPARATOR + mplsLabel; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 49 | return Objects.hash(type().ordinal(), mplsLabel); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public boolean equals(Object obj) { |
| 54 | if (this == obj) { |
| 55 | return true; |
| 56 | } |
| 57 | if (obj instanceof MplsCriterion) { |
| 58 | MplsCriterion that = (MplsCriterion) obj; |
| 59 | return Objects.equals(mplsLabel, that.mplsLabel) && |
| 60 | Objects.equals(this.type(), that.type()); |
| 61 | } |
| 62 | return false; |
| 63 | } |
| 64 | } |