blob: 1219cf6cac3195d3940143cd36a97dbcf4a06345 [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.node;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.base.Objects;
20import com.google.common.collect.ImmutableList;
21import com.google.common.collect.ImmutableMap;
22import com.google.common.collect.Lists;
23import com.google.common.collect.Maps;
24import org.onosproject.tetopology.management.api.KeyId;
25
26import java.util.List;
27import java.util.Map;
28
29/**
30 * Default network node implementation.
31 */
32public class DefaultNetworkNode implements NetworkNode {
33 private final KeyId id;
34 private final List<NetworkNodeKey> supportingNodeIds;
35 private final TeNode teNode;
36 private final Map<KeyId, TerminationPoint> tps;
37
38
39 /**
40 * Creates a network node instance.
41 *
42 * @param id network node identifier
43 * @param nodeIds support node identifiers
44 * @param teNode te parameter of the node
45 * @param tps the tps to set
46 */
47 public DefaultNetworkNode(KeyId id,
48 List<NetworkNodeKey> nodeIds,
49 TeNode teNode,
50 Map<KeyId, TerminationPoint> tps) {
51 this.id = id;
52 this.supportingNodeIds = nodeIds != null ?
53 Lists.newArrayList(nodeIds) : null;
54 this.teNode = teNode;
55 this.tps = tps != null ? Maps.newHashMap(tps) : null;
56 }
57
58 /**
59 * Returns the node identifier.
60 *
61 * @return node identifier
62 */
63 @Override
64 public KeyId nodeId() {
65 return id;
66 }
67
68 /**
69 * Returns the list of supporting node identifiers for this node.
70 *
71 * @return list of supporting node identifiers
72 */
73 @Override
74 public List<NetworkNodeKey> supportingNodeIds() {
75 if (supportingNodeIds == null) {
76 return null;
77 }
78 return ImmutableList.copyOf(supportingNodeIds);
79 }
80
81 /**
82 * Returns the node TE attributes.
83 *
84 * @return TE attributes of this node
85 */
86 @Override
87 public TeNode teNode() {
88 return teNode;
89 }
90
91 /**
92 * Returns the list of termination points associated with this node.
93 *
94 * @return a list of termination points
95 */
96 @Override
97 public Map<KeyId, TerminationPoint> terminationPoints() {
98 if (tps == null) {
99 return null;
100 }
101 return ImmutableMap.copyOf(tps);
102 }
103
104 /**
105 * Returns the termination point.
106 *
107 * @return the termination point
108 */
109 @Override
110 public TerminationPoint terminationPoint(KeyId tpId) {
111 return tps.get(tpId);
112 }
113
114 @Override
115 public int hashCode() {
116 return Objects.hashCode(id, supportingNodeIds, teNode, tps);
117 }
118
119 @Override
120 public boolean equals(Object object) {
121 if (this == object) {
122 return true;
123 }
124 if (object instanceof DefaultNetworkNode) {
125 DefaultNetworkNode that = (DefaultNetworkNode) object;
126 return Objects.equal(id, that.id) &&
127 Objects.equal(supportingNodeIds, that.supportingNodeIds) &&
128 Objects.equal(teNode, that.teNode) &&
129 Objects.equal(tps, that.tps);
130 }
131 return false;
132 }
133
134 @Override
135 public String toString() {
136 return MoreObjects.toStringHelper(this)
137 .add("id", id)
138 .add("supportingNodeIds", supportingNodeIds)
139 .add("teNode", teNode)
140 .add("tps", tps)
141 .toString();
142 }
143
144}