|
| 1 | +/* |
| 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 | + |
| 17 | +package org.onosproject.net.behaviour; |
| 18 | + |
| 19 | +import org.onlab.packet.IpAddress; |
| 20 | +import org.onlab.packet.MacAddress; |
| 21 | +import org.onlab.packet.VlanId; |
| 22 | +import org.onlab.util.Identifier; |
| 23 | +import org.onosproject.core.ApplicationId; |
| 24 | +import org.onosproject.net.driver.HandlerBehaviour; |
| 25 | +import org.onosproject.net.pi.runtime.PiCounterCellData; |
| 26 | + |
| 27 | +import java.util.Map; |
| 28 | + |
| 29 | +/** |
| 30 | + * BNG programmable behavior. Provides means to update device forwarding state |
| 31 | + * to perform BNG user plane functions (e.g., tunnel termination, accounting, |
| 32 | + * etc.). An implementation of this API should not write state directly to the |
| 33 | + * device, but instead, always rely on core ONOS subsystems (e.g., |
| 34 | + * FlowRuleService, GroupService, etc). |
| 35 | + */ |
| 36 | +public interface BngProgrammable extends HandlerBehaviour { |
| 37 | + |
| 38 | + /** |
| 39 | + * Provision rules to punt BNG control packets to ONOS. Control packets |
| 40 | + * might include Session Discovery, Authentication, Address Assignment etc. |
| 41 | + * Apps are expected to call this method as the first one when they are |
| 42 | + * ready to process attachment connection requests. |
| 43 | + * |
| 44 | + * @param appId Application ID of the caller of this API. |
| 45 | + * @return True if initialized, false otherwise. |
| 46 | + */ |
| 47 | + boolean init(ApplicationId appId); |
| 48 | + |
| 49 | + /** |
| 50 | + * Remove any state previously created by this API for the given application |
| 51 | + * ID. |
| 52 | + * |
| 53 | + * @param appId Application ID of the application using the |
| 54 | + * BngProgrammable. |
| 55 | + * @throws BngProgrammableException while writing on BNG device. |
| 56 | + */ |
| 57 | + void cleanUp(ApplicationId appId) throws BngProgrammableException; |
| 58 | + |
| 59 | + /** |
| 60 | + * Set up the necessary state to enable termination of the attachment |
| 61 | + * traffic. Make also sure that the state of the given attachment is cleaned |
| 62 | + * up. If the attachment is active, packets will be forwarded/terminated |
| 63 | + * after calling this method, if not they will be dropped. |
| 64 | + * |
| 65 | + * @param attachmentInfo Attachment information to configure the line |
| 66 | + * termination. |
| 67 | + * @throws BngProgrammableException while writing on BNG device. |
| 68 | + */ |
| 69 | + void setupAttachment(Attachment attachmentInfo) |
| 70 | + throws BngProgrammableException; |
| 71 | + |
| 72 | + /** |
| 73 | + * Remove any state associated with the given attachment, including |
| 74 | + * termination flow rules. Calling this method while an attachment is |
| 75 | + * generating/receiving traffic, will eventually cause all packets to be |
| 76 | + * dropped for that attachment. |
| 77 | + * |
| 78 | + * @param attachmentInfo Attachment information to remove the line |
| 79 | + * termination. |
| 80 | + */ |
| 81 | + void removeAttachment(Attachment attachmentInfo); |
| 82 | + |
| 83 | + /** |
| 84 | + * Read all counters for a given attachment and returns a map with keys |
| 85 | + * BngCounterType and values the ones obtained from the device. If a |
| 86 | + * specific BngCounterType is not found in the map, it means the device does |
| 87 | + * not support it. |
| 88 | + * |
| 89 | + * @param attachmentInfo Attachment information. |
| 90 | + * @return The counter values of the attachment. |
| 91 | + * @throws BngProgrammableException while reading from BNG device. |
| 92 | + */ |
| 93 | + Map<BngCounterType, PiCounterCellData> readCounters(Attachment attachmentInfo) |
| 94 | + throws BngProgrammableException; |
| 95 | + |
| 96 | + /** |
| 97 | + * Read a specific counter value of a specific attachment. If the given |
| 98 | + * BngCounterType is not supported by the device, returns null. |
| 99 | + * |
| 100 | + * @param attachmentInfo Attachment information. |
| 101 | + * @param counter The counter to be read. |
| 102 | + * @return The value of the specific counter. |
| 103 | + * @throws BngProgrammableException while reading from BNG device. |
| 104 | + */ |
| 105 | + PiCounterCellData readCounter(Attachment attachmentInfo, BngCounterType counter) |
| 106 | + throws BngProgrammableException; |
| 107 | + |
| 108 | + /** |
| 109 | + * Read the control plane traffic counter of packets punted before |
| 110 | + * attachment creation (e.g., when an attachment is not created yet). If |
| 111 | + * unsupported, return null value. |
| 112 | + * |
| 113 | + * @return The value of the control traffic counter. |
| 114 | + * @throws BngProgrammableException while reading from BNG device. |
| 115 | + */ |
| 116 | + PiCounterCellData readControlTrafficCounter() |
| 117 | + throws BngProgrammableException; |
| 118 | + |
| 119 | + /** |
| 120 | + * Reset the given counter of a specific attachment. |
| 121 | + * |
| 122 | + * @param attachmentInfo Attachment information. |
| 123 | + * @param counter The counter to be reset. |
| 124 | + * @throws BngProgrammableException while writing on BNG device. |
| 125 | + */ |
| 126 | + void resetCounter(Attachment attachmentInfo, BngCounterType counter) |
| 127 | + throws BngProgrammableException; |
| 128 | + |
| 129 | + /** |
| 130 | + * Reset the all the counters of a specific attachment. |
| 131 | + * |
| 132 | + * @param attachmentInfo Attachment information. |
| 133 | + * @throws BngProgrammableException while writing on BNG device. |
| 134 | + */ |
| 135 | + void resetCounters(Attachment attachmentInfo) |
| 136 | + throws BngProgrammableException; |
| 137 | + |
| 138 | + /** |
| 139 | + * Reset the control plane traffic counter of packets punted before |
| 140 | + * attachment creation (e.g., when an attachment is not created yet). |
| 141 | + * |
| 142 | + * @throws BngProgrammableException while writing on BNG device. |
| 143 | + */ |
| 144 | + void resetControlTrafficCounter() |
| 145 | + throws BngProgrammableException; |
| 146 | + |
| 147 | + /** |
| 148 | + * Counters to implement BNG accounting. Some of these counters can be |
| 149 | + * unsupported by the implementations. |
| 150 | + */ |
| 151 | + enum BngCounterType { |
| 152 | + /** |
| 153 | + * Count the received packets in the downstream direction. |
| 154 | + */ |
| 155 | + DOWNSTREAM_RX, |
| 156 | + |
| 157 | + /** |
| 158 | + * Count the transmitted packets in the downstream direction. |
| 159 | + */ |
| 160 | + DOWNSTREAM_TX, |
| 161 | + |
| 162 | + /** |
| 163 | + * Count the dropped packets in the downstream direction. |
| 164 | + */ |
| 165 | + DOWNSTREAM_DROPPED, |
| 166 | + |
| 167 | + /** |
| 168 | + * Count the received packets in the upstream direction. |
| 169 | + */ |
| 170 | + UPSTREAM_RX, |
| 171 | + |
| 172 | + /** |
| 173 | + * Count the transmitted packets in the upstream direction. |
| 174 | + */ |
| 175 | + UPSTREAM_TX, |
| 176 | + |
| 177 | + /** |
| 178 | + * Count the dropped packets in the upstream direction. |
| 179 | + */ |
| 180 | + UPSTREAM_DROPPED, |
| 181 | + |
| 182 | + /** |
| 183 | + * Count the received control plane packets. |
| 184 | + */ |
| 185 | + CONTROL_PLANE |
| 186 | + } |
| 187 | + |
| 188 | + /** |
| 189 | + * Immutable representation of an attachment in the BNG context. It |
| 190 | + * identifies a L2/L2.5 tunnel line between the RG and the BNG. |
| 191 | + */ |
| 192 | + interface Attachment { |
| 193 | + /** |
| 194 | + * Get the identifier of the attachment. |
| 195 | + * |
| 196 | + * @return The identifier of the attachment. |
| 197 | + */ |
| 198 | + AttachmentId attachmentId(); |
| 199 | + |
| 200 | + /** |
| 201 | + * Get the application ID that generated the attachment. |
| 202 | + * |
| 203 | + * @return The application ID. |
| 204 | + */ |
| 205 | + ApplicationId appId(); |
| 206 | + |
| 207 | + /** |
| 208 | + * Get the VLAN S-tag of the attachment. |
| 209 | + * |
| 210 | + * @return The VLAN S-tag of the attachment. |
| 211 | + */ |
| 212 | + VlanId sTag(); |
| 213 | + |
| 214 | + /** |
| 215 | + * Get the VLAN C-tag of the attachment. |
| 216 | + * |
| 217 | + * @return The VLAN C-tag of the attachment. |
| 218 | + */ |
| 219 | + VlanId cTag(); |
| 220 | + |
| 221 | + /** |
| 222 | + * Get the MAC address of the attachment. |
| 223 | + * |
| 224 | + * @return The MAC address of the attachment. |
| 225 | + */ |
| 226 | + MacAddress macAddress(); |
| 227 | + |
| 228 | + /** |
| 229 | + * Get the IP address of the attachment. |
| 230 | + * |
| 231 | + * @return The IP address of the attachment. |
| 232 | + */ |
| 233 | + IpAddress ipAddress(); |
| 234 | + |
| 235 | + /** |
| 236 | + * Defines if the line related to the attachment is active. |
| 237 | + * |
| 238 | + * @return True if the line is active, False otherwise. |
| 239 | + */ |
| 240 | + boolean lineActive(); |
| 241 | + |
| 242 | + /** |
| 243 | + * Get the type of attachment. |
| 244 | + * |
| 245 | + * @return type of attachment |
| 246 | + */ |
| 247 | + AttachmentType type(); |
| 248 | + |
| 249 | + /** |
| 250 | + * Get the PPPoE session ID of the attachment. This method is meaningful |
| 251 | + * only if the attachment type is PPPoE. |
| 252 | + * |
| 253 | + * @return The PPPoE session ID. |
| 254 | + */ |
| 255 | + short pppoeSessionId(); |
| 256 | + |
| 257 | + enum AttachmentType { |
| 258 | + /** |
| 259 | + * Implemented as PPPoE attachment. |
| 260 | + */ |
| 261 | + PPPoE, |
| 262 | + |
| 263 | + /** |
| 264 | + * Implemented as IPoE attachment. |
| 265 | + */ |
| 266 | + // TODO: unsupported. |
| 267 | + IPoE |
| 268 | + } |
| 269 | + } |
| 270 | + |
| 271 | + /** |
| 272 | + * The identifier of the attachment. |
| 273 | + */ |
| 274 | + class AttachmentId extends Identifier<Long> { |
| 275 | + /** |
| 276 | + * Identifies the attachment at network level. |
| 277 | + * |
| 278 | + * @param id long value |
| 279 | + */ |
| 280 | + public AttachmentId(long id) { |
| 281 | + super(id); |
| 282 | + } |
| 283 | + } |
| 284 | + |
| 285 | + /** |
| 286 | + * An exception indicating a an error happened in the BNG programmable |
| 287 | + * behaviour. |
| 288 | + */ |
| 289 | + class BngProgrammableException extends Exception { |
| 290 | + /** |
| 291 | + * Creates a new exception for the given message. |
| 292 | + * |
| 293 | + * @param message message |
| 294 | + */ |
| 295 | + public BngProgrammableException(String message) { |
| 296 | + super(message); |
| 297 | + } |
| 298 | + } |
| 299 | +} |
| 300 | + |
| 301 | + |
0 commit comments