blob: ccf9fb90b1f5e45376279d9a98b87f5c28fd5708 [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;
Daniele Moro464e5ed2019-07-25 14:45:01 -070022import org.onosproject.core.ApplicationId;
23import org.onosproject.net.driver.HandlerBehaviour;
24import org.onosproject.net.pi.runtime.PiCounterCellData;
25
26import 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 */
35public 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 Moro893988e2019-11-27 16:14:38 -080056 void cleanUp(ApplicationId appId)
57 throws BngProgrammableException;
Daniele Moro464e5ed2019-07-25 14:45:01 -070058
59 /**
60 * Set up the necessary state to enable termination of the attachment
Daniele Moro893988e2019-11-27 16:14:38 -080061 * 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 Moro464e5ed2019-07-25 14:45:01 -070065 *
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 Moro893988e2019-11-27 16:14:38 -080081 * @throws BngProgrammableException while writing on BNG device.
Daniele Moro464e5ed2019-07-25 14:45:01 -070082 */
Daniele Moro893988e2019-11-27 16:14:38 -080083 void removeAttachment(Attachment attachmentInfo)
84 throws BngProgrammableException;
Daniele Moro464e5ed2019-07-25 14:45:01 -070085
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 Moro464e5ed2019-07-25 14:45:01 -0700196
197 /**
Carmelo Casconeda15af82019-12-09 22:36:48 -0800198 * Returns the application that is responsible for managing the
199 * attachment.
Daniele Moro464e5ed2019-07-25 14:45:01 -0700200 *
201 * @return The application ID.
202 */
203 ApplicationId appId();
204
205 /**
Carmelo Casconeda15af82019-12-09 22:36:48 -0800206 * Returns the VLAN S-tag of the attachment.
Daniele Moro464e5ed2019-07-25 14:45:01 -0700207 *
208 * @return The VLAN S-tag of the attachment.
209 */
210 VlanId sTag();
211
212 /**
Carmelo Casconeda15af82019-12-09 22:36:48 -0800213 * Returns the VLAN C-tag of the attachment.
Daniele Moro464e5ed2019-07-25 14:45:01 -0700214 *
215 * @return The VLAN C-tag of the attachment.
216 */
217 VlanId cTag();
218
219 /**
Carmelo Casconeda15af82019-12-09 22:36:48 -0800220 * Returns the MAC address of the attachment.
Daniele Moro464e5ed2019-07-25 14:45:01 -0700221 *
222 * @return The MAC address of the attachment.
223 */
224 MacAddress macAddress();
225
226 /**
Carmelo Casconeda15af82019-12-09 22:36:48 -0800227 * Returns the IP address of the attachment.
Daniele Moro464e5ed2019-07-25 14:45:01 -0700228 *
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 Casconeda15af82019-12-09 22:36:48 -0800241 * Returns the type of attachment.
Daniele Moro464e5ed2019-07-25 14:45:01 -0700242 *
243 * @return type of attachment
244 */
245 AttachmentType type();
246
247 /**
Carmelo Casconeda15af82019-12-09 22:36:48 -0800248 * Returns the PPPoE session ID of the attachment. This method is
249 * meaningful only if the attachment type is PPPoE.
Daniele Moro464e5ed2019-07-25 14:45:01 -0700250 *
251 * @return The PPPoE session ID.
252 */
253 short pppoeSessionId();
254
Carmelo Casconeda15af82019-12-09 22:36:48 -0800255 /**
256 * Types of attachment.
257 */
Daniele Moro464e5ed2019-07-25 14:45:01 -0700258 enum AttachmentType {
259 /**
Carmelo Casconeda15af82019-12-09 22:36:48 -0800260 * PPPoE attachment.
Daniele Moro464e5ed2019-07-25 14:45:01 -0700261 */
262 PPPoE,
263
264 /**
Carmelo Casconeda15af82019-12-09 22:36:48 -0800265 * IPoE attachment.
Daniele Moro464e5ed2019-07-25 14:45:01 -0700266 */
267 // TODO: unsupported.
268 IPoE
269 }
270 }
271
272 /**
Daniele Moro464e5ed2019-07-25 14:45:01 -0700273 * 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