Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPExcludeRouteObject.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.object;
9
10 import java.util.List;
11
12 import org.opendaylight.protocol.pcep.PCEPObject;
13 import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject;
14 import com.google.common.base.Objects.ToStringHelper;
15
16 /**
17  * Provides a list of network resources that the PCE is requested to exclude
18  * from the path that it computes. Flags associated with each list member
19  * instruct the PCE as to whether the network resources must be excluded from
20  * the computed path, or whether the PCE should make best efforts to exclude the
21  * resources from the computed path.
22  *
23  * @see <a href="http://tools.ietf.org/html/rfc5521#section-2.1.1"> Exclude
24  *      Route Object definition</a>
25  */
26 public class PCEPExcludeRouteObject extends PCEPObject {
27
28     private final boolean fail;
29
30     private final List<ExcludeRouteSubobject> subobjects;
31
32     /**
33      * Constructs Exclude Route Object.
34      *
35      * @param subobjects
36      *            List<PCEPXROSubobject>. Can't be null or empty.
37      * @param fail
38      *            boolean
39      * @param processed
40      *            boolean
41      * @param ignored
42      *            boolean
43      */
44     public PCEPExcludeRouteObject(List<ExcludeRouteSubobject> subobjects, boolean fail, boolean processed, boolean ignored) {
45         super(processed, ignored);
46         if (subobjects == null || subobjects.isEmpty())
47             throw new IllegalArgumentException("Subobjects can't be null or empty.");
48
49         this.fail = fail;
50         this.subobjects = subobjects;
51     }
52
53     /**
54      * Gets list of sub-objects
55      *
56      * @return List<PCEPXROSubobject>. Can't be null or empty.
57      */
58     public List<ExcludeRouteSubobject> getSubobjects() {
59         return this.subobjects;
60     }
61
62     /**
63      * @see <a href="http://tools.ietf.org/html/rfc5521#section-2.1.1"> Exclude
64      *      Route Object definition</a>
65      *
66      * @return if returns true, the requesting PCC requires the computation of a
67      *         new path for an existing TE LSP that has failed
68      */
69     public boolean isFail() {
70         return this.fail;
71     }
72
73         @Override
74         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
75                 toStringHelper.add("fail", this.fail);
76                 toStringHelper.add("subobjects", this.subobjects);
77                 return super.addToStringAttributes(toStringHelper);
78         }
79
80     @Override
81     public int hashCode() {
82         final int prime = 31;
83         int result = super.hashCode();
84         result = prime * result + ((this.subobjects == null) ? 0 : this.subobjects.hashCode());
85         return result;
86     }
87
88     @Override
89     public boolean equals(Object obj) {
90         if (this == obj)
91             return true;
92         if (!super.equals(obj))
93             return false;
94         if (this.getClass() != obj.getClass())
95             return false;
96         final PCEPExcludeRouteObject other = (PCEPExcludeRouteObject) obj;
97         if (this.subobjects == null) {
98             if (other.subobjects != null)
99                 return false;
100         } else if (!this.subobjects.equals(other.subobjects))
101             return false;
102         return true;
103     }
104
105 }