blob: 7a08668a57245375f5b07bb55c103341e0a06596 [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;
26import org.onosproject.net.pi.runtime.PiActionGroup;
Yi Tseng8d355132018-04-13 01:40:48 +080027import org.onosproject.net.pi.runtime.PiActionGroupMember;
Carmelo Casconee44592f2018-09-12 02:24:47 -070028import org.onosproject.net.pi.runtime.PiActionGroupMemberId;
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 Casconee5b28722018-06-22 17:28:28 +0200188 * Performs the given write operation for the given action group members and
189 * pipeconf.
Yi Tseng82512da2017-08-16 19:46:36 -0700190 *
Carmelo Casconee44592f2018-09-12 02:24:47 -0700191 * @param members action group 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 Casconee5b28722018-06-22 17:28:28 +0200196 CompletableFuture<Boolean> writeActionGroupMembers(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700197 List<PiActionGroupMember> members,
Carmelo Casconee5b28722018-06-22 17:28:28 +0200198 WriteOperationType opType, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700199
200 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200201 * Performs the given write operation for the given action group and
202 * pipeconf.
Yi Tseng82512da2017-08-16 19:46:36 -0700203 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700204 * @param group the action group
205 * @param opType write operation type
Yi Tseng82512da2017-08-16 19:46:36 -0700206 * @param pipeconf the pipeconf currently deployed on the device
ghj0504520ed7340c2018-10-26 13:06:35 -0700207 * @param maxMemberSize the maximum number of members that can be added to the group.
208 * This is meaningful only if it's an INSERT operation, otherwise
209 * its value should be 0
Yi Tseng82512da2017-08-16 19:46:36 -0700210 * @return true if the operation was successful, false otherwise
211 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200212 CompletableFuture<Boolean> writeActionGroup(
ghj0504520ed7340c2018-10-26 13:06:35 -0700213 PiActionGroup group, WriteOperationType opType, PiPipeconf pipeconf, int maxMemberSize);
Yi Tseng82512da2017-08-16 19:46:36 -0700214
215 /**
216 * Dumps all groups currently installed for the given action profile.
217 *
218 * @param actionProfileId the action profile id
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700219 * @param pipeconf the pipeconf currently deployed on the device
Carmelo Casconee44592f2018-09-12 02:24:47 -0700220 * @return completable future of a list of groups
Yi Tseng82512da2017-08-16 19:46:36 -0700221 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700222 CompletableFuture<List<PiActionGroup>> dumpGroups(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200223 PiActionProfileId actionProfileId, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700224
225 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -0700226 * Dumps all action profile member IDs for a given action profile.
227 *
228 * @param actionProfileId action profile ID
229 * @param pipeconf pipeconf
230 * @return future of list of action profile member ID
231 */
232 CompletableFuture<List<PiActionGroupMemberId>> dumpActionProfileMemberIds(
233 PiActionProfileId actionProfileId, PiPipeconf pipeconf);
234
235 /**
236 * Removes the given members from the given action profile. Returns the list
237 * of successfully removed members.
238 *
239 * @param actionProfileId action profile ID
240 * @param memberIds member IDs
241 * @param pipeconf pipeconf
242 * @return list of member IDs that were successfully removed from the device
243 */
244 CompletableFuture<List<PiActionGroupMemberId>> removeActionProfileMembers(
245 PiActionProfileId actionProfileId,
246 List<PiActionGroupMemberId> memberIds,
247 PiPipeconf pipeconf);
248
249 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200250 * Returns the configuration of all meter cells for the given set of meter
251 * identifiers and pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900252 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200253 * @param meterIds meter identifiers
254 * @param pipeconf pipeconf
Carmelo Casconee44592f2018-09-12 02:24:47 -0700255 * @return list of meter configurations
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900256 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700257 CompletableFuture<List<PiMeterCellConfig>> readAllMeterCells(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200258 Set<PiMeterId> meterIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900259
260 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -0700261 * Returns a list of meter configurations corresponding to the given set of
262 * meter cell identifiers, for the given pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900263 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200264 * @param cellIds set of meter cell identifiers
265 * @param pipeconf pipeconf
Carmelo Casconee44592f2018-09-12 02:24:47 -0700266 * @return list of meter configrations
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900267 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700268 CompletableFuture<List<PiMeterCellConfig>> readMeterCells(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200269 Set<PiMeterCellId> cellIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900270
271 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200272 * Performs a write operation for the given meter configurations and
273 * pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900274 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200275 * @param cellConfigs meter cell configurations
276 * @param pipeconf pipeconf currently deployed on the device
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900277 * @return true if the operation was successful, false otherwise.
278 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200279 CompletableFuture<Boolean> writeMeterCells(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700280 List<PiMeterCellConfig> cellConfigs, PiPipeconf pipeconf);
Carmelo Cascone58136812018-07-19 03:40:16 +0200281
282 /**
283 * Performs the given write operation for the given PI multicast groups
284 * entries.
285 *
286 * @param entries multicast group entries
287 * @param opType write operation type
288 * @return true if the operation was successful, false otherwise
289 */
290 CompletableFuture<Boolean> writePreMulticastGroupEntries(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700291 List<PiMulticastGroupEntry> entries,
Carmelo Cascone58136812018-07-19 03:40:16 +0200292 WriteOperationType opType);
293
294 /**
295 * Returns all multicast groups on device.
296 *
297 * @return multicast groups
298 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700299 CompletableFuture<List<PiMulticastGroupEntry>> readAllMulticastGroupEntries();
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400300}