blob: ea8c34d8ed11746536bc0253fdcea44ee2861924 [file] [log] [blame]
Frank Wangd7e3b4b2017-09-24 13:37:54 +09001/*
2 * Copyright 2017-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
17package org.onosproject.net.pi.runtime;
18
19import com.google.common.annotations.Beta;
20
21import java.util.Objects;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24
25/**
26 * Represents a band used within a meter.
27 */
28@Beta
Carmelo Cascone4c289b72019-01-22 15:30:45 -080029public final class PiMeterBand {
pierventrec0914ec2021-08-27 15:25:02 +020030 private final PiMeterBandType type;
Frank Wangd7e3b4b2017-09-24 13:37:54 +090031 private final long rate;
32 private final long burst;
33
34 /**
35 * Creates a band with rate and burst.
36 *
pierventrec0914ec2021-08-27 15:25:02 +020037 * @param type type of this band
Frank Wangd7e3b4b2017-09-24 13:37:54 +090038 * @param rate rate of this band
39 * @param burst burst of this band
40 */
pierventrec0914ec2021-08-27 15:25:02 +020041 public PiMeterBand(PiMeterBandType type, long rate, long burst) {
42 this.type = type;
Frank Wangd7e3b4b2017-09-24 13:37:54 +090043 this.rate = rate;
44 this.burst = burst;
45 }
46
47 /**
pierventrec0914ec2021-08-27 15:25:02 +020048 * Returns the type of this band.
49 *
50 * @return type of this band
51 */
52 public PiMeterBandType type() {
53 return type;
54 }
55
56 /**
Frank Wangd7e3b4b2017-09-24 13:37:54 +090057 * Returns the rate of this band.
58 *
59 * @return rate of this band
60 */
61 public long rate() {
62 return rate;
63 }
64
65 /**
66 * Returns the burst of this band.
67 *
68 * @return burst of this band
69 */
70 public long burst() {
71 return burst;
72 }
73
74 @Override
75 public int hashCode() {
pierventrec0914ec2021-08-27 15:25:02 +020076 return Objects.hash(type, rate, burst);
Frank Wangd7e3b4b2017-09-24 13:37:54 +090077 }
78
79 @Override
80 public boolean equals(Object obj) {
81 if (this == obj) {
82 return true;
83 }
84 if (obj instanceof PiMeterBand) {
85 PiMeterBand that = (PiMeterBand) obj;
pierventrec0914ec2021-08-27 15:25:02 +020086 return Objects.equals(type, that.type) &&
87 Objects.equals(rate, that.rate) &&
Frank Wangd7e3b4b2017-09-24 13:37:54 +090088 Objects.equals(burst, that.burst);
89
90 }
91 return false;
92 }
93
94 public String toString() {
95 return toStringHelper(this)
pierventrec0914ec2021-08-27 15:25:02 +020096 .add("type", type)
Frank Wangd7e3b4b2017-09-24 13:37:54 +090097 .add("rate", rate)
98 .add("burst", burst).toString();
99 }
100}