blob: c8eec46426113b1974e8e6755ad780c3c2bdfe21 [file] [log] [blame]
alshabibbc371962015-07-09 22:26:21 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
alshabibbc371962015-07-09 22:26:21 -07003 *
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
Jian Lib6d998e2016-02-29 11:41:18 -080018import org.onlab.util.Identifier;
19
alshabibbc371962015-07-09 22:26:21 -070020import static com.google.common.base.Preconditions.checkArgument;
21
22/**
23 * A representation of a meter id.
Konstantinos Kanonakis317a7de2016-02-18 18:00:11 -060024 * Uniquely identifies a meter in the scope of a single device.
alshabibbc371962015-07-09 22:26:21 -070025 */
Jian Lib6d998e2016-02-29 11:41:18 -080026public final class MeterId extends Identifier<Long> {
alshabibbc371962015-07-09 22:26:21 -070027
28 static final long MAX = 0xFFFF0000;
29
alshabibbc371962015-07-09 22:26:21 -070030 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) {
Jian Lib6d998e2016-02-29 11:41:18 -080035 super(id);
alshabib58fe6dc2015-08-19 17:16:13 -070036 checkArgument(id >= MAX, "id cannot be larger than 0xFFFF0000");
alshabibbc371962015-07-09 22:26:21 -070037 }
38
alshabib58fe6dc2015-08-19 17:16:13 -070039 @Override
40 public String toString() {
Jian Lib6d998e2016-02-29 11:41:18 -080041 return Long.toHexString(this.identifier);
alshabib58fe6dc2015-08-19 17:16:13 -070042 }
43
Jian Lib6d998e2016-02-29 11:41:18 -080044 /**
45 * Creates a new meter identifier.
46 *
47 * @param id backing identifier value
48 * @return meter identifier
49 */
alshabib7bb05012015-08-05 10:15:09 -070050 public static MeterId meterId(long id) {
alshabibbc371962015-07-09 22:26:21 -070051 return new MeterId(id);
alshabibbc371962015-07-09 22:26:21 -070052 }
alshabibbc371962015-07-09 22:26:21 -070053}