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 | import com.google.common.collect.ImmutableList; |
| 21 | import com.google.common.collect.Lists; |
| 22 | import org.onosproject.tetopology.management.api.EncodingType; |
| 23 | import org.onosproject.tetopology.management.api.SwitchingType; |
| 24 | import org.onosproject.tetopology.management.api.TeStatus; |
| 25 | |
| 26 | import java.util.BitSet; |
| 27 | import java.util.List; |
| 28 | |
| 29 | /** |
| 30 | * Representation of link common attributes. |
| 31 | */ |
| 32 | public class CommonLinkData { |
| 33 | private final TeStatus adminStatus; |
| 34 | private final TeStatus opStatus; |
| 35 | private final BitSet flags; |
| 36 | |
| 37 | private final SwitchingType switchingLayer; |
| 38 | private final EncodingType encodingLayer; |
| 39 | |
| 40 | private final ExternalLink externalLink; |
| 41 | private final UnderlayPath underlayPath; |
| 42 | private final TePathAttributes teAttributes; |
| 43 | private final List<Long> interLayerLocks; |
| 44 | private final LinkBandwidth bandwidth; |
| 45 | private final Long adminGroup; |
| 46 | |
| 47 | /** |
| 48 | * Creates an instance of CommonLinkData. |
| 49 | * |
| 50 | * @param adminStatus the admin status |
| 51 | * @param opStatus the operational Status |
| 52 | * @param flags the flags |
| 53 | * @param switchingLayer the network layer switching type |
| 54 | * @param encodingLayer the network layer encoding type |
| 55 | * @param externalLink the external link specific attributes |
| 56 | * @param underlayPath the link underlay path and supporting tunnel |
| 57 | * @param teAttributes the link path TE attributes |
| 58 | * @param adminGroup the administrative group |
| 59 | * @param interLayerLocks the supported inter-layer locks |
| 60 | * @param bandwidth the link maximum and available bandwidth at |
| 61 | * each priority level |
| 62 | */ |
| 63 | public CommonLinkData(TeStatus adminStatus, |
| 64 | TeStatus opStatus, BitSet flags, SwitchingType switchingLayer, |
| 65 | EncodingType encodingLayer, ExternalLink externalLink, |
| 66 | UnderlayPath underlayPath, TePathAttributes teAttributes, |
| 67 | Long adminGroup, List<Long> interLayerLocks, |
| 68 | LinkBandwidth bandwidth) { |
| 69 | this.adminStatus = adminStatus; |
| 70 | this.opStatus = opStatus; |
| 71 | this.flags = flags; |
| 72 | this.switchingLayer = switchingLayer; |
| 73 | this.encodingLayer = encodingLayer; |
| 74 | this.externalLink = externalLink; |
| 75 | this.underlayPath = underlayPath; |
| 76 | this.teAttributes = teAttributes; |
| 77 | this.adminGroup = adminGroup; |
| 78 | this.interLayerLocks = interLayerLocks != null ? |
| 79 | Lists.newArrayList(interLayerLocks) : null; |
| 80 | this.bandwidth = bandwidth; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Creates an instance of CommonLinkData with a TeLink. |
| 85 | * |
| 86 | * @param link the TE link |
| 87 | */ |
| 88 | public CommonLinkData(TeLink link) { |
| 89 | this.adminStatus = link.adminStatus(); |
| 90 | this.opStatus = link.opStatus(); |
| 91 | this.flags = link.flags(); |
| 92 | this.switchingLayer = link.switchingLayer(); |
| 93 | this.encodingLayer = link.encodingLayer(); |
| 94 | this.externalLink = link.externalLink(); |
| 95 | this.underlayPath = new UnderlayPath(link); |
| 96 | this.teAttributes = new TePathAttributes(link); |
| 97 | this.adminGroup = link.administrativeGroup(); |
| 98 | this.interLayerLocks = link.interLayerLocks() != null ? |
| 99 | Lists.newArrayList(link.interLayerLocks()) : null; |
| 100 | this.bandwidth = new LinkBandwidth(link); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /** |
| 105 | * Returns the admin status. |
| 106 | * |
| 107 | * @return the admin status |
| 108 | */ |
| 109 | public TeStatus adminStatus() { |
| 110 | return adminStatus; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Returns the operational status. |
| 115 | * |
| 116 | * @return the optional status |
| 117 | */ |
| 118 | public TeStatus opStatus() { |
| 119 | return opStatus; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Returns the flags. |
| 124 | * |
| 125 | * @return the flags |
| 126 | */ |
| 127 | public BitSet flags() { |
| 128 | return flags; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Returns the network layer switching type for this link. |
| 133 | * |
| 134 | * @return the switching layer type |
| 135 | */ |
| 136 | public SwitchingType switchingLayer() { |
| 137 | return switchingLayer; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Returns the network layer encoding type for this link. |
| 142 | * |
| 143 | * @return the encoding type |
| 144 | */ |
| 145 | public EncodingType encodingLayer() { |
| 146 | return encodingLayer; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Returns the external link. |
| 151 | * |
| 152 | * @return the external link |
| 153 | */ |
| 154 | public ExternalLink externalLink() { |
| 155 | return externalLink; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Returns the link underlay path and tunnel. |
| 160 | * |
| 161 | * @return the underlay path |
| 162 | */ |
| 163 | public UnderlayPath underlayPath() { |
| 164 | return underlayPath; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Returns the path TE attributes. |
| 169 | * |
| 170 | * @return the path TE Attributes |
| 171 | */ |
| 172 | public TePathAttributes teAttributes() { |
| 173 | return teAttributes; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Returns the link administrative group. |
| 178 | * |
| 179 | * @return the admin group |
| 180 | */ |
| 181 | public Long adminGroup() { |
| 182 | return adminGroup; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Returns the supported inter-layer locks. |
| 187 | * |
| 188 | * @return the inter-layer locks |
| 189 | */ |
| 190 | public List<Long> interLayerLocks() { |
| 191 | if (interLayerLocks == null) { |
| 192 | return null; |
| 193 | } |
| 194 | return ImmutableList.copyOf(interLayerLocks); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Returns the link maximum and available bandwidth at each priority level. |
| 199 | * |
| 200 | * @return the bandwidth |
| 201 | */ |
| 202 | public LinkBandwidth bandwidth() { |
| 203 | return bandwidth; |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public int hashCode() { |
| 208 | return Objects.hashCode(adminStatus, opStatus, flags, switchingLayer, |
| 209 | encodingLayer, externalLink, underlayPath, |
| 210 | teAttributes, interLayerLocks, bandwidth); |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public boolean equals(Object object) { |
| 215 | if (this == object) { |
| 216 | return true; |
| 217 | } |
| 218 | if (object instanceof CommonLinkData) { |
| 219 | CommonLinkData that = (CommonLinkData) object; |
| 220 | return Objects.equal(adminStatus, that.adminStatus) && |
| 221 | Objects.equal(opStatus, that.opStatus) && |
| 222 | Objects.equal(flags, that.flags) && |
| 223 | Objects.equal(switchingLayer, that.switchingLayer) && |
| 224 | Objects.equal(encodingLayer, that.encodingLayer) && |
| 225 | Objects.equal(externalLink, that.externalLink) && |
| 226 | Objects.equal(underlayPath, that.underlayPath) && |
| 227 | Objects.equal(teAttributes, that.teAttributes) && |
| 228 | Objects.equal(interLayerLocks, that.interLayerLocks) && |
| 229 | Objects.equal(bandwidth, that.bandwidth); |
| 230 | } |
| 231 | return false; |
| 232 | } |
| 233 | |
| 234 | @Override |
| 235 | public String toString() { |
| 236 | return MoreObjects.toStringHelper(this) |
| 237 | .add("adminStatus", adminStatus) |
| 238 | .add("opStatus", opStatus) |
| 239 | .add("flags", flags) |
| 240 | .add("switchingLayer", switchingLayer) |
| 241 | .add("encodingLayer", encodingLayer) |
| 242 | .add("externalLink", externalLink) |
| 243 | .add("underlayPath", underlayPath) |
| 244 | .add("teAttributes", teAttributes) |
| 245 | .add("interLayerLocks", interLayerLocks) |
| 246 | .add("bandwidth", bandwidth) |
| 247 | .toString(); |
| 248 | } |
| 249 | |
| 250 | } |