blob: ea7cf36f2cc941c130e3ee88c27dbe47c4c5a22a [file] [log] [blame]
alshabibbc371962015-07-09 22:26:21 -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 */
alshabib1d2bc402015-07-31 17:04:11 -070016package org.onosproject.incubator.net.meter;
alshabibbc371962015-07-09 22:26:21 -070017
18import static com.google.common.base.Preconditions.checkArgument;
19
20/**
21 * A representation of a meter id.
22 * Uniquely identifies a meter for a given device.
23 */
24public final class MeterId {
25
26 static final long MAX = 0xFFFF0000;
27
28 private final int id;
29
30 public static final MeterId SLOWPATH = new MeterId(0xFFFFFFFD);
31 public static final MeterId CONTROLLER = new MeterId(0xFFFFFFFE);
32 public static final MeterId ALL = new MeterId(0xFFFFFFFF);
33
alshabib1d2bc402015-07-31 17:04:11 -070034 private MeterId(int id) {
alshabibbc371962015-07-09 22:26:21 -070035 checkArgument(id <= MAX, "id cannot be larger than 0xFFFF0000");
36 this.id = id;
37 }
38
39 /**
40 * The integer representation of the meter id.
41 *
42 * @return an integer
43 */
alshabibc7911792015-07-30 17:55:30 -070044 public int id() {
alshabibbc371962015-07-09 22:26:21 -070045 return id;
46 }
47
48 @Override
49 public boolean equals(Object o) {
50 if (this == o) {
51 return true;
52 }
53 if (o == null || getClass() != o.getClass()) {
54 return false;
55 }
56
57 MeterId meterId = (MeterId) o;
58
59 return id == meterId.id;
60
61 }
62
63 @Override
64 public int hashCode() {
65 return id;
66 }
67
68 public static MeterId meterId(int id) {
69 return new MeterId(id);
70
71 }
72
73}