blob: 80b08d260f64f9269b198301a8be58b42bdb6fcc [file] [log] [blame]
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07003 *
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 */
16package org.onosproject.net.flow.criteria;
17
18import org.onlab.packet.MplsLabel;
19
20import java.util.Objects;
21
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070022/**
23 * Implementation of MPLS tag criterion (20 bits).
24 */
25public 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 Hartc7840bd2016-01-21 23:26:29 -080044 return type().toString() + SEPARATOR + mplsLabel;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070045 }
46
47 @Override
48 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -070049 return Objects.hash(type().ordinal(), mplsLabel);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070050 }
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}