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.4">Path
20 * Computation Request (PCReq) Message</a> - <request></br>
22 * @see <a href="tools.ietf.org/html/rfc5455#section-3.2">Path Computation
23 * Request Message with CLASSTYPE Object</a>
25 public class CompositeRequestObject {
27 private final PCEPRequestParameterObject requestParameter;
29 private final PCEPEndPointsObject<?> endPoints;
31 private final PCEPClassTypeObject classType;
33 private final PCEPLspObject lsp;
35 private final PCEPLspaObject lspa;
37 private final PCEPRequestedPathBandwidthObject bandwidth;
39 private final List<PCEPMetricObject> metrics;
41 private final PCEPReportedRouteObject reportedRoute;
43 private final PCEPExistingPathBandwidthObject rroBandwidth;
45 private final PCEPIncludeRouteObject includeRoute;
47 private final PCEPLoadBalancingObject loadBalancing;
50 * Constructs basic composite object only with mandatory objects.
52 * @param requestParameter
53 * PCEPRequestParameterObject. Can't be null.
55 * PCEPEndPointsObject<?>. Can't be null.
57 public CompositeRequestObject(PCEPRequestParameterObject requestParameter, PCEPEndPointsObject<?> endPoints) {
58 this(requestParameter, endPoints, null, null, null, null, null, null, null, null, null);
62 * Constructs composite object with optional objects.
64 * @param requestParameter
65 * PCEPRequestParameterObject. Can't be null.
67 * PCEPEndPointsObject<?>. Can't be null.
75 * PCEPRequestedPathBandwidthObject
77 * List<PCEPMetricObject>
78 * @param reportedRoute
79 * PCEPReportedRouteObject
81 * PCEPExistingPathBandwidthObject
83 * PCEPIncludeRouteObject
84 * @param loadBalancing
85 * PCEPLoadBalancingObject
87 public CompositeRequestObject(PCEPRequestParameterObject requestParameter, PCEPEndPointsObject<?> endPoints, PCEPClassTypeObject classType,
88 PCEPLspObject lsp, PCEPLspaObject lspa, PCEPRequestedPathBandwidthObject bandwidth, List<PCEPMetricObject> metrics,
89 PCEPReportedRouteObject reportedRoute, PCEPExistingPathBandwidthObject rroBandwidth, PCEPIncludeRouteObject includeRoute,
90 PCEPLoadBalancingObject loadBalancing) {
91 if (requestParameter == null)
92 throw new IllegalArgumentException("Request Parameter Object is mandatory.");
93 if (endPoints == null)
94 throw new IllegalArgumentException("End-Points Object is mandatory.");
95 this.requestParameter = requestParameter;
96 this.endPoints = endPoints;
97 this.classType = classType;
100 this.bandwidth = bandwidth;
102 this.metrics = metrics;
104 this.metrics = Collections.emptyList();
105 this.reportedRoute = reportedRoute;
106 this.rroBandwidth = rroBandwidth;
107 this.includeRoute = includeRoute;
108 this.loadBalancing = loadBalancing;
112 * Gets list of all objects, which are in appropriate order.
114 * @return List<PCEPObject>. Can't be null or empty.
116 public List<PCEPObject> getCompositeAsList() {
117 final List<PCEPObject> list = new ArrayList<PCEPObject>();
118 list.add(this.requestParameter);
119 list.add(this.endPoints);
120 if (this.classType != null)
121 list.add(this.classType);
122 if (this.lsp != null)
124 if (this.lspa != null)
126 if (this.bandwidth != null)
127 list.add(this.bandwidth);
128 if (this.metrics != null && !this.metrics.isEmpty())
129 list.addAll(this.metrics);
130 if (this.reportedRoute != null) {
131 list.add(this.reportedRoute);
132 if (this.rroBandwidth != null)
133 list.add(this.rroBandwidth);
135 if (this.includeRoute != null)
136 list.add(this.includeRoute);
137 if (this.loadBalancing != null)
138 list.add(this.loadBalancing);
143 * Creates this object from a list of PCEPObjects.
146 * List<PCEPObject> list of PCEPObjects from whose this object
148 * @return CompositeRequestObject
150 public static CompositeRequestObject getCompositeFromList(List<PCEPObject> objects) {
151 if (objects == null || objects.isEmpty()) {
152 throw new IllegalArgumentException("List cannot be null or empty.");
154 PCEPRequestParameterObject requestParameter = null;
155 if (objects.get(0) instanceof PCEPRequestParameterObject) {
156 requestParameter = (PCEPRequestParameterObject) objects.get(0);
157 objects.remove(requestParameter);
161 PCEPEndPointsObject<?> endPoints = null;
162 if (objects.get(0) instanceof PCEPEndPointsObject<?>) {
163 endPoints = (PCEPEndPointsObject<?>) objects.get(0);
164 objects.remove(endPoints);
166 throw new IllegalArgumentException("End Points object must be second.");
168 PCEPClassTypeObject classType = null;
169 PCEPLspObject lsp = null;
170 PCEPLspaObject lspa = null;
171 PCEPRequestedPathBandwidthObject bandwidth = null;
172 final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
173 PCEPReportedRouteObject rro = null;
174 PCEPExistingPathBandwidthObject rroBandwidth = null;
175 PCEPIncludeRouteObject iro = null;
176 PCEPLoadBalancingObject loadBalancing = null;
179 while (!objects.isEmpty()) {
180 final PCEPObject obj = objects.get(0);
184 if (obj instanceof PCEPClassTypeObject) {
185 classType = (PCEPClassTypeObject) obj;
190 if (obj instanceof PCEPLspObject) {
191 lsp = (PCEPLspObject) obj;
196 if (obj instanceof PCEPLspaObject) {
197 lspa = (PCEPLspaObject) obj;
202 if (obj instanceof PCEPRequestedPathBandwidthObject) {
203 bandwidth = (PCEPRequestedPathBandwidthObject) obj;
208 if (obj instanceof PCEPMetricObject) {
209 metrics.add((PCEPMetricObject) obj);
216 if (obj instanceof PCEPReportedRouteObject) {
217 rro = (PCEPReportedRouteObject) obj;
223 if (obj instanceof PCEPExistingPathBandwidthObject) {
224 rroBandwidth = (PCEPExistingPathBandwidthObject) obj;
229 if (obj instanceof PCEPIncludeRouteObject) {
230 iro = (PCEPIncludeRouteObject) obj;
234 if (obj instanceof PCEPLoadBalancingObject) {
235 loadBalancing = (PCEPLoadBalancingObject) obj;
248 return new CompositeRequestObject(requestParameter, endPoints, classType, lsp, lspa, bandwidth, metrics, rro, rroBandwidth, iro, loadBalancing);
252 * Gets {@link PCEPRequestParameterObject}.
254 * @return PCEPRequestParameterObject. Can't be null.
256 public PCEPRequestParameterObject getRequestParameter() {
257 return this.requestParameter;
261 * Gets {@link PCEPEndPointsObject}.
263 * @return PCEPEndPointsObject<?>. Can't be null.
265 public PCEPEndPointsObject<?> getEndPoints() {
266 return this.endPoints;
270 * Gets {@link PCEPClassTypeObject}.
272 * @return PCEPClassTypeObject. May be null.
274 public PCEPClassTypeObject getClassType() {
275 return this.classType;
279 * Gets {@link PCEPLspObject}.
281 * @return PCEPLspObject. May be null.
283 public PCEPLspObject getLsp() {
288 * Gets {@link PCEPLspaObject}.
290 * @return PCEPLspaObject. May be null.
292 public PCEPLspaObject getLspa() {
297 * Gets {@link PCEPBandwidthObject}.
299 * @return PCEPBandwidthObject. May be null.
301 public PCEPBandwidthObject getBandwidth() {
302 return this.bandwidth;
306 * Gets list of {@link PCEPMetricObject}.
308 * @return List<PCEPMetricObject>
310 public List<PCEPMetricObject> getMetrics() {
315 * Gets {@link PCEPReportedRouteObject}.
317 * @return PCEPReportedRouteObject. May be null.
319 public PCEPReportedRouteObject getReportedRoute() {
320 return this.reportedRoute;
324 * Gets {@link PCEPBandwidthObject}.
326 * @return PCEPBandwidthObject. May be null.
328 public PCEPBandwidthObject getRroBandwidth() {
329 return this.rroBandwidth;
333 * Gets {@link PCEPIncludeRouteObject}.
335 * @return PCEPIncludeRouteObject. May be null.
337 public PCEPIncludeRouteObject getIncludeRoute() {
338 return this.includeRoute;
342 * Gets {@link PCEPLoadBalancingObject}.
344 * @return PCEPLoadBalancingObject. May be null.
346 public PCEPLoadBalancingObject getLoadBalancing() {
347 return this.loadBalancing;
351 public int hashCode() {
352 final int prime = 31;
354 result = prime * result + ((this.bandwidth == null) ? 0 : this.bandwidth.hashCode());
355 result = prime * result + ((this.classType == null) ? 0 : this.classType.hashCode());
356 result = prime * result + ((this.endPoints == null) ? 0 : this.endPoints.hashCode());
357 result = prime * result + ((this.includeRoute == null) ? 0 : this.includeRoute.hashCode());
358 result = prime * result + ((this.loadBalancing == null) ? 0 : this.loadBalancing.hashCode());
359 result = prime * result + ((this.lsp == null) ? 0 : this.lsp.hashCode());
360 result = prime * result + ((this.lspa == null) ? 0 : this.lspa.hashCode());
361 result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode());
362 result = prime * result + ((this.reportedRoute == null) ? 0 : this.reportedRoute.hashCode());
363 result = prime * result + ((this.requestParameter == null) ? 0 : this.requestParameter.hashCode());
364 result = prime * result + ((this.rroBandwidth == null) ? 0 : this.rroBandwidth.hashCode());
369 public boolean equals(Object obj) {
374 if (!(obj instanceof CompositeRequestObject))
376 final CompositeRequestObject other = (CompositeRequestObject) obj;
377 if (this.bandwidth == null) {
378 if (other.bandwidth != null)
380 } else if (!this.bandwidth.equals(other.bandwidth))
382 if (this.classType == null) {
383 if (other.classType != null)
385 } else if (!this.classType.equals(other.classType))
387 if (this.endPoints == null) {
388 if (other.endPoints != null)
390 } else if (!this.endPoints.equals(other.endPoints))
392 if (this.includeRoute == null) {
393 if (other.includeRoute != null)
395 } else if (!this.includeRoute.equals(other.includeRoute))
397 if (this.loadBalancing == null) {
398 if (other.loadBalancing != null)
400 } else if (!this.loadBalancing.equals(other.loadBalancing))
402 if (this.lsp == null) {
403 if (other.lsp != null)
405 } else if (!this.lsp.equals(other.lsp))
407 if (this.lspa == null) {
408 if (other.lspa != null)
410 } else if (!this.lspa.equals(other.lspa))
412 if (this.metrics == null) {
413 if (other.metrics != null)
415 } else if (!this.metrics.equals(other.metrics))
417 if (this.reportedRoute == null) {
418 if (other.reportedRoute != null)
420 } else if (!this.reportedRoute.equals(other.reportedRoute))
422 if (this.requestParameter == null) {
423 if (other.requestParameter != null)
425 } else if (!this.requestParameter.equals(other.requestParameter))
427 if (this.rroBandwidth == null) {
428 if (other.rroBandwidth != null)
430 } else if (!this.rroBandwidth.equals(other.rroBandwidth))
436 public String toString() {
437 final StringBuilder builder = new StringBuilder();
438 builder.append("CompositeRequestObject [requestParameter=");
439 builder.append(this.requestParameter);
440 builder.append(", endPoints=");
441 builder.append(this.endPoints);
442 builder.append(", classType=");
443 builder.append(this.classType);
444 builder.append(", lsp=");
445 builder.append(this.lsp);
446 builder.append(", lspa=");
447 builder.append(this.lspa);
448 builder.append(", bandwidth=");
449 builder.append(this.bandwidth);
450 builder.append(", metrics=");
451 builder.append(this.metrics);
452 builder.append(", reportedRoute=");
453 builder.append(this.reportedRoute);
454 builder.append(", rroBandwidth=");
455 builder.append(this.rroBandwidth);
456 builder.append(", includeRoute=");
457 builder.append(this.includeRoute);
458 builder.append(", loadBalancing=");
459 builder.append(this.loadBalancing);
461 return builder.toString();