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