blob: e9d3fec71262972ad02c2e37f7fd0395046be4d8 [file] [log] [blame]
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05301/*
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 */
16
17package org.onosproject.pce.pceservice;
18
19import static com.google.common.base.MoreObjects.toStringHelper;
20
21import java.util.Objects;
22
23import org.onosproject.incubator.net.tunnel.Tunnel;
24import org.onosproject.incubator.net.tunnel.TunnelId;
25import org.onosproject.net.intent.Constraint;
26
27/**
28 * Implementation of an entity which provides functionalities of pce path.
29 */
30public final class DefaultPcePath implements PcePath {
31
32 private TunnelId id; // path id
33 private String source; // Ingress
34 private String destination; // Egress
35 private LspType lspType; // LSP type
36 private String name; // symbolic-path-name
37 private Constraint costConstraint; // cost constraint
38 private Constraint bandwidthConstraint; // bandwidth constraint
39
40 /**
41 * Initializes PCE path attributes.
42 *
43 * @param id path id
44 * @param src ingress
45 * @param dst egress
46 * @param lspType lsp type
47 * @param name symbolic-path-name
48 * @param constrnt pce constraint
49 */
50 private DefaultPcePath(TunnelId id, String src, String dst, LspType lspType,
51 String name, Constraint costConstrnt, Constraint bandwidthConstrnt) {
52
53 this.id = id;
54 this.source = src;
55 this.destination = dst;
56 this.lspType = lspType;
57 this.name = name;
58 this.costConstraint = costConstrnt;
59 this.bandwidthConstraint = bandwidthConstrnt;
60 }
61
62 @Override
63 public TunnelId id() {
64 return id;
65 }
66
67 @Override
68 public void id(TunnelId id) {
69 this.id = id;
70 }
71
72 @Override
73 public String source() {
74 return source;
75 }
76
77 @Override
78 public void source(String src) {
79 this.source = src;
80 }
81
82 @Override
83 public String destination() {
84 return destination;
85 }
86
87 @Override
88 public void destination(String dst) {
89 this.destination = dst;
90 }
91
92 @Override
93 public LspType lspType() {
94 return lspType;
95 }
96
97 @Override
98 public String name() {
99 return name;
100 }
101
102 @Override
103 public Constraint costConstraint() {
104 return costConstraint;
105 }
106
107 @Override
108 public Constraint bandwidthConstraint() {
109 return bandwidthConstraint;
110 }
111
112 @Override
113 public PcePath copy(PcePath path) {
114 if (null != path.source()) {
115 this.source = path.source();
116 }
117 if (null != path.destination()) {
118 this.destination = path.destination();
119 }
120
121 this.lspType = path.lspType();
122
123 if (null != path.name()) {
124 this.name = path.name();
125 }
126 if (null != path.costConstraint()) {
127 this.costConstraint = path.costConstraint();
128 }
129 if (null != path.bandwidthConstraint()) {
130 this.bandwidthConstraint = path.bandwidthConstraint();
131 }
132 return this;
133 }
134
135 @Override
136 public int hashCode() {
137 return Objects.hash(id, source, destination, lspType, name, costConstraint, bandwidthConstraint);
138 }
139
140 @Override
141 public boolean equals(Object obj) {
142 if (this == obj) {
143 return true;
144 }
145 if (obj instanceof DefaultPcePath) {
146 DefaultPcePath that = (DefaultPcePath) obj;
147 return Objects.equals(id, that.id)
148 && Objects.equals(source, that.source)
149 && Objects.equals(destination, that.destination)
150 && Objects.equals(lspType, that.lspType)
151 && Objects.equals(name, that.name)
152 && Objects.equals(costConstraint, that.costConstraint)
153 && Objects.equals(bandwidthConstraint, that.bandwidthConstraint);
154 }
155 return false;
156 }
157
158 @Override
159 public String toString() {
160 return toStringHelper(this)
161 .add("id", id())
162 .add("source", source)
163 .add("destination", destination)
164 .add("lsptype", lspType)
165 .add("name", name)
166 .add("costConstraint", costConstraint.toString())
167 .add("bandwidthConstraint", bandwidthConstraint.toString())
168 .toString();
169 }
170
171 /**
172 * Creates an instance of the pce path builder.
173 *
174 * @return instance of builder
175 */
176 public static Builder builder() {
177 return new Builder();
178 }
179
180 /**
181 * Builder class for pce path.
182 */
183 public static final class Builder implements PcePath.Builder {
184 private TunnelId id;
185 private String source;
186 private String destination;
187 private LspType lspType;
188 private String name;
189 private Constraint costConstraint;
190 private Constraint bandwidthConstraint;
191
192 @Override
193 public Builder id(String id) {
194 this.id = TunnelId.valueOf(id);
195 return this;
196 }
197
198 @Override
199 public Builder source(String source) {
200 this.source = source;
201 return this;
202 }
203
204 @Override
205 public Builder destination(String destination) {
206 this.destination = destination;
207 return this;
208 }
209
210 @Override
211 public Builder lspType(String type) {
212 if (null != type) {
213 this.lspType = LspType.values()[Integer.valueOf(type) - 1];
214 }
215 return this;
216 }
217
218 @Override
219 public Builder name(String name) {
220 this.name = name;
221 return this;
222 }
223
224 @Override
225 public Builder costConstraint(String cost) {
226 this.costConstraint = null;
227 //TODO: below lines will be uncommented once CostConstraint class is ready
228 // this.costConstraint = CostConstraint.of(cost);
229 //}
230 return this;
231 }
232
233 @Override
234 public Builder bandwidthConstraint(String bandwidth) {
235 this.bandwidthConstraint = null;
236 //TODO: below lines will be uncommented once LocalBandwidthConstraint class is ready
237 // this.bandwidthConstraint = LocalBandwidthConstraint.of(bandwidth);
238 //}
239 return this;
240 }
241
242 @Override
243 public Builder of(Tunnel tunnel) {
244 this.id = TunnelId.valueOf(tunnel.tunnelId().id());
245 this.source = tunnel.src().toString();
246 this.destination = tunnel.dst().toString();
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +0530247 //TODO: need to uncomment below line once LSP_SIG_TYPE is added to AnnotationKeys.
248 this.lspType = null; // = LspType.valueOf(tunnel.annotations()
249 //.value(AnnotationKeys.LSP_SIG_TYPE));
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530250 this.name = tunnel.tunnelName().toString();
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +0530251 //TODO: uncomment below lines once CostConstraint and LocalBandwidthConstraint classes are ready
252 this.costConstraint = null; // = CostConstraint.of(tunnel.path().cost());
253 this.bandwidthConstraint = null; // = LocalBandwidthConstraint.of(tunnel.annotations()
254 //.value(AnnotationKeys.BANDWIDTH));
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530255 return this;
256 }
257
258 @Override
259 public PcePath build() {
260 return new DefaultPcePath(id, source, destination, lspType, name,
261 costConstraint, bandwidthConstraint);
262 }
263 }
264}