blob: cdad3b288290aa6573fc3e549ba1f944050550f5 [file] [log] [blame]
Mahesh Poojary Sba827292016-05-09 11:31:12 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.pce.pcestore;
17
18import com.google.common.base.MoreObjects;
19
20import java.util.Objects;
21
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.PortNumber;
24import org.onosproject.incubator.net.resource.label.LabelResourceId;
25import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
26
27/**
28 * Local node details including IN and OUT labels as well as IN and OUT port details.
29 */
30public final class DefaultLspLocalLabelInfo implements LspLocalLabelInfo {
31
32 private final DeviceId deviceId;
33
34 private final LabelResourceId inLabelId;
35
36 private final LabelResourceId outLabelId;
37
38 private final PortNumber inPort;
39
40 private final PortNumber outPort;
41
42 /**
43 * Initialization of member variables.
44 *
45 * @param deviceId device id
46 * @param inLabelId in label id of a node
47 * @param outLabelId out label id of a node
48 * @param inPort input port
49 * @param outPort remote port
50 */
51 private DefaultLspLocalLabelInfo(DeviceId deviceId,
52 LabelResourceId inLabelId,
53 LabelResourceId outLabelId,
54 PortNumber inPort,
55 PortNumber outPort) {
56 this.deviceId = deviceId;
57 this.inLabelId = inLabelId;
58 this.outLabelId = outLabelId;
59 this.inPort = inPort;
60 this.outPort = outPort;
61 }
62
63 /**
64 * Initialization of member variables for serialization.
65 */
66 private DefaultLspLocalLabelInfo() {
67 this.deviceId = null;
68 this.inLabelId = null;
69 this.outLabelId = null;
70 this.inPort = null;
71 this.outPort = null;
72 }
73
74 @Override
75 public DeviceId deviceId() {
76 return deviceId;
77 }
78
79 @Override
80 public LabelResourceId inLabelId() {
81 return inLabelId;
82 }
83
84 @Override
85 public LabelResourceId outLabelId() {
86 return outLabelId;
87 }
88
89 @Override
90 public PortNumber inPort() {
91 return inPort;
92 }
93
94 @Override
95 public PortNumber outPort() {
96 return outPort;
97 }
98
99 @Override
100 public int hashCode() {
101 return Objects.hash(deviceId, inLabelId, outLabelId, inPort, outPort);
102 }
103
104 @Override
105 public boolean equals(Object obj) {
106 if (this == obj) {
107 return true;
108 }
109 if (obj instanceof LspLocalLabelInfo) {
110 final DefaultLspLocalLabelInfo other = (DefaultLspLocalLabelInfo) obj;
111 return Objects.equals(this.deviceId, other.deviceId) &&
112 Objects.equals(this.inLabelId, other.inLabelId) &&
113 Objects.equals(this.outLabelId, other.outLabelId) &&
114 Objects.equals(this.inPort, other.inPort) &&
115 Objects.equals(this.outPort, other.outPort);
116 }
117 return false;
118 }
119
120 @Override
121 public String toString() {
122 return MoreObjects.toStringHelper(getClass())
123 .omitNullValues()
Priyanka B844ee052016-08-16 12:12:19 +0530124 .add("DeviceId", deviceId)
125 .add("InLabelId", inLabelId)
126 .add("OutLabelId", outLabelId)
127 .add("InPort", inPort)
128 .add("OutPort", outPort)
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530129 .toString();
130 }
131
132 /**
133 * Creates and returns a new builder instance that clones an existing object.
134 *
135 * @param deviceLabelInfo device label information
136 * @return new builder
137 */
138 public static Builder builder(LspLocalLabelInfo deviceLabelInfo) {
139 return new Builder(deviceLabelInfo);
140 }
141
142 /**
143 * Creates and returns a new builder instance.
144 *
145 * @return new builder
146 */
147 public static Builder builder() {
148 return new Builder();
149 }
150
151 /**
152 * Builder.
153 */
154 public static final class Builder implements LspLocalLabelInfo.Builder {
155
156 private DeviceId deviceId;
157
158 private LabelResourceId inLabelId;
159
160 private LabelResourceId outLabelId;
161
162 private PortNumber inPort;
163
164 private PortNumber outPort;
165
166 /**
167 * Constructs default builder.
168 */
169 private Builder() {
170 }
171
172 /**
173 * Initializes member variables with existing object.
174 */
175 private Builder(LspLocalLabelInfo deviceLabelInfo) {
176 this.deviceId = deviceLabelInfo.deviceId();
177 this.inLabelId = deviceLabelInfo.inLabelId();
178 this.outLabelId = deviceLabelInfo.outLabelId();
179 this.inPort = deviceLabelInfo.inPort();
180 this.outPort = deviceLabelInfo.outPort();
181 }
182
183 @Override
184 public Builder deviceId(DeviceId id) {
185 this.deviceId = id;
186 return this;
187 }
188
189 @Override
190 public Builder inLabelId(LabelResourceId id) {
191 this.inLabelId = id;
192 return this;
193 }
194
195 @Override
196 public Builder outLabelId(LabelResourceId id) {
197 this.outLabelId = id;
198 return this;
199 }
200
201 @Override
202 public Builder inPort(PortNumber port) {
203 this.inPort = port;
204 return this;
205 }
206
207 @Override
208 public Builder outPort(PortNumber port) {
209 this.outPort = port;
210 return this;
211 }
212
213 @Override
214 public LspLocalLabelInfo build() {
215 return new DefaultLspLocalLabelInfo(deviceId, inLabelId, outLabelId, inPort, outPort);
216 }
217 }
218}