blob: a3a4fc274204bdd1d0f5034a3ba1fcb452a5e73b [file] [log] [blame]
alshabib1d2bc402015-07-31 17:04:11 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
alshabib10c810b2015-08-18 16:59:04 -070016package org.onosproject.net.meter;
alshabib1d2bc402015-07-31 17:04:11 -070017
18import static com.google.common.base.Preconditions.checkArgument;
19
20/**
21 * A default implementation for a Band.
22 */
alshabib7bb05012015-08-05 10:15:09 -070023public final class DefaultBand implements Band, BandEntry {
alshabib1d2bc402015-07-31 17:04:11 -070024
25 private final Type type;
26 private final long rate;
27 private final long burstSize;
28 private final short prec;
alshabib7bb05012015-08-05 10:15:09 -070029 private long packets;
30 private long bytes;
alshabib1d2bc402015-07-31 17:04:11 -070031
32 public DefaultBand(Type type, long rate,
33 long burstSize, short prec) {
34 this.type = type;
35 this.rate = rate;
36 this.burstSize = burstSize;
37 this.prec = prec;
38 }
39
40 @Override
41 public long rate() {
42 return rate;
43 }
44
45 @Override
46 public long burst() {
47 return burstSize;
48 }
49
50 @Override
51 public short dropPrecedence() {
52 return prec;
53 }
54
55 @Override
56 public Type type() {
57 return type;
58 }
59
alshabib7bb05012015-08-05 10:15:09 -070060 @Override
61 public long packets() {
62 return packets;
63 }
64
65 @Override
66 public long bytes() {
67 return bytes;
68 }
69
70 @Override
71 public void setPackets(long packets) {
72 this.packets = packets;
73 }
74
75 @Override
76 public void setBytes(long bytes) {
77 this.bytes = bytes;
78 }
79
alshabib1d2bc402015-07-31 17:04:11 -070080 public static Builder builder() {
81 return new Builder();
82 }
83
84 public static final class Builder implements Band.Builder {
85
86 private long rate;
87 private long burstSize;
88 private Short prec;
89 private Type type;
90
91 @Override
92 public Band.Builder withRate(long rate) {
93 this.rate = rate;
94 return this;
95 }
96
97 @Override
98 public Band.Builder burstSize(long burstSize) {
99 this.burstSize = burstSize;
100 return this;
101 }
102
103 @Override
104 public Band.Builder dropPrecedence(short prec) {
105 this.prec = prec;
106 return this;
107 }
108
109 @Override
110 public Band.Builder ofType(Type type) {
111 this.type = type;
112 return this;
113 }
114
115 @Override
alshabib7bb05012015-08-05 10:15:09 -0700116 public DefaultBand build() {
alshabib1d2bc402015-07-31 17:04:11 -0700117 checkArgument(prec != null && type == Type.REMARK,
118 "Only REMARK bands can have a precendence.");
119
120 return new DefaultBand(type, rate, burstSize, prec);
121 }
122
123
124 }
125}