blob: 34d384f13ccd90c9c3bc4e73e72d2a8b3297de24 [file] [log] [blame]
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001/*
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 */
16package org.onosproject.net.flow.criteria;
17
18import org.onlab.packet.MplsLabel;
19
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
24/**
25 * Implementation of MPLS tag criterion (20 bits).
26 */
27public 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() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -070052 return Objects.hash(type().ordinal(), mplsLabel);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070053 }
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}