Daniele Moro | 94660a0 | 2019-12-02 12:02:07 -0800 | [diff] [blame] | 1 | /* |
Joey Armstrong | a68e785 | 2024-01-28 13:27:02 -0500 | [diff] [blame] | 2 | * Copyright 2019-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Daniele Moro | 94660a0 | 2019-12-02 12:02:07 -0800 | [diff] [blame] | 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 | |
| 17 | package org.opencord.bng; |
| 18 | |
| 19 | import com.google.common.base.MoreObjects; |
| 20 | import org.onlab.packet.IpAddress; |
| 21 | import org.onlab.packet.MacAddress; |
| 22 | import org.onlab.packet.VlanId; |
| 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.net.ConnectPoint; |
| 25 | import org.onosproject.net.behaviour.BngProgrammable; |
| 26 | |
| 27 | /** |
| 28 | * Abstract implementation of an attachment. |
| 29 | */ |
| 30 | public 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. |
Daniele Moro | 94660a0 | 2019-12-02 12:02:07 -0800 | [diff] [blame] | 141 | */ |
| 142 | public abstract static class BngBuilder { |
| 143 | ApplicationId appId; |
| 144 | VlanId sTag; |
| 145 | VlanId cTag; |
| 146 | MacAddress macAddress; |
| 147 | IpAddress ipAddress = IpAddress.valueOf(0); |
| 148 | boolean lineActivated; |
| 149 | ConnectPoint oltconnectPoint; |
| 150 | String onuSerial; |
| 151 | short qinqTpid; |
| 152 | |
| 153 | BngBuilder() { |
| 154 | // Hide constructor |
| 155 | this.lineActivated = false; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Sets the ONU serial number. |
| 160 | * |
| 161 | * @param onuSerial The ONU serial number |
| 162 | * @return self |
| 163 | */ |
| 164 | public BngBuilder withOnuSerial(String onuSerial) { |
| 165 | this.onuSerial = onuSerial; |
| 166 | return this; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Sets the OLT connect point (UNI port). |
| 171 | * |
| 172 | * @param oltconnectPoint The OLT connect point |
| 173 | * @return self |
| 174 | */ |
| 175 | public BngBuilder withOltConnectPoint(ConnectPoint oltconnectPoint) { |
| 176 | this.oltconnectPoint = oltconnectPoint; |
| 177 | return this; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Sets the VLAN S-Tag. |
| 182 | * |
| 183 | * @param sTag The VLAN S-Tag |
| 184 | * @return self |
| 185 | */ |
| 186 | public BngBuilder withSTag(VlanId sTag) { |
| 187 | this.sTag = sTag; |
| 188 | return this; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Sets the VLAN C-Tag. |
| 193 | * |
| 194 | * @param cTag the VLAN C-Tag |
| 195 | * @return self |
| 196 | */ |
| 197 | public BngBuilder withCTag(VlanId cTag) { |
| 198 | this.cTag = cTag; |
| 199 | return this; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Sets the attachment activation state. |
| 204 | * |
| 205 | * @param lineActivated The attachment activation state |
| 206 | * @return self |
| 207 | */ |
| 208 | public BngBuilder lineActivated(boolean lineActivated) { |
| 209 | this.lineActivated = lineActivated; |
| 210 | return this; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Sets the application ID. |
| 215 | * |
| 216 | * @param appId The application ID. |
| 217 | * @return self |
| 218 | */ |
| 219 | public BngBuilder withApplicationId(ApplicationId appId) { |
| 220 | this.appId = appId; |
| 221 | return this; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Sets the attachment MAC address. |
| 226 | * |
| 227 | * @param macAddress The MAC address |
| 228 | * @return self |
| 229 | */ |
| 230 | public BngBuilder withMacAddress(MacAddress macAddress) { |
| 231 | this.macAddress = macAddress; |
| 232 | return this; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Sets the attachment IP address. |
| 237 | * |
| 238 | * @param ipAddress The IP address |
| 239 | * @return self |
| 240 | */ |
| 241 | public BngBuilder withIpAddress(IpAddress ipAddress) { |
| 242 | this.ipAddress = ipAddress; |
| 243 | return this; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Sets the QinQ tpid. |
| 248 | * |
| 249 | * @param qinqTpid The QinQ tpid |
| 250 | * @return self |
| 251 | */ |
| 252 | public BngBuilder withQinqTpid(short qinqTpid) { |
| 253 | this.qinqTpid = qinqTpid; |
| 254 | return this; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Returns a new BNG attachment. |
| 259 | * |
| 260 | * @return BNG attachment |
| 261 | */ |
| 262 | public abstract BngAttachment build(); |
| 263 | } |
| 264 | } |