blob: b99aef345ece0deb862fc93c23e2d1d279dfc779 [file] [log] [blame]
Carmelo Cascone4c289b72019-01-22 15:30:45 -08001/*
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.p4runtime.api;
18
19import org.onosproject.net.pi.model.PiActionProfileId;
20import org.onosproject.net.pi.model.PiCounterId;
21import org.onosproject.net.pi.model.PiMeterId;
22import org.onosproject.net.pi.model.PiPipeconf;
23import org.onosproject.net.pi.model.PiTableId;
24import org.onosproject.net.pi.runtime.PiEntity;
25import org.onosproject.net.pi.runtime.PiHandle;
26
27import java.util.Collection;
28import java.util.concurrent.CompletableFuture;
29
30/**
31 * P4Runtime client interface for the Read RPC that allows reading multiple
32 * entities with one request.
33 */
34public interface P4RuntimeReadClient {
35
36 /**
37 * Returns a new {@link ReadRequest} instance that can bed used to build a
Carmelo Casconec2be50a2019-04-10 00:15:39 -070038 * batched read request, for the given P4Runtime-internal device ID and
39 * pipeconf.
Carmelo Cascone4c289b72019-01-22 15:30:45 -080040 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070041 * @param p4DeviceId P4Runtime-internal device ID
42 * @param pipeconf pipeconf
Carmelo Cascone4c289b72019-01-22 15:30:45 -080043 * @return new read request
44 */
Carmelo Casconec2be50a2019-04-10 00:15:39 -070045 ReadRequest read(long p4DeviceId, PiPipeconf pipeconf);
Carmelo Cascone4c289b72019-01-22 15:30:45 -080046
47 /**
Carmelo Cascone61469462019-03-05 23:59:11 -080048 * Abstraction of a batched P4Runtime read request. Multiple entities can be
49 * added to the same request before submitting it.
Carmelo Cascone4c289b72019-01-22 15:30:45 -080050 */
51 interface ReadRequest {
52
53 /**
54 * Requests to read one entity identified by the given handle.
55 *
56 * @param handle handle
57 * @return this
58 */
59 ReadRequest handle(PiHandle handle);
60
61 /**
62 * Requests to read multiple entities identified by the given handles.
63 *
64 * @param handles iterable of handles
65 * @return this
66 */
67 ReadRequest handles(Iterable<? extends PiHandle> handles);
68
69 /**
70 * Requests to read all table entries from the given table ID.
71 *
72 * @param tableId table ID
73 * @return this
74 */
75 ReadRequest tableEntries(PiTableId tableId);
76
77 /**
78 * Requests to read all table entries from the given table IDs.
79 *
80 * @param tableIds table IDs
81 * @return this
82 */
83 ReadRequest tableEntries(Iterable<PiTableId> tableIds);
84
85 /**
86 * Requests to read the default table entry from the given table.
87 *
88 * @param tableId table ID
89 * @return this
90 */
91 ReadRequest defaultTableEntry(PiTableId tableId);
92
93 /**
94 * Requests to read the default table entry from the given tables.
95 *
96 * @param tableIds table IDs
97 * @return this
98 */
99 ReadRequest defaultTableEntry(Iterable<PiTableId> tableIds);
100
101 /**
102 * Requests to read all action profile groups from the given action
103 * profile.
104 *
105 * @param actionProfileId action profile ID
106 * @return this
107 */
108 ReadRequest actionProfileGroups(PiActionProfileId actionProfileId);
109
110 /**
111 * Requests to read all action profile groups from the given action
112 * profiles.
113 *
114 * @param actionProfileIds action profile IDs
115 * @return this
116 */
117 ReadRequest actionProfileGroups(Iterable<PiActionProfileId> actionProfileIds);
118
119 /**
120 * Requests to read all action profile members from the given action
121 * profile.
122 *
123 * @param actionProfileId action profile ID
124 * @return this
125 */
126 ReadRequest actionProfileMembers(PiActionProfileId actionProfileId);
127
128 /**
129 * Requests to read all action profile members from the given action
130 * profiles.
131 *
132 * @param actionProfileIds action profile IDs
133 * @return this
134 */
135 ReadRequest actionProfileMembers(Iterable<PiActionProfileId> actionProfileIds);
136
137 /**
138 * Requests to read all counter cells from the given counter.
139 *
140 * @param counterId counter ID
141 * @return this
142 */
143 ReadRequest counterCells(PiCounterId counterId);
144
145 /**
146 * Requests to read all counter cells from the given counters.
147 *
148 * @param counterIds counter IDs
149 * @return this
150 */
151 ReadRequest counterCells(Iterable<PiCounterId> counterIds);
152
153 /**
154 * Requests to read all direct counter cells from the given table.
155 *
156 * @param tableId table ID
157 * @return this
158 */
159 ReadRequest directCounterCells(PiTableId tableId);
160
161 /**
162 * Requests to read all direct counter cells from the given tables.
163 *
164 * @param tableIds table IDs
165 * @return this
166 */
167 ReadRequest directCounterCells(Iterable<PiTableId> tableIds);
168
169 /**
170 * Requests to read all meter cell configs from the given meter ID.
171 *
172 * @param meterId meter ID
173 * @return this
174 */
175 ReadRequest meterCells(PiMeterId meterId);
176
177 /**
178 * Requests to read all meter cell configs from the given meter IDs.
179 *
180 * @param meterIds meter IDs
181 * @return this
182 */
183 ReadRequest meterCells(Iterable<PiMeterId> meterIds);
184
185 /**
186 * Requests to read all direct meter cell configs from the given table.
187 *
188 * @param tableId table ID
189 * @return this
190 */
191 ReadRequest directMeterCells(PiTableId tableId);
192
193 /**
194 * Requests to read all direct meter cell configs from the given
195 * tables.
196 *
197 * @param tableIds table IDs
198 * @return this
199 */
200 ReadRequest directMeterCells(Iterable<PiTableId> tableIds);
201
202 /**
203 * Submits the read request and returns a read response wrapped in a
204 * completable future. The future is completed once all entities have
205 * been received by the P4Runtime client.
206 *
207 * @return completable future of a read response
208 */
209 CompletableFuture<ReadResponse> submit();
210
211 /**
212 * Similar to {@link #submit()}, but blocks until the operation is
213 * completed, after which, it returns a read response.
214 *
215 * @return read response
216 */
217 ReadResponse submitSync();
218
219 //TODO: implement per-entity asynchronous reads. This would allow a user
220 // of this client to process read entities as they arrive, instead of
221 // waiting for the client to receive them all. Java 9 Reactive Streams
222 // seems a good way of doing it.
223 }
224
225 /**
226 * Response to a P4Runtime read request.
227 */
228 interface ReadResponse {
229
230 /**
231 * Returns true if the request was successful with no errors, otherwise
232 * returns false. In case of errors, further details can be obtained
233 * with {@link #explanation()} and {@link #throwable()}.
234 *
235 * @return true if the request was successful with no errors, false
236 * otherwise
237 */
238 boolean isSuccess();
239
240 /**
241 * Returns a collection of all PI entities returned by the server.
242 *
243 * @return collection of all PI entities returned by the server
244 */
245 Collection<PiEntity> all();
246
247 /**
248 * Returns a collection of all PI entities of a given class returned by
249 * the server.
250 *
251 * @param clazz PI entity class
252 * @param <E> PI entity class
253 * @return collection of all PI entities returned by the server for the
254 * given PI entity class
255 */
256 <E extends PiEntity> Collection<E> all(Class<E> clazz);
257
258 /**
259 * If the read request was not successful, this method returns a message
260 * explaining the error occurred. Returns an empty string if such
261 * message is not available, or {@code null} if no errors occurred.
262 *
263 * @return error explanation or empty string or null
264 */
265 String explanation();
266
267 /**
268 * If the read request was not successful, this method returns the
269 * internal throwable instance associated with the error (e.g. a {@link
270 * io.grpc.StatusRuntimeException} instance). Returns null if such
271 * throwable instance is not available or if no errors occurred.
272 *
273 * @return throwable instance
274 */
275 Throwable throwable();
276 }
277}