alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 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 | /** |
Jordi Ortiz | 75f5fb9 | 2016-10-21 19:26:16 +0200 | [diff] [blame] | 23 | * A representation of a meter identifier. |
Konstantinos Kanonakis | 317a7de | 2016-02-18 18:00:11 -0600 | [diff] [blame] | 24 | * Uniquely identifies a meter in the scope of a single device. |
Jordi Ortiz | 75f5fb9 | 2016-10-21 19:26:16 +0200 | [diff] [blame] | 25 | * <p> |
| 26 | * The meter_id field uniquely identifies a meter within a switch. Meters are |
| 27 | * defined starting with meter_id=1 up to the maximum number of meters that the |
| 28 | * switch can support. The OpenFlow protocol also defines some additional |
| 29 | * virtual meters that can not be associated with flows: |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 30 | */ |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 31 | public final class MeterId extends Identifier<Long> { |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 32 | |
Jordi Ortiz | 75f5fb9 | 2016-10-21 19:26:16 +0200 | [diff] [blame] | 33 | /** Flow meters can use any number up to MAX. */ |
| 34 | public static final long MAX = 0xFFFF0000L; |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 35 | |
Jordi Ortiz | 75f5fb9 | 2016-10-21 19:26:16 +0200 | [diff] [blame] | 36 | |
| 37 | /* The following are virtual meters as defined in openflow-spec-1.3 P. 58 */ |
| 38 | /** Meter for slow datapath, if any. */ |
| 39 | public static final MeterId SLOWPATH = new MeterId(0xFFFFFFFDL); |
| 40 | /** Meter for controller connection. */ |
| 41 | public static final MeterId CONTROLLER = new MeterId(0xFFFFFFFEL); |
| 42 | /** Represents all meters for stat requests commands. */ |
| 43 | public static final MeterId ALL = new MeterId(0xFFFFFFFFL); |
| 44 | |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 45 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 46 | private MeterId(long id) { |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 47 | super(id); |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 48 | } |
| 49 | |
alshabib | 58fe6dc | 2015-08-19 17:16:13 -0700 | [diff] [blame] | 50 | @Override |
| 51 | public String toString() { |
Jordi Ortiz | 75f5fb9 | 2016-10-21 19:26:16 +0200 | [diff] [blame] | 52 | return Long.toHexString(identifier); |
alshabib | 58fe6dc | 2015-08-19 17:16:13 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 55 | /** |
| 56 | * Creates a new meter identifier. |
| 57 | * |
Jordi Ortiz | 75f5fb9 | 2016-10-21 19:26:16 +0200 | [diff] [blame] | 58 | * @param id the backing identifier value |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 59 | * @return meter identifier |
| 60 | */ |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 61 | public static MeterId meterId(long id) { |
Jordi Ortiz | 75f5fb9 | 2016-10-21 19:26:16 +0200 | [diff] [blame] | 62 | checkArgument(id > 0, "id cannot be negative nor 0"); |
| 63 | checkArgument(id <= MAX, "id cannot be larger than {}", MAX); |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 64 | return new MeterId(id); |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 65 | } |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 66 | } |