blob: 3f6f9e98b49879424c36de3738d9431b8e01e864 [file] [log] [blame]
Daniele Moro464e5ed2019-07-25 14:45:01 -07001/*
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.onosproject.net.behaviour;
18
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.MacAddress;
21import org.onlab.packet.VlanId;
22import org.onlab.util.Identifier;
23import org.onosproject.core.ApplicationId;
24import org.onosproject.net.driver.HandlerBehaviour;
25import org.onosproject.net.pi.runtime.PiCounterCellData;
26
27import 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 */
36public 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 */
Daniele Moro893988e2019-11-27 16:14:38 -080057 void cleanUp(ApplicationId appId)
58 throws BngProgrammableException;
Daniele Moro464e5ed2019-07-25 14:45:01 -070059
60 /**
61 * Set up the necessary state to enable termination of the attachment
Daniele Moro893988e2019-11-27 16:14:38 -080062 * traffic. If the attachment is active, packets will be
63 * forwarded/terminated after calling this method, if not they will be
64 * dropped. State, if already present in the data plane, will not be cleaned
65 * (e.g., counters).
Daniele Moro464e5ed2019-07-25 14:45:01 -070066 *
67 * @param attachmentInfo Attachment information to configure the line
68 * termination.
69 * @throws BngProgrammableException while writing on BNG device.
70 */
71 void setupAttachment(Attachment attachmentInfo)
72 throws BngProgrammableException;
73
74 /**
75 * Remove any state associated with the given attachment, including
76 * termination flow rules. Calling this method while an attachment is
77 * generating/receiving traffic, will eventually cause all packets to be
78 * dropped for that attachment.
79 *
80 * @param attachmentInfo Attachment information to remove the line
81 * termination.
Daniele Moro893988e2019-11-27 16:14:38 -080082 * @throws BngProgrammableException while writing on BNG device.
Daniele Moro464e5ed2019-07-25 14:45:01 -070083 */
Daniele Moro893988e2019-11-27 16:14:38 -080084 void removeAttachment(Attachment attachmentInfo)
85 throws BngProgrammableException;
Daniele Moro464e5ed2019-07-25 14:45:01 -070086
87 /**
88 * Read all counters for a given attachment and returns a map with keys
89 * BngCounterType and values the ones obtained from the device. If a
90 * specific BngCounterType is not found in the map, it means the device does
91 * not support it.
92 *
93 * @param attachmentInfo Attachment information.
94 * @return The counter values of the attachment.
95 * @throws BngProgrammableException while reading from BNG device.
96 */
97 Map<BngCounterType, PiCounterCellData> readCounters(Attachment attachmentInfo)
98 throws BngProgrammableException;
99
100 /**
101 * Read a specific counter value of a specific attachment. If the given
102 * BngCounterType is not supported by the device, returns null.
103 *
104 * @param attachmentInfo Attachment information.
105 * @param counter The counter to be read.
106 * @return The value of the specific counter.
107 * @throws BngProgrammableException while reading from BNG device.
108 */
109 PiCounterCellData readCounter(Attachment attachmentInfo, BngCounterType counter)
110 throws BngProgrammableException;
111
112 /**
113 * Read the control plane traffic counter of packets punted before
114 * attachment creation (e.g., when an attachment is not created yet). If
115 * unsupported, return null value.
116 *
117 * @return The value of the control traffic counter.
118 * @throws BngProgrammableException while reading from BNG device.
119 */
120 PiCounterCellData readControlTrafficCounter()
121 throws BngProgrammableException;
122
123 /**
124 * Reset the given counter of a specific attachment.
125 *
126 * @param attachmentInfo Attachment information.
127 * @param counter The counter to be reset.
128 * @throws BngProgrammableException while writing on BNG device.
129 */
130 void resetCounter(Attachment attachmentInfo, BngCounterType counter)
131 throws BngProgrammableException;
132
133 /**
134 * Reset the all the counters of a specific attachment.
135 *
136 * @param attachmentInfo Attachment information.
137 * @throws BngProgrammableException while writing on BNG device.
138 */
139 void resetCounters(Attachment attachmentInfo)
140 throws BngProgrammableException;
141
142 /**
143 * Reset the control plane traffic counter of packets punted before
144 * attachment creation (e.g., when an attachment is not created yet).
145 *
146 * @throws BngProgrammableException while writing on BNG device.
147 */
148 void resetControlTrafficCounter()
149 throws BngProgrammableException;
150
151 /**
152 * Counters to implement BNG accounting. Some of these counters can be
153 * unsupported by the implementations.
154 */
155 enum BngCounterType {
156 /**
157 * Count the received packets in the downstream direction.
158 */
159 DOWNSTREAM_RX,
160
161 /**
162 * Count the transmitted packets in the downstream direction.
163 */
164 DOWNSTREAM_TX,
165
166 /**
167 * Count the dropped packets in the downstream direction.
168 */
169 DOWNSTREAM_DROPPED,
170
171 /**
172 * Count the received packets in the upstream direction.
173 */
174 UPSTREAM_RX,
175
176 /**
177 * Count the transmitted packets in the upstream direction.
178 */
179 UPSTREAM_TX,
180
181 /**
182 * Count the dropped packets in the upstream direction.
183 */
184 UPSTREAM_DROPPED,
185
186 /**
187 * Count the received control plane packets.
188 */
189 CONTROL_PLANE
190 }
191
192 /**
193 * Immutable representation of an attachment in the BNG context. It
194 * identifies a L2/L2.5 tunnel line between the RG and the BNG.
195 */
196 interface Attachment {
197 /**
198 * Get the identifier of the attachment.
199 *
200 * @return The identifier of the attachment.
201 */
202 AttachmentId attachmentId();
203
204 /**
205 * Get the application ID that generated the attachment.
206 *
207 * @return The application ID.
208 */
209 ApplicationId appId();
210
211 /**
212 * Get the VLAN S-tag of the attachment.
213 *
214 * @return The VLAN S-tag of the attachment.
215 */
216 VlanId sTag();
217
218 /**
219 * Get the VLAN C-tag of the attachment.
220 *
221 * @return The VLAN C-tag of the attachment.
222 */
223 VlanId cTag();
224
225 /**
226 * Get the MAC address of the attachment.
227 *
228 * @return The MAC address of the attachment.
229 */
230 MacAddress macAddress();
231
232 /**
233 * Get the IP address of the attachment.
234 *
235 * @return The IP address of the attachment.
236 */
237 IpAddress ipAddress();
238
239 /**
240 * Defines if the line related to the attachment is active.
241 *
242 * @return True if the line is active, False otherwise.
243 */
244 boolean lineActive();
245
246 /**
247 * Get the type of attachment.
248 *
249 * @return type of attachment
250 */
251 AttachmentType type();
252
253 /**
254 * Get the PPPoE session ID of the attachment. This method is meaningful
255 * only if the attachment type is PPPoE.
256 *
257 * @return The PPPoE session ID.
258 */
259 short pppoeSessionId();
260
261 enum AttachmentType {
262 /**
263 * Implemented as PPPoE attachment.
264 */
265 PPPoE,
266
267 /**
268 * Implemented as IPoE attachment.
269 */
270 // TODO: unsupported.
271 IPoE
272 }
273 }
274
275 /**
276 * The identifier of the attachment.
277 */
278 class AttachmentId extends Identifier<Long> {
279 /**
280 * Identifies the attachment at network level.
281 *
282 * @param id long value
283 */
284 public AttachmentId(long id) {
285 super(id);
286 }
287 }
288
289 /**
290 * An exception indicating a an error happened in the BNG programmable
291 * behaviour.
292 */
293 class BngProgrammableException extends Exception {
294 /**
295 * Creates a new exception for the given message.
296 *
297 * @param message message
298 */
299 public BngProgrammableException(String message) {
300 super(message);
301 }
302 }
303}
304
305