blob: cd8189f59c514b06ae30cbd5e214c4eb5cda8a98 [file] [log] [blame]
Frank Wange11a98d2016-10-26 17:04:03 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Frank Wange11a98d2016-10-26 17:04:03 +08003 *
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 */
16package org.onosproject.net.behaviour;
17
18import com.google.common.annotations.Beta;
19import com.google.common.base.MoreObjects;
20import org.onlab.util.Bandwidth;
21import org.onosproject.net.AbstractDescription;
22import org.onosproject.net.SparseAnnotations;
23
24import java.util.Map;
25import java.util.Objects;
26import java.util.Optional;
27
28import static com.google.common.base.Preconditions.checkNotNull;
29
30
31/**
32 * Default implementation of Qos description entity.
33 */
34@Beta
35public final class DefaultQosDescription extends AbstractDescription
36 implements QosDescription {
37
38 private final QosId qosId;
39 private final Type type;
40 private final Optional<Bandwidth> maxRate;
41 private final Optional<Long> cir;
42 private final Optional<Long> cbs;
43 private final Optional<Map<Long, QueueDescription>> queues;
44
45 private DefaultQosDescription(QosId qosId, Type type, Optional<Bandwidth> maxRate,
46 Optional<Long> cir, Optional<Long> cbs,
47 Optional<Map<Long, QueueDescription>> queues,
48 SparseAnnotations... annotations) {
49 super(annotations);
50 this.qosId = checkNotNull(qosId);
51 this.type = checkNotNull(type);
52 this.maxRate = maxRate;
53 this.cir = cir;
54 this.cbs = cbs;
55 this.queues = queues;
56 }
57
58 @Override
59 public QosId qosId() {
60 return qosId;
61 }
62
63 @Override
64 public Type type() {
65 return type;
66 }
67
68 @Override
69 public Optional<Bandwidth> maxRate() {
70 return maxRate;
71 }
72
73 @Override
74 public Optional<Long> cir() {
75 return cir;
76 }
77
78 @Override
79 public Optional<Long> cbs() {
80 return cbs;
81 }
82
83 @Override
84 public Optional<Map<Long, QueueDescription>> queues() {
85 return queues;
86 }
87
88 @Override
89 public int hashCode() {
90 return Objects.hash(qosId, type, maxRate, cir, cbs, queues);
91 }
92
93 @Override
94 public boolean equals(Object obj) {
95 if (this == obj) {
96 return true;
97 }
98 if (obj instanceof DefaultQosDescription) {
99 final DefaultQosDescription other = (DefaultQosDescription) obj;
100 return Objects.equals(this.qosId, other.qosId) &&
101 Objects.equals(this.type, other.type) &&
102 Objects.equals(this.maxRate, other.maxRate) &&
103 Objects.equals(this.cir, other.cir) &&
104 Objects.equals(this.cbs, other.cbs) &&
105 Objects.equals(this.queues, other.queues);
106 }
107 return false;
108 }
109
110 @Override
111 public String toString() {
112 return MoreObjects.toStringHelper(this)
113 .add("qosId", qosId())
114 .add("type", type())
115 .add("maxRate", maxRate().orElse(null))
116 .add("cir", cir().orElse(0L))
117 .add("cbs", cbs().orElse(0L))
118 .add("queues", queues().orElse(null))
119 .toString();
120 }
121
122 public static Builder builder() {
123 return new Builder();
124 }
125
126 public static final class Builder implements QosDescription.Builder {
127
128 private QosId qosId;
129 private Type type;
130 private Optional<Bandwidth> maxRate = Optional.empty();
131 private Optional<Long> cir = Optional.empty();
132 private Optional<Long> cbs = Optional.empty();
133 private Optional<Map<Long, QueueDescription>> queues = Optional.empty();
134
135 private Builder() {
136 }
137
138 @Override
139 public QosDescription build() {
140 return new DefaultQosDescription(qosId, type, maxRate, cir, cbs, queues);
141 }
142
143 @Override
144 public Builder qosId(QosId qosId) {
145 this.qosId = qosId;
146 return this;
147 }
148
149 @Override
150 public Builder type(Type type) {
151 this.type = type;
152 return this;
153 }
154
155 @Override
156 public Builder maxRate(Bandwidth maxRate) {
157 this.maxRate = Optional.ofNullable(maxRate);
158 return this;
159 }
160
161 @Override
162 public Builder cir(Long cir) {
163 this.cir = Optional.ofNullable(cir);
164 return this;
165 }
166
167 @Override
168 public Builder cbs(Long cbs) {
169 this.cbs = Optional.ofNullable(cbs);
170 return this;
171 }
172
173 @Override
174 public Builder queues(Map<Long, QueueDescription> queues) {
175 this.queues = Optional.ofNullable(queues);
176 return this;
177 }
178 }
179}
180