blob: 2f759004176232ae152b873a789a68f9bbbdd66e [file] [log] [blame]
chenqinghui86320ae2016-12-01 15:40:39 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
chenqinghui86320ae2016-12-01 15:40:39 +08003 *
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 */
16
17package org.onosproject.tetunnel.api.lsp;
18
19import com.google.common.collect.ImmutableList;
20import com.google.common.collect.Lists;
21import org.onosproject.tetopology.management.api.node.TeNodeKey;
22import org.onosproject.tetopology.management.api.node.TtpKey;
23import org.onosproject.tetunnel.api.tunnel.TeTunnel;
24import org.onosproject.tetunnel.api.tunnel.TeTunnelKey;
25import org.onosproject.tetunnel.api.tunnel.path.TeRouteSubobject;
26
27import java.util.List;
28
29/**
30 * Default implementation of TE LSP.
31 */
32public class DefaultTeLsp implements TeLsp {
33
34 private final TeLspKey teLspKey;
35 private final TeNodeKey srcNode;
36 private final TeNodeKey dstNode;
37 private final TtpKey srcTp;
38 private final TtpKey dstTp;
39 private final TeTunnelKey teTunnelKey;
40 private final TeTunnel.Type tunnelType;
41 private final TeTunnel.State operStatus;
42 private final LspProtectionRole lspProtectionRole;
43 private final OriginType originType;
44 private final List<TeRouteSubobject> lspRecordRoutes;
45
46 /**
47 * Creates an instance of default TE LSP with supplied information.
48 *
49 * @param teLspKey TE LSP key
50 * @param srcNode source TE node key
51 * @param dstNode destination TE node key
52 * @param srcTp source TE termination point key
53 * @param dstTp destination TE termination point key
54 * @param teTunnelKey TE tunnel key
55 * @param tunnelType TE tunnel type
56 * @param operStatus operational status
57 * @param lspProtectionRole protection type
58 * @param originType origin type
59 * @param lspRecordRoutes route of the LSP
60 */
61 protected DefaultTeLsp(TeLspKey teLspKey, TeNodeKey srcNode, TeNodeKey dstNode,
62 TtpKey srcTp, TtpKey dstTp, TeTunnelKey teTunnelKey,
63 TeTunnel.Type tunnelType, TeTunnel.State operStatus,
64 LspProtectionRole lspProtectionRole,
65 OriginType originType,
66 List<TeRouteSubobject> lspRecordRoutes) {
67 this.srcNode = srcNode;
68 this.dstNode = dstNode;
69 this.srcTp = srcTp;
70 this.dstTp = dstTp;
71 this.teTunnelKey = teTunnelKey;
72 this.tunnelType = tunnelType;
73 this.operStatus = operStatus;
74 this.lspProtectionRole = lspProtectionRole;
75 this.originType = originType;
76 this.lspRecordRoutes = Lists.newArrayList(lspRecordRoutes);
77 this.teLspKey = teLspKey;
78 }
79
80 @Override
81 public TeLspKey teLspKey() {
82 return teLspKey;
83 }
84
85 @Override
86 public TeNodeKey srcNode() {
87 return srcNode;
88 }
89
90 @Override
91 public TeNodeKey dstNode() {
92 return dstNode;
93 }
94
95 @Override
96 public TtpKey srcTp() {
97 return srcTp;
98 }
99
100 @Override
101 public TtpKey dstTp() {
102 return dstTp;
103 }
104
105 @Override
106 public TeTunnelKey teTunnelKey() {
107 return teTunnelKey;
108 }
109
110 @Override
111 public TeTunnel.Type tunnelType() {
112 return tunnelType;
113 }
114
115 @Override
116 public TeTunnel.State operStatus() {
117 return operStatus;
118 }
119
120 @Override
121 public LspProtectionRole lspProtectionRole() {
122 return lspProtectionRole;
123 }
124
125 @Override
126 public OriginType originType() {
127 return originType;
128 }
129
130 @Override
131 public List<TeRouteSubobject> lspRecordRoutes() {
132 return ImmutableList.copyOf(lspRecordRoutes);
133 }
134
135
136 /**
137 * Creates a new default TE LSP builder.
138 *
139 * @return default builder
140 */
141 public static Builder builder() {
142 return new Builder();
143 }
144
145 /**
146 * Builder for default TE LSP objects.
147 */
148 public static class Builder {
149
150 private TeLspKey teLspKey = null;
151 private TeNodeKey srcNode = null;
152 private TeNodeKey dstNode = null;
153 private TtpKey srcTp = null;
154 private TtpKey dstTp = null;
155 private TeTunnelKey teTunnelKey = null;
156 private TeTunnel.Type tunnelType = null;
157 private TeTunnel.State operStatus = null;
158 private LspProtectionRole lspProtectionRole = null;
159 private OriginType originType = null;
160 private List<TeRouteSubobject> lspRecordRoutes = Lists.newArrayList();
161
162 /**
163 * Builds a default TE LSP object from the accumulated parameters.
164 *
165 * @return default TE LSP object
166 */
167 public DefaultTeLsp build() {
168 return new DefaultTeLsp(teLspKey, srcNode, dstNode, srcTp, dstTp,
169 teTunnelKey, tunnelType, operStatus,
170 lspProtectionRole, originType,
171 lspRecordRoutes);
172 }
173
174 /**
175 * Sets TE LSP key to be used by this builder.
176 *
177 * @param teLspKey TE LSP key
178 * @return self
179 */
180 public Builder teLspKey(TeLspKey teLspKey) {
181 this.teLspKey = teLspKey;
182 return this;
183 }
184
185 /**
186 * Sets source node key to be used by this builder.
187 *
188 * @param srcNode source node key
189 * @return self
190 */
191 public Builder srcNode(TeNodeKey srcNode) {
192 this.srcNode = srcNode;
193 return this;
194 }
195
196 /**
197 * Sets destination node key to be used by this builder.
198 *
199 * @param dstNode destination node key
200 * @return self
201 */
202 public Builder dstNode(TeNodeKey dstNode) {
203 this.dstNode = dstNode;
204 return this;
205 }
206
207 /**
208 * Sets source termination point key to be used by this builder.
209 *
210 * @param srcTp source termination point key
211 * @return self
212 */
213 public Builder srcTp(TtpKey srcTp) {
214 this.srcTp = srcTp;
215 return this;
216 }
217
218 /**
219 * Sets destination termination point key to be used by this builder.
220 *
221 * @param dstTp destination termination point key
222 * @return self
223 */
224 public Builder dstTp(TtpKey dstTp) {
225 this.dstTp = dstTp;
226 return this;
227 }
228
229 /**
230 * Sets TE tunnel key to be used by this builder.
231 *
232 * @param teTunnelKey TE tunnel key
233 * @return self
234 */
235 public Builder teTunnelKey(TeTunnelKey teTunnelKey) {
236 this.teTunnelKey = teTunnelKey;
237 return this;
238 }
239
240 /**
241 * Sets TE tunnel type to be used by this builder.
242 *
243 * @param tunnelType TE tunnel type
244 * @return self
245 */
246 public Builder tunnelType(TeTunnel.Type tunnelType) {
247 this.tunnelType = tunnelType;
248 return this;
249 }
250
251 /**
252 * Sets LSP operational status to be used by this builder.
253 *
254 * @param operStatus LSP operational status
255 * @return self
256 */
257 public Builder operStatus(TeTunnel.State operStatus) {
258 this.operStatus = operStatus;
259 return this;
260 }
261
262 /**
263 * Sets LSP protection role to be used by this builder.
264 *
265 * @param lspProtectionRole LSP protection role
266 * @return self
267 */
268 public Builder lspProtectionRole(LspProtectionRole lspProtectionRole) {
269 this.lspProtectionRole = lspProtectionRole;
270 return this;
271 }
272
273 /**
274 * Sets LSP origin type to be used by this builder.
275 *
276 * @param originType LSP origin type
277 * @return self
278 */
279 public Builder originType(OriginType originType) {
280 this.originType = originType;
281 return this;
282 }
283
284 /**
285 * Sets LSP record routes to be used by this builder.
286 *
287 * @param lspRecordRoutes LSP record routes
288 * @return self
289 */
290 public Builder lspRecordRoutes(List<TeRouteSubobject> lspRecordRoutes) {
291 if (lspRecordRoutes != null) {
292 this.lspRecordRoutes = lspRecordRoutes;
293 }
294 return this;
295 }
296 }
297}