alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame] | 16 | package org.onosproject.net.meter; |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 17 | |
| 18 | import static com.google.common.base.Preconditions.checkArgument; |
| 19 | |
| 20 | /** |
| 21 | * A representation of a meter id. |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 22 | * Uniquely identifies a meter system wide. |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 23 | */ |
| 24 | public final class MeterId { |
| 25 | |
| 26 | static final long MAX = 0xFFFF0000; |
| 27 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 28 | private final long id; |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 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 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 34 | private MeterId(long id) { |
alshabib | 58fe6dc | 2015-08-19 17:16:13 -0700 | [diff] [blame] | 35 | checkArgument(id >= MAX, "id cannot be larger than 0xFFFF0000"); |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 36 | this.id = id; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * The integer representation of the meter id. |
| 41 | * |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 42 | * @return a long |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 43 | */ |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 44 | public long id() { |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 45 | 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() { |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 65 | return Long.hashCode(id); |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 66 | } |
| 67 | |
alshabib | 58fe6dc | 2015-08-19 17:16:13 -0700 | [diff] [blame] | 68 | @Override |
| 69 | public String toString() { |
| 70 | return Long.toHexString(this.id); |
| 71 | } |
| 72 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 73 | public static MeterId meterId(long id) { |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 74 | return new MeterId(id); |
| 75 | |
| 76 | } |
| 77 | |
| 78 | } |