blob: 856e192ef0945eb046e5227e73a5f6a8e167cce4 [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
Jian Lif1ecf992015-12-02 17:48:54 -080020/**
21 * Implementation of PBB I-SID criterion (24 bits unsigned integer).
22 */
23public final class PbbIsidCriterion implements Criterion {
24 private static final int MASK = 0xfffff;
25 private final int pbbIsid; // PBB I-SID: 24 bits
26
27 /**
28 * Constructor.
29 *
30 * @param pbbIsid the PBB I-SID to match (24 bits)
31 */
32 PbbIsidCriterion(int pbbIsid) {
33 this.pbbIsid = pbbIsid & MASK;
34 }
35
36 @Override
37 public Criterion.Type type() {
38 return Criterion.Type.PBB_ISID;
39 }
40
41 /**
42 * Gets the PBB I-SID to match.
43 *
44 * @return the PBB I-SID to match (24 bits)
45 */
46 public int pbbIsid() {
47 return this.pbbIsid;
48 }
49
50 @Override
51 public String toString() {
Jonathan Hartc7840bd2016-01-21 23:26:29 -080052 return type().toString() + SEPARATOR + Long.toHexString(pbbIsid);
Jian Lif1ecf992015-12-02 17:48:54 -080053 }
54
55 @Override
56 public int hashCode() {
57 return Objects.hash(type().ordinal(), pbbIsid);
58 }
59
60 @Override
61 public boolean equals(Object obj) {
62 if (this == obj) {
63 return true;
64 }
65 if (obj instanceof PbbIsidCriterion) {
66 PbbIsidCriterion that = (PbbIsidCriterion) obj;
67 return Objects.equals(pbbIsid, that.pbbIsid) &&
68 Objects.equals(this.type(), that.type());
69 }
70 return false;
71 }
72}