blob: 72e713f22fa50e63b82e1551f1aaa62367354dda [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;
20import org.onosproject.tetopology.management.api.EncodingType;
21import org.onosproject.tetopology.management.api.SwitchingType;
22import org.onosproject.tetopology.management.api.TeConstants;
23import org.onosproject.tetopology.management.api.TeStatus;
24import org.onosproject.tetopology.management.api.TeTopologyKey;
25
26import java.util.BitSet;
27import java.util.List;
28
29/**
30 * The default implementation of TE link.
31 */
32public class DefaultTeLink implements TeLink {
33 private final TeLinkTpKey teLinkKey;
34 private final TeLinkTpKey peerTeLinkKey;
35 private final TeTopologyKey underlayTopologyId;
36 private final TeLinkTpGlobalKey supportTeLinkId;
37 private final TeLinkTpGlobalKey sourceTeLinkId;
38 private final CommonLinkData teData;
39
40 /**
41 * Creates an instance of a TE link.
42 *
43 * @param teLinkKey the TE link key
44 * @param peerTeLinkKey the bi-directional peer link key
45 * @param underlayTopologyId the link underlay TE topology id
46 * @param supportTeLinkId the supporting TE link id
47 * @param sourceTeLinkId the source TE link id
48 * @param teData the link common te data
49 */
50 public DefaultTeLink(TeLinkTpKey teLinkKey,
51 TeLinkTpKey peerTeLinkKey,
52 TeTopologyKey underlayTopologyId,
53 TeLinkTpGlobalKey supportTeLinkId,
54 TeLinkTpGlobalKey sourceTeLinkId,
55 CommonLinkData teData) {
56 this.teLinkKey = teLinkKey;
57 this.peerTeLinkKey = peerTeLinkKey;
58 this.underlayTopologyId = underlayTopologyId;
59 this.supportTeLinkId = supportTeLinkId;
60 this.sourceTeLinkId = sourceTeLinkId;
61 this.teData = teData;
62 }
63
64 @Override
65 public TeLinkTpKey teLinkKey() {
66 return teLinkKey;
67 }
68
69 @Override
70 public TeLinkTpKey peerTeLinkKey() {
71 return peerTeLinkKey;
72 }
73
74 @Override
75 public BitSet flags() {
76 if (teData == null) {
77 return null;
78 }
79 return teData.flags();
80 }
81
82 @Override
83 public SwitchingType switchingLayer() {
84 if (teData == null) {
85 return null;
86 }
87 return teData.switchingLayer();
88 }
89
90 @Override
91 public EncodingType encodingLayer() {
92 if (teData == null) {
93 return null;
94 }
95 return teData.encodingLayer();
96 }
97
98 @Override
99 public ExternalLink externalLink() {
100 if (teData == null) {
101 return null;
102 }
103 return teData.externalLink();
104 }
105
106 @Override
107 public TeTopologyKey underlayTeTopologyId() {
108 return underlayTopologyId;
109 }
110
111 @Override
112 public UnderlayPrimaryPath primaryPath() {
113 if (teData == null || teData.underlayPath() == null) {
114 return null;
115 }
116 return teData.underlayPath().primaryPath();
117 }
118
119 @Override
120 public List<UnderlayBackupPath> backupPaths() {
121 if (teData == null || teData.underlayPath() == null) {
122 return null;
123 }
124 return teData.underlayPath().backupPaths();
125 }
126
127 @Override
128 public TunnelProtectionType tunnelProtectionType() {
129 if (teData == null || teData.underlayPath() == null) {
130 return null;
131 }
132 return teData.underlayPath().tunnelProtectionType();
133 }
134
135 @Override
136 public long sourceTtpId() {
137 if (teData == null || teData.underlayPath() == null) {
138 return TeConstants.NIL_LONG_VALUE;
139 }
140 return teData.underlayPath().srcTtpId();
141 }
142
143 @Override
144 public long destinationTtpId() {
145 if (teData == null || teData.underlayPath() == null) {
146 return TeConstants.NIL_LONG_VALUE;
147 }
148 return teData.underlayPath().dstTtpId();
149 }
150
151 @Override
152 public TeTunnelId teTunnelId() {
153 if (teData == null || teData.underlayPath() == null) {
154 return null;
155 }
156 return teData.underlayPath().teTunnelId();
157 }
158
159 @Override
160 public TeLinkTpGlobalKey supportingTeLinkId() {
161 return supportTeLinkId;
162 }
163
164 @Override
165 public TeLinkTpGlobalKey sourceTeLinkId() {
166 return sourceTeLinkId;
167 }
168
169 @Override
170 public long cost() {
171 if (teData == null || teData.teAttributes() == null) {
172 return TeConstants.NIL_LONG_VALUE;
173 }
174 return teData.teAttributes().cost();
175 }
176
177 @Override
178 public long delay() {
179 if (teData == null || teData.teAttributes() == null) {
180 return TeConstants.NIL_LONG_VALUE;
181 }
182 return teData.teAttributes().delay();
183 }
184
185 @Override
186 public List<Long> srlgs() {
187 if (teData == null || teData.teAttributes() == null) {
188 return null;
189 }
190 return teData.teAttributes().srlgs();
191 }
192
193 @Override
194 public Long administrativeGroup() {
195 if (teData == null) {
196 return null;
197 }
198 return teData.adminGroup();
199 }
200
201 @Override
202 public List<Long> interLayerLocks() {
203 if (teData == null) {
204 return null;
205 }
206 return teData.interLayerLocks();
207 }
208
209 @Override
210 public float[] maxBandwidth() {
211 if (teData == null || teData.bandwidth() == null) {
212 return null;
213 }
214 return teData.bandwidth().maxBandwidth();
215 }
216
217 @Override
218 public float[] availBandwidth() {
219 if (teData == null || teData.bandwidth() == null) {
220 return null;
221 }
222 return teData.bandwidth().availBandwidth();
223 }
224
225 @Override
226 public float[] maxAvailLspBandwidth() {
227 if (teData == null || teData.bandwidth() == null) {
228 return null;
229 }
230 return teData.bandwidth().maxAvailLspBandwidth();
231 }
232
233 @Override
234 public float[] minAvailLspBandwidth() {
235 if (teData == null || teData.bandwidth() == null) {
236 return null;
237 }
238 return teData.bandwidth().minAvailLspBandwidth();
239 }
240
241 @Override
242 public OduResource oduResource() {
243 if (teData == null || teData.bandwidth() == null) {
244 return null;
245 }
246 return teData.bandwidth().oduResource();
247 }
248
249 @Override
250 public TeStatus adminStatus() {
251 if (teData == null) {
252 return null;
253 }
254 return teData.adminStatus();
255 }
256
257 @Override
258 public TeStatus opStatus() {
259 if (teData == null) {
260 return null;
261 }
262 return teData.opStatus();
263 }
264
265 @Override
266 public int hashCode() {
267 return Objects.hashCode(teLinkKey, peerTeLinkKey, underlayTopologyId,
268 supportTeLinkId, sourceTeLinkId, teData);
269 }
270
271 @Override
272 public boolean equals(Object object) {
273 if (this == object) {
274 return true;
275 }
276 if (object instanceof DefaultTeLink) {
277 DefaultTeLink that = (DefaultTeLink) object;
278 return Objects.equal(teLinkKey, that.teLinkKey) &&
279 Objects.equal(peerTeLinkKey, that.peerTeLinkKey) &&
280 Objects.equal(underlayTopologyId, that.underlayTopologyId) &&
281 Objects.equal(supportTeLinkId, that.supportTeLinkId) &&
282 Objects.equal(sourceTeLinkId, that.sourceTeLinkId) &&
283 Objects.equal(teData, that.teData);
284 }
285 return false;
286 }
287
288 @Override
289 public String toString() {
290 return MoreObjects.toStringHelper(this)
291 .add("teLinkKey", teLinkKey)
292 .add("peerTeLinkKey", peerTeLinkKey)
293 .add("underlayTopologyId", underlayTopologyId)
294 .add("supportTeLinkId", supportTeLinkId)
295 .add("sourceTeLinkId", sourceTeLinkId)
296 .add("teData", teData)
297 .toString();
298 }
299
300
301}