Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016 Open Networking Foundation |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 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 | package org.onosproject.tetopology.management.api.link; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.base.Objects; |
| 20 | |
| 21 | import java.util.Arrays; |
| 22 | |
| 23 | /** |
| 24 | * Representation the TE link bandwidths. |
| 25 | */ |
| 26 | public 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() { |
kdarapu | 95eb7d3 | 2017-01-04 14:41:11 +0530 | [diff] [blame] | 154 | return Objects.hashCode(Arrays.hashCode(maxBandwidth), |
| 155 | Arrays.hashCode(availBandwidth), |
| 156 | Arrays.hashCode(maxAvailLspBandwidth), |
| 157 | Arrays.hashCode(minAvailLspBandwidth), |
| 158 | odu); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public boolean equals(Object object) { |
| 163 | if (this == object) { |
| 164 | return true; |
| 165 | } |
| 166 | if (object instanceof LinkBandwidth) { |
| 167 | LinkBandwidth that = (LinkBandwidth) object; |
kdarapu | 95eb7d3 | 2017-01-04 14:41:11 +0530 | [diff] [blame] | 168 | return Arrays.equals(maxBandwidth, that.maxBandwidth) && |
| 169 | Arrays.equals(availBandwidth, that.availBandwidth) && |
| 170 | Arrays.equals(maxAvailLspBandwidth, that.maxAvailLspBandwidth) && |
| 171 | Arrays.equals(minAvailLspBandwidth, that.minAvailLspBandwidth) && |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 172 | Objects.equal(odu, that.odu); |
| 173 | } |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | @Override |
| 178 | public String toString() { |
| 179 | return MoreObjects.toStringHelper(this) |
| 180 | .add("maxBandwidth", maxBandwidth) |
| 181 | .add("availBandwidth", availBandwidth) |
| 182 | .add("maxAvailLspBandwidth", maxAvailLspBandwidth) |
| 183 | .add("minAvailLspBandwidth", minAvailLspBandwidth) |
| 184 | .add("odu", odu) |
| 185 | .toString(); |
| 186 | } |
| 187 | } |