blob: f44c629d7160b5ac49774a83f6af0fd9c0870962 [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;
Carmelo Cascone87892e22017-11-13 16:01:29 -080020import org.onosproject.net.pi.model.PiActionProfileId;
Carmelo Cascone81929aa2018-04-07 01:38:55 -070021import org.onosproject.net.pi.model.PiCounterId;
22import org.onosproject.net.pi.model.PiMeterId;
23import org.onosproject.net.pi.model.PiPipeconf;
24import org.onosproject.net.pi.model.PiTableId;
25import org.onosproject.net.pi.runtime.PiActionGroup;
Yi Tseng8d355132018-04-13 01:40:48 +080026import org.onosproject.net.pi.runtime.PiActionGroupMember;
Carmelo Casconee44592f2018-09-12 02:24:47 -070027import org.onosproject.net.pi.runtime.PiActionGroupMemberId;
steven308017632e152018-10-20 00:51:08 +080028import org.onosproject.net.pi.runtime.PiCounterCell;
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020029import org.onosproject.net.pi.runtime.PiCounterCellId;
Frank Wangd7e3b4b2017-09-24 13:37:54 +090030import org.onosproject.net.pi.runtime.PiMeterCellConfig;
31import org.onosproject.net.pi.runtime.PiMeterCellId;
Carmelo Cascone58136812018-07-19 03:40:16 +020032import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
Andrea Campanella432f7182017-07-14 18:43:27 +020033import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040034import org.onosproject.net.pi.runtime.PiTableEntry;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040035
Carmelo Casconed61fdb32017-10-30 10:09:57 -070036import java.nio.ByteBuffer;
Carmelo Casconee44592f2018-09-12 02:24:47 -070037import java.util.List;
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020038import java.util.Set;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040039import java.util.concurrent.CompletableFuture;
40
41/**
42 * Client to control a P4Runtime device.
43 */
44@Beta
45public interface P4RuntimeClient {
46
47 /**
48 * Type of write operation.
49 */
50 enum WriteOperationType {
51 UNSPECIFIED,
52 INSERT,
Carmelo Cascone8d99b172017-07-18 17:26:31 -040053 MODIFY,
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040054 DELETE
55 }
56
57 /**
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070058 * Starts the Stream RPC with the device.
Carmelo Casconee5b28722018-06-22 17:28:28 +020059 *
60 * @return completable future containing true if the operation was
61 * successful, false otherwise.
62 */
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070063 CompletableFuture<Boolean> startStreamChannel();
64
65 /**
66 * Returns true if the stream RPC is active, false otherwise.
67 *
68 * @return boolean
69 */
70 boolean isStreamChannelOpen();
Carmelo Casconee5b28722018-06-22 17:28:28 +020071
72 /**
73 * Shutdowns the client by terminating any active RPC such as the Stream
74 * one.
75 *
76 * @return a completable future to signal the completion of the shutdown
77 * procedure
78 */
79 CompletableFuture<Void> shutdown();
80
81 /**
82 * Sends a master arbitration update to the device with a new election ID
83 * that is guaranteed to be the highest value between all clients.
84 *
85 * @return completable future containing true if the operation was
86 * successful; false otherwise
87 */
88 CompletableFuture<Boolean> becomeMaster();
89
90 /**
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070091 * Returns true if this client is master for the device, false otherwise.
92 *
93 * @return boolean
94 */
95 boolean isMaster();
96
97 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020098 * Sets the device pipeline according to the given pipeconf, and for the
99 * given byte buffer representing the target-specific data to be used in the
100 * P4Runtime's SetPipelineConfig message. This method should be called
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700101 * before any other method of this client.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400102 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700103 * @param pipeconf pipeconf
104 * @param deviceData target-specific data
Carmelo Casconee5b28722018-06-22 17:28:28 +0200105 * @return a completable future of a boolean, true if the operations was
106 * successful, false otherwise.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400107 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200108 CompletableFuture<Boolean> setPipelineConfig(
109 PiPipeconf pipeconf, ByteBuffer deviceData);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400110
111 /**
Carmelo Cascone9e4972c2018-08-30 00:29:16 -0700112 * Returns true if the device has the given pipeconf set, false otherwise.
113 * Equality is based on the P4Info extension of the pipeconf as well as the
114 * given device data byte buffer.
115 * <p>
116 * This method is expected to return {@code true} if invoked after calling
117 * {@link #setPipelineConfig(PiPipeconf, ByteBuffer)} with the same
118 * parameters.
119 *
120 * @param pipeconf pipeconf
121 * @param deviceData target-specific data
122 * @return boolean
123 */
124 boolean isPipelineConfigSet(PiPipeconf pipeconf, ByteBuffer deviceData);
125
126 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200127 * Performs the given write operation for the given table entries and
128 * pipeconf.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400129 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -0400130 * @param entries table entries
131 * @param opType operation type
132 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400133 * @return true if the operation was successful, false otherwise.
134 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200135 CompletableFuture<Boolean> writeTableEntries(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700136 List<PiTableEntry> entries, WriteOperationType opType,
Carmelo Casconee5b28722018-06-22 17:28:28 +0200137 PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400138
139 /**
Carmelo Cascone50d195f2018-09-11 13:26:38 -0700140 * Dumps all entries currently installed in the given tables, for the given
141 * pipeconf. If defaultEntries is set to true only the default action
142 * entries will be returned, otherwise non-default entries will be
143 * considered.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400144 *
Carmelo Casconee44592f2018-09-12 02:24:47 -0700145 * @param tableIds table identifiers
146 * @param defaultEntries true to read default entries, false for
147 * non-default
148 * @param pipeconf pipeconf currently deployed on the device
149 * @return completable future of a list of table entries
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400150 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700151 CompletableFuture<List<PiTableEntry>> dumpTables(
Carmelo Cascone50d195f2018-09-11 13:26:38 -0700152 Set<PiTableId> tableIds, boolean defaultEntries, PiPipeconf pipeconf);
Carmelo Casconee5b28722018-06-22 17:28:28 +0200153
154 /**
155 * Dumps entries from all tables, for the given pipeconf.
156 *
157 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconee44592f2018-09-12 02:24:47 -0700158 * @return completable future of a list of table entries
Carmelo Casconee5b28722018-06-22 17:28:28 +0200159 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700160 CompletableFuture<List<PiTableEntry>> dumpAllTables(PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400161
162 /**
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200163 * Executes a packet-out operation for the given pipeconf.
Andrea Campanella432f7182017-07-14 18:43:27 +0200164 *
165 * @param packet packet-out operation to be performed by the device
166 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconee5b28722018-06-22 17:28:28 +0200167 * @return a completable future of a boolean, true if the operations was
168 * successful, false otherwise.
Andrea Campanella432f7182017-07-14 18:43:27 +0200169 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200170 CompletableFuture<Boolean> packetOut(
171 PiPacketOperation packet, PiPipeconf pipeconf);
Andrea Campanella432f7182017-07-14 18:43:27 +0200172
Andrea Campanella432f7182017-07-14 18:43:27 +0200173 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200174 * Returns the value of all counter cells for the given set of counter
175 * identifiers and pipeconf.
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200176 *
177 * @param counterIds counter identifiers
178 * @param pipeconf pipeconf
Carmelo Casconee44592f2018-09-12 02:24:47 -0700179 * @return list of counter data
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200180 */
steven308017632e152018-10-20 00:51:08 +0800181 CompletableFuture<List<PiCounterCell>> readAllCounterCells(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200182 Set<PiCounterId> counterIds, PiPipeconf pipeconf);
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200183
184 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -0700185 * Returns a list of counter data corresponding to the given set of counter
186 * cell identifiers, for the given pipeconf.
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200187 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700188 * @param cellIds set of counter cell identifiers
189 * @param pipeconf pipeconf
Carmelo Casconee44592f2018-09-12 02:24:47 -0700190 * @return list of counter data
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200191 */
steven308017632e152018-10-20 00:51:08 +0800192 CompletableFuture<List<PiCounterCell>> readCounterCells(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200193 Set<PiCounterCellId> cellIds, PiPipeconf pipeconf);
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200194
195 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200196 * Performs the given write operation for the given action group members and
197 * pipeconf.
Yi Tseng82512da2017-08-16 19:46:36 -0700198 *
Carmelo Casconee44592f2018-09-12 02:24:47 -0700199 * @param members action group members
200 * @param opType write operation type
201 * @param pipeconf the pipeconf currently deployed on the device
Yi Tseng82512da2017-08-16 19:46:36 -0700202 * @return true if the operation was successful, false otherwise
203 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200204 CompletableFuture<Boolean> writeActionGroupMembers(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700205 List<PiActionGroupMember> members,
Carmelo Casconee5b28722018-06-22 17:28:28 +0200206 WriteOperationType opType, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700207
208 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200209 * Performs the given write operation for the given action group and
210 * pipeconf.
Yi Tseng82512da2017-08-16 19:46:36 -0700211 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700212 * @param group the action group
213 * @param opType write operation type
Yi Tseng82512da2017-08-16 19:46:36 -0700214 * @param pipeconf the pipeconf currently deployed on the device
ghj0504520ed7340c2018-10-26 13:06:35 -0700215 * @param maxMemberSize the maximum number of members that can be added to the group.
216 * This is meaningful only if it's an INSERT operation, otherwise
217 * its value should be 0
Yi Tseng82512da2017-08-16 19:46:36 -0700218 * @return true if the operation was successful, false otherwise
219 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200220 CompletableFuture<Boolean> writeActionGroup(
ghj0504520ed7340c2018-10-26 13:06:35 -0700221 PiActionGroup group, WriteOperationType opType, PiPipeconf pipeconf, int maxMemberSize);
Yi Tseng82512da2017-08-16 19:46:36 -0700222
223 /**
224 * Dumps all groups currently installed for the given action profile.
225 *
226 * @param actionProfileId the action profile id
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700227 * @param pipeconf the pipeconf currently deployed on the device
Carmelo Casconee44592f2018-09-12 02:24:47 -0700228 * @return completable future of a list of groups
Yi Tseng82512da2017-08-16 19:46:36 -0700229 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700230 CompletableFuture<List<PiActionGroup>> dumpGroups(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200231 PiActionProfileId actionProfileId, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700232
233 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -0700234 * Dumps all action profile member IDs for a given action profile.
235 *
236 * @param actionProfileId action profile ID
237 * @param pipeconf pipeconf
238 * @return future of list of action profile member ID
239 */
240 CompletableFuture<List<PiActionGroupMemberId>> dumpActionProfileMemberIds(
241 PiActionProfileId actionProfileId, PiPipeconf pipeconf);
242
243 /**
244 * Removes the given members from the given action profile. Returns the list
245 * of successfully removed members.
246 *
247 * @param actionProfileId action profile ID
248 * @param memberIds member IDs
249 * @param pipeconf pipeconf
250 * @return list of member IDs that were successfully removed from the device
251 */
252 CompletableFuture<List<PiActionGroupMemberId>> removeActionProfileMembers(
253 PiActionProfileId actionProfileId,
254 List<PiActionGroupMemberId> memberIds,
255 PiPipeconf pipeconf);
256
257 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200258 * Returns the configuration of all meter cells for the given set of meter
259 * identifiers and pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900260 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200261 * @param meterIds meter identifiers
262 * @param pipeconf pipeconf
Carmelo Casconee44592f2018-09-12 02:24:47 -0700263 * @return list of meter configurations
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900264 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700265 CompletableFuture<List<PiMeterCellConfig>> readAllMeterCells(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200266 Set<PiMeterId> meterIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900267
268 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -0700269 * Returns a list of meter configurations corresponding to the given set of
270 * meter cell identifiers, for the given pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900271 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200272 * @param cellIds set of meter cell identifiers
273 * @param pipeconf pipeconf
Carmelo Casconee44592f2018-09-12 02:24:47 -0700274 * @return list of meter configrations
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900275 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700276 CompletableFuture<List<PiMeterCellConfig>> readMeterCells(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200277 Set<PiMeterCellId> cellIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900278
279 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200280 * Performs a write operation for the given meter configurations and
281 * pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900282 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200283 * @param cellConfigs meter cell configurations
284 * @param pipeconf pipeconf currently deployed on the device
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900285 * @return true if the operation was successful, false otherwise.
286 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200287 CompletableFuture<Boolean> writeMeterCells(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700288 List<PiMeterCellConfig> cellConfigs, PiPipeconf pipeconf);
Carmelo Cascone58136812018-07-19 03:40:16 +0200289
290 /**
291 * Performs the given write operation for the given PI multicast groups
292 * entries.
293 *
294 * @param entries multicast group entries
295 * @param opType write operation type
296 * @return true if the operation was successful, false otherwise
297 */
298 CompletableFuture<Boolean> writePreMulticastGroupEntries(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700299 List<PiMulticastGroupEntry> entries,
Carmelo Cascone58136812018-07-19 03:40:16 +0200300 WriteOperationType opType);
301
302 /**
303 * Returns all multicast groups on device.
304 *
305 * @return multicast groups
306 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700307 CompletableFuture<List<PiMulticastGroupEntry>> readAllMulticastGroupEntries();
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400308}