blob: be262f06cbaf0cf2582afe8d67fcd7d37ee9ba49 [file] [log] [blame]
Mahesh Poojary Sba827292016-05-09 11:31:12 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Mahesh Poojary Sba827292016-05-09 11:31:12 +05303 *
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 */
Avantika-Huawei9e848e82016-09-01 12:12:42 +053016package org.onosproject.pcelabelstore;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053017
18import com.google.common.base.MoreObjects;
19
20import java.util.Objects;
21
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.PortNumber;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053024import org.onosproject.pcelabelstore.api.LspLocalLabelInfo;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053025import org.onosproject.incubator.net.resource.label.LabelResourceId;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053026
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;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053033 private final LabelResourceId inLabelId;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053034 private final LabelResourceId outLabelId;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053035 private final PortNumber inPort;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053036 private final PortNumber outPort;
37
38 /**
39 * Initialization of member variables.
40 *
41 * @param deviceId device id
42 * @param inLabelId in label id of a node
43 * @param outLabelId out label id of a node
44 * @param inPort input port
45 * @param outPort remote port
46 */
47 private DefaultLspLocalLabelInfo(DeviceId deviceId,
48 LabelResourceId inLabelId,
49 LabelResourceId outLabelId,
50 PortNumber inPort,
51 PortNumber outPort) {
52 this.deviceId = deviceId;
53 this.inLabelId = inLabelId;
54 this.outLabelId = outLabelId;
55 this.inPort = inPort;
56 this.outPort = outPort;
57 }
58
59 /**
60 * Initialization of member variables for serialization.
61 */
62 private DefaultLspLocalLabelInfo() {
63 this.deviceId = null;
64 this.inLabelId = null;
65 this.outLabelId = null;
66 this.inPort = null;
67 this.outPort = null;
68 }
69
70 @Override
71 public DeviceId deviceId() {
72 return deviceId;
73 }
74
75 @Override
76 public LabelResourceId inLabelId() {
77 return inLabelId;
78 }
79
80 @Override
81 public LabelResourceId outLabelId() {
82 return outLabelId;
83 }
84
85 @Override
86 public PortNumber inPort() {
87 return inPort;
88 }
89
90 @Override
91 public PortNumber outPort() {
92 return outPort;
93 }
94
95 @Override
96 public int hashCode() {
97 return Objects.hash(deviceId, inLabelId, outLabelId, inPort, outPort);
98 }
99
100 @Override
101 public boolean equals(Object obj) {
102 if (this == obj) {
103 return true;
104 }
105 if (obj instanceof LspLocalLabelInfo) {
106 final DefaultLspLocalLabelInfo other = (DefaultLspLocalLabelInfo) obj;
107 return Objects.equals(this.deviceId, other.deviceId) &&
108 Objects.equals(this.inLabelId, other.inLabelId) &&
109 Objects.equals(this.outLabelId, other.outLabelId) &&
110 Objects.equals(this.inPort, other.inPort) &&
111 Objects.equals(this.outPort, other.outPort);
112 }
113 return false;
114 }
115
116 @Override
117 public String toString() {
118 return MoreObjects.toStringHelper(getClass())
119 .omitNullValues()
Priyanka B844ee052016-08-16 12:12:19 +0530120 .add("DeviceId", deviceId)
121 .add("InLabelId", inLabelId)
122 .add("OutLabelId", outLabelId)
123 .add("InPort", inPort)
124 .add("OutPort", outPort)
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530125 .toString();
126 }
127
128 /**
129 * Creates and returns a new builder instance that clones an existing object.
130 *
131 * @param deviceLabelInfo device label information
132 * @return new builder
133 */
134 public static Builder builder(LspLocalLabelInfo deviceLabelInfo) {
135 return new Builder(deviceLabelInfo);
136 }
137
138 /**
139 * Creates and returns a new builder instance.
140 *
141 * @return new builder
142 */
143 public static Builder builder() {
144 return new Builder();
145 }
146
147 /**
148 * Builder.
149 */
150 public static final class Builder implements LspLocalLabelInfo.Builder {
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530151 private DeviceId deviceId;
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530152 private LabelResourceId inLabelId;
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530153 private LabelResourceId outLabelId;
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530154 private PortNumber inPort;
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530155 private PortNumber outPort;
156
157 /**
158 * Constructs default builder.
159 */
160 private Builder() {
161 }
162
163 /**
164 * Initializes member variables with existing object.
165 */
166 private Builder(LspLocalLabelInfo deviceLabelInfo) {
167 this.deviceId = deviceLabelInfo.deviceId();
168 this.inLabelId = deviceLabelInfo.inLabelId();
169 this.outLabelId = deviceLabelInfo.outLabelId();
170 this.inPort = deviceLabelInfo.inPort();
171 this.outPort = deviceLabelInfo.outPort();
172 }
173
174 @Override
175 public Builder deviceId(DeviceId id) {
176 this.deviceId = id;
177 return this;
178 }
179
180 @Override
181 public Builder inLabelId(LabelResourceId id) {
182 this.inLabelId = id;
183 return this;
184 }
185
186 @Override
187 public Builder outLabelId(LabelResourceId id) {
188 this.outLabelId = id;
189 return this;
190 }
191
192 @Override
193 public Builder inPort(PortNumber port) {
194 this.inPort = port;
195 return this;
196 }
197
198 @Override
199 public Builder outPort(PortNumber port) {
200 this.outPort = port;
201 return this;
202 }
203
204 @Override
205 public LspLocalLabelInfo build() {
206 return new DefaultLspLocalLabelInfo(deviceId, inLabelId, outLabelId, inPort, outPort);
207 }
208 }
209}