blob: 5d7e93e7523452383a9b0448564d549ae4560669 [file] [log] [blame]
Carmelo Casconef7aa3f92017-07-06 23:56:50 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Carmelo Casconef7aa3f92017-07-06 23:56:50 -04003 *
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 com.google.common.annotations.Beta;
Yi Tseng2a340f72018-11-02 16:52:47 -070020import org.onosproject.grpc.api.GrpcClient;
Carmelo Cascone87892e22017-11-13 16:01:29 -080021import org.onosproject.net.pi.model.PiActionProfileId;
Carmelo Cascone81929aa2018-04-07 01:38:55 -070022import org.onosproject.net.pi.model.PiCounterId;
23import org.onosproject.net.pi.model.PiMeterId;
24import org.onosproject.net.pi.model.PiPipeconf;
25import org.onosproject.net.pi.model.PiTableId;
Carmelo Casconecb4327a2018-09-11 15:17:23 -070026import org.onosproject.net.pi.runtime.PiActionProfileGroup;
27import org.onosproject.net.pi.runtime.PiActionProfileMember;
28import org.onosproject.net.pi.runtime.PiActionProfileMemberId;
steven308017632e152018-10-20 00:51:08 +080029import org.onosproject.net.pi.runtime.PiCounterCell;
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020030import org.onosproject.net.pi.runtime.PiCounterCellId;
Frank Wangd7e3b4b2017-09-24 13:37:54 +090031import org.onosproject.net.pi.runtime.PiMeterCellConfig;
32import org.onosproject.net.pi.runtime.PiMeterCellId;
Carmelo Cascone58136812018-07-19 03:40:16 +020033import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
Andrea Campanella432f7182017-07-14 18:43:27 +020034import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040035import org.onosproject.net.pi.runtime.PiTableEntry;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040036
Carmelo Casconed61fdb32017-10-30 10:09:57 -070037import java.nio.ByteBuffer;
Carmelo Casconee44592f2018-09-12 02:24:47 -070038import java.util.List;
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020039import java.util.Set;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040040import java.util.concurrent.CompletableFuture;
41
42/**
43 * Client to control a P4Runtime device.
44 */
45@Beta
Yi Tseng2a340f72018-11-02 16:52:47 -070046public interface P4RuntimeClient extends GrpcClient {
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040047
48 /**
49 * Type of write operation.
50 */
51 enum WriteOperationType {
52 UNSPECIFIED,
53 INSERT,
Carmelo Cascone8d99b172017-07-18 17:26:31 -040054 MODIFY,
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040055 DELETE
56 }
57
58 /**
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070059 * Starts the Stream RPC with the device.
Carmelo Casconee5b28722018-06-22 17:28:28 +020060 *
61 * @return completable future containing true if the operation was
62 * successful, false otherwise.
63 */
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070064 CompletableFuture<Boolean> startStreamChannel();
65
66 /**
67 * Returns true if the stream RPC is active, false otherwise.
68 *
69 * @return boolean
70 */
71 boolean isStreamChannelOpen();
Carmelo Casconee5b28722018-06-22 17:28:28 +020072
73 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020074 * Sends a master arbitration update to the device with a new election ID
75 * that is guaranteed to be the highest value between all clients.
76 *
77 * @return completable future containing true if the operation was
78 * successful; false otherwise
79 */
80 CompletableFuture<Boolean> becomeMaster();
81
82 /**
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070083 * Returns true if this client is master for the device, false otherwise.
84 *
85 * @return boolean
86 */
87 boolean isMaster();
88
89 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020090 * Sets the device pipeline according to the given pipeconf, and for the
91 * given byte buffer representing the target-specific data to be used in the
92 * P4Runtime's SetPipelineConfig message. This method should be called
Carmelo Casconed61fdb32017-10-30 10:09:57 -070093 * before any other method of this client.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040094 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -070095 * @param pipeconf pipeconf
96 * @param deviceData target-specific data
Carmelo Casconee5b28722018-06-22 17:28:28 +020097 * @return a completable future of a boolean, true if the operations was
98 * successful, false otherwise.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040099 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200100 CompletableFuture<Boolean> setPipelineConfig(
101 PiPipeconf pipeconf, ByteBuffer deviceData);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400102
103 /**
Carmelo Cascone9e4972c2018-08-30 00:29:16 -0700104 * Returns true if the device has the given pipeconf set, false otherwise.
105 * Equality is based on the P4Info extension of the pipeconf as well as the
106 * given device data byte buffer.
107 * <p>
108 * This method is expected to return {@code true} if invoked after calling
109 * {@link #setPipelineConfig(PiPipeconf, ByteBuffer)} with the same
110 * parameters.
111 *
112 * @param pipeconf pipeconf
113 * @param deviceData target-specific data
114 * @return boolean
115 */
116 boolean isPipelineConfigSet(PiPipeconf pipeconf, ByteBuffer deviceData);
117
118 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200119 * Performs the given write operation for the given table entries and
120 * pipeconf.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400121 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -0400122 * @param entries table entries
123 * @param opType operation type
124 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400125 * @return true if the operation was successful, false otherwise.
126 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200127 CompletableFuture<Boolean> writeTableEntries(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700128 List<PiTableEntry> entries, WriteOperationType opType,
Carmelo Casconee5b28722018-06-22 17:28:28 +0200129 PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400130
131 /**
Carmelo Cascone50d195f2018-09-11 13:26:38 -0700132 * Dumps all entries currently installed in the given tables, for the given
133 * pipeconf. If defaultEntries is set to true only the default action
134 * entries will be returned, otherwise non-default entries will be
135 * considered.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400136 *
Carmelo Casconee44592f2018-09-12 02:24:47 -0700137 * @param tableIds table identifiers
138 * @param defaultEntries true to read default entries, false for
139 * non-default
140 * @param pipeconf pipeconf currently deployed on the device
141 * @return completable future of a list of table entries
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400142 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700143 CompletableFuture<List<PiTableEntry>> dumpTables(
Carmelo Cascone50d195f2018-09-11 13:26:38 -0700144 Set<PiTableId> tableIds, boolean defaultEntries, PiPipeconf pipeconf);
Carmelo Casconee5b28722018-06-22 17:28:28 +0200145
146 /**
147 * Dumps entries from all tables, for the given pipeconf.
148 *
149 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconee44592f2018-09-12 02:24:47 -0700150 * @return completable future of a list of table entries
Carmelo Casconee5b28722018-06-22 17:28:28 +0200151 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700152 CompletableFuture<List<PiTableEntry>> dumpAllTables(PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400153
154 /**
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200155 * Executes a packet-out operation for the given pipeconf.
Andrea Campanella432f7182017-07-14 18:43:27 +0200156 *
157 * @param packet packet-out operation to be performed by the device
158 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconee5b28722018-06-22 17:28:28 +0200159 * @return a completable future of a boolean, true if the operations was
160 * successful, false otherwise.
Andrea Campanella432f7182017-07-14 18:43:27 +0200161 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200162 CompletableFuture<Boolean> packetOut(
163 PiPacketOperation packet, PiPipeconf pipeconf);
Andrea Campanella432f7182017-07-14 18:43:27 +0200164
Andrea Campanella432f7182017-07-14 18:43:27 +0200165 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200166 * Returns the value of all counter cells for the given set of counter
167 * identifiers and pipeconf.
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200168 *
169 * @param counterIds counter identifiers
170 * @param pipeconf pipeconf
Carmelo Casconee44592f2018-09-12 02:24:47 -0700171 * @return list of counter data
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200172 */
steven308017632e152018-10-20 00:51:08 +0800173 CompletableFuture<List<PiCounterCell>> readAllCounterCells(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200174 Set<PiCounterId> counterIds, PiPipeconf pipeconf);
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200175
176 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -0700177 * Returns a list of counter data corresponding to the given set of counter
178 * cell identifiers, for the given pipeconf.
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200179 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700180 * @param cellIds set of counter cell identifiers
181 * @param pipeconf pipeconf
Carmelo Casconee44592f2018-09-12 02:24:47 -0700182 * @return list of counter data
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200183 */
steven308017632e152018-10-20 00:51:08 +0800184 CompletableFuture<List<PiCounterCell>> readCounterCells(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200185 Set<PiCounterCellId> cellIds, PiPipeconf pipeconf);
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200186
187 /**
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700188 * Performs the given write operation for the given action profile members
189 * and pipeconf.
Yi Tseng82512da2017-08-16 19:46:36 -0700190 *
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700191 * @param members action profile members
192 * @param opType write operation type
193 * @param pipeconf the pipeconf currently deployed on the device
Yi Tseng82512da2017-08-16 19:46:36 -0700194 * @return true if the operation was successful, false otherwise
195 */
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700196 CompletableFuture<Boolean> writeActionProfileMembers(
197 List<PiActionProfileMember> members,
Carmelo Casconee5b28722018-06-22 17:28:28 +0200198 WriteOperationType opType, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700199
200 /**
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700201 * Performs the given write operation for the given action profile group and
Carmelo Casconee5b28722018-06-22 17:28:28 +0200202 * pipeconf.
Yi Tseng82512da2017-08-16 19:46:36 -0700203 *
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700204 * @param group the action profile group
205 * @param opType write operation type
206 * @param pipeconf the pipeconf currently deployed on the device
207 * @param maxMemberSize the maximum number of members that can be added to
208 * the group. This is meaningful only if it's an INSERT
209 * operation, otherwise its value should be 0
Yi Tseng82512da2017-08-16 19:46:36 -0700210 * @return true if the operation was successful, false otherwise
211 */
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700212 CompletableFuture<Boolean> writeActionProfileGroup(
213 PiActionProfileGroup group,
214 WriteOperationType opType,
215 PiPipeconf pipeconf,
216 int maxMemberSize);
Yi Tseng82512da2017-08-16 19:46:36 -0700217
218 /**
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700219 * Dumps all groups currently installed in the given action profile.
Yi Tseng82512da2017-08-16 19:46:36 -0700220 *
221 * @param actionProfileId the action profile id
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700222 * @param pipeconf the pipeconf currently deployed on the device
Carmelo Casconee44592f2018-09-12 02:24:47 -0700223 * @return completable future of a list of groups
Yi Tseng82512da2017-08-16 19:46:36 -0700224 */
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700225 CompletableFuture<List<PiActionProfileGroup>> dumpActionProfileGroups(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200226 PiActionProfileId actionProfileId, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700227
228 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -0700229 * Dumps all action profile member IDs for a given action profile.
230 *
231 * @param actionProfileId action profile ID
232 * @param pipeconf pipeconf
233 * @return future of list of action profile member ID
234 */
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700235 CompletableFuture<List<PiActionProfileMemberId>> dumpActionProfileMemberIds(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700236 PiActionProfileId actionProfileId, PiPipeconf pipeconf);
237
238 /**
239 * Removes the given members from the given action profile. Returns the list
240 * of successfully removed members.
241 *
242 * @param actionProfileId action profile ID
243 * @param memberIds member IDs
244 * @param pipeconf pipeconf
245 * @return list of member IDs that were successfully removed from the device
246 */
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700247 CompletableFuture<List<PiActionProfileMemberId>> removeActionProfileMembers(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700248 PiActionProfileId actionProfileId,
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700249 List<PiActionProfileMemberId> memberIds,
Carmelo Casconee44592f2018-09-12 02:24:47 -0700250 PiPipeconf pipeconf);
251
252 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200253 * Returns the configuration of all meter cells for the given set of meter
254 * identifiers and pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900255 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200256 * @param meterIds meter identifiers
257 * @param pipeconf pipeconf
Carmelo Casconee44592f2018-09-12 02:24:47 -0700258 * @return list of meter configurations
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900259 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700260 CompletableFuture<List<PiMeterCellConfig>> readAllMeterCells(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200261 Set<PiMeterId> meterIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900262
263 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -0700264 * Returns a list of meter configurations corresponding to the given set of
265 * meter cell identifiers, for the given pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900266 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200267 * @param cellIds set of meter cell identifiers
268 * @param pipeconf pipeconf
Carmelo Casconee44592f2018-09-12 02:24:47 -0700269 * @return list of meter configrations
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900270 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700271 CompletableFuture<List<PiMeterCellConfig>> readMeterCells(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200272 Set<PiMeterCellId> cellIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900273
274 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200275 * Performs a write operation for the given meter configurations and
276 * pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900277 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200278 * @param cellConfigs meter cell configurations
279 * @param pipeconf pipeconf currently deployed on the device
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900280 * @return true if the operation was successful, false otherwise.
281 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200282 CompletableFuture<Boolean> writeMeterCells(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700283 List<PiMeterCellConfig> cellConfigs, PiPipeconf pipeconf);
Carmelo Cascone58136812018-07-19 03:40:16 +0200284
285 /**
286 * Performs the given write operation for the given PI multicast groups
287 * entries.
288 *
289 * @param entries multicast group entries
290 * @param opType write operation type
291 * @return true if the operation was successful, false otherwise
292 */
293 CompletableFuture<Boolean> writePreMulticastGroupEntries(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700294 List<PiMulticastGroupEntry> entries,
Carmelo Cascone58136812018-07-19 03:40:16 +0200295 WriteOperationType opType);
296
297 /**
298 * Returns all multicast groups on device.
299 *
300 * @return multicast groups
301 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700302 CompletableFuture<List<PiMulticastGroupEntry>> readAllMulticastGroupEntries();
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400303}