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> - <path></br> Same for every
21 * usage of path object.
23 public class CompositePathObject {
25 private final PCEPExplicitRouteObject explicitRoute;
27 private final PCEPLspaObject lspa;
29 private final PCEPRequestedPathBandwidthObject bandwidth;
31 private List<PCEPMetricObject> metrics;
33 private final PCEPIncludeRouteObject includeRoute;
36 * Constructs basic composite object only with mandatory objects.
38 * @param explicitRoute
39 * PCEPExplicitRouteObject. Can't be null or empty.
41 public CompositePathObject(PCEPExplicitRouteObject explicitRoute) {
42 this(explicitRoute, null, null, null, null);
46 * Constructs composite object with optional objects.
48 * @param explicitRoute
49 * PCEPExplicitRouteObject. Can't be null or empty.
53 * PCEPRequestedPathBandwidthObject
55 * List<PCEPMetricObject>
57 * PCEPIncludeRouteObject
59 public CompositePathObject(PCEPExplicitRouteObject explicitRoute, PCEPLspaObject lspa, PCEPRequestedPathBandwidthObject bandwidth,
60 List<PCEPMetricObject> metrics, PCEPIncludeRouteObject includeRoute) {
61 if (explicitRoute == null)
62 throw new IllegalArgumentException("Explicit Route Object is mandatory.");
63 this.explicitRoute = explicitRoute;
65 this.bandwidth = bandwidth;
67 this.metrics = metrics;
69 this.metrics = Collections.emptyList();
70 this.includeRoute = includeRoute;
74 * Gets list of all objects, which are in appropriate order.
76 * @return List<PCEPObject>. Can't be null or empty.
78 public List<PCEPObject> getCompositeAsList() {
79 final List<PCEPObject> list = new ArrayList<PCEPObject>();
80 list.add(this.explicitRoute);
81 if (this.lspa != null)
83 if (this.bandwidth != null)
84 list.add(this.bandwidth);
85 if (this.metrics != null && !this.metrics.isEmpty())
86 list.addAll(this.metrics);
87 if (this.includeRoute != null)
88 list.add(this.includeRoute);
93 * Creates this object from a list of PCEPObjects.
94 * @param objects List<PCEPObject> list of PCEPObjects from whose this
95 * object should be created.
96 * @return CompositePathObject
98 public static CompositePathObject getCompositeFromList(List<PCEPObject> objects) {
99 if (objects == null || objects.isEmpty()) {
100 throw new IllegalArgumentException("List cannot be null or empty.");
103 PCEPExplicitRouteObject explicitRoute = null;
104 if (objects.get(0) instanceof PCEPExplicitRouteObject) {
105 explicitRoute = (PCEPExplicitRouteObject) objects.get(0);
106 objects.remove(explicitRoute);
110 PCEPLspaObject lspa = null;
111 PCEPRequestedPathBandwidthObject bandwidth = null;
112 final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
113 PCEPIncludeRouteObject iro = null;
116 while (!objects.isEmpty()) {
117 final PCEPObject obj = objects.get(0);
122 if (obj instanceof PCEPLspaObject) {
123 lspa = (PCEPLspaObject) obj;
128 if (obj instanceof PCEPRequestedPathBandwidthObject) {
129 bandwidth = (PCEPRequestedPathBandwidthObject) obj;
133 if (obj instanceof PCEPMetricObject) {
134 metrics.add((PCEPMetricObject) obj);
140 if (obj instanceof PCEPIncludeRouteObject) {
141 iro = (PCEPIncludeRouteObject) obj;
154 return new CompositePathObject(explicitRoute, lspa, bandwidth, metrics, iro);
158 * Gets {@link PCEPExplicitRouteObject}.
160 * @return PCEPExplicitRouteObject. Can't be null.
162 public PCEPExplicitRouteObject getExcludedRoute() {
163 return this.explicitRoute;
167 * Gets {@link PCEPLspaObject}.
169 * @return PCEPLspaObject. May be null.
171 public PCEPLspaObject getLspa() {
176 * Gets {@link PCEPBandwidthObject}.
178 * @return PCEPBandwidthObject. May be null.
180 public PCEPBandwidthObject getBandwidth() {
181 return this.bandwidth;
185 * Gets list of {@link PCEPMetricObject}.
187 * @return List<PCEPMetricObject>. Can't be null, but may be empty.
189 public List<PCEPMetricObject> getMetrics() {
194 * Gets {@link PCEPIncludeRouteObject}.
196 * @return PCEPIncludeRouteObject. May be null.
198 public PCEPIncludeRouteObject getIncludeRoute() {
199 return this.includeRoute;
203 public int hashCode() {
204 final int prime = 31;
206 result = prime * result + ((this.bandwidth == null) ? 0 : this.bandwidth.hashCode());
207 result = prime * result + ((this.explicitRoute == null) ? 0 : this.explicitRoute.hashCode());
208 result = prime * result + ((this.includeRoute == null) ? 0 : this.includeRoute.hashCode());
209 result = prime * result + ((this.lspa == null) ? 0 : this.lspa.hashCode());
210 result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode());
215 public boolean equals(Object obj) {
220 if (this.getClass() != obj.getClass())
222 final CompositePathObject other = (CompositePathObject) obj;
223 if (this.bandwidth == null) {
224 if (other.bandwidth != null)
226 } else if (!this.bandwidth.equals(other.bandwidth))
228 if (this.explicitRoute == null) {
229 if (other.explicitRoute != null)
231 } else if (!this.explicitRoute.equals(other.explicitRoute))
233 if (this.includeRoute == null) {
234 if (other.includeRoute != null)
236 } else if (!this.includeRoute.equals(other.includeRoute))
238 if (this.lspa == null) {
239 if (other.lspa != null)
241 } else if (!this.lspa.equals(other.lspa))
243 if (this.metrics == null) {
244 if (other.metrics != null)
246 } else if (!this.metrics.equals(other.metrics))
252 public String toString() {
253 final StringBuilder builder = new StringBuilder();
254 builder.append("CompositePathObject [explicitRoute=");
255 builder.append(this.explicitRoute);
256 builder.append(", lspa=");
257 builder.append(this.lspa);
258 builder.append(", bandwidth=");
259 builder.append(this.bandwidth);
260 builder.append(", metrics=");
261 builder.append(this.metrics);
262 builder.append(", includeRoute=");
263 builder.append(this.includeRoute);
265 return builder.toString();