blob: 90333aceff5f71f87227c5b556964e6120717353 [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.TeStatus;
25import org.onosproject.tetopology.management.api.TeTopologyKey;
26
27import java.util.BitSet;
28import java.util.Collections;
29import java.util.List;
30import java.util.Map;
31
32/**
33 * The default implementation of TE Node.
34 */
35public class DefaultTeNode implements TeNode {
36 private final long teNodeId;
37 private final TeTopologyKey underlayTopologyId;
38 private final TeNodeKey supportTeNodeId;
39 private final TeNodeKey sourceTeNodeId;
40 private final CommonNodeData teData;
41 private final Map<Long, ConnectivityMatrix> connMatrices;
42 private final List<Long> teLinkIds;
43 private final Map<Long, TunnelTerminationPoint> ttps;
44 private final List<Long> teTpIds;
45
46 /**
47 * Creates a TE node instance.
48 *
49 * @param teNodeId TE node identifier
50 * @param underlayTopologyIdId the node underlay TE topology id
51 * @param supportTeNodeId the supporting TE node id
52 * @param sourceTeNodeId the source TE node id
53 * @param teData the node common te data
54 * @param connMatrices the connectivity matrix table
55 * @param teLinkIds the list of TE link ids originating from the node
56 * @param ttps the list of tunnel termination points
57 * @param teTpIds the currently known termination point ids
58 */
59 public DefaultTeNode(long teNodeId,
60 TeTopologyKey underlayTopologyIdId,
61 TeNodeKey supportTeNodeId,
62 TeNodeKey sourceTeNodeId,
63 CommonNodeData teData,
64 Map<Long, ConnectivityMatrix> connMatrices,
65 List<Long> teLinkIds,
66 Map<Long, TunnelTerminationPoint> ttps,
67 List<Long> teTpIds) {
68 this.teNodeId = teNodeId;
69 this.underlayTopologyId = underlayTopologyIdId;
70 this.supportTeNodeId = supportTeNodeId;
71 this.sourceTeNodeId = sourceTeNodeId;
72 this.teData = teData;
73 this.connMatrices = connMatrices != null ?
74 Maps.newHashMap(connMatrices) : null;
75 this.teLinkIds = teLinkIds != null ?
76 Lists.newArrayList(teLinkIds) : null;
77 this.ttps = ttps != null ? Maps.newHashMap(ttps) : null;
78 this.teTpIds = teTpIds != null ?
79 Lists.newArrayList(teTpIds) : null;
80 }
81
82 @Override
83 public long teNodeId() {
84 return teNodeId;
85 }
86
87 @Override
88 public String name() {
89 if (teData == null) {
90 return null;
91 }
92 return teData.name();
93 }
94
95 @Override
96 public BitSet flags() {
97 if (teData == null) {
98 return null;
99 }
100 return teData.flags();
101 }
102
103 @Override
104 public TeTopologyKey underlayTeTopologyId() {
105 return underlayTopologyId;
106 }
107
108 @Override
109 public TeNodeKey supportingTeNodeId() {
110 return supportTeNodeId;
111 }
112
113 @Override
114 public TeNodeKey sourceTeNodeId() {
115 return sourceTeNodeId;
116 }
117
118 @Override
119 public Map<Long, ConnectivityMatrix> connectivityMatrices() {
120 if (connMatrices == null) {
121 return null;
122 }
123 return ImmutableMap.copyOf(connMatrices);
124 }
125
126 @Override
127 public ConnectivityMatrix connectivityMatrix(long entryId) {
128 return connMatrices.get(entryId);
129 }
130
131 @Override
132 public List<Long> teLinkIds() {
133 if (teLinkIds == null) {
134 return null;
135 }
136 return ImmutableList.copyOf(teLinkIds);
137 }
138
139 @Override
140 public Map<Long, TunnelTerminationPoint> tunnelTerminationPoints() {
141 if (ttps == null) {
142 return null;
143 }
144 return ImmutableMap.copyOf(ttps);
145 }
146
147 @Override
148 public TunnelTerminationPoint tunnelTerminationPoint(long ttpId) {
149 return ttps.get(ttpId);
150 }
151
152 @Override
153 public TeStatus adminStatus() {
154 if (teData == null) {
155 return null;
156 }
157 return teData.adminStatus();
158 }
159
160 @Override
161 public TeStatus opStatus() {
162 if (teData == null) {
163 return null;
164 }
165 return teData.opStatus();
166 }
167
168 @Override
169 public List<Long> teTerminationPointIds() {
170 return Collections.unmodifiableList(teTpIds);
171 }
172
173 @Override
174 public int hashCode() {
175 return Objects.hashCode(teNodeId, underlayTopologyId,
176 supportTeNodeId, sourceTeNodeId, teData,
177 connMatrices, teLinkIds, ttps, teTpIds);
178 }
179
180 @Override
181 public boolean equals(Object object) {
182 if (this == object) {
183 return true;
184 }
185 if (object instanceof DefaultTeNode) {
186 DefaultTeNode that = (DefaultTeNode) object;
187 return Objects.equal(teNodeId, that.teNodeId) &&
188 Objects.equal(underlayTopologyId, that.underlayTopologyId) &&
189 Objects.equal(supportTeNodeId, that.supportTeNodeId) &&
190 Objects.equal(sourceTeNodeId, that.sourceTeNodeId) &&
191 Objects.equal(teData, that.teData) &&
192 Objects.equal(connMatrices, that.connMatrices) &&
193 Objects.equal(teLinkIds, that.teLinkIds) &&
194 Objects.equal(ttps, that.ttps) &&
195 Objects.equal(teTpIds, that.teTpIds);
196 }
197 return false;
198 }
199
200 @Override
201 public String toString() {
202 return MoreObjects.toStringHelper(this)
203 .add("teNodeId", teNodeId)
204 .add("underlayTopologyId", underlayTopologyId)
205 .add("supportTeNodeId", supportTeNodeId)
206 .add("sourceTeNodeId", sourceTeNodeId)
207 .add("teData", teData)
208 .add("connMatrices", connMatrices)
209 .add("teLinkIds", teLinkIds)
210 .add("ttps", ttps)
211 .add("teTpIds", teTpIds)
212 .toString();
213 }
214}