blob: 3fce9803282bbc31609aa6f6db1a1535a440af89 [file] [log] [blame]
Daniele Moro94660a02019-12-02 12:02:07 -08001/*
2 * Copyright 2019-present Open Networking Foundation
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 */
16
17package org.opencord.bng;
18
19import com.google.common.base.MoreObjects;
20import org.onlab.packet.IpAddress;
21import org.onlab.packet.MacAddress;
22import org.onlab.packet.VlanId;
23import org.onosproject.core.ApplicationId;
24import org.onosproject.net.ConnectPoint;
25import org.onosproject.net.behaviour.BngProgrammable;
26
27/**
28 * Abstract implementation of an attachment.
29 */
30public abstract class BngAttachment implements BngProgrammable.Attachment {
31 private final ApplicationId appId;
32 private final VlanId sTag;
33 private final VlanId cTag;
34 private final MacAddress macAddress;
35 private final IpAddress ipAddress;
36 private final boolean lineActivated;
37 private final ConnectPoint oltConnectPoint;
38 private final String onuSerial;
39 private final short qinqTpid;
40
41 /**
42 * Creates a new attachment.
43 *
44 * @param appId The application that created this attachment
45 * @param sTag The VLAN S-TAG
46 * @param cTag The VLAN C-TAG
47 * @param macAddress The MAC address of the attachment
48 * @param ipAddress The IP address of the attachment
49 * @param lineActivated Define if the attachment is active or not
50 * @param oltConnectPoint The connect point of the OLT (UNI port)
51 * @param onuSerial The serial string of the ONU
52 * @param qinqTpid The QinQ Tpid for the packets
53 */
54 BngAttachment(ApplicationId appId, VlanId sTag, VlanId cTag,
55 MacAddress macAddress, IpAddress ipAddress,
56 boolean lineActivated, ConnectPoint oltConnectPoint,
57 String onuSerial, short qinqTpid) {
58 this.appId = appId;
59 this.sTag = sTag;
60 this.cTag = cTag;
61 this.macAddress = macAddress;
62 this.ipAddress = ipAddress;
63 this.lineActivated = lineActivated;
64 this.oltConnectPoint = oltConnectPoint;
65 this.onuSerial = onuSerial;
66 this.qinqTpid = qinqTpid;
67 }
68
69 /**
70 * Returns the OLT connect point (UNI port).
71 *
72 * @return The OLT connect point
73 */
74 public ConnectPoint oltConnectPoint() {
75 return this.oltConnectPoint;
76 }
77
78 /**
79 * Returns the ONU serial number.
80 *
81 * @return The ONU serial number
82 */
83 public String onuSerial() {
84 return this.onuSerial;
85 }
86
87 /**
88 * Returns the QinQ TPID.
89 *
90 * @return The QinQ TPID
91 */
92 public short qinqTpid() {
93 return this.qinqTpid;
94 }
95
96 @Override
97 public ApplicationId appId() {
98 return appId;
99 }
100
101 @Override
102 public VlanId sTag() {
103 return sTag;
104 }
105
106 @Override
107 public VlanId cTag() {
108 return cTag;
109 }
110
111 @Override
112 public MacAddress macAddress() {
113 return macAddress;
114 }
115
116 @Override
117 public IpAddress ipAddress() {
118 return ipAddress;
119 }
120
121 @Override
122 public boolean lineActive() {
123 return lineActivated;
124 }
125
126 MoreObjects.ToStringHelper toStringHelper() {
127 return MoreObjects.toStringHelper(this)
128 .add("appId", appId)
129 .add("sTag", sTag)
130 .add("cTag", cTag)
131 .add("macAddress", macAddress)
132 .add("ipAddress", ipAddress)
133 .add("lineActivated", lineActivated)
134 .add("oltConnectPoint", oltConnectPoint)
135 .add("onuSerial", onuSerial)
136 .add("qinqTpid", qinqTpid);
137 }
138
139 /**
140 * Abstract builder of attachments.
141 * <p>
142 * TODO: javadoc
143 */
144 public abstract static class BngBuilder {
145 ApplicationId appId;
146 VlanId sTag;
147 VlanId cTag;
148 MacAddress macAddress;
149 IpAddress ipAddress = IpAddress.valueOf(0);
150 boolean lineActivated;
151 ConnectPoint oltconnectPoint;
152 String onuSerial;
153 short qinqTpid;
154
155 BngBuilder() {
156 // Hide constructor
157 this.lineActivated = false;
158 }
159
160 /**
161 * Sets the ONU serial number.
162 *
163 * @param onuSerial The ONU serial number
164 * @return self
165 */
166 public BngBuilder withOnuSerial(String onuSerial) {
167 this.onuSerial = onuSerial;
168 return this;
169 }
170
171 /**
172 * Sets the OLT connect point (UNI port).
173 *
174 * @param oltconnectPoint The OLT connect point
175 * @return self
176 */
177 public BngBuilder withOltConnectPoint(ConnectPoint oltconnectPoint) {
178 this.oltconnectPoint = oltconnectPoint;
179 return this;
180 }
181
182 /**
183 * Sets the VLAN S-Tag.
184 *
185 * @param sTag The VLAN S-Tag
186 * @return self
187 */
188 public BngBuilder withSTag(VlanId sTag) {
189 this.sTag = sTag;
190 return this;
191 }
192
193 /**
194 * Sets the VLAN C-Tag.
195 *
196 * @param cTag the VLAN C-Tag
197 * @return self
198 */
199 public BngBuilder withCTag(VlanId cTag) {
200 this.cTag = cTag;
201 return this;
202 }
203
204 /**
205 * Sets the attachment activation state.
206 *
207 * @param lineActivated The attachment activation state
208 * @return self
209 */
210 public BngBuilder lineActivated(boolean lineActivated) {
211 this.lineActivated = lineActivated;
212 return this;
213 }
214
215 /**
216 * Sets the application ID.
217 *
218 * @param appId The application ID.
219 * @return self
220 */
221 public BngBuilder withApplicationId(ApplicationId appId) {
222 this.appId = appId;
223 return this;
224 }
225
226 /**
227 * Sets the attachment MAC address.
228 *
229 * @param macAddress The MAC address
230 * @return self
231 */
232 public BngBuilder withMacAddress(MacAddress macAddress) {
233 this.macAddress = macAddress;
234 return this;
235 }
236
237 /**
238 * Sets the attachment IP address.
239 *
240 * @param ipAddress The IP address
241 * @return self
242 */
243 public BngBuilder withIpAddress(IpAddress ipAddress) {
244 this.ipAddress = ipAddress;
245 return this;
246 }
247
248 /**
249 * Sets the QinQ tpid.
250 *
251 * @param qinqTpid The QinQ tpid
252 * @return self
253 */
254 public BngBuilder withQinqTpid(short qinqTpid) {
255 this.qinqTpid = qinqTpid;
256 return this;
257 }
258
259 /**
260 * Returns a new BNG attachment.
261 *
262 * @return BNG attachment
263 */
264 public abstract BngAttachment build();
265 }
266}