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 | |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 18 | import org.onlab.util.Identifier; |
| 19 | |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 20 | import static com.google.common.base.Preconditions.checkArgument; |
| 21 | |
| 22 | /** |
| 23 | * A representation of a meter id. |
Konstantinos Kanonakis | 317a7de | 2016-02-18 18:00:11 -0600 | [diff] [blame] | 24 | * Uniquely identifies a meter in the scope of a single device. |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 25 | */ |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 26 | public final class MeterId extends Identifier<Long> { |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 27 | |
| 28 | static final long MAX = 0xFFFF0000; |
| 29 | |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 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) { |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 35 | super(id); |
alshabib | 58fe6dc | 2015-08-19 17:16:13 -0700 | [diff] [blame] | 36 | checkArgument(id >= MAX, "id cannot be larger than 0xFFFF0000"); |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 37 | } |
| 38 | |
alshabib | 58fe6dc | 2015-08-19 17:16:13 -0700 | [diff] [blame] | 39 | @Override |
| 40 | public String toString() { |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 41 | return Long.toHexString(this.identifier); |
alshabib | 58fe6dc | 2015-08-19 17:16:13 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 44 | /** |
| 45 | * Creates a new meter identifier. |
| 46 | * |
| 47 | * @param id backing identifier value |
| 48 | * @return meter identifier |
| 49 | */ |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 50 | public static MeterId meterId(long id) { |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 51 | return new MeterId(id); |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 52 | } |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 53 | } |