blob: cd479295147a1b9234d32c1ebe5706dc9107621a [file] [log] [blame]
Yixiao Chen68bfab22016-11-11 11:04:10 -05001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Yixiao Chen68bfab22016-11-11 11:04:10 -05003 *
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.impl;
17
18import java.util.List;
19import java.util.Map;
20
21import org.apache.commons.collections.CollectionUtils;
22import org.apache.commons.collections.MapUtils;
23import org.onosproject.tetopology.management.api.TeTopologyKey;
24import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey;
25import org.onosproject.tetopology.management.api.node.CommonNodeData;
26import org.onosproject.tetopology.management.api.node.ConnectivityMatrix;
27import org.onosproject.tetopology.management.api.node.ConnectivityMatrixKey;
28import org.onosproject.tetopology.management.api.node.NetworkNodeKey;
29import org.onosproject.tetopology.management.api.node.TeNode;
30import org.onosproject.tetopology.management.api.node.TeNodeKey;
31import org.onosproject.tetopology.management.api.node.TtpKey;
32import org.onosproject.tetopology.management.api.node.TunnelTerminationPoint;
33
34import com.google.common.base.MoreObjects;
35import com.google.common.base.Objects;
36import com.google.common.collect.Lists;
37
38/**
39 * The Node representation in store.
40 */
41public class InternalTeNode {
42 private CommonNodeData teData;
43 private TeTopologyKey underlayTopologyKey;
44 private TeNodeKey supportNodeKey;
45 private TeNodeKey sourceTeNodeKey;
46 private List<ConnectivityMatrixKey> connMatrixKeys;
47 private List<TeLinkTpGlobalKey> teLinkTpKeys;
48 private List<TeLinkTpGlobalKey> teTpKeys;
49 private List<TtpKey> ttpKeys;
50 private NetworkNodeKey networkNodeKey;
51 private boolean parentUpdate;
52 private boolean childUpdate;
53
54 // Next available TE link Id egressing from the TE node.
55 private long nextTeLinkId;
56
57 /**
58 * Creates an instance of InternalTeNode.
59 *
60 * @param nodeKey the TE node key
61 * @param node the TE node
62 * @param networkNodeKey the network node key
63 * @param parentUpdate the flag if the data is updated by parent
64 */
65 public InternalTeNode(TeNodeKey nodeKey, TeNode node,
66 NetworkNodeKey networkNodeKey, boolean parentUpdate) {
67 this.networkNodeKey = networkNodeKey;
68 this.parentUpdate = parentUpdate;
69 // Underlay topology
70 this.underlayTopologyKey = node.underlayTeTopologyId();
71 // Supporting topology
72 this.supportNodeKey = node.supportingTeNodeId();
73 // Source topology
74 this.sourceTeNodeKey = node.sourceTeNodeId();
75 // Common data
76 this.teData = new CommonNodeData(node);
77 // Connectivity matrix
78 if (MapUtils.isNotEmpty(node.connectivityMatrices())) {
79 this.connMatrixKeys = Lists.newArrayList();
80 for (Map.Entry<Long, ConnectivityMatrix> entry : node.connectivityMatrices().entrySet()) {
81 this.connMatrixKeys.add(new ConnectivityMatrixKey(nodeKey, entry.getKey()));
82 }
83 }
84 // Tunnel termination point
85 if (MapUtils.isNotEmpty(node.tunnelTerminationPoints())) {
86 this.ttpKeys = Lists.newArrayList();
87 for (Map.Entry<Long, TunnelTerminationPoint> entry : node.tunnelTerminationPoints().entrySet()) {
88 this.ttpKeys.add(new TtpKey(nodeKey, entry.getKey()));
89 }
90 }
91 // teLink Keys
92 if (CollectionUtils.isNotEmpty(node.teLinkIds())) {
93 this.teLinkTpKeys = Lists.newArrayList();
94 for (Long linkId : node.teLinkIds()) {
95 this.teLinkTpKeys.add(new TeLinkTpGlobalKey(nodeKey, linkId));
96 }
97
98 }
99 // teTp Keys
100 if (CollectionUtils.isNotEmpty(node.teTerminationPointIds())) {
101 this.teTpKeys = Lists.newArrayList();
102 for (Long tpId : node.teTerminationPointIds()) {
103 this.teTpKeys.add(new TeLinkTpGlobalKey(nodeKey, tpId));
104 }
105 }
106 }
107
108 /**
109 * Returns the node common data.
110 *
111 * @return the teData
112 */
113 public CommonNodeData teData() {
114 return teData;
115 }
116
117 /**
118 * Sets the node common data.
119 *
120 * @param teData the teData to set
121 */
122 public void setTeData(CommonNodeData teData) {
123 this.teData = teData;
124 }
125
126 /**
127 * Returns the node underlay topology key.
128 *
129 * @return the underlayTopologyKey
130 */
131 public TeTopologyKey underlayTopologyKey() {
132 return underlayTopologyKey;
133 }
134
135 /**
136 * Sets the node underlay topology key.
137 *
138 * @param underlayTopologyKey the underlayTopologyKey to set
139 */
140 public void setUnderlayTopologyKey(TeTopologyKey underlayTopologyKey) {
141 this.underlayTopologyKey = underlayTopologyKey;
142 }
143
144 /**
145 * Returns the supporting node key.
146 *
147 * @return the supportNodeKey
148 */
149 public TeNodeKey supportNodeKey() {
150 return supportNodeKey;
151 }
152
153 /**
154 * Sets the supporting node key.
155 *
156 * @param supportNodeKey the supportNodeKey to set
157 */
158 public void setSupportNodeKey(TeNodeKey supportNodeKey) {
159 this.supportNodeKey = supportNodeKey;
160 }
161
162 /**
163 * Returns the source node key.
164 *
165 * @return the sourceTeNodeKey
166 */
167 public TeNodeKey sourceTeNodeKey() {
168 return sourceTeNodeKey;
169 }
170
171 /**
172 * Sets the source node key.
173 *
174 * @param sourceTeNodeKey the sourceTeNodeKey to set
175 */
176 public void setSourceTeNodeKey(TeNodeKey sourceTeNodeKey) {
177 this.sourceTeNodeKey = sourceTeNodeKey;
178 }
179
180 /**
181 * Returns the node connect matrix keys.
182 *
183 * @return the connMatrixKeys
184 */
185 public List<ConnectivityMatrixKey> connMatrixKeys() {
186 return connMatrixKeys;
187 }
188
189 /**
190 * Sets the node connect matrix keys.
191 *
192 * @param connMatrixKeys the connMatrixKeys to set
193 */
194 public void setConnMatrixKeys(List<ConnectivityMatrixKey> connMatrixKeys) {
195 this.connMatrixKeys = connMatrixKeys;
196 }
197
198 /**
199 * Returns the TE link Ids.
200 *
201 * @return the teLinkTpKeys
202 */
203 public List<TeLinkTpGlobalKey> teLinkTpKeys() {
204 return teLinkTpKeys;
205 }
206
207 /**
208 * Sets the TE link Ids from the node.
209 *
210 * @param teLinkTpKeys the teLinkTpKeys to set
211 */
212 public void setTeLinkTpKeys(List<TeLinkTpGlobalKey> teLinkTpKeys) {
213 this.teLinkTpKeys = teLinkTpKeys;
214 }
215
216 /**
217 * Returns the TE termitation point Ids.
218 *
219 * @return the teTpKeys
220 */
221 public List<TeLinkTpGlobalKey> teTpKeys() {
222 return teTpKeys;
223 }
224
225 /**
226 * Sets the TE termitation point Ids.
227 *
228 * @param teTpKeys the teTpKeys to set
229 */
230 public void setTeTpKeys(List<TeLinkTpGlobalKey> teTpKeys) {
231 this.teTpKeys = teTpKeys;
232 }
233
234 /**
235 * Returns the list of Tunnel Termination Point keys of the node.
236 *
237 * @return the ttpKeys
238 */
239 public List<TtpKey> ttpKeys() {
240 return ttpKeys;
241 }
242
243 /**
244 * Sets the list of Tunnel Termination Point keys.
245 *
246 * @param ttpKeys the ttpKeys to set
247 */
248 public void setTtpKeys(List<TtpKey> ttpKeys) {
249 this.ttpKeys = ttpKeys;
250 }
251
252 /**
253 * Returns the network node Key.
254 *
255 * @return the networkNodeKey
256 */
257 public NetworkNodeKey networkNodeKey() {
258 return networkNodeKey;
259 }
260
261 /**
262 * Returns the next available TE link id from the node.
263 *
264 * @return the nextTeLinkId
265 */
266 public long nextTeLinkId() {
267 return nextTeLinkId;
268 }
269
270 /**
271 * Sets the next available TE link id.
272 *
273 * @param nextTeLinkId the nextTeLinkId to set
274 */
275 public void setNextTeLinkId(long nextTeLinkId) {
276 this.nextTeLinkId = nextTeLinkId;
277 }
278
279 /**
280 * Returns the flag if the data was updated by parent change.
281 *
282 * @return value of parentUpdate
283 */
284 public boolean parentUpdate() {
285 return parentUpdate;
286 }
287
288 /**
289 * Returns the flag if the data was updated by child change.
290 *
291 * @return value of childUpdate
292 */
293 public boolean childUpdate() {
294 return childUpdate;
295 }
296
297 /**
298 * Sets the flag if the data was updated by child change.
299 *
300 * @param childUpdate the childUpdate value to set
301 */
302 public void setChildUpdate(boolean childUpdate) {
303 this.childUpdate = childUpdate;
304 }
305
306 @Override
307 public int hashCode() {
308 return Objects.hashCode(teData, underlayTopologyKey, supportNodeKey,
309 sourceTeNodeKey, connMatrixKeys, teLinkTpKeys, ttpKeys, networkNodeKey);
310 }
311
312 @Override
313 public boolean equals(Object object) {
314 if (this == object) {
315 return true;
316 }
317 if (object instanceof InternalTeNode) {
318 InternalTeNode that = (InternalTeNode) object;
319 return Objects.equal(teData, that.teData)
320 && Objects.equal(underlayTopologyKey,
321 that.underlayTopologyKey)
322 && Objects.equal(supportNodeKey, that.supportNodeKey)
323 && Objects.equal(sourceTeNodeKey, that.sourceTeNodeKey)
324 && Objects.equal(connMatrixKeys, that.connMatrixKeys)
325 && Objects.equal(teLinkTpKeys, that.teLinkTpKeys)
326 && Objects.equal(ttpKeys, that.ttpKeys)
327 && Objects.equal(networkNodeKey, that.networkNodeKey);
328 }
329 return false;
330 }
331
332 @Override
333 public String toString() {
334 return MoreObjects.toStringHelper(this)
335 .add("teData", teData)
336 .add("underlayTopologyKey", underlayTopologyKey)
337 .add("supportNodeKey", supportNodeKey)
338 .add("sourceTeNodeKey", sourceTeNodeKey)
339 .add("connMatrixKeys", connMatrixKeys)
340 .add("teLinkTpKeys", teLinkTpKeys)
341 .add("ttpKeys", ttpKeys)
342 .add("nextTeLinkId", nextTeLinkId)
343 .add("networkNodeKey", networkNodeKey)
344 .add("parentUpdate", parentUpdate)
345 .add("childUpdate", childUpdate)
346 .toString();
347 }
348}