blob: 979aa6bd214e09bfbe54af8b3b31eac6b9730c8c [file] [log] [blame]
Jian Lif1ecf992015-12-02 17:48:54 -08001/*
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 java.util.Objects;
19
20import static com.google.common.base.MoreObjects.toStringHelper;
21
22/**
23 * Implementation of PBB I-SID criterion (24 bits unsigned integer).
24 */
25public final class PbbIsidCriterion implements Criterion {
26 private static final int MASK = 0xfffff;
27 private final int pbbIsid; // PBB I-SID: 24 bits
28
29 /**
30 * Constructor.
31 *
32 * @param pbbIsid the PBB I-SID to match (24 bits)
33 */
34 PbbIsidCriterion(int pbbIsid) {
35 this.pbbIsid = pbbIsid & MASK;
36 }
37
38 @Override
39 public Criterion.Type type() {
40 return Criterion.Type.PBB_ISID;
41 }
42
43 /**
44 * Gets the PBB I-SID to match.
45 *
46 * @return the PBB I-SID to match (24 bits)
47 */
48 public int pbbIsid() {
49 return this.pbbIsid;
50 }
51
52 @Override
53 public String toString() {
54 return toStringHelper(type().toString())
55 .add("pbbIsid", Long.toHexString(pbbIsid)).toString();
56 }
57
58 @Override
59 public int hashCode() {
60 return Objects.hash(type().ordinal(), pbbIsid);
61 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj) {
66 return true;
67 }
68 if (obj instanceof PbbIsidCriterion) {
69 PbbIsidCriterion that = (PbbIsidCriterion) obj;
70 return Objects.equals(pbbIsid, that.pbbIsid) &&
71 Objects.equals(this.type(), that.type());
72 }
73 return false;
74 }
75}