2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.object;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
14 import org.opendaylight.protocol.pcep.PCEPObject;
17 * Structure that combines set of related objects.
19 * @see <a href="http://tools.ietf.org/html/rfc5440#section-6.5">Path
20 * Computation Reply (PCRep) Message</a> - <response></br>
22 public class CompositeResponseObject {
24 private final PCEPRequestParameterObject requestParameter;
26 private final PCEPNoPathObject noPath;
28 private final PCEPLspObject lsp;
30 private final PCEPLspaObject lspa;
32 private final PCEPRequestedPathBandwidthObject bandwidth;
34 private List<PCEPMetricObject> metrics;
36 private final PCEPIncludeRouteObject includeRoute;
38 private List<CompositePathObject> paths;
41 * Constructs basic composite object only with mandatory objects.
43 * @param requestParameter
44 * PCEPRequestParameterObject. Can't be null.
46 public CompositeResponseObject(PCEPRequestParameterObject requestParameter) {
47 this(requestParameter, null, null, null, null, null, null, null);
51 * Constructs composite object with optional objects.
53 * @param requestParameter
54 * PCEPRequestParameterObject. Can't be null.
62 * PCEPRequestedPathBandwidthObject
64 * List<PCEPMetricObject>
66 * PCEPIncludeRouteObject
68 * List<CompositePathObject>
70 public CompositeResponseObject(PCEPRequestParameterObject requestParameter, PCEPNoPathObject noPath, PCEPLspObject lsp, PCEPLspaObject lspa,
71 PCEPRequestedPathBandwidthObject bandwidth, List<PCEPMetricObject> metrics, PCEPIncludeRouteObject includeRoute, List<CompositePathObject> paths) {
72 if (requestParameter == null)
73 throw new IllegalArgumentException("Request Parameter Object is mandatory.");
74 this.requestParameter = requestParameter;
78 this.bandwidth = bandwidth;
80 this.metrics = metrics;
82 this.metrics = Collections.emptyList();
83 this.includeRoute = includeRoute;
87 this.paths = Collections.emptyList();
91 * Gets list of all objects, which are in appropriate order.
93 * @return List<PCEPObject>
95 public List<PCEPObject> getCompositeAsList() {
96 final List<PCEPObject> list = new ArrayList<PCEPObject>();
97 list.add(this.requestParameter);
98 if (this.noPath != null)
99 list.add(this.noPath);
100 if (this.lsp != null)
102 if (this.lspa != null)
104 if (this.bandwidth != null)
105 list.add(this.bandwidth);
106 if (this.metrics != null && !this.metrics.isEmpty())
107 list.addAll(this.metrics);
108 if (this.includeRoute != null)
109 list.add(this.includeRoute);
110 if (this.paths != null && !this.paths.isEmpty())
111 for (final CompositePathObject cpo : this.paths)
112 list.addAll(cpo.getCompositeAsList());
117 * Creates this object from a list of PCEPObjects.
118 * @param objects List<PCEPObject> list of PCEPObjects from whose this
119 * object should be created.
120 * @return CompositeResponseObject
122 public static CompositeResponseObject getCompositeFromList(List<PCEPObject> objects) {
123 if (objects == null || objects.isEmpty()) {
124 throw new IllegalArgumentException("List cannot be null or empty.");
126 PCEPRequestParameterObject requestParameter = null;
127 if (objects.get(0) instanceof PCEPRequestParameterObject) {
128 requestParameter = (PCEPRequestParameterObject) objects.get(0);
129 objects.remove(requestParameter);
132 PCEPNoPathObject noPath = null;
133 PCEPLspObject lsp = null;
134 PCEPLspaObject lspa = null;
135 PCEPRequestedPathBandwidthObject bandwidth = null;
136 final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
137 PCEPIncludeRouteObject iro = null;
138 final List<CompositePathObject> paths = new ArrayList<CompositePathObject>();
141 while (!objects.isEmpty()) {
142 final PCEPObject obj = objects.get(0);
146 if (obj instanceof PCEPNoPathObject) {
147 noPath = (PCEPNoPathObject) obj;
152 if (obj instanceof PCEPLspObject) {
153 lsp = (PCEPLspObject) obj;
158 if (obj instanceof PCEPLspaObject) {
159 lspa = (PCEPLspaObject) obj;
164 if (obj instanceof PCEPRequestedPathBandwidthObject) {
165 bandwidth = (PCEPRequestedPathBandwidthObject) obj;
169 if (obj instanceof PCEPMetricObject) {
170 metrics.add((PCEPMetricObject) obj);
177 if (obj instanceof PCEPIncludeRouteObject) {
178 iro = (PCEPIncludeRouteObject) obj;
192 if (!objects.isEmpty()) {
193 CompositePathObject path = CompositePathObject.getCompositeFromList(objects);
194 while (path != null) {
196 if (objects.isEmpty())
198 path = CompositePathObject.getCompositeFromList(objects);
201 return new CompositeResponseObject(requestParameter, noPath, lsp, lspa, bandwidth, metrics, iro, paths);
205 * Gets {@link PCEPRequestParameterObject}.
207 * @return PCEPRequestParameterObject. Can't be null.
209 public PCEPRequestParameterObject getRequestParameter() {
210 return this.requestParameter;
214 * Gets {@link PCEPNoPathObject}.
216 * @return PCEPNoPathObject. May be null.
218 public PCEPNoPathObject getNoPath() {
223 * Gets {@link PCEPLspObject}
225 * @return PCEPLspObject. May be null.
227 public PCEPLspObject getLsp() {
232 * Gets {@link PCEPLspaObject}.
234 * @return PCEPLspaObject. May be null.
236 public PCEPLspaObject getLspa() {
241 * Gets {@link PCEPBandwidthObject}.
243 * @return PCEPBandwidthObject. May be null.
245 public PCEPBandwidthObject getBandwidth() {
246 return this.bandwidth;
250 * Gets list of {@link PCEPMetricObject}.
252 * @return List<PCEPMetricObject>. Can't be null, but may be empty.
254 public List<PCEPMetricObject> getMetrics() {
259 * Gets list of {@link CompositePathObject}.
261 * @return PCEPIncludeRouteObject. Can't be null, but may be empty.
263 public PCEPIncludeRouteObject getIncludeRoute() {
264 return this.includeRoute;
268 * Gets list of {@link CompositePathObject}.
270 * @return List<CompositePathObject>. Can't be null, but may be empty.
272 public List<CompositePathObject> getPaths() {
277 public int hashCode() {
278 final int prime = 31;
280 result = prime * result + ((this.bandwidth == null) ? 0 : this.bandwidth.hashCode());
281 result = prime * result + ((this.includeRoute == null) ? 0 : this.includeRoute.hashCode());
282 result = prime * result + ((this.lsp == null) ? 0 : this.lsp.hashCode());
283 result = prime * result + ((this.lspa == null) ? 0 : this.lspa.hashCode());
284 result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode());
285 result = prime * result + ((this.noPath == null) ? 0 : this.noPath.hashCode());
286 result = prime * result + ((this.paths == null) ? 0 : this.paths.hashCode());
287 result = prime * result + ((this.requestParameter == null) ? 0 : this.requestParameter.hashCode());
292 public boolean equals(Object obj) {
297 if (this.getClass() != obj.getClass())
299 final CompositeResponseObject other = (CompositeResponseObject) obj;
300 if (this.bandwidth == null) {
301 if (other.bandwidth != null)
303 } else if (!this.bandwidth.equals(other.bandwidth))
305 if (this.includeRoute == null) {
306 if (other.includeRoute != null)
308 } else if (!this.includeRoute.equals(other.includeRoute))
310 if (this.lsp == null) {
311 if (other.lsp != null)
313 } else if (!this.lsp.equals(other.lsp))
315 if (this.lspa == null) {
316 if (other.lspa != null)
318 } else if (!this.lspa.equals(other.lspa))
320 if (this.metrics == null) {
321 if (other.metrics != null)
323 } else if (!this.metrics.equals(other.metrics))
325 if (this.noPath == null) {
326 if (other.noPath != null)
328 } else if (!this.noPath.equals(other.noPath))
330 if (this.paths == null) {
331 if (other.paths != null)
333 } else if (!this.paths.equals(other.paths))
335 if (this.requestParameter == null) {
336 if (other.requestParameter != null)
338 } else if (!this.requestParameter.equals(other.requestParameter))
344 public String toString() {
345 final StringBuilder builder = new StringBuilder();
346 builder.append("CompositeResponseObject [requestParameter=");
347 builder.append(this.requestParameter);
348 builder.append(", noPath=");
349 builder.append(this.noPath);
350 builder.append(", lsp=");
351 builder.append(this.lsp);
352 builder.append(", lspa=");
353 builder.append(this.lspa);
354 builder.append(", bandwidth=");
355 builder.append(this.bandwidth);
356 builder.append(", metrics=");
357 builder.append(this.metrics);
358 builder.append(", includeRoute=");
359 builder.append(this.includeRoute);
360 builder.append(", paths=");
361 builder.append(this.paths);
363 return builder.toString();