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 draft-ietf-pce-stateful-pce-01 (sec. 6.2) - The PCUpd Message -
22 public class CompositeUpdPathObject {
24 private final PCEPExplicitRouteObject explicitRoute;
26 private final PCEPLspaObject lspa;
28 private final PCEPRequestedPathBandwidthObject bandwidth;
30 private List<PCEPMetricObject> metrics;
33 * Constructs basic composite object only with mandatory objects.
34 * @param explicitRoute PCEPExplicitRouteObject
36 public CompositeUpdPathObject(PCEPExplicitRouteObject explicitRoute) {
37 this(explicitRoute, null, null, null);
41 * Constructs composite object with optional objects.
42 * @param explicitRoute PCEPExplicitRouteObject
43 * @param lspa PCEPLspaObject
44 * @param bandwidth PCEPRequestedPathBandwidthObject
45 * @param metrics List<PCEPMetricObject>
47 public CompositeUpdPathObject(PCEPExplicitRouteObject explicitRoute, PCEPLspaObject lspa, PCEPRequestedPathBandwidthObject bandwidth,
48 List<PCEPMetricObject> metrics) {
49 if (explicitRoute == null)
50 throw new IllegalArgumentException("Explicit Route Object is mandatory.");
51 this.explicitRoute = explicitRoute;
53 this.bandwidth = bandwidth;
55 this.metrics = metrics;
57 this.metrics = Collections.emptyList();
61 * Gets list of all objects, which are in appropriate order.
62 * @return List<PCEPObject>
64 public List<PCEPObject> getCompositeAsList() {
65 final List<PCEPObject> list = new ArrayList<PCEPObject>();
66 list.add(this.explicitRoute);
67 if (this.lspa != null)
69 if (this.bandwidth != null)
70 list.add(this.bandwidth);
71 if (this.metrics != null && !this.metrics.isEmpty())
72 list.addAll(this.metrics);
77 * Creates this object from a list of PCEPObjects.
78 * @param objects List<PCEPObject> list of PCEPObjects from whose this
79 * object should be created.
80 * @return CompositeUpdPathObject constructed from objects
82 public static CompositeUpdPathObject getCompositeFromList(List<PCEPObject> objects) {
83 if (objects == null || objects.isEmpty()) {
84 throw new IllegalArgumentException("List cannot be null or empty.");
87 PCEPExplicitRouteObject explicitRoute = null;
88 if (objects.get(0) instanceof PCEPExplicitRouteObject) {
89 explicitRoute = (PCEPExplicitRouteObject) objects.get(0);
90 objects.remove(explicitRoute);
94 PCEPLspaObject lspa = null;
95 PCEPRequestedPathBandwidthObject bandwidth = null;
96 final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
99 while (!objects.isEmpty()) {
100 final PCEPObject obj = objects.get(0);
105 if (obj instanceof PCEPLspaObject) {
106 lspa = (PCEPLspaObject) obj;
111 if (obj instanceof PCEPRequestedPathBandwidthObject) {
112 bandwidth = (PCEPRequestedPathBandwidthObject) obj;
116 if (obj instanceof PCEPMetricObject) {
117 metrics.add((PCEPMetricObject) obj);
131 return new CompositeUpdPathObject(explicitRoute, lspa, bandwidth, metrics);
135 * Gets {@link PCEPExplicitRouteObject}
137 * @return PCEPExplicitRouteObject
139 public PCEPExplicitRouteObject getExcludedRoute() {
140 return this.explicitRoute;
144 * Gets {@link PCEPLspaObject}
146 * @return PCEPLspaObject
148 public PCEPLspaObject getLspa() {
155 * @return PCEPBandwidthObject
157 public PCEPBandwidthObject getBandwidth() {
158 return this.bandwidth;
162 * Gets list of {@link PCEPMetricObject}.
164 * @return List<PCEPMetricObject>
166 public List<PCEPMetricObject> getMetrics() {
171 public int hashCode() {
172 final int prime = 31;
174 result = prime * result + ((this.bandwidth == null) ? 0 : this.bandwidth.hashCode());
175 result = prime * result + ((this.explicitRoute == null) ? 0 : this.explicitRoute.hashCode());
176 result = prime * result + ((this.lspa == null) ? 0 : this.lspa.hashCode());
177 result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode());
182 public boolean equals(Object obj) {
187 if (this.getClass() != obj.getClass())
189 final CompositeUpdPathObject other = (CompositeUpdPathObject) obj;
190 if (this.bandwidth == null) {
191 if (other.bandwidth != null)
193 } else if (!this.bandwidth.equals(other.bandwidth))
195 if (this.explicitRoute == null) {
196 if (other.explicitRoute != null)
198 } else if (!this.explicitRoute.equals(other.explicitRoute))
200 if (this.lspa == null) {
201 if (other.lspa != null)
203 } else if (!this.lspa.equals(other.lspa))
205 if (this.metrics == null) {
206 if (other.metrics != null)
208 } else if (!this.metrics.equals(other.metrics))
214 public String toString() {
215 final StringBuilder builder = new StringBuilder();
216 builder.append("CompositeUpdPathObject [explicitRoute=");
217 builder.append(this.explicitRoute);
218 builder.append(", lspa=");
219 builder.append(this.lspa);
220 builder.append(", bandwidth=");
221 builder.append(this.bandwidth);
222 builder.append(", metrics=");
223 builder.append(this.metrics);
225 return builder.toString();