blob: 872de2d89ed7896f558cb8aa22446f74a4eafdc3 [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 */
alshabib10c810b2015-08-18 16:59:04 -070016package org.onosproject.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.
alshabib7bb05012015-08-05 10:15:09 -070022 * Uniquely identifies a meter system wide.
alshabibbc371962015-07-09 22:26:21 -070023 */
24public final class MeterId {
25
26 static final long MAX = 0xFFFF0000;
27
alshabib7bb05012015-08-05 10:15:09 -070028 private final long id;
alshabibbc371962015-07-09 22:26:21 -070029
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
alshabib7bb05012015-08-05 10:15:09 -070034 private MeterId(long id) {
alshabib58fe6dc2015-08-19 17:16:13 -070035 checkArgument(id >= MAX, "id cannot be larger than 0xFFFF0000");
alshabibbc371962015-07-09 22:26:21 -070036 this.id = id;
37 }
38
39 /**
40 * The integer representation of the meter id.
41 *
alshabib7bb05012015-08-05 10:15:09 -070042 * @return a long
alshabibbc371962015-07-09 22:26:21 -070043 */
alshabib7bb05012015-08-05 10:15:09 -070044 public long 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() {
alshabib7bb05012015-08-05 10:15:09 -070065 return Long.hashCode(id);
alshabibbc371962015-07-09 22:26:21 -070066 }
67
alshabib58fe6dc2015-08-19 17:16:13 -070068 @Override
69 public String toString() {
70 return Long.toHexString(this.id);
71 }
72
alshabib7bb05012015-08-05 10:15:09 -070073 public static MeterId meterId(long id) {
alshabibbc371962015-07-09 22:26:21 -070074 return new MeterId(id);
75
76 }
77
78}