blob: 32b1f9f5475cfb9fe91a9785018906cfe819c70c [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 Cascone0e427dc2018-08-14 22:15:10 -070057 * Starts the client by starting the Stream RPC with the device. The
58 * implementation of this method is equivalent to {@link #becomeMaster()}.
Carmelo Casconee5b28722018-06-22 17:28:28 +020059 *
60 * @return completable future containing true if the operation was
61 * successful, false otherwise.
62 */
63 CompletableFuture<Boolean> start();
64
65 /**
66 * Shutdowns the client by terminating any active RPC such as the Stream
67 * one.
68 *
69 * @return a completable future to signal the completion of the shutdown
70 * procedure
71 */
72 CompletableFuture<Void> shutdown();
73
74 /**
75 * Sends a master arbitration update to the device with a new election ID
76 * that is guaranteed to be the highest value between all clients.
77 *
78 * @return completable future containing true if the operation was
79 * successful; false otherwise
80 */
81 CompletableFuture<Boolean> becomeMaster();
82
83 /**
84 * Sets the device pipeline according to the given pipeconf, and for the
85 * given byte buffer representing the target-specific data to be used in the
86 * P4Runtime's SetPipelineConfig message. This method should be called
Carmelo Casconed61fdb32017-10-30 10:09:57 -070087 * before any other method of this client.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040088 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -070089 * @param pipeconf pipeconf
90 * @param deviceData target-specific data
Carmelo Casconee5b28722018-06-22 17:28:28 +020091 * @return a completable future of a boolean, true if the operations was
92 * successful, false otherwise.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040093 */
Carmelo Casconee5b28722018-06-22 17:28:28 +020094 CompletableFuture<Boolean> setPipelineConfig(
95 PiPipeconf pipeconf, ByteBuffer deviceData);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040096
97 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020098 * Performs the given write operation for the given table entries and
99 * pipeconf.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400100 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -0400101 * @param entries table entries
102 * @param opType operation type
103 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400104 * @return true if the operation was successful, false otherwise.
105 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200106 CompletableFuture<Boolean> writeTableEntries(
107 Collection<PiTableEntry> entries, WriteOperationType opType,
108 PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400109
110 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200111 * Dumps all entries currently installed in the given table, for the given
112 * pipeconf.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400113 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -0400114 * @param tableId table identifier
115 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400116 * @return completable future of a collection of table entries
117 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200118 CompletableFuture<Collection<PiTableEntry>> dumpTable(
119 PiTableId tableId, PiPipeconf pipeconf);
120
121 /**
122 * Dumps entries from all tables, for the given pipeconf.
123 *
124 * @param pipeconf pipeconf currently deployed on the device
125 * @return completable future of a collection of table entries
126 */
127 CompletableFuture<Collection<PiTableEntry>> dumpAllTables(PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400128
129 /**
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200130 * Executes a packet-out operation for the given pipeconf.
Andrea Campanella432f7182017-07-14 18:43:27 +0200131 *
132 * @param packet packet-out operation to be performed by the device
133 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconee5b28722018-06-22 17:28:28 +0200134 * @return a completable future of a boolean, true if the operations was
135 * successful, false otherwise.
Andrea Campanella432f7182017-07-14 18:43:27 +0200136 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200137 CompletableFuture<Boolean> packetOut(
138 PiPacketOperation packet, PiPipeconf pipeconf);
Andrea Campanella432f7182017-07-14 18:43:27 +0200139
Andrea Campanella432f7182017-07-14 18:43:27 +0200140 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200141 * Returns the value of all counter cells for the given set of counter
142 * identifiers and pipeconf.
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200143 *
144 * @param counterIds counter identifiers
145 * @param pipeconf pipeconf
146 * @return collection of counter data
147 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200148 CompletableFuture<Collection<PiCounterCellData>> readAllCounterCells(
149 Set<PiCounterId> counterIds, PiPipeconf pipeconf);
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200150
151 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200152 * Returns a collection of counter data corresponding to the given set of
153 * counter cell identifiers, for the given pipeconf.
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200154 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700155 * @param cellIds set of counter cell identifiers
156 * @param pipeconf pipeconf
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200157 * @return collection of counter data
158 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200159 CompletableFuture<Collection<PiCounterCellData>> readCounterCells(
160 Set<PiCounterCellId> cellIds, PiPipeconf pipeconf);
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200161
162 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200163 * Performs the given write operation for the given action group members and
164 * pipeconf.
Yi Tseng82512da2017-08-16 19:46:36 -0700165 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200166 * @param profileId action group profile ID
167 * @param members action group members
168 * @param opType write operation type
169 * @param pipeconf the pipeconf currently deployed on the device
Yi Tseng82512da2017-08-16 19:46:36 -0700170 * @return true if the operation was successful, false otherwise
171 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200172 CompletableFuture<Boolean> writeActionGroupMembers(
173 PiActionProfileId profileId, Collection<PiActionGroupMember> members,
174 WriteOperationType opType, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700175
176 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200177 * Performs the given write operation for the given action group and
178 * pipeconf.
Yi Tseng82512da2017-08-16 19:46:36 -0700179 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700180 * @param group the action group
181 * @param opType write operation type
Yi Tseng82512da2017-08-16 19:46:36 -0700182 * @param pipeconf the pipeconf currently deployed on the device
183 * @return true if the operation was successful, false otherwise
184 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200185 CompletableFuture<Boolean> writeActionGroup(
186 PiActionGroup group, WriteOperationType opType, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700187
188 /**
189 * Dumps all groups currently installed for the given action profile.
190 *
191 * @param actionProfileId the action profile id
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700192 * @param pipeconf the pipeconf currently deployed on the device
Yi Tseng82512da2017-08-16 19:46:36 -0700193 * @return completable future of a collection of groups
194 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200195 CompletableFuture<Collection<PiActionGroup>> dumpGroups(
196 PiActionProfileId actionProfileId, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700197
198 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200199 * Returns the configuration of all meter cells for the given set of meter
200 * identifiers and pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900201 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200202 * @param meterIds meter identifiers
203 * @param pipeconf pipeconf
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900204 * @return collection of meter configurations
205 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200206 CompletableFuture<Collection<PiMeterCellConfig>> readAllMeterCells(
207 Set<PiMeterId> meterIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900208
209 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200210 * Returns a collection of meter configurations corresponding to the given
211 * set of meter cell identifiers, for the given pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900212 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200213 * @param cellIds set of meter cell identifiers
214 * @param pipeconf pipeconf
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900215 * @return collection of meter configrations
216 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200217 CompletableFuture<Collection<PiMeterCellConfig>> readMeterCells(
218 Set<PiMeterCellId> cellIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900219
220 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200221 * Performs a write operation for the given meter configurations and
222 * pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900223 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200224 * @param cellConfigs meter cell configurations
225 * @param pipeconf pipeconf currently deployed on the device
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900226 * @return true if the operation was successful, false otherwise.
227 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200228 CompletableFuture<Boolean> writeMeterCells(
229 Collection<PiMeterCellConfig> cellConfigs, PiPipeconf pipeconf);
Carmelo Cascone58136812018-07-19 03:40:16 +0200230
231 /**
232 * Performs the given write operation for the given PI multicast groups
233 * entries.
234 *
235 * @param entries multicast group entries
236 * @param opType write operation type
237 * @return true if the operation was successful, false otherwise
238 */
239 CompletableFuture<Boolean> writePreMulticastGroupEntries(
240 Collection<PiMulticastGroupEntry> entries,
241 WriteOperationType opType);
242
243 /**
244 * Returns all multicast groups on device.
245 *
246 * @return multicast groups
247 */
248 CompletableFuture<Collection<PiMulticastGroupEntry>> readAllMulticastGroupEntries();
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400249}