blob: ebb9f689d730407ecd807e49392c103e08e65592 [file] [log] [blame]
Daniele Morodbcffda2021-06-11 16:41:48 +02001/*
2 * Copyright 2021-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.upf;
18
19import com.google.common.annotations.Beta;
20import org.onlab.packet.Ip4Address;
21
22import java.nio.ByteBuffer;
23import java.util.Collection;
24
25/**
26 * Provides means to update forwarding state to implement a 3GPP User Plane Function.
27 */
28@Beta
29public interface UpfDevice {
30
31 /**
32 * Remove any state previously created by this API.
33 */
34 void cleanUp();
35
36 /**
37 * Remove all interfaces currently installed on the UPF-programmable device.
38 */
39 void clearInterfaces();
40
41 /**
42 * Remove all UE flows (PDRs, FARs) currently installed on the UPF-programmable device.
43 */
44 void clearFlows();
45
46 /**
47 * Get all ForwardingActionRules currently installed on the UPF-programmable device.
48 *
49 * @return a collection of installed FARs
50 * @throws UpfProgrammableException if FARs are unable to be read
51 */
52 Collection<ForwardingActionRule> getFars() throws UpfProgrammableException;
53
54 /**
55 * Get all PacketDetectionRules currently installed on the UPF-programmable device.
56 *
57 * @return a collection of installed PDRs
58 * @throws UpfProgrammableException if PDRs are unable to be read
59 */
60 Collection<PacketDetectionRule> getPdrs() throws UpfProgrammableException;
61
62 /**
63 * Get all UPF interface lookup entries currently installed on the UPF-programmable device.
64 *
65 * @return a collection of installed interfaces
66 * @throws UpfProgrammableException if interfaces are unable to be read
67 */
68 Collection<UpfInterface> getInterfaces() throws UpfProgrammableException;
69
70 /**
71 * Add a Packet Detection Rule (PDR) to the given device.
72 *
73 * @param pdr The PDR to be added
74 * @throws UpfProgrammableException if the PDR cannot be installed, or the counter index is out
75 * of bounds
76 */
77 void addPdr(PacketDetectionRule pdr) throws UpfProgrammableException;
78
79 /**
80 * Remove a previously installed Packet Detection Rule (PDR) from the target device.
81 *
82 * @param pdr The PDR to be removed
83 * @throws UpfProgrammableException if the PDR cannot be found
84 */
85 void removePdr(PacketDetectionRule pdr) throws UpfProgrammableException;
86
87 /**
88 * Add a Forwarding Action Rule (FAR) to the given device.
89 *
90 * @param far The FAR to be added
91 * @throws UpfProgrammableException if the FAR cannot be installed
92 */
93 void addFar(ForwardingActionRule far) throws UpfProgrammableException;
94
95 /**
96 * Remove a previously installed Forwarding Action Rule (FAR) from the target device.
97 *
98 * @param far The FAR to be removed
99 * @throws UpfProgrammableException if the FAR cannot be found
100 */
101 void removeFar(ForwardingActionRule far) throws UpfProgrammableException;
102
103 /**
104 * Install a new interface on the UPF device's interface lookup tables.
105 *
106 * @param upfInterface the interface to install
107 * @throws UpfProgrammableException if the interface cannot be installed
108 */
109 void addInterface(UpfInterface upfInterface) throws UpfProgrammableException;
110
111 /**
112 * Remove a previously installed UPF interface from the target device.
113 *
114 * @param upfInterface the interface to be removed
115 * @throws UpfProgrammableException if the interface cannot be found
116 */
117 void removeInterface(UpfInterface upfInterface) throws UpfProgrammableException;
118
119 /**
120 * Read the the given cell (Counter index) of the PDR counters from the given device.
121 *
122 * @param counterIdx The counter cell index from which to read
123 * @return A structure containing ingress and egress packet and byte counts for the given
124 * cellId.
125 * @throws UpfProgrammableException if the cell ID is out of bounds
126 */
127 PdrStats readCounter(int counterIdx) throws UpfProgrammableException;
128
129 /**
130 * Return the number of PDR counter cells available. The number of cells in the ingress and
131 * egress PDR counters are equivalent.
132 *
133 * @return PDR counter size
134 */
135 long pdrCounterSize();
136
137 /**
138 * Return the number of maximum number of table entries the FAR table supports.
139 *
140 * @return the number of FARs that can be installed
141 */
142 long farTableSize();
143
144 /**
145 * Return the total number of table entries the downlink and uplink PDR tables support. Both
146 * tables support an equal number of entries, so the total is twice the size of either.
147 *
148 * @return the total number of PDRs that can be installed
149 */
150 long pdrTableSize();
151
152 /**
153 * Read the counter contents for all cell indices that are valid on the hardware switch.
154 * @code maxCounterId} parameter is used to limit the number of counters
155 * retrieved from the UPF device. If the limit given is larger than the
156 * physical limit, the physical limit will be used. A limit of -1 removes
157 * limitations.
158 *
159 * @param maxCounterId Maximum counter ID to retrieve from the UPF device.
160 * @return A collection of counter values for all valid hardware counter cells
161 * @throws UpfProgrammableException if the counters are unable to be read
162 */
163 Collection<PdrStats> readAllCounters(long maxCounterId) throws UpfProgrammableException;
164
165 /**
166 * Set the source and destination of the GTPU tunnel used to send packets to a dbuf buffering
167 * device.
168 *
169 * @param switchAddr the address on the switch that sends and receives packets to and from dbuf
170 * @param dbufAddr the dataplane address of dbuf
171 */
172 void setDbufTunnel(Ip4Address switchAddr, Ip4Address dbufAddr);
173
174 /**
175 * Removes the dbuf tunnel info if they were previously set using {@link
176 * #setDbufTunnel(Ip4Address, Ip4Address)}.
177 */
178 void unsetDbufTunnel();
179
180 /**
181 * Install a BufferDrainer reference that can be used to trigger the draining of a specific dbuf
182 * buffer back into the UPF device.
183 *
184 * @param drainer the BufferDrainer reference
185 */
186 void setBufferDrainer(UpfProgrammable.BufferDrainer drainer);
187
188 /**
189 * Removes the buffer drainer if one was set using {@link #setBufferDrainer(UpfProgrammable.BufferDrainer)}.
190 */
191 void unsetBufferDrainer();
192
193 /**
194 * Instructs the UPF-programmable device to use GTP-U extension PDU Session Container (PSC) when
195 * doing encap of downlink packets, with the given QoS Flow Identifier (QFI).
196 *
197 * @param defaultQfi QFI to be used by default for all encapped packets.
198 * @throws UpfProgrammableException if operation is not available
199 */
200 // FIXME: remove once we expose QFI in logical pipeline
201 // QFI should be set by the SMF using PFCP
202 void enablePscEncap(int defaultQfi) throws UpfProgrammableException;
203
204 /**
205 * Disable PSC encap previously enabled with {@link #enablePscEncap(int)}.
206 *
207 * @throws UpfProgrammableException if operation is not available
208 */
209 // FIXME: remove once we expose QFI in logical pipeline
210 // QFI should be set by the SMF using PFCP
211 void disablePscEncap() throws UpfProgrammableException;
212
213 /**
214 * Sends the given data as a data plane packet-out through this device. Data is expected to
215 * contain an Ethernet frame.
216 *
217 * The device should process the packet through the pipeline tables to select an output port
218 * and to apply eventual modifications (e.g., MAC rewrite for routing, pushing a VLAN tag,
219 * etc.).
220 *
221 * @param data Ethernet frame bytes
222 */
223 void sendPacketOut(ByteBuffer data);
224
225 /**
226 * Used by the UpfProgrammable to trigger buffer draining as needed. Install an instance using
227 * {@link UpfProgrammable#setBufferDrainer(UpfProgrammable.BufferDrainer)}
228 */
229 //TODO: remove from UpfDevice
230 interface BufferDrainer {
231 /**
232 * Drain the buffer that contains packets for the UE with the given address.
233 *
234 * @param ueAddr the address of the UE for which we should drain a buffer
235 */
236 void drain(Ip4Address ueAddr);
237 }
238}