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