blob: 62c65b5406375a0f6450d248f9d2c91f094b3c9b [file] [log] [blame]
Aihua Guo1ce2dd12016-08-12 23:37:44 -04001/*
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.node;
17
18import java.util.List;
19
20import org.onosproject.tetopology.management.api.KeyId;
21
22import com.google.common.base.MoreObjects;
23import com.google.common.base.Objects;
24
25/**
26 * NetworkNode implementation.
27 * <p>
28 * The Set/Get methods below are defined to accept and pass references because
29 * the object class is treated as a "composite" object class that holds
30 * references to various member objects and their relationships, forming a
31 * data tree. Internal routines of the TE topology manager may use the
32 * following example methods to construct and manipulate any piece of data in
33 * the data tree:
34 *<pre>
35 * newNode.getTe().setAdminStatus(), or
36 * newNode.getSupportingNodeIds().add(nodeId), etc.
37 *</pre>
38 * Same for constructors where, for example, a child list may be constructed
39 * first and passed in by reference to its parent object constructor.
40 */
41public class DefaultNetworkNode implements NetworkNode {
42 private final KeyId id;
43 private List<NetworkNodeKey> supportingNodeIds;
44 private TeNode te;
45 private List<TerminationPoint> tps;
46
47 /**
48 * Creates an instance of DefaultNetworkNode using Id.
49 *
50 * @param id network node identifier
51 */
52 public DefaultNetworkNode(KeyId id) {
53 this.id = id;
54 }
55
56 /**
57 * Creates an instance of DefaultNetworkNode.
58 *
59 * @param id network node identifier
60 * @param nodeIds support node identifiers
61 * @param te te parameter of the node
62 */
63 public DefaultNetworkNode(KeyId id, List<NetworkNodeKey> nodeIds, TeNode te) {
64 this.id = id;
65 this.supportingNodeIds = nodeIds;
66 this.te = te;
67 }
68
69 /**
70 * Sets the list of supporting node ids.
71 *
72 * @param ids the supporting node ids to set
73 */
74 public void setSupportingNodeIds(List<NetworkNodeKey> ids) {
75 this.supportingNodeIds = ids;
76 }
77
78 /**
79 * Sets the te attribute.
80 *
81 * @param te the te to set
82 */
83 public void setTe(TeNode te) {
84 this.te = te;
85 }
86
87 /**
88 * Sets the TerminationPoints.
89 *
90 * @param tps the tps to set
91 */
92 public void setTerminationPoints(List<TerminationPoint> tps) {
93 this.tps = tps;
94 }
95
96 /**
97 * Returns the node identifier.
98 *
99 * @return node identifier
100 */
101 @Override
102 public KeyId nodeId() {
103 return id;
104 }
105
106 /**
107 * Returns the supportingNodeIds.
108 *
109 * @return list of supporting node identifiers for this node
110 */
111 @Override
112 public List<NetworkNodeKey> getSupportingNodeIds() {
113 return supportingNodeIds;
114 }
115
116 /**
117 * Returns the te attribute value.
118 *
119 * @return TE attributes of this node
120 */
121 @Override
122 public TeNode getTe() {
123 return te;
124 }
125
126 /**
127 * Returns the list of termination points.
128 *
129 * @return a list of termination points associated with this node
130 */
131 @Override
132 public List<TerminationPoint> getTerminationPoints() {
133 return tps;
134 }
135
136 /**
137 * Returns the termination point.
138 *
139 * @return the termination point
140 */
141 @Override
142 public TerminationPoint getTerminationPoint(KeyId tpId) {
143
144 for (TerminationPoint tp : tps) {
145 if (tp.id().equals(tpId)) {
146 return tp;
147 }
148 }
149
150 return null;
151 }
152
153 @Override
154 public int hashCode() {
155 return Objects.hashCode(id, supportingNodeIds, te, tps);
156 }
157
158 @Override
159 public boolean equals(Object object) {
160 if (this == object) {
161 return true;
162 }
163 if (object instanceof DefaultNetworkNode) {
164 DefaultNetworkNode that = (DefaultNetworkNode) object;
165 return Objects.equal(this.id, that.id) &&
166 Objects.equal(this.supportingNodeIds, that.supportingNodeIds) &&
167 Objects.equal(this.te, that.te) &&
168 Objects.equal(this.tps, that.tps);
169 }
170 return false;
171 }
172
173 @Override
174 public String toString() {
175 return MoreObjects.toStringHelper(this)
176 .add("id", id)
177 .add("supportingNodeIds", supportingNodeIds)
178 .add("te", te)
179 .add("tps", tps)
180 .toString();
181 }
182
183}