blob: f30ec28f344d780daa2734488389b07ffc174735 [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
215 * @return true if the operation was successful, false otherwise
216 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200217 CompletableFuture<Boolean> writeActionGroup(
218 PiActionGroup group, WriteOperationType opType, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700219
220 /**
221 * Dumps all groups currently installed for the given action profile.
222 *
223 * @param actionProfileId the action profile id
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700224 * @param pipeconf the pipeconf currently deployed on the device
Carmelo Casconee44592f2018-09-12 02:24:47 -0700225 * @return completable future of a list of groups
Yi Tseng82512da2017-08-16 19:46:36 -0700226 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700227 CompletableFuture<List<PiActionGroup>> dumpGroups(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200228 PiActionProfileId actionProfileId, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700229
230 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -0700231 * Dumps all action profile member IDs for a given action profile.
232 *
233 * @param actionProfileId action profile ID
234 * @param pipeconf pipeconf
235 * @return future of list of action profile member ID
236 */
237 CompletableFuture<List<PiActionGroupMemberId>> dumpActionProfileMemberIds(
238 PiActionProfileId actionProfileId, PiPipeconf pipeconf);
239
240 /**
241 * Removes the given members from the given action profile. Returns the list
242 * of successfully removed members.
243 *
244 * @param actionProfileId action profile ID
245 * @param memberIds member IDs
246 * @param pipeconf pipeconf
247 * @return list of member IDs that were successfully removed from the device
248 */
249 CompletableFuture<List<PiActionGroupMemberId>> removeActionProfileMembers(
250 PiActionProfileId actionProfileId,
251 List<PiActionGroupMemberId> memberIds,
252 PiPipeconf pipeconf);
253
254 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200255 * Returns the configuration of all meter cells for the given set of meter
256 * identifiers and pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900257 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200258 * @param meterIds meter identifiers
259 * @param pipeconf pipeconf
Carmelo Casconee44592f2018-09-12 02:24:47 -0700260 * @return list of meter configurations
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900261 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700262 CompletableFuture<List<PiMeterCellConfig>> readAllMeterCells(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200263 Set<PiMeterId> meterIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900264
265 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -0700266 * Returns a list of meter configurations corresponding to the given set of
267 * meter cell identifiers, for the given pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900268 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200269 * @param cellIds set of meter cell identifiers
270 * @param pipeconf pipeconf
Carmelo Casconee44592f2018-09-12 02:24:47 -0700271 * @return list of meter configrations
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900272 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700273 CompletableFuture<List<PiMeterCellConfig>> readMeterCells(
Carmelo Casconee5b28722018-06-22 17:28:28 +0200274 Set<PiMeterCellId> cellIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900275
276 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200277 * Performs a write operation for the given meter configurations and
278 * pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900279 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200280 * @param cellConfigs meter cell configurations
281 * @param pipeconf pipeconf currently deployed on the device
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900282 * @return true if the operation was successful, false otherwise.
283 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200284 CompletableFuture<Boolean> writeMeterCells(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700285 List<PiMeterCellConfig> cellConfigs, PiPipeconf pipeconf);
Carmelo Cascone58136812018-07-19 03:40:16 +0200286
287 /**
288 * Performs the given write operation for the given PI multicast groups
289 * entries.
290 *
291 * @param entries multicast group entries
292 * @param opType write operation type
293 * @return true if the operation was successful, false otherwise
294 */
295 CompletableFuture<Boolean> writePreMulticastGroupEntries(
Carmelo Casconee44592f2018-09-12 02:24:47 -0700296 List<PiMulticastGroupEntry> entries,
Carmelo Cascone58136812018-07-19 03:40:16 +0200297 WriteOperationType opType);
298
299 /**
300 * Returns all multicast groups on device.
301 *
302 * @return multicast groups
303 */
Carmelo Casconee44592f2018-09-12 02:24:47 -0700304 CompletableFuture<List<PiMulticastGroupEntry>> readAllMulticastGroupEntries();
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400305}