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.
20 * href="http://tools.ietf.org/html/draft-crabbe-pce-stateful-pce-02#section-6.1">PCRpt
23 public class CompositeRptPathObject {
24 private final PCEPExplicitRouteObject explicitRoute;
26 private final PCEPLspaObject lspa;
28 private final PCEPExistingPathBandwidthObject bandwidth;
30 private final PCEPReportedRouteObject reportedRoute;
32 private List<PCEPMetricObject> metrics;
35 * Constructs basic composite object only with mandatory objects.
37 * @param explicitRoute
38 * PCEPExplicitRouteObject. Can't be null.
40 public CompositeRptPathObject(final PCEPExplicitRouteObject explicitRoute) {
41 this(explicitRoute, null, null, null, null);
45 * Constructs composite object with optional objects.
47 * @param explicitRoute
48 * PCEPExplicitRouteObject. Can't be null.
52 * PCEPRequestedPathBandwidthObject
53 * @param reportedRoute
54 * PCEPReportedRouteObject
56 * List<PCEPMetricObject>
58 public CompositeRptPathObject(final PCEPExplicitRouteObject explicitRoute, final PCEPLspaObject lspa, final PCEPExistingPathBandwidthObject bandwidth,
59 final PCEPReportedRouteObject reportedRoute, final List<PCEPMetricObject> metrics) {
60 if (explicitRoute == null)
61 throw new IllegalArgumentException("Explicit Route Object is mandatory.");
62 this.explicitRoute = explicitRoute;
64 this.bandwidth = bandwidth;
66 this.metrics = metrics;
68 this.metrics = Collections.emptyList();
69 this.reportedRoute = reportedRoute;
73 * Gets list of all objects, which are in appropriate order.
75 * @return List<PCEPObject>. Can't be null or empty.
77 public List<PCEPObject> getCompositeAsList() {
78 final List<PCEPObject> list = new ArrayList<PCEPObject>();
79 list.add(this.explicitRoute);
80 if (this.lspa != null)
82 if (this.bandwidth != null)
83 list.add(this.bandwidth);
84 if (this.reportedRoute != null)
85 list.add(this.reportedRoute);
86 if (this.metrics != null && !this.metrics.isEmpty())
87 list.addAll(this.metrics);
92 * Creates this object from a list of PCEPObjects.
93 * @param objects List<PCEPObject> list of PCEPObjects from whose this
94 * object should be created.
95 * @return CompositeRptPathObject
97 public static CompositeRptPathObject getCompositeFromList(final List<PCEPObject> objects) {
98 if (objects == null || objects.isEmpty()) {
99 throw new IllegalArgumentException("List cannot be null or empty.");
102 PCEPExplicitRouteObject explicitRoute = null;
103 if (objects.get(0) instanceof PCEPExplicitRouteObject) {
104 explicitRoute = (PCEPExplicitRouteObject) objects.get(0);
105 objects.remove(explicitRoute);
109 PCEPLspaObject lspa = null;
110 PCEPExistingPathBandwidthObject bandwidth = null;
111 final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
112 PCEPReportedRouteObject rro = null;
115 while (!objects.isEmpty()) {
116 final PCEPObject obj = objects.get(0);
121 if (obj instanceof PCEPLspaObject) {
122 lspa = (PCEPLspaObject) obj;
127 if (obj instanceof PCEPExistingPathBandwidthObject) {
128 bandwidth = (PCEPExistingPathBandwidthObject) obj;
133 if (obj instanceof PCEPReportedRouteObject) {
134 rro = (PCEPReportedRouteObject) obj;
138 if (obj instanceof PCEPMetricObject) {
139 metrics.add((PCEPMetricObject) obj);
153 return new CompositeRptPathObject(explicitRoute, lspa, bandwidth, rro, metrics);
157 * Gets {@link PCEPExplicitRouteObject}.
159 * @return PCEPExplicitRouteObject. Can't be null.
161 public PCEPExplicitRouteObject getExcludedRoute() {
162 return this.explicitRoute;
166 * Gets {@link PCEPLspaObject}.
168 * @return PCEPLspaObject. May be null.
170 public PCEPLspaObject getLspa() {
175 * Gets {@link PCEPBandwidthObject}.
177 * @return PCEPBandwidthObject. May be null.
179 public PCEPBandwidthObject getBandwidth() {
180 return this.bandwidth;
184 * Gets list of {@link PCEPMetricObject}.
186 * @return List<PCEPMetricObject>. Can't be null, but may be empty.
188 public List<PCEPMetricObject> getMetrics() {
193 * Gets {@link PCEPReportedRouteObject}.
195 * @return PCEPReportedRouteObject. May be null.
197 public PCEPReportedRouteObject getReportedRoute() {
198 return this.reportedRoute;
202 public int hashCode() {
203 final int prime = 31;
205 result = prime * result + ((this.bandwidth == null) ? 0 : this.bandwidth.hashCode());
206 result = prime * result + ((this.explicitRoute == null) ? 0 : this.explicitRoute.hashCode());
207 result = prime * result + ((this.lspa == null) ? 0 : this.lspa.hashCode());
208 result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode());
209 result = prime * result + ((this.reportedRoute == null) ? 0 : this.reportedRoute.hashCode());
214 public boolean equals(final Object obj) {
219 if (this.getClass() != obj.getClass())
221 final CompositeRptPathObject other = (CompositeRptPathObject) obj;
222 if (this.bandwidth == null) {
223 if (other.bandwidth != null)
225 } else if (!this.bandwidth.equals(other.bandwidth))
227 if (this.explicitRoute == null) {
228 if (other.explicitRoute != null)
230 } else if (!this.explicitRoute.equals(other.explicitRoute))
232 if (this.lspa == null) {
233 if (other.lspa != null)
235 } else if (!this.lspa.equals(other.lspa))
237 if (this.metrics == null) {
238 if (other.metrics != null)
240 } else if (!this.metrics.equals(other.metrics))
242 if (this.reportedRoute == null) {
243 if (other.reportedRoute != null)
245 } else if (!this.reportedRoute.equals(other.reportedRoute))
251 public String toString() {
252 final StringBuilder builder = new StringBuilder();
253 builder.append("CompositeRptPathObject [explicitRoute=");
254 builder.append(this.explicitRoute);
255 builder.append(", lspa=");
256 builder.append(this.lspa);
257 builder.append(", bandwidth=");
258 builder.append(this.bandwidth);
259 builder.append(", reportedRoute=");
260 builder.append(this.reportedRoute);
261 builder.append(", metrics=");
262 builder.append(this.metrics);
264 return builder.toString();