blob: 0aff5abfe5fef38e1697aa92c7e6de559233cb78 [file] [log] [blame]
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001/*
2 * Copyright 2016 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 */
16package org.onosproject.tetopology.management.api.link;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.base.Objects;
20
21import java.util.Arrays;
22
23/**
24 * Representation the TE link bandwidths.
25 */
26public class LinkBandwidth {
27 /**
28 * Maximum bandwidth, Size is MAX_PRIORITY + 1.
29 */
30 private final float[] maxBandwidth;
31
32 /**
33 * Unreserved bandwidth, Size is MAX_PRIORITY + 1.
34 */
35 private final float[] availBandwidth;
36
37 /**
38 * Maximum available bandwidth for a LSP.
39 */
40 private final float[] maxAvailLspBandwidth;
41
42 /**
43 * Minimum available bandwidth for a LSP.
44 */
45 private final float[] minAvailLspBandwidth;
46
47 /**
48 * ODU resources.
49 */
50 private final OduResource odu;
51
52 /**
53 * Creates an instance of link bandwidth.
54 *
55 * @param maxBandwidth the maximum bandwidth at each priority level
56 * @param availBandwidth the available bandwidth at each priority level
57 * @param maxAvailLspBandwidth the maximum available bandwidth for a LSP at
58 * each priority level
59 * @param minAvailLspBandwidth the minimum available bandwidth for a LSP at
60 * each priority level
61 * @param odu ODU resources
62 */
63 public LinkBandwidth(float[] maxBandwidth,
64 float[] availBandwidth,
65 float[] maxAvailLspBandwidth,
66 float[] minAvailLspBandwidth,
67 OduResource odu) {
68 this.maxBandwidth = maxBandwidth != null ?
69 Arrays.copyOf(maxBandwidth, maxBandwidth.length) : null;
70 this.availBandwidth = availBandwidth != null ?
71 Arrays.copyOf(availBandwidth, availBandwidth.length) : null;
72 this.maxAvailLspBandwidth = maxAvailLspBandwidth != null ?
73 Arrays.copyOf(maxAvailLspBandwidth,
74 maxAvailLspBandwidth.length) : null;
75 this.minAvailLspBandwidth = minAvailLspBandwidth != null ?
76 Arrays.copyOf(minAvailLspBandwidth,
77 minAvailLspBandwidth.length) : null;
78 this.odu = odu;
79 }
80
81 /**
82 * Creates an instance of link bandwidth with a TE link.
83 *
84 * @param link the TE link
85 */
86 public LinkBandwidth(TeLink link) {
87 this.maxBandwidth = link.maxBandwidth();
88 this.availBandwidth = link.maxAvailLspBandwidth();
89 this.maxAvailLspBandwidth = link.maxAvailLspBandwidth();
90 this.minAvailLspBandwidth = link.minAvailLspBandwidth();
91 this.odu = link.oduResource();
92 }
93
94 /**
95 * Returns the maximum bandwidth at each priority level.
96 *
97 * @return the maxBandwidth
98 */
99 public float[] maxBandwidth() {
100 if (maxBandwidth == null) {
101 return null;
102 }
103 return Arrays.copyOf(maxBandwidth, maxBandwidth.length);
104 }
105
106 /**
107 * Returns the available bandwidth at each priority level.
108 *
109 * @return the available bandwidth
110 */
111 public float[] availBandwidth() {
112 if (availBandwidth == null) {
113 return null;
114 }
115 return Arrays.copyOf(availBandwidth, availBandwidth.length);
116 }
117
118 /**
119 * Returns the maximum available bandwidth for a LSP at each priority
120 * level.
121 *
122 * @return the maximum available bandwidth
123 */
124 public float[] maxAvailLspBandwidth() {
125 if (maxAvailLspBandwidth == null) {
126 return null;
127 }
128 return Arrays.copyOf(maxAvailLspBandwidth, maxAvailLspBandwidth.length);
129 }
130
131 /**
132 * Returns the minimum available bandwidth for a LSP at each priority level.
133 *
134 * @return the minimum available bandwidth
135 */
136 public float[] minAvailLspBandwidth() {
137 if (minAvailLspBandwidth == null) {
138 return null;
139 }
140 return Arrays.copyOf(minAvailLspBandwidth, minAvailLspBandwidth.length);
141 }
142
143 /**
144 * Returns the link ODUk resources.
145 *
146 * @return the ODUk resources
147 */
148 public OduResource oduResource() {
149 return odu;
150 }
151
152 @Override
153 public int hashCode() {
154 return Objects.hashCode(maxBandwidth, availBandwidth, maxAvailLspBandwidth,
155 minAvailLspBandwidth, odu);
156 }
157
158 @Override
159 public boolean equals(Object object) {
160 if (this == object) {
161 return true;
162 }
163 if (object instanceof LinkBandwidth) {
164 LinkBandwidth that = (LinkBandwidth) object;
165 return Objects.equal(maxBandwidth, that.maxBandwidth) &&
166 Objects.equal(availBandwidth, that.availBandwidth) &&
167 Objects.equal(maxAvailLspBandwidth, that.maxAvailLspBandwidth) &&
168 Objects.equal(minAvailLspBandwidth, that.minAvailLspBandwidth) &&
169 Objects.equal(odu, that.odu);
170 }
171 return false;
172 }
173
174 @Override
175 public String toString() {
176 return MoreObjects.toStringHelper(this)
177 .add("maxBandwidth", maxBandwidth)
178 .add("availBandwidth", availBandwidth)
179 .add("maxAvailLspBandwidth", maxAvailLspBandwidth)
180 .add("minAvailLspBandwidth", minAvailLspBandwidth)
181 .add("odu", odu)
182 .toString();
183 }
184}