blob: 93adf11eddb048110ab33f020a2ad86a06c26f7f [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 Casconeb045ddc2017-09-01 01:26:35 +020027import org.onosproject.net.pi.runtime.PiCounterCellData;
28import org.onosproject.net.pi.runtime.PiCounterCellId;
Frank Wangd7e3b4b2017-09-24 13:37:54 +090029import org.onosproject.net.pi.runtime.PiMeterCellConfig;
30import org.onosproject.net.pi.runtime.PiMeterCellId;
Carmelo Cascone58136812018-07-19 03:40:16 +020031import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
Andrea Campanella432f7182017-07-14 18:43:27 +020032import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040033import org.onosproject.net.pi.runtime.PiTableEntry;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040034
Carmelo Casconed61fdb32017-10-30 10:09:57 -070035import java.nio.ByteBuffer;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040036import java.util.Collection;
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020037import java.util.Set;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040038import java.util.concurrent.CompletableFuture;
39
40/**
41 * Client to control a P4Runtime device.
42 */
43@Beta
44public interface P4RuntimeClient {
45
46 /**
47 * Type of write operation.
48 */
49 enum WriteOperationType {
50 UNSPECIFIED,
51 INSERT,
Carmelo Cascone8d99b172017-07-18 17:26:31 -040052 MODIFY,
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040053 DELETE
54 }
55
56 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020057 * Starts the client by starting the Stream RPC with the device.
58 *
59 * @return completable future containing true if the operation was
60 * successful, false otherwise.
61 */
62 CompletableFuture<Boolean> start();
63
64 /**
65 * Shutdowns the client by terminating any active RPC such as the Stream
66 * one.
67 *
68 * @return a completable future to signal the completion of the shutdown
69 * procedure
70 */
71 CompletableFuture<Void> shutdown();
72
73 /**
74 * 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 /**
83 * Sets the device pipeline according to the given pipeconf, and for the
84 * given byte buffer representing the target-specific data to be used in the
85 * P4Runtime's SetPipelineConfig message. This method should be called
Carmelo Casconed61fdb32017-10-30 10:09:57 -070086 * before any other method of this client.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040087 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -070088 * @param pipeconf pipeconf
89 * @param deviceData target-specific data
Carmelo Casconee5b28722018-06-22 17:28:28 +020090 * @return a completable future of a boolean, true if the operations was
91 * successful, false otherwise.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040092 */
Carmelo Casconee5b28722018-06-22 17:28:28 +020093 CompletableFuture<Boolean> setPipelineConfig(
94 PiPipeconf pipeconf, ByteBuffer deviceData);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040095
96 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020097 * Performs the given write operation for the given table entries and
98 * pipeconf.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040099 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -0400100 * @param entries table entries
101 * @param opType operation type
102 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400103 * @return true if the operation was successful, false otherwise.
104 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200105 CompletableFuture<Boolean> writeTableEntries(
106 Collection<PiTableEntry> entries, WriteOperationType opType,
107 PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400108
109 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200110 * Dumps all entries currently installed in the given table, for the given
111 * pipeconf.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400112 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -0400113 * @param tableId table identifier
114 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400115 * @return completable future of a collection of table entries
116 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200117 CompletableFuture<Collection<PiTableEntry>> dumpTable(
118 PiTableId tableId, PiPipeconf pipeconf);
119
120 /**
121 * Dumps entries from all tables, for the given pipeconf.
122 *
123 * @param pipeconf pipeconf currently deployed on the device
124 * @return completable future of a collection of table entries
125 */
126 CompletableFuture<Collection<PiTableEntry>> dumpAllTables(PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400127
128 /**
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200129 * Executes a packet-out operation for the given pipeconf.
Andrea Campanella432f7182017-07-14 18:43:27 +0200130 *
131 * @param packet packet-out operation to be performed by the device
132 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconee5b28722018-06-22 17:28:28 +0200133 * @return a completable future of a boolean, true if the operations was
134 * successful, false otherwise.
Andrea Campanella432f7182017-07-14 18:43:27 +0200135 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200136 CompletableFuture<Boolean> packetOut(
137 PiPacketOperation packet, PiPipeconf pipeconf);
Andrea Campanella432f7182017-07-14 18:43:27 +0200138
Andrea Campanella432f7182017-07-14 18:43:27 +0200139 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200140 * Returns the value of all counter cells for the given set of counter
141 * identifiers and pipeconf.
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200142 *
143 * @param counterIds counter identifiers
144 * @param pipeconf pipeconf
145 * @return collection of counter data
146 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200147 CompletableFuture<Collection<PiCounterCellData>> readAllCounterCells(
148 Set<PiCounterId> counterIds, PiPipeconf pipeconf);
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200149
150 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200151 * Returns a collection of counter data corresponding to the given set of
152 * counter cell identifiers, for the given pipeconf.
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200153 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700154 * @param cellIds set of counter cell identifiers
155 * @param pipeconf pipeconf
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200156 * @return collection of counter data
157 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200158 CompletableFuture<Collection<PiCounterCellData>> readCounterCells(
159 Set<PiCounterCellId> cellIds, PiPipeconf pipeconf);
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200160
161 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200162 * Performs the given write operation for the given action group members and
163 * pipeconf.
Yi Tseng82512da2017-08-16 19:46:36 -0700164 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200165 * @param profileId action group profile ID
166 * @param members action group members
167 * @param opType write operation type
168 * @param pipeconf the pipeconf currently deployed on the device
Yi Tseng82512da2017-08-16 19:46:36 -0700169 * @return true if the operation was successful, false otherwise
170 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200171 CompletableFuture<Boolean> writeActionGroupMembers(
172 PiActionProfileId profileId, Collection<PiActionGroupMember> members,
173 WriteOperationType opType, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700174
175 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200176 * Performs the given write operation for the given action group and
177 * pipeconf.
Yi Tseng82512da2017-08-16 19:46:36 -0700178 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700179 * @param group the action group
180 * @param opType write operation type
Yi Tseng82512da2017-08-16 19:46:36 -0700181 * @param pipeconf the pipeconf currently deployed on the device
182 * @return true if the operation was successful, false otherwise
183 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200184 CompletableFuture<Boolean> writeActionGroup(
185 PiActionGroup group, WriteOperationType opType, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700186
187 /**
188 * Dumps all groups currently installed for the given action profile.
189 *
190 * @param actionProfileId the action profile id
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700191 * @param pipeconf the pipeconf currently deployed on the device
Yi Tseng82512da2017-08-16 19:46:36 -0700192 * @return completable future of a collection of groups
193 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200194 CompletableFuture<Collection<PiActionGroup>> dumpGroups(
195 PiActionProfileId actionProfileId, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700196
197 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200198 * Returns the configuration of all meter cells for the given set of meter
199 * identifiers and pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900200 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200201 * @param meterIds meter identifiers
202 * @param pipeconf pipeconf
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900203 * @return collection of meter configurations
204 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200205 CompletableFuture<Collection<PiMeterCellConfig>> readAllMeterCells(
206 Set<PiMeterId> meterIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900207
208 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200209 * Returns a collection of meter configurations corresponding to the given
210 * set of meter cell identifiers, for the given pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900211 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200212 * @param cellIds set of meter cell identifiers
213 * @param pipeconf pipeconf
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900214 * @return collection of meter configrations
215 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200216 CompletableFuture<Collection<PiMeterCellConfig>> readMeterCells(
217 Set<PiMeterCellId> cellIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900218
219 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200220 * Performs a write operation for the given meter configurations and
221 * pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900222 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200223 * @param cellConfigs meter cell configurations
224 * @param pipeconf pipeconf currently deployed on the device
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900225 * @return true if the operation was successful, false otherwise.
226 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200227 CompletableFuture<Boolean> writeMeterCells(
228 Collection<PiMeterCellConfig> cellConfigs, PiPipeconf pipeconf);
Carmelo Cascone58136812018-07-19 03:40:16 +0200229
230 /**
231 * Performs the given write operation for the given PI multicast groups
232 * entries.
233 *
234 * @param entries multicast group entries
235 * @param opType write operation type
236 * @return true if the operation was successful, false otherwise
237 */
238 CompletableFuture<Boolean> writePreMulticastGroupEntries(
239 Collection<PiMulticastGroupEntry> entries,
240 WriteOperationType opType);
241
242 /**
243 * Returns all multicast groups on device.
244 *
245 * @return multicast groups
246 */
247 CompletableFuture<Collection<PiMulticastGroupEntry>> readAllMulticastGroupEntries();
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400248}