blob: 22ef064c01c2f29ed12829dda313d1f7bc7a934f [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/**
Jordi Ortiz75f5fb92016-10-21 19:26:16 +020023 * A representation of a meter identifier.
Konstantinos Kanonakis317a7de2016-02-18 18:00:11 -060024 * Uniquely identifies a meter in the scope of a single device.
Jordi Ortiz75f5fb92016-10-21 19:26:16 +020025 * <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:
alshabibbc371962015-07-09 22:26:21 -070030 */
Jian Lib6d998e2016-02-29 11:41:18 -080031public final class MeterId extends Identifier<Long> {
alshabibbc371962015-07-09 22:26:21 -070032
Jordi Ortiz75f5fb92016-10-21 19:26:16 +020033 /** Flow meters can use any number up to MAX. */
34 public static final long MAX = 0xFFFF0000L;
alshabibbc371962015-07-09 22:26:21 -070035
Jordi Ortiz75f5fb92016-10-21 19:26:16 +020036
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
alshabibbc371962015-07-09 22:26:21 -070045
alshabib7bb05012015-08-05 10:15:09 -070046 private MeterId(long id) {
Jian Lib6d998e2016-02-29 11:41:18 -080047 super(id);
alshabibbc371962015-07-09 22:26:21 -070048 }
49
alshabib58fe6dc2015-08-19 17:16:13 -070050 @Override
51 public String toString() {
Jordi Ortiz75f5fb92016-10-21 19:26:16 +020052 return Long.toHexString(identifier);
alshabib58fe6dc2015-08-19 17:16:13 -070053 }
54
Jian Lib6d998e2016-02-29 11:41:18 -080055 /**
56 * Creates a new meter identifier.
57 *
Jordi Ortiz75f5fb92016-10-21 19:26:16 +020058 * @param id the backing identifier value
Jian Lib6d998e2016-02-29 11:41:18 -080059 * @return meter identifier
60 */
alshabib7bb05012015-08-05 10:15:09 -070061 public static MeterId meterId(long id) {
Jordi Ortiz75f5fb92016-10-21 19:26:16 +020062 checkArgument(id > 0, "id cannot be negative nor 0");
63 checkArgument(id <= MAX, "id cannot be larger than {}", MAX);
alshabibbc371962015-07-09 22:26:21 -070064 return new MeterId(id);
alshabibbc371962015-07-09 22:26:21 -070065 }
alshabibbc371962015-07-09 22:26:21 -070066}