Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [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.iptopology.api; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | |
| 20 | import java.util.Iterator; |
| 21 | import java.util.List; |
| 22 | import java.util.Objects; |
| 23 | |
| 24 | import org.onlab.packet.Ip4Address; |
| 25 | import org.onlab.packet.Ip6Address; |
| 26 | import org.onlab.util.Bandwidth; |
| 27 | |
| 28 | /** |
| 29 | * Represents Link Traffic engineering parameters. |
| 30 | */ |
| 31 | public class LinkTed { |
| 32 | private final Bandwidth maximumLink; |
| 33 | private final Bandwidth maxReserved; |
| 34 | private final List<Bandwidth> maxUnResBandwidth; |
| 35 | private final Metric teMetric; |
| 36 | private final Metric igpMetric; |
| 37 | private final List<Ip4Address> ipv4LocRouterId; |
| 38 | private final List<Ip6Address> ipv6LocRouterId; |
| 39 | private final List<Ip4Address> ipv4RemRouterId; |
| 40 | private final List<Ip6Address> ipv6RemRouterId; |
| 41 | private final Color color; |
| 42 | private final Signalling signalType; |
| 43 | private final List<Srlg> srlgGroup; |
| 44 | private final ProtectionType protectType; |
| 45 | |
| 46 | /** |
| 47 | * Constructor to initialize its parameter. |
| 48 | * |
| 49 | * @param maximumLink maximum bandwidth can be used |
| 50 | * @param maxReserved max bandwidth that can be reserved |
| 51 | * @param maxUnResBandwidth amount of bandwidth reservable |
| 52 | * @param teMetric Traffic engineering metric |
| 53 | * @param igpMetric IGP metric |
| 54 | * @param color information on administrative group assigned to the interface |
| 55 | * @param signalType MPLS signaling protocols |
| 56 | * @param srlgGroup Shared Risk Link Group information |
| 57 | * @param protectType protection capabilities of the link |
| 58 | * @param ipv4LocRouterId IPv4 router-Id of local node |
| 59 | * @param ipv6LocRouterId IPv6 router-Id of local node |
| 60 | * @param ipv4RemRouterId IPv4 router-Id of remote node |
| 61 | * @param ipv6RemRouterId IPv6 router-Id of remote node |
| 62 | */ |
| 63 | public LinkTed(Bandwidth maximumLink, Bandwidth maxReserved, List<Bandwidth> maxUnResBandwidth, |
| 64 | Metric teMetric, Metric igpMetric, Color color, Signalling signalType, List<Srlg> srlgGroup, |
| 65 | ProtectionType protectType, List<Ip4Address> ipv4LocRouterId, List<Ip6Address> ipv6LocRouterId, |
| 66 | List<Ip4Address> ipv4RemRouterId, List<Ip6Address> ipv6RemRouterId) { |
| 67 | this.maximumLink = maximumLink; |
| 68 | this.maxReserved = maxReserved; |
| 69 | this.maxUnResBandwidth = maxUnResBandwidth; |
| 70 | this.teMetric = teMetric; |
| 71 | this.igpMetric = igpMetric; |
| 72 | this.color = color; |
| 73 | this.signalType = signalType; |
| 74 | this.srlgGroup = srlgGroup; |
| 75 | this.protectType = protectType; |
| 76 | this.ipv4LocRouterId = ipv4LocRouterId; |
| 77 | this.ipv6LocRouterId = ipv6LocRouterId; |
| 78 | this.ipv4RemRouterId = ipv4RemRouterId; |
| 79 | this.ipv6RemRouterId = ipv6RemRouterId; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Provides maximum bandwidth can be used on the link. |
| 84 | * |
| 85 | * @return maximum bandwidth |
| 86 | */ |
| 87 | public Bandwidth maximumLink() { |
| 88 | return maximumLink; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Amount of bandwidth reservable on the link. |
| 93 | * |
| 94 | * @return unreserved bandwidth |
| 95 | */ |
| 96 | public List<Bandwidth> maxUnResBandwidth() { |
| 97 | return maxUnResBandwidth; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Provides max bandwidth that can be reserved on the link. |
| 102 | * |
| 103 | * @return max bandwidth reserved |
| 104 | */ |
| 105 | public Bandwidth maxReserved() { |
| 106 | return maxReserved; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Provides Traffic engineering metric for the link. |
| 111 | * |
| 112 | * @return Traffic engineering metric |
| 113 | */ |
| 114 | public Metric teMetric() { |
| 115 | return teMetric; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Provides IGP metric for the link. |
| 120 | * |
| 121 | * @return IGP metric |
| 122 | */ |
| 123 | public Metric igpMetric() { |
| 124 | return igpMetric; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Provides protection capabilities of the link. |
| 129 | * |
| 130 | * @return link protection type |
| 131 | */ |
| 132 | public ProtectionType protectType() { |
| 133 | return protectType; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Provides Shared Risk Link Group information. |
| 138 | * |
| 139 | * @return Shared Risk Link Group value |
| 140 | */ |
| 141 | public List<Srlg> srlgGroup() { |
| 142 | return srlgGroup; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Provides which MPLS signaling protocols are enabled. |
| 147 | * |
| 148 | * @return signal type |
| 149 | */ |
| 150 | public Signalling signalType() { |
| 151 | return signalType; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Provides information on administrative group assigned to the interface. |
| 156 | * |
| 157 | * @return 4-octect bit mask assigned by network administrator |
| 158 | */ |
| 159 | public Color color() { |
| 160 | return color; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Provides IPv4 router-Id of local node. |
| 165 | * |
| 166 | * @return IPv4 router-Id of local node |
| 167 | */ |
| 168 | public List<Ip4Address> ipv4LocRouterId() { |
| 169 | return ipv4LocRouterId; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Provides IPv6 router-Id of local node. |
| 174 | * |
| 175 | * @return IPv6 router-Id of local node |
| 176 | */ |
| 177 | public List<Ip6Address> ipv6LocRouterId() { |
| 178 | return ipv6LocRouterId; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Provides IPv4 router-Id of remote node. |
| 183 | * |
| 184 | * @return IPv4 router-Id of remote node |
| 185 | */ |
| 186 | public List<Ip4Address> ipv4RemRouterId() { |
| 187 | return ipv4RemRouterId; |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Provides IPv6 router-Id of remote node. |
| 192 | * |
| 193 | * @return IPv6 router-Id of remote node |
| 194 | */ |
| 195 | public List<Ip6Address> ipv6RemRouterId() { |
| 196 | return ipv6RemRouterId; |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public int hashCode() { |
| 201 | return Objects.hash(maximumLink, maxReserved, maxUnResBandwidth, teMetric, igpMetric, |
| 202 | ipv4LocRouterId, ipv6LocRouterId, ipv4RemRouterId, ipv6RemRouterId, |
| 203 | color, signalType, srlgGroup, protectType); |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public boolean equals(Object obj) { |
| 208 | if (this == obj) { |
| 209 | return true; |
| 210 | } |
| 211 | |
| 212 | if (obj instanceof LinkTed) { |
| 213 | int countCommonBandwidth = 0; |
| 214 | int countOtherCommonBandwidth = 0; |
| 215 | int countOther4LocRouterId = 0; |
| 216 | int countCommon4LocRouterId = 0; |
| 217 | int countOther6RemRouterId = 0; |
| 218 | int countCommon6RemRouterId = 0; |
| 219 | int countOther4RemRouterId = 0; |
| 220 | int countCommon4RemRouterId = 0; |
| 221 | int countCommon6LocRouterId = 0; |
| 222 | int countOther6LocRouterId = 0; |
| 223 | int countCommonSrlg = 0; |
| 224 | int countOtherSrlg = 0; |
| 225 | boolean isCommonBandwidth = true; |
| 226 | boolean isCommonIp4Loc = true; |
| 227 | boolean isCommonIp4Rem = true; |
| 228 | boolean isCommonIp6Loc = true; |
| 229 | boolean isCommonIp6Rem = true; |
| 230 | boolean isCommonSrlg = true; |
| 231 | LinkTed other = (LinkTed) obj; |
| 232 | Iterator<Bandwidth> objListIterator = other.maxUnResBandwidth.iterator(); |
| 233 | countOtherCommonBandwidth = other.maxUnResBandwidth.size(); |
| 234 | countCommonBandwidth = maxUnResBandwidth.size(); |
| 235 | |
| 236 | Iterator<Ip4Address> ipv4local = other.ipv4LocRouterId.iterator(); |
| 237 | countOther4LocRouterId = other.ipv4LocRouterId.size(); |
| 238 | countCommon4LocRouterId = ipv4LocRouterId.size(); |
| 239 | |
| 240 | Iterator<Ip4Address> ipv4remote = other.ipv4RemRouterId.iterator(); |
| 241 | countOther4RemRouterId = other.ipv4RemRouterId.size(); |
| 242 | countCommon4RemRouterId = ipv4RemRouterId.size(); |
| 243 | |
| 244 | Iterator<Ip6Address> ipv6local = other.ipv6LocRouterId.iterator(); |
| 245 | countOther6LocRouterId = other.ipv6LocRouterId.size(); |
| 246 | countCommon6LocRouterId = ipv6LocRouterId.size(); |
| 247 | |
| 248 | Iterator<Ip6Address> ipv6remote = other.ipv6RemRouterId.iterator(); |
| 249 | countOther6RemRouterId = other.ipv6RemRouterId.size(); |
| 250 | countCommon6RemRouterId = ipv6RemRouterId.size(); |
| 251 | |
| 252 | Iterator<Srlg> srlg = other.srlgGroup.iterator(); |
| 253 | countOtherSrlg = other.srlgGroup.size(); |
| 254 | countCommonSrlg = srlgGroup.size(); |
| 255 | |
| 256 | if (countOtherCommonBandwidth != countCommonBandwidth |
| 257 | || countOther4LocRouterId != countCommon4LocRouterId |
| 258 | || countOther4RemRouterId != countCommon4RemRouterId |
| 259 | || countOther6LocRouterId != countCommon6LocRouterId |
| 260 | || countOther6RemRouterId != countCommon6RemRouterId |
| 261 | || countOtherSrlg != countCommonSrlg) { |
| 262 | return false; |
| 263 | } else { |
| 264 | while (objListIterator.hasNext() && isCommonBandwidth) { |
| 265 | Bandwidth subTlv = objListIterator.next(); |
| 266 | if (maxUnResBandwidth.contains(subTlv) && other.maxUnResBandwidth.contains(subTlv)) { |
| 267 | isCommonBandwidth = Objects.equals(maxUnResBandwidth.get(maxUnResBandwidth.indexOf(subTlv)), |
| 268 | other.maxUnResBandwidth.get(other.maxUnResBandwidth.indexOf(subTlv))); |
| 269 | } else { |
| 270 | isCommonBandwidth = false; |
| 271 | } |
| 272 | } |
| 273 | while (ipv4local.hasNext() && isCommonIp4Loc) { |
| 274 | Ip4Address subTlv = ipv4local.next(); |
| 275 | if (ipv4LocRouterId.contains(subTlv) && other.ipv4LocRouterId.contains(subTlv)) { |
| 276 | isCommonIp4Loc = Objects.equals(ipv4LocRouterId.get(ipv4LocRouterId.indexOf(subTlv)), |
| 277 | other.ipv4LocRouterId.get(other.ipv4LocRouterId.indexOf(subTlv))); |
| 278 | } else { |
| 279 | isCommonIp4Loc = false; |
| 280 | } |
| 281 | } |
| 282 | while (ipv4remote.hasNext() && isCommonIp4Rem) { |
| 283 | Ip4Address subTlv = ipv4remote.next(); |
| 284 | if (ipv4RemRouterId.contains(subTlv) && other.ipv4RemRouterId.contains(subTlv)) { |
| 285 | isCommonIp4Rem = Objects.equals(ipv4RemRouterId.get(ipv4RemRouterId.indexOf(subTlv)), |
| 286 | other.ipv4RemRouterId.get(other.ipv4RemRouterId.indexOf(subTlv))); |
| 287 | } else { |
| 288 | isCommonIp4Rem = false; |
| 289 | } |
| 290 | } |
| 291 | while (ipv6remote.hasNext() && isCommonIp6Rem) { |
| 292 | Ip6Address subTlv = ipv6remote.next(); |
| 293 | if (ipv6RemRouterId.contains(subTlv) && other.ipv6RemRouterId.contains(subTlv)) { |
| 294 | isCommonIp6Rem = Objects.equals(ipv6RemRouterId.get(ipv6RemRouterId.indexOf(subTlv)), |
| 295 | other.ipv6RemRouterId.get(other.ipv6RemRouterId.indexOf(subTlv))); |
| 296 | } else { |
| 297 | isCommonIp6Rem = false; |
| 298 | } |
| 299 | } |
| 300 | while (ipv6local.hasNext() && isCommonIp6Loc) { |
| 301 | Ip6Address subTlv = ipv6local.next(); |
| 302 | if (ipv6LocRouterId.contains(subTlv) && other.ipv6LocRouterId.contains(subTlv)) { |
| 303 | isCommonIp6Loc = Objects.equals(ipv6LocRouterId.get(ipv6LocRouterId.indexOf(subTlv)), |
| 304 | other.ipv6LocRouterId.get(other.ipv6LocRouterId.indexOf(subTlv))); |
| 305 | } else { |
| 306 | isCommonIp6Loc = false; |
| 307 | } |
| 308 | } |
| 309 | while (srlg.hasNext() && isCommonIp6Loc) { |
| 310 | Srlg subTlv = srlg.next(); |
| 311 | if (srlgGroup.contains(subTlv) && other.srlgGroup.contains(subTlv)) { |
| 312 | isCommonSrlg = Objects.equals(srlgGroup.get(srlgGroup.indexOf(subTlv)), |
| 313 | other.srlgGroup.get(other.srlgGroup.indexOf(subTlv))); |
| 314 | } else { |
| 315 | isCommonSrlg = false; |
| 316 | } |
| 317 | } |
| 318 | return isCommonBandwidth && isCommonIp4Loc && isCommonIp4Rem && isCommonIp6Rem && isCommonIp6Loc |
| 319 | && isCommonSrlg |
| 320 | && Objects.equals(igpMetric, other.igpMetric) |
| 321 | && Objects.equals(teMetric, other.teMetric) |
| 322 | && Objects.equals(maximumLink, other.maximumLink) |
| 323 | && Objects.equals(protectType, other.protectType) |
| 324 | && Objects.equals(color, other.color) |
| 325 | && Objects.equals(signalType, other.signalType); |
| 326 | } |
| 327 | } |
| 328 | return false; |
| 329 | } |
| 330 | |
| 331 | @Override |
| 332 | public String toString() { |
| 333 | return toStringHelper(this) |
| 334 | .add("igpMetric", igpMetric) |
| 335 | .add("teMetric", teMetric) |
| 336 | .add("maximumLink", maximumLink) |
| 337 | .add("maxReserved", maxReserved) |
| 338 | .add("maxUnResBandwidth", maxUnResBandwidth) |
| 339 | .add("ipv4LocRouterId", ipv4LocRouterId) |
| 340 | .add("ipv4RemRouterId", ipv4RemRouterId) |
| 341 | .add("ipv6LocRouterId", ipv6LocRouterId) |
| 342 | .add("ipv6RemRouterId", ipv6RemRouterId) |
| 343 | .add("protectType", protectType) |
| 344 | .add("color", color) |
| 345 | .add("srlgGroup", srlgGroup) |
| 346 | .add("signalType", signalType) |
| 347 | .toString(); |
| 348 | } |
| 349 | } |