Wailok Shum | f013a78 | 2021-07-26 16:51:01 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-present Open Networking Foundation |
| 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 | */ |
| 16 | package org.onosproject.net.meter; |
| 17 | |
| 18 | import org.onlab.util.Identifier; |
| 19 | |
| 20 | /** |
| 21 | * Scope of Meter Features. |
| 22 | * |
| 23 | * There are multiple meter tables in a P4RT device, |
| 24 | * to distinguish and represent them uniquely, |
| 25 | * we added a Scope field. |
| 26 | * |
| 27 | * For P4RT device, value will be the PiMeterId. |
| 28 | * For OF device, we use "global" by default, since there is only 1 table in OF. |
| 29 | * In general, a Meter Scope is referring to a Meter Table. |
| 30 | * It can be a PiMeterId or "global" for the single OF meter table. |
| 31 | * |
| 32 | * During runtime, users need to provide a PiMeterId to indicate which Meter Cell they |
| 33 | * are intended to modify. The value will then be used to create a Meter Scope |
| 34 | * for the rest of the process. |
| 35 | * If no PiMeterId is provided, a "global" Meter Scope is created. |
| 36 | */ |
| 37 | public class MeterScope extends Identifier<String> { |
| 38 | |
| 39 | public static final String METER_GLOBAL_SCOPE = "global"; |
| 40 | |
| 41 | /** |
| 42 | * Create a Meter Scope from id string. |
| 43 | * @param scope the scope |
| 44 | * @return a Meter Scope |
| 45 | */ |
| 46 | public static MeterScope of(String scope) { |
| 47 | return new MeterScope(scope); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Create a global Meter Scope. |
| 52 | * @return a Meter Scope |
| 53 | */ |
| 54 | public static MeterScope globalScope() { |
| 55 | return new MeterScope(METER_GLOBAL_SCOPE); |
| 56 | } |
| 57 | |
| 58 | MeterScope(String scope) { |
| 59 | super(scope); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Global scope or not. |
| 64 | * @return true if global scope, false if not. |
| 65 | */ |
| 66 | public boolean isGlobal() { |
| 67 | return identifier.equals(METER_GLOBAL_SCOPE); |
| 68 | } |
| 69 | } |